static Event CreateEvent(System.Type eventType, GameVars gameVars, Ship ship, ShipSpeedModifiers shipSpeedModifiers, Transform shipTransform, float aggregateCloutScore) { var result = System.Activator.CreateInstance(eventType) as Event; result.Init(gameVars, ship, shipSpeedModifiers, shipTransform, aggregateCloutScore); return(result); }
public void Init(GameVars gameVars, Ship ship, ShipSpeedModifiers shipSpeedModifiers, Transform shipTransform, float aggregateCloutScore) { this.gameVars = gameVars; this.ship = ship; this.shipSpeedModifiers = shipSpeedModifiers; this.shipTransform = shipTransform; this.aggregateCloutScore = aggregateCloutScore; }
static void ExecuteEvent(IEnumerable <System.Type> options, GameVars gameVars, Ship ship, ShipSpeedModifiers shipSpeedModifiers, Transform shipTransform, float aggregateCloutScore) { var eventObj = CreateEvent(options.RandomElement(), gameVars, ship, shipSpeedModifiers, shipTransform, aggregateCloutScore); eventObj.Execute(); }
//######################################################################################################### // RANDOM EVENT FUNCTION //========================= // --This function determines whether or not a random event will happen to the ship. Regardless of // --whether or not a random event occurs, it will trigger journal messages based on whether or not // --the ship is in open sea or near a sphere of influence of a settlement/location of interest // //######################################################################################################### // it makes sense for this to have access to the ship, the ship's movement data and position, and the crew, as well as things like clout // doesn't need access to things like the GUI public static void WillARandomEventHappen(GameVars gameVars, Ship ship, ShipSpeedModifiers shipSpeedModifiers, Transform shipTransform) { //Random Events have a chance to occur every half day of travel //------------------------------------------------------------- //These values help determine the half day of travel float tenthPlaceTemp = (ship.totalNumOfDaysTraveled - Mathf.FloorToInt(ship.totalNumOfDaysTraveled)); tenthPlaceTemp *= 10; //Debug.Log (tenthPlaceTemp + " " + hundredthPlaceTemp); //If we are at a half day's travel, then see if a random event occurs if ((Mathf.FloorToInt(tenthPlaceTemp) == 5 || Mathf.FloorToInt(tenthPlaceTemp) == 9) && !gameVars.isPerformingRandomEvent) { gameVars.isPerformingRandomEvent = true; float chanceOfEvent = .95f; //0 - 1 value representing chance of a random event occuring //We determine if the if (Random.Range(0f, 1f) <= chanceOfEvent) { //Debug.Log ("Triggering Random Event"); //When we trigger a random event, let's make the ship drop anchor! gameVars.playerShipVariables.rayCheck_stopShip = true; //We separate Random events into two possible categories: Positive, and Negative. //First we need to determine if the player has a positive or negative event occur //--The basic chance is a 50/50 chance of either or, but we need to figure out if the //--crew makeup has any augers, and if so, each auger decreases the chance of a negative (now controlled by PostiveEvent modifiers) //--event by 10%. We then roll an aggregate clout score to further reduce the chance by a maximum of 20% //Get the 0-1 aggregate clout score. Here we use the current zone of influence's network id to check int currentZoneID = 0; //TODO Right now this just uses the relevant city's ID to check--but in the aggregate score function--it should start using the networks--not the city. if (gameVars.activeSettlementInfluenceSphereList.Count > 0) { currentZoneID = gameVars.activeSettlementInfluenceSphereList[0]; } float aggregateCloutScore = gameVars.GetOverallCloutModifier(currentZoneID); //Now determine the final weighted chance score that will be .5f and under chanceOfEvent = .5f - ship.crewRoster.Sum(c => c.changeOnHire.PositiveEvent / 100f) - (.2f * aggregateCloutScore); //If we roll under our range, that means we hit a NEGATIVE random event if (Random.Range(0f, 1f) <= chanceOfEvent) { ExecuteEvent(GetSubclassesOfType <NegativeEvent>(), gameVars, ship, shipSpeedModifiers, shipTransform, aggregateCloutScore); } else { ExecuteEvent(GetSubclassesOfType <PositiveEvent>(), gameVars, ship, shipSpeedModifiers, shipTransform, aggregateCloutScore); } } //If we do or don't get a random event, we should always get a message from the crew--let's call them tales //here they describe things like any cities nearby if the crew is familiar or snippets of greek mythology, or they //may be from a list of messages concering any nearby zones of influence from passing settlements/locations of interest var log = gameVars.GetRandomCaptainsLogFromPool(); if (log != null) { ship.shipCaptainsLog.Add(log); log.dateTimeOfEntry = ship.totalNumOfDaysTraveled + " days"; gameVars.AddToCaptainsLog(log.dateTimeOfEntry + "\n" + log.logEntry); } } //let's make sure the trigger for a new log / event doesn't happen again until needed by // by turning it off when the the trigger number changes--which means it won't take effect // again until the next time the trigger number occurs //Debug.Log (Mathf.FloorToInt(tenthPlaceTemp)); if (Mathf.FloorToInt(tenthPlaceTemp) != 5 && Mathf.FloorToInt(tenthPlaceTemp) != 9) { gameVars.isPerformingRandomEvent = false; } }
static void ExecuteEvent(IEnumerable <System.Type> options, GameVars gameVars, Ship ship, ShipSpeedModifiers shipSpeedModifiers, Transform shipTransform, float aggregateCloutScore) { IEnumerable <Event> events = options.Select(type => CreateEvent(type, gameVars, ship, shipSpeedModifiers, shipTransform, aggregateCloutScore)); IEnumerable <Event> filteredEvents = events.Where(evnt => evnt.isValid() == true); //calls for an event/ mini game to play wiht a higher chance that minigames will happen due to their higher Weight() return value var eventObj = filteredEvents.WeightedRandomElement(filteredEvents.Select(element => element.Weight())); if (eventObj != null) { eventObj.Execute(); } else { Debug.Log("EVENT WAS NULL."); } }