-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevents.js
More file actions
99 lines (93 loc) · 3.89 KB
/
events.js
File metadata and controls
99 lines (93 loc) · 3.89 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
// events.js - Contains all event definitions for the simulation
// Event pool array to store all events
const events = [
//Event 1: Master Death
{
id: "event_kill_master",
description: "{master.name} walks into a landmine and dies.",
valid: (participants) => {
return participants.filter(p => p.type === "master" && p.status === "alive");
},
effects: (master, servant, participants) => {
master.status = "dead";
const linkedServant = participants.find(p => p.type === "servant" && p.masterId === master.id);
if (linkedServant && !linkedServant.hasIndependentAction) {
linkedServant.status = "dead";
}
}
},
{
id: "event_duel",
description: "{servant1.name} fights with {servant2.name} to the death.",
valid: (participants) => {
const aliveServants = participants.filter(p => p.type === "servant" && p.status === "alive");
if (aliveServants.length < 2) return [];
// Generate all possible pairs
const pairs = [];
for (let i = 0; i < aliveServants.length; i++) {
for (let j = i + 1; j < aliveServants.length; j++) {
pairs.push([aliveServants[i], aliveServants[j]]);
}
}
return pairs;
},
effects: (servant1, servant2, participants) => {
const loser = Math.random() < 0.5 ? servant1 : servant2;
loser.status = "dead";
}
},
{
id: "event_betrayal",
description: "{servant1.name} betrays {master.name}. The master is left defenseless and killed.",
valid: (participants) => {
const betrayers = [];
const aliveServants = participants.filter(p => p.type === "servant" && p.status === "alive");
aliveServants.forEach(servant => {
const master = participants.find(p => p.id === servant.masterId && p.status === "alive");
if (master) {
betrayers.push([servant, master]);
}
});
return betrayers;
},
effects: (servant1, master, participants) => {
master.status = "dead";
// Servant survives (no change)
}
},
{
id: "poison_mushroom",
description: "{master.name} eats a poisonous mushroom!",
valid: (participants) => participants.filter(p => p.type === "master" && p.status === "alive"),
effects: (master, servant, participants) => {
// no persistent state; just logs the event
}
},
{
id: "poison_death",
description: "{master.name} succumbs to the poison and dies.",
followUpFor: ["poison_mushroom"],
valid: (participants, pastEvents) =>
pastEvents.includes("poison_mushroom") &&
participants.filter(p => p.type === "master" && p.status === "alive"),
effects: (master, servant, participants) => {
master.status = "dead";
if (servant && !servant.hasIndependentAction) {
servant.status = "dead";
}
}
},
{
id: "poison_heal",
description: "{master.name} miraculously recovers from the poison!",
followUpFor: ["poison_mushroom"],
valid: (participants, pastEvents) =>
pastEvents.includes("poison_mushroom") &&
participants.filter(p => p.type === "master" && p.status === "alive"),
effects: (master, servant, participants) => {
// healed, no death
}
},
];
// Export the eventPool so it can be used in other files
export { events };