public void TryUpgradePet(int id, List <XItem> items) { if (items == null || items == null) { GTItemHelper.ShowTip("缺少食物"); return; } for (int i = 0; i < items.Count; i++) { if (MLPet.Instance.IsFood(items[i].Id) == false) { GTItemHelper.ShowTip("加入的食品列表有误"); return; } } DActor db = ReadCfgActor.GetDataById(id); XPet data = DataDBSPet.GetDataById(id); if (data != null) { int count = 0; foreach (var current in ReadCfgPetLevel.Dict) { if (current.Value.Quality == db.Quality) { count++; } } if (data.Level >= count) { GTItemHelper.ShowTip("宠物等级已满"); return; } } ReqUpgradePet req = new ReqUpgradePet(); req.ID = id; req.UseItems.AddRange(items); NetworkManager.Instance.Send <ReqUpgradePet>(MessageID.MSG_REQ_UPGRADE_PET, req); }
private void ShowView() { DActor db = ReadCfgActor.GetDataById(mCurPetID); XPet data = DataDBSPet.GetDataById(mCurPetID); data = data == null?GTDataFactory.CreatePet(mCurPetID) : data; DPetLevel levelDB = ReadCfgPetLevel.GetDataById(db.Quality * 1000 + data.Level); GTItemHelper.ShowProgressSlider(expSlider, data.CurExp, levelDB.Exp); GTItemHelper.ShowProgressText(expNum, data.CurExp, levelDB.Exp); for (int i = 0; i < mFoods.Count; i++) { FoodItem tab = mFoods[i]; if (i < mItems.Count) { XItem itemData = mItems[i]; GTItemHelper.ShowItemTexture(tab.itemTexture, itemData.Id); GTItemHelper.ShowItemQuality(tab.itemQuality, itemData.Id); } else { tab.itemQuality.gameObject.SetActive(false); tab.itemTexture.gameObject.SetActive(false); } } string str = GTTools.Format("{0} +{1}", db.Name, data.Level); GTItemHelper.ShowQualityText(title, str, db.Quality); ShowPropertyView(mCurPetID, data.Level); XCharacter role = RoleModule.Instance.GetCurPlayer(); btnBattle.SetActive(role.PetID != mCurPetID); btnUnload.SetActive(role.PetID == mCurPetID); }
private void OnAck_UpgradePet(MessageRecv obj) { System.IO.MemoryStream ms = new System.IO.MemoryStream(obj.Data); AckUpgradePet ack = Serializer.Deserialize <AckUpgradePet>(ms); int id = ack.ID; List <XItem> items = ack.UseItems; DActor db = ReadCfgActor.GetDataById(id); XPet data = DataDBSPet.GetDataById(id); if (data == null) { data = GTDataFactory.CreatePet(id); } int exp = PetModule.Instance.GetExpByItemList(items); DPetLevel levelDB = ReadCfgPetLevel.GetDataById(db.Quality * 1000 + data.Level); int addExp = exp + data.CurExp; while (addExp > levelDB.Exp) { addExp -= levelDB.Exp; data.Level++; levelDB = ReadCfgPetLevel.GetDataById(db.Quality * 1000 + data.Level); } data.CurExp = addExp; DataDBSPet.Update(id, data); for (int i = 0; i < items.Count; i++) { GTDataManager.Instance.UseItemById(items[i].Id, 1); } CharacterManager.Instance.SyncMainPlayerData(ESyncDataType.TYPE_BASEATTR); GTEventCenter.FireEvent(GTEventID.TYPE_UPGRADE_PET); GTEventCenter.FireEvent(GTEventID.TYPE_CHANGE_FIGHTVALUE); }