//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"); }
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"; }
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"); }
public string UpgradeToNextTower(int ID = 0) { UnitTower nextLevelTower = nextLevelTowerList[Mathf.Clamp(ID, 0, nextLevelTowerList.Count)]; 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(true); GameControl.SelectTower(towerInstance); Destroy(thisObj); return(""); }
//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"); }
//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"); }