Refactor calculateFenceStandingChangeFromKills()
This commit is contained in:
parent
c45c9185a6
commit
8c3924baab
@ -79,32 +79,38 @@ export class InRaidHelper
|
||||
*/
|
||||
public calculateFenceStandingChangeFromKills(existingFenceStanding: number, victims: Victim[]): number
|
||||
{
|
||||
const botTypes = this.databaseServer.getTables().bots.types;
|
||||
for (const victim of victims)
|
||||
// Run callback on every victim, adding up the standings gained/lossed, starting value is existing fence standing
|
||||
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")
|
||||
{
|
||||
// Scavs and bosses
|
||||
standingForKill = botTypes[victim.Role.toLowerCase()].experience.standingForKill;
|
||||
return botTypes[victim.Role.toLowerCase()]?.experience?.standingForKill;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
// PMCs
|
||||
standingForKill = 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;
|
||||
return botTypes[victim.Side.toLowerCase()]?.experience?.standingForKill;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user