Skip to content

Commit

Permalink
added xp cooldown for dialogue xp skills
Browse files Browse the repository at this point in the history
closes #820
  • Loading branch information
b5635 committed Sep 23, 2023
1 parent 4926ca6 commit 523be7b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 57 deletions.
72 changes: 41 additions & 31 deletions src/nss/inc_xp.nss
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ void GiveXPToPC(object oPC, float fXpAmount, int bQuest = FALSE, string sSource

if (iWhole > 0)
SetXP(oPC, GetXP(oPC) + iWhole);

UpdateXPBarUI(oPC);
}

Expand Down Expand Up @@ -342,15 +342,15 @@ float GetPartyXPValue(object oCreature, int bAmbush, float fAverageLevel, int iT
}
else if (fCR < fAverageLevel)
{
fXP = fmin(100.0, BASE_XP * pow(2.0, (fCR - fAverageLevel)/2.0));
fXP = fmin(100.0, BASE_XP * pow(2.0, (fCR - fAverageLevel)/2.0));
}

// apply any boss multipliers, etc
fXP = fXP * fMultiplier;

// award more XP if the enemy is a caster or can summon pets
if (GetLevelByClass(CLASS_TYPE_DRUID, oCreature) >= 1 || GetLevelByClass(CLASS_TYPE_SORCERER, oCreature) > 1 || GetLevelByClass(CLASS_TYPE_WIZARD, oCreature) >= 1 || GetLevelByClass(CLASS_TYPE_CLERIC, oCreature) > 1 || GetLevelByClass(CLASS_TYPE_RANGER, oCreature) >= 6 )
fXP = fXP * 1.25;
fXP = fXP * 1.25;

// Cap the xp.
if (fXP > XP_MAX) fXP = XP_MAX;
Expand Down Expand Up @@ -398,7 +398,7 @@ void XPBar(object oPC)
{
return;
}

string sWindow = "pc_xpbar";
json jLabels = JsonArray();
jLabels = JsonArrayInsert(jLabels, JsonString("Horizontal"));
Expand All @@ -417,83 +417,83 @@ void XPBar(object oPC)
AddInterfaceConfigOptionColorPick(sWindow, "graduationcolor", "Graduation Color", "The color of the graduation marks along the bar.", NuiColor(20, 20, 20, 255));
AddInterfaceConfigOptionCheckBox(sWindow, "textvisible", "Progress Text", "Whether to show progress percent on the middle of the bar.", 1);
AddInterfaceConfigOptionColorPick(sWindow, "textcolor", "Progress Text Color", "Color of the progress text on the bar.", NuiColor(100, 100, 100, 255));

json jBackgroundColor = GetNuiConfigBind(sWindow, "backgroundcolor");
json jFilledColor = GetNuiConfigBind(sWindow, "progresscolor");
json jRestedColor = GetNuiConfigBind(sWindow, "restedcolor");
json jEdgeColor = GetNuiConfigBind(sWindow, "edgecolor");
json jGraduationColor = GetNuiConfigBind(sWindow, "graduationcolor");
json jTextVisible = GetNuiConfigBind(sWindow, "textvisible");
json jTextColor = GetNuiConfigBind(sWindow, "textcolor");

// The bar itself is a few components, drawn on top of each other.

// 1) Background.
// 2) Filled
// 3) Rested
// 4) Graduation
// 5) Edge

// We do graduation before edge so everything except the "teeth" can be squished by the edge
// If edge was afterwards it would have to be a long series of drawlists, which binds can't really change
// Making it one big drawlist and then covering it up later gets around that

json jBackgroundDrawListCoords = NuiBind("background_coords");
//json jBackgroundDrawList = NuiDrawListPolyLine(JsonBool(1), jBackgroundColor, JsonBool(1), JsonFloat(1.0), jBackgroundDrawListCoords);
json jBackgroundDrawList = NuiDrawListPolyLine(JsonBool(1), jBackgroundColor, JsonBool(1), JsonFloat(1.0), jBackgroundDrawListCoords);

json jFilledDrawListCoords = NuiBind("filled_coords");
json jFilledDrawList = NuiDrawListPolyLine(JsonBool(1), jFilledColor, JsonBool(1), JsonFloat(1.0), jFilledDrawListCoords);

json jRestedDrawListCoords = NuiBind("rested_coords");
json jRestedDrawList = NuiDrawListPolyLine(JsonBool(1), jRestedColor, JsonBool(1), JsonFloat(1.0), jRestedDrawListCoords);

json jGraduationDrawListCoords = NuiBind("graduation_coords");
json jGraduationDrawList = NuiDrawListPolyLine(JsonBool(1), jGraduationColor, JsonBool(0), JsonFloat(1.0), jGraduationDrawListCoords);

json jEdgeDrawListCoords = NuiBind("edge_coords");
json jEdgeDrawList = NuiDrawListPolyLine(JsonBool(1), jEdgeColor, JsonBool(0), JsonFloat(1.0), jEdgeDrawListCoords);

json jTextPos = NuiBind("text_pos");
json jTextContent = NuiBind("text_content");
json jTextDrawList = NuiDrawListText(jTextVisible, jTextColor, jTextPos, jTextContent);

json jDrawListArray = JsonArray();
jDrawListArray = JsonArrayInsert(jDrawListArray, jBackgroundDrawList);
jDrawListArray = JsonArrayInsert(jDrawListArray, jFilledDrawList);
jDrawListArray = JsonArrayInsert(jDrawListArray, jRestedDrawList);
jDrawListArray = JsonArrayInsert(jDrawListArray, jGraduationDrawList);
jDrawListArray = JsonArrayInsert(jDrawListArray, jEdgeDrawList);



jDrawListArray = JsonArrayInsert(jDrawListArray, jTextDrawList);

float fWinSizeX = 400.0;
float fWinSizeY = 40.0;

float fMidX = IntToFloat(GetPlayerDeviceProperty(oPC, PLAYER_DEVICE_PROPERTY_GUI_WIDTH)/2) - (fWinSizeX/2);
float fMidY = IntToFloat(GetPlayerDeviceProperty(oPC, PLAYER_DEVICE_PROPERTY_GUI_HEIGHT))*0.8 - (fWinSizeY/2);

json jGeometry = GetPersistentWindowGeometryBind(oPC, sWindow, NuiRect(fMidX, fMidY, fWinSizeX, fWinSizeY));

json jLabel = NuiLabel(JsonString(""), JsonInt(NUI_HALIGN_CENTER), JsonInt(NUI_VALIGN_MIDDLE));
jLabel = NuiDrawList(jLabel, JsonBool(0), jDrawListArray);

json jLayout = JsonArray();
jLayout = JsonArrayInsert(jLayout, jLabel);

json jRoot = NuiRow(jLayout);
json jNui = EditableNuiWindow(sWindow, "XP Bar", jRoot, "", jGeometry, 0, 0, 0, JsonBool(1), JsonBool(0));
//json jNui = NuiWindow(jRoot, JsonBool(FALSE), jGeometry, JsonBool(0), JsonBool(0), JsonBool(0), JsonBool(0), JsonBool(0));

json jNui = EditableNuiWindow(sWindow, "XP Bar", jRoot, "", jGeometry, 0, 0, 0, JsonBool(1), JsonBool(0));
//json jNui = NuiWindow(jRoot, JsonBool(FALSE), jGeometry, JsonBool(0), JsonBool(0), JsonBool(0), JsonBool(0), JsonBool(0));

int nToken = NuiCreate(oPC, jNui, sWindow);
// This thing wants to be much too small for this crude stuff
SetIsInterfaceConfigurable(oPC, nToken, 0, 0);
LoadNuiConfigBinds(oPC, nToken);


// The event script can calculate all the drawlist coordinates...
SetScriptParam("init", "init");
SetScriptParam("pc", ObjectToString(oPC));
Expand Down Expand Up @@ -532,6 +532,16 @@ void UpdateXPBarUI(object oPC)

void GiveDialogueSkillXP(object oPC, int nDC, int nSkill)
{
// OBJECT_SELF is probably going to be NPC speaker in most circumstances
string sIdentifier = "dlg_"+IntToString(nSkill)+"_xp_"+GetName(oPC) + GetPCPublicCDKey(oPC);

// this cannot be awarded again until reset
if (GetLocalInt(OBJECT_SELF, sIdentifier) == 1) return;


SetLocalInt(OBJECT_SELF, sIdentifier, 1);
DelayCommand(1800.0, DeleteLocalInt(OBJECT_SELF, sIdentifier)); // reset in 30 minutes

float fXP = IntToFloat(nDC) / 2.5;

if (fXP > 16.0) fXP = 16.0;
Expand All @@ -544,7 +554,7 @@ void GiveDialogueSkillXP(object oPC, int nDC, int nSkill)
case SKILL_BLUFF: sSkill = "Intimidation"; break;
case SKILL_INTIMIDATE: sSkill = "Bluffing"; break;
}

GiveXPToPC(oPC, fXP, FALSE, sSkill);
}

Expand Down
28 changes: 2 additions & 26 deletions src/nss/on_pc_skilla.nss
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ void GiveSkillXP(object oTarget, object oPC, string sSkill)
SetLocalInt(oTarget, sIdentifier, 1);
DelayCommand(1800.0, DeleteLocalInt(oTarget, sIdentifier)); // reset in 30 minutes

// we use party data to award XP. That means to maximize XP value, you must be solo or far away enough from people.
// Does that seem odd? Yes. But this is the way to make sure that the correct XP is accounted for if they kill the creature with a party
// we use party data to award XP. That means to maximize XP value, you must be solo or far away enough from people.
// Does that seem odd? Yes. But this is the way to make sure that the correct XP is accounted for if they kill the creature with a party
// (players can get more potential XP if they use a skill in a party versus killing them without any successful skill uses)
// another way to think about it, pickpocketing NPCs or using animal empathy with a party is less risky because you have a party to back you up in case shit hits the fan and they aggro

Expand Down Expand Up @@ -86,28 +86,4 @@ void main()
GiveSkillXP(oTarget, OBJECT_SELF, "Animal Empathy");
}
}
/* this doesnt seem to work :(
else if (StringToInt(NWNX_Events_GetEventData("SKILL_ID")) == SKILL_OPEN_LOCK)
{
object oTarget = StringToObject(NWNX_Events_GetEventData("TARGET_OBJECT_ID"));
if (GetIsPC(OBJECT_SELF) && StringToInt(NWNX_Events_GetEventData("ACTION_RESULT"))) //&& !GetLocked(oTarget))
{
float fXP = IntToFloat(GetLockUnlockDC(oTarget));
if (fXP > 0.0)
{
fXP = fXP/4.0;
}
else
{
return;
}
if (fXP > 12.0) fXP = 12.0;
GiveXPToPC(OBJECT_SELF, fXP, FALSE, "Lockpicking");
}
}
*/
}

0 comments on commit 523be7b

Please sign in to comment.