Skip to content

Commit

Permalink
Event Code Refactor + Event Modifiers + Emperor Icon (#1758)
Browse files Browse the repository at this point in the history
Odd, Even, Delayed, and One Shot now work on Events.

Added a Cave In Event, Blocks Night Actions like a blizzard but it also
forces players to Vote a player to kill, Will also feed all players
during famine if kill is successful.

Events are now coded more like effects/items/roles.

---------

Co-authored-by: SawJester <[email protected]>
  • Loading branch information
SawJester and SawJester authored Nov 3, 2024
1 parent 9037352 commit fee6e5d
Show file tree
Hide file tree
Showing 24 changed files with 630 additions and 143 deletions.
51 changes: 51 additions & 0 deletions Games/core/Event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const shortid = require("shortid");
const Utils = require("./Utils");

module.exports = class Event {
constructor(name, modifiers, game) {
this.game = game;
this.id = shortid.generate();
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 = [];
}

getRequirements() {
if (
this.getModifierRequirements() == true &&
this.getNormalRequirements() == true
) {
return true;
} else {
return false;
}
}

getModifierRequirements() {
return true;
}

getNormalRequirements() {
return true;
}

doEvent() {}

queueActions() {
for (let action of this.actions) this.game.queueAction(action);
}

dequeueActions() {
for (let action of this.actions) this.game.dequeueAction(action);
}
};
64 changes: 36 additions & 28 deletions Games/core/Game.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Player = require("./Player");
const Event = require("./Event");
const Spectator = require("./Spectator");
const Message = require("./Message");
const History = require("./History");
Expand Down Expand Up @@ -789,7 +790,7 @@ module.exports = class Game {
for (let role in this.setup.roles[0]) {
let roleName = role.split(":")[0];
let isBanished = role.toLowerCase().includes("banished");
let isEvent = (this.getRoleAlignment(roleName) == "Event");
let isEvent = this.getRoleAlignment(roleName) == "Event";
const roleFromRoleData = roleData[this.type][roleName];
if (!roleFromRoleData) {
this.sendAlert(
Expand All @@ -799,22 +800,20 @@ module.exports = class Game {
}

let alignment = roleFromRoleData.alignment;
if(!isEvent){
this.PossibleRoles.push(role);
if (!isEvent) {
this.PossibleRoles.push(role);
}
if (!isBanished && !isEvent) {
if (!rolesByAlignment[alignment]) rolesByAlignment[alignment] = [];

for (let i = 0; i < this.setup.roles[0][role]; i++)
rolesByAlignment[alignment].push(role);
} else {
if(!isEvent){
this.banishedRoles.push(role);
}
else if(!isBanished){
if (!isEvent) {
this.banishedRoles.push(role);
} else if (!isBanished) {
this.PossibleEvents.push(role);
}
else{
} else {
this.BanishedEvents.push(role);
}
}
Expand Down Expand Up @@ -858,24 +857,22 @@ module.exports = class Game {
let rolesetArray = [];
for (let role in roleset) {
let isBanished = role.toLowerCase().includes("banished");
let isEvent = (this.getRoleAlignment(role.split(":")[0]) == "Event");
if(!isEvent){
this.PossibleRoles.push(role);
let isEvent = this.getRoleAlignment(role.split(":")[0]) == "Event";
if (!isEvent) {
this.PossibleRoles.push(role);
}
if (!isBanished && !isEvent) {
for (let i = 0; i < roleset[role]; i++) {
rolesetArray.push(role);
}
} else {
if(!isEvent){
if (!isEvent) {
this.banishedRoles.push(role);
}
else if(!isBanished){
this.PossibleEvents.push(role);
}
else{
this.BanishedEvents.push(role);
}
} else if (!isBanished) {
this.PossibleEvents.push(role);
} else {
this.BanishedEvents.push(role);
}
}
}

Expand Down Expand Up @@ -950,13 +947,12 @@ module.exports = class Game {
for (let i = 0; i < roleset[role]; i++) {
let roleName = role.split(":")[0];
let isBanished = role.toLowerCase().includes("banished");
let isEvent = (this.getRoleAlignment(roleName) == "Event");
if(isEvent){
if(isBanished) this.BanishedEvents.push(role);
let isEvent = this.getRoleAlignment(roleName) == "Event";
if (isEvent) {
if (isBanished) this.BanishedEvents.push(role);
else this.PossibleEvents.push(role);
}
else{
this.PossibleRoles.push(role);
} else {
this.PossibleRoles.push(role);
}
}
}
Expand Down Expand Up @@ -1010,7 +1006,7 @@ module.exports = class Game {
let toDelete = [];
for (let roleName in roleset) {
let role = roleName.split(":")[0];
if(this.getRoleAlignment(role) == "Event"){
if (this.getRoleAlignment(role) == "Event") {
toDelete.push(roleName);
}
if (role != "Host") {
Expand Down Expand Up @@ -1243,6 +1239,18 @@ module.exports = class Game {
return roleData[this.type][role.split(":")[0]].tags;
}

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 Expand Up @@ -2085,4 +2093,4 @@ module.exports = class Game {
}, this.scheduled - Date.now())
);
}
};
};
4 changes: 1 addition & 3 deletions Games/core/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ module.exports = class Item {
this.actions = [];
this.meetings = {};
this.listeners = {};
this.stateMods = {
};
this.stateMods = {};
this.lifespan = Infinity;
this.ageListener;

Expand Down Expand Up @@ -91,5 +90,4 @@ module.exports = class Item {
hear(message) {}

seeVote(vote) {}

};
53 changes: 53 additions & 0 deletions Games/types/Mafia/Event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const Event = require("../../core/Event");

module.exports = class MafiaEvent extends Event {
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.dayCount % 2 == 0 &&
this.modifiers.includes("Odd")
) {
return false;
}
//this.game.queueAlert(`${this.modifiers} ${this.modifiers.includes("Odd")}`);
if (
this.game.dayCount % 2 == 1 &&
this.modifiers.includes("Even")
) {
return false;
}
if (
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.splice(this.game.PossibleEvents.indexOf(this.fullName),1);
} else if (
this.modifiers.includes("One Shot") &&
this.modifiers.includes("Banished")
) {
this.game.BanishedEvents.splice(
this.game.BanishedEvents.indexOf(this.fullName),
1
);
}
}

}
};
40 changes: 40 additions & 0 deletions Games/types/Mafia/Events/Brainblast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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 () {
if (this.game.SilentEvents != false) {
this.game.queueAlert(
`Event: Brainblast, A player got a brainblast and can learn another player's role!`
);
}
let targetTypes = ["neighbors", "even", "odd"];
let targetType = Random.randArrayVal(targetTypes);
this.target.holdItem("WackyRoleLearner", targetType, "Day");
},
});
this.game.queueAction(this.action);
}
};
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 CaveIn extends Event {
constructor(modifiers, game) {
super("Cave In", 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);
}
};
Loading

0 comments on commit fee6e5d

Please sign in to comment.