Exemplo n.º 1
0
        void Construction()
        {
            if (constructRemained < 0)
            {
                return;
            }

            constructRemained -= Time.fixedDeltaTime;
            if (constructRemained <= 0)
            {
                if (constructState == _ConstructState.Sell)
                {
                    RscManager.GainRsc(GetSellValue());

                    effectSold.Spawn(GetPos(), Quaternion.identity);
                    Destroyed(false);
                }
                if (constructState == _ConstructState.Upgrade)
                {
                    effectBuilt.Spawn(GetPos(), Quaternion.identity);
                    level += 1;
                    AudioManager.OnUpgradeComplete();
                    AudioManager.PlaySound(soundBuilt);
                }
                if (constructState == _ConstructState.Build)
                {
                    effectBuilt.Spawn(GetPos(), Quaternion.identity);
                    AudioManager.OnBuildComplete();
                    AudioManager.PlaySound(soundUpgraded);
                }
            }
        }
Exemplo n.º 2
0
 public List <float> GetPurchaseCostRsc()
 {
     //float costMultiplier=PerkManager.GetPerkCostMul(prefabID);
     //List<float> costList=RscManager.ApplyMultiplier(new List<float>( costRsc ), costMultiplier);
     //return RscManager.ApplyMultiplier(costList, PerkManager.GetPerkCost(prefabID));
     return(RscManager.ApplyMultiplier(costRsc, PerkManager.GetPerkCost(prefabID)));
 }
Exemplo n.º 3
0
        public void Init()
        {
            if (Application.isPlaying && init)
            {
                return;
            }

            init = true;

            int count = RscManager.GetResourceCount();

            if (attRscGainOnCleared.Count < count)
            {
                while (attRscGainOnCleared.Count < count)
                {
                    attRscGainOnCleared.Add(new GenAttribute(true));
                }
            }
            else if (attRscGainOnCleared.Count > count)
            {
                while (attRscGainOnCleared.Count > count)
                {
                    attRscGainOnCleared.RemoveAt(attRscGainOnCleared.Count - 1);
                }
            }

            for (int i = 0; i < genItemList.Count; i++)
            {
                genItemList[i].VerifyRsc(count);
            }
        }
Exemplo n.º 4
0
        public void _Show(Ability ability, Vector3 pos, int pivotCorner = 2, Vector3 offset = default(Vector3))
        {
            SetPivot(pivotCorner);

            labelName.text = ability.name;
            labelDesp.text = ability.desp;    labelDesp.enabled = true;

            if (AbilityManager.UseRscManagerForCost())
            {
                List <float> cost = ability.GetCostRsc();
                for (int i = 0; i < RscManager.GetResourceCount(); i++)
                {
                    rscItemList[i].imgMain.sprite = RscManager.GetRscIcon(i);
                    rscItemList[i].lbMain.text    = cost[i].ToString("f0");
                    rscItemList[i].SetActive(true);
                }
            }
            else
            {
                rscItemList[0].imgMain.sprite = AbilityDB.GetRscIcon();
                rscItemList[0].lbMain.text    = ability.GetCost().ToString("f0");
                for (int i = 1; i < RscManager.GetResourceCount(); i++)
                {
                    rscItemList[i].SetActive(false);
                }
            }

            minHeight = 120;

            rectT.position = pos + offset;

            canvasGroup.alpha = 1;
            thisObj.SetActive(true);
        }
Exemplo n.º 5
0
        public void _ShowUpgrade(UnitTower tower, int uIdx, Vector3 pos, int pivotCorner = 2, Vector3 offset = default(Vector3))
        {
            SetPivot(pivotCorner);

            if (tower.GetUpgradeType() == 0)
            {
                labelName.text = "Upgrade";
            }
            else
            {
                labelName.text = "Upgrade to" + tower.GetUpgradeTower(uIdx).unitName;
            }

            labelDesp.enabled = false;

            List <float> cost = tower.GetUpgradeCost(uIdx);

            for (int i = 0; i < RscManager.GetResourceCount(); i++)
            {
                rscItemList[i].imgMain.sprite = RscManager.GetRscIcon(i);
                rscItemList[i].lbMain.text    = cost[i].ToString("f0");
            }

            minHeight      = -1;
            rectT.position = pos + offset;

            canvasGroup.alpha = 1;
            thisObj.SetActive(true);
        }
Exemplo n.º 6
0
        public void Activate(Vector3 pos = default(Vector3))
        {
            useCount += 1;
            currentCD = GetCooldown();

            if (AbilityManager.UseRscManagerForCost())
            {
                RscManager.SpendRsc(GetCostRsc());
            }
            else
            {
                AbilityManager.SpendRsc(GetCost());
            }


            effectOnActivate.Spawn(pos, Quaternion.identity);
            AudioManager.PlaySound(soundOnActivate);


            //activateCallback();
            if (effectType != _EffectType.Default)
            {
                return;
            }

            AbilityManager.GetInstance().StartCoroutine(AbilityEffect(pos));
        }
Exemplo n.º 7
0
        public static void EndGame()
        {
            if (instance.gameState == _GameState.Over)
            {
                return;
            }

            instance.playerWon = instance.life > 0;
            instance.gameState = _GameState.Over;

            if (instance.playerWon)
            {
                RscManager.GainRsc(instance.rscGainOnWin);
                PerkManager.GainRsc(instance.perkRscGainOnWin);

                RscManager.CachedRsc();                         //for rsc to be carry forth to next level
                PerkManager.CachedProgress();                   //for perk progress to be carry forth to next level
                AudioManager.OnPlayerWon();
            }
            else
            {
                AudioManager.OnPlayerLost();
            }

            Debug.Log("Game Over " + instance.playerWon + "    " + instance.gameState);
            TDTK.OnGameOver(instance.playerWon);
        }
Exemplo n.º 8
0
 public void Test()
 {
     if (sInfo.HasValidPoint() && sInfo.AvailableForBuild() && sInfo.CanBuildTower(dndTower.prefabID))
     {
         if (RscManager.HasSufficientRsc(dndTower.GetCost()))
         {
             RscManager.SpendRsc(dndTower.GetCost());
             Debug.Log("buy");
             SelectControl.ClearUnit();
             if (!UseFreeFormMode())
             {
                 AddTower(dndTower, sInfo.platform, sInfo.nodeID);
             }
             else
             {
                 AddTower(dndTower, CreatePlatformForTower(dndTower, GetGridSize()), 0);
             }
             dndTower.Build();       dndTower = null;  dndCooldown = Time.time;
         }
         else
         {
             GameControl.InvalidAction("Insufficient Resources");
             _ExitDragNDropPhase();
         }
     }
     else
     {
         GameControl.InvalidAction("Invalid Build Point");
         _ExitDragNDropPhase();
     }
 }
Exemplo n.º 9
0
 public List <int> GetRsc(UnitCreep unit, List <int> overrideList = null)
 {
     if (mulRsc >= 0)
     {
         overrideList = RscManager.ApplyMultiplier(new List <int>(unit.rscGainOnDestroyed), mulRsc);
     }
     return(overrideList);
 }
Exemplo n.º 10
0
        public List <float> GetRscGain()
        {
            List <float> list = RscManager.ApplyModifier(new List <float>(statsList[level].rscGain), activeEffectMod.stats.rscGain);

            list = RscManager.ApplyModifier(list, PerkManager.GetModUnitRscGain(prefabID));

            list = RscManager.ApplyModifier(list, activeEffectMul.stats.rscGain);
            return(RscManager.ApplyModifier(list, PerkManager.GetMulUnitRscGain(prefabID)));
        }
Exemplo n.º 11
0
 private bool CheckCost(List <float> cost)
 {
     if (!RscManager.HasSufficientRsc(cost))
     {
         Debug.Log("Insufficient resources");
         return(false);
     }
     return(true);
 }
Exemplo n.º 12
0
 private bool CheckCost(List <float> cost)
 {
     if (!RscManager.HasSufficientRsc(cost))
     {
         //Debug.Log("Insufficient resources");
         GameControl.InvalidAction("Insufficient resources");
         return(false);
     }
     return(true);
 }
Exemplo n.º 13
0
 public bool HasSufficientRsc()
 {
     if (PerkManager.UseRscManagerForCost())
     {
         return(RscManager.HasSufficientRsc(costRsc));
     }
     else
     {
         return(PerkManager.HasSufficientRsc(cost));
     }
 }
Exemplo n.º 14
0
        //modifier
        public static List <float> GetModAbilityCostRsc(int prefabID, List <float> modList = null)
        {
            List <float> baseList = new List <float>(defaultRsclistMod);

            for (int i = 0; i < uPIDList.Count; i++)
            {
                modList  = GetPerk(uPIDList[i]).GetModCostRsc(prefabID);
                baseList = RscManager.ApplyModifier(baseList, modList);
            }
            return(baseList);
        }
Exemplo n.º 15
0
        //multiplier
        public static List <float> GetMulUnitCost(int prefabID, List <float> mulList = null)
        {
            List <float> baseList = new List <float>(defaultRsclistMul);

            for (int i = 0; i < uPIDList.Count; i++)
            {
                mulList  = GetPerk(uPIDList[i]).GetMulCostRsc(prefabID);
                baseList = RscManager.ApplyMultiplier(baseList, mulList);
            }
            return(baseList);
        }
Exemplo n.º 16
0
        public static List <float> GetPerkCost(int prefabID, List <float> itemList = null)
        {
            List <float> baseList = new List <float>(defaultRsclistMul);

            for (int i = 0; i < pPIDList.Count; i++)
            {
                itemList = GetPerk(pPIDList[i]).GetCost(prefabID);
                baseList = RscManager.ApplyMultiplier(baseList, itemList);
            }
            return(baseList);
        }
Exemplo n.º 17
0
        public void Cleared()
        {
            cleared = true;

            GameControl.GainLife(PerkManager.GetLifeGainOnWaveCleared(lifeGainOnCleared));
            RscManager.GainRsc(rscGainOnCleared, RscManager._GainType.WaveCleared);
            PerkManager.GainRsc(perkRscGainOnCleared);
            AbilityManager.GainRsc(PerkManager.GetAbRscGainOnWaveCleared(abilityRscGainOnCleared));

            PerkManager.WaveCleared(waveIdx + 1);
        }
Exemplo n.º 18
0
 public static bool Init()
 {
     if (instance != null)
     {
         return(true);
     }
     instance = (RscManager)FindObjectOfType(typeof(RscManager));
     if (instance == null)
     {
         Debug.LogWarning("No RscManager in scene!"); return(false);
     }
     return(true);
 }
Exemplo n.º 19
0
        //fixed update for resource, aoe and mine, check '#region support tower' for support
        void TowerFunction()
        {
            if (!GameControl.HasGameStarted())
            {
                return;
            }
            if (InConstruction() || IsStunned() || IsDestroyed())
            {
                return;
            }

            //if(GameControl.HasGameStarted() && !GameControl.IsGamePaused()) cooldown-=Time.fixedDeltaTime;
            if (cooldown > 0)
            {
                return;
            }

            if (IsResource())            // && cooldownRsc<0){
            {
                RscManager.GainRsc(GetRscGain(), RscManager._GainType.RscTower);
                cooldown = GetCooldown();              //cooldownRsc=GetCooldown();
            }

            if (IsAOE())            // && cooldownAOE<0){
            {
                List <Unit> tgtList = SpawnManager.GetUnitsWithinRange(this, GetAttackRange(), GetTargetGroup());
                if (tgtList.Count > 0)
                {
                    cooldown = GetCooldown();                  //cooldownAOE=GetCooldown();
                    for (int i = 0; i < tgtList.Count; i++)
                    {
                        tgtList[i].ApplyAttack(new AttackInfo(this, tgtList[i]));
                    }
                }
                else
                {
                    cooldown = 0.1f;               //cooldownAOE=0.1f;
                }
            }

            if (IsMine())            // && cooldownAttack<0){
            {
                List <Unit> tgtList = SpawnManager.GetUnitsWithinRange(this, TowerManager.GetGridSize() * .25f, GetTargetGroup());
                if (tgtList.Count > 0)
                {
                    tgtList[0].ApplyAttack(new AttackInfo(this, tgtList[0]));
                    Destroyed();
                }
                cooldown = 0.1f;              //cooldownAttack=0.1f;
            }
        }
Exemplo n.º 20
0
 public List <float> GetUpgradeCost(int upgradeIdx = 0)
 {
     if (GetUpgradeType() == 0)           //return statsList[level+1].cost;
     //return RscManager.ApplyMultiplier(new List<float>( statsList[level+1].cost ), PerkManager.GetUnitCost(prefabID));
     {
         List <float> list = RscManager.ApplyModifier(new List <float>(statsList[level + 1].cost), PerkManager.GetModUnitCost(prefabID));
         return(RscManager.ApplyMultiplier(list, PerkManager.GetMulUnitCost(prefabID)));
     }
     else              //return upgradeTowerList[upgradeIdx].GetCost();
                       //~ return RscManager.ApplyMultiplier(new List<float>( upgradeTowerList[upgradeIdx].GetCost() ), PerkManager.GetUnitCost(upgradeTowerList[upgradeIdx].prefabID));
     {
         return(upgradeTowerList[upgradeIdx].GetCost(0));
     }
 }
Exemplo n.º 21
0
        public List <float> GetCost(int lvl = -1)
        {
            if (lvl < 0)
            {
                lvl = level;
            }
            //List<float> list=new List<float>(statsList[level].cost);
            //List<float> listMod=PerkManager.GetModUnitCost(prefabID);
            //List<float> listMul=PerkManager.GetMulUnitCost(prefabID);
            List <float> list = RscManager.ApplyModifier(new List <float>(statsList[lvl].cost), PerkManager.GetModUnitCost(prefabID));

            return(RscManager.ApplyMultiplier(list, PerkManager.GetMulUnitCost(prefabID)));

            //return RscManager.ApplyMultiplier(new List<float>( statsList[level].cost ), PerkManager.GetUnitCost(prefabID));
        }
Exemplo n.º 22
0
 public void Upgrade(int upgradeIdx = 0)
 {
     if (GetUpgradeType() == 0)
     {
         RscManager.SpendRsc(GetUpgradeCost(0));
         Build(true);
     }
     else
     {
         TowerManager.RemoveTower(this);
         if (buildPlatform != null)
         {
             buildPlatform.RemoveTower(nodeID);
         }
         TowerManager.BuildTower(upgradeTowerList[upgradeIdx], buildPlatform, nodeID);
         Destroy(thisObj);
     }
 }
Exemplo n.º 23
0
        public override void Destroyed(bool spawnEffDestroyed = true)
        {
            path.OnCreepExit(this);

            if (spawnEffDestroyed)
            {
                effectDestroyed.Spawn(GetPos(), Quaternion.identity);
                AudioManager.PlaySound(soundDestroyed);
            }

            if (IsSupport())
            {
                SupportClearAllTarget();
            }

            if (spawnOnDestroyed != null && sodCount > 0)
            {
                float      oHP  = sodOverride.GetHP(this);
                float      oSH  = sodOverride.GetSH(this);
                float      oSpd = sodOverride.GetSpd(this);
                int        oExp = sodOverride.GetExp(this);
                List <int> oRsc = sodOverride.GetRsc(this, rscGainOnDestroyed);

                for (int i = 0; i < sodCount; i++)
                {
                    SpawnSubCreep(spawnOnDestroyed, oHP, oSH, oSpd, oExp, oRsc);
                }
            }

            ClearAllEffect();

            if (Random.value < lifeGainedOnDestroyedChance)
            {
                GameControl.GainLife(lifeGainedOnDestroyed);
            }
            RscManager.GainRsc(rscGainOnDestroyed, RscManager._GainType.CreepKilled);

            float animDuration = AnimPlayDestroyed();

            SpawnManager.CreepDestroyed(this);
            ObjectPoolManager.Unspawn(thisObj, animDuration);
            //Destroy(thisObj);
        }
Exemplo n.º 24
0
        void Awake()
        {
            if (instance != null && instance != this)
            {
                Debug.LogWarning("Multiple RscManager in scene! ");
                return;
            }

            rscItemList = new List <RscItem>(RscDB.GetList());
            if (rscItemList.Count != rscList.Count)
            {
                while (rscList.Count < rscItemList.Count)
                {
                    rscList.Add(0);
                }
                while (rscList.Count > rscItemList.Count)
                {
                    rscList.RemoveAt(rscList.Count - 1);
                }
            }

            for (int i = 0; i < rscItemList.Count; i++)
            {
                regenModList.Add(rscItemList[i].regenRate);
                regenMulList.Add(rscItemList[i].regenRateMultiplier);
                regenCachedList.Add(0);
            }

            if (carryOver && cachedList.Count == rscList.Count)
            {
                for (int i = 0; i < rscList.Count; i++)
                {
                    if (!rscItemList[i].enableCarry)
                    {
                        continue;
                    }
                    rscList[i] = cachedList[i];
                }
            }

            instance = this;
        }
Exemplo n.º 25
0
        void Start()
        {
            defaultRsclistMod = new List <float>();
            defaultRsclistMul = new List <float>();

            rscGainModList            = new List <int>();
            rscGainModCreepKilledList = new List <int>();
            rscGainModWaveClearedList = new List <int>();
            rscGainModRscTowerList    = new List <int>();

            rscGainMulList            = new List <float>();
            rscGainMulCreepKilledList = new List <float>();
            rscGainMulWaveClearedList = new List <float>();
            rscGainMulRscTowerList    = new List <float>();

            for (int i = 0; i < RscManager.GetResourceCount(); i++)
            {
                defaultRsclistMod.Add(0);
                defaultRsclistMul.Add(1);

                rscGainModList.Add(0);
                rscGainModCreepKilledList.Add(0);
                rscGainModWaveClearedList.Add(0);
                rscGainModRscTowerList.Add(0);

                rscGainMulList.Add(1);
                rscGainMulCreepKilledList.Add(1);
                rscGainMulWaveClearedList.Add(1);
                rscGainMulRscTowerList.Add(1);
            }

            for (int i = 0; i < perkList.Count; i++)
            {
                if (!purchasedPrefabIDList.Contains(perkList[i].prefabID))
                {
                    continue;
                }
                _PurchasePerk(i, false);
            }

            WaveCleared(0);
        }
Exemplo n.º 26
0
 public _Status IsReady()
 {
     if (currentCD > 0)
     {
         return(_Status.OnCooldown);
     }
     if (UseLimitReached())
     {
         return(_Status.UseLimitReached);
     }
     if (AbilityManager.UseRscManagerForCost() && !RscManager.HasSufficientRsc(GetCostRsc()))
     {
         return(_Status.InsufficientRsc);
     }
     if (!AbilityManager.UseRscManagerForCost() && !AbilityManager.HasSufficientRsc(GetCost()))
     {
         return(_Status.InsufficientRsc);
     }
     return(_Status.Ready);
 }
Exemplo n.º 27
0
        public static void BuildTower(UnitTower prefab, BuildPlatform platform, int nodeID, bool useRsc = true)
        {
            Debug.Log("BuildTower  " + prefab);

            if (useRsc)
            {
                if (!RscManager.HasSufficientRsc(prefab.GetCost()))
                {
                    Debug.Log("Insufficient resources");
                    return;
                }
                Debug.Log("Get cost " + prefab.GetCost()[0]);
                RscManager.SpendRsc(prefab.GetCost());
            }

            NodeTD     node  = platform.GetNode(nodeID);
            GameObject obj   = (GameObject)Instantiate(prefab.gameObject, node.pos, platform.GetRot() * Quaternion.Euler(-90, 0, 0));
            UnitTower  tower = obj.GetComponent <UnitTower>();

            AddTower(tower, platform, nodeID);
        }
Exemplo n.º 28
0
        public void _ShowSell(UnitTower tower, Vector3 pos, int pivotCorner = 2, Vector3 offset = default(Vector3))
        {
            SetPivot(pivotCorner);

            labelName.text    = "Sell " + tower.unitName;
            labelDesp.enabled = false;

            List <float> cost = tower.GetSellValue();

            for (int i = 0; i < RscManager.GetResourceCount(); i++)
            {
                rscItemList[i].imgMain.sprite = RscManager.GetRscIcon(i);
                rscItemList[i].lbMain.text    = cost[i].ToString("f0");
            }

            minHeight      = -1;
            rectT.position = pos + offset;

            canvasGroup.alpha = 1;
            thisObj.SetActive(true);
        }
Exemplo n.º 29
0
        public override void Start()
        {
            base.Start();

            for (int i = 0; i < RscManager.GetResourceCount(); i++)
            {
                if (i > 0)
                {
                    rscItemList.Add(new UIObject(UI.Clone(rscItemList[0].rootObj)));
                }
                rscItemList[i].Init();
                rscItemList[i].imgMain.sprite = RscManager.GetRscIcon(i);
            }

            rectName = labelName.gameObject.GetComponent <RectTransform>();
            rectDesp = labelDesp.gameObject.GetComponent <RectTransform>();

            canvasGroup.alpha          = 0;
            canvasGroup.interactable   = false;
            canvasGroup.blocksRaycasts = false;
            //thisObj.SetActive(false);
        }
Exemplo n.º 30
0
        public static void SaveGeneralProgress()
        {
            //level progress
            PlayerPrefs.SetInt("TDTK_HighestLvlID", GameControl.GetHighestLevelID());

            //resource
            List <int> rscList = RscManager.GetCachedList();

            PlayerPrefs.SetInt("TDTK_RscCount", rscList.Count);
            for (int i = 0; i < rscList.Count; i++)
            {
                PlayerPrefs.SetInt("TDTK_Rsc_" + i, rscList[i]);
            }

            //Perk
            PlayerPrefs.SetInt("TDTK_PerkRsc", PerkManager.GetCachedRsc());
            List <int> perkList = PerkManager.GetCachedPurchasedIDList();

            PlayerPrefs.SetInt("TDTK_PerkCount", perkList.Count);
            for (int i = 0; i < perkList.Count; i++)
            {
                PlayerPrefs.SetInt("TDTK_PerkID_" + i, perkList[i]);
            }
        }