Skip to content

Commit

Permalink
Pending changes exported from your codespace
Browse files Browse the repository at this point in the history
  • Loading branch information
SawJester committed Nov 2, 2024
1 parent 11012ad commit 7a5994b
Show file tree
Hide file tree
Showing 16 changed files with 237 additions and 36 deletions.
17 changes: 13 additions & 4 deletions Games/core/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@ const shortid = require("shortid");
const Utils = require("./Utils");

module.exports = class Event {
constructor(name, game) {
constructor(name, modifiers, game) {
this.game = game;
this.id = shortid.generate();
this.fullName = name;
this.name = name.event.split(":")[0];
this.modifiers = name.split(":")[1].split("/");
this.fullName = `${name}:${modifiers}`;
this.name = name;
this.modifiers = modifiers;
//this.game.queueAlert(`Core ${modifiers}`);
/*
if(this.modifiers <= 0){
this.modifiers = [];
}
else{
this.modifiers = this.modifiers.split("/");
}
*/
this.actions = [];
}

Expand Down
12 changes: 9 additions & 3 deletions Games/core/Game.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Player = require("./Player");
const Player = require("./Event");
const Event = require("./Event");
const Spectator = require("./Spectator");
const Message = require("./Message");
const History = require("./History");
Expand Down Expand Up @@ -1239,12 +1239,18 @@ module.exports = class Game {
return roleData[this.type][role.split(":")[0]].tags;
}

checkEvent(event) {
let temp = new Event(event, this);
checkEvent(eventName,eventMod) {
let temp = this.createGameEvent(eventName,eventMod);
let valid = temp.getRequirements();
return valid;
}

createGameEvent(eventName, eventMods){
const eventClass = Utils.importGameClass(this.type, "Events", eventName);
const event = new eventClass(eventMods,this);
return event;
}

recordRole(player, appearance) {
for (let _player of this.players)
_player.history.recordRole(player, appearance);
Expand Down
25 changes: 15 additions & 10 deletions Games/types/Mafia/Event.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,53 @@
const Event = require("../../core/Event");

module.exports = class MafiaEvent extends Event {
constructor(name, game, data) {
super(name, game, data);
constructor(name, modifiers, game, data) {
super(name, modifiers, game, data);
//this.game.queueAlert(`Mafia ${modifiers}`);
}

getModifierRequirements() {
if(this.modifiers == null) return true;
//this.game.queueAlert("Checks Null");
if (
this.game.getStateInfo().dayCount % 2 == 0 &&
this.game.dayCount % 2 == 0 &&
this.modifiers.includes("Odd")
) {
return false;
}
//this.game.queueAlert(`${this.modifiers} ${this.modifiers.includes("Odd")}`);
if (
this.game.getStateInfo().dayCount % 1 == 0 &&
this.game.dayCount % 2 == 1 &&
this.modifiers.includes("Even")
) {
return false;
}
if (
this.game.getStateInfo().dayCount == 1 &&
this.game.dayCount == 1 &&
this.modifiers.includes("Delayed")
) {
return false;
}
return true;
}

doEvent() {
if(this.modifiers != null){
if (
this.modifiers.includes("One Shot") &&
!this.modifiers.includes("Banished")
) {
this.game.PossibleEvents.slice(
this.game.PossibleEvents.indexOf(this.fullName),
1
);
this.game.PossibleEvents.splice(this.game.PossibleEvents.indexOf(this.fullName),1);
} else if (
this.modifiers.includes("One Shot") &&
this.modifiers.includes("Banished")
) {
this.game.PossibleEvents.slice(
this.game.BanishedEvents.splice(
this.game.BanishedEvents.indexOf(this.fullName),
1
);
}
}

}
};
8 changes: 6 additions & 2 deletions Games/types/Mafia/Events/Brainblast.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
const Event = require("../Event");
const Action = require("../Action");
const Random = require("../../../../lib/Random");
const {
PRIORITY_ITEM_GIVER_DEFAULT,
PRIORITY_BECOME_DEAD_ROLE,
} = require("../const/Priority");

module.exports = class Brainblast extends Event {
constructor(name, game, data) {
super("Brainblast", game);
constructor(modifiers, game) {
super("Brainblast", modifiers, game);
}

getNormalRequirements() {
Expand Down
35 changes: 35 additions & 0 deletions Games/types/Mafia/Events/CaveIn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const Event = require("../Event");
const Action = require("../Action");
const Random = require("../../../../lib/Random");
const {
PRIORITY_ITEM_GIVER_DEFAULT,
PRIORITY_BECOME_DEAD_ROLE,
} = require("../const/Priority");

module.exports = class Brainblast extends Event {
constructor(modifiers, game) {
super("Brainblast", modifiers, game);
}

getNormalRequirements() {
return true;
}

doEvent() {
super.doEvent();
let victim = Random.randArrayVal(this.game.alivePlayers());
this.action = new Action({
actor: victim,
target: victim,
game: this.game,
priority: PRIORITY_ITEM_GIVER_DEFAULT,
labels: ["hidden", "absolute"],
run: function () {
for (const player of this.game.players) {
player.holdItem("CaveIn");
}
},
});
this.game.queueAction(this.action);
}
};
9 changes: 7 additions & 2 deletions Games/types/Mafia/Events/Evolution.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
const Event = require("../Event");
const Action = require("../Action");
const Random = require("../../../../lib/Random");
const roles = require("../../../../data/roles");
const {
PRIORITY_ITEM_GIVER_DEFAULT,
PRIORITY_BECOME_DEAD_ROLE,
} = require("../const/Priority");

module.exports = class Evolution extends Event {
constructor(name, game, data) {
super("Evolution", game);
constructor(modifiers, game) {
super("Evolution", modifiers, game);
}

getNormalRequirements() {
Expand Down
9 changes: 7 additions & 2 deletions Games/types/Mafia/Events/MissingSupplies.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
const Event = require("../Event");
const Action = require("../Action");
const Random = require("../../../../lib/Random");
const {
PRIORITY_ITEM_GIVER_DEFAULT,
PRIORITY_BECOME_DEAD_ROLE,
} = require("../const/Priority");

module.exports = class MissingSupplies extends Event {
constructor(name, game, data) {
super("MissingSupplies", game);
constructor(modifiers, game) {
super("Missing Supplies", modifiers, game);
//this.game.queueAlert(`Supplies ${modifiers}`);
}

getNormalRequirements() {
Expand Down
23 changes: 23 additions & 0 deletions Games/types/Mafia/Events/NoEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const Event = require("../Event");
const Action = require("../Action");
const Random = require("../../../../lib/Random");
const {
PRIORITY_ITEM_GIVER_DEFAULT,
PRIORITY_BECOME_DEAD_ROLE,
} = require("../const/Priority");

module.exports = class MissingSupplies extends Event {
constructor(modifiers, game) {
super("No Event", modifiers, game);

}

getNormalRequirements() {
return true;
}

doEvent() {
super.doEvent();

}
};
14 changes: 10 additions & 4 deletions Games/types/Mafia/Events/TimeLoop.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
const Event = require("../Event");
const Action = require("../Action");
const Random = require("../../../../lib/Random");
const {
PRIORITY_ITEM_GIVER_DEFAULT,
PRIORITY_BECOME_DEAD_ROLE,
} = require("../const/Priority");

module.exports = class TimeLoop extends Event {
constructor(name, game) {
super("Time Loop", game);
constructor(modifiers, game) {
super("Time Loop", modifiers, game);
}

getNormalRequirements() {
Expand All @@ -13,7 +17,9 @@ module.exports = class TimeLoop extends Event {

doEvent() {
super.doEvent();
this.game.PossibleEvents.splice(this.game.PossibleEvents.indexOf(this.fullName),1);
let victim = Random.randArrayVal(this.game.alivePlayers());
//this.game.;
let L = function () {
if (this.role.data.doTimeLoop == true) {
this.role.data.doTimeLoop = false;
Expand All @@ -22,8 +28,8 @@ module.exports = class TimeLoop extends Event {
return false;
}
};
L = L.bind(this.holder);
this.holder.role.data.doTimeLoop = true;
L = L.bind(victim);
victim.role.data.doTimeLoop = true;
this.game.setStateShouldSkip("Day", L);
this.action = new Action({
actor: victim,
Expand Down
11 changes: 6 additions & 5 deletions Games/types/Mafia/Game.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Game = require("../../core/Game");
const Player = require("./Player");
const Event = require("./Event");
const Queue = require("../../core/Queue");
const Winners = require("./Winners");
const Action = require("./Action");
Expand Down Expand Up @@ -143,17 +144,17 @@ module.exports = class MafiaGame extends Game {
incrementState(index, skipped) {
super.incrementState(index, skipped);

if (this.getStateName() == "Night" && this.PossibleEvents.length > 0) {
this.selectedEvent = false;
this.alivePlayers()[0].holdItem("EventManager", 1);
this.events.emit("ManageRandomEvents");
}
if (
(this.setup.startState == "Night" && this.getStateName() == "Night") ||
(this.setup.startState == "Day" && this.getStateName() == "Day")
) {
this.dayCount++;
}
if (this.getStateName() == "Night" && this.PossibleEvents.length > 0) {
this.selectedEvent = false;
this.alivePlayers()[0].holdItem("EventManager", 1);
this.events.emit("ManageRandomEvents");
}
}

getStateInfo(state) {
Expand Down
83 changes: 83 additions & 0 deletions Games/types/Mafia/items/CaveIn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
const Item = require("../Item");
const { PRIORITY_KILL_DEFAULT,MEETING_PRIORITY_JAIL } = require("../const/Priority");


module.exports = class CaveIn extends Item {
constructor() {
super("CaveIn");

this.cannotBeStolen = true;
this.cannotBeSnooped = true;

this.meetings = {
"Caved In": {
actionName: "Convert Player to Food",
states: ["Night"],
flags: ["group", "speech", "voting", "mustAct"],
priority: MEETING_PRIORITY_JAIL,
passiveDead: true,
whileDead: true,
speakDead: true,
targets: { include: ["alive"], exclude: ["dead"] },
action: {
labels: ["kill", "hidden"],
priority: PRIORITY_KILL_DEFAULT,
power: 3,
item: this,
run: function () {
if (this.dominates()) {
if (!this.target.alive) {
this.game.exorcisePlayer(this.target);
}
this.target.kill("basic", this.actor);
for (let person of this.game.players) {
if (person.alive && person.role.name !== "Turkey") {
person.holdItem("Food", "Fresh Meat");
}
}
}


},
},

},
};

this.listeners = {
state: function () {
const state = this.game.getStateName();
if (state == "Day" && this.hasBeenNight == true) {
this.drop();
return;
}
if (state != "Night") {
return;
}
this.hasBeenNight = true;
this.holder.queueAlert(
`Event: Cave In, You all need something to eat!`
);

},
};


}

shouldDisableMeeting(name) {
// do not disable jailing, gov actions
if (this.game.getStateName() != "Night") {
return false;
}
/*
if (this.holder.role.alignment == "Cult") {
return false;
}
*/

return name !== "Caved In";
}


};
Loading

0 comments on commit 7a5994b

Please sign in to comment.