public void OnConsumablesClick() { BattlePlayerController battlePlayerController = ExploreManager.Instance.battlePlayerCtr; if (item.itemType == ItemType.Consumables) { Consumables cons = item as Consumables; cons.UseConsumables(battlePlayerController); bool isLevelUp = Player.mainPlayer.LevelUpIfExperienceEnough(); if (isLevelUp) { ExploreManager.Instance.battlePlayerCtr.SetEffectAnim(CommonData.levelUpEffectName); GameManager.Instance.soundManager.PlayAudioClip(CommonData.levelUpAudioName); ExploreManager.Instance.expUICtr.ShowLevelUpPlane(); } GameManager.Instance.soundManager.PlayAudioClip(cons.audioName); } else if (item.itemType == ItemType.SpecialItem) { SpecialItem specialItem = item as SpecialItem; specialItem.UseSpecialItem(specialItem, null); //GameManager.Instance.soundManager.PlayAudioClip(specialItem.audioName); } Player.mainPlayer.RemoveItem(item, 1); ExploreManager.Instance.expUICtr.UpdateActiveSkillButtons(); if (refreshCallBack != null) { refreshCallBack(); } }
/// <summary> /// 在物品详细信息页点击了使用按钮 /// </summary> public void OnUseButtonClick() { // 如果选中的物品为空,直接返回 if (currentSelectItem == null) { return; } // 标记是否清除物品详细信息【如果物品使用完成后数量为0,从背包中移除了,则清除物品的详细信息】 bool clearItemDetail = false; // 进行特殊操作物品【如点金石点的装备,重铸石重铸的装备等】 Item specialOperaitonItem = null; // 标记是否从背包中移除 bool totallyRemoved = true; // 根据当前选中物品的类型不同,区分不同的使用逻辑 switch (currentSelectItem.itemType) { // 消耗品使用逻辑 case ItemType.Consumables: Consumables consumables = currentSelectItem as Consumables; PropertyChange propertyChange = consumables.UseConsumables(null); if (consumables.itemCount > 0) { totallyRemoved = false; } bagView.SetUpPlayerStatusPlane(propertyChange); GameManager.Instance.soundManager.PlayAudioClip(consumables.audioName); break; // 技能卷轴的使用逻辑 case ItemType.SkillScroll: SkillScroll skillScroll = currentSelectItem as SkillScroll; // 检查技能是否已经学满了 if (Player.mainPlayer.CheckSkillFull()) { string skillFullHint = string.Format("只能学习{0}个技能", Player.mainPlayer.maxSkillCount); bagView.SetUpSingleTextTintHUD(skillFullHint); return; } // 检查技能是否已经学习过了 bool skillHasLearned = Player.mainPlayer.CheckSkillHasLearned(skillScroll.skillId); if (skillHasLearned) { bagView.SetUpSingleTextTintHUD("不能重复学习技能"); return; } totallyRemoved = true; propertyChange = skillScroll.UseSkillScroll(); GameManager.Instance.soundManager.PlayAudioClip(CommonData.paperAudioName); // 由于有被动技能,学习后玩家属性上可能有变化,所以学习技能后也要更新属性面板 bagView.SetUpPlayerStatusPlane(propertyChange); break; // 特殊物品的使用逻辑 case ItemType.SpecialItem: SpecialItem specialItem = currentSelectItem as SpecialItem; Item itemForSpecialOperation = bagView.itemDetail.soCell.itemInCell; specialOperaitonItem = itemForSpecialOperation; switch (specialItem.specialItemType) { case SpecialItemType.ChongZhuShi: case SpecialItemType.DianJinFuShi: if (itemForSpecialOperation == null) { return; } break; case SpecialItemType.TuiMoJuanZhou: if (itemForSpecialOperation == null) { return; } Equipment equipment = itemForSpecialOperation as Equipment; if (equipment.attachedPropertyGemstones.Count == 0) { bagView.hintHUD.SetUpSingleTextTintHUD("当前装备未镶嵌宝石"); return; } int addItemCount = 0; for (int i = 0; i < equipment.attachedPropertyGemstones.Count; i++) { PropertyGemstone propertyGemstone = equipment.attachedPropertyGemstones[i]; bool gemstoneExist = Player.mainPlayer.CheckItemExistInBag(propertyGemstone); if (!gemstoneExist) { addItemCount++; } } if (specialItem.itemCount == 1) { addItemCount--; } bool bagFull = Player.mainPlayer.allItemsInBag.Count + addItemCount >= Player.mainPlayer.maxBagCount * CommonData.singleBagItemVolume; if (bagFull) { bagView.hintHUD.SetUpSingleTextTintHUD("背包已满"); return; } break; default: break; } propertyChange = specialItem.UseSpecialItem(itemForSpecialOperation, bagView.itemDetail.SetUpItemDetail); bagView.SetUpEquipedEquipmentsPlane(); bagView.SetUpPlayerStatusPlane(propertyChange); break; } // 如果玩家正在战斗中,更新技能按钮状态 if (ExploreManager.Instance.battlePlayerCtr.isInFight) { ExploreManager.Instance.expUICtr.UpdateActiveSkillButtons(); } // 从背包中移除当前选中的物品,如果该物品完全从背包中移除了,则清空物品详细信息面板 clearItemDetail = Player.mainPlayer.RemoveItem(currentSelectItem, 1); // 更新当前背包 bagView.UpdateCurrentBagItemsPlane(); if (clearItemDetail) { bagView.ClearItemDetail(); } // 进行特殊操作的物品,特殊操作结束后显示被操作物品的信息,并在背包中将该物品的选中框高亮 if (specialOperaitonItem != null) { currentSelectItem = specialOperaitonItem; bagView.SetUpItemDetail(specialOperaitonItem); int specialOperaitonItemIndexInBag = Player.mainPlayer.GetItemIndexInBag(specialOperaitonItem); if (specialOperaitonItemIndexInBag >= 0) { int itemIndexInCurrentBag = specialOperaitonItemIndexInBag % CommonData.singleBagItemVolume; bagView.bagItemsDisplay.SetSelectionIcon(itemIndexInCurrentBag, true); } } // 非特殊操作的物品,如果使用完之后还没有从背包中完全移除,则显示物品的选中框 else if (!totallyRemoved) { int itemIndexInBag = Player.mainPlayer.GetItemIndexInBag(currentSelectItem); if (itemIndexInBag >= 0) { int itemIndexInCurrentBag = itemIndexInBag % CommonData.singleBagItemVolume; bagView.bagItemsDisplay.SetSelectionIcon(itemIndexInCurrentBag, true); } } }