예제 #1
0
        //called by any external component to build tower, uses buildInfo
        public static string BuildTower(UnitTower tower)
        {
            if (buildInfo == null)
            {
                return("Select a Build Point First");
            }

            UnitTower sampleTower = GetSampleTower(tower);

            //check if there are sufficient resource
            List <int> cost     = sampleTower.GetCost();
            int        suffCost = ResourceManager.HasSufficientResource(cost);

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

                GameObject towerObj      = (GameObject)Instantiate(tower.gameObject, buildInfo.position, buildInfo.platform.thisT.rotation);
                UnitTower  towerInstance = towerObj.GetComponent <UnitTower>();
                towerInstance.InitTower(instance.towerCount += 1);
                towerInstance.Build();

                //clear the build info and indicator for build manager
                ClearBuildPoint();

                return("");
            }

            return("Insufficient Resource");
        }
예제 #2
0
        public string Upgrade(int ID = 0)               //ID specify which nextTower to use
        {
            if (nextLevelTowerList.Count == 0 && currentActiveStat >= stats.Count - 1)
            {
                return("Tower is at maximum level!");
            }

            List <int> cost = GetCost();

            if (ResourceManager.HasSufficientResource(GetCost()) >= 0)
            {
                return("Insufficient Resource");
            }
            ResourceManager.SpendResource(cost);

            if (currentActiveStat < stats.Count - 1)
            {
                return(UpgradeToNextStat());
            }
            else if (nextLevelTowerList.Count > 0)
            {
                return(UpgradeToNextTower(ID));
            }
            return("");
        }
예제 #3
0
        public string Purchase(bool useRsc = true)
        {
            if (purchased)
            {
                return("Purchased");
            }

            if (useRsc)
            {
                int temp = ResourceManager.HasSufficientResource(cost);
                if (temp != -1)
                {
                    return("Insufficient " + ResourceManager.GetResourceList()[temp].name);
                }
                ResourceManager.SpendResource(cost);
            }

            if (!repeatable)
            {
                purchased = true;
            }
            purchasedCount += 1;

            return("");
        }
예제 #4
0
        public bool UpgradeToNextTower(int ID = 0)
        {
            UnitTower nextLevelTower = nextLevelTowerList[Mathf.Clamp(ID, 0, nextLevelTowerList.Count)];

            int  cost       = GetCost();
            bool isSuffCost = ResourceManager.HasSufficientResource(cost);

            if (isSuffCost == true)
            {
                ResourceManager.SpendResource(cost);

                GameObject towerObj      = (GameObject)Instantiate(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);
                }
                Destroy(thisObj);
                return(true);
            }
            return(false);
            //"Insufficient Resource";
        }
예제 #5
0
        public bool _BuildTowerDragNDrop(UnitTower tower)
        {
            if (tower.type == _TowerType.Resource && !GameControl.IsGameStarted())
            {
                return(false);
                // "Cant Build Tower before spawn start";
            }

            UnitTower sampleTower = GetSampleTower(tower);
            int       cost        = sampleTower.GetCost();

            bool isSuffCost = ResourceManager.HasSufficientResource(cost);

            if (isSuffCost == true)
            {
                sampleTower.thisObj.SetActive(true);
                _ShowPlatform(true);
                GameControl.SelectTower(sampleTower);
                UnitTower towerInstance = sampleTower;
                towerInstance.StartCoroutine(towerInstance.DragNDropRoutine());
                return(true);
            }

            return(false);
            //"Insufficient Resource";
        }
예제 #6
0
        //called when a tower building is initated in DragNDrop, use the sample tower as the model and set it in DragNDrop mode
        public string StartDragNDrop(int ID, int pointerID = -1)
        {
            UnitTower sampleTower = GetSampleTower(ID);

            if (sampleTower.type == _TowerType.Resource && !GameControl.IsGameStarted())
            {
                return("Cant Build Tower before spawn start");
            }

            IndicatorControl.SetDragNDropPhase(true);

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

            if (suffCost == -1)
            {
                sampleTower.thisT.position = new Vector3(9999, 9999, 9999);
                sampleTower.thisObj.SetActive(true);

                UnitTower towerInstance = sampleTower;

                towerInstance.StartCoroutine(towerInstance.DragNDropRoutine(pointerID));

                return("");
            }

            return("Insufficient Resource   " + suffCost);
        }
예제 #7
0
        public static string _BuildTower(UnitTower tower, BuildInfo bInfo)              //called from UnitTower.DragNDropRoutine
        {
            if (bInfo == null)
            {
                if (!UseDragNDrop())
                {
                    return("Select a Build Point First");
                }
                else
                {
                    return("Invalid build position");
                }
            }

            if (bInfo.status != _TileStatus.Available)
            {
                return("Invalid build position");
            }

            //dont allow building of resource tower before game started
            if (tower.type == _TowerType.Resource && !GameControl.IsGameStarted())
            {
                return("Cant Build Tower before spawn start");
            }

            UnitTower sampleTower = GetSampleTower(tower);

            //check if there are sufficient resource
            List <int> cost     = sampleTower.GetCost();
            int        suffCost = ResourceManager.HasSufficientResource(cost);

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

                GameObject towerObj      = (GameObject)Instantiate(tower.gameObject, bInfo.position, bInfo.platform.thisT.rotation);
                UnitTower  towerInstance = towerObj.GetComponent <UnitTower>();
                towerInstance.InitTower(instance.towerCount += 1);
                towerInstance.Build();

                //if(bInfo.platform!=null) towerObj.transform.parent=bInfo.platform.transform;

                //register the tower to the platform
                if (bInfo.platform != null)
                {
                    bInfo.platform.BuildTower(bInfo.position, towerInstance);
                }

                //clear the build info and indicator for build manager
                //ClearBuildIndicator();
                IndicatorControl.ClearBuildTileIndicator();

                return("");
            }

            return("Insufficient Resource");
        }
예제 #8
0
        public string _BuildTowerDragNDrop(UnitTower tower)
        {
            UnitTower  sampleTower = GetSampleTower(tower);
            List <int> cost        = sampleTower.GetCost();

            int suffCost = ResourceManager.HasSufficientResource(cost);

            if (suffCost == -1)
            {
                sampleTower.thisObj.SetActive(true);
                GameControl.SelectTower(sampleTower);
                UnitTower towerInstance = sampleTower;
                towerInstance.StartCoroutine(towerInstance.DragNDropRoutine());

                return("");
            }

            return("Insufficient Resource   " + suffCost);
        }
예제 #9
0
        //called by any external component to build tower, uses buildInfo
        public static string BuildTower(UnitTower tower)
        {
            if (buildInfo == null)
            {
                return("Select a Build Point First");
            }

            //dont allow building of resource tower before game started
            if (tower.type == _TowerType.Resource && !GameControl.IsGameStarted())
            {
                return("Cant Build Tower before spawn start");
            }

            UnitTower sampleTower = GetSampleTower(tower);

            //check if there are sufficient resource
            List <int> cost     = sampleTower.GetCost();
            int        suffCost = ResourceManager.HasSufficientResource(cost);

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

                GameObject towerObj      = (GameObject)Instantiate(tower.gameObject, buildInfo.position, buildInfo.platform.thisT.rotation);
                UnitTower  towerInstance = towerObj.GetComponent <UnitTower>();
                towerInstance.InitTower(instance.towerCount += 1);
                towerInstance.Build();

                //register the tower to the platform
                if (buildInfo.platform != null)
                {
                    buildInfo.platform.BuildTower(buildInfo.position, towerInstance);
                }

                //clear the build info and indicator for build manager
                ClearBuildPoint();

                return("");
            }

            return("Insufficient Resource");
        }
예제 #10
0
        public string UpgradeToNextStat()
        {
            List <int> cost     = GetCost();
            int        suffCost = ResourceManager.HasSufficientResource(cost);

            if (suffCost == -1)
            {
                level             += 1;
                currentActiveStat += 1;
                ResourceManager.SpendResource(cost);
                AddValue(stats[currentActiveStat].cost);
                Build();

                if (onUpgradedE != null)
                {
                    onUpgradedE(this);
                }
                return("");
            }
            return("금액 부족");
        }
예제 #11
0
        public bool UpgradeToNextStat()
        {
            int  cost       = GetCost();
            bool isSuffCost = ResourceManager.HasSufficientResource(cost);

            if (isSuffCost == true)
            {
                level             += 1;
                currentActiveStat += 1;
                ResourceManager.SpendResource(cost);
                AddValue(stats[currentActiveStat].cost);
                Build();

                if (onUpgradedE != null)
                {
                    onUpgradedE(this);
                }
                return(true);
            }
            return(false);
            //"Insufficient Resource";
        }
예제 #12
0
        //called by any external component to build tower, uses buildInfo
        public static string BuildTower(UnitTower tower)
        {
            if (buildInfo == null)
            {
                return("Select a Build Point First");
            }

            UnitTower sampleTower = GetSampleTower(tower);

            /***/
            // check if there's energy reciving tower
            if (tower.electricityNeeded && !tower.electricityReciever && !tower.electricityFacility)
            {
                LayerMask maskTarget = 1 << LayerManager.LayerTower();

                Collider[] cols = Physics.OverlapSphere(buildInfo.position, 1000 /*GetRange()*/, maskTarget);

                if (cols.Length > 0)
                {
                    tower.electicitySources.Clear();
                    // find all electric facility
                    for (int i = 0; i < cols.Length; i++)
                    {
                        // if it's not electric reciever skip
                        if (!cols[i].gameObject.GetComponent <UnitTower>().electricityReciever)
                        {
                            continue;
                        }

                        //float test = cols[i].gameObject.GetComponent<UnitTower>().GetRange();
                        //float test2 = Vector3.Distance(cols[i].gameObject.GetComponent<UnitTower>().transform.position, buildInfo.position);

                        // if this tower is in range of electricityReciever
                        if (Vector3.Distance(cols[i].gameObject.GetComponent <UnitTower>().transform.position, buildInfo.position) <= cols[i].gameObject.GetComponent <UnitTower>().GetRange())
                        {
                            tower.electicitySources.Add(cols[i].gameObject.GetComponent <UnitTower>());
                        }
                    }

                    if (tower.electicitySources.Count == 0)
                    {
                        // set electricity source for tower weapon
                        return("There is not enough electricity");
                    }
                }
                else
                {
                    return("There is not enough electricity");
                }
            }
            /***/


            //check if there are sufficient resource
            List <int> cost     = sampleTower.GetCost();
            int        suffCost = ResourceManager.HasSufficientResource(cost);

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

                GameObject towerObj      = (GameObject)Instantiate(tower.gameObject, buildInfo.position, buildInfo.platform.thisT.rotation);
                UnitTower  towerInstance = towerObj.GetComponent <UnitTower>();
                towerInstance.InitTower(instance.towerCount += 1, buildInfo.platform);
                towerInstance.Build();



                // if new electricity reciver is placed search for all towers in it's range and add itself as electricity source
                if (tower.electricityReciever)
                {
                    LayerMask maskTarget = 1 << LayerManager.LayerTower();

                    Collider[] cols = Physics.OverlapSphere(buildInfo.position, tower.GetRange(), maskTarget);

                    if (cols.Length > 0)
                    {
                        UnitTower tmp_tow;
                        for (int i = 0; i < cols.Length; i++)
                        {
                            tmp_tow = cols[i].gameObject.GetComponent <UnitTower>();

                            if (tmp_tow.electricityReciever || tmp_tow.electricityFacility)
                            {
                                continue;
                            }

                            tmp_tow.electicitySources.Add(towerInstance);
                        }
                    }
                }



                //clear the build info and indicator for build manager
                ClearBuildPoint();

                return("");
            }

            return("Insufficient Resource");
        }