/// <summary> /// Adds the item with itemId. where itemId is the id which we registered with item prefab as unique. /// </summary> /// <returns>The item.</returns> /// <param name="itemId">Item identifier.</param> public BaseItemScript AddItem(int itemId, int instanceId, int posX, int posY, bool immediate, bool ownedItem) { BaseItemScript builder = null; Debug.LogError("CreateItemID:" + itemId); if (!immediate) { // builder = this.GetFreeBuilder(); // if (builder == null) // { // Debug.Log("All builders are busy!"); // UIManager.instance.ShowBuildersBusyWindow(); // return null; // } } BaseItemScript instance = Utilities.CreateInstance(this.BaseItem, this.ItemsContainer, true).GetComponent <BaseItemScript>(); if (instanceId == -1) { instanceId = this._GetUnusedInstanceId(); } instance.instanceId = instanceId; this._itemInstances.Add(instanceId, instance); instance.SetItemData(itemId, posX, posY); instance.SetState(Common.State.IDLE); // GroundManager.Cell freeCell = GroundManager.instance.GetRandomFreeCellForItem (instance); // instance.SetPosition (GroundManager.instance.CellToPosition (freeCell)); if (!immediate) { instance.UI.ShowProgressUI(true); if (!instance.itemData.configuration.isCharacter && instance.itemData.configuration.buildTime > 0) { if (builder != null) { builder.BuilderAction(instance); } } } if (!instance.itemData.configuration.isCharacter) { GroundManager.instance.UpdateBaseItemNodes(instance, GroundManager.Action.ADD); } if (instance.itemData.name == "Wall") { this.UpdateWalls(); } instance.ownedItem = ownedItem; return(instance); }
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(); } }