public void UpdateConnectedItems() { //add archers if it is a tower item if (this.itemData.name == "Tower") { BaseItemScript towerArcher = null; if (this.connectedItems.Count > 0) { towerArcher = this.connectedItems[0]; } if (towerArcher == null) { towerArcher = SceneManager.instance.AddItem(1502, true, ownedItem); this.connectedItems.Add(towerArcher); } towerArcher.SetPosition(this.GetCenterPosition() + new Vector3(0, 1.2f, 0)); towerArcher.SetState(state); towerArcher.SetDirection(direction); } //add builder to builder hut if (this.itemData.name == "BuilderHut" && SceneManager.instance.gameMode == Common.GameMode.NORMAL) { if (SceneManager.instance.selectedItem == this) { //that means the hut is on drag //builder comes to hut only after on stop drag return; } BaseItemScript builder = null; if (this.connectedItems.Count > 0) { builder = this.connectedItems[0]; } if (builder == null) { builder = SceneManager.instance.AddItem(3823, true, ownedItem); builder.SetPosition(this.GetRandomFrontCellPosition()); //connect builder item to the builder hut this.connectedItems.Add(builder); //connect this builder hut item to builder builder.connectedItems.Add(this); } builder.ReturnBuilder(); } }
public void addItem() { int itemId = 0; switch (this._subCategory.subCategoryName) { case "BARRACK": itemId = 8833; break; case "BOAT": itemId = 6871; break; case "BUILDER_HUT": itemId = 3635; break; case "CAMP": itemId = 2728; break; case "CANNON": itemId = 1712; break; case "ELIXIR_COLLECTOR": itemId = 4856; break; case "ELIXIR_STORAGE": itemId = 2090; break; case "GEMS": itemId = 3336; break; case "GOLD_MINE": itemId = 3265; break; case "GOLD_STORAGE": itemId = 9074; break; case "TOWER": itemId = 4764; break; case "TOWN_CENTER": itemId = 2496; break; case "TREE1": itemId = 2949; break; case "TREE2": itemId = 1251; break; case "WINDMILL": itemId = 6677; break; case "WALL": itemId = 7666; break; case "TREE3": itemId = 5341; break; case "CoconutTree": itemId = 7802; break; case "Tent": itemId = 1604; break; } ItemsCollection.ItemData itemData = Items.GetItem(itemId); Vector3 freePosition = GroundManager.instance.GetRandomFreePositionForItem(itemData.gridSize, itemData.gridSize); BaseItemScript item = SceneManager.instance.AddItem(itemId, false, true); if (item != null) { item.SetPosition(freePosition); DataBaseManager.instance.UpdateItemData(item); if (this._subCategory.reqMap[DataBaseManager.GOLD_RESOURCE_NAME] > 0) { DataBaseManager.instance.UpdateResourceData(DataBaseManager.GOLD_RESOURCE_NAME, this._subCategory.reqMap[DataBaseManager.GOLD_RESOURCE_NAME], false); SceneManager.instance.ConsumeResource("gold", this._subCategory.reqMap[DataBaseManager.GOLD_RESOURCE_NAME]); } if (this._subCategory.reqMap[DataBaseManager.WOOD_RESOURCE_NAME] > 0) { DataBaseManager.instance.UpdateResourceData(DataBaseManager.GOLD_RESOURCE_NAME, this._subCategory.reqMap[DataBaseManager.WOOD_RESOURCE_NAME], false); } if (this._subCategory.reqMap[DataBaseManager.LEAVES_RESOURCE_NAME] > 0) { DataBaseManager.instance.UpdateResourceData(DataBaseManager.LEAVES_RESOURCE_NAME, this._subCategory.reqMap[DataBaseManager.LEAVES_RESOURCE_NAME], false); } } SceneManager.instance.UpdateResourcesValues(); this.GetComponentInParent <ShopWindowScript>().Close(); }