Skip to content

Fixed Events in Multi-Setups + Famine Event now makes players start with bread + Added Option to allow players to choose how many events occur each night #1839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 19, 2025
28 changes: 26 additions & 2 deletions Games/core/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,7 @@ module.exports = class Game {
this.banishedRoles = [];
this.PossibleRoles = [];
this.PossibleEvents = [];
this.CurrentEvents = [];
this.BanishedEvents = [];

for (let role in this.setup.roles[0]) {
Expand Down Expand Up @@ -838,7 +839,7 @@ module.exports = class Game {
roleset[role]++;
}
}

this.CurrentEvents = this.PossibleEvents.filter((e) => e);
return roleset;
}

Expand All @@ -847,6 +848,7 @@ module.exports = class Game {
this.banishedRoles = [];
this.PossibleRoles = [];
this.PossibleEvents = [];
this.CurrentEvents = [];
this.BanishedEvents = [];

for (let i in this.setup.roles) {
Expand Down Expand Up @@ -892,7 +894,7 @@ module.exports = class Game {
finalRoleset[role]++;
}
}

this.CurrentEvents = this.PossibleEvents.filter((e) => e);
return finalRoleset;
}

Expand Down Expand Up @@ -938,6 +940,7 @@ module.exports = class Game {
var roleset;
this.PossibleRoles = [];
this.PossibleEvents = [];
this.CurrentEvents = [];
this.BanishedEvents = [];

for (let i in this.setup.roles) {
Expand Down Expand Up @@ -1008,6 +1011,9 @@ module.exports = class Game {
let role = roleName.split(":")[0];
if (this.getRoleAlignment(role) == "Event") {
toDelete.push(roleName);
if (!this.BanishedEvents.includes(roleName)) {
this.CurrentEvents.push(roleName);
}
}
if (role != "Host") {
continue;
Expand Down Expand Up @@ -1058,6 +1064,19 @@ module.exports = class Game {
this.SpecialInteractionRoles.push(this.PossibleRoles[z]);
}
}
for (let z = 0; z < this.PossibleEvents.length; z++) {
if (this.PossibleEvents[z].split(":")[0] == "Famine") {
this.FamineEventPossible = true;
}
if (
this.getRoleTags(this.PossibleEvents[z]).includes("Pregame Actions")
) {
this.HaveDuskOrDawn = true;
}
if (this.getSpecialInteractions(this.PossibleEvents[z]) != null) {
this.SpecialInteractionRoles.push(this.PossibleEvents[z]);
}
}
if (this.setup.closed && this.setup.banished > 0) {
var banishedRoles = this.banishedRoles;
var banishedCount = this.setup.banished;
Expand Down Expand Up @@ -1179,6 +1198,11 @@ module.exports = class Game {
this.rollQueue.shift();
}

if (this.FamineEventPossible) {
this.players.map((p) => p.holdItem("Bread"));
this.players.map((p) => p.queueGetItemAlert("Bread"));
}

this.players.map((p) => p.role.revealToSelf(false));
this.players.map((p) => this.events.emit("roleAssigned", p));
}
Expand Down
13 changes: 9 additions & 4 deletions Games/core/Meeting.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ module.exports = class Meeting {
var member = this.members[playerId] || {};
var votes = {};
var voteRecord = [];
var isExcludeSelf = this.targetsDescription && this.targetsDescription["exclude"] && this.targetsDescription["exclude"].includes("self");
var isExcludeSelf =
this.targetsDescription &&
this.targetsDescription["exclude"] &&
this.targetsDescription["exclude"].includes("self");

if (this.voting) {
if (member.id) {
Expand Down Expand Up @@ -259,8 +262,7 @@ module.exports = class Meeting {
personalizedTargets.splice(indexOfSelf, 1);
}
}
}
else {
} else {
personalizedTargets = this.targets;
}

Expand Down Expand Up @@ -708,7 +710,10 @@ module.exports = class Meeting {

this.finished = true;

var isExcludeSelf = this.targetsDescription && this.targetsDescription["exclude"] && this.targetsDescription["exclude"].includes("self");
var isExcludeSelf =
this.targetsDescription &&
this.targetsDescription["exclude"] &&
this.targetsDescription["exclude"].includes("self");
var count = {};
var highest = { targets: [], votes: 1 };
var finalTarget;
Expand Down
4 changes: 2 additions & 2 deletions Games/types/Mafia/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ module.exports = class MafiaEvent extends Event {
this.modifiers.includes("One Shot") &&
!this.modifiers.includes("Banished")
) {
this.game.PossibleEvents.splice(
this.game.PossibleEvents.indexOf(this.fullName),
this.game.CurrentEvents.splice(
this.game.CurrentEvents.indexOf(this.fullName),
1
);
} else if (
Expand Down
31 changes: 31 additions & 0 deletions Games/types/Mafia/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const Game = require("../../core/Game");
const Utils = require("../../core/Utils");
const Player = require("./Player");
const Event = require("./Event");
const Random = require("../../../lib/Random");
const Queue = require("../../core/Queue");
const Winners = require("./Winners");
const Action = require("./Action");
Expand Down Expand Up @@ -60,6 +61,7 @@ module.exports = class MafiaGame extends Game {
this.RoomTwo = [];
this.FinalRound = 3;
this.CurrentRound = 0;
this.EventsPerNight = this.setup.EventsPerNight;
this.lastNightVisits = [];
this.infoLog = [];
}
Expand Down Expand Up @@ -179,8 +181,37 @@ module.exports = class MafiaGame extends Game {
}
if (this.getStateName() == "Night" && this.PossibleEvents.length > 0) {
this.selectedEvent = false;
/*
this.alivePlayers()[0].holdItem("EventManager", 1);
this.events.emit("ManageRandomEvents");
*/
for (
let x = 0;
x < this.EventsPerNight &&
this.CurrentEvents.filter(
(e) => this.checkEvent(e.split(":")[0], e.split(":")[1]) == true
).length > 0;
x++
) {
let event;
let eventMods;
let eventName;

let Events = this.CurrentEvents.filter(
(e) => this.checkEvent(e.split(":")[0], e.split(":")[1]) == true
);
if (Events.length <= 0) {
break;
}
event = Random.randArrayVal(Events);
eventMods = event.split(":")[1];
eventName = event.split(":")[0];
//this.game.queueAlert(`Manager ${eventMods}`);
event = this.createGameEvent(eventName, eventMods);
event.doEvent();
event = null;
}
this.selectedEvent = true;
}
if (
this.getStateName() == "Day" &&
Expand Down
3 changes: 2 additions & 1 deletion Games/types/Mafia/events/Feast.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ module.exports = class Feast extends Event {
run: function () {
if (this.game.SilentEvents != false) {
this.game.queueAlert(
`Event: Feast, The Town discovered a hidden create a Grand Feast will be Held!`
`Event: Feast, The Town discovered hidden rations a Grand Feast will be Held!`
);
}
for (let person of this.game.players) {
if (person.alive && person.role.name !== "Turkey") {
person.holdItem("Food", "Bread");
person.queueGetItemAlert("Bread");
}
}
},
Expand Down
1 change: 1 addition & 0 deletions Games/types/Mafia/items/CaveIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports = class CaveIn extends Item {
for (let person of this.game.players) {
if (person.alive && person.role.name !== "Turkey") {
person.holdItem("Food", "Fresh Meat");
person.queueGetItemAlert("Mystery Meat");
}
}
}
Expand Down
1 change: 1 addition & 0 deletions db/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ var schemas = {
AlignmentShare: Boolean,
PrivateShare: Boolean,
PublicShare: Boolean,
EventsPerNight: Number,
swapAmt: Number,
roundAmt: Number,
firstTeamSize: Number,
Expand Down
9 changes: 9 additions & 0 deletions react_main/src/pages/Play/CreateSetup/CreateMafiaSetup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ export default function CreateMafiaSetup() {
value: false,
type: "boolean",
},
{
label: "Events Per Night",
ref: "EventsPerNight",
type: "number",
value: "1",
min: "0",
max: "5",
},
]);

const formFieldValueMods = {
Expand Down Expand Up @@ -247,6 +255,7 @@ export default function CreateMafiaSetup() {
AlignmentShare: formFields[26].value,
PrivateShare: formFields[27].value,
PublicShare: formFields[28].value,
EventsPerNight: formFields[29].value,
editing: editing,
id: params.get("edit"),
})
Expand Down
1 change: 1 addition & 0 deletions routes/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ router.post("/create", async function (req, res) {
setup.AlignmentShare = Boolean(setup.AlignmentShare);
setup.PrivateShare = Boolean(setup.PrivateShare);
setup.PublicShare = Boolean(setup.PublicShare);
setup.EventsPerNight = Number(setup.EventsPerNight || 0);

if (
!routeUtils.validProp(setup.gameType) ||
Expand Down
Loading