示例#1
0
        private void DeployTroopGroup(int index, TroopTypeVO troop, DefenseTroopGroup group)
        {
            int degrees = group.Direction;

            if (group.Quantity > 1)
            {
                degrees = group.Direction + group.Spread * index / (group.Quantity - 1) - group.Spread / 2;
            }
            int locX = 0;
            int locZ = 0;

            DefensiveBattleController.GetBoardEdge(degrees, group.Range, out locX, out locZ);
            IntPosition nearestValidBoardPosition = this.GetNearestValidBoardPosition(locX, locZ);
            bool        sendPlacedEvent           = index == 0;
            Entity      entity = this.troopController.SpawnTroop(troop, TeamType.Attacker, nearestValidBoardPosition, TroopSpawnMode.Unleashed, sendPlacedEvent);

            if (entity != null)
            {
                if (!troop.IsHealer)
                {
                    this.waves[this.currentWaveIndex].Troops.Add(entity);
                }
                Service.BattleController.OnTroopDeployed(troop.Uid, TeamType.Attacker, nearestValidBoardPosition);
                Service.EventManager.SendEvent(EventId.TroopDeployed, entity);
            }
        }
示例#2
0
        public static List <DefenseTroopGroup> ParseTroopGroups(string uid, string encounterData, int directionOffset)
        {
            encounterData = encounterData.Trim();
            List <DefenseTroopGroup> list = new List <DefenseTroopGroup>();

            string[] array = encounterData.Split(new char[]
            {
                ' '
            });
            try
            {
                for (int i = 0; i < array.Length; i++)
                {
                    DefenseTroopGroup defenseTroopGroup = new DefenseTroopGroup();
                    string            text   = array[i];
                    string[]          array2 = text.Split(new char[]
                    {
                        ','
                    });
                    if (array2.Length != 6)
                    {
                        Service.Logger.ErrorFormat("{0} There is an error parsing group {1} of DefenseEncounter {2}", new object[]
                        {
                            "Bad Metadata.",
                            i.ToString(),
                            uid
                        });
                    }
                    defenseTroopGroup.TroopUid   = array2[0];
                    defenseTroopGroup.Quantity   = Convert.ToInt32(array2[1]);
                    defenseTroopGroup.Direction  = Convert.ToInt32(array2[2]);
                    defenseTroopGroup.Direction += directionOffset;
                    defenseTroopGroup.Direction %= 360;
                    defenseTroopGroup.Spread     = Convert.ToInt32(array2[3]);
                    defenseTroopGroup.Range      = Math.Min(Convert.ToInt32(array2[4]), 45);
                    defenseTroopGroup.Seconds    = Convert.ToUInt32(array2[5]);
                    list.Add(defenseTroopGroup);
                }
            }
            catch (Exception ex)
            {
                Service.Logger.ErrorFormat("There was an error parsing the data for DefenseEncounter: {0}", new object[]
                {
                    uid
                });
                throw ex;
            }
            return(list);
        }
示例#3
0
        private void DeployNextWave(uint id, object cookie)
        {
            this.timers.Remove(id);
            this.currentWaveIndex    = this.wavesDeployed;
            this.currentWave         = this.waves[this.currentWaveIndex];
            this.waveDirectionOffset = ((!this.randomizeWaves) ? 0 : Service.Rand.SimRange(0, 360));
            List <DefenseTroopGroup> list = DefensiveBattleController.ParseTroopGroups(this.currentWave.Encounter.Uid, this.currentWave.Encounter.WaveGroup, this.waveDirectionOffset);
            int count = list.Count;

            for (int i = 0; i < count; i++)
            {
                DefenseTroopGroup defenseTroopGroup = list[i];
                this.timers.Add(this.timerManager.CreateSimTimer(defenseTroopGroup.Seconds * 1000u, false, new TimerDelegate(this.DeployGroupAfterDelay), defenseTroopGroup));
            }
            this.wavesDeployed++;
        }
        public void StartDefenseMissionAfterLoadingAssets(CampaignMissionVO mission)
        {
            DefenseWave defenseWave         = this.waves[this.currentWaveIndex];
            List <DefenseTroopGroup> list   = DefensiveBattleController.ParseTroopGroups(defenseWave.Encounter.Uid, defenseWave.Encounter.WaveGroup, 0);
            int                count        = list.Count;
            AssetManager       assetManager = Service.Get <AssetManager>();
            List <string>      list2        = new List <string>();
            List <object>      list3        = new List <object>();
            List <AssetHandle> list4        = new List <AssetHandle>();

            for (int i = 0; i < count; i++)
            {
                DefenseTroopGroup defenseTroopGroup = list[i];
                TroopTypeVO       troopTypeVO       = this.sdc.Get <TroopTypeVO>(defenseTroopGroup.TroopUid);
                list2.Add(troopTypeVO.AssetName);
                list3.Add(new InternalLoadCookie(troopTypeVO.AssetName));
                list4.Add(AssetHandle.Invalid);
            }
            assetManager.MultiLoad(list4, list2, null, null, null, new AssetsCompleteDelegate(this.StartDefenseMissionAfterPreload), mission);
        }
示例#5
0
        private void DeployGroupAfterDelay(uint id, object cookie)
        {
            this.timers.Remove(id);
            DefenseTroopGroup defenseTroopGroup = (DefenseTroopGroup)cookie;
            TroopTypeVO       troop             = this.sdc.Get <TroopTypeVO>(defenseTroopGroup.TroopUid);

            for (int i = 0; i < defenseTroopGroup.Quantity; i++)
            {
                this.DeployTroopGroup(i, troop, defenseTroopGroup);
            }
            if (this.waves[this.currentWaveIndex].Troops.Count == 0 && this.timers.Count == 0)
            {
                this.EndCurrentWave();
            }
            if (Service.CurrentPlayer.CampaignProgress.FueInProgress)
            {
                int boardX = 0;
                int boardZ = 0;
                DefensiveBattleController.GetBoardEdge(defenseTroopGroup.Direction, defenseTroopGroup.Range, out boardX, out boardZ);
                this.AddCameraEvent(Units.BoardToWorldX(boardX), Units.BoardToWorldZ(boardZ), DefensiveCameraEventType.TroopSpawned);
            }
        }