Skip to content

Commit

Permalink
prayer drain impl
Browse files Browse the repository at this point in the history
  • Loading branch information
LlemonDuck authored and jayktaylor committed Jul 3, 2024
1 parent cbea983 commit 5c4c62c
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/enums/Prayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export type PrayerCombatStyle = 'magic' | 'ranged' | 'melee';
export interface PrayerData {
name: string,
image: StaticImageData,
drainRate: number;
combatStyle?: PrayerCombatStyle,
magicDamageBonus?: number,
factorAccuracy?: Factor,
Expand All @@ -97,51 +98,59 @@ export const PrayerMap: { [k in Prayer]: PrayerData } = {
[Prayer.BURST_OF_STRENGTH]: {
name: 'Burst of Strength',
image: BurstOfStrength,
drainRate: 1,
combatStyle: 'melee',
factorStrength: [21, 20],
},
[Prayer.CLARITY_OF_THOUGHT]: {
name: 'Clarity of Thought',
image: ClarityOfThought,
drainRate: 1,
combatStyle: 'melee',
factorAccuracy: [21, 20],
},
[Prayer.SHARP_EYE]: {
name: 'Sharp Eye',
image: SharpEye,
drainRate: 1,
combatStyle: 'ranged',
factorAccuracy: [21, 20],
factorStrength: [21, 20],
},
[Prayer.MYSTIC_WILL]: {
name: 'Mystic Will',
image: MysticWill,
drainRate: 1,
combatStyle: 'magic',
factorAccuracy: [21, 20],
factorDefenceMagic: [21, 20],
},
[Prayer.SUPERHUMAN_STRENGTH]: {
name: 'Superhuman Strength',
image: SuperhumanStrength,
drainRate: 6,
combatStyle: 'melee',
factorStrength: [11, 10],
},
[Prayer.IMPROVED_REFLEXES]: {
name: 'Improved Reflexes',
image: ImprovedReflexes,
drainRate: 6,
combatStyle: 'melee',
factorAccuracy: [11, 10],
},
[Prayer.HAWK_EYE]: {
name: 'Hawk Eye',
image: HawkEye,
drainRate: 6,
combatStyle: 'ranged',
factorAccuracy: [11, 10],
factorStrength: [11, 10],
},
[Prayer.MYSTIC_LORE]: {
name: 'Mystic Lore',
image: MysticLore,
drainRate: 6,
combatStyle: 'magic',
magicDamageBonus: 10,
factorAccuracy: [11, 10],
Expand All @@ -150,25 +159,29 @@ export const PrayerMap: { [k in Prayer]: PrayerData } = {
[Prayer.ULTIMATE_STRENGTH]: {
name: 'Ultimate Strength',
image: UltimateStrength,
drainRate: 12,
combatStyle: 'melee',
factorStrength: [23, 20],
},
[Prayer.INCREDIBLE_REFLEXES]: {
name: 'Incredible Reflexes',
image: IncredibleReflexes,
drainRate: 12,
combatStyle: 'melee',
factorAccuracy: [23, 20],
},
[Prayer.EAGLE_EYE]: {
name: 'Eagle Eye',
image: EagleEye,
drainRate: 12,
combatStyle: 'ranged',
factorAccuracy: [23, 20],
factorStrength: [23, 20],
},
[Prayer.MYSTIC_MIGHT]: {
name: 'Mystic Might',
image: MysticMight,
drainRate: 12,
combatStyle: 'magic',
magicDamageBonus: 20,
factorAccuracy: [23, 20],
Expand All @@ -177,6 +190,7 @@ export const PrayerMap: { [k in Prayer]: PrayerData } = {
[Prayer.CHIVALRY]: {
name: 'Chivalry',
image: Chivalry,
drainRate: 24,
combatStyle: 'melee',
factorAccuracy: [23, 20],
factorStrength: [118, 100],
Expand All @@ -185,6 +199,7 @@ export const PrayerMap: { [k in Prayer]: PrayerData } = {
[Prayer.PIETY]: {
name: 'Piety',
image: Piety,
drainRate: 24,
combatStyle: 'melee',
factorAccuracy: [6, 5],
factorStrength: [123, 100],
Expand All @@ -193,6 +208,7 @@ export const PrayerMap: { [k in Prayer]: PrayerData } = {
[Prayer.RIGOUR]: {
name: 'Rigour',
image: Rigour,
drainRate: 24,
combatStyle: 'ranged',
factorAccuracy: [6, 5],
factorStrength: [123, 100],
Expand All @@ -201,6 +217,7 @@ export const PrayerMap: { [k in Prayer]: PrayerData } = {
[Prayer.AUGURY]: {
name: 'Augury',
image: Augury,
drainRate: 24,
combatStyle: 'magic',
magicDamageBonus: 40,
factorAccuracy: [5, 4],
Expand All @@ -210,40 +227,49 @@ export const PrayerMap: { [k in Prayer]: PrayerData } = {
[Prayer.THICK_SKIN]: {
name: 'Thick Skin',
image: ThickSkin,
drainRate: 1,
factorDefence: [21, 20],
},
[Prayer.ROCK_SKIN]: {
name: 'Rock Skin',
image: RockSkin,
drainRate: 6,
factorDefence: [11, 10],
},
[Prayer.STEEL_SKIN]: {
name: 'Steel Skin',
image: SteelSkin,
drainRate: 12,
factorDefence: [23, 20],
},
// [Prayer.PROTECT_MAGIC]: {
// name: 'Protect from Magic',
// image: ProtectMagic,
// drainRate: 12,
// },
// [Prayer.PROTECT_MELEE]: {
// name: 'Protect from Melee',
// image: ProtectMelee,
// drainRate: 12,
// },
// [Prayer.PROTECT_RANGED]: {
// name: 'Protect from Missiles',
// image: ProtectRanged,
// drainRate: 12,
// },
// [Prayer.RETRIBUTION]: {
// name: 'Retribution',
// image: Retribution,
// drainRate: 3,
// },
// [Prayer.REDEMPTION]: {
// name: 'Redemption',
// image: Redemption,
// drainRate: 6,
// },
// [Prayer.SMITE]: {
// name: 'Smite',
// image: Smite,
// drainRate: 18,
// },
};
26 changes: 25 additions & 1 deletion src/lib/PlayerVsNPCCalc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { AmmoApplicability, ammoApplicability } from '@/lib/Equipment';
import BaseCalc, { CalcOpts, InternalOpts } from '@/lib/BaseCalc';
import { scaleMonsterHpOnly } from '@/lib/MonsterScaling';
import { getRangedDamageType } from '@/types/PlayerCombatStyle';
import { range } from 'd3-array';
import { range, sum } from 'd3-array';

/**
* Class for computing various player-vs-NPC metrics.
Expand Down Expand Up @@ -1225,6 +1225,30 @@ export default class PlayerVsNPCCalc extends BaseCalc {
return this.getDpt() / SECONDS_PER_TICK;
}

/**
* Returns the amount of time (in ticks) that the user can maintain their prayers before running out of prayer points.
* Does not account for flicking or toggling prayers.
*/
public getPrayerTicks(): number {
const drain = sum(this.player.prayers, (p) => PrayerMap[p].drainRate);
if (drain === 0) {
return Infinity;
}

const drainResistance = 2 * this.player.bonuses.prayer + 60;
const totalPrayerUnits = this.player.skills.prayer * drainResistance;

return Math.ceil(totalPrayerUnits / drain);
}

/**
* Returns the amount of time (in seconds) that the user can maintain their prayers before running out of prayer points.
* Does not account for flicking or toggling prayers.
*/
public getPrayerDuration(): number {
return this.getPrayerTicks() * SECONDS_PER_TICK;
}

/**
* Returns the average hits-to-kill calculation.
*/
Expand Down
70 changes: 70 additions & 0 deletions src/tests/lib/PrayerDrain.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { describe, expect, test } from '@jest/globals';
import PlayerVsNPCCalc from '@/lib/PlayerVsNPCCalc';
import { getTestMonster, getTestPlayer } from '@/tests/utils/TestUtils';
import { Prayer } from '@/enums/Prayer';

describe('getPrayerTicks', () => {
test('no prayers lasts forever', () => {
const m = getTestMonster('Abyssal demon', 'Standard');
const p = getTestPlayer(m, {
bonuses: {
prayer: 0,
},
prayers: [],
});
const calc = new PlayerVsNPCCalc(p, m);

expect(calc.getPrayerTicks()).toBe(Infinity);
expect(calc.getPrayerDuration()).toBe(Infinity);
});

test('0 prayer bonus 99 prayer piety', () => {
const m = getTestMonster('Abyssal demon', 'Standard');
const p = getTestPlayer(m, {
bonuses: {
prayer: 0,
},
prayers: [
Prayer.PIETY,
],
});
const calc = new PlayerVsNPCCalc(p, m);

expect(calc.getPrayerTicks()).toBe(248);
expect(calc.getPrayerDuration()).toBeCloseTo(148.8);
});

test('30 prayer 99 prayer bonus piety', () => {
const m = getTestMonster('Abyssal demon', 'Standard');
const p = getTestPlayer(m, {
bonuses: {
prayer: 30,
},
prayers: [
Prayer.PIETY,
],
});
const calc = new PlayerVsNPCCalc(p, m);

expect(calc.getPrayerTicks()).toBe(495);
expect(calc.getPrayerDuration()).toBeCloseTo(297);
});

test('15 prayer bonus 99 prayer steel skin and superhuman strength and improved reflexes', () => {
const m = getTestMonster('Abyssal demon', 'Standard');
const p = getTestPlayer(m, {
bonuses: {
prayer: 15,
},
prayers: [
Prayer.STEEL_SKIN,
Prayer.SUPERHUMAN_STRENGTH,
Prayer.IMPROVED_REFLEXES,
],
});
const calc = new PlayerVsNPCCalc(p, m);

expect(calc.getPrayerTicks()).toBe(372);
expect(calc.getPrayerDuration()).toBeCloseTo(223.2);
});
});

0 comments on commit 5c4c62c

Please sign in to comment.