void ItemUsePanelDataReset() { UseItemData data = useItemDataList[useItemState]; UISprite icon = panelList[1].transform.FindChild("BGPanel/Icon").GetComponent <UISprite>(); icon.spriteName = data.IconName; UILabel name = panelList[1].transform.FindChild("LabelPanel/Name").GetComponent <UILabel>(); name.text = data.name; UILabel discrip = panelList[1].transform.FindChild("LabelPanel/Discrip").GetComponent <UILabel>(); discrip.text = data.discrip; UILabel priceText = panelList[1].transform.FindChild("LabelPanel/PriceText").GetComponent <UILabel>(); UILabel priceValue = panelList[1].transform.FindChild("LabelPanel/PriceValue").GetComponent <UILabel>(); priceValue.text = data.price.ToString(); priceText.gameObject.SetActive(data.price != -1); priceValue.gameObject.SetActive(data.price != -1); }
void InitPetData(UseItemEnum type) { if (CurPet == null) { return; } UpdateSlider(); m_lstUseItemData.Clear(); string str = "ExpItem"; if (type == UseItemEnum.PetLife) { str = "LifeItem"; m_label_title.text = CommonData.GetLocalString(" 珍兽寿命"); } else if (type == UseItemEnum.PetExp) { str = "ExpItem"; m_label_title.text = petDataManager.GetCurPetLevelStr(); } else { return; } List <string> itemList = GameTableManager.Instance.GetGlobalConfigKeyList(str); PetDataBase pdb = GameTableManager.Instance.GetTableItem <PetDataBase>(CurPet.PetBaseID); if (pdb == null) { return; } uint carryLevel = (uint)petDataManager.GetCurPetLevel(); #region 从lua里面拿出来的数据无序 要先排序 List <uint> tempList = new List <uint>(); foreach (var strID in itemList) { uint id = uint.Parse(strID); tempList.Add(id); } tempList.Sort((x1, x2) => { if (x1 > x2) { return(1); } else if (x1 < x2) { return(-1); } else { return(0); } }); List <uint> itemIDList = new List <uint>(); #endregion for (int i = 0; i < tempList.Count; i++) { uint id = tempList[i]; itemIDList.Add(id); //if (type == UseItemEnum.PetLife) //{ // int firstLevel = GameTableManager.Instance.GetGlobalConfig<int>("PetFirstLevel"); // int secondLevel = GameTableManager.Instance.GetGlobalConfig<int>("PetSecondLevel"); // if (carryLevel < firstLevel) // { // if (i == 0 || i == 3) // { // itemIDList.Add(id); // } // } // else if (carryLevel > secondLevel) // { // if (i == 2 || i == 5) // { // itemIDList.Add(id); // } // } // else // { // if (i == 1 || i == 4) // { // itemIDList.Add(id); // } // } //} //else //{ // itemIDList.Add(id); //} } itemIDList.Sort((x1, x2) => { if (x1 > x2) { return(1); } else if (x1 < x2) { return(-1); } else { return(0); } }); if (type == UseItemEnum.PetExp) { List <uint> hasList = new List <uint>(); List <uint> noList = new List <uint>(); for (int i = 0; i < itemIDList.Count; i++) { uint id = itemIDList[i]; int count = DataManager.Manager <ItemManager>().GetItemNumByBaseId(id); if (count != 0) { hasList.Add(id); } else { noList.Add(id); } } itemIDList.Clear(); itemIDList.AddRange(hasList); itemIDList.AddRange(noList); } for (int i = 0; i < itemIDList.Count; i++) { UseItemData itemdata = new UseItemData(); itemdata.parent = this; itemdata.itemid = (itemIDList[i]); itemdata.useNum = (uint)1; m_lstUseItemData.Add(itemdata); } }
private void InventoryTransactionHandle(InventoryTransactionPacket pk) { List <InventoryAction> actions = new List <InventoryAction>(); for (int i = 0; i < pk.Actions.Length; ++i) { try { InventoryAction action = pk.Actions[i].GetInventoryAction(this); actions.Add(action); } catch (Exception e) { Logger.Log($"Unhandled inventory action from {this.Name}: {e.Message}"); this.SendAllInventories(); return; } } if (pk.TransactionType == InventoryTransactionPacket.TYPE_NORMAL) { InventoryTransaction transaction = new InventoryTransaction(this, actions); if (this.IsSpectator) { this.SendAllInventories(); return; } if (!transaction.Execute()) { Logger.Log($"Failed to execute inventory transaction from {this.Name} with actions"); } } else if (pk.TransactionType == InventoryTransactionPacket.TYPE_MISMATCH) { this.SendAllInventories(); return; } else if (pk.TransactionType == InventoryTransactionPacket.TYPE_USE_ITEM) { UseItemData data = (UseItemData)pk.TransactionData; Vector3 blockPos = data.BlockPos; BlockFace face = data.Face; if (data.ActionType == InventoryTransactionPacket.USE_ITEM_ACTION_CLICK_BLOCK) { this.SetFlag(Entity.DATA_FLAGS, Entity.DATA_FLAG_ACTION, false, true); if (this.CanInteract(blockPos + new Vector3(0.5f, 0.5f, 0.5f), this.IsCreative ? 13 : 7)) { Item item = this.Inventory.MainHandItem; this.World.UseItem(blockPos, item, face, data.ClickPos, this); } //Send MainHand } else if (data.ActionType == InventoryTransactionPacket.USE_ITEM_ACTION_BREAK_BLOCK) { Item item = this.Inventory.MainHandItem; if (this.CanInteract(blockPos + new Vector3(0.5f, 0.5f, 0.5f), this.IsCreative ? 13 : 7)) { this.World.UseBreak(data.BlockPos, item, this); if (this.IsSurvival) { //TODO : food this.Inventory.SendMainHand(); } } else { this.World.SendBlocks(new Player[] { this }, new Vector3[] { data.BlockPos }); } } } else if (pk.TransactionType == InventoryTransactionPacket.TYPE_USE_ITEM_ON_ENTITY) { } else if (pk.TransactionType == InventoryTransactionPacket.TYPE_RELEASE_ITEM) { ReleaseItemData data = (ReleaseItemData)pk.TransactionData; if (data.ActionType == InventoryTransactionPacket.RELEASE_ITEM_ACTION_RELEASE) { } else if (data.ActionType == InventoryTransactionPacket.RELEASE_ITEM_ACTION_CONSUME) { if (this.Inventory.MainHandItem != data.MainHandItem || this.Inventory.MainHandSlot != data.HotbarSlot) { this.Inventory.SendMainHand(this); return; } Item item = this.Inventory.MainHandItem; if (!(item is IConsumeable)) { this.Inventory.SendMainHand(this); return; } IConsumeable consume = (IConsumeable)item; PlayerItemConsumeableEventArgs playerItemConsumeableEvent = new PlayerItemConsumeableEventArgs(this, consume); PlayerEvents.OnPlayerItemConsumeable(playerItemConsumeableEvent); if (playerItemConsumeableEvent.IsCancel) { this.Inventory.SendMainHand(this); return; } consume.OnConsume(this); } } }