/// <summary>
        /// 初始化所有消耗品显示界面
        /// </summary>
        public void SetUpConsumablesInBagPlane()
        {
            UpdatePageButtonStatus();

            consumablesButtonPool.AddChildInstancesToPool(consumablesInBagContainer);

            if (player.allConsumablesInBag.Count <= equipedConsumablesButtons.Length)
            {
                return;
            }

            int firstIndexOfCurrentPage = equipedConsumablesButtons.Length + currentConsumablesPage * consumablesCountInOnePage;

            int firstIndexOfNextPage = firstIndexOfCurrentPage + consumablesCountInOnePage;

            int endIndexOfConsumablesInCurrentPage = player.allConsumablesInBag.Count < firstIndexOfNextPage ? player.allConsumablesInBag.Count - 1 : firstIndexOfNextPage - 1;

            for (int i = firstIndexOfCurrentPage; i <= endIndexOfConsumablesInCurrentPage; i++)
            {
                Consumables consumables = Player.mainPlayer.allConsumablesInBag [i];

                Button consumablesButton = consumablesButtonPool.GetInstance <Button> (consumablesButtonModel.gameObject, consumablesInBagContainer);

                consumablesButton.GetComponent <ConsumablesInBagCell> ().SetUpConsumablesInBagCell(consumables);
            }
        }
        protected override void OnUserDrop(UnityEngine.EventSystems.PointerEventData eventData)
        {
            // 获取拖拽中的物品
            Consumables consumablesPrepareToLoad = GetDraggedItem(eventData) as Consumables;

            // 没有拖拽中的物品或者物品类型不是装备直接返回
            if (consumablesPrepareToLoad == null || consumablesPrepareToLoad.itemType != ItemType.Consumables)
            {
                SetDropResult(eventData, false);
                tintImage.enabled = false;
                return;
            }

            Consumables consumablesPrepareToUnload = Player.mainPlayer.allConsumablesInBag [consumablesIndexInPanel];

            int indexOfConsumablesPrepareToLoad   = GetConsumablesIndexInBag(consumablesPrepareToLoad);
            int indexOfConsumablesPrepareToUnload = consumablesIndexInPanel;

            Player.mainPlayer.allConsumablesInBag [indexOfConsumablesPrepareToLoad]   = consumablesPrepareToUnload;
            Player.mainPlayer.allConsumablesInBag [indexOfConsumablesPrepareToUnload] = consumablesPrepareToLoad;

            explorePlayerUICtr.SetUpBottomConsumablesButtons();
            explorePlayerUICtr.SetUpConsumablesInBagPlane();


            SetDropResult(eventData, true);

            tintImage.enabled = false;
        }
Beispiel #3
0
        public void SetUpConsumablesInBagCell(Consumables consumables)
        {
            if (consumables == null)
            {
                itemIcon.enabled = false;
//				NewItemTintIcon.enabled = false;
                itemCount.text = "";
                consumablesButton.interactable = false;
                return;
            }

            consumablesButton.interactable = true;

            ConsumablesInBagDragControl dragControl = gameObject.GetComponent <ConsumablesInBagDragControl> ();

            if (dragControl != null)
            {
                dragControl.item = consumables;
            }

            Sprite itemSprite = GameManager.Instance.gameDataCenter.allItemSprites.Find(delegate(Sprite obj) {
                return(obj.name == consumables.spriteName);
            });

            itemIcon.sprite = itemSprite;

            itemIcon.enabled = itemSprite != null;

//			NewItemTintIcon.enabled = consumables.isNewItem;

            itemCount.text = consumables.itemCount.ToString();
        }
        /// <summary>
        /// 初始化工具选择栏
        /// </summary>
        /// <param name="mapItem">Map item.</param>
        public void SetUpToolChoicePlane(MapItem mapItem, Consumables tool)
        {
            Transform toolChoiceButton = Instantiate(toolChoiceButtonModel.gameObject).transform;

            toolChoiceButton.SetParent(toolChoicesContaienr);
            toolChoiceButton.localScale    = Vector3.one;
            toolChoiceButton.localRotation = Quaternion.identity;
//			Transform toolChoiceButton = toolChoiceButtonPool.GetInstance<Transform> (toolChoiceButtonModel.gameObject, toolChoicesContaienr);

            Image toolIcon = toolChoiceButton.Find("ToolIcon").GetComponent <Image> ();

            Text toolCount = toolChoiceButton.Find("ToolCount").GetComponent <Text> ();

            Sprite s = GameManager.Instance.gameDataCenter.allItemSprites.Find(delegate(Sprite obj) {
                return(obj.name == tool.spriteName);
            });


            toolIcon.sprite  = s;
            toolIcon.enabled = s != null;


            toolCount.text = tool.itemCount.ToString();

            toolChoiceButton.GetComponent <Button> ().onClick.RemoveAllListeners();

            toolChoiceButton.GetComponent <Button> ().onClick.AddListener(delegate() {
                OnToolChoiceButtonClick(tool, mapItem);
            });

            toolChoicesPlane.gameObject.SetActive(true);
        }
 private int GetConsumablesIndexInBag(Consumables consumables)
 {
     for (int i = 0; i < Player.mainPlayer.allConsumablesInBag.Count; i++)
     {
         if (Player.mainPlayer.allConsumablesInBag [i] == consumables)
         {
             return(i);
         }
     }
     return(-1);
 }
        public void ShowConsumablesValidPointTintAround(Consumables consumables)
        {
//			Debug.Log ("显示消耗品使用范围提示");

            if (battlePlayerCtr.pathPosList.Count > 0)
            {
                battlePlayerCtr.StopMoveAtEndOfCurrentStep();
            }

            StartCoroutine("LatelyShowConsumablesValidTints", consumables);
        }
        public void OnConsumablesButtonClick(Consumables consumables)
        {
            bool consumblesUsedInExploreScene = false;

            switch (consumables.itemName)
            {
            case "药剂":
            case "草药":
            case "蓝莓":
            case "菠菜":
            case "胡萝卜":
            case "樱桃":
            case "南瓜":
            case "蘑菇":
            case "辣椒":
                Player.mainPlayer.UseMedicines(consumables);
                consumblesUsedInExploreScene = false;
                break;

            case "卷轴":
                player.RemoveItem(consumables, 1);
                player.ResetBattleAgentProperties(true);
                exploreManager.GetComponent <ExploreManager> ().QuitExploreScene(true);
                consumblesUsedInExploreScene = false;
                break;

            case "锄头":
            case "锯子":
            case "镰刀":
            case "钥匙":
            case "树苗":
            case "火把":
            case "水":
            case "地板":
            case "开关":
            case "土块":
                consumblesUsedInExploreScene = true;
                break;
            }

            if (consumblesUsedInExploreScene)
            {
                exploreManager.clickForConsumablesPos = true;
                exploreManager.ShowConsumablesValidPointTintAround(consumables);
            }
            else
            {
                SetUpBottomConsumablesButtons();
                SetUpConsumablesInBagPlane();
            }

            QuitConsumablesInBagPlane();
        }
Beispiel #8
0
        public static Item NewItemWith(Item item, int itemCount)
        {
//			ItemModel itemModel = null;
            Item newItem = null;

            switch (item.itemType)
            {
            case ItemType.Equipment:
                newItem = new Equipment(item as Equipment);
                break;

            case ItemType.Consumables:
                newItem = new Consumables(item as Consumables, itemCount);
                break;
            }
            return(newItem);
        }
Beispiel #9
0
        public Agent.PropertyChange UseMedicines(Consumables consumables)
        {
            if (consumables.attachedSkillInfos.Length > 0)
            {
                for (int i = 0; i < consumables.attachedSkillInfos.Length; i++)
                {
                    SkillInfo        si = consumables.attachedSkillInfos [i];
                    ConsumablesSkill cs = SkillGenerator.Instance.GenerateConsumablesSkill(consumables, si, consumablesSkillsContainer);
                    cs.AffectAgents(battleAgentCtr, null);
                }
                RemoveItem(consumables, 1);
            }

            Debug.LogFormat("{0}使用了{1}", agentName, consumables.itemName);

            return(ResetBattleAgentProperties(false));
        }
Beispiel #10
0
        /// <summary>
        /// 通过物品id和数量初始化物品
        /// </summary>
        public static Item NewItemWith(int itemId, int itemCount)
        {
            ItemModel itemModel = null;
            Item      newItem   = null;

            if (itemId < 200)
            {
                itemModel = GameManager.Instance.gameDataCenter.allItemModels.Find(delegate(ItemModel obj) {
                    return(obj.itemId == itemId);
                });

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

                switch (itemModel.itemType)
                {
                case ItemType.Equipment:
                    newItem = new Equipment(itemModel, itemCount);
                    break;

                case ItemType.Consumables:
                    newItem = new Consumables(itemModel, itemCount);
                    break;
                }
            }
            else if (itemId < 400)
            {
                itemModel = GameManager.Instance.gameDataCenter.allItemModels.Find(delegate(ItemModel obj) {
                    return(obj.itemId == itemId - 200);
                });
                newItem = new UnlockScroll(itemModel);
            }
            else
            {
                itemModel = GameManager.Instance.gameDataCenter.allItemModels.Find(delegate(ItemModel obj) {
                    return(obj.itemId == itemId - 400);
                });
                newItem = new CraftingRecipe(itemModel);
            }

            return(newItem);
        }
        private void EnterObstacle(Transform obstacleTrans)
        {
            Obstacle obstacle = obstacleTrans.GetComponent <Obstacle>();

            Consumables tool = Player.mainPlayer.allConsumablesInBag.Find(delegate(Consumables obj) {
                return(obj.itemName == obstacle.destroyToolName);
            });

            if (tool != null)
            {
                expUICtr.GetComponent <BattlePlayerUIController> ().SetUpToolChoicePlane(obstacle, tool);
            }
            else
            {
                string tint = string.Format("缺少{0}x1", obstacle.destroyToolName);
                expUICtr.SetUpTintHUD(tint, null);
            }
        }
        private void EnterPlant(Transform plantTransform)
        {
            Plant obstacle = plantTransform.GetComponent <Plant>();

            Consumables tool = Player.mainPlayer.allConsumablesInBag.Find(delegate(Consumables obj) {
                return(obj.itemName == "镰刀");
            });

            if (tool != null)
            {
                expUICtr.GetComponent <BattlePlayerUIController> ().SetUpToolChoicePlane(obstacle, tool);
            }
            else
            {
                expUICtr.SetUpTintHUD("缺少镰刀x1", null);
            }

//			Debug.Log ("碰到了植物");
        }
        private void EnterTreasureBox(Transform treasureBoxTrans)
        {
            TreasureBox tb = treasureBoxTrans.GetComponent <TreasureBox>();

            // 如果mapitem已打开,则直接返回
            if (tb.unlockItemName != "" && !tb.locked)
            {
                return;
            }

            // 如果该宝箱不需要使用钥匙开启
            if (tb.unlockItemName == "")
            {
//				SoundManager.Instance.PlayAudioClip ("MapEffect/" + tb.audioClipName);

                mapGenerator.mapWalkableInfoArray [(int)tb.transform.position.x, (int)tb.transform.position.y] = 1;

                tb.GetComponent <BoxCollider2D> ().enabled = false;

                // 如果该地图物品不需要使用特殊物品开启
                tb.UnlockTreasureBox(() => {
                    mapGenerator.SetUpAwardInMap(tb.awardItem, tb.transform.position);
                });

                return;
            }

            // 宝箱需要使用钥匙开启
            // 查找背包中是否有钥匙
            Consumables key = Player.mainPlayer.allConsumablesInBag.Find(delegate(Consumables obj) {
                return(obj.itemName == tb.unlockItemName);
            });

            // 如果背包中有钥匙,则进入工具选择栏
            if (key != null)
            {
                expUICtr.GetComponent <BattlePlayerUIController> ().SetUpToolChoicePlane(tb, key);
            }
            else
            {
                expUICtr.SetUpTintHUD("缺少钥匙x1", null);
            }
        }
Beispiel #14
0
        public Consumables(Consumables cons, int count)
        {
            // 初始化物品基础属性
            this.itemId   = cons.itemId;
            this.itemName = cons.itemName;
            this.itemGeneralDescription  = cons.itemGeneralDescription;
            this.itemPropertyDescription = cons.itemPropertyDescription;
            this.spriteName        = cons.spriteName;
            this.itemType          = cons.itemType;
            this.itemNameInEnglish = cons.itemNameInEnglish;

            this.itemType  = ItemType.Consumables;
            this.itemCount = count;

            this.attachedSkillInfos  = cons.attachedSkillInfos;
            this.itemInfosForProduce = cons.itemInfosForProduce;

            this.price = cons.price;
        }
        /// <summary>
        /// 更新底部物品栏状态
        /// </summary>
        public void SetUpBottomConsumablesButtons()
        {
            int totalConsumablesCount = player.allConsumablesInBag.Count;

            for (int i = 0; i < equipedConsumablesButtons.Length; i++)
            {
                Button equipedConsumablesButton = equipedConsumablesButtons [i];

                if (i < totalConsumablesCount)
                {
                    Consumables consumables = player.allConsumablesInBag [i];

                    equipedConsumablesButton.GetComponent <ConsumablesInBagCell> ().SetUpConsumablesInBagCell(consumables);
                }
                else
                {
                    equipedConsumablesButton.GetComponent <ConsumablesInBagCell> ().SetUpConsumablesInBagCell(null);
                }
            }
        }
        /// <summary>
        /// 选择了一种工具后的响应方法
        /// </summary>
        /// <param name="tool">Tool.</param>
        /// <param name="mapItem">Map item.</param>
        private void OnToolChoiceButtonClick(Consumables tool, MapItem mapItem)
        {
            QuitToolChoicePlane();

            // 背包中的工具数量-1
            player.RemoveItem(tool, 1);

            // 播放对应的音效
            SoundManager.Instance.PlayAudioClip("MapEffects/" + mapItem.audioClipName);

            Vector3      mapItemPos   = mapItem.transform.position;
            MapGenerator mapGenerator = TransformManager.FindTransform("ExploreManager").GetComponent <MapGenerator> ();

            int[,] mapWalkableInfoArray = mapGenerator.mapWalkableInfoArray;

            switch (mapItem.mapItemType)
            {
            case MapItemType.Stone:
            case MapItemType.Tree:
                (mapItem as Obstacle).DestroyObstacle(null);
                mapWalkableInfoArray [(int)mapItemPos.x, (int)mapItemPos.y] = 1;
                break;

            case MapItemType.TreasureBox:
                TreasureBox tb = mapItem as TreasureBox;
                tb.UnlockTreasureBox(null);
                mapWalkableInfoArray [(int)mapItemPos.x, (int)mapItemPos.y] = 1;
                mapGenerator.SetUpAwardInMap(tb.awardItem, mapItemPos);
                break;

            case MapItemType.Plant:
                Plant plant = mapItem as Plant;
                mapGenerator.AddMapItemInPool(mapItem.transform);
                mapWalkableInfoArray [(int)mapItemPos.x, (int)mapItemPos.y] = 1;
                mapGenerator.SetUpAwardInMap(plant.attachedItem, mapItemPos);
                break;
            }

            SetUpBottomConsumablesButtons();
        }
Beispiel #17
0
        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();
            }
        }
Beispiel #18
0
        public static Item NewItemWith(ItemModel itemModel, int itemCount)
        {
            Item newItem = null;

            if (itemModel == null)
            {
                string error = string.Format("传入的物品模型为null");
                Debug.LogError(error);
            }

            switch (itemModel.itemType)
            {
            case ItemType.Equipment:
                newItem = new Equipment(itemModel, itemCount);
                break;

            case ItemType.Consumables:
                newItem = new Consumables(itemModel, itemCount);
                break;
            }

            return(newItem);
        }
Beispiel #19
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);
        }
Beispiel #20
0
        /// <summary>
        /// 生成奖励物品
        /// </summary>
        /// <returns>The reward item.</returns>
        public Item GenerateRewardItem()
        {
            Monster monster = GetComponent <Monster>();

            Item rewardItem = null;

            if (monster.isBoss)
            {
                if (!hasReward)
                {
                    return(null);
                }

                int index = 0;
                if (monster.monsterId % 2 == 0)
                {
                    index = (Player.mainPlayer.currentLevelIndex / 5 + 1) * 1000;

                    List <EquipmentModel> ems = GameManager.Instance.gameDataCenter.allEquipmentModels.FindAll(delegate(EquipmentModel obj)
                    {
                        return(obj.equipmentGrade == index);
                    });

                    int randomSeed = Random.Range(0, ems.Count);

                    rewardItem = new Equipment(ems[randomSeed], 1);
                }
                else
                {
                    index = (Player.mainPlayer.currentLevelIndex / 5 + 2);
                    if (index == 10)
                    {
                        index = 9;
                    }

                    List <EquipmentModel> ems = GameManager.Instance.gameDataCenter.allEquipmentModels.FindAll(delegate(EquipmentModel obj)
                    {
                        return(obj.equipmentGrade == index);
                    });

                    int randomSeed = Random.Range(0, ems.Count);

                    rewardItem = new Equipment(ems[randomSeed], 1);

                    (rewardItem as Equipment).SetToGoldQuality();
                }
            }
            else
            {
                int randomSeed = Random.Range(0, 100);

                int dropItemSeed = 0;

                switch (Player.mainPlayer.luckInMonsterTreasure)
                {
                case 0:
                    dropItemSeed = 5 + Player.mainPlayer.extraLuckInMonsterTreasure;
                    break;

                case 1:
                    dropItemSeed = 10 + Player.mainPlayer.extraLuckInMonsterTreasure;
                    break;
                }

                if (randomSeed >= 0 && randomSeed < dropItemSeed)
                {
                    randomSeed = Random.Range(0, 10);

                    // 掉落物品是30%的概率掉落装备
                    if (randomSeed <= 2)
                    {
                        int index = Player.mainPlayer.currentLevelIndex / 5 + 1;

                        if (index == 10)
                        {
                            index = 9;
                        }

                        List <EquipmentModel> ems = GameManager.Instance.gameDataCenter.allEquipmentModels.FindAll(delegate(EquipmentModel obj)
                        {
                            return(obj.equipmentGrade == index);
                        });
                        randomSeed = Random.Range(0, ems.Count);
                        rewardItem = new Equipment(ems[randomSeed], 1);
                    }
                    else
                    {
                        int consumablesGrade = Player.mainPlayer.currentLevelIndex / 10;

                        if (consumablesGrade >= 4)
                        {
                            consumablesGrade = 3;
                        }

                        List <ConsumablesModel> cms = GameManager.Instance.gameDataCenter.allConsumablesModels.FindAll(delegate(ConsumablesModel obj)
                        {
                            return(obj.consumablesGrade == consumablesGrade);
                        });

                        randomSeed = Random.Range(0, cms.Count);

                        rewardItem = new Consumables(cms[randomSeed], 1);
                    }
                }
                else
                {
                    rewardItem = null;
                }
            }

            return(rewardItem);
        }
Beispiel #21
0
        public void RemoveItem(Item item, int removeCount)
        {
            switch (item.itemType)
            {
            case ItemType.Equipment:

                Equipment equipment = allEquipmentsInBag.Find(delegate(Equipment obj) {
                    return(obj == item);
                });

                if (equipment.equiped)
                {
                    for (int i = 0; i < allEquipedEquipments.Length; i++)
                    {
                        if (allEquipedEquipments [i] == equipment)
                        {
                            allEquipedEquipments [i] = new Equipment();
                        }
                    }
                }

                allEquipmentsInBag.Remove(equipment);

                allItemsInBag.Remove(equipment);
//				TransformManager.FindTransform ("BagCanvas").GetComponent<BagViewController> ().RemoveItem (item);
                break;

            // 如果是消耗品,且背包中已经存在该消耗品,则只合并数量
            case ItemType.Consumables:
                Consumables consumablesInBag = allConsumablesInBag.Find(delegate(Consumables obj) {
                    return(obj == item);
                });

                consumablesInBag.itemCount -= removeCount;

                if (consumablesInBag.itemCount <= 0)
                {
                    allConsumablesInBag.Remove(consumablesInBag);
                    allItemsInBag.Remove(consumablesInBag);
//					TransformManager.FindTransform ("BagCanvas").GetComponent<BagViewController> ().RemoveItem (item);
                }
                break;

            case ItemType.UnlockScroll:
                UnlockScroll unlockScroll = allUnlockScrollsInBag.Find(delegate(UnlockScroll obj) {
                    return(obj == item);
                });
                if (!unlockScroll.unlocked)
                {
                    allUnlockScrollsInBag.Remove(unlockScroll);
                }
                allItemsInBag.Remove(unlockScroll);
                break;

            case ItemType.CraftingRecipes:
                allItemsInBag.Remove(item);
                allCraftingRecipesInBag.Remove(item as CraftingRecipe);
                break;

            case ItemType.CharacterFragment:
                CharacterFragment characterFragment = item as CharacterFragment;
                int characterIndex = (int)(characterFragment.character) - CommonData.aInASCII;
                if (charactersCount [characterIndex] > 0)
                {
                    charactersCount [characterIndex]--;
                }
                break;
            }
//			return removeFromBag;
        }
Beispiel #22
0
        /// <summary>
        /// 添加物品到背包中
        /// </summary>
        /// <param name="item">Item.</param>
        public void AddItem(Item item)
        {
            if (item == null)
            {
                string error = "添加的物品为null";
                Debug.LogError(error);
                return;
            }

            switch (item.itemType)
            {
            case ItemType.Equipment:
                for (int i = 0; i < item.itemCount; i++)
                {
                    Equipment equipment = Item.NewItemWith(item, 1) as Equipment;
                    allEquipmentsInBag.Add(equipment);
                    allItemsInBag.Add(equipment);
                }
                break;

            // 如果是消耗品,且背包中已经存在该消耗品,则只合并数量
            case ItemType.Consumables:
                Consumables consumablesInBag = allConsumablesInBag.Find(delegate(Consumables obj) {
                    return(obj.itemId == item.itemId);
                });
                if (consumablesInBag != null)
                {
                    consumablesInBag.itemCount += item.itemCount;
                }
                else
                {
                    consumablesInBag = new Consumables(item as Consumables, item.itemCount);
                    allConsumablesInBag.Add(item as Consumables);
                    allItemsInBag.Add(item);
                }
                break;

//			case ItemType.FuseStone:
//				allFuseStonesInBag.Add (item as FuseStone);
//				allItemsInBag.Add (item);
//				break;
//			case ItemType.Task:
//				allTaskItemsInBag.Add (item as TaskItem);
//				allItemsInBag.Add (item);
//				break;
            case ItemType.UnlockScroll:
                UnlockScroll unlockScroll = item as UnlockScroll;
                allUnlockScrollsInBag.Add(unlockScroll);
                allItemsInBag.Add(unlockScroll);
                break;

            case ItemType.CraftingRecipes:
                allItemsInBag.Add(item);
                allCraftingRecipesInBag.Add(item as CraftingRecipe);
                break;

            case ItemType.CharacterFragment:
                CharacterFragment characterFragment = item as CharacterFragment;
                int characterIndex = (int)(characterFragment.character) - CommonData.aInASCII;
                charactersCount [characterIndex]++;
                break;
            }
        }
Beispiel #23
0
        /// <summary>
        /// 在物品详细信息页点击了使用按钮(消耗品)
        /// </summary>
        public void OnUseButtonClick()
        {
            Debug.Log("使用了" + currentSelectItem.itemName);

            bool consumblesUsedInExploreScene = false;

            Consumables consumables = currentSelectItem as Consumables;

            Agent.PropertyChange propertyChange = new Agent.PropertyChange();

            switch (consumables.itemName)
            {
            case "药剂":
            case "草药":
            case "蓝莓":
            case "菠菜":
            case "胡萝卜":
            case "樱桃":
            case "南瓜":
            case "蘑菇":
            case "辣椒":

                propertyChange = Player.mainPlayer.UseMedicines(consumables);

                bagView.SetUpPlayerStatusPlane(propertyChange);

                consumblesUsedInExploreScene = false;
                break;

            case "卷轴":

                Player.mainPlayer.RemoveItem(consumables, 1);

                Player.mainPlayer.ResetBattleAgentProperties(true);

                TransformManager.FindTransform("ExploreManager").GetComponent <ExploreManager> ().QuitExploreScene(true);

                consumblesUsedInExploreScene = false;
                break;

            case "锄头":
            case "锯子":
            case "镰刀":
            case "钥匙":
            case "树苗":
            case "火把":
            case "水":
            case "地板":
            case "土块":
            case "开关":
                consumblesUsedInExploreScene = true;
                break;
            }

            bagView.QuitItemDetailHUD();

            if (consumblesUsedInExploreScene)
            {
                OnQuitBagPlaneButtonClick();
                exploreManager.GetComponent <ExploreManager>().clickForConsumablesPos = true;
                exploreManager.GetComponent <ExploreManager>().ShowConsumablesValidPointTintAround(consumables);
            }

            if (!Player.mainPlayer.CheckBagFull())
            {
                AddItemInWait();
            }

            bagView.SetUpCurrentBagItemsPlane();
        }
Beispiel #24
0
        public void SetUpConsumablesButtons()
        {
            ClearConsumablesButtons();

            int minIndex = consumablesDisplayCount * consumablesDisplayIndex;

            int validCount = 0;

            int indexInPanel = 0;

            for (int i = 0; i < Player.mainPlayer.allConsumablesInBag.Count; i++)
            {
                Consumables cons = Player.mainPlayer.allConsumablesInBag [i];

                if (cons.isShowInBagOnly)
                {
                    continue;
                }

                if (validCount < minIndex)
                {
                    validCount++;
                    continue;
                }

                consCells [indexInPanel].SetUpConsumablesCell(cons, delegate {
                    SetUpConsumablesButtons();
                    refreshPlayerStatusPlane();
                });

                indexInPanel++;

                if (indexInPanel >= consumablesDisplayCount)
                {
                    return;
                }
            }

            for (int i = 0; i < Player.mainPlayer.allSpecialItemsInBag.Count; i++)
            {
                SpecialItem specialItem = Player.mainPlayer.allSpecialItemsInBag[i];

                if (specialItem.isShowInBagOnly)
                {
                    continue;
                }

                if (validCount < minIndex)
                {
                    validCount++;
                    continue;
                }

                consCells[indexInPanel].SetUpConsumablesCell(specialItem, delegate {
                    SetUpConsumablesButtons();
                    refreshPlayerStatusPlane();
                });

                indexInPanel++;

                if (indexInPanel >= consumablesDisplayCount)
                {
                    return;
                }
            }
        }
Beispiel #25
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);
                }
            }
        }
        private IEnumerator LatelyShowConsumablesValidTints(Consumables consumables)
        {
            yield return(new WaitUntil(() => battlePlayerCtr.isIdle));

            mapGenerator.ShowConsumablesValidPointsTint(consumables);
        }
        public void OnEquipedConsumablesButtonClick(int indexInPanel)
        {
            Consumables consumables = player.allConsumablesInBag [indexInPanel];

            OnConsumablesButtonClick(consumables);
        }