-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStronghold.js
More file actions
103 lines (85 loc) · 2.77 KB
/
Copy pathStronghold.js
File metadata and controls
103 lines (85 loc) · 2.77 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* Stronghold Module - World of Agents Phase 3
* Main base structures - destroy to win
*/
const STRONGHOLD_HP = 1000;
const STRONGHOLD_REGEN = 5; // HP per tick when not under attack
const STRONGHOLD_REGEN_DELAY = 10; // ticks without damage before regen starts
export function createStronghold(faction) {
return {
faction,
hp: STRONGHOLD_HP,
maxHp: STRONGHOLD_HP,
alive: true,
lastDamageTick: -999,
underAttack: false,
};
}
export function createStrongholds() {
return {
alliance: createStronghold("alliance"),
horde: createStronghold("horde"),
};
}
export function isStrongholdAlive(stronghold) {
return stronghold.alive && stronghold.hp > 0;
}
export function damageStronghold(stronghold, amount, currentTick) {
if (!stronghold.alive) return 0;
const actualDamage = Math.min(stronghold.hp, amount);
stronghold.hp -= actualDamage;
stronghold.lastDamageTick = currentTick;
stronghold.underAttack = true;
if (stronghold.hp <= 0) {
stronghold.hp = 0;
stronghold.alive = false;
}
return actualDamage;
}
export function regenStronghold(stronghold, currentTick) {
if (!stronghold.alive) return 0;
if (stronghold.hp >= stronghold.maxHp) return 0;
// Check if enough time has passed since last damage
const ticksSinceDamage = currentTick - stronghold.lastDamageTick;
if (ticksSinceDamage >= STRONGHOLD_REGEN_DELAY) {
stronghold.underAttack = false;
const regenAmount = Math.min(STRONGHOLD_REGEN, stronghold.maxHp - stronghold.hp);
stronghold.hp += regenAmount;
return regenAmount;
}
return 0;
}
export function canAttackStronghold(towers, faction, lane) {
// Can only attack stronghold if all towers in at least one lane are destroyed
const enemyFaction = faction === "alliance" ? "horde" : "alliance";
// Check if both towers in this lane are destroyed
const laneTowers = towers[lane][enemyFaction];
return laneTowers.every(tower => !tower.alive);
}
export function getStrongholdStatus(stronghold) {
const hpPercent = Math.round((stronghold.hp / stronghold.maxHp) * 100);
let condition;
if (hpPercent > 75) condition = "Fortified";
else if (hpPercent > 50) condition = "Damaged";
else if (hpPercent > 25) condition = "Critical";
else if (hpPercent > 0) condition = "Falling";
else condition = "Destroyed";
return {
faction: stronghold.faction,
hp: stronghold.hp,
maxHp: stronghold.maxHp,
hpPercent,
alive: stronghold.alive,
underAttack: stronghold.underAttack,
condition,
};
}
export function checkVictory(strongholds) {
if (!isStrongholdAlive(strongholds.alliance)) {
return { winner: "horde", loser: "alliance" };
}
if (!isStrongholdAlive(strongholds.horde)) {
return { winner: "alliance", loser: "horde" };
}
return null;
}