using Snxxz.UI;
|
using System.Collections.Generic;
|
using System.Text;
|
using UnityEngine;
|
using System;
|
|
namespace Snxxz.UI
|
{
|
[XLua.LuaCallCSharp]
|
public class ItemOperateUtility : Singleton<ItemOperateUtility>
|
{
|
EquipModel equipModel { get { return ModelCenter.Instance.GetModel<EquipModel>(); } }
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
ItemTipsModel itemTipsModel { get { return ModelCenter.Instance.GetModel<ItemTipsModel>(); } }
|
BuffModel Buffmodel { get { return ModelCenter.Instance.GetModel<BuffModel>(); } }
|
FairyModel fairyModel { get { return ModelCenter.Instance.GetModel<FairyModel>(); } }
|
BoxGetItemModel BoxModel { get { return ModelCenter.Instance.GetModel<BoxGetItemModel>(); } }
|
DogzModel dogzModel { get { return ModelCenter.Instance.GetModel<DogzModel>(); } }
|
EquipGemModel equipGemModel { get { return ModelCenter.Instance.GetModel<EquipGemModel>(); } }
|
AlchemyModel alchemyModel { get { return ModelCenter.Instance.GetModel<AlchemyModel>(); } }
|
EquipStrengthModel equipStrengthModel { get { return ModelCenter.Instance.GetModel<EquipStrengthModel>(); } }
|
EquipStarModel equipStarModel { get { return ModelCenter.Instance.GetModel<EquipStarModel>(); } }
|
EquipTrainModel equipTrainModel { get { return ModelCenter.Instance.GetModel<EquipTrainModel>(); } }
|
|
#region 装备
|
|
|
public void PutOnItem(string guid)
|
{
|
var item = packModel.GetItemByGuid(guid);
|
if (item == null)
|
{
|
return;
|
}
|
|
var itemId = item.itemId;
|
if (!ItemLogicUtility.Instance.IsJobCompatibleItem(item.itemId))
|
{
|
SysNotifyMgr.Instance.ShowTip("GeRen_lhs_31379");
|
return;
|
}
|
|
var equipServerIndex = EquipSet.ClientPlaceToServerPlace(new Int2(item.config.LV, item.config.EquipPlace));
|
var putOnLimits = item.GetUseData((int)ItemUseDataKey.cancelUseLimit);
|
if (putOnLimits != null && putOnLimits[0] == 1)
|
{
|
PutOnEquip(equipServerIndex, item.guid);
|
return;
|
}
|
|
var wearable = IsWearable(itemId);
|
if (wearable)
|
{
|
PutOnEquip(equipServerIndex, item.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("<Img img={0}/>", needRealmConfig.Img);
|
if (curRealmConfig != null && PlayerDatas.Instance.baseData.realmLevel > 0)
|
{
|
curRealmImgStr.AppendFormat("<Img img={0}/>", curRealmConfig.Img);
|
}
|
else
|
{
|
curRealmImgStr.AppendFormat("<Img img={0}/>", "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));
|
var newItem = packModel.GetItemByGuid(guid);
|
|
if (!ItemLogicUtility.Instance.IsRealmEquip(newItem.itemId))
|
{
|
PutOnNormalEquip(equipPlace, guid);
|
SoundPlayer.Instance.PlayUIAudio(24);
|
return;
|
}
|
|
m_RecordSwitchEquipItemId = oldItem == null ? 0 : oldItem.itemId;
|
|
EquipSuitShift(oldItem, newItem, (bool _suitOk) =>
|
{
|
if (_suitOk)
|
{
|
EquipDevelopShift(oldItem, newItem, (bool _developOk) =>
|
{
|
if (_developOk)
|
{
|
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);
|
}
|
|
/// <summary>
|
/// 替换装备时属性转移提示
|
/// </summary>
|
private void EquipAttrShift(int equipPlace, ItemModel item)
|
{
|
var putOnModel = packModel.GetItemByIndex(PackType.Equip, equipPlace);
|
if (putOnModel == null)
|
{
|
return;
|
}
|
|
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;
|
}
|
}
|
}
|
|
}
|
|
private void EquipSuitShift(ItemModel oldItem, ItemModel newItem, Action<bool> callback)
|
{
|
if (oldItem != null && oldItem.config.SuiteiD > 0 &&
|
newItem != null && newItem.config.SuiteiD == 0)
|
{
|
var suitName = EquipSuitConfig.GetEquipSuitName(oldItem.config.SuiteiD);
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
|
Language.Get("EquipShiftRemind_1", suitName),
|
(bool isOk) =>
|
{
|
if (callback != null)
|
{
|
callback(isOk);
|
}
|
});
|
return;
|
}
|
if (callback != null)
|
{
|
callback(true);
|
}
|
}
|
|
private void EquipDevelopShift(ItemModel oldItem, ItemModel newItem, Action<bool> callback)
|
{
|
if (oldItem != null && newItem != null &&
|
oldItem.config.ItemColor > newItem.config.ItemColor)
|
{
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
|
Language.Get("EquipShiftRemind_2"),
|
(bool isOk) =>
|
{
|
if (callback != null)
|
{
|
callback(isOk);
|
}
|
});
|
return;
|
}
|
if (callback != null)
|
{
|
callback(true);
|
}
|
}
|
|
int m_RecordSwitchEquipItemId = 0;
|
public void ShowPutOnNewEquipRemind(int newItemId)
|
{
|
if (DTC0403_tagPlayerLoginLoadOK.finishedLogin)
|
{
|
if (m_RecordSwitchEquipItemId != 0)
|
{
|
var oldConfig = ItemConfig.Get(m_RecordSwitchEquipItemId);
|
var newConfig = ItemConfig.Get(newItemId);
|
|
var oldNameLabel = StringUtility.Contact(UIHelper.GetEquipSuitName(oldConfig.ID, true),
|
UIHelper.AppendColor(oldConfig.ItemColor, oldConfig.ItemName, true));
|
var newNameLabel = StringUtility.Contact(UIHelper.GetEquipSuitName(newConfig.ID, true),
|
UIHelper.AppendColor(newConfig.ItemColor, newConfig.ItemName, true));
|
|
var shiftStar = equipStarModel.GetStarLevel(new Int2(oldConfig.LV, oldConfig.EquipPlace)) > 0;
|
|
var shiftStrength = false;
|
if (FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Strength))
|
{
|
shiftStrength = equipStrengthModel.GetStrengthLevel(oldConfig.LV, oldConfig.EquipPlace) > 0;
|
}
|
|
var shiftGem = false;
|
int[] equipGems;
|
if (equipGemModel.TryGetEquipGems(oldConfig.LV, oldConfig.EquipPlace, out equipGems))
|
{
|
foreach (var id in equipGems)
|
{
|
if (id > 0)
|
{
|
shiftGem = true;
|
break;
|
}
|
}
|
}
|
|
var shiftTrain = equipTrainModel.GetTrainLevel(new Int2(oldConfig.LV, oldConfig.EquipPlace)) > 0;
|
|
if (shiftStar || shiftStrength || shiftGem || shiftTrain)
|
{
|
var shiftSb = new StringBuilder();
|
if (shiftStar)
|
{
|
shiftSb.Append(Language.Get("EquipShiftRemind_Star"));
|
}
|
if (shiftStrength)
|
{
|
if (shiftSb.Length > 0)
|
{
|
shiftSb.Append("、");
|
}
|
shiftSb.Append(Language.Get("EquipShiftRemind_Strength"));
|
}
|
if (shiftGem)
|
{
|
if (shiftSb.Length > 0)
|
{
|
shiftSb.Append("、");
|
}
|
shiftSb.Append(Language.Get("EquipShiftRemind_Gem"));
|
}
|
if (shiftTrain)
|
{
|
if (shiftSb.Length > 0)
|
{
|
shiftSb.Append("、");
|
}
|
shiftSb.Append(Language.Get("EquipShiftRemind_Train"));
|
}
|
|
|
if (newConfig.ItemColor >= oldConfig.ItemColor)
|
{
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
|
Language.Get("EquipShiftRemind_3", oldNameLabel, newNameLabel, shiftSb.ToString()));
|
}
|
else
|
{
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
|
Language.Get("EquipShiftRemind_4", oldNameLabel, newNameLabel, shiftSb.ToString()));
|
}
|
}
|
}
|
}
|
m_RecordSwitchEquipItemId = 0;
|
}
|
|
public void GotoPutOnEquip(string guid)
|
{
|
WindowCenter.Instance.Close<KnapSackWin>();
|
WindowCenter.Instance.Close<EquipTipWin>();
|
WindowCenter.Instance.Open<RealmEquipWin>();
|
|
Clock.AlarmAfter(0.5f, () => { ItemTipUtility.Show(guid); });
|
}
|
|
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;
|
}
|
|
if (ItemLogicUtility.Instance.IsSpiritWeapon(useItemModel.itemId))
|
{
|
var serverIndex = EquipSet.ClientPlaceToServerPlace(new Int2(useItemModel.config.LV, useItemModel.config.EquipPlace));
|
PutOnEquip(serverIndex, guid);
|
return;
|
}
|
|
switch (useItemModel.config.Type)
|
{
|
case (int)ItemType.Box:
|
BoxModel.SetModel(useItemModel.guid, useItemModel.itemId);
|
return;
|
case 83:
|
var fashionModel = ModelCenter.Instance.GetModel<FashionDressModel>();
|
fashionModel.jumpFashionDress = useItemModel.config.EffectValueA1;
|
break;
|
case 55:
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.BlastFurnace))
|
{
|
FuncOpen.Instance.ProcessorFuncErrorTip((int)FuncOpenEnum.BlastFurnace);
|
return;
|
}
|
var alchemyId = 0;
|
if (alchemyModel.TryGetAlchemyByStudyMaterial(useItemModel.itemId, out alchemyId))
|
{
|
var alchemyConfig = AlchemyConfig.Get(alchemyId);
|
int alchemingId;
|
if (alchemyModel.IsStoveAlcheming((AlchemyType)alchemyConfig.AlchemType, out alchemingId))
|
{
|
SysNotifyMgr.Instance.ShowTip("AlchemyStudyJumpError_1");
|
return;
|
}
|
if (alchemyModel.IsGraspRecipe(alchemyId))
|
{
|
SysNotifyMgr.Instance.ShowTip("AlchemyStudyJumpError_2");
|
return;
|
}
|
alchemyModel.jumpAlchemy = alchemyId;
|
WindowJumpMgr.Instance.WindowJumpTo((AlchemyType)alchemyConfig.AlchemType == AlchemyType.Normal ?
|
JumpUIType.AlchemyNormal : JumpUIType.AlchemyFairy);
|
}
|
return;
|
}
|
|
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<CrossServerOneVsOneModel>();
|
if (!crossOneVsOneModel.TryGetBuyMatchTimes("CrossMatching26"))
|
{
|
return;
|
}
|
break;
|
}
|
if (packModel.CheckIsDrugById(useItemModel.itemId))
|
{
|
if (CheckItemUselimit(useItemModel.itemId))
|
{
|
var fruitConfig = AttrFruitConfig.Get(useItemModel.itemId);
|
if (fruitConfig != null)
|
{
|
if (fruitConfig.drugType == (int)AlchemyType.Normal)
|
{
|
WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.UseNormalDrug);
|
}
|
else if (fruitConfig.drugType == (int)AlchemyType.Fairy)
|
{
|
WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.UseFairyDrug);
|
}
|
}
|
}
|
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);
|
}
|
}
|
|
/// <summary>
|
/// 获取当前道具可以开启的格子数
|
/// </summary>
|
/// <param name="startLockIndex"></param>
|
/// <param name="needTool"></param>
|
/// <param name="extendCnt"></param>
|
/// <returns></returns>
|
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<int>(_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;
|
}
|
|
public bool CheckUseCondition(ItemModel itemModel)
|
{
|
if (!CheckItemUselimit(itemModel.itemId))
|
{
|
return false;
|
}
|
|
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<OfflineHangUpUseWin>();
|
}
|
return true;
|
}
|
|
if (itemModel.itemId == fairyModel.changeFairyNameItem)
|
{
|
if (PlayerDatas.Instance.fairyData.HasFairy)
|
{
|
WindowCenter.Instance.Open<FamilyChangeNameWin>();
|
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<BatchWin>();
|
}
|
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<RoleRenameWin>();
|
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)
|
{
|
var limitTimes = 0;
|
if (fruitConfig.FuncID == 2)
|
{
|
limitTimes = alchemyModel.GetAlchemyDrugUseLimit(item.itemId);
|
}
|
else
|
{
|
limitTimes = fruitConfig.basicUseLimit;
|
}
|
if (usedCountTotal >= limitTimes || useCnt > limitTimes)
|
{
|
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
|
|
|
public string splitGuid;
|
public int splitItemTotalCount;
|
#region 拆分
|
public void OnClickSplitBtn(string guid)
|
{
|
splitGuid = guid;
|
var item = packModel.GetItemByGuid(guid);
|
if (item == null)
|
{
|
return;
|
}
|
|
splitItemTotalCount = item.count;
|
WindowCenter.Instance.Open<SplitWin>();
|
}
|
|
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>();
|
auctionHelpModel.ItemModel = itemModel;
|
WindowCenter.Instance.Open<AuctionShelfWin>();
|
}
|
#endregion
|
|
#region 养成
|
public void GotoInlayItem(string guid)
|
{
|
var item = packModel.GetItemByGuid(guid);
|
if (item == null)
|
{
|
return;
|
}
|
var equipGemModel = ModelCenter.Instance.GetModel<EquipGemModel>();
|
if (ItemLogicUtility.Instance.IsRealmEquip(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>();
|
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>();
|
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<EquipTrainModel>();
|
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(string guid)
|
{
|
var item = packModel.GetItemByGuid(guid);
|
if (item == null)
|
{
|
return;
|
}
|
|
if (ItemLogicUtility.Instance.IsRealmEquip(item.itemId) || ItemLogicUtility.Instance.IsSpiritWeapon(item.itemId))
|
{
|
var isOverdue = ItemLogicUtility.Instance.IsOverdue(guid);
|
var isLimit = ItemLogicUtility.Instance.IsJobCompatibleItem(item.itemId) ? true : false;
|
var equipedItem = packModel.GetItemByIndex(PackType.Equip, item.gridIndex);
|
|
if (!isLimit || isOverdue || (equipedItem != null && item.score < equipedItem.score))
|
{
|
if (item.config.SellTip == 0)
|
{
|
SendSellQuest(guid);
|
}
|
else if (item.config.SellTip == 1)
|
{
|
SetSellItemPrompt(guid, "KnapS128", item.config.ItemName);
|
}
|
}
|
else
|
{
|
if (equipedItem == null)
|
{
|
SetSellItemPrompt(guid, "KnapS147", UIHelper.GetEquipPlaceName(item.config.EquipPlace));
|
}
|
else
|
{
|
if (item.config.SellTip == 0)
|
{
|
SetSellItemPrompt(guid, "KnapS146", item.config.ItemName);
|
}
|
else if (item.config.SellTip == 1)
|
{
|
SetSellItemPrompt(guid, "KnapS128", item.config.ItemName);
|
}
|
}
|
}
|
}
|
else
|
{
|
if (item.config.SellTip == 0)
|
{
|
SendSellQuest(guid);
|
}
|
else if (item.config.SellTip == 1)
|
{
|
SetSellItemPrompt(guid, "KnapS128", item.config.ItemName);
|
}
|
}
|
|
}
|
|
private void SetSellItemPrompt(string guid, string key, string parms)
|
{
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get(key, parms), (bool isOK) =>
|
{
|
if (isOK)
|
{
|
SendSellQuest(guid);
|
}
|
});
|
}
|
|
private void SendSellQuest(string guid)
|
{
|
var item = packModel.GetItemByGuid(guid);
|
if (item == null)
|
{
|
return;
|
}
|
|
if (item.packType != PackType.Item)
|
{
|
return;
|
}
|
|
var sellItem = new C0806_tagCPlayerSellItem();
|
sellItem.PackType = (byte)item.packType;
|
sellItem.ItemIndex = (byte)item.gridIndex;
|
GameNetSystem.Instance.SendInfo(sellItem);
|
}
|
|
#endregion
|
|
#region 续费
|
public void RenewalItem(string guid)
|
{
|
GuardOverdueWin.guid = guid;
|
WindowCenter.Instance.Open<GuardOverdueWin>();
|
}
|
#endregion
|
|
}
|
}
|