-
Notifications
You must be signed in to change notification settings - Fork 21
/
PonyDetection.ts
90 lines (81 loc) · 2.8 KB
/
PonyDetection.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { CollectibleType, EntityFlag } from "isaac-typescript-definitions";
import { Exported } from "../../../decorators";
import { ModCallbackCustom } from "../../../enums/ModCallbackCustom";
import { hasFlag } from "../../../functions/flag";
import {
setAddPlayer,
setDeletePlayer,
setHasPlayer,
} from "../../../functions/playerDataStructures";
import { getPlayers } from "../../../functions/playerIndex";
import type { PlayerIndex } from "../../../types/PlayerIndex";
import { Feature } from "../../private/Feature";
const FLAGS_WHEN_PONY_IS_ACTIVE = [
EntityFlag.NO_KNOCKBACK, // 1 << 26
EntityFlag.NO_PHYSICS_KNOCKBACK, // 1 << 30
EntityFlag.NO_DAMAGE_BLINK, // 1 << 36
] as const;
const v = {
run: {
playersIsPonyActive: new Set<PlayerIndex>(),
},
};
export class PonyDetection extends Feature {
/** @internal */
public override v = v;
/** @internal */
constructor() {
super();
this.customCallbacksUsed = [
[
ModCallbackCustom.POST_PEFFECT_UPDATE_REORDERED,
this.postPEffectUpdateReordered,
],
];
}
// ModCallbackCustom.POST_PEFFECT_UPDATE_REORDERED
private readonly postPEffectUpdateReordered = (player: EntityPlayer) => {
const effects = player.GetEffects();
const entityFlags = player.GetEntityFlags();
const hasPonyCollectibleEffect =
effects.HasCollectibleEffect(CollectibleType.PONY) ||
effects.HasCollectibleEffect(CollectibleType.WHITE_PONY);
const isPonyActiveOnPreviousFrame = setHasPlayer(
v.run.playersIsPonyActive,
player,
);
const hasPonyFlags = hasFlag(entityFlags, ...FLAGS_WHEN_PONY_IS_ACTIVE);
const isPonyActiveNow =
hasPonyCollectibleEffect || (isPonyActiveOnPreviousFrame && hasPonyFlags);
if (isPonyActiveNow) {
setAddPlayer(v.run.playersIsPonyActive, player);
} else {
setDeletePlayer(v.run.playersIsPonyActive, player);
}
};
/**
* Helper function to see if the player is under the effects of A Pony or White Pony charge.
* Detecting this is difficult, as the temporary effect will disappear upon entering a new room.
*
* In order to use this function, you must upgrade your mod with `ISCFeature.PONY_DETECTION`.
*
* @public
*/
@Exported
public isPlayerUsingPony(player: EntityPlayer): boolean {
return setHasPlayer(v.run.playersIsPonyActive, player);
}
/**
* Helper function to see if any player is under the effects of A Pony or White Pony charge.
* Detecting this is difficult, as the temporary effect will disappear upon entering a new room.
*
* In order to use this function, you must upgrade your mod with `ISCFeature.PONY_DETECTION`.
*
* @public
*/
@Exported
public anyPlayerUsingPony(): boolean {
const players = getPlayers();
return players.some((player) => this.isPlayerUsingPony(player));
}
}