/// <summary> /// 查找人物身上对应的钥匙 /// </summary> /// <returns>The key for key type.</returns> /// <param name="keyType">Key type.</param> private List <SpecialItem> FindAllKeyOnPlayer() { List <SpecialItem> keys = new List <SpecialItem>(); SpecialItem key = null; key = Player.mainPlayer.allSpecialItemsInBag.Find(delegate(SpecialItem obj) { return(obj.specialItemType == SpecialItemType.TieYaoShi); }); if (key != null) { keys.Add(key); } key = Player.mainPlayer.allSpecialItemsInBag.Find(delegate(SpecialItem obj) { return(obj.specialItemType == SpecialItemType.TongYaoShi); }); if (key != null) { keys.Add(key); } key = Player.mainPlayer.allSpecialItemsInBag.Find(delegate(SpecialItem obj) { return(obj.specialItemType == SpecialItemType.JinYaoShi); }); if (key != null) { keys.Add(key); } key = Player.mainPlayer.allSpecialItemsInBag.Find(delegate(SpecialItem obj) { return(obj.specialItemType == SpecialItemType.WanNengYaoShi); }); if (key != null) { keys.Add(key); } key = Player.mainPlayer.allSpecialItemsInBag.Find(delegate(SpecialItem obj) { return(obj.specialItemType == SpecialItemType.QiaoZhen); }); if (key != null) { keys.Add(key); } return(keys); }
private void SetUpKeysSelect(List <SpecialItem> keys) { toolButtonPool.AddChildInstancesToPool(toolButtonContainer); for (int i = 0; i < keys.Count; i++) { SpecialItem tool = keys[i]; ToolButton toolButton = toolButtonPool.GetInstance <ToolButton>(toolButtonModel.gameObject, toolButtonContainer); toolButton.SetUpToolButton(tool, ToolSelectCallBack); } }
public void SetUpToolButton(SpecialItem tool, CallBackWithItem toolSelectCallBack) { toolIcon.sprite = GameManager.Instance.gameDataCenter.allSpecialItemSprites.Find(delegate(Sprite obj) { return(obj.name == tool.spriteName); }); toolName.text = tool.itemName; toolCount.text = tool.itemCount.ToString(); toolButton.onClick.RemoveAllListeners(); toolButton.onClick.AddListener(delegate { toolSelectCallBack(tool); }); }
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(); } }
private void ToolSelectCallBack(Item tool) { SpecialItem key = tool as SpecialItem; bool needEnterUnlockOperator = true; hintIndexList.Clear(); int hintCount = 0; List <int> allIndex = new List <int>(); for (int i = 0; i < keyDoorWord.wordLength; i++) { allIndex.Add(i); } switch (key.specialItemType) { case SpecialItemType.TieYaoShi: hintCount = 1; keyIcon.sprite = ironKeySprite; hintText.text = "铁钥匙可提示一个字母"; break; case SpecialItemType.TongYaoShi: hintCount = 2; keyIcon.sprite = brassKeySprite; hintText.text = "铜钥匙可提示两个字母"; break; case SpecialItemType.JinYaoShi: keyIcon.sprite = goldKeySprite; hintText.text = "金钥匙可提示三个字母"; hintCount = 3; break; case SpecialItemType.WanNengYaoShi: unlockSuccessCallBack(null); needEnterUnlockOperator = false; QuitKeyDoorOperatorView(); break; case SpecialItemType.QiaoZhen: unlockSuccessCallBack(null); needEnterUnlockOperator = false; QuitKeyDoorOperatorView(); break; } Player.mainPlayer.RemoveItem(key, 1); if (needEnterUnlockOperator) { toolButtonPool.AddChildInstancesToPool(toolButtonContainer); char[] characters = keyDoorWord.spell.ToCharArray(); for (int i = 0; i < hintCount; i++) { int randomSeed = Random.Range(0, allIndex.Count); int index = allIndex[randomSeed]; hintIndexList.Add(index); char character = characters[index]; SetCharacterAsHint(character, index); allIndex.RemoveAt(randomSeed); } unlockOperationPlane.gameObject.SetActive(true); toolSelectPlane.gameObject.SetActive(false); } }
public void SetUpItemDetail(Item item) { ClearItemDetails(); Sprite itemSprite = GameManager.Instance.gameDataCenter.GetGameItemSprite(item); itemIcon.sprite = itemSprite; itemIcon.enabled = true; itemIconBackground.enabled = true; itemName.text = item.itemName; itemIconBackground.sprite = grayEquipmentFrame; itemName.color = CommonData.grayEquipmentColor; goldIcon.enabled = true; priceText.text = (item.price / 8).ToString(); switch (item.itemType) { case ItemType.Equipment: Equipment eqp = item as Equipment; itemDescription.text = item.itemDescription; specialOperationHint.enabled = false; attachedDescription.text = eqp.attachedPropertyDescription; switch (eqp.quality) { case EquipmentQuality.Gray: itemName.color = CommonData.grayEquipmentColor; itemIconBackground.sprite = grayEquipmentFrame; break; case EquipmentQuality.Blue: itemName.color = CommonData.blueEquipmentColor; itemIconBackground.sprite = blueEquipmentFrame; break; case EquipmentQuality.Gold: itemName.color = CommonData.goldEquipmentColor; itemIconBackground.sprite = goldEquipmentFrame; break; case EquipmentQuality.Purple: itemName.color = CommonData.purpleEquipmentColor; itemIconBackground.sprite = purpleEquipmentFrame; break; } SetUpOperationButtons(!eqp.equiped, eqp.equiped, false); specialOperationContainer.gameObject.SetActive(false); attachedGemstoneDisplay.SetUpAttachedSkillDisplay(eqp.attachedPropertyGemstones); attachedGemstoneDisplay.gameObject.SetActive(true); break; case ItemType.Consumables: //Consumables cons = item as Consumables; attachedDescription.text = item.itemDescription; SetUpOperationButtons(false, false, true); specialOperationContainer.gameObject.SetActive(false); specialOperationHint.enabled = false; //attachedSkillDisplay.gameObject.SetActive (false); attachedGemstoneDisplay.gameObject.SetActive(false); break; case ItemType.SkillScroll: //SkillScroll skillScroll = item as SkillScroll; attachedDescription.text = item.itemDescription; itemDescription.text = string.Empty; //attachedSkillDisplay.gameObject.SetActive (true); // Skill attachedSkill = GameManager.Instance.gameDataCenter.allSkills.Find (delegate(Skill obj) { //return obj.skillId == skillScroll.skillId; //}); SetUpOperationButtons(false, false, true); specialOperationContainer.gameObject.SetActive(false); specialOperationHint.enabled = false; //attachedSkillDisplay.SetUpAttachedSkillDisplay(attachedSkill); attachedGemstoneDisplay.gameObject.SetActive(false); break; case ItemType.PropertyGemstone: attachedDescription.text = item.itemDescription; itemDescription.text = string.Empty; SetUpOperationButtons(false, false, false); specialOperationContainer.gameObject.SetActive(false); specialOperationHint.enabled = false; //attachedSkillDisplay.gameObject.SetActive(false); attachedGemstoneDisplay.gameObject.SetActive(false); break; case ItemType.SpecialItem: attachedDescription.text = item.itemDescription; specialOperationHint.enabled = false; SpecialItem specialItem = item as SpecialItem; switch (specialItem.specialItemType) { case SpecialItemType.TieYaoShi: case SpecialItemType.TongYaoShi: case SpecialItemType.JinYaoShi: case SpecialItemType.WanNengYaoShi: case SpecialItemType.QiaoZhen: SetUpOperationButtons(false, false, false); specialOperationContainer.gameObject.SetActive(false); break; case SpecialItemType.DianJinFuShi: case SpecialItemType.ChongZhuShi: case SpecialItemType.TuiMoJuanZhou: SetUpOperationButtons(false, false, true); specialOperationContainer.gameObject.SetActive(true); soCell.SetUpSpeicalOperationCell(null); soCell.InitSpecialOperaiton(null); specialOperationHint.enabled = true; break; default: SetUpOperationButtons(false, false, true); specialOperationContainer.gameObject.SetActive(false); break; } //attachedSkillDisplay.gameObject.SetActive(false); attachedGemstoneDisplay.gameObject.SetActive(false); break; } generalItemDetailContainer.gameObject.SetActive(true); }
/// <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); } } }
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; } } }
/// <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); }