/// <summary> /// Construct a new CombatManager object with the provided data. /// </summary> /// <param name="parties">All participants in combat, grouped by their Party affiliation.</param> /// <param name="standardActionGenerator">Supplier of standard actions which all Actors have access to.</param> /// <param name="winningPartyCalculator">Calculator for how CombatManager decides when combat is finished and which party won.</param> /// <param name="actorChangeCalculator">Calculator for changes within an actor's properties.</param> /// <param name="initiativeQueue">Implementation of an initiative queue for use in this combat session.</param> /// <param name="eventQueue">Implementation of an event queue for use in this combat session.</param> public CombatManager( IReadOnlyCollection <IParty> parties, ITurnController turnController, IStandardActionGenerator standardActionGenerator, IWinningPartyCalculator winningPartyCalculator, IActorChangeCalculator actorChangeCalculator, IInitiativeQueue initiativeQueue, IEventQueue eventQueue) { _turnController = turnController ?? new OneActionTurnController(); _standardActionGenerator = standardActionGenerator ?? new NullStandardActionGenerator(); _winningPartyCalculator = winningPartyCalculator ?? new AnyAliveWinningPartyCalculator(); _actorChangeCalculator = actorChangeCalculator ?? new NullActorChangeCalculator(); _initiativeQueue = initiativeQueue ?? new InitiativeQueue(100); _eventQueue = eventQueue ?? new EventQueue(); _parties.AddRange(parties); foreach (IParty party in parties) { _controllerByPartyId[party.Id] = party.Controller ?? new RandomCharacterController(); foreach (IInitiativeActor actor in party.Actors) { if (actor is ITargetableActor targetableActor) { _allTargets.Add(targetableActor); } float startingInitiative = (float)(RANDOM.NextDouble() * _initiativeQueue.InitiativeThreshold * 0.5f); _initiativeQueue.Add(actor, startingInitiative); } } _combatState = CombatState.Init; _eventQueue.EnqueueEvent(new CombatStateChangedEvent(_combatState)); }
private void CombatThread() { _combatState = CombatState.Active; _eventQueue.EnqueueEvent(new CombatStateChangedEvent(_combatState)); _eventQueue.EnqueueEvent(new CombatStartedEvent()); uint winningParty = LoopUntilCombatComplete(); _combatState = CombatState.Completed; _eventQueue.EnqueueEvent(new CombatStateChangedEvent(_combatState)); _eventQueue.EnqueueEvent(new CombatCompletedEvent(winningParty)); }