479 lines
18 KiB
C#
479 lines
18 KiB
C#
//**********************************************//
|
||
//作者:#何健#
|
||
//日期:#2020.02.13#
|
||
//简述:#装备数据结构#
|
||
//*********************************************//
|
||
using UnityEngine;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
|
||
using Thousandto.Cfg.Data;
|
||
using Thousandto.Code.Global;
|
||
using Thousandto.Code.Center;
|
||
using MSG_ImmortalEquip;
|
||
|
||
namespace Thousandto.Code.Logic
|
||
{
|
||
/// <summary>
|
||
/// 类Equipment说明
|
||
/// </summary>
|
||
public class ImmortalEquip: ItemBase
|
||
{
|
||
#region//静态变量
|
||
#endregion
|
||
|
||
#region //私有变量
|
||
private DeclareEquip _equip; //装备表数据
|
||
private uint _power;
|
||
|
||
//基础属性
|
||
private Dictionary<int, ulong> _baseAttrs;
|
||
private Dictionary<int, ulong> _specialAttrs;
|
||
|
||
private MSG_backpack.ItemInfo _itemInfoFromServer;
|
||
|
||
#endregion
|
||
|
||
#region //属性
|
||
public DeclareEquip ItemInfo
|
||
{
|
||
get
|
||
{
|
||
return _equip;
|
||
}
|
||
}
|
||
#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);
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public override void UnInitialization()
|
||
{
|
||
_baseAttrs.Clear();
|
||
}
|
||
|
||
public override int GetItemType()
|
||
{
|
||
return ItemType.ImmortalEquip;
|
||
}
|
||
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 dressEquip = GameCenter.EquipmentSystem.GetPlayerDressBackEquip(Part);
|
||
if(dressEquip != null)
|
||
{
|
||
return Power > dressEquip.Power;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public override bool CheckCanEquip()
|
||
{
|
||
var lp = GameCenter.GameSceneSystem.GetLocalPlayer();
|
||
if(lp != null)
|
||
{
|
||
return CheackOcc((int)lp.Occ) && CheckLevel(lp.Level) && !isTimeOut();
|
||
}
|
||
return false;
|
||
}
|
||
|
||
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()
|
||
{
|
||
if (CheckCanEquip())
|
||
{
|
||
ReqInlayImmortalEquip msg = new ReqInlayImmortalEquip();
|
||
msg.UID = DBID;
|
||
msg.Send();
|
||
}
|
||
else
|
||
GameCenter.MsgPromptSystem.ShowPrompt(DeclareMessageString.Get(DeclareMessageString.C_EQUIP_WEAR_FIALD));
|
||
}
|
||
|
||
//获取和已穿戴装备的战斗力差
|
||
public override int GetDressPowerDiff()
|
||
{
|
||
var dressEquip = GameCenter.EquipmentSystem.GetPlayerDressEquip(Part);
|
||
if (dressEquip != null)
|
||
{
|
||
return (int)Power - (int)dressEquip.Power;
|
||
}
|
||
return (int)Power;
|
||
}
|
||
#endregion
|
||
|
||
#region//公共接口
|
||
public ImmortalEquip( MSG_backpack.ItemInfo info ):
|
||
base(info)
|
||
{
|
||
Initialization();
|
||
SetAttribute();
|
||
|
||
_itemInfoFromServer = info;
|
||
}
|
||
|
||
public ImmortalEquip( ImmortalEquip info ):
|
||
base(info)
|
||
{
|
||
Initialization();
|
||
SetAttribute();
|
||
}
|
||
|
||
public string ToProtoBufferBytes()
|
||
{
|
||
byte[] bytes = Plugins.Common.ProtoBufUtils.Serialize(_itemInfoFromServer);
|
||
return Convert.ToBase64String(bytes);
|
||
}
|
||
|
||
public static ImmortalEquip ToEquipment(string str)
|
||
{
|
||
ImmortalEquip result;
|
||
byte[] message = Convert.FromBase64String(str);
|
||
MSG_backpack.ItemInfo itemInfo = new MSG_backpack.ItemInfo();
|
||
Plugins.Common.ProtoBufUtils.Deserialize(itemInfo, message);
|
||
result = new ImmortalEquip(itemInfo);
|
||
|
||
return result;
|
||
}
|
||
|
||
public ImmortalEquip(int id) :
|
||
base(id)
|
||
{
|
||
Initialization();
|
||
SetAttribute();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取装备的最基本的属性值
|
||
/// </summary>
|
||
/// <returns>属性类型,属性值</returns>
|
||
public Dictionary<int , ulong> GetBaseAttribute()
|
||
{
|
||
if (_baseAttrs != null)
|
||
return _baseAttrs;
|
||
return new Dictionary<int, ulong>();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取装备的最基本的属性值
|
||
/// </summary>
|
||
/// <returns>属性类型,属性值</returns>
|
||
public Dictionary<int, ulong> GetSpecialAttribute()
|
||
{
|
||
if (_specialAttrs != null)
|
||
return _specialAttrs;
|
||
return new Dictionary<int, ulong>();
|
||
}
|
||
|
||
//是否有效
|
||
public override bool IsValid()
|
||
{
|
||
return _equip != null;
|
||
}
|
||
#endregion
|
||
|
||
#region//私有方法
|
||
/// <summary>
|
||
/// 计算当前装备的属性值
|
||
/// </summary>
|
||
/// <param name="level"></param>
|
||
/// <returns>属性类型,增加的属性值</returns>
|
||
private void SetAttribute()
|
||
{
|
||
if (Equipment.EquipBaseAttDic == null)
|
||
{
|
||
Equipment.EquipBaseAttDic = new Dictionary<int, Dictionary<int, ulong>>(512);
|
||
}
|
||
if (_equip == null) return;
|
||
if (Equipment.EquipBaseAttDic.ContainsKey(_equip.Id))
|
||
{
|
||
_baseAttrs = Equipment.EquipBaseAttDic[_equip.Id];
|
||
}
|
||
else
|
||
{
|
||
if (_baseAttrs == null)
|
||
_baseAttrs = new Dictionary<int, ulong>();
|
||
_baseAttrs.Clear();
|
||
|
||
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);
|
||
}
|
||
}
|
||
//将属性缓存起来,下次使用的时候不会再次GC
|
||
Equipment.EquipBaseAttDic[_equip.Id] = _baseAttrs;
|
||
}
|
||
|
||
if (Equipment.EquipSpecialAttDic == null)
|
||
{
|
||
Equipment.EquipSpecialAttDic = new Dictionary<int, Dictionary<int, ulong>>(512);
|
||
}
|
||
if (Equipment.EquipSpecialAttDic.ContainsKey(_equip.Id))
|
||
{
|
||
_specialAttrs = Equipment.EquipSpecialAttDic[_equip.Id];
|
||
}
|
||
else
|
||
{
|
||
if (_specialAttrs == null)
|
||
_specialAttrs = new Dictionary<int, ulong>();
|
||
_specialAttrs.Clear();
|
||
var attrsArr = _equip.Attribute2.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 (_specialAttrs.ContainsKey(iType))
|
||
continue;
|
||
_specialAttrs.Add(iType, (ulong)baseAttr);
|
||
}
|
||
}
|
||
//将属性缓存起来,下次使用的时候不会再次GC
|
||
Equipment.EquipSpecialAttDic[_equip.Id] = _specialAttrs;
|
||
}
|
||
_power = FightPowerHelper.GetPropetryPower(_baseAttrs) + FightPowerHelper.GetPropetryPower(_specialAttrs);
|
||
}
|
||
#endregion
|
||
|
||
#region //辅助方法 此为静态方法
|
||
|
||
//装备的类型名字
|
||
public static string GetEquipNameWithType( int iType )
|
||
{
|
||
string ret = null;
|
||
var type = iType;
|
||
if (type < 400)
|
||
{
|
||
if (type == XianJiaType.XianJiaWeapon || (iType - (int)XianJiaType.XianJiaWeapon) % 14 == 0)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE30);
|
||
else if (type == XianJiaType.XianJiaClothes || (iType - (int)XianJiaType.XianJiaClothes) % 14 == 0)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE31);
|
||
else if (type == XianJiaType.XianJiaRing || (iType - (int)XianJiaType.XianJiaRing) % 14 == 0)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE32);
|
||
else if (type == XianJiaType.XianJiaZhenD || (iType - (int)XianJiaType.XianJiaZhenD) % 14 == 0)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE33);
|
||
else if (type == XianJiaType.XianJiaLeftP || (iType - (int)XianJiaType.XianJiaLeftP) % 14 == 0)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE34);
|
||
else if (type == XianJiaType.XianJiaRightP || (iType - (int)XianJiaType.XianJiaRightP) % 14 == 0)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE35);
|
||
else if (type == XianJiaType.XianJiaHelmet || (iType - (int)XianJiaType.XianJiaHelmet) % 14 == 0)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE36);
|
||
else if (type == XianJiaType.XianJiaShoulder || (iType - (int)XianJiaType.XianJiaShoulder) % 14 == 0)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE37);
|
||
else if (type == XianJiaType.XianJiaHuWan || (iType - (int)XianJiaType.XianJiaHuWan) % 14 == 0)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE38);
|
||
else if (type == XianJiaType.XianJiaShouT || (iType - (int)XianJiaType.XianJiaShouT) % 14 == 0)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE39);
|
||
else if (type == XianJiaType.XianJiaNeiCen || (iType - (int)XianJiaType.XianJiaNeiCen) % 14 == 0)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE40);
|
||
else if (type == XianJiaType.XianJiaBelt || (iType - (int)XianJiaType.XianJiaBelt) % 14 == 0)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE41);
|
||
else if (type == XianJiaType.XianJiaLeg || (iType - (int)XianJiaType.XianJiaLeg) % 14 == 0)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE42);
|
||
else if (type == XianJiaType.XianJiaShoe || (iType - (int)XianJiaType.XianJiaShoe) % 14 == 0)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE43);
|
||
}
|
||
else
|
||
{
|
||
if (type == XianJiaType.YangBaGua || (type - XianJiaType.YangBaGua) % 10 == 0)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE401);
|
||
else if (type == XianJiaType.YinBaGua || (type - XianJiaType.YangBaGua) % 10 == 1)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE402);
|
||
else if (type == XianJiaType.BaGua1 || (type - XianJiaType.YangBaGua) % 10 == 2)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE403);
|
||
else if (type == XianJiaType.BaGua2 || (type - XianJiaType.YangBaGua) % 10 == 3)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE404);
|
||
else if (type == XianJiaType.BaGua3 || (type - XianJiaType.YangBaGua) % 10 == 4)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE405);
|
||
else if (type == XianJiaType.BaGua4 || (type - XianJiaType.YangBaGua) % 10 == 5)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE406);
|
||
else if (type == XianJiaType.BaGua5 || (type - XianJiaType.YangBaGua) % 10 == 6)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE407);
|
||
else if (type == XianJiaType.BaGua6 || (type - XianJiaType.YangBaGua) % 10 == 7)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE408);
|
||
else if (type == XianJiaType.BaGua7 || (type - XianJiaType.YangBaGua) % 10 == 8)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE409);
|
||
else if (type == XianJiaType.BaGua8 || (type - XianJiaType.YangBaGua) % 10 == 9)
|
||
ret = Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_IMMORTALEQUIP_TYPE410);
|
||
}
|
||
|
||
return ret;
|
||
}
|
||
#endregion
|
||
}
|
||
}
|