Files
Main/Assets/Code/Logic/Item/ItemModel.cs

283 lines
8.3 KiB
C#
Raw Normal View History

2025-01-25 04:38:09 +08:00
//**********************************************//
//作者:#何健#
//日期:#2016.10.12#
//简述:#物品基础数据结构#
//*********************************************//
using Thousandto.Cfg.Data;
using MSG_backpack;
using Thousandto.Code.Global;
using Thousandto.Code.Center;
using Thousandto.Plugins.Common;
using System.Collections.Generic;
namespace Thousandto.Code.Logic
{
public class ItemModel : ItemBase
{
#region //私有变量
private DeclareItem _item;
#endregion
#region //属性
public DeclareItem ItemInfo
{
get
{
return _item;
}
}
#endregion
#region //公共方法
public ItemModel(ItemInfo info) :
base(info)
{
Initialization();
}
public ItemModel(int cfgId, ulong dbid = 0) :
base(cfgId, dbid)
{
Initialization();
}
public ItemModel(ItemModel info) :
base(info)
{
Initialization();
}
public override bool IsCanUse(int useType = ItemOpertion.Use)
{
//TODO 零时测试
bool ret = false;
int type = (int)useType;
if (ItemInfo.ButtonType.Contains(type.ToString()))
ret = true;
if (useType == ItemOpertion.Stall && !IsBind && (ItemInfo.AuctionMaxPrice > 0 || ItemInfo.AuctionMaxPrice == -1))
ret = true;
return ret;
}
public override bool CheckCareer(int career)
{
return base.CheckCareer(career);
}
public override bool CheckLevel(int level)
{
bool ret = false;
if (ItemInfo.Level <= level)
{
ret = true;
}
return ret;
}
public override bool isTimeOut()
{
return base.isTimeOut();
}
public override bool CheackOcc(int sex)
{
bool ret = false;
if (ItemInfo.Sex == 2)
{
ret = true;
}
else if (sex == ItemInfo.Sex)
{
ret = true;
}
return ret;
}
public override bool IsNeedSecond(int useType = ItemOpertion.Use)
{
bool ret = false;
ret = ItemInfo.IfConfirm == 1;
return ret;
}
public override bool IsUsedInBatches()
{
bool ret = false;
if (null != ItemInfo)
{
ret = !ItemInfo.ButtonType.Contains("3") ? false : true;
}
return ret;
}
//是否有效
public override bool IsValid()
{
return _item != null;
}
public override int GetItemType()
{
var ret = ItemType.UnDefine;
if (ItemInfo != null)
ret = ItemInfo.Type;
return ret;
}
public override int GetQuality()
{
int ret = -1;
if (ItemInfo != null)
ret = ItemInfo.Color;
return ret;
}
public override string GetName()
{
if (null != ItemInfo)
{
int length = ItemInfo.Name.LastIndexOf("_");
if (length == -1)
{
length = ItemInfo.Name.Length;
}
else
{
length += 1;
}
string realName = ItemInfo.Name.Substring(0, length);
return realName;
}
else
{
return null;
}
}
public override int GetEffect()
{
int ret = -1;
if (ItemInfo != null)
ret = ItemInfo.Effect;
return ret;
}
public override int GetIcon()
{
int ret = -1;
if (ItemInfo != null)
ret = ItemInfo.Icon;
return ret;
}
public override string GetOcc()
{
if (ItemInfo != null)
{
return ItemInfo.Occupation;
}
return "9";
}
//检测是否可以上架
public override bool CanAuction()
{
if (!GameCenter.MainFunctionSystem.FunctionIsVisible(FunctionStartIdCode.Auchtion))
return false;
if (IsBind)
return false;
if (ItemInfo.AuctionMaxPrice == 0)
return false;
return true;
}
//使用物品
public override void UseItem()
{
//--如果是多选一宝箱,打开宝箱开启使用界面
if (Type == ItemType.SpecialBox)
{
GameCenter.PushFixEvent(UIEventDefine.UITreasureChestsForm_Open, this);
return;
}
if (!string.IsNullOrEmpty(ItemInfo.UesUIId))
{
var arr = ItemInfo.UesUIId.Split('_');
int functionID = 0;
if (arr.Length > 0)
int.TryParse(arr[0], out functionID);
if (arr.Length > 1)
{
var param = new int[arr.Length - 1];
for (int i = 1; i < arr.Length; i++)
{
param[i - 1] = int.Parse(arr[i]);
}
GameCenter.MainFunctionSystem.DoFunctionCallBack(functionID, param);
}
else
GameCenter.MainFunctionSystem.DoFunctionCallBack(functionID, null);
return;
}
if (Count > 1 && IsUsedInBatches())
{
GameCenter.PushFixEvent(UIEventDefine.UIITEMBATCH_OPEN, this);
}
else
{
var sendUse = true;
var effArr = ItemInfo.EffectNum.Split('_');
if (effArr.Length > 2)
{
var attType = 0;
var attValue = 0;
if (int.TryParse(effArr[0], out attType) && int.TryParse(effArr[1], out attValue))
{
if (attType == 3)
{
var curItemRate = GameCenter.LuaSystem.Adaptor.GetCurItemAddRate() * 100;
if (curItemRate > 0 && curItemRate != attValue)
{
sendUse = false;
GameCenter.MsgPromptSystem.ShowMsgBox(string.Format(Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_ITEMUSE_TIPSOFFLINE_TIPS), Name),
(code) =>
{
if (code == MsgBoxResultCode.Button2)
{
ReqUseItem msg = new ReqUseItem();
msg.itemId = DBID;
msg.num = 1;
msg.Send();
}
});
}
}
else if (attType == 10)
{
//经验丹
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_USEEXP_ITEM);
}
}
}
if (sendUse)
{
ReqUseItem msg = new ReqUseItem();
msg.itemId = DBID;
msg.num = 1;
msg.Send();
}
}
}
//获取和已穿戴装备的战斗力差
public override int GetDressPowerDiff()
{
return 0;
}
#endregion
#region private methods
public override bool Initialization()
{
base.Initialization();
_item = DeclareItem.Get(CfgID);
return ItemInfo != null;
}
#endregion
}
}