/* Note that we use a much more strict delineation between individual and nonindividual events here than in the old event system.
 * Individual events always trigger for the chosen event slave, and the first actor is always the event slave.
 * Nonindividual events are not provided any event slave and should cast one themselves.
 */

/** get a list of possible individual event based on a given available main actor
 * @param {App.Entity.SlaveState} slave
 * @returns {Array<App.Events.BaseEvent>}
 */
App.Events.getIndividualEvents = function(slave) {
	return [
		// instantiate all possible random individual events here
		// example: new App.Events.TestEvent(),
		new App.Events.RESSLazyEvening(),
		new App.Events.RESSMuscles(),
		new App.Events.RESSHotPC(),
		new App.Events.RESSMoistPussy(),
		new App.Events.RESSWaistlineWoes(),
		new App.Events.RESSAssFitting(),
	]
	.filter(e => (e.eventPrerequisites().every(p => p()) && e.castActors(slave)))
	.reduce((res, cur) => res.concat(Array(cur.weight).fill(cur)), []);
};

/** get a list of possible nonindividual events
 * @returns {Array<App.Events.BaseEvent>}
 */
App.Events.getNonindividualEvents = function() {
	return [
		// instantiate all possible random nonindividual events here
		// example: new App.Events.TestEvent(),
		new App.Events.REDevotees(),
		new App.Events.RERelativeRecruiter(),
	]
	.filter(e => (e.eventPrerequisites().every(p => p()) && e.castActors(null)))
	.reduce((res, cur) => res.concat(Array(cur.weight).fill(cur)), []);
};

/* --- below here is a bunch of workaround crap because we have to somehow persist event selection through multiple twine passages. ---
 * eventually all this should go away, and we should use just one simple passage for both selection and execution, so everything can be kept in object form instead of being continually serialized and deserialized.
 * we need to be able to serialize/deserialize the active event anyway so that saves work right, so this mechanism just piggybacks on that capability so the event passages don't need to be reworked all at once
 */

/** get a stringified list of possible individual events as fake passage names - TODO: kill me */
App.Events.getIndividualEventsPassageList = function(slave) {
	const events = App.Events.getIndividualEvents(slave);
	return events.map(e => `JSRE ${e.eventName}:${JSON.stringify(e.toJSON())}`);
};

/** get a stringified list of possible individual events as fake passage names - TODO: kill me */
App.Events.getNonindividualEventsPassageList = function() {
	const events = App.Events.getNonindividualEvents();
	return events.map(e => `JSRE ${e.eventName}:${JSON.stringify(e.toJSON())}`);
};

/** execute a fake event passage from the embedded JSON - TODO: kill me */
App.Events.setGlobalEventForPassageTransition = function(psg) {
	V.event = JSON.parse(psg.slice(psg.indexOf(":") + 1));
};

/** strip the embedded JSON from the fake event passage so it can be read by a human being - TODO: kill me */
App.Events.printEventPassage = function(psg) {
	return psg.slice(0, psg.indexOf(":"));
};

src/events/randomEvent.js