Refactor calculateFenceStandingChangeFromKills()

This commit is contained in:
Dev 2023-04-22 16:41:00 +01:00
parent c45c9185a6
commit 8c3924baab

View File

@ -79,32 +79,38 @@ export class InRaidHelper
*/ */
public calculateFenceStandingChangeFromKills(existingFenceStanding: number, victims: Victim[]): number public calculateFenceStandingChangeFromKills(existingFenceStanding: number, victims: Victim[]): number
{ {
const botTypes = this.databaseServer.getTables().bots.types; // Run callback on every victim, adding up the standings gained/lossed, starting value is existing fence standing
for (const victim of victims) const newFenceStanding = victims.reduce((acc, victim) =>
{ {
let standingForKill = null; const standingForKill = this.getStandingChangeForKill(victim);
if (standingForKill)
{
return acc + standingForKill;
}
this.logger.warning(this.localisationService.getText("inraid-missing_standing_for_kill", {victimSide: victim.Side, victimRole: victim.Role}));
return acc;
}, existingFenceStanding);
return newFenceStanding;
}
/**
* Get the standing gain/loss for killing an npc
* @param victim Who was killed by player
* @returns a numerical standing gain or loss
*/
protected getStandingChangeForKill(victim: Victim): number
{
const botTypes = this.databaseServer.getTables().bots.types;
if (victim.Side.toLowerCase() === "savage") if (victim.Side.toLowerCase() === "savage")
{ {
// Scavs and bosses // Scavs and bosses
standingForKill = botTypes[victim.Role.toLowerCase()].experience.standingForKill; return botTypes[victim.Role.toLowerCase()]?.experience?.standingForKill;
} }
else
{
// PMCs // PMCs
standingForKill = botTypes[victim.Side.toLowerCase()].experience.standingForKill; return botTypes[victim.Side.toLowerCase()]?.experience?.standingForKill;
}
if (standingForKill)
{
existingFenceStanding += standingForKill;
}
else
{
this.logger.warning(this.localisationService.getText("inraid-missing_standing_for_kill", {victimSide: victim.Side, victimRole: victim.Role}));
}
}
return existingFenceStanding;
} }
/** /**