using Snxxz.UI; using System.Collections.Generic; using System.Text; using UnityEngine; using System; namespace Snxxz.UI { [XLua.LuaCallCSharp] public class ItemOperateUtility : Singleton { EquipModel equipModel { get { return ModelCenter.Instance.GetModel(); } } PackModel packModel { get { return ModelCenter.Instance.GetModel(); } } ItemTipsModel itemTipsModel { get { return ModelCenter.Instance.GetModel(); } } StrengthenModel strengthModel { get { return ModelCenter.Instance.GetModel(); } } BuffModel Buffmodel { get { return ModelCenter.Instance.GetModel(); } } FairyModel fairyModel { get { return ModelCenter.Instance.GetModel(); } } BoxGetItemModel BoxModel { get { return ModelCenter.Instance.GetModel(); } } DogzModel dogzModel { get { return ModelCenter.Instance.GetModel(); } } EquipGemModel equipGemModel { get { return ModelCenter.Instance.GetModel(); } } #region 装备 public string operateItemGuid { get; private set; } public void PutOnItem(string guid) { this.operateItemGuid = guid; var selectedItem = packModel.GetItemByGuid(guid); if (selectedItem == null) { return; } var itemId = selectedItem.itemId; if (!ItemLogicUtility.Instance.IsJobCompatibleItem(selectedItem.itemId)) { SysNotifyMgr.Instance.ShowTip("GeRen_lhs_31379"); return; } var putOnLimits = selectedItem.GetUseData((int)ItemUseDataKey.cancelUseLimit); if (putOnLimits != null && putOnLimits[0] == 1) { PutOnEquip(selectedItem.equipPlace, selectedItem.guid); return; } var wearable = IsWearable(itemId); if (wearable) { PutOnEquip(selectedItem.equipPlace, selectedItem.guid); } } bool IsWearable(int itemId) { var config = ItemConfig.Get(itemId); var uselimits = config.UseCondiType; var wearable = true; if (!uselimits.IsNullOrEmpty()) { for (int i = 0; i < uselimits.Length; i++) { switch (uselimits[i]) { case 1: wearable = CheckPutOnRealm(itemId); break; } } } return wearable; } private StringBuilder curRealmImgStr = new StringBuilder(); private StringBuilder needRealmImgStr = new StringBuilder(); private bool CheckPutOnRealm(int itemId) { var config = ItemConfig.Get(itemId); curRealmImgStr.Length = 0; needRealmImgStr.Length = 0; var realmLevel = config.RealmLimit; var needRealmConfig = RealmConfig.Get(realmLevel); var curRealmConfig = RealmConfig.Get(PlayerDatas.Instance.baseData.realmLevel); if (PlayerDatas.Instance.baseData.realmLevel < realmLevel) { needRealmImgStr.AppendFormat("", needRealmConfig.Img); if (curRealmConfig != null && PlayerDatas.Instance.baseData.realmLevel > 0) { curRealmImgStr.AppendFormat("", curRealmConfig.Img); } else { curRealmImgStr.AppendFormat("", "NoRealm"); } switch (config.EquipPlace) { case 0: ConfirmCancel.ShowRealmPopConfirm(Language.Get("Mail101"), Language.Get("RealmNeeds", needRealmImgStr.ToString(), curRealmImgStr.ToString()), Language.Get("PopConfirmWin_Promote"), () => { WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.RealmFunc1); }); break; default: ConfirmCancel.ShowRealmPopConfirm(Language.Get("Mail101"), Language.Get("KnapS142", needRealmImgStr.ToString(), curRealmImgStr.ToString()), Language.Get("PopConfirmWin_Promote"), () => { WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.RealmFunc1); }); break; } return false; } return true; } void PutOnEquip(int equipPlace, string guid) { var clientPlaceInfo = EquipSet.ServerPlaceToClientPlace(equipPlace); var oldItem = packModel.GetItemByGuid(equipModel.GetEquip(clientPlaceInfo)); if (oldItem != null) { EquipAttrShift(equipPlace, oldItem); } PutOnNormalEquip(equipPlace, guid); SoundPlayer.Instance.PlayUIAudio(24); } private void PutOnNormalEquip(int equipPlace, string guid) { var item = packModel.GetItemByGuid(guid); var putOnEquip = new C0703_tagCEquipItem(); putOnEquip.RoleEquipType = (byte)equipPlace; putOnEquip.ItemIndex = (byte)item.gridIndex; GameNetSystem.Instance.SendInfo(putOnEquip); } /// /// 替换装备时属性转移提示 /// private void EquipAttrShift(int equipPlace, ItemModel item) { var packType = GeneralDefine.GetPackTypeByItemType(item.config.Type); var putOnModel = packModel.GetItemByIndex(PackType.Equip, equipPlace); if (putOnModel == null) { return; } //var equipStrengthDic = strengthModel._EqInfo; //var isPrompt = strengthModel.TheRatingPrompt(item.itemId); //if (isPrompt && !PlayerPrefs.HasKey(PackModel.StrengthAttrShift_RecordKey)) //{ // LocalSave.SetBool(PackModel.StrengthAttrShift_RecordKey, true); // ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("SwitchEquip_Strengthen")); //} //if (equipStrengthDic.ContainsKey(equipPlace)) //{ // if (equipStrengthDic[equipPlace].EquipPartStarLV >= 1) // { // SysNotifyMgr.Instance.ShowTip("SwitchEquip_Strengthen2"); // } //} int[] stones = null; equipGemModel.TryGetEquipGems(equipPlace, out stones); if (stones != null) { int i = 0; for (i = 0; i < stones.Length; i++) { if (stones[i] != 0 && equipGemModel.IsEquipGemHoleOpen(equipPlace, 0)) { SysNotifyMgr.Instance.ShowTip("SwitchEquip_Gem"); break; } } } } public void PutOffEquip(string guid) { var item = packModel.GetItemByGuid(guid); if (item == null) { return; } var equipPlace = EquipModel.GetItemServerEquipPlace(item.itemId); var singlePack = packModel.GetSinglePack(PackType.Item); var remainGrid = packModel.GetEmptyGridCount(PackType.Item); if (remainGrid < 1) { SysNotifyMgr.Instance.ShowTip("GeRen_chenxin_998371"); } else { if (singlePack != null) { int gridIndex = singlePack.GetFirstEmptyGridIndex(); SendPutOffNormalEquip(equipPlace, gridIndex); SoundPlayer.Instance.PlayUIAudio(25); } } } private void SendPutOffNormalEquip(int equipPlace, int itemIndex) { var putOffEquip = new C0704_tagCUnEquipItem(); putOffEquip.EquipIndex = (byte)equipPlace; putOffEquip.PackIndex = (byte)itemIndex; GameNetSystem.Instance.SendInfo(putOffEquip); } #endregion #region 仓库 public void RequestWarehouseData() { var openWarehouse = new CA204_tagCMOpenLongWarehouse(); GameNetSystem.Instance.SendInfo(openWarehouse); } public void PutInWareHouse(string guid) { var itemModel = packModel.GetItemByGuid(guid); if (itemModel == null) { return; } var putInWarehouse = new C0C01_tagCPutItemInWarehouse(); putInWarehouse.ItemIndex = (ushort)itemModel.gridIndex; putInWarehouse.WarehouseIndex = 0; putInWarehouse.Count = (ushort)itemModel.count; GameNetSystem.Instance.SendInfo(putInWarehouse); } public void TakeOutFromWarehouse(string guid) { var itemModel = packModel.GetItemByGuid(guid); if (itemModel == null) { return; } var putOutWarehouse = new C0C02_tagCGetItemInWarehouse(); putOutWarehouse.WarehouseIndex = (ushort)itemModel.gridIndex; putOutWarehouse.ItemIndex = 0; putOutWarehouse.Count = (ushort)itemModel.count; GameNetSystem.Instance.SendInfo(putOutWarehouse); } #endregion #region 使用物品 public ItemModel useItemModel { get; set; } public void GotoUseItem(string guid) { useItemModel = packModel.GetItemByGuid(guid); if (useItemModel == null) { return; } switch (useItemModel.config.Type) { case (int)ItemType.Box: BoxModel.SetModel(useItemModel.guid, useItemModel.itemId); return; case 83: var fashionModel = ModelCenter.Instance.GetModel(); fashionModel.jumpFashionDress = useItemModel.config.EffectValueA1; break; } switch (useItemModel.config.ID) { case 951: var singlePack = packModel.GetSinglePack(PackType.Item); int startLockIndex = singlePack.unlockedGridCount - GeneralDefine.initBagGridCount; int chooseGridCnt = singlePack.unlockedGridCount + GetExtendGridCnt(startLockIndex); packModel.UnLockPackGrid(chooseGridCnt, PackType.Item); return; case 1506: var crossOneVsOneModel = ModelCenter.Instance.GetModel(); if (!crossOneVsOneModel.TryGetBuyMatchTimes("CrossMatching26")) { return; } break; } if (packModel.CheckIsDrugById(useItemModel.itemId)) { if (CheckItemUselimit(useItemModel.itemId)) { WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.MakeDrug); } return; } int dungeonID = packModel.GetDungeonIDByDrugID(useItemModel.itemId); if (dungeonID != 0) { MapConfig tagMapModel = MapConfig.Get(PlayerDatas.Instance.baseData.MapID); if (tagMapModel.MapFBType == 0) { DungeonOpenTimeConfig timeConfig = DungeonOpenTimeConfig.Get(dungeonID); ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("DrugUsePrompt", useItemModel.config.ItemName, timeConfig.FBName), (bool isOk) => { if (isOk) { CheckUseCondition(useItemModel); } }); return; } } for (int i = 0; i < itemTipsModel.jumpAndUseTypes.Length; i++) { if (itemTipsModel.jumpAndUseTypes[i] == useItemModel.config.Type) { if (CheckUseCondition(useItemModel)) { var error = 0; if (CanUseItem(useItemModel.guid, 1, out error)) { if (useItemModel.config.Jump != 0) { WindowJumpMgr.Instance.WindowJumpTo((JumpUIType)useItemModel.config.Jump); } } } return; } } if (useItemModel.config.Jump != 0) { WindowJumpMgr.Instance.WindowJumpTo((JumpUIType)useItemModel.config.Jump); } else { CheckUseCondition(useItemModel); } } /// /// 获取当前道具可以开启的格子数 /// /// /// /// /// private int GetExtendGridCnt(int startLockIndex, int needTool = 0, int extendCnt = 0) { FuncConfigConfig _tagFuncModel = FuncConfigConfig.Get("OpenBagItem"); int haveCount = packModel.GetItemCountByID(PackType.Item, useItemModel.itemId); startLockIndex += 1; Equation.Instance.Clear(); Equation.Instance.AddKeyValue("index", startLockIndex); needTool += Equation.Instance.Eval(_tagFuncModel.Numerical2); if (haveCount >= needTool) { extendCnt += 1; return GetExtendGridCnt(startLockIndex, needTool, extendCnt); } else { if (extendCnt <= 0) { extendCnt = 1; } int remianLock = GeneralDefine.maxBagGridCount - packModel.GetSinglePack(PackType.Item).unlockedGridCount; if (extendCnt > remianLock) { extendCnt = remianLock; } return extendCnt; } } public bool CheckItemUselimit(int itemId) { var config = ItemConfig.Get(itemId); int[] uselimits = config.UseCondiType; if (uselimits == null) return true; for (int i = 0; i < uselimits.Length; i++) { switch (uselimits[i]) { case 0: int playerLv = PlayerDatas.Instance.baseData.LV; if (playerLv < config.UseLV) { ServerTipDetails.DisplayNormalTip(Language.Get("MakeUseItem101", useItemModel.config.UseLV)); return false; } break; case 1: return CheckPutOnRealm(itemId); } } return true; } bool CheckUseCondition(ItemModel itemModel) { if (!CheckItemUselimit(itemModel.itemId)) { return false; } if (itemModel.config.Type == 59) { //packModel.GotoWashAttributePoint(itemModel.guid); //WindowCenter.Instance.Open(); //return true; } if (itemModel.config.Effect1 == 209 && !PlayerDatas.Instance.fairyData.HasFairy) { SysNotifyMgr.Instance.ShowTip("jiazu_andyshao_0"); return false; } if (itemModel.itemId == 952) { int maxUseCnt = GetOfflineMaxNum(itemModel); if (maxUseCnt <= 1) { if (!CheckIsMaxOfflineTime(maxUseCnt, itemModel)) { UseItem(itemModel.guid); } else { return false; } } else { BatchUseModel.Instance.SetOfflineUseModel(itemModel.guid); WindowCenter.Instance.Open(); } return true; } if (itemModel.itemId == fairyModel.changeFairyNameItem) { if (PlayerDatas.Instance.fairyData.HasFairy) { WindowCenter.Instance.Open(); return true; } else { SysNotifyMgr.Instance.ShowTip("jiazu_andyshao_0"); return false; } } if (dogzModel.AddAssistItem == itemModel.itemId) { dogzModel.MakeUseAddAssistNum(); return true; } ulong maxValue = 0; packModel.IsReachUseLimit(itemModel.guid, out maxValue); if (itemModel.config.BatchUse != 0 && maxValue > 1) { BatchUseModel.Instance.SetBatchModel(itemModel.guid); WindowCenter.Instance.Open(); } else { if (Buffmodel.BuffCover(itemModel.itemId)) { ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("FairyLand_Func22"), (bool isOk) => { if (isOk) { UseItem(itemModel.guid); } } ); } else { switch (itemModel.itemId) { case RoleRenameWin.renameToolId: WindowCenter.Instance.Open(); break; default: ItemCDCool cool = KnapsackTimeCDMgr.Instance.GetItemCoolById(itemModel.guid); if (cool == null || cool.GetRemainTime() <= 0) { UseItem(itemModel.guid); } else { return false; } break; } } } return true; } public int GetOfflineMaxNum(ItemModel itemModel) { int remainOffline = HangUpSetModel.Instance.maxOfflinePluginTime - HangUpSetModel.Instance.offlinePluginTime; int maxUseCnt = 0; if (remainOffline > 0) { int extraCnt = remainOffline % itemModel.config.EffectValueA1 > 0 ? 1 : 0; maxUseCnt = remainOffline / itemModel.config.EffectValueA1 + extraCnt; if (maxUseCnt > itemModel.count) { return itemModel.count; } } return maxUseCnt; } public bool CheckIsMaxOfflineTime(int useNum, ItemModel itemModel) { int remainOffline = HangUpSetModel.Instance.maxOfflinePluginTime - HangUpSetModel.Instance.offlinePluginTime; if (remainOffline <= 0) { SysNotifyMgr.Instance.ShowTip("OfflinePluginTime"); return true; } else { int willTime = HangUpSetModel.Instance.offlinePluginTime + itemModel.config.EffectValueA1 * useNum; if (willTime > HangUpSetModel.Instance.maxOfflinePluginTime) { ConfirmCancel.ShowPopConfirm(Language.Get("OfflinePluginTime102"), Language.Get("OfflinePluginTime101"), (bool isOk) => { if (isOk) { UseItem(itemModel.guid, useNum); } }); return true; } } return false; } public void UseItem(string guid, int useCnt = 1, int extra = 0) { var item = packModel.GetItemByGuid(guid); if (item == null) { return; } var error = 0; if (CanUseItem(guid, useCnt, out error)) { UseItemMainServer(guid, useCnt, extra); } else { switch (error) { case 1: SysNotifyMgr.Instance.ShowTip("EverydayUseLimit"); break; case 2: SysNotifyMgr.Instance.ShowTip("UseCntLimit"); break; default: break; } } } public bool CanUseItem(string guid, int useCnt, out int error) { var item = packModel.GetItemByGuid(guid); if (item == null) { error = 999; return false; } var usedCountToday = packModel.GetItemUsedTimesToday(item.itemId); if (item.config.MaxSkillCnt > 0 && item.config.MaxSkillCnt <= usedCountToday) { error = 1; return false; } var usedCountTotal = packModel.GetItemTotalUsedTimes(item.itemId); var fruitConfig = AttrFruitConfig.Get(item.itemId); if (fruitConfig != null && (usedCountTotal >= fruitConfig.MaxUseCnt || useCnt > fruitConfig.MaxUseCnt)) { error = 1; return false; } error = 0; return true; } void UseItemMainServer(string guid, int useCnt, int extra) { var itemModel = packModel.GetItemByGuid(guid); if (itemModel == null) { return; } var useItem = new CA323_tagCMUseItems(); useItem.ItemIndex = (byte)itemModel.gridIndex; useItem.UseCnt = (ushort)useCnt; useItem.ExData = (uint)extra; GameNetSystem.Instance.SendInfo(useItem); //使用物品 } public void UseItemCrossServer(string guid) { var itemModel = packModel.GetItemByGuid(guid); if (itemModel == null) { return; } var useItem = new CC107_tagCMCrossUseItem(); useItem.ItemID = (uint)itemModel.itemId; GameNetSystem.Instance.SendToCrossServer(useItem); } public void ProcessOverdueItem(string guid) { var item = packModel.GetItemByGuid(guid); if (item == null) { return; } var info = new CA308_tagCMItemTimeout(); info.PackType = (byte)item.packType; info.ItemIndex = (byte)item.gridIndex; GameNetSystem.Instance.SendInfo(info); } #endregion #region 拆分 public void OnClickSplitBtn(string guid) { WindowCenter.Instance.Open(); } public void SplitItem(string guid, int splitCount) { if (string.IsNullOrEmpty(guid)) { return; } var itemModel = packModel.GetItemByGuid(guid); if (itemModel == null) { return; } var packType = GeneralDefine.GetPackTypeByItemType(itemModel.config.Type); var singlePack = packModel.GetSinglePack(packType); if (packModel.GetEmptyGridCount(packType) < 1) { SysNotifyMgr.Instance.ShowTip("GeRen_chenxin_676165", packType); } else { var sendInfo = new C0708_tagCDragItem(); sendInfo.SrcIndex = (ushort)itemModel.gridIndex; sendInfo.DestIndex = (ushort)singlePack.GetFirstEmptyGridIndex(); sendInfo.ItemCount = (ushort)splitCount; GameNetSystem.Instance.SendInfo(sendInfo); //拆分物体 } } #endregion #region 上架 public void PutAway(string guid) { var itemModel = packModel.GetItemByGuid(guid); if (itemModel == null || itemModel.packType != PackType.Item) { return; } var auctionHelpModel = ModelCenter.Instance.GetModel(); auctionHelpModel.ItemModel = itemModel; WindowCenter.Instance.Open(); } #endregion #region 养成 public void GotoInlayItem(string guid) { var item = packModel.GetItemByGuid(guid); if (item == null) { return; } var equipGemModel = ModelCenter.Instance.GetModel(); if (ItemLogicUtility.Instance.IsEquip(item.itemId)) { equipGemModel.jumpEquipPosition = new Int2(item.config.LV, item.config.EquipPlace); } else { equipGemModel.jumpEquipPosition = equipGemModel.TryGotoUseGem(item.itemId); } WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.StrengthFunc3); } public void GotoStarUpgrade(string guid) { var item = packModel.GetItemByGuid(guid); if (item == null) { return; } var equipStarModel = ModelCenter.Instance.GetModel(); equipStarModel.SelectLevel(item.config.LV); equipStarModel.SelectPlace(new Int2(item.config.LV, item.config.EquipPlace)); WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.StrengthFunc2); } public void GotoStrengthen(string guid) { var item = packModel.GetItemByGuid(guid); if (item == null) { return; } var equipStrengthModel = ModelCenter.Instance.GetModel(); equipStrengthModel.jumpEquipPosition = new Int2(item.config.LV, item.config.EquipPlace); WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.StrengthFunc1); } public void GotoTrain(string guid) { var item = packModel.GetItemByGuid(guid); if (item == null) { return; } var trainModel = ModelCenter.Instance.GetModel(); trainModel.SelectLevel(item.config.LV); trainModel.SelectPlace(new Int2(item.config.LV, item.config.EquipPlace)); WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.StrengthFunc4); } #endregion #region 合成 public void GotoComposeItem(int jumpId) { WindowJumpMgr.Instance.WindowJumpTo((JumpUIType)jumpId); } #endregion #region 出售 public void SellItem(ItemAttrData attrData) { if (attrData.itemConfig.EquipPlace > 0 && attrData.itemConfig.EquipPlace <= (int)RoleEquipType.Guard1) { bool isOverdue = ItemLogicUtility.Instance.IsOverdue(attrData.guid); bool isLimit = ItemLogicUtility.Instance.IsJobCompatibleItem(attrData.itemId) ? true : false; var putModel = packModel.GetItemByIndex(PackType.Equip, attrData.itemConfig.EquipPlace); if (!isLimit || isOverdue || (putModel != null && attrData.score < putModel.score)) { if (attrData.itemConfig.SellTip == 0) { SendSellQuest(attrData.packType, attrData.index); } else if (attrData.itemConfig.SellTip == 1) { SetSellItemPrompt(attrData, "KnapS128", attrData.itemConfig.ItemName); } } else { if (putModel == null) { SetSellItemPrompt(attrData, "KnapS147", UIHelper.GetEquipPlaceName(attrData.itemConfig.EquipPlace)); } else { if (attrData.itemConfig.SellTip == 0) { SetSellItemPrompt(attrData, "KnapS146", attrData.itemConfig.ItemName); } else if (attrData.itemConfig.SellTip == 1) { SetSellItemPrompt(attrData, "KnapS128", attrData.itemConfig.ItemName); } } } } else { if (attrData.itemConfig.SellTip == 0) { SendSellQuest(attrData.packType, attrData.index); } else if (attrData.itemConfig.SellTip == 1) { SetSellItemPrompt(attrData, "KnapS128", attrData.itemConfig.ItemName); } } } private void SetSellItemPrompt(ItemAttrData attrData, string key, string parms) { ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get(key, parms), (bool isOK) => { if (isOK) { SendSellQuest(attrData.packType, attrData.index); } }); } public void SendSellQuest(PackType type, int index) { var sellItem = new C0806_tagCPlayerSellItem(); sellItem.PackType = (byte)type; sellItem.ItemIndex = (byte)index; GameNetSystem.Instance.SendInfo(sellItem); } #endregion #region 拆解 public void DismantleItem(ItemAttrData attrData) { var dismantleReturnlist = attrData.GetUseDataModel((int)ItemUseDataKey.itemDecompound); int needGridCnt = 0; int fixedMatcnt = 0; int unfixedMatId = 0; for (int i = 0; i < dismantleReturnlist.Count; i++) { if (i == 0) { if (dismantleReturnlist[i] != 0) { needGridCnt += 1; unfixedMatId = dismantleReturnlist[i]; } } else { if ((i - 1) % 3 == 0) { if (dismantleReturnlist[i] != 0) { needGridCnt += 1; fixedMatcnt += dismantleReturnlist[i + 1]; } } } } int offsetGrid = needGridCnt - packModel.GetEmptyGridCount(PackType.Item); if (offsetGrid > 0) { SysNotifyMgr.Instance.ShowTip("BagFull102", attrData.itemConfig.ItemName, offsetGrid); return; } var itemConfig = ItemConfig.Get(unfixedMatId); if (itemConfig != null) { ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("PinkChaiRemind2", fixedMatcnt, itemConfig.LV), (bool ok) => { if (ok) { var decompound = new CA313_tagCMItemDecompound(); decompound.Index = (byte)attrData.index; GameNetSystem.Instance.SendInfo(decompound); } }); } else { var decompound = new CA313_tagCMItemDecompound(); decompound.Index = (byte)attrData.index; GameNetSystem.Instance.SendInfo(decompound); } } #endregion #region 续费 public void RenewalItem(string guid) { GuardOverdueWin.guid = guid; WindowCenter.Instance.Open(); } #endregion } }