Example #1
0
        public string UpgradeToNextTower(int ID = 0)
        {
            UnitTower nextLevelTower = nextLevelTowerList[Mathf.Clamp(ID, 0, nextLevelTowerList.Count)];

            List <int> cost     = GetCost();
            int        suffCost = ResourceManager.HasSufficientResource(cost);

            if (suffCost == -1)
            {
                ResourceManager.SpendResource(cost);

                GameObject towerObj      = (GameObject)ObjectPoolManager.Spawn(nextLevelTower.gameObject, thisT.position, thisT.rotation);
                UnitTower  towerInstance = towerObj.GetComponent <UnitTower>();
                towerInstance.InitTower(instanceID);
                towerInstance.SetPlatform(occupiedPlatform, occupiedNode);
                towerInstance.AddValue(value);
                towerInstance.SetLevel(level + 1);
                towerInstance.Build();
                GameControl.SelectTower(towerInstance);

                if (onUpgradedE != null)
                {
                    onUpgradedE(towerInstance);
                }

                ObjectPoolManager.Unspawn(thisObj);

                return("");
            }
            return("Insufficient Resource");
        }
Example #2
0
        public void BuildTower(Vector3 pos, UnitTower tower)
        {
            //pathfinding related code, only call if this platform is walkable;
            if (!walkable)
            {
                return;
            }

            if (tower.type != _TowerType.Mine)
            {
                NodeTD node = PathFinder.GetNearestNode(pos, nodeGraph);
                node.walkable = false;
                tower.SetPlatform(this, node);

                //if the node has been check before during CheckForBlock(), just use the altPath
                if (node == nextBuildNode)
                {
                    for (int i = 0; i < subPathList.Count; i++)
                    {
                        if (subPathList[i].IsNodeInPath(node))
                        {
                            subPathList[i].SwitchToSubPath();
                        }
                    }
                    return;
                }

                for (int i = 0; i < subPathList.Count; i++)
                {
                    if (subPathList[i].IsNodeInPath(node))
                    {
                        subPathList[i].SearchNewPath(nodeGraph);
                    }
                }
            }
        }