/// <summary> /// Assign the slot by item info. /// </summary> /// <param name="itemInfo">The item info.</param> public bool Assign(UIItemInfo itemInfo) { if (itemInfo == null) { return(false); } // Make sure we unassign first, so the event is called before new assignment this.Unassign(); // Use the base class assign to set the icon this.Assign(itemInfo.Icon); // Set the spell info this.m_ItemInfo = itemInfo; // Invoke the on assign event if (this.onAssign != null) { this.onAssign.Invoke(this); } // Success return(true); }
// <summary> /// Performs a slot swap. /// </summary> /// <returns><c>true</c>, if slot swap was performed, <c>false</c> otherwise.</returns> /// <param name="sourceSlot">Source slot.</param> public override bool PerformSlotSwap(Object sourceObject) { // Get the source slot UISlotBase sourceSlot = (sourceObject as UISlotBase); // Get the source item info UIItemInfo sourceItemInfo = null; bool assign1 = false; // Check the type of the source slot if (sourceSlot is UIItemSlot) { sourceItemInfo = (sourceSlot as UIItemSlot).GetItemInfo(); // Assign the source slot by this one assign1 = (sourceSlot as UIItemSlot).Assign(this.GetItemInfo()); } else if (sourceSlot is UIEquipSlot) { sourceItemInfo = (sourceSlot as UIEquipSlot).GetItemInfo(); // Assign the source slot by this one assign1 = (sourceSlot as UIEquipSlot).Assign(this.GetItemInfo()); } // Assign this slot by the source slot bool assign2 = this.Assign(sourceItemInfo); // Return the status return(assign1 && assign2); }
/* * Creator: Yunzheng Zhou * Assign the slot by item info. * Parameter: itemInfo - the item info */ public bool Assign(UIItemInfo itemInfo) { //Debug.Log("iteminfo is " + itemInfo); if (itemInfo == null) { return(false); } //Debug.Log("check type " + this.CheckEquipType(itemInfo)); // Check if the equipment type matches the target slot if (!this.CheckEquipType(itemInfo)) { return(false); } // Make sure we unassign first, so the event is called before new assignment this.Unassign(); // Use the base class assign to set the icon this.Assign(itemInfo.Icon); // Set the spell info this.m_ItemInfo = itemInfo; // Invoke the on assign event if (this.onAssign != null) { this.onAssign.Invoke(this); } // Success return(true); }
/// <summary> /// Checks if the given item can assigned to this slot. /// </summary> /// <returns><c>true</c>, if equip type was checked, <c>false</c> otherwise.</returns> /// <param name="info">Info.</param> public virtual bool CheckEquipType(UIItemInfo info) { if (info.EquipType != this.equipType) { return(false); } return(true); }
/// <summary> /// Unassign this slot. /// </summary> public override void Unassign() { // Remove the icon base.Unassign(); // Clear the spell info this.m_ItemInfo = null; // Invoke the on unassign event if (this.onUnassign != null) { this.onUnassign.Invoke(this); } }
/* * Creator: Yunzheng Zhou * Checks if the given item can assigned to this slot. * Parameter: info - a UIItemInfo object * Return: a bool variable indicating whether equip type was checked or not */ public virtual bool CheckEquipType(UIItemInfo info) { if (info.EquipType == 0) { return(true); } if (info.EquipType != this.equipType) { return(false); } //Debug.Log("niniu"); return(true); }
/// <summary> /// Prepares the tooltip with the specified item info. /// </summary> /// <param name="itemInfo">Item info.</param> public static void PrepareTooltip(UIItemInfo itemInfo) { if (itemInfo == null) { return; } // Set the title and description UITooltip.AddTitle("<color=#" + UIItemQualityColor.GetHexColor(itemInfo.Quality) + ">" + itemInfo.Name + "</color>"); // Spacer UITooltip.AddSpacer(); // Item types UITooltip.AddLineColumn(itemInfo.Type, "ItemAttribute"); UITooltip.AddLineColumn(itemInfo.Subtype, "ItemAttribute"); if (itemInfo.ItemType == 1) { UITooltip.AddLineColumn(itemInfo.Damage.ToString() + " Damage", "ItemAttribute"); UITooltip.AddLineColumn(itemInfo.AttackSpeed.ToString("0.0") + " Attack speed", "ItemAttribute"); UITooltip.AddLine("(" + ((float)itemInfo.Damage / itemInfo.AttackSpeed).ToString("0.0") + " damage per second)", "ItemAttribute"); } else { UITooltip.AddLineColumn(itemInfo.Armor.ToString() + " Armor", "ItemAttribute"); UITooltip.AddLineColumn(itemInfo.Block.ToString() + " Block", "ItemAttribute"); } UITooltip.AddSpacer(); UITooltip.AddLine("+" + itemInfo.Stamina.ToString() + " Stamina", "ItemStat"); UITooltip.AddLine("+" + itemInfo.Strength.ToString() + " Strength", "ItemStat"); // Set the item description if not empty if (!string.IsNullOrEmpty(itemInfo.Description)) { UITooltip.AddSpacer(); UITooltip.AddLine(itemInfo.Description, "ItemDescription"); } }
/// <summary> /// Prepares the tooltip with the specified item info. /// </summary> /// <param name="itemInfo">Item info.</param> public static void PrepareTooltip(UIItemInfo itemInfo) { if (itemInfo == null) { return; } // Set the title and description UITooltip.AddTitle(itemInfo.Name); // Item types UITooltip.AddLineColumn(itemInfo.Type); UITooltip.AddLineColumn(itemInfo.Subtype); if (itemInfo.ItemType == 1) { UITooltip.AddLineColumn(itemInfo.Damage.ToString() + " Damage"); UITooltip.AddLineColumn(itemInfo.AttackSpeed.ToString("0.0") + " Attack speed"); UITooltip.AddLine("(" + ((float)itemInfo.Damage / itemInfo.AttackSpeed).ToString("0.0") + " damage per second)"); } else { UITooltip.AddLineColumn(itemInfo.Block.ToString() + " Block"); UITooltip.AddLineColumn(itemInfo.Armor.ToString() + " Armor"); } UITooltip.AddLine("<color=#008000ff>+" + itemInfo.Stamina.ToString() + " Stamina</color>", new RectOffset(0, 0, 6, 0)); UITooltip.AddLine("<color=#008000ff>+" + itemInfo.Strength.ToString() + " Strength</color>"); // Set the item description if not empty if (!string.IsNullOrEmpty(itemInfo.Description)) { UITooltip.AddDescription(itemInfo.Description); } }
/* * Function: PrepareTooltip * Prepares the tooltip with the specified item info. * All infomation are saved in iteminfodatabase. if the specific atrribute is 0, then it will not show up in tooltip panel * Parameter: itemInfo - UIItemInfo object */ public static void PrepareTooltip(UIItemInfo itemInfo) { if (itemInfo == null) { return; } // Set the title and description UITooltip.AddTitle(itemInfo.Name); UITooltip.AddLine(""); // Item types UITooltip.AddLineColumn(itemInfo.Type); UITooltip.AddLineColumn(itemInfo.Subtype); /*if (itemInfo.ItemType == 1) * { * UITooltip.AddLineColumn(itemInfo.Damage.ToString() + " Damage"); * UITooltip.AddLineColumn(itemInfo.AttackSpeed.ToString("0.0") + " Attack speed"); * * UITooltip.AddLine("(" + ((float)itemInfo.Damage / itemInfo.AttackSpeed).ToString("0.0") + " damage per second)"); * } * else * { * UITooltip.AddLineColumn(itemInfo.Block.ToString() + " Block"); * UITooltip.AddLineColumn(itemInfo.Armor.ToString() + " Armor"); * } * * UITooltip.AddLine("+" + itemInfo.Stamina.ToString() + " Stamina", new RectOffset(0, 0, 6, 0)); * UITooltip.AddLine("+" + itemInfo.Strength.ToString() + " Strength"); */ if (itemInfo.weight != 0) { UITooltip.AddLineColumn("Weight:" + itemInfo.weight.ToString()); UITooltip.AddLine(""); } if (itemInfo.gemSlot != 0) { UITooltip.AddLine("<color=#db81fc>" + (itemInfo.gemSlot == 1 ? "FlameStrike GEM" : "Rageful Laser GEM") + "</color>"); } if (itemInfo.Damage != 0) { UITooltip.AddLineColumn("<color=#fee95e>AttackPower:</color>"); UITooltip.AddLineColumn("<color=#00ff00> + " + itemInfo.Damage.ToString() + "</color>"); } if (itemInfo.Cooldown != 0) { UITooltip.AddLineColumn("<color=#fee95e>CoolingDown:</color>"); UITooltip.AddLineColumn("<color=#00ff00> + " + itemInfo.Cooldown.ToString() + "</color>"); } if (itemInfo.Lifesteal != 0) { UITooltip.AddLineColumn("<color=#fee95e>Life Steal:</color>"); UITooltip.AddLineColumn("<color=#00ff00> + " + itemInfo.Lifesteal.ToString() + "</color>"); } if (itemInfo.Range != 0) { UITooltip.AddLineColumn("<color=#fee95e>Skill Range:</color>"); UITooltip.AddLineColumn("<color=#00ff00> + " + itemInfo.Range.ToString() + "</color>"); } if (itemInfo.RageGen != 0) { UITooltip.AddLineColumn("<color=#fee95e>Rage generation:</color>"); UITooltip.AddLineColumn("<color=#00ff00> + " + itemInfo.RageGen.ToString() + "</color>"); } if (itemInfo.Radius != 0) { UITooltip.AddLineColumn("<color=#fee95e>Radius:</color>"); UITooltip.AddLineColumn("<color=#00ff00> + " + itemInfo.Radius.ToString() + "</color>"); } if (itemInfo.LastTime != 0) { UITooltip.AddLineColumn("<color=#fee95e>Last Time:</color>"); UITooltip.AddLineColumn("<color=#00ff00> + " + itemInfo.LastTime.ToString() + "</color>"); } if (itemInfo.Stamina != 0) { UITooltip.AddLineColumn("<color=#fee95e>Health:</color>"); UITooltip.AddLineColumn("<color=#00ff00> + " + itemInfo.Stamina.ToString() + "</color>"); } if (itemInfo.Armor != 0) { UITooltip.AddLineColumn("<color=#fee95e>Armor:</color>"); UITooltip.AddLineColumn("<color=#00ff00> + " + itemInfo.Armor.ToString() + "</color>"); } // Set the item description if not empty if (!string.IsNullOrEmpty(itemInfo.Description)) { UITooltip.AddDescription(itemInfo.Description); } UITooltip.AddLineColumn(""); UITooltip.AddLineColumn("<color=#fee95e>Sell: " + itemInfo.price.ToString() + "</color>"); }
/* * Creator: Yunzheng Zhou * Description: * Performs a item swap from one slot to another slot * The destination slot will varied. if the destination slot is vendor inventory * then it means that the player is trading with vendor. * otherwise swap the items. * Parameter: sourceObject object * Return a bool value indicating if slot swap was performed */ public override bool PerformSlotSwap(Object sourceObject) { // Get the source slot UISlotBase sourceSlot = (sourceObject as UISlotBase); //Debug.Log("Itemslot!"); // Get the source item info UIItemInfo sourceItemInfo = null; bool assign1 = false; bool sourceVendor = false; bool thisVendor = false; // Check the type of the source slot if (sourceSlot is UIItemSlot) { sourceItemInfo = (sourceSlot as UIItemSlot).GetItemInfo(); if ((sourceSlot as UIItemSlot).isVendor) { sourceVendor = true; } if (this.isVendor) { thisVendor = true; } Text gold = Inventory.instance.gold.GetComponent <Text>(); if (sourceVendor && !thisVendor) { gold.text = Convert.ToString(Convert.ToInt32(gold.text) + this.GetItemInfo().price); } if (!sourceVendor && thisVendor) { if (gold.text == "0") { return(false); } if (this.GetItemInfo().price > Convert.ToInt32(gold.text)) { return(false); } gold.text = Convert.ToString(Convert.ToInt32(gold.text) - this.GetItemInfo().price); } // Assign the source slot by this one assign1 = (sourceSlot as UIItemSlot).Assign(this.GetItemInfo()); Test_UIItemSlot_Assign sourceItem = sourceSlot.GetComponent <Test_UIItemSlot_Assign>(); Test_UIItemSlot_Assign Toitem = this.GetComponent <Test_UIItemSlot_Assign>(); int id = sourceItem.assignItem; sourceItem.assignItem = Toitem.assignItem; Toitem.assignItem = id; /*if (sourceItem.assignItem == 0) * { * sourceSlot.Unassign(); * } * if (Toitem.assignItem == 0) * { * this.Unassign(); * }*/ } else if (sourceSlot is UIEquipSlot) { sourceItemInfo = (sourceSlot as UIEquipSlot).GetItemInfo(); if (this.GetItemInfo().gemSlot != (sourceSlot as UIEquipSlot).slotindex) { return(false); } if (this.GetItemInfo().EquipType == 0) { return(false); } // Assign the source slot by this one assign1 = (sourceSlot as UIEquipSlot).Assign(this.GetItemInfo()); if (!assign1) { return(false); } Test_UIEquipSlot_Assign sourceItem = sourceSlot.GetComponent <Test_UIEquipSlot_Assign>(); Test_UIItemSlot_Assign Toitem = this.GetComponent <Test_UIItemSlot_Assign>(); int id = sourceItem.assignItem; sourceItem.assignItem = Toitem.assignItem; Toitem.assignItem = id; if ((int)sourceSlot.GetComponent <UIEquipSlot>().equipType == 1) { Player.instance.playerController.WeaponState = 1; } //Debug.Log("source is " + sourceItem.assignItem); //Debug.Log("this is " + this + " id is " + Toitem.assignItem); } //Debug.Log("perform swap"); // Assign this slot by the source slot for (int i = 4; i < 8; i++) { EquipmentManager.instance.EquipmentUpdate(i); } bool assign2 = this.Assign(sourceItemInfo); //Debug.Log("assign1 is " + assign1 + "assign2 is " + assign2); // Return the status //Inventory.instance.UpdateInventory(); return(assign1 && assign2); }
/* * Creator: Yunzheng Zhou * Performs a slot swap. * Parameter: Source slot object * Return: a bool variable indicating if slot swap was performed */ public override bool PerformSlotSwap(Object sourceObject) { // Get the source item info UIItemInfo sourceItemInfo = null; bool assign1 = false; //Debug.Log(sourceObject + " equipment"); // Check the type of the source slot if (sourceObject is UIItemSlot) { sourceItemInfo = (sourceObject as UIItemSlot).GetItemInfo(); /*if (sourceItemInfo.EquipType == 0) * { * Debug.Log("source is the ! " + sourceItemInfo); * (sourceObject as UIItemSlot).Unassign(); * assign1 = true; * }*/ // Assign the source slot by this one //else //{ assign1 = (sourceObject as UIItemSlot).Assign(this.GetItemInfo()); Test_UIItemSlot_Assign sourceitem = (sourceObject as UIItemSlot).GetComponent <Test_UIItemSlot_Assign>(); Test_UIEquipSlot_Assign thisitem = this.GetComponent <Test_UIEquipSlot_Assign>(); Player.instance.playerStats.OnEquipmentChanged(null, backupitemDataBase.GetItem(thisitem.assignItem) as Equipment); if ((int)this.GetComponent <UIEquipSlot>().equipType == 1) { Player.instance.playerController.WeaponState = 0; } int tmp = sourceitem.assignItem; sourceitem.assignItem = thisitem.assignItem; thisitem.assignItem = tmp; //Debug.Log("source is " + sourceitem.assignItem); //Debug.Log("assign1 " + assign1); //} } else if (sourceObject is UIEquipSlot) { return(false); sourceItemInfo = (sourceObject as UIEquipSlot).GetItemInfo(); // Assign the source slot by this one assign1 = (sourceObject as UIEquipSlot).Assign(this.GetItemInfo()); } else { for (int i = 4; i < 8; i++) { EquipmentManager.instance.EquipmentUpdate(i); } return(false); } for (int i = 4; i < 8; i++) { EquipmentManager.instance.EquipmentUpdate(i); } // Assign this slot by the source slot bool assign2 = this.Assign(sourceItemInfo); // Return the status return(assign1 && assign2); }
/* * Creator: Yunzheng Zhou * Retrieve and use item from inventary slot. * Parameter: item - RaycastResult variable referencing mouse postion and action */ public void UseItem(RaycastResult item) // right click. Use this! { if (this is UIEquipSlot && (int)(this as UIEquipSlot).equipType != 9) { return; } UIItemSlot inventorySlot = item.gameObject.GetComponent <UIItemSlot>(); UIEquipSlot equipSlot = item.gameObject.GetComponent <UIEquipSlot>(); Test_UIItemSlot_Assign tmpItem = item.gameObject.GetComponent <Test_UIItemSlot_Assign>(); Test_UIEquipSlot_Assign equipItem = item.gameObject.GetComponent <Test_UIEquipSlot_Assign>(); if (equipItem != null) { if (equipItem.assignItem == 0) { return; } } UIItemInfo inven; Item consumable; if (inventorySlot == null) { //equipSlot = item.gameObject.GetComponent<UIEquipSlot>(); //equipItem = item.gameObject.GetComponent<Test_UIEquipSlot_Assign>(); if (equipItem == null) { return; } consumable = backupitemDataBase.GetItem(equipItem.assignItem); inven = equipSlot.GetItemInfo(); } else //consumable { if (inventorySlot.isVendor) { return; } tmpItem = item.gameObject.GetComponent <Test_UIItemSlot_Assign>(); inven = inventorySlot.GetItemInfo(); consumable = backupitemDataBase.GetItem(tmpItem.assignItem); } if (consumable.isconsumable) { playSFX(onConsumeSFX); consumable.Use(); if (inventorySlot == null) { equipSlot.Assign(itemdatabase.GetByID(0)); fillinPotionslot(equipSlot, equipItem.assignItem, equipItem); return; } inventorySlot.Assign(itemdatabase.GetByID(0)); tmpItem.assignItem = 0; } else //equip { int i = (int)(itemdatabase.GetByID(tmpItem.assignItem).EquipType); if (i > 6 || i < 1) { //Debug.Log("find gem"); return; } //this.InternalHideTooltip(); UIEquipSlot EquipedSlot = EquipmentManager.instance.equipmentSlot[i].GetComponent <UIEquipSlot>(); //Debug.Log(EquipedSlot); UIItemInfo currentEquiped = EquipedSlot.GetItemInfo(); if (currentEquiped.EquipType == 0) { //tmpItem.assignItem = 10; playSFX(onEquipSFX); inventorySlot.Assign(EquipedSlot); if ((int)EquipedSlot.equipType == 1) { Player.instance.playerController.WeaponState = 1; } } else { playSFX(onEquipSFX); inventorySlot.Assign(currentEquiped); } int tmpID = currentEquiped.ID; Test_UIEquipSlot_Assign equipedItem = EquipmentManager.instance.equipmentSlot[i].GetComponent <Test_UIEquipSlot_Assign>(); equipedItem.assignItem = tmpItem.assignItem; equipedItem.itemDatabase = itemdatabase; //equipedItem.slot = EquipedSlot; EquipedSlot.Assign(inven); //equipedItem.slot.Assign(inven); //EquipedSlot.Assign(itemdatabase.GetByID(equipedItem.assignItem)); //equipedItem.slot.Assign(itemdatabase.GetByID(equipedItem.assignItem)); tmpItem.assignItem = tmpID; Test_UIItemSlot_Assign inventoryitem = inventorySlot.GetComponent <Test_UIItemSlot_Assign>(); inventoryitem.assignItem = tmpID; //Inventory.instance.UpdateInventory(); for (int k = 4; k < 8; k++) { EquipmentManager.instance.EquipmentUpdate(k); } } }