Exemplo n.º 1
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;
            }
        }
Exemplo n.º 2
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;
        }
        public void BattlePlayerWin(Transform[] monsterTransArray)
        {
            (battlePlayerCtr.agent as Player).DestroyEquipmentInBagAttachedSkills();

            battlePlayerCtr.enemy = null;

            battleMonsterCtr.enemy = null;

//			battlePlayerCtr.RemoveTriggeredSkillEffect ();
//			battleMonsterCtr.RemoveTriggeredSkillEffect ();

            FightEndCallBacks();

            battlePlayerCtr.agent.ResetBattleAgentProperties(false);

            mapGenerator.AddAllEffectAnimToPool();

            if (monsterTransArray.Length <= 0)
            {
                return;
            }

            Transform trans = monsterTransArray [0];

            Vector3 monsterPos = trans.GetComponent <BattleMonsterController> ().originalPos;

            // 位置偏差修正
            int X = Mathf.RoundToInt(monsterPos.x);
            int Y = Mathf.RoundToInt(monsterPos.y);

            mapGenerator.mapWalkableInfoArray [X, Y] = 1;

            Player player = battlePlayerCtr.agent as Player;

            player.experience += trans.GetComponent <Monster> ().rewardExperience; //更新玩家经验值

            bool isLevelUp = player.LevelUpIfExperienceEnough();                   //判断是否升级

            if (isLevelUp)
            {
                PlayLevelUpAnim();
            }


            Item award = null;

            // 怪物是普通怪
            if (monsterTransArray [0].GetComponent <Monster> ().monsterId < 50)
            {
                int characterIndex = Random.Range(0, 26);

                char character = (char)(characterIndex + CommonData.aInASCII);

                award = new CharacterFragment(character, 1);
            }
            else
            {
                int randomCraftingRecipesId = Random.Range(450, 460);

                award = Item.NewItemWith(randomCraftingRecipesId, 1);
            }


            mapGenerator.SetUpAwardInMap(award, monsterPos);

            ResetCamareAndContinueMove(battleMonsterCtr.originalPos);
        }