Fix displaying xp gained with Swift Learner bonus

This commit is contained in:
Alexander Batalov 2022-08-14 18:46:02 +03:00
parent 7096116296
commit b10c580d6f
5 changed files with 27 additions and 17 deletions

View File

@ -2822,7 +2822,9 @@ void _combat_give_exps(int exp_points)
return; return;
} }
pcAddExperience(exp_points); // SFALL: Display actual xp received.
int xpGained;
pcAddExperience(exp_points, &xpGained);
v7.num = 621; // %s you earn %d exp. points. v7.num = 621; // %s you earn %d exp. points.
if (!messageListGetItem(&gProtoMessageList, &v7)) { if (!messageListGetItem(&gProtoMessageList, &v7)) {
@ -2841,7 +2843,7 @@ void _combat_give_exps(int exp_points)
return; return;
} }
sprintf(text, v7.text, v9.text, exp_points); sprintf(text, v7.text, v9.text, xpGained);
displayMonitorAddMessage(text); displayMonitorAddMessage(text);
} }

View File

@ -3901,15 +3901,17 @@ int inventoryOpenLooting(Object* a1, Object* a2)
stealingXp = std::min(300 - skillGetValue(a1, SKILL_STEAL), stealingXp); stealingXp = std::min(300 - skillGetValue(a1, SKILL_STEAL), stealingXp);
debugPrint("\n[[[%d]]]", 300 - skillGetValue(a1, SKILL_STEAL)); debugPrint("\n[[[%d]]]", 300 - skillGetValue(a1, SKILL_STEAL));
// SFALL: Display actual xp received.
int xpGained;
pcAddExperience(stealingXp, &xpGained);
// You gain %d experience points for successfully using your Steal skill. // You gain %d experience points for successfully using your Steal skill.
messageListItem.num = 29; messageListItem.num = 29;
if (messageListGetItem(&gInventoryMessageList, &messageListItem)) { if (messageListGetItem(&gInventoryMessageList, &messageListItem)) {
char formattedText[200]; char formattedText[200];
sprintf(formattedText, messageListItem.text, stealingXp); sprintf(formattedText, messageListItem.text, xpGained);
displayMonitorAddMessage(formattedText); displayMonitorAddMessage(formattedText);
} }
pcAddExperience(stealingXp);
} }
} }
} }

View File

@ -717,14 +717,16 @@ int statRoll(Object* critter, int stat, int modifier, int* howMuch)
} }
// 0x4AFAA8 // 0x4AFAA8
int pcAddExperience(int xp) int pcAddExperience(int xp, int* xpGained)
{ {
return pcAddExperienceWithOptions(xp, true); return pcAddExperienceWithOptions(xp, true, xpGained);
} }
// 0x4AFAB8 // 0x4AFAB8
int pcAddExperienceWithOptions(int xp, bool a2) int pcAddExperienceWithOptions(int xp, bool a2, int* xpGained)
{ {
int oldXp = gPcStatValues[PC_STAT_EXPERIENCE];
int newXp = gPcStatValues[PC_STAT_EXPERIENCE]; int newXp = gPcStatValues[PC_STAT_EXPERIENCE];
newXp += xp; newXp += xp;
newXp += perkGetRank(gDude, PERK_SWIFT_LEARNER) * 5 * xp / 100; newXp += perkGetRank(gDude, PERK_SWIFT_LEARNER) * 5 * xp / 100;
@ -784,6 +786,10 @@ int pcAddExperienceWithOptions(int xp, bool a2)
} }
} }
if (xpGained != NULL) {
*xpGained = newXp - oldXp;
}
return 0; return 0;
} }

View File

@ -35,8 +35,8 @@ char* pcStatGetName(int pcStat);
char* pcStatGetDescription(int pcStat); char* pcStatGetDescription(int pcStat);
int statGetFrmId(int stat); int statGetFrmId(int stat);
int statRoll(Object* critter, int stat, int modifier, int* howMuch); int statRoll(Object* critter, int stat, int modifier, int* howMuch);
int pcAddExperience(int xp); int pcAddExperience(int xp, int* xpGained = NULL);
int pcAddExperienceWithOptions(int xp, bool a2); int pcAddExperienceWithOptions(int xp, bool a2, int* xpGained = NULL);
int pcSetExperience(int a1); int pcSetExperience(int a1);
static inline bool statIsValid(int stat) static inline bool statIsValid(int stat)

View File

@ -3678,21 +3678,21 @@ int _wmRndEncounterOccurred()
int xp = 100 - outdoorsman; int xp = 100 - outdoorsman;
if (xp > 0) { if (xp > 0) {
// SFALL: Display actual xp received.
debugPrint("WorldMap: Giving Player [%d] Experience For Catching Rnd Encounter!", xp);
int xpGained;
pcAddExperience(xp, &xpGained);
MessageListItem messageListItem; MessageListItem messageListItem;
char* text = getmsg(&gMiscMessageList, &messageListItem, 8500); char* text = getmsg(&gMiscMessageList, &messageListItem, 8500);
if (strlen(text) < 110) { if (strlen(text) < 110) {
char formattedText[120]; char formattedText[120];
sprintf(formattedText, text, xp); sprintf(formattedText, text, xpGained);
displayMonitorAddMessage(formattedText); displayMonitorAddMessage(formattedText);
} else { } else {
debugPrint("WorldMap: Error: Rnd Encounter string too long!"); debugPrint("WorldMap: Error: Rnd Encounter string too long!");
} }
debugPrint("WorldMap: Giving Player [%d] Experience For Catching Rnd Encounter!", xp);
if (xp < 100) {
pcAddExperience(xp);
}
} }
} }
} else { } else {