Skip to content
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

Add seasonal events without the seasonal events #104

Merged
merged 5 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import EventsManager from "./events/EventsManager";
import MinigamesManager from "./events/MinigamesManager";
import events from "./events.json";
import choices from "./choices.json";
import config from "./game-config.json";
import minigames from "./minigames.json";
import Hud from "./components/hud/Hud";
import GamePlayConsole from "./components/gamePlayConsole/GamePlayConsole";
Expand Down Expand Up @@ -43,16 +44,21 @@ export default class App extends React.Component<IProps, IState> {
super(props);

const playerStats = new PlayerStats();
const eventTracker = new EventTracker(
[events.BoomerGregorEvent, events.CuteGirlEvent, events.FratPartyEvent, events.MidtermEvent, events.SquirrelEvent],
[events.LandingEvent, events.PickFacultyEvent, events.PickResidenceEvent]
);
let firstEvent = eventTracker.getNextEvent();

//TODO: should we auto allocate a dummy player name or allow user to input their own?
this.name = "P1";
this.choiceManager = new ChoicesManager(choices);
this.eventManager = new EventsManager(events);
let seasons = [];
for (const w of config.events.seasonal) {
seasons.push(w.map(this.eventManager.get.bind(this.eventManager)));
}
const eventTracker = new EventTracker(
config.events.pool.map(this.eventManager.get.bind(this.eventManager)),
config.events.followUp.map(this.eventManager.get.bind(this.eventManager)),
seasons
);
let firstEvent = eventTracker.getNextEvent(0);
this.minigameManager = new MinigamesManager(minigames);
this.state = {
// TODO: The week number may not be how we choose to track time,
Expand Down Expand Up @@ -88,7 +94,7 @@ export default class App extends React.Component<IProps, IState> {
);
}

let nextEvent = this.state.eventTracker.getNextEvent();
let nextEvent = this.state.eventTracker.getNextEvent(this.state.week + 1);

this.setState(prevState => {
return {
Expand Down Expand Up @@ -124,7 +130,7 @@ export default class App extends React.Component<IProps, IState> {

finishMinigame = (statChanges: number[]) => {
this.state.playerStats.applyStatChanges(statChanges, "");
let nextEvent = this.state.eventTracker.getNextEvent();
let nextEvent = this.state.eventTracker.getNextEvent(this.state.week + 1);
this.setState(prevState => {
return {
week: prevState.week + 1,
Expand Down
24 changes: 24 additions & 0 deletions src/game-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"events": {
"pool": [
"BoomerGregorEvent", "CuteGirlEvent", "FratPartyEvent", "MidtermEvent", "SquirrelEvent"
],
"followUp": [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why call this followUp?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cuz that's what it's called before. probably need to refactor to something easier to understand, such as startUp.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just called queue before wasn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

"LandingEvent", "PickFacultyEvent", "PickResidenceEvent"
],
"seasonal": [
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[]
]
}
}
chuck-sys marked this conversation as resolved.
Show resolved Hide resolved
27 changes: 22 additions & 5 deletions src/trackers/EventTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,50 @@ import { IEvent } from "../events/core";
import { GamePlayMode } from "../events/core";

export default class EventTracker {
readonly SEASONAL_CHANCE = 30;
private pool: IEvent[];
private queue: IEvent[];
private seasonal: IEvent[][];

constructor(eventPool: IEvent[], eventQueue: IEvent[]) {
constructor(eventPool: IEvent[], eventQueue: IEvent[], seasonalPool: IEvent[][]) {
this.pool = eventPool;
this.queue = eventQueue;
this.seasonal = seasonalPool;
}

public getNextEvent(): IEvent {
public getNextEvent(week: number): IEvent {
// The queue being non-empty indicates there is a follow up
// event to go through, otherwise pick a random event
if (this.queue.length > 0)
return this.queue.shift() as IEvent;
else if (this.pool.length > 0){

const r = Math.random() * 100;
// 0 to 11
const month = (Math.floor(week / 4) + 8) % 12;
if (this.pool.length > 0 &&
(r > this.SEASONAL_CHANCE || this.seasonal[month].length === 0)) {
// If we roll a normal pool or if there are no seasonal events then
// use the normal pool (given that there are still things in the
// normal pool)
let event = this.pool[Math.floor(Math.random() * this.pool.length)];
const index = this.pool.indexOf(event);
this.pool.splice(index, 1);
return event;
}
else
} else if (r <= this.SEASONAL_CHANCE && this.seasonal[month].length > 0) {
// Else we use the seasonal events pool
let event = this.seasonal[month][Math.floor(Math.random() * this.seasonal[month].length)];
const index = this.seasonal[month].indexOf(event);
this.seasonal[month].splice(index, 1);
return event;
} else {
return {
"prompt": "Oops! No more events!",
"imgPath": "",
"choices": [],
"hasBottomBoxBorder": true,
"gamePlayMode": GamePlayMode.Hide
};
}
}

public queueFollowUpEvent(event: IEvent) {
Expand Down