예제 #1
0
        /// <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);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 通过物品id和数量初始化物品
        /// 【0-299】装备
        /// 【300-399】消耗品
        /// 【400-499】属性宝石
        /// 【500-599】技能卷轴
        /// 【600-699】特殊物品
        /// </summary>
        public static Item NewItemWith(int itemId, int itemCount)
        {
            Item newItem = null;

            // 逻辑上相同:寻找数据模型->使用数据模型创建新物品

            if (itemId < 300)
            {
                EquipmentModel equipmentModel = GameManager.Instance.gameDataCenter.allEquipmentModels.Find(delegate(EquipmentModel obj)
                {
                    return(obj.itemId == itemId);
                });

                if (equipmentModel == null)
                {
                    string error = string.Format("未找到id为{0}的物品", itemId);
                    Debug.LogError(error);
                }

                newItem = new Equipment(equipmentModel, itemCount);
            }
            else if (itemId >= 300 && itemId < 400)
            {
                ConsumablesModel cm = GameManager.Instance.gameDataCenter.allConsumablesModels.Find(delegate(ConsumablesModel obj)
                {
                    return(obj.itemId == itemId);
                });

                if (cm == null)
                {
                    string error = string.Format("未找到id为{0}的物品", itemId);
                    Debug.LogError(error);
                }

                newItem = new Consumables(cm, itemCount);
            }
            else if (itemId >= 400 && itemId < 500)
            {
                PropertyGemstoneModel propertyGemstoneModel = GameManager.Instance.gameDataCenter.allPropertyGemstoneModels.Find(delegate(PropertyGemstoneModel obj)
                {
                    return(obj.itemId == itemId);
                });

                if (propertyGemstoneModel == null)
                {
                    string error = string.Format("未找到id为{0}的物品", itemId);
                    Debug.LogError(error);
                }

                newItem = new PropertyGemstone(propertyGemstoneModel, itemCount);
            }
            else if (itemId >= 500 && itemId < 600)
            {
                SkillScrollModel skillScrollModel = GameManager.Instance.gameDataCenter.allSkillScrollModels.Find(delegate(SkillScrollModel obj)
                {
                    return(obj.itemId == itemId);
                });

                if (skillScrollModel == null)
                {
                    string error = string.Format("未找到id为{0}的物品", itemId);
                    Debug.LogError(error);
                }

                newItem = new SkillScroll(skillScrollModel, itemCount);
            }
            else if (itemId >= 600 && itemId < 700)
            {
                SpecialItemModel specialItemModel = GameManager.Instance.gameDataCenter.allSpecialItemModels.Find(delegate(SpecialItemModel obj)
                {
                    return(obj.itemId == itemId);
                });
                if (specialItemModel == null)
                {
                    string error = string.Format("未找到id为{0}的物品", itemId);
                    Debug.LogError(error);
                }
                newItem = new SpecialItem(specialItemModel, itemCount);
            }

            return(newItem);
        }