Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Player Statistics UI #756

Merged
merged 9 commits into from
Jul 26, 2023
2 changes: 1 addition & 1 deletion config/common.env
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export NWNX_AREA_SKIP=n
export NWNX_CHAT_SKIP=n
export NWNX_COMBATMODES_SKIP=n
export NWNX_CREATURE_SKIP=n
export NWNX_DAMAGE_SKIP=y
export NWNX_DAMAGE_SKIP=n
export NWNX_DATA_SKIP=y
export NWNX_DIALOG_SKIP=y
export NWNX_ELC_SKIP=n
Expand Down
3 changes: 2 additions & 1 deletion src/nss/0e_load_menu.nss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

void main ()
{
if (SQLocalsPlayer_GetInt(OBJECT_SELF, "pc_menu_disabled") != 1)
string sKey = GetPCPublicCDKey(OBJECT_SELF, TRUE);
if (GetCampaignInt(sKey, "pc_menu_disabled") != 1)
{
// Sets up the player target event.
// If you have a target event then you will have to adjust it for you NUI.
Expand Down
61 changes: 4 additions & 57 deletions src/nss/0e_window.nss
Original file line number Diff line number Diff line change
Expand Up @@ -11,62 +11,6 @@
#include "inc_restxp"
#include "inc_sqlite_time"

void SendStatistic(object oPlayer, string sLabel, string sStatKey)
{
string sStat = IntToString(SQLocalsPlayer_GetInt(oPlayer, STAT_PREFIX+sStatKey));

SendColorMessageToPC(oPlayer, sLabel + ": " + sStat, MESSAGE_COLOR_INFO);
}

// TODO: Make this into NUI
void SendStatistics(object oPlayer)
{
SendStatistic(oPlayer, "Time played (seconds)", "time_played");

SendStatistic(oPlayer, "Locks unlocked", "locks_unlocked");
SendStatistic(oPlayer, "Locks bashed", "locks_bashed");

SendStatistic(oPlayer, "Henchman recruited", "henchman_recruited");
SendStatistic(oPlayer, "Henchman died", "henchman_died");
SendStatistic(oPlayer, "Followers recruited", "followers_recruited");
SendStatistic(oPlayer, "Followers died", "followers_died");

SendStatistic(oPlayer, "Bounties completed", "bounties_completed");

SendStatistic(oPlayer, "Gold looted", "gold_looted");
SendStatistic(oPlayer, "Treasures looted", "treasures_looted");
SendStatistic(oPlayer, "Gold earned from selling", "gold_earned_from_selling");
SendStatistic(oPlayer, "Items sold", "items_sold");

SendStatistic(oPlayer, "Gold spent", "gold_spent_from_buying");
SendStatistic(oPlayer, "Items bought", "items_bought");

SendStatistic(oPlayer, "Ferries used", "ferries_used");
SendStatistic(oPlayer, "Gold spent on ferries", "gold_spent_on_ferries");

SendStatistic(oPlayer, "Boats used", "long_travel_used");
SendStatistic(oPlayer, "Gold spent on boats", "gold_spent_on_long_travel");

SendStatistic(oPlayer, "Treasure maps completed", "treasure_maps_completed");

SendStatistic(oPlayer, "Traps triggered", "traps_triggered");

SendStatistic(oPlayer, "Assassination attempts thwarted", "assasination_attempts_thwarted");
SendStatistic(oPlayer, "Times rested", "rests_completed");
SendStatistic(oPlayer, "Times ambushed while resting", "rest_ambushes");

SendStatistic(oPlayer, "Enemies killed", "enemies_killed");
SendStatistic(oPlayer, "Enemies killed by you", "enemies_killed_with_credit");
SendStatistic(oPlayer, "Bosses killed by you", "bosses_killed");
SendStatistic(oPlayer, "Innocents murdered by you", "innocents_killed");
SendStatistic(oPlayer, "Allies killed by you", "allies_killed");

SendStatistic(oPlayer, "Deaths", "deaths");
SendStatistic(oPlayer, "Deaths from traps", "deaths_from_traps");
SendStatistic(oPlayer, "Respawns", "respawned");
SendStatistic(oPlayer, "Revived", "revived"); // this can probably be deprecated, you can determine this from deaths + respawns
}

void main()
{
// Let the inspector handle what it wants.
Expand Down Expand Up @@ -119,7 +63,6 @@ void main()
string sRespawn = GetRespawnLocationName(oPlayer);
SendColorMessageToPC(oPlayer, "You have chosen to respawn in " + sRespawn + ".", MESSAGE_COLOR_INFO);
SendRestedXPNotifierToPC(oPlayer);
SendStatistics(oPlayer);
// PopUpPlayerSummaryGUIPanel(oPlayer, "pcsummarywin");
}
}
Expand Down Expand Up @@ -170,6 +113,10 @@ void main()
{
DisplayUIMasterConfigurationInterface(oPlayer);
}
else if (sEvent == "click" && sElem == "open_statistics")
{
ShowPlayerStatsUI(oPlayer);
}
}
// This is the bug report event.
else if (sWndId == "pcbugwin")
Expand Down
11 changes: 11 additions & 0 deletions src/nss/0i_win_layouts.nss
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,17 @@ void PopUpOptionsGUIPanel (object oPC, string sWinID)
// Add row to the column.
jCol = JsonArrayInsert(jCol, NuiRow(jRow));

// Create row 1 (label).
jRow = JsonArray();
jButton = NuiButton(JsonString("Gameplay Statistics"));
jButton = NuiWidth(jButton, 300.0);
jButton = NuiHeight(jButton, 40.0);
jButton = NuiTooltip(jButton, JsonString("View your gameplay statistics."));
jButton = NuiId(jButton, "open_statistics");
jRow = JsonArrayInsert(jRow, jButton);
// Add row to the column.
jCol = JsonArrayInsert(jCol, NuiRow(jRow));

// Create row 1 (label).
jRow = JsonArray ();
json jCheckBox = NuiWidth(NuiHeight(NuiCheck(NuiBind("hide_discord_label"), NuiBind("hide_discord_value2")), 40.0), 300.0);
Expand Down
5 changes: 3 additions & 2 deletions src/nss/70_inc_nwnx.nss
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@

const int REST_EVENTTYPE_REST_FORCEREST = 4;

const int DURATION_TYPE_EQUIPPED = 3;
const int DURATION_TYPE_INNATE = 4;
// These conflict with real nwnx stuff
//const int DURATION_TYPE_EQUIPPED = 3;
//const int DURATION_TYPE_INNATE = 4;

const int AREA_DAYTIME_RESET_DEFAULT = -1;
const int AREA_DAYTIME_DAY = 0;
Expand Down
7 changes: 4 additions & 3 deletions src/nss/_pc_menu_toggler.nss
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
void main()
{
object oPC = GetItemActivator();
string sKey = GetPCPublicCDKey(oPC, TRUE);

if (SQLocalsPlayer_GetInt(oPC, "pc_menu_disabled") == 1)
if (GetCampaignInt(sKey, "pc_menu_disabled") == 1)
{
SendColorMessageToPC(oPC, "Player menu enabled", MESSAGE_COLOR_INFO);
SQLocalsPlayer_DeleteInt(oPC, "pc_menu_disabled");
DeleteCampaignVariable(sKey, "pc_menu_disabled");
PopUpPlayerHorGUIPanel(oPC);
}
else
{
SendColorMessageToPC(oPC, "Player menu disabled", MESSAGE_COLOR_INFO);
SQLocalsPlayer_SetInt(oPC, "pc_menu_disabled", 1);
SetCampaignInt(sKey, "pc_menu_disabled", 1);
NuiDestroy(oPC, NuiFindWindow(oPC, "pcplayerwin"));
}
}
40 changes: 22 additions & 18 deletions src/nss/ai_ondeath.nss
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,38 @@ void main()

if (GetLocalString(OBJECT_SELF, "heartbeat_script") == "fol_heartb")
{
IncrementStat(GetMaster(OBJECT_SELF), "followers_died");
IncrementPlayerStatistic(GetMaster(OBJECT_SELF), "followers_died");
}

// not counting associates. we should count summons though

if (GetIsPC(oKiller))
object oPCToIncrementOn = oKiller;

if (GetIsPC(GetMaster(oKiller)))
{
IncrementStat(oKiller, "enemies_killed");
int nAssociateType = GetAssociateType(oKiller);

if (GetLocalInt(OBJECT_SELF, "boss") == 1)
if (nAssociateType == ASSOCIATE_TYPE_FAMILIAR || nAssociateType == ASSOCIATE_TYPE_ANIMALCOMPANION || nAssociateType == ASSOCIATE_TYPE_DOMINATED || nAssociateType == ASSOCIATE_TYPE_SUMMONED)
{
IncrementStat(oKiller, "bosses_killed");
oPCToIncrementOn = GetMaster(oKiller);
}
}
else if (GetIsPC(GetMaster(oKiller)))

if (GetIsPC(oPCToIncrementOn))
{
int nAssociateType = GetAssociateType(oKiller);
int nCR = GetLocalInt(OBJECT_SELF, "cr");
IncrementPlayerStatistic(oPCToIncrementOn, "enemies_killed");

if (nAssociateType == ASSOCIATE_TYPE_FAMILIAR || nAssociateType == ASSOCIATE_TYPE_ANIMALCOMPANION || nAssociateType == ASSOCIATE_TYPE_DOMINATED || nAssociateType == ASSOCIATE_TYPE_SUMMONED)
if (GetLocalInt(OBJECT_SELF, "boss") == 1)
{
object oPC = GetMaster(oKiller);

IncrementStat(oPC, "enemies_killed");

if (GetLocalInt(OBJECT_SELF, "boss") == 1)
{
IncrementStat(oPC, "bosses_killed");
}
nCR++;
IncrementPlayerStatistic(oPCToIncrementOn, "bosses_killed");
}

int nOldMaxCR = GetPlayerStatistic(oPCToIncrementOn, "most_powerful_cr");
if (nCR > nOldMaxCR)
{
SetPlayerStatistic(oPCToIncrementOn, "most_powerful_cr", nCR);
SetPlayerStatisticString(oPCToIncrementOn, "most_powerful_killed", GetName(OBJECT_SELF));
}
}

Expand All @@ -79,7 +83,7 @@ void main()
oMurderer = oKiller;
}

IncrementStat(oMurderer, "innocents_killed");
IncrementPlayerStatistic(oMurderer, "innocents_killed");

if (GetIsPC(oMurderer))
AdjustAlignment(oMurderer, ALIGNMENT_EVIL, 5, FALSE);
Expand Down
2 changes: 1 addition & 1 deletion src/nss/bash_lock.nss
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void BashLock(object oAttacker)
nEffect = VFX_COM_BLOOD_SPARK_LARGE;
AssignCommand(oAttacker, ClearAllActions(TRUE));

IncrementStat(oAttacker, "locks_bashed");
IncrementPlayerStatistic(oAttacker, "locks_bashed");

PlaySound("cb_bu_metallrg");

Expand Down
23 changes: 10 additions & 13 deletions src/nss/dev_khadala.nss
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ int GetMultiplierForBaseItemType(int nBaseItem)
else if (nBaseItem == BASE_ITEM_SPELLSCROLL) { nMultiplier = 0; }
else if (nBaseItem == BASE_ITEM_GLOVES) { nMultiplier = 3; }
else if (nBaseItem == BASE_ITEM_BRACER) { nMultiplier = 3; }
else if (nBaseItem == BASE_ITEM_RING) { nMultiplier = 5; }
else if (nBaseItem == BASE_ITEM_AMULET) { nMultiplier = 6; }
else if (nBaseItem == BASE_ITEM_RING) { nMultiplier = 3; }
else if (nBaseItem == BASE_ITEM_AMULET) { nMultiplier = 3; }
else if (nBaseItem == BASE_ITEM_CLOAK) { nMultiplier = 3; }
else if (nBaseItem == BASE_ITEM_BELT) { nMultiplier = 3; }
else if (nBaseItem == BASE_ITEM_HELMET) { nMultiplier = 3; }
else if (nBaseItem == BASE_ITEM_LARGESHIELD) { nMultiplier = 3; }
else if (nBaseItem == BASE_ITEM_TOWERSHIELD) { nMultiplier = 4; }
else if (nBaseItem == BASE_ITEM_MAGICWAND) { nMultiplier = 8; }
else if (nBaseItem == BASE_ITEM_MAGICWAND) { nMultiplier = 3; }
return nMultiplier;
}

Expand Down Expand Up @@ -191,15 +191,13 @@ float _GetExpectedCostForItemOfTier(float fChance, float fExpectedItemValue, int
}

float GetAverageCostForBaseItem(int nBaseItem, int nCost)
{
int nMultiplier = GetMultiplierForBaseItemType(nBaseItem);

{
int nRandom = d100();


float fT5Chance = IntToFloat(1*nMultiplier)/100.0;
float fT4Chance = IntToFloat(3*nMultiplier)/100.0;
float fT3Chance = IntToFloat(7*nMultiplier)/100.0;
float fT5Chance = 3.0/100.0;
float fT4Chance = 7.0/100.0;
float fT3Chance = 20.0/100.0;


float fT2Chance = 1.0 - (fT3Chance + fT4Chance + fT5Chance);
Expand Down Expand Up @@ -231,13 +229,12 @@ float GetAverageCostForBaseItem(int nBaseItem, int nCost)

float GetAverageCostForBaseAC(int nAC, int nCost)
{
int nMultiplier = GetMultiplierForBaseAC(nAC);
int nRandom = d100();


float fT5Chance = IntToFloat(1*nMultiplier)/100.0;
float fT4Chance = IntToFloat(3*nMultiplier)/100.0;
float fT3Chance = IntToFloat(7*nMultiplier)/100.0;
float fT5Chance = 3.0/100.0;
float fT4Chance = 7.0/100.0;
float fT3Chance = 20.0/100.0;


float fT2Chance = 1.0 - (fT3Chance + fT4Chance + fT5Chance);
Expand Down
6 changes: 2 additions & 4 deletions src/nss/dev_test.nss
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "inc_nui_config"
#include "nui_playerstats"

void main()
{
AssignCommand(GetFirstPC(), SpeakString("dev_test"));
ExecuteScript("pc_xpbar", GetFirstPC());
DisplayUIMasterConfigurationInterface(GetFirstPC());
ShowPlayerStatsUI(GetFirstPC());
}
4 changes: 2 additions & 2 deletions src/nss/dlg_andriel_act.nss
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ void main()

TakeGoldFromCreature(nRealCost, oPC, TRUE);

IncrementStat(oPC, "gold_spent_from_buying", nRealCost);
IncrementStat(oPC, "items_bought");
IncrementPlayerStatistic(oPC, "gold_spent_from_buying", nRealCost);
IncrementPlayerStatistic(oPC, "items_bought");

int nACR = GetHitDice(oPC);
int nVariability = GetHitDice(oPC) / 4;
Expand Down
3 changes: 3 additions & 0 deletions src/nss/dlg_andriel_cond.nss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "inc_gold"
#include "inc_treasuremap"
#include "inc_persist"
#include "inc_general"
#include "inc_sqlite_time"

// See also: dlg_andriel_act
Expand Down Expand Up @@ -45,9 +46,11 @@ int StartingConditional()

if(!(GetIsSkillSuccessful(oPC, nSkill, nDC)))
{
IncrementPlayerStatistic(oPC, "persuade_failed");
SetTemporaryInt(GetPCPublicCDKey(oPC, TRUE)+GetName(oPC)+"_"+GetTag(OBJECT_SELF)+"_pers", 1, 900.0);
return FALSE;
}
IncrementPlayerStatistic(oPC, "persuade_succeeded");
}

string sHasMap = GetScriptParam("hasmap");
Expand Down
3 changes: 3 additions & 0 deletions src/nss/dlg_avista_pers.nss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "inc_gold"
#include "inc_persist"
#include "inc_general"

int StartingConditional()
{
Expand All @@ -13,11 +14,13 @@ int StartingConditional()

if(!(GetIsSkillSuccessful(oPC, nSkill, nDC)))
{
IncrementPlayerStatistic(oPC, "persuade_failed");
SetTemporaryInt(GetPCPublicCDKey(oPC, TRUE)+GetName(oPC)+GetTag(OBJECT_SELF), 1, 900.0);
return FALSE;
}
else
{
IncrementPlayerStatistic(oPC, "persuade_succeeded");
TakeGoldFromCreature(nCost, oPC, TRUE);
return TRUE;
}
Expand Down
3 changes: 3 additions & 0 deletions src/nss/dlg_bluf_chk.nss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "inc_persist"
#include "inc_general"

int StartingConditional()
{
Expand All @@ -8,11 +9,13 @@ int StartingConditional()

if(!(GetIsSkillSuccessful(oPC, nSkill, nDC)))
{
IncrementPlayerStatistic(oPC, "bluff_failed");
SetTemporaryInt(GetPCPublicCDKey(oPC, TRUE)+GetName(oPC)+GetTag(OBJECT_SELF)+"_bluf", 1, 900.0);
return FALSE;
}
else
{
IncrementPlayerStatistic(oPC, "bluff_succeeded");
return TRUE;
}
}
4 changes: 3 additions & 1 deletion src/nss/dlg_chk_bluf.nss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "inc_persist"
#include "inc_general"
// Bluff against bluff_dc local variable, offer 1 attempt per 15min
// set script param "dc" to use that instead

Expand All @@ -21,9 +22,10 @@ int StartingConditional()

if(!(GetIsSkillSuccessful(oPC, nSkill, nDC)))
{
IncrementPlayerStatistic(oPC, "bluff_failed");
SetTemporaryInt(GetPCPublicCDKey(oPC, TRUE)+GetName(oPC)+"_"+GetTag(OBJECT_SELF)+"_bluf", 1, 900.0);
return FALSE;
}

IncrementPlayerStatistic(oPC, "bluff_succeeded");
return TRUE;
}
Loading
Loading