551 lines
18 KiB
C#
551 lines
18 KiB
C#
//**********************************************//
|
|
//作者:#杨全福#
|
|
//日期:#2019.11.04#
|
|
//简述:#圣装数据结构#
|
|
//*********************************************//
|
|
using UnityEngine;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
using Thousandto.Cfg.Data;
|
|
using Thousandto.Code.Global;
|
|
using Thousandto.Code.Center;
|
|
using XLua;
|
|
|
|
namespace Thousandto.Code.Logic
|
|
{
|
|
/// <summary>
|
|
/// HolyEquip
|
|
/// </summary>
|
|
public class HolyEquip : ItemBase
|
|
{
|
|
#region //私有变量
|
|
private DeclareEquip _equip; //装备表数据
|
|
|
|
//基础属性
|
|
private Dictionary<int, ulong> _baseAttrs;
|
|
//装备战斗力
|
|
private uint _power = 0;
|
|
//接收到的服务器数据
|
|
private MSG_HolyEquip.HolyEquipItem _itemInfoFromServer;
|
|
#endregion
|
|
|
|
#region //属性
|
|
//物品配置
|
|
public DeclareEquip ItemInfo
|
|
{
|
|
get
|
|
{
|
|
return _equip;
|
|
}
|
|
}
|
|
//是否可以分解
|
|
public bool CanFenJie { get; private set; }
|
|
//分解物品数量
|
|
public int FenJieCount { get; private set; }
|
|
//是否可以拆解
|
|
public bool CanChaiJian { get; private set; }
|
|
//拆解物品列表
|
|
public Dictionary<int, int> CaiJianItems { get; private set; }
|
|
//所属的套装ID
|
|
public int SuitID { get; private set; }
|
|
//激活的套装数量和ID
|
|
public Dictionary<int, int> ActiveSuits { get; private set; }
|
|
#endregion
|
|
|
|
#region//继承父类
|
|
public override bool Initialization()
|
|
{
|
|
base.Initialization();
|
|
_equip = DeclareEquip.Get(CfgID);
|
|
if (_equip == null)
|
|
{
|
|
//Debug.LogError("equip info initialization declareequip is null id = " + CfgID);
|
|
}
|
|
var resolveCfg = DeclareEquipHolyResolve.Get(CfgID);
|
|
if (resolveCfg != null)
|
|
{
|
|
CaiJianItems = new Dictionary<int, int>();
|
|
CanFenJie = resolveCfg.Type == 1;
|
|
CanChaiJian = resolveCfg.Type == 2;
|
|
var itemParam = resolveCfg.Item.Split(';');
|
|
if (itemParam != null && itemParam.Length > 0)
|
|
{
|
|
for (int i = 0; i < itemParam.Length; ++i)
|
|
{
|
|
var itemParamArray = itemParam[i].Split('_');
|
|
if(itemParamArray.Length >= 2)
|
|
{
|
|
if (CanFenJie)
|
|
{
|
|
FenJieCount = int.Parse(itemParamArray[1]);
|
|
break;
|
|
}
|
|
else if (CanChaiJian)
|
|
{
|
|
CaiJianItems[int.Parse(itemParamArray[0])] = int.Parse(itemParamArray[1]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if(CanChaiJian)
|
|
{
|
|
itemParam = resolveCfg.HolyEquip.Split(';');
|
|
if (itemParam != null && itemParam.Length > 0)
|
|
{
|
|
for (int i = 0; i < itemParam.Length; ++i)
|
|
{
|
|
var itemParamArray = itemParam[i].Split('_');
|
|
int itemID = int.Parse(itemParamArray[0]);
|
|
int itemCount = int.Parse(itemParamArray[1]);
|
|
if (CaiJianItems.ContainsKey(itemID))
|
|
{
|
|
CaiJianItems[itemID] = CaiJianItems[itemID] + itemCount;
|
|
}
|
|
else
|
|
{
|
|
CaiJianItems[itemID] = itemCount;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//计算套装ID
|
|
SuitID = _equip.Grade * 10000 + _equip.Quality * 100 + _equip.HolySuitType;
|
|
ActiveSuits = new Dictionary<int, int>(4);
|
|
return true;
|
|
}
|
|
|
|
public override void UnInitialization()
|
|
{
|
|
_baseAttrs.Clear();
|
|
}
|
|
|
|
public override int GetItemType()
|
|
{
|
|
return ItemType.HolyEquip;
|
|
}
|
|
public override string GetName()
|
|
{
|
|
string ret = "";
|
|
if (null != ItemInfo)
|
|
{
|
|
ret = ItemInfo.Name;
|
|
}
|
|
return ret;
|
|
}
|
|
public override int GetIcon()
|
|
{
|
|
int ret = -1;
|
|
if (ItemInfo != null)
|
|
ret = ItemInfo.Icon;
|
|
return ret;
|
|
}
|
|
public override int GetEffect()
|
|
{
|
|
int ret = -1;
|
|
if (ItemInfo != null)
|
|
ret = ItemInfo.Effect;
|
|
return ret;
|
|
}
|
|
public override int GetQuality()
|
|
{
|
|
int ret = -1;
|
|
if (ItemInfo != null)
|
|
ret = ItemInfo.Quality;
|
|
return ret;
|
|
}
|
|
public override int GetStarNum()
|
|
{
|
|
var ret = 0;
|
|
if (ItemInfo != null)
|
|
ret = ItemInfo.DiamondNumber;
|
|
return ret;
|
|
}
|
|
public override string GetOcc()
|
|
{
|
|
if (ItemInfo != null)
|
|
{
|
|
return ItemInfo.Gender;
|
|
}
|
|
return "";
|
|
}
|
|
public override int GetPart()
|
|
{
|
|
var ret = -1;
|
|
if (ItemInfo != null)
|
|
ret = ItemInfo.Part;
|
|
return ret;
|
|
}
|
|
public override int GetGrade()
|
|
{
|
|
var ret = 0;
|
|
if (ItemInfo != null)
|
|
ret = ItemInfo.Grade;
|
|
return ret;
|
|
}
|
|
public override uint GetPower()
|
|
{
|
|
return _power;
|
|
}
|
|
|
|
public override bool IsCanUse(int useType = ItemOpertion.Use)
|
|
{
|
|
return base.IsCanUse(useType);
|
|
}
|
|
|
|
public override bool CheckLevel(int level)
|
|
{
|
|
return ItemInfo.Level <= level;
|
|
}
|
|
|
|
public override bool CheackOcc(int sex)
|
|
{
|
|
if (Occ.IndexOf("9") >= 0)
|
|
return true;
|
|
bool ret = false;
|
|
if (ItemInfo.Gender.IndexOf(sex.ToString()) >= 0)
|
|
{
|
|
ret = true;
|
|
}
|
|
else
|
|
{
|
|
ret = false;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
public override bool CheckBetterThanDress()
|
|
{
|
|
var dressPower = GameCenter.LuaSystem.Adaptor.GetHolyPartFightPower(Part);
|
|
return Power > dressPower;
|
|
}
|
|
|
|
public override bool CheckCanEquip()
|
|
{
|
|
var localPlayer = GameCenter.GameSceneSystem.GetLocalPlayer();
|
|
if (localPlayer == null)
|
|
{
|
|
return false;
|
|
}
|
|
if (!CheckLevel(localPlayer.Level))
|
|
{
|
|
return false;
|
|
}
|
|
if (!CheackOcc((int)localPlayer.Occ))
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public override bool CheckClass()
|
|
{
|
|
//if (Occ == 9)
|
|
// return true;
|
|
//LocalPlayer p = GameCenter.GameSceneSystem.GetLocalPlayer();
|
|
//if (p != null)
|
|
//{
|
|
// int curID = ((int)p.Occ + 1) * 1000 + p.GradeLevel;
|
|
// if (curID >= ItemInfo.Classlevel)
|
|
// {
|
|
// return true;
|
|
// }
|
|
// else
|
|
// {
|
|
// return false;
|
|
// }
|
|
//}
|
|
//return false;
|
|
return true;
|
|
}
|
|
|
|
public override bool isTimeOut()
|
|
{
|
|
return base.isTimeOut();
|
|
}
|
|
|
|
public override bool IsNeedSecond(int useType = ItemOpertion.Use)
|
|
{
|
|
bool ret = false;
|
|
if (ItemInfo == null)
|
|
{
|
|
return false;
|
|
}
|
|
switch (useType)
|
|
{
|
|
case ItemOpertion.Use:
|
|
ret = ItemInfo.Quality >= 4; //紫色以上装备就需要提示
|
|
break;
|
|
case ItemOpertion.Split:
|
|
ret = false;
|
|
break;
|
|
case ItemOpertion.Sell:
|
|
case ItemOpertion.Stall:
|
|
case ItemOpertion.Resolve:
|
|
ret = ItemInfo.Quality >= 4; //紫色以上装备就需要提示
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
public override bool IsUsedInBatches()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//检测是否可以上架
|
|
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()
|
|
{
|
|
MSG_HolyEquip.ReqInlayHoly msg = new MSG_HolyEquip.ReqInlayHoly();
|
|
msg.UID = DBID;
|
|
msg.Send();
|
|
}
|
|
|
|
//获取和已穿戴装备的战斗力差
|
|
public override int GetDressPowerDiff()
|
|
{
|
|
var dressPower = GameCenter.LuaSystem.Adaptor.GetHolyPartFightPower(Part);
|
|
return (int)Power - dressPower;
|
|
}
|
|
#endregion
|
|
|
|
#region//公共接口
|
|
|
|
public HolyEquip(MSG_backpack.ItemInfo info) :
|
|
base(info)
|
|
{
|
|
Initialization();
|
|
SetAttribute();
|
|
//_itemInfoFromServer = info;
|
|
}
|
|
|
|
public HolyEquip(MSG_HolyEquip.HolyEquipItem info) :
|
|
base(info)
|
|
{
|
|
Initialization();
|
|
SetAttribute();
|
|
_itemInfoFromServer = info;
|
|
}
|
|
|
|
public HolyEquip(HolyEquip info) :
|
|
base(info)
|
|
{
|
|
Initialization();
|
|
SetAttribute();
|
|
_itemInfoFromServer = info._itemInfoFromServer;
|
|
}
|
|
|
|
public HolyEquip(int id) :
|
|
base(id)
|
|
{
|
|
Initialization();
|
|
SetAttribute();
|
|
}
|
|
|
|
public string ToProtoBufferBytes()
|
|
{
|
|
byte[] bytes = Plugins.Common.ProtoBufUtils.Serialize(_itemInfoFromServer);
|
|
return Convert.ToBase64String(bytes);
|
|
}
|
|
|
|
public static Equipment ToEquipment(string str)
|
|
{
|
|
Equipment result;
|
|
byte[] message = Convert.FromBase64String(str);
|
|
MSG_backpack.ItemInfo itemInfo = new MSG_backpack.ItemInfo();
|
|
Plugins.Common.ProtoBufUtils.Deserialize(itemInfo, message);
|
|
result = new Equipment(itemInfo);
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取装备的最基本的属性值
|
|
/// </summary>
|
|
/// <returns>属性类型,属性值</returns>
|
|
public Dictionary<int, ulong> GetBaseAttribute()
|
|
{
|
|
if (_baseAttrs != null)
|
|
return _baseAttrs;
|
|
return new Dictionary<int, ulong>();
|
|
}
|
|
|
|
//是否有效
|
|
public override bool IsValid()
|
|
{
|
|
return _equip != null;
|
|
}
|
|
|
|
//获取根据数量获取激活的套装
|
|
public int GetActiveSuitID(int count)
|
|
{
|
|
var result = 0;
|
|
ActiveSuits.TryGetValue(count, out result);
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
#region//私有方法
|
|
/// <summary>
|
|
/// 计算当前装备的属性值
|
|
/// </summary>
|
|
/// <param name="level"></param>
|
|
/// <returns>属性类型,增加的属性值</returns>
|
|
private void SetAttribute()
|
|
{
|
|
if (_baseAttrs == null)
|
|
_baseAttrs = new Dictionary<int, ulong>();
|
|
_baseAttrs.Clear();
|
|
if (_equip == null) return;
|
|
|
|
var attrsArr = _equip.Attribute1.Split(GameDefine.SplitSemicolon, StringSplitOptions.RemoveEmptyEntries);
|
|
for (int i = 0; i < attrsArr.Length; i++)
|
|
{
|
|
string[] attrs = attrsArr[i].Split(GameDefine.SplitUnderline, StringSplitOptions.RemoveEmptyEntries);
|
|
if (attrs.Length == 2)
|
|
{
|
|
int iType = int.Parse(attrs[0]);
|
|
int baseAttr = int.Parse(attrs[1]);
|
|
if (_baseAttrs.ContainsKey(iType))
|
|
continue;
|
|
_baseAttrs.Add(iType, (ulong)baseAttr);
|
|
}
|
|
}
|
|
_power = FightPowerHelper.GetPropetryPower(_baseAttrs);
|
|
}
|
|
#endregion
|
|
|
|
#region //辅助方法 此为静态方法
|
|
//装备的类型名字
|
|
public static string GetEquipNameWithType(int type)
|
|
{
|
|
type = (type - 101) % 11;
|
|
switch (type)
|
|
{
|
|
case 0://圣装鞋子
|
|
return Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_HOLY_EQUIP_LV);
|
|
case 1://圣装裤子
|
|
return Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_HOLY_EQUIP_KU);
|
|
case 2://圣装护手
|
|
return Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_HOLY_EQUIP_WAN);
|
|
case 3://圣装武器
|
|
return Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_HOLY_EQUIP_WU);
|
|
case 4://圣装衣服
|
|
return Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_HOLY_EQUIP_YI);
|
|
case 5://圣装头盔
|
|
return Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_HOLY_EQUIP_GUAN);
|
|
case 6://圣装项链
|
|
return Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_EQUIP_NAME_NECKLACE);
|
|
case 7://圣装戒指
|
|
return Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_EQUIP_NAME_FINGERRING);
|
|
case 8://圣装配饰
|
|
return Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_HOLY_EQUIP_PEISHI);
|
|
case 9://圣装耳环
|
|
return Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_HOLY_EQUIP_ERHUAN);
|
|
case 10://圣装斗心
|
|
return Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_HOLY_EQUIP_DOUXIN);
|
|
}
|
|
return Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_ITEM_OCC_NAME_COMMON);
|
|
}
|
|
|
|
//装备职业名字
|
|
public static string GetOccNameWithOcc(int occ)
|
|
{
|
|
//如果在配置文件中找到,那么就返回名字,如果找不到,返回通用
|
|
var cfg = DeclarePlayerOccupation.Get(occ);
|
|
if (cfg != null)
|
|
{
|
|
return cfg.JobName;
|
|
}
|
|
return DeclareMessageString.Get(DeclareMessageString.C_ITEM_OCC_NAME_COMMON);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 阶数转换,输入等阶
|
|
/// </summary>
|
|
/// <param name="level"></param>
|
|
/// <returns></returns>
|
|
public static string LevelConvert(int level)
|
|
{
|
|
string str = "";
|
|
switch (level)
|
|
{
|
|
case 1:
|
|
str = DeclareMessageString.Get(DeclareMessageString.C_GUILD_SORT_LEVEL_1);
|
|
break;
|
|
case 2:
|
|
str = DeclareMessageString.Get(DeclareMessageString.C_GUILD_SORT_LEVEL_2);
|
|
break;
|
|
case 3:
|
|
str = DeclareMessageString.Get(DeclareMessageString.C_GUILD_SORT_LEVEL_3);
|
|
break;
|
|
case 4:
|
|
str = DeclareMessageString.Get(DeclareMessageString.C_GUILD_SORT_LEVEL_4);
|
|
break;
|
|
case 5:
|
|
str = DeclareMessageString.Get(DeclareMessageString.C_GUILD_SORT_LEVEL_5);
|
|
break;
|
|
case 6:
|
|
str = DeclareMessageString.Get(DeclareMessageString.C_GUILD_SORT_LEVEL_6);
|
|
break;
|
|
case 7:
|
|
str = DeclareMessageString.Get(DeclareMessageString.C_GUILD_SORT_LEVEL_7);
|
|
break;
|
|
case 8:
|
|
str = DeclareMessageString.Get(DeclareMessageString.C_GUILD_SORT_LEVEL_8);
|
|
break;
|
|
case 9:
|
|
str = DeclareMessageString.Get(DeclareMessageString.C_GUILD_SORT_LEVEL_9);
|
|
break;
|
|
case 10:
|
|
str = DeclareMessageString.Get(DeclareMessageString.C_GUILD_SORT_LEVEL_10);
|
|
break;
|
|
case 11:
|
|
str = DeclareMessageString.Get(DeclareMessageString.C_GUILD_SORT_LEVEL_11);
|
|
break;
|
|
case 12:
|
|
str = DeclareMessageString.Get(DeclareMessageString.C_GUILD_SORT_LEVEL_12);
|
|
break;
|
|
case 13:
|
|
str = DeclareMessageString.Get(DeclareMessageString.C_GUILD_SORT_LEVEL_13);
|
|
break;
|
|
case 14:
|
|
str = DeclareMessageString.Get(DeclareMessageString.C_GUILD_SORT_LEVEL_14);
|
|
break;
|
|
case 15:
|
|
str = DeclareMessageString.Get(DeclareMessageString.C_GUILD_SORT_LEVEL_15);
|
|
break;
|
|
}
|
|
return str;
|
|
}
|
|
|
|
//根据luamsg创建圣装
|
|
public static HolyEquip CreateByLuaMsg(LuaTable msgTable)
|
|
{
|
|
var msg = new MSG_HolyEquip.HolyEquipItem();
|
|
if (!msgTable.TryGet("uid", out msg.uid))//物品唯一ID值
|
|
return null;
|
|
if (!msgTable.TryGet("itemId", out msg.itemId))//物品模板ID值
|
|
return null;
|
|
if (!msgTable.TryGet("isBind", out msg.isBind))//是否绑定
|
|
return null;
|
|
return new HolyEquip(msg);
|
|
}
|
|
#endregion
|
|
}
|
|
}
|