コード例 #1
0
        public void Remove(ICombatGroup group, BattleSide side, ReportState state)
        {
            lock (battleLock)
            {
                // Remove from appropriate combat list
                if (side == BattleSide.Attack)
                {
                    if (!Attackers.Remove(group))
                    {
                        return;
                    }

                    group.CombatObjectAdded   -= AttackerGroupOnCombatObjectAdded;
                    group.CombatObjectRemoved -= AttackerGroupOnCombatObjectRemoved;
                }
                else
                {
                    if (!Defenders.Remove(group))
                    {
                        return;
                    }

                    group.CombatObjectAdded   -= DefenderGroupOnCombatObjectAdded;
                    group.CombatObjectRemoved -= DefenderGroupOnCombatObjectRemoved;
                }

                // If battle hasnt started then dont worry about cleaning anything up since nothing has happened to these objects
                if (!BattleStarted)
                {
                    return;
                }

                // Snap a report of exit
                BattleReport.WriteReportGroup(group, side == BattleSide.Attack, state);

                // Tell objects to exit from battle
                foreach (var co in group.Where(co => !co.Disposed))
                {
                    co.ExitBattle();
                }

                // Send exit events
                if (side == BattleSide.Attack)
                {
                    WithdrawAttacker(this, group);
                }
                else
                {
                    WithdrawDefender(this, group);
                }
            }
        }
コード例 #2
0
        public void Add(ICombatGroup combatGroup, BattleSide battleSide, bool allowReportAccess)
        {
            bool isAttacker = battleSide == BattleSide.Attack;

            lock (battleLock)
            {
                if (GetCombatGroup(combatGroup.Id) != null)
                {
                    throw new Exception(
                              string.Format("Trying to add a group to battle {0} with id {1} that already exists",
                                            BattleId,
                                            combatGroup.Id));
                }

                (battleSide == BattleSide.Attack ? Attackers : Defenders).Add(combatGroup);

                if (isAttacker)
                {
                    combatGroup.CombatObjectAdded   += AttackerGroupOnCombatObjectAdded;
                    combatGroup.CombatObjectRemoved += AttackerGroupOnCombatObjectRemoved;
                }
                else
                {
                    combatGroup.CombatObjectAdded   += DefenderGroupOnCombatObjectAdded;
                    combatGroup.CombatObjectRemoved += DefenderGroupOnCombatObjectRemoved;
                }

                if (BattleStarted)
                {
                    BattleReport.WriteReportGroup(combatGroup, isAttacker, ReportState.Entering);

                    if (isAttacker)
                    {
                        ReinforceAttacker(this, combatGroup);
                    }
                    else
                    {
                        ReinforceDefender(this, combatGroup);
                    }
                }

                if (allowReportAccess)
                {
                    BattleReport.AddAccess(combatGroup, battleSide);
                }

                if (combatGroup.Tribe != null)
                {
                    BattleReport.AddTribeToBattle(combatGroup.Tribe, battleSide);
                }
            }
        }