Пример #1
0
        void spawnUpgBtn_Click(Button button)
        {
            DefenderSpawnStruct dss = (DefenderSpawnStruct)button.Tag;

            if (CanUpgradeSpawnCnt(dss.ID, true))
            {
                UpgradeDefenderCnt(dss.ID);
                button.IsEnabled = CanUpgradeSpawnCnt(dss.ID, false);
            }
            else
            {
#warning todo: display error message here or play error sound.
            }
        }
Пример #2
0
        /// <summary>
        /// Spawns an exta defender if possible
        /// </summary>
        public void UpgradeDefenderCnt(int ddsID)
        {
            foreach (BaseDefender bd in Defenders)
            {
                if (bd.ID == ddsID && !bd.IsSpawned)
                {
                    bd.Spawn();

                    AudioMgrPooled.Instance.PlaySound(AudioConstants.BuildingUpgraded);
                    TowerStruct         ts  = DataStructs.Towers.Find(t => t.ID == ID);
                    DefenderSpawnStruct dds = ts.Defenders.Find(d => d.ID == ddsID);
                    TotalValue += dds.UpgCntCost;
                    Level.Instance.Player.Gold -= dds.UpgCntCost;
                    break;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Checks if the player can spawn a new defender of that ID.
        /// Checks if the player has enough gold.
        /// Checks if there are any defenders with that matching ID that have not yet been spawned.
        /// </summary>
        /// <param name="ddsID"></param>
        /// <returns></returns>
        public bool CanUpgradeSpawnCnt(int ddsID, bool includeGoldCheck)
        {
            if (Defenders.Where(d => d.ID == ddsID && !d.IsSpawned).Count() > 0)
            {
                TowerStruct         ts  = DataStructs.Towers.Find(t => t.ID == ID);
                DefenderSpawnStruct dds = ts.Defenders.Find(d => d.ID == ddsID);

                if (includeGoldCheck && Level.Instance.Player.Gold < dds.UpgCntCost)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
Пример #4
0
        public static void LoadTowers()
        {
            Towers.Clear();
            string[] towerXmls = Directory.GetFiles("Data/Towers", "*.xml");

            foreach (string path in towerXmls)
            {
                XDocument doc = XDocument.Load(path);

                #region Required
                XElement RequiredNode = doc.Root.Element("Required");
                if (RequiredNode == null)
                {
                    throw new Exception("Required node missing. " + path);
                }

                TowerStruct ts       = new TowerStruct(int.Parse(RequiredNode.Element("ID").Value));
                XElement    required = RequiredNode.Element("Name");
                if (required != null)
                {
                    ts.Name = required.Value;
                }
                else
                {
                    throw new Exception("Name missing." + path);
                }
                required = null;

                required = RequiredNode.Element("Description");
                if (required != null)
                {
                    ts.Desc = required.Value;
                }
                else
                {
                    throw new Exception("Description missing." + path);
                }
                required = null;

                required = RequiredNode.Element("Cost");
                if (required != null)
                {
                    ts.Cost = int.Parse(required.Value);
                }
                else
                {
                    throw new Exception("Cost missing." + path);
                }
                required = null;

                required = RequiredNode.Element("Icon");
                if (required != null)
                {
                    ts.Icon = Common.str2Tex("Icons/" + required.Value);
                }
                else
                {
                    throw new Exception("Icon missing." + path);
                }
                required = null;

                required = RequiredNode.Element("Animation");
                if (required != null)
                {
                    ts.AnimationType = (eAnimation)Enum.Parse(typeof(eAnimation), required.Value);
                }
                else
                {
                    throw new Exception("Animation missing." + path);
                }
                required = null;
                #endregion

                #region Basic
                XElement basicNode = doc.Root.Element("Basic");
                if (basicNode != null)
                {
                    XElement basic;

                    basic = basicNode.Element("BuildSize");
                    if (basic != null)
                    {
                        ts.BuildSize = Common.Str2Point(basic.Value);
                    }
                    basic = null;

                    basic = basicNode.Element("BuildTime");
                    if (basic != null)
                    {
                        ts.BuildTimeInMS = int.Parse(basic.Value);
                    }
                    basic = null;

                    basic = basicNode.Element("Supply");
                    if (basic != null)
                    {
                        ts.SupplyCost = int.Parse(basic.Value);
                    }
                    basic = null;

                    basic = basicNode.Element("UpgradeTime");
                    if (basic != null)
                    {
                        ts.UpgTimeInMS = int.Parse(basic.Value);
                    }
                    basic = null;
                }
                #endregion

                #region Advanced
                XElement advancedNode = doc.Root.Element("Advanced");
                if (advancedNode != null)
                {
                    XElement advanced;

                    advanced = advancedNode.Element("IncomePerTick");
                    if (advanced != null)
                    {
                        ts.IncomePerTick = int.Parse(advanced.Value);
                    }
                    advanced = null;

                    advanced = advancedNode.Element("IncomeTickDelay");
                    if (advanced != null)
                    {
                        ts.IncomeTickDelayInMS = int.Parse(advanced.Value);
                    }
                    advanced = null;

                    advanced = advancedNode.Element("IncomePerWave");
                    if (advanced != null)
                    {
                        ts.IncomePerWave = int.Parse(advanced.Value);
                    }
                    advanced = null;
                }
                #endregion

                #region Weapons
                XElement wpnNode = doc.Root.Element("Weapons");
                if (wpnNode != null)
                {
                    foreach (XElement wpn in wpnNode.Elements())
                    {
                        XElement wpnRange = wpn.Element("Range");
                        if (wpnRange == null)
                        {
                            throw new Exception("Weapon has no range. " + path);
                        }

                        XElement wpnRoF = wpn.Element("RoF");
                        if (wpnRoF == null)
                        {
                            throw new Exception("Weapon has no RoF. " + path);
                        }

                        XElement wpnDmg = wpn.Element("Damage");
                        if (wpnDmg == null)
                        {
                            throw new Exception("Weapon has no Damage. " + path);
                        }

                        XElement wpnProjectileType = wpn.Element("Projectile");
                        if (wpnProjectileType == null)
                        {
                            throw new Exception("Weapon has no Projectile. " + path);
                        }

                        XElement wpnSplash = wpn.Element("Splash");
                        int      wpnSplashValue;
                        if (wpnSplash == null)
                        {
                            wpnSplashValue = 0;
                        }
                        else
                        {
                            wpnSplashValue = int.Parse(wpnSplash.Value);
                        }

                        XElement wpnSplashDmgPercentage = wpn.Element("SplashDmgPercentage");
                        int      wpnSplashDmgPercentageValue;
                        if (wpnSplashDmgPercentage == null)
                        {
                            wpnSplashDmgPercentageValue = 0;
                        }
                        else
                        {
                            wpnSplashDmgPercentageValue = int.Parse(wpnSplashDmgPercentage.Value);
                        }

                        XElement           wpnAttackableTargets = wpn.Element("AttackableTargets");
                        eAttackableTargets wpnAttackableTargetsValue;
                        if (wpnAttackableTargets == null)
                        {
                            wpnAttackableTargetsValue = eAttackableTargets.Ground;
                        }
                        else
                        {
                            wpnAttackableTargetsValue = (eAttackableTargets)Enum.Parse(typeof(eAttackableTargets), required.Value);
                        }

                        WeaponStruct ws = new WeaponStruct(int.Parse(wpnRange.Value), int.Parse(wpnRoF.Value), int.Parse(wpnDmg.Value), (eProjectile)Enum.Parse(typeof(eProjectile), wpnProjectileType.Value), wpnSplashValue, wpnSplashDmgPercentageValue, wpnAttackableTargetsValue);

                        XElement wpnProjectileSpawnOffset = wpn.Element("ProjectileSpawnOffset");
                        if (wpnProjectileSpawnOffset != null)
                        {
                            ws.ProjectileSpawnOffset = Common.Str2Vector(wpnProjectileSpawnOffset.Value);
                        }

                        XElement wpnCritical;
                        wpnCritical = wpn.Element("CritRate");
                        if (wpnCritical != null)
                        {
                            ws.CritChance = int.Parse(wpnCritical.Value);
                        }

                        XElement wpnCritMultiplier;
                        wpnCritMultiplier = wpn.Element("CritMultiplier");
                        if (wpnCritMultiplier != null)
                        {
                            ws.CritMultiplier = int.Parse(wpnCritMultiplier.Value);
                        }

                        XElement shootFXNode = wpn.Element("ShootFX");
                        if (shootFXNode != null)
                        {
                            ws.ShootFX = int.Parse(shootFXNode.Value);
                        }
                        XElement impactFXNode = wpn.Element("ImpactFX");
                        if (impactFXNode != null)
                        {
                            ws.ImpactFX = int.Parse(impactFXNode.Value);
                        }

                        #region Modifiers
                        XElement modifierNode = wpn.Element("Stunchance");
                        if (modifierNode != null)
                        {
                            ws.WeaponModifiers.StunChance = int.Parse(modifierNode.Value);
                        }
                        modifierNode = null;
                        modifierNode = wpn.Element("Slows");
                        if (modifierNode != null)
                        {
                            ws.WeaponModifiers.Slows = bool.Parse(modifierNode.Value);
                        }
                        modifierNode = null;
                        modifierNode = wpn.Element("RootChance");
                        if (modifierNode != null)
                        {
                            ws.WeaponModifiers.RootChance = int.Parse(modifierNode.Value);
                        }
                        modifierNode = null;
                        modifierNode = wpn.Element("ArmorReductionValue");
                        if (modifierNode != null)
                        {
                            ws.WeaponModifiers.ArmorReductionValue = int.Parse(modifierNode.Value);
                        }
                        modifierNode = null;
                        #endregion

                        ts.Weapons.Add(ws);
                    }
                }
                #endregion

                #region Spawn
                XElement spawnMainNode = doc.Root.Element("Spawns");
                if (spawnMainNode != null)
                {
                    ts.MaxRallyPointRange     = int.Parse(spawnMainNode.Attribute("maxRallyPointRange").Value);
                    ts.RallyPointPersuitRange = int.Parse(spawnMainNode.Attribute("persuitRange").Value);
                    foreach (XElement spawnNode in spawnMainNode.Elements())
                    {
                        ts.Spawns = true;
                        int defID = int.Parse(spawnNode.Element("ID").Value);
                        DefenderSpawnStruct ds = new DefenderSpawnStruct(defID);

                        XElement initialAmountNode = spawnNode.Element("InitialAmount");
                        if (initialAmountNode != null)
                        {
                            ds.InitialAmount = int.Parse(initialAmountNode.Value);
                        }

                        XElement spawnUpgCost = spawnNode.Element("UpgCntCost");
                        if (spawnUpgCost != null)
                        {
                            ds.UpgCntCost = int.Parse(spawnUpgCost.Value);
                        }

                        XElement maxNode = spawnNode.Element("Max");
                        if (maxNode != null)
                        {
                            ds.Max = int.Parse(maxNode.Value);
                        }

                        ts.Defenders.Add(ds);
                    }
                }
                #endregion

                #region Upgrades (to another tower)
                XElement towerUpgradeMainNode = doc.Root.Element("Upgrades");
                if (towerUpgradeMainNode != null)
                {
                    foreach (XElement towerUpgNode in towerUpgradeMainNode.Elements())
                    {
                        ts.Upgrades.Add(new TowerUpgrade(int.Parse(towerUpgNode.Element("NewTowerID").Value),
                                                         int.Parse(towerUpgNode.Element("Cost").Value),
                                                         ts.Icon
                                                         )
                                        );
                    }
                }
                #endregion

                #region Categories
                XElement catMainNode = doc.Root.Element("Categories");
                if (catMainNode != null)
                {
                    foreach (XElement catIDNode in catMainNode.Elements())
                    {
                        ts.Categories.Add(int.Parse(catIDNode.Value));
                    }
                }
                #endregion

                #region info
                XElement infoMainNode = doc.Root.Element("Info");
                if (infoMainNode != null)
                {
                    foreach (XElement infoNode in infoMainNode.Elements())
                    {
                        ts.Info.Add(new StringBuilder(infoNode.Value));
                    }
                }
                #endregion

                #region Requirements
                XElement requiredMainNode = doc.Root.Element("Requirements");
                if (requiredMainNode != null)
                {
                    foreach (XElement requiredOrNode in requiredMainNode.Elements())
                    {
                        List <int> requirementsAND = new List <int>();
                        foreach (XElement requiredAndNode in requiredOrNode.Elements())
                        {
                            requirementsAND.Add(int.Parse(requiredAndNode.Value));
                        }
                        ts.Requirements.Add(requirementsAND);
                    }
                }
                #endregion

                Towers.Add(ts);
            }
        }