public void RollScavengeEvents(MapRegion eventRegion,List<PartyMember> presentMembers) { GameEvent resEvent=null; //if (eventRegion.hasGasoline) resEvent=new GasolineEvent(); //else { float eventsRoll=Random.value; EventChance trackedEventRecord=new EventChance(); resEvent=PickRandomEvent(scavengingEvents, ref trackedEventRecord,eventsRoll, eventRegion, presentMembers); if (!resEvent.repeatable) scavengingEvents.Remove(trackedEventRecord); } if (resEvent!=null) StartEventDraw(resEvent, eventRegion, presentMembers); }
GameEvent PickRandomEvent(List<EventChance> eventsList, ref EventChance eventRecord, float roll , MapRegion eventRegion,List<PartyMember> movedMembers) { //find events with met preconditions //MapRegion currentTeamRegion=MapManager.main.GetRegion(PartyManager.mainPartyManager.selectedMembers.); List<EventChance> eligibleEvents=new List<EventChance>(); foreach(EventChance chance in eventsList) { if (chance.myEvent.PreconditionsMet(eventRegion,movedMembers)) {eligibleEvents.Add (chance);} } //form a dictionary based on probability intervals float eventPositiveProbabilitySpace=0; foreach (EventChance chance in eligibleEvents) {eventPositiveProbabilitySpace+=chance.chance;} Dictionary<float,EventChance> intervalDict=new Dictionary<float, EventChance>(); foreach (EventChance chance in eligibleEvents) { intervalDict.Add (eventPositiveProbabilitySpace,chance); eventPositiveProbabilitySpace-=chance.chance; } //roll on resulting intervals GameEvent resEvent=null; //Compiler made me assign this, should be null //EventChance eventRecord=new EventChance(); foreach (float chance in intervalDict.Keys) { if (roll<chance) { resEvent=intervalDict[chance].myEvent; eventRecord=intervalDict[chance]; } } return resEvent; }
public void RollCampEvents(MapRegion eventRegion,List<PartyMember> presentMembers) { float eventsRoll=Random.value; EventChance trackedEventRecord=new EventChance(); GameEvent resEvent; /* //Morale events resEvent=PickRandomEvent(moraleEvents, ref trackedEventRecord,eventsRoll, eventRegion, presentMembers); if (resEvent!=null) QueueEvent(resEvent,eventRegion,presentMembers);//StartEventDraw(resEvent, eventRegion, presentMembers); //Cold events resEvent=PickRandomEvent(coldEvents, ref trackedEventRecord,eventsRoll, eventRegion, presentMembers); if (resEvent!=null) QueueEvent(resEvent,eventRegion,presentMembers);//StartEventDraw(resEvent, eventRegion, presentMembers); //Attack events resEvent=PickRandomEvent(campSafetyEvents, ref trackedEventRecord,eventsRoll, eventRegion, presentMembers); if (resEvent!=null) QueueEvent(resEvent,eventRegion,presentMembers); //Relationship events resEvent=PickRandomEvent(grudgeEvents, ref trackedEventRecord,eventsRoll, eventRegion, presentMembers); if (resEvent!=null) QueueEvent(resEvent,eventRegion,presentMembers); resEvent=PickRandomEvent(friendshipEvents, ref trackedEventRecord,eventsRoll, eventRegion, presentMembers); if (resEvent!=null) QueueEvent(resEvent,eventRegion,presentMembers); */ }