示例#1
0
        public void Init()
        {
            if (init)
            {
                return;
            }

            init = true;

            if (instance != null)
            {
                Destroy(gameObject);
                return;
            }

            instance = this;

            //load your custom/saved purchasedIDList here if you are doing a persistent perk system

            List <Perk> dbList = PerkDB.Load();

            for (int i = 0; i < dbList.Count; i++)
            {
                if (!unavailableIDList.Contains(dbList[i].ID))
                {
                    Perk perk = dbList[i].Clone();
                    perkList.Add(perk);
                }
            }

            globalTowerModifier     = new PerkTowerModifier();
            globalAbilityModifier   = new PerkAbilityModifier();
            globalFPSWeaponModifier = new PerkFPSWeaponModifier();

            emptyTowerModifier     = new PerkTowerModifier();
            emptyAbilityModifier   = new PerkAbilityModifier();
            emptyFPSWeaponModifier = new PerkFPSWeaponModifier();

            int rscCount = ResourceManager.GetResourceCount();

            for (int i = 0; i < rscCount; i++)
            {
                rscRegen.Add(0);
                rscGain.Add(0);
                rscCreepKilledGain.Add(0);
                rscWaveClearedGain.Add(0);
                rscRscTowerGain.Add(0);
            }

            for (int i = 0; i < perkList.Count; i++)
            {
                if (purchasedIDList.Contains(perkList[i].ID))
                {
                    if (perkList[i].type == _PerkType.NewTower || perkList[i].type == _PerkType.NewAbility || perkList[i].type == _PerkType.NewFPSWeapon)
                    {
                        StartCoroutine(DelayPurchasePerk(perkList[i]));
                    }
                    else
                    {
                        _PurchasePerk(perkList[i], false);                      //dont use rsc since these are pre-purchased perk
                    }
                }
            }

            if (persistantProgress)
            {
                transform.parent = null;
                DontDestroyOnLoad(gameObject);
            }
        }
示例#2
0
        public string _PurchasePerk(Perk perk, bool useRsc = true)
        {
            string text = perk.Purchase(useRsc);

            if (text != "")
            {
                return(text);
            }

            if (onPerkPurchasedE != null)
            {
                onPerkPurchasedE(perk);
            }

            //process the prereq for other perk
            for (int i = 0; i < perkList.Count; i++)
            {
                Perk perkTemp = perkList[i];
                if (perkTemp.purchased || perkTemp.prereq.Count == 0)
                {
                    continue;
                }
                perkTemp.prereq.Remove(perk.ID);
            }


            perkPoint += 1;
            if (onPerkPointE != null)
            {
                onPerkPointE(perkPoint);
            }

            if (perk.type == _PerkType.NewTower)
            {
                List <UnitTower> towerList = TowerDB.Load();
                for (int i = 0; i < towerList.Count; i++)
                {
                    if (towerList[i].prefabID == perk.itemIDList[0])
                    {
                        unlockedTower.Add(towerList[i]);
                        BuildManager.AddNewTower(towerList[i]);
                    }
                }
            }
            else if (perk.type == _PerkType.NewAbility)
            {
                List <Ability> abilityList = AbilityDB.Load();
                for (int i = 0; i < abilityList.Count; i++)
                {
                    if (abilityList[i].ID == perk.itemIDList[0])
                    {
                        unlockedAbility.Add(abilityList[i]);
                        AbilityManager.AddNewAbility(abilityList[i]);
                    }
                }
            }
            else if (perk.type == _PerkType.NewFPSWeapon)
            {
                List <FPSWeapon> FPSWeaponList = FPSWeaponDB.Load();
                for (int i = 0; i < FPSWeaponList.Count; i++)
                {
                    if (FPSWeaponList[i].prefabID == perk.itemIDList[0])
                    {
                        unlockedWeapon.Add(FPSWeaponList[i]);
                        FPSControl.AddNewWeapon(FPSWeaponList[i]);
                    }
                }
            }

            else if (perk.type == _PerkType.GainLife)
            {
                GameControl.GainLife((int)Random.Range(perk.value, perk.valueAlt));
            }
            else if (perk.type == _PerkType.LifeCap)
            {
                lifeCap += (int)perk.value; GameControl.GainLife(0);
            }
            else if (perk.type == _PerkType.LifeRegen)
            {
                lifeRegen += perk.value;
            }
            else if (perk.type == _PerkType.LifeWaveClearedBonus)
            {
                lifeWaveClearedBonus += (int)perk.value;
            }

            else if (perk.type == _PerkType.GainRsc)
            {
                List <int> valueList = new List <int>();
                for (int i = 0; i < perk.valueRscList.Count; i++)
                {
                    valueList.Add((int)perk.valueRscList[i]);
                }
                ResourceManager.GainResource(valueList, null, false);                   //dont pass multiplier and dont use multiplier
            }
            else if (perk.type == _PerkType.RscRegen)
            {
                for (int i = 0; i < perk.valueRscList.Count; i++)
                {
                    rscRegen[i] += perk.valueRscList[i];
                }
            }
            else if (perk.type == _PerkType.RscGain)
            {
                for (int i = 0; i < perk.valueRscList.Count; i++)
                {
                    rscGain[i] += perk.valueRscList[i];
                }
            }
            else if (perk.type == _PerkType.RscCreepKilledGain)
            {
                for (int i = 0; i < perk.valueRscList.Count; i++)
                {
                    rscCreepKilledGain[i] += perk.valueRscList[i];
                }
            }
            else if (perk.type == _PerkType.RscWaveClearedGain)
            {
                for (int i = 0; i < perk.valueRscList.Count; i++)
                {
                    rscWaveClearedGain[i] += perk.valueRscList[i];
                }
            }
            else if (perk.type == _PerkType.RscResourceTowerGain)
            {
                for (int i = 0; i < perk.valueRscList.Count; i++)
                {
                    rscRscTowerGain[i] += perk.valueRscList[i];
                }
            }

            else if (perk.type == _PerkType.Tower)
            {
                ModifyTowerModifier(globalTowerModifier, perk);
            }
            else if (perk.type == _PerkType.TowerSpecific)
            {
                for (int i = 0; i < perk.itemIDList.Count; i++)
                {
                    int ID = TowerModifierExist(perk.itemIDList[i]);
                    if (ID == -1)
                    {
                        PerkTowerModifier towerModifier = new PerkTowerModifier();
                        towerModifier.prefabID = perk.itemIDList[i];
                        towerModifierList.Add(towerModifier);
                        ID = towerModifierList.Count - 1;
                    }
                    ModifyTowerModifierInList(ID, perk);
                }
            }
            else if (perk.type == _PerkType.Ability)
            {
                ModifyAbilityModifier(globalAbilityModifier, perk);
            }
            else if (perk.type == _PerkType.AbilitySpecific)
            {
                for (int i = 0; i < perk.itemIDList.Count; i++)
                {
                    int ID = AbilityModifierExist(perk.itemIDList[i]);
                    if (ID == -1)
                    {
                        PerkAbilityModifier abilityModifier = new PerkAbilityModifier();
                        abilityModifier.abilityID = perk.itemIDList[i];
                        abilityModifierList.Add(abilityModifier);
                        ID = abilityModifierList.Count - 1;
                    }
                    ModifyAbilityModifierInList(ID, perk);
                }
            }
            else if (perk.type == _PerkType.FPSWeapon)
            {
                ModifyFPSWeaponModifier(globalFPSWeaponModifier, perk);
            }
            else if (perk.type == _PerkType.FPSWeaponSpecific)
            {
                for (int i = 0; i < perk.itemIDList.Count; i++)
                {
                    int ID = FPSWeaponModifierExist(perk.itemIDList[i]);
                    if (ID == -1)
                    {
                        PerkFPSWeaponModifier weaponModifier = new PerkFPSWeaponModifier();
                        weaponModifier.prefabID = perk.itemIDList[i];
                        FPSWeaponModifierList.Add(weaponModifier);
                        ID = FPSWeaponModifierList.Count - 1;
                    }
                    ModifyFPSWeaponModifierInList(ID, perk);
                }
            }

            else if (perk.type == _PerkType.EnergyRegen)
            {
                energyRegen += perk.value;
            }
            else if (perk.type == _PerkType.EnergyIncreaseCap)
            {
                energyCap += perk.value;
            }
            else if (perk.type == _PerkType.EnergyCreepKilledBonus)
            {
                energyCreepKilledBonus += perk.value;
            }
            else if (perk.type == _PerkType.EnergyWaveClearedBonus)
            {
                energyWaveClearedBonus += perk.value;
            }

            return("");
        }