Skip to content

Commit

Permalink
Merge pull request #149 from Makar8000/nin-sim
Browse files Browse the repository at this point in the history
Ninja Sim
  • Loading branch information
xpdota authored Jun 27, 2024
2 parents 6692823 + 2a94bd6 commit 743cbbc
Show file tree
Hide file tree
Showing 11 changed files with 1,295 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ You can try it out [here](https://xivgear.app).
## Help Wanted

We are still looking for people to write simulations for the following jobs:
- All melee classes except RPR
- All melee classes except RPR and NIN
- All tank classes except PLD
- All casters
- All physical ranged
- All physical ranged except DNC

## User Guides

Expand Down
9 changes: 4 additions & 5 deletions packages/core/src/sims/buffs.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {Ability, PartyBuff} from "./sim_types";


export const Mug = {
name: "Mug",
export const Dokumori = {
name: "Dokumori",
saveKey: "Mug",
job: "NIN",
duration: 20,
Expand All @@ -12,7 +11,7 @@ export const Mug = {
dmgIncrease: 0.05,
},
startTime: 3.5,
statusId: 3183
statusId: 3849
} as const satisfies PartyBuff;

export const Litany = {
Expand Down Expand Up @@ -260,7 +259,7 @@ export const OffGuardBuff = {
*/

export const ALL_BUFFS = [
Mug, Litany, DragonSight, Brotherhood, ArcaneCircle, SearingLight, Embolden,
Dokumori, Litany, DragonSight, Brotherhood, ArcaneCircle, SearingLight, Embolden,
Devilment, TechnicalFinish, BattleVoice, RadiantFinale, Chain, Divination,
AstCard, OffGuardBuff
] as const;
Expand Down
98 changes: 85 additions & 13 deletions packages/core/src/sims/cycle_sim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,11 @@ export type MultiCycleSettings = {
/**
* Whether to use auto-attacks.
*/
readonly useAutos: boolean
readonly useAutos: boolean,
/**
* Whether to hide dividers indicating the start and end of a cycle
*/
readonly hideCycleDividers?: boolean
}

export type CycleFunction = (cycle: CycleContext) => void
Expand Down Expand Up @@ -391,6 +395,10 @@ export class CycleProcessor {
* Whether auto-attacks are enabled
*/
readonly useAutos: boolean;
/**
* Whether to show dividers indicating the start and end of a cycle
*/
readonly hideCycleDividers: boolean
/**
* Cooldown tracker.
*/
Expand All @@ -417,6 +425,7 @@ export class CycleProcessor {
this.stats = settings.stats;
this.manuallyActivatedBuffs = settings.manuallyActivatedBuffs ?? [];
this.useAutos = settings.useAutos;
this.hideCycleDividers = settings.hideCycleDividers;
this.comboTrackerMap = new Map();
this.aaAbility = {
attackType: 'Auto-attack',
Expand Down Expand Up @@ -475,15 +484,33 @@ export class CycleProcessor {
* @param buff The buff to cancel
*/
removeBuff(buff: Buff) {
const activeUsages = this.getActiveBuffsData().filter(buffHist => {
return buffHist.buff === buff;
});
const activeUsages = this.getActiveBuffsData().filter(buffHist => buffHist.buff.name === buff.name);
activeUsages.forEach(au => {
au.end = this.currentTime;
au.forceEnd = true;
});
}

/**
* Modifies the stack value for a given buff. The stack value provided should be the modified amount and not the final amount
*
* @param buff The Buff
* @param stacks The stack modification to add
*/
modifyBuffStacks(buff: Buff, stacksDelta: number) {
const activeUsages = this.getActiveBuffsData().filter(buffHist => buffHist.buff.name === buff.name);
this.removeBuff(buff);
activeUsages.forEach(au => {
const newStacks = au.buff.stacks + stacksDelta;
if (newStacks > 0) {
this.activateBuff({
...au.buff,
stacks: au.buff.stacks + stacksDelta,
});
}
});
}

/**
* Whether a buff is an automatically-activated party buff.
*
Expand Down Expand Up @@ -590,6 +617,17 @@ export class CycleProcessor {
return this.buffHistory.filter(h => h.start <= queryTime && h.end > queryTime && !h.forceEnd);
}

/**
* Get the buff data for an active buff.
*
* @param buff The buff
* @returns BuffUsage for the buff, or null if this buff is not active
*/
protected getActiveBuffData(buff: Buff): BuffUsage {
const activeBuffData = this.getActiveBuffsData().find(bd => bd.buff === buff);
return activeBuffData ? {...activeBuffData} : null;
}

/**
* Add a special text row to the output records.
*
Expand Down Expand Up @@ -800,6 +838,18 @@ export class CycleProcessor {
}
}

/**
* Determines whether or not an Off-GCD ability can be used without clipping the GCD
*
* @param action The Off-GCD ability to check for
* @returns whether or not this ability can be used without clipping the GCD
*/
canUseWithoutClipping(action: OgcdAbility) {
const readyAt = this.cdTracker.statusOf(action).readyAt.absolute;
const maxDelayAt = this.nextGcdTime - (action.animationLock ?? STANDARD_ANIMATION_LOCK);
return readyAt <= Math.min(maxDelayAt, this.totalTime);
}

/**
* Fast-forward (i.e. do nothing until) the given time.
*
Expand Down Expand Up @@ -1081,10 +1131,12 @@ export class CycleProcessor {
const ctx = new CycleContext(this, cycleTime);
// console.debug('Delta', delta);
// TODO: make some kind of 'marker' for this
this.allRecords.push({
label: "-- Start of Cycle --",
usedAt: this.currentTime,
});
if (!this.hideCycleDividers) {
this.allRecords.push({
label: "-- Start of Cycle --",
usedAt: this.currentTime,
});
}
const cycleInfo: CycleInfo = {
cycleNum: this.currentCycle,
start: this.currentTime,
Expand All @@ -1093,10 +1145,12 @@ export class CycleProcessor {
this.cycles.push(cycleInfo);
cycleFunction(ctx);
ctx.recheckPrepull();
this.allRecords.push({
label: "-- End of Cycle --",
usedAt: this.currentTime,
});
if (!this.hideCycleDividers) {
this.allRecords.push({
label: "-- End of Cycle --",
usedAt: this.currentTime,
});
}
cycleInfo.end = this.currentTime;
this.currentCycle++;
}
Expand Down Expand Up @@ -1135,7 +1189,25 @@ export class CycleProcessor {
},
removeSelf(): void {
this.removeStatus(buff);
}
},
modifyStacks(buff: Buff, stacksDelta: number): void {
outer.modifyBuffStacks(buff, stacksDelta);
},
modifyStacksSelf(stacksDelta: number): void {
this.modifyStacks(buff, stacksDelta);
},
addStacks(buff: Buff, stacks: number): void {
this.modifyStacks(buff, stacks);
},
addStacksSelf(stacks: number): void {
this.modifyStacks(buff, stacks);
},
subtractStacks(buff: Buff, stacks: number): void {
this.modifyStacks(buff, stacks * -1);
},
subtractStacksSelf(stacks: number): void {
this.modifyStacks(buff, stacks * -1);
},
}
}

Expand Down
12 changes: 12 additions & 0 deletions packages/core/src/sims/sim_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,18 @@ export type BuffEffects = {
export type BuffController = {
removeStatus(buff: Buff): void;
removeSelf(): void;
/** Modify the number of stacks of a `buff` by `stacksDelta` amount. e.g. -1 = remove 1 stack. */
modifyStacks(buff: Buff, stacksDelta: number): void;
/** Modify the number of stacks of this buff by `stacksDelta` amount. e.g. -1 = remove 1 stack. */
modifyStacksSelf(stacksDelta: number): void;
/** Increase the number of stacks of a `buff` by `stacks` amount.*/
addStacks(buff: Buff, stacks: number): void;
/** Increase the number of stacks of this buff by `stacks` amount.*/
addStacksSelf(stacks: number): void;
/** Decrease the number of stacks of a `buff` by `stacks` amount.*/
subtractStacks(buff: Buff, stacks: number): void;
/** Decrease the number of stacks of this buff by `stacks` amount.*/
subtractStacksSelf(stacks: number): void;
};

export type BaseBuff = Readonly<{
Expand Down
2 changes: 2 additions & 0 deletions packages/frontend/src/scripts/sims/default_sims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {astNewSheetSpec} from "./healer/ast_sheet_sim";
import {schNewSheetSpec} from "./healer/sch_sheet_sim";
import {whmNewSheetSpec} from "./healer/whm_new_sheet_sim";
import {rprSheetSpec} from "./melee/rpr_sheet_sim";
import {ninSpec} from "./melee/nin/nin_lv100_sim";
import {potRatioSimSpec} from "./common/potency_ratio";
import {BluWinged120Spec} from "./blu/blu_winged120";
import {BluFlame120Spec} from "./blu/blu_flame120";
Expand All @@ -24,6 +25,7 @@ export function registerDefaultSims() {
registerSim(schNewSheetSpec);
registerSim(whmNewSheetSpec);
registerSim(rprSheetSpec);
registerSim(ninSpec);
registerSim(BluWinged120Spec);
registerSim(BluFlame120Spec);
registerSim(BluBreath60Spec);
Expand Down
Loading

0 comments on commit 743cbbc

Please sign in to comment.