// get max count of given building type from database public int GetBuildingCountMax(int BuildingType) { BuildingType bt = TBDatabase.GetBuildingType(BuildingType); Building buildingTown = Buildings[0][0]; return(bt.MaxCount[buildingTown.Level - 1]); }
void Reset() { queItems.Clear(); bd = null; bt = TBDatabase.GetBuildingType(7); //building.Type); bd = bt.GetDefine(1); //building.Level); // delete old items of each content for (int j = rtUnitQueList.childCount - 1; j >= 0; j--) { Destroy(rtUnitQueList.GetChild(j).gameObject); } for (int i = 0; i < building.queUnitGen.Count; ++i) { GenQueItem item = building.queUnitGen[i]; GameObject go = (GameObject)Instantiate(prefabUnitQueItem, Vector3.zero, Quaternion.identity); go.transform.SetParent(rtUnitQueList); go.transform.localScale = Vector3.one; RectTransform rt = go.GetComponent <RectTransform>(); rt.anchoredPosition = new Vector2(i * -100, 0); UIUnitQueItem script = go.GetComponent <UIUnitQueItem>(); script.Init(this, item); queItems.Add(script); Debug.Log("queItems.Add " + queItems.Count.ToString() + "unitID:" + item.unitID.ToString()); } // delete old items of each content for (int j = rtUnitList.childCount - 1; j >= 0; j--) { Destroy(rtUnitList.GetChild(j).gameObject); } int sz = TBDatabase.GetArmyTypeCount(); for (int i = 0; i < sz; ++i) { int col = i / 2; int row = i % 2; GameObject go = (GameObject)Instantiate(prefabUnitItem, Vector3.zero, Quaternion.identity); go.transform.SetParent(rtUnitList); go.transform.localScale = Vector3.one; RectTransform rt = go.GetComponent <RectTransform>(); rt.anchoredPosition = new Vector2(col * 160, row * -160); UIUnitItem script = go.GetComponent <UIUnitItem>(); script.Init(this, i); } rtUnitList.sizeDelta = new Vector3(160 * ((sz + 1) / 2), 310); }
// whether upgrading is enable public bool IsUpgradeEnable() { BuildingType bt = TBDatabase.GetBuildingType(Type); // if this level is max level if (bt.LevelMax <= Level) { return(false); } // if no next level if (defNext == null) { return(false); } // if user don't have enough resources to upgrade if (((defNext.BuildGoldPrice != 0) && (SceneTown.Gold.Target() < defNext.BuildGoldPrice)) && ((defNext.BuildElixirPrice != 0) && (SceneTown.Elixir.Target() < defNext.BuildElixirPrice))) { return(false); } return(true); }
void _Show(ShopType type) { // if shop dialog called while new building is in creation, // delete new building if (SceneTown.buildingSelected != null) { if (!SceneTown.buildingSelected.OnceLanded) { SceneTown.instance.BuildingDelete(); } } gameObject.transform.localPosition = Vector3.zero; gameObject.SetActive(true); gameObject.GetComponent <Image>().color = new Color32(0, 0, 0, 0); SceneTown.isModalShow = true; eType = type; // delete old items of each content for (int i = 0; i < contents.Length; ++i) { for (int j = contents[i].transform.childCount - 1; j >= 0; j--) { Destroy(contents[i].transform.GetChild(j).gameObject); } } // create shop items of each contents if (eType == ShopType.Normal) { List <BuildingType> bt = new List <BuildingType>(); // fill first tab bt.Clear(); bt.Add(TBDatabase.GetBuildingType(3)); bt.Add(TBDatabase.GetBuildingType(4)); bt.Add(TBDatabase.GetBuildingType(5)); bt.Add(TBDatabase.GetBuildingType(6)); FillContents(0, "Economy", bt); // fill second tab bt.Clear(); bt.Add(TBDatabase.GetBuildingType(2)); bt.Add(TBDatabase.GetBuildingType(7)); bt.Add(TBDatabase.GetBuildingType(8)); //bt.Add (TBDatabase.GetBuildingType(9)); //bt.Add (TBDatabase.GetBuildingType(10)); FillContents(1, "Defense", bt); // fill third tab bt.Clear(); bt.Add(TBDatabase.GetBuildingbyName(name: "Hut")); bt.Add(TBDatabase.GetBuildingbyName(name: "wangtianshu")); bt.Add(TBDatabase.GetBuildingbyName(name: "apartment_mess")); bt.Add(TBDatabase.GetBuildingbyName(name: "apartment_huge")); FillContents(2, "Support", bt); BETween.anchoredPosition(rtDialog.gameObject, 0.3f, new Vector3(0, -500), new Vector3(0, 0)).method = BETweenMethod.easeOut; } else if (eType == ShopType.InApp) { FillInApp(0, "InApp"); // if shop has only one tab, then change position to hide tab BETween.anchoredPosition(rtDialog.gameObject, 0.3f, new Vector3(0, -500), new Vector3(0, -50)).method = BETweenMethod.easeOut; } else if (eType == ShopType.House) { List <BuildingType> bt = new List <BuildingType>(); // add house building bt.Clear(); bt.Add(TBDatabase.GetBuildingType(1)); FillContents(0, "House", bt); // if shop has only one tab, then change position to hide tab BETween.anchoredPosition(rtDialog.gameObject, 0.3f, new Vector3(0, -500), new Vector3(0, -50)).method = BETweenMethod.easeOut; } else { } toggleButtons[0].isOn = true; CategorySelected(0); rtDialog.anchoredPosition = new Vector3(0, -500); BETween.alpha(gameObject, 0.3f, 0, 0.5f).method = BETweenMethod.easeOut; }
void Reset() { //bd = null; bt = TBDatabase.GetBuildingType(building.Type); //bd = bt.GetDefine(building.Level); //bdNext = bt.GetDefine(building.Level+1); //bdLast = bt.GetDefLast(); textTitle.text = bt.Name; textLevel.text = "Level " + building.Level.ToString(); imgIcon.sprite = Resources.Load <Sprite>("Icons/Building/" + bt.Name); for (int i = 0; i < progresses.Length; ++i) { progresses[i].gameObject.SetActive(true); } // display progresses of building by building type if (bt.ID == 0) { // incase building si town hall, show gold capacity, elixir capacit and hitpoint textInfo.text = "This is the heart of your village. Upgrading your Town Hall unlocks new defenses, buildings, traps and much more."; building.UIFillProgress(progresses[0], BDInfo.CapacityGold); building.UIFillProgress(progresses[1], BDInfo.CapacityElixir); building.UIFillProgress(progresses[2], BDInfo.HitPoint); } else if (bt.ID == 1) { // incase building is house, only show hitpoint, and disable other progresses textInfo.text = "Nothing gets done around here without Builders! You can hire more Builders to start multiple construction projects, or speed up their work by using green gems."; building.UIFillProgress(progresses[0], BDInfo.HitPoint); progresses[1].gameObject.SetActive(false); progresses[2].gameObject.SetActive(false); } else if (bt.ID == 2) { textInfo.text = "Walls are great for keeping your village safe and your enemies in the line of fire."; building.UIFillProgress(progresses[0], BDInfo.HitPoint); progresses[1].gameObject.SetActive(false); progresses[2].gameObject.SetActive(false); } else if ((bt.ID == 3) || (bt.ID == 4)) { if (bt.ID == 3) { textInfo.text = "The Gold Mine produces gold. Upgrade it to boost its production and gold storage capacity."; } else { textInfo.text = "Elixir is pumped from the Ley Lines coursing underneath your village. Upgrade your Elixir Collectors to maximize elixir production."; } building.UIFillProgress(progresses[0], BDInfo.Capacity); building.UIFillProgress(progresses[1], BDInfo.ProductionRate); building.UIFillProgress(progresses[2], BDInfo.HitPoint); } else if ((bt.ID == 5) || (bt.ID == 6)) { if (bt.ID == 5) { textInfo.text = "All your precious gold is stored here. Don't let sneaky goblins anywhere near! Upgrade the storage to increase its capacity and durability against attack."; } else { textInfo.text = "These storages contain the elixir pumped from underground. Upgrade them to increase the maximum amount of elixir you can store."; } building.UIFillProgress(progresses[0], BDInfo.StorageCapacity); building.UIFillProgress(progresses[1], BDInfo.HitPoint); progresses[2].gameObject.SetActive(false); } else if (bt.ID == 7) { textInfo.text = "The Barracks allow you to train troops to attack your enemies. Upgrade the Barracks to unlock advanced units that can win epic battles."; //"Training Capacity : 0/20"; //"HitPoint" } else if (bt.ID == 8) { textInfo.text = "Your troops are stationed in Army Camps. Build more camps and upgrade them to muster a powerful army."; //"Total troop Capacity : 0/20"; //"HitPoint" // show troops icon (click to remove unit) "Remove Troops?" } else if (bt.ID == 9) { textInfo.text = "Cannons are great for point defense. Upgrade cannons to increase their firepower, but beware that your defensive turrets cannot shoot while being upgraded!"; //"Damage per second:15"; //"HitPoint" //Range : 9 Tiles //Damage Type: Single Target //Targets: Ground //Favorite target: Any } else if (bt.ID == 10) { textInfo.text = "Archer Towers have longer range than cannons, and unlike cannons they can attack flying enemies."; } else { } }
// initialize building public void Init(int type, int level) { Type = type; Level = level; // delete old meshes if (goCenter != null) { Destroy(goCenter); goCenter = null; } if (goXInc != null) { Destroy(goXInc); goXInc = null; } if (goZInc != null) { Destroy(goZInc); goZInc = null; } bt = TBDatabase.GetBuildingType(type); // get mesh path type and level int displayLevel = (level == 0) ? 1 : level; string meshPath = "Prefabs/Building/" + bt.Name + "_" + displayLevel.ToString(); //Debug.Log ("Loading Mesh "+meshPath); // instantiate mesh and set to goCenter GameObject prefabMesh = Resources.Load(meshPath) as GameObject; goCenter = (GameObject)Instantiate(prefabMesh, Vector3.zero, Quaternion.identity); goCenter.transform.SetParent(gameObject.transform); goCenter.transform.localPosition = Vector3.zero; goCenter.transform.localRotation = Quaternion.Euler(0, -90, 0); // if wall if (type == 2) { // create x,z side mesh string meshSidePath = meshPath + "Side"; GameObject prefabMeshSide = Resources.Load(meshSidePath) as GameObject; goXInc = (GameObject)Instantiate(prefabMeshSide, Vector3.zero, Quaternion.identity); goXInc.transform.SetParent(gameObject.transform); goXInc.transform.localPosition = Vector3.zero; goXInc.transform.localRotation = Quaternion.Euler(0, 180, 0); // rotate to x direction goZInc = (GameObject)Instantiate(prefabMeshSide, Vector3.zero, Quaternion.identity); goZInc.transform.SetParent(gameObject.transform); goZInc.transform.localPosition = Vector3.zero; goZInc.transform.localRotation = Quaternion.Euler(0, 90, 0); // rotate to z direction } // set tile size tileSize = new Vector2(bt.TileX, bt.TileZ); // set proper material to gogrid goGrid.GetComponent <Renderer>().material = Resources.Load("Materials/Tile" + bt.TileX.ToString() + "x" + bt.TileZ.ToString()) as Material; goGrid.transform.localScale = new Vector3(bt.TileX, 1, bt.TileZ); goArrowXMinus.transform.localPosition = new Vector3(-(0.4f + (float)bt.TileX * 0.5f), 0.01f, 0); goArrowXPlus.transform.localPosition = new Vector3((0.4f + (float)bt.TileX * 0.5f), 0.01f, 0); goArrowZMinus.transform.localPosition = new Vector3(0, 0.01f, -(0.4f + (float)bt.TileX * 0.5f)); goArrowZPlus.transform.localPosition = new Vector3(0, 0.01f, (0.4f + (float)bt.TileX * 0.5f)); goArea.transform.localScale = new Vector3(bt.TileX, 1, bt.TileZ); // get ui if (transform.Find("UIBuilding")) { uiInfo = transform.Find("UIBuilding").transform.Find("UIInfo").GetComponent <UIInfo>(); } else { uiInfo = UIInGame.instance.AddInGameUI(prefUIInfo, transform, new Vector3(0, 1.5f, 0)).GetComponent <UIInfo>(); } uiInfo.groupInfo.gameObject.SetActive(false); uiInfo.groupProgress.gameObject.SetActive(false); uiInfo.groupCollect.gameObject.SetActive(false); uiInfo.Name.text = TBDatabase.GetBuildingName(Type); uiInfo.Level.text = "Level " + displayLevel.ToString(); uiInfo.building = this; // currently not used goRangeIn.SetActive(false); goRangeOut.SetActive(false); // initialize values tilePosOld = tilePos; CheckLandable(); CheckNeighbor(); def = TBDatabase.GetBuildingDef(Type, Level); defNext = bt.GetDefine(Level + 1); defLast = bt.GetDefLast(); UpgradeTimeTotal = (defNext != null) ? defNext.BuildTime : 0; }
void Reset() { //bd = null; bt = TBDatabase.GetBuildingType(building.Type); //bd = bt.GetDefine(building.Level); bdNext = bt.GetDefine(building.Level + 1); //bdLast = bt.GetDefLast(); textTitle.text = "Upgrade " + bt.Name + " to Level " + (building.Level + 1).ToString() + " ?"; imgIcon.sprite = Resources.Load <Sprite>("Icons/Building/" + bt.Name); for (int i = 0; i < progresses.Length; ++i) { progresses[i].gameObject.SetActive(true); } // display progresses of building by building type if (bt.ID == 0) { // incase building si town hall, show gold capacity, elixir capacit and hitpoint building.UIFillProgressWithNext(progresses[0], BDInfo.CapacityGold); building.UIFillProgressWithNext(progresses[1], BDInfo.CapacityElixir); building.UIFillProgressWithNext(progresses[2], BDInfo.HitPoint); } else if (bt.ID == 1) { // incase building is house, only show hitpoint, and disable other progresses building.UIFillProgressWithNext(progresses[0], BDInfo.HitPoint); progresses[1].gameObject.SetActive(false); progresses[2].gameObject.SetActive(false); } else if (bt.ID == 2) { building.UIFillProgressWithNext(progresses[0], BDInfo.HitPoint); progresses[1].gameObject.SetActive(false); progresses[2].gameObject.SetActive(false); } else if ((bt.ID == 3) || (bt.ID == 4)) { building.UIFillProgressWithNext(progresses[0], BDInfo.Capacity); building.UIFillProgressWithNext(progresses[1], BDInfo.ProductionRate); building.UIFillProgressWithNext(progresses[2], BDInfo.HitPoint); } else if ((bt.ID == 5) || (bt.ID == 6)) { building.UIFillProgressWithNext(progresses[0], BDInfo.StorageCapacity); building.UIFillProgressWithNext(progresses[1], BDInfo.HitPoint); progresses[2].gameObject.SetActive(false); } else if (bt.ID == 7) { //"Training Capacity : 0/20"; //"HitPoint" } else if (bt.ID == 8) { //"Total troop Capacity : 0/20"; //"HitPoint" // show troops icon (click to remove unit) "Remove Troops?" } else if (bt.ID == 9) { //"Damage per second:15"; //"HitPoint" //Range : 9 Tiles //Damage Type: Single Target //Targets: Ground //Favorite target: Any } else if (bt.ID == 10) { } else { } // get townhall to check upgrade requires next townhall Building buildingTown = BEGround.instance.Buildings[0][0]; if (bdNext.TownHallLevelRequired > buildingTown.Level) { goNote.SetActive(true); NoteInfo.text = "To upgrade this building, you first need\n Town Hall Level " + bdNext.TownHallLevelRequired.ToString() + "!"; TownLevelOk = false; goNormal.SetActive(false); } else { goNote.SetActive(false); TownLevelOk = true; goNormal.SetActive(true); // set infos about upgrade bdNext.PriceInfoApply(PriceIcon, Price); textBuildTime.text = BENumber.SecToString(bdNext.BuildTime); GemCount = (bdNext.BuildTime + 1) / 60; // 1 gem per minute PriceGem.text = GemCount.ToString("#,##0"); PriceGem.color = (SceneTown.Gem.Target() < GemCount) ? Color.red : Color.white; } }