Ejemplo n.º 1
0
        public bool ForwardAction(TimeMachine timeMachine, GameState state)
        {
            this._combatant1Specialists = _combatant1.GetSpecialistManager().GetSpecialists();
            this._combatant2Specialists = _combatant1.GetSpecialistManager().GetSpecialists();

            List <Specialist> specialists = new List <Specialist>();

            specialists.AddRange(_combatant1.GetSpecialistManager().GetSpecialists());
            specialists.AddRange(_combatant2.GetSpecialistManager().GetSpecialists());

            while (specialists.Count > 0)
            {
                Specialist topPriority = null;
                foreach (Specialist s in specialists)
                {
                    // If any of the specialists are invalid, cancel the event.
                    if (!Validator.ValidateSpecialist(s))
                    {
                        this._eventSuccess = false;
                        return(false);
                    }
                    if (topPriority == null || s.GetPriority() < topPriority.GetPriority())
                    {
                        topPriority = s;
                    }
                }
                // Apply the specialist effect to the enemey.
                ICombatable enemy    = _combatant1.GetOwner() == topPriority.GetOwner() ? _combatant2 : _combatant1;
                ICombatable friendly = _combatant1.GetOwner() == topPriority.GetOwner() ? _combatant1 : _combatant2;
                topPriority.ApplyEffect(friendly, enemy);
            }
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Undoes the specialist combat
        /// </summary>
        /// <returns>If the event was undone</returns>
        public bool BackwardAction()
        {
            if (!_eventSuccess)
            {
                return(false);
            }

            List <Specialist> specialists = new List <Specialist>();

            specialists.AddRange(_combatant1Specialists);
            specialists.AddRange(_combatant2Specialists);

            while (specialists.Count > 0)
            {
                Specialist lowPriority = null;
                foreach (Specialist s in specialists)
                {
                    if (lowPriority == null || s.GetPriority() >= lowPriority.GetPriority())
                    {
                        lowPriority = s;
                    }
                }
                // Apply the specialist effect to the enemey.
                ICombatable enemy    = _combatant1.GetOwner() == lowPriority.GetOwner() ? _combatant2 : _combatant1;
                ICombatable friendly = _combatant1.GetOwner() == lowPriority.GetOwner() ? _combatant1 : _combatant2;
                lowPriority.UndoEffect(friendly, enemy);
            }
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Performs the forward operation of the event
        /// </summary>
        public override bool ForwardAction()
        {
            if (!Validator.ValidateICombatable(_combatant1) || !Validator.ValidateICombatable(_combatant2))
            {
                this.EventSuccess = false;
                return(false);
            }

            // Determine additional events that should be triggered for this particular combat.
            if (_combatant1.GetOwner() == _combatant2.GetOwner())
            {
                this._actions.Add(new FriendlySubArrive(_combatant1, _combatant2));
            }
            else
            {
                this._actions.Add(new SpecialistCombat(_combatant1, _combatant2));
                this._actions.Add(new DrillerCombat(_combatant1, _combatant2));

                if (_combatant1 is Outpost || _combatant2 is Outpost)
                {
                    this._actions.Add(new OwnershipTransfer(_combatant1, _combatant2));
                }
            }

            foreach (IReversible action in this._actions)
            {
                action.ForwardAction();
            }
            this.EventSuccess = true;
            return(true);
        }
Ejemplo n.º 4
0
        public override bool ForwardAction(TimeMachine timeMachine, GameState state)
        {
            if (!Validator.ValidateICombatable(state, _combatant1) || !Validator.ValidateICombatable(state, _combatant2))
            {
                this.EventSuccess = false;
                return(false);
            }

            // Determine additional events that should be triggered for this particular combat.
            if (_combatant1.GetOwner() == _combatant2.GetOwner())
            {
                this._actions.Add(new FriendlySubArrive(_combatant1, _combatant2));
            }
            else
            {
                this._actions.Add(new SpecialistCombat(_combatant1, _combatant2));
                this._actions.Add(new DrillerCombat(_combatant1, _combatant2));
                this._actions.Add(new CombatCleanup(_combatant1, _combatant2));
            }

            foreach (IReversible action in this._actions)
            {
                action.ForwardAction(timeMachine, state);
            }
            this.EventSuccess = true;
            return(true);
        }
Ejemplo n.º 5
0
        public CombatCleanup(ICombatable combatant1, ICombatable combatant2)
        {
            // Determine the losing sub:
            if (combatant1.GetDrillerCount() < combatant2.GetDrillerCount())
            {
                loser  = combatant1;
                winner = combatant2;
            }
            else if (combatant1.GetDrillerCount() > combatant2.GetDrillerCount())
            {
                loser  = combatant2;
                winner = combatant1;
            }
            else
            {
                // Tie. Compare specialist count.
                if (combatant1.GetSpecialistManager().GetSpecialistCount() <
                    combatant2.GetSpecialistManager().GetSpecialistCount())
                {
                    loser  = combatant1;
                    winner = combatant2;
                }
                else if (combatant2.GetSpecialistManager().GetSpecialistCount() >
                         combatant2.GetSpecialistManager().GetSpecialistCount())
                {
                    loser  = combatant2;
                    winner = combatant1;
                }
                else if (combatant1 is Outpost || combatant2 is Outpost)
                {
                    winner = combatant1 is Outpost ? combatant1 : combatant2;
                    loser  = combatant1 is Outpost ? combatant2 : combatant1;
                }
                else
                {
                    // Complete tie.
                    isTie = true;
                    // winner & loser don't matter in a tie.
                    winner = combatant1;
                    loser  = combatant2;
                }
            }

            initialLoserDrillerCount = loser.GetDrillerCount();
            losingPlayer             = loser.GetOwner();
            loserSpecialists         = loser.GetSpecialistManager().GetSpecialists();
        }
Ejemplo n.º 6
0
        public bool ForwardAction(TimeMachine timeMachine, GameState state)
        {
            if (isTie)
            {
                // TODO: Handle tie.
                return(false);
            }

            if (loser is Sub)
            {
                // Cleanup the sub.
                if (loser.GetSpecialistManager().GetSpecialistCount() > 0)
                {
                    loser.GetSpecialistManager().captureAll();
                    ((Sub)loser).IsCaptured = true;
                }
                else
                {
                    // Remove the sub
                    state.RemoveSub((Sub)loser);
                }
            }

            if (loser is Outpost)
            {
                // Transfer Ownership and give drillers.
                loser.SetOwner(winner.GetOwner());

                // Remove the winning sub and make it arrive at the outpost.
                loser.SetDrillerCount(0);
                loser.AddDrillers(winner.GetDrillerCount());

                // Transfer any specialists to the outpost.
                loser.GetSpecialistManager().captureAll();
                winner.GetSpecialistManager().transferSpecialistsTo(loser.GetSpecialistManager());

                // Remove the incoming sub.
                state.RemoveSub((Sub)winner);
            }

            this.isSuccess = true;
            return(isSuccess);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Constructor for the combat event
        /// </summary>
        /// <param name="combatant1">The first combatant</param>
        /// <param name="combatant2">The second combatant</param>
        /// <param name="tick">The tick the combat occurs</param>
        /// <param name="combatLocation">The location of the combat</param>
        public CombatEvent(ICombatable combatant1, ICombatable combatant2, GameTick tick, RftVector combatLocation)
        {
            this._combatant1     = combatant1;
            this._combatant2     = combatant2;
            this._eventTick      = tick;
            this._combatLocation = combatLocation;
            this.EventName       = "Combat Event";

            // Determine additional events that should be triggered for this particular combat.
            if (_combatant1.GetOwner() == _combatant2.GetOwner())
            {
                this._actions.Add(new FriendlySubArrive(_combatant1, _combatant2));
            }
            else
            {
                this._actions.Add(new SpecialistCombat(_combatant1, _combatant2));
                this._actions.Add(new DrillerCombat(_combatant1, _combatant2));
                this._actions.Add(new CombatCleanup(_combatant1, _combatant2));
            }
        }