Skip to content

Commit

Permalink
ui: add overhead prayers (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
jayktaylor committed Jan 29, 2024
1 parent d4be16b commit f66079a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 10 deletions.
45 changes: 43 additions & 2 deletions src/enums/Prayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import Chivalry from '@/public/img/prayers/Chivalry.png';
import Piety from '@/public/img/prayers/Piety.png';
import Rigour from '@/public/img/prayers/Rigour.png';
import Augury from '@/public/img/prayers/Augury.png';
import ProtectMagic from '@/public/img/prayers/Protect_from_Magic.png';
import ProtectMelee from '@/public/img/prayers/Protect_from_Melee.png';
import ProtectRanged from '@/public/img/prayers/Protect_from_Missiles.png';
import Redemption from '@/public/img/prayers/Redemption.png';
import Retribution from '@/public/img/prayers/Retribution.png';
import Smite from '@/public/img/prayers/Smite.png';
import { StaticImageData } from 'next/image';
import { Factor } from '@/lib/Math';

Expand All @@ -34,6 +40,12 @@ export enum Prayer {
PIETY,
RIGOUR,
AUGURY,
PROTECT_MAGIC,
PROTECT_RANGED,
PROTECT_MELEE,
RETRIBUTION,
REDEMPTION,
SMITE,
}

export const DEFENSIVE_PRAYERS = [
Expand All @@ -54,11 +66,16 @@ export const ARM_PRAYERS = [
Prayer.BURST_OF_STRENGTH, Prayer.SUPERHUMAN_STRENGTH, Prayer.ULTIMATE_STRENGTH,
];

export type PrayerCombatStyle = 'magic' | 'ranged' | 'melee';
export const OVERHEAD_PRAYERS = [
Prayer.PROTECT_MAGIC, Prayer.PROTECT_RANGED, Prayer.PROTECT_MELEE,
Prayer.RETRIBUTION, Prayer.REDEMPTION, Prayer.SMITE,
];

export type PrayerCombatStyle = 'magic' | 'ranged' | 'melee' | 'overhead';
export interface PrayerData {
name: string,
image: StaticImageData,
combatStyle: PrayerCombatStyle,
combatStyle?: PrayerCombatStyle,
factorAccuracy?: Factor,
factorStrength?: Factor,
}
Expand Down Expand Up @@ -166,4 +183,28 @@ export const PrayerMap: { [k in Prayer]: PrayerData } = {
combatStyle: 'magic',
factorAccuracy: [5, 4],
},
[Prayer.PROTECT_MAGIC]: {
name: 'Protect from Magic',
image: ProtectMagic,
},
[Prayer.PROTECT_MELEE]: {
name: 'Protect from Melee',
image: ProtectMelee,
},
[Prayer.PROTECT_RANGED]: {
name: 'Protect from Missiles',
image: ProtectRanged,
},
[Prayer.RETRIBUTION]: {
name: 'Retribution',
image: Retribution,
},
[Prayer.REDEMPTION]: {
name: 'Redemption',
image: Redemption,
},
[Prayer.SMITE]: {
name: 'Smite',
image: Smite,
},
};
26 changes: 19 additions & 7 deletions src/lib/CombatCalc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {
WeightedHit,
} from '@/lib/HitDist';
import { isBindSpell, isFireSpell, isWaterSpell } from '@/types/Spell';
import { PrayerData, PrayerMap } from '@/enums/Prayer';
import {
OVERHEAD_PRAYERS, Prayer, PrayerData, PrayerMap,
} from '@/enums/Prayer';
import { isVampyre, MonsterAttribute } from '@/enums/MonsterAttribute';
import {
GLOWING_CRYSTAL_IDS,
Expand Down Expand Up @@ -589,7 +591,7 @@ export default class CombatCalc {
const { style } = this.player;

let effectiveLevel: number = this.track(DetailKey.ACCURACY_LEVEL, this.player.skills.atk + this.player.boosts.atk);
for (const p of this.getPrayers(true)) {
for (const p of this.getCombatPrayers(true)) {
effectiveLevel = this.trackFactor(DetailKey.ACCURACY_LEVEL_PRAYER, effectiveLevel, p.factorAccuracy!);
}

Expand Down Expand Up @@ -678,7 +680,7 @@ export default class CombatCalc {
const baseLevel: number = this.trackAdd(DetailKey.DAMAGE_LEVEL, this.player.skills.str, this.player.boosts.str);
let effectiveLevel: number = baseLevel;

for (const p of this.getPrayers(false)) {
for (const p of this.getCombatPrayers(false)) {
effectiveLevel = this.trackFactor(DetailKey.DAMAGE_LEVEL_PRAYER, effectiveLevel, p.factorStrength!);
}

Expand Down Expand Up @@ -793,7 +795,7 @@ export default class CombatCalc {
const { style } = this.player;

let effectiveLevel: number = this.track(DetailKey.ACCURACY_LEVEL, this.player.skills.ranged + this.player.boosts.ranged);
for (const p of this.getPrayers(true)) {
for (const p of this.getCombatPrayers(true)) {
effectiveLevel = this.trackFactor(DetailKey.ACCURACY_LEVEL_PRAYER, effectiveLevel, p.factorAccuracy!);
}

Expand Down Expand Up @@ -852,7 +854,7 @@ export default class CombatCalc {
const { style } = this.player;

let effectiveLevel: number = this.track(DetailKey.DAMAGE_LEVEL, this.player.skills.ranged + this.player.boosts.ranged);
for (const p of this.getPrayers(false)) {
for (const p of this.getCombatPrayers(false)) {
effectiveLevel = this.trackFactor(DetailKey.DAMAGE_LEVEL_PRAYER, effectiveLevel, p.factorStrength!);
}

Expand Down Expand Up @@ -914,7 +916,7 @@ export default class CombatCalc {
const { style } = this.player;

let effectiveLevel: number = this.track(DetailKey.ACCURACY_LEVEL, this.player.skills.magic + this.player.boosts.magic);
for (const p of this.getPrayers(true)) {
for (const p of this.getCombatPrayers(true)) {
effectiveLevel = this.trackFactor(DetailKey.ACCURACY_LEVEL_PRAYER, effectiveLevel, p.factorAccuracy!);
}

Expand Down Expand Up @@ -1073,7 +1075,17 @@ export default class CombatCalc {
return maxHit;
}

private getPrayers(accuracy: boolean): PrayerData[] {
/**
* Get the overhead prayer being used. Only one can be used at a time, so we can just return whichever matches first.
*/
private getOverheadPrayer(): Prayer | null {
return this.player.prayers.find((p) => OVERHEAD_PRAYERS.includes(p)) || null;
}

/**
* Get the "combat" prayers for the current combat style. These are prayers that aren't overheads.
*/
private getCombatPrayers(accuracy: boolean): PrayerData[] {
const style = this.player.style.type;

let prayers = this.player.prayers.map((p) => PrayerMap[p]);
Expand Down
5 changes: 4 additions & 1 deletion src/state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import getMonsters from '@/lib/Monsters';
import { calculateEquipmentBonusesFromGear } from '@/lib/Equipment';
import { EquipmentCategory } from './enums/EquipmentCategory';
import {
ARM_PRAYERS, BRAIN_PRAYERS, DEFENSIVE_PRAYERS, OFFENSIVE_PRAYERS, Prayer,
ARM_PRAYERS, BRAIN_PRAYERS, DEFENSIVE_PRAYERS, OFFENSIVE_PRAYERS, OVERHEAD_PRAYERS, Prayer,
} from './enums/Prayer';
import Potion from './enums/Potion';

Expand Down Expand Up @@ -437,6 +437,9 @@ class GlobalState implements State {
// If this is a defensive prayer, disable all other defensive prayers
if (DEFENSIVE_PRAYERS.includes(prayer)) newPrayers = newPrayers.filter((p) => !DEFENSIVE_PRAYERS.includes(p));

// If this is an overhead prayer, disable all other defensive prayers
if (OVERHEAD_PRAYERS.includes(prayer)) newPrayers = newPrayers.filter((p) => !OVERHEAD_PRAYERS.includes(p));

// If this is an offensive prayer...
if (OFFENSIVE_PRAYERS.includes(prayer)) {
newPrayers = newPrayers.filter((p) => {
Expand Down

0 comments on commit f66079a

Please sign in to comment.