265 lines
8.0 KiB
Lua
265 lines
8.0 KiB
Lua
------------------------------------------------
|
||
--作者: HJ
|
||
--日期: 2021-03-10
|
||
--文件: PetEquip.lua
|
||
--模块: PetEquip
|
||
--描述: 宠物装备数据模型
|
||
------------------------------------------------
|
||
local FightUtils = require "Logic.Base.FightUtils.FightUtils"
|
||
local L_ParentCSType = CS.Thousandto.Code.Logic.LuaItemBase
|
||
local PetEquip = {
|
||
--CS父类对象
|
||
_SuperObj_ = 0,
|
||
--配置表
|
||
ItemInfo = nil,
|
||
--基础属性字典
|
||
BaseAttrs = nil,
|
||
--特殊属性字典
|
||
SpecialAttrs = nil,
|
||
Power = 0,
|
||
}
|
||
|
||
---------------------------继承父类接口begin------------------------
|
||
function PetEquip:Initialization(id)
|
||
self.ItemInfo = DataConfig.DataEquip[id]
|
||
return true;
|
||
end
|
||
|
||
function PetEquip:UnInitialization()
|
||
if self.BaseAttrs then
|
||
self.BaseAttrs:Clear()
|
||
end
|
||
end
|
||
function PetEquip:GetItemType()
|
||
return ItemType.PetEquip;
|
||
end
|
||
function PetEquip:GetName()
|
||
local ret = "";
|
||
if self.ItemInfo then
|
||
ret = self.ItemInfo.Name;
|
||
end
|
||
return ret;
|
||
end
|
||
function PetEquip:GetIcon()
|
||
local ret = -1;
|
||
if self.ItemInfo then
|
||
ret = self.ItemInfo.Icon;
|
||
end
|
||
return ret;
|
||
end
|
||
function PetEquip:GetEffect()
|
||
local ret = -1;
|
||
if self.ItemInfo then
|
||
ret = self.ItemInfo.Effect;
|
||
end
|
||
return ret;
|
||
end
|
||
function PetEquip:GetQuality()
|
||
local ret = -1;
|
||
if self.ItemInfo then
|
||
ret = self.ItemInfo.Quality;
|
||
end
|
||
return ret;
|
||
end
|
||
function PetEquip:GetStarNum()
|
||
local ret = 0;
|
||
if self.ItemInfo then
|
||
ret = self.ItemInfo.DiamondNumber;
|
||
end
|
||
return ret;
|
||
end
|
||
function PetEquip:GetOcc()
|
||
local ret = "";
|
||
if self.ItemInfo then
|
||
ret = self.ItemInfo.Gender;
|
||
end
|
||
return ret;
|
||
end
|
||
function PetEquip:GetPart()
|
||
local ret = -1;
|
||
if self.ItemInfo then
|
||
ret = self.ItemInfo.Part;
|
||
end
|
||
return ret;
|
||
end
|
||
function PetEquip:GetGrade()
|
||
local ret = 0;
|
||
if self.ItemInfo then
|
||
ret = self.ItemInfo.Grade;
|
||
end
|
||
return ret;
|
||
end
|
||
function PetEquip:GetPower()
|
||
return self.Power;
|
||
end
|
||
function PetEquip:CheckLevel(level)
|
||
return self.ItemInfo.Level <= level;
|
||
end
|
||
function PetEquip:CheackOcc(sex)
|
||
if (string.find(self.Occ, "9") ~= nil) then
|
||
return true;
|
||
end
|
||
local ret = false;
|
||
if string.find(self.ItemInfo.Gender, tostring(sex)) ~= nil then
|
||
ret = true;
|
||
else
|
||
ret = false;
|
||
end
|
||
return ret;
|
||
end
|
||
|
||
function PetEquip:CheckClass()
|
||
if (self.ItemInfo.Classlevel <= 0) then
|
||
return true;
|
||
else
|
||
local p = GameCenter.GameSceneSystem:GetLocalPlayer();
|
||
if p then
|
||
if (p.ChangeJobLevel >= self.ItemInfo.Classlevel) then
|
||
return true;
|
||
else
|
||
return false;
|
||
end
|
||
end
|
||
end
|
||
return false;
|
||
end
|
||
|
||
--检测是否可以上架
|
||
function PetEquip:CanAuction()
|
||
if not GameCenter.MainFunctionSystem:FunctionIsVisible(FunctionStartIdCode.Auchtion) then
|
||
return false;
|
||
end
|
||
if (self.IsBind) then
|
||
return false;
|
||
end
|
||
if (self.ItemInfo.AuctionMaxPrice == 0) then
|
||
return false;
|
||
end
|
||
return true;
|
||
end
|
||
--是否有效
|
||
function PetEquip:IsValid()
|
||
return self.ItemInfo ~= nil
|
||
end
|
||
---------------------------继承父类接口end--------------------------
|
||
function PetEquip:NewWithMsg(msg)
|
||
local _m = Utils.DeepCopy(self)
|
||
_m._SuperObj_ = L_ParentCSType.CreateByMsg(msg);
|
||
_m:_InitBindOverride_();
|
||
_m:_InitContent_();
|
||
if msg then
|
||
_m:Initialization(msg.itemModelId);
|
||
end
|
||
_m:SetAttribute();
|
||
Utils.BuildInheritRel(_m);
|
||
return _m
|
||
end
|
||
function PetEquip:New(...)
|
||
local _m = Utils.DeepCopy(self)
|
||
_m._SuperObj_ = L_ParentCSType.Create(...);
|
||
_m:_InitBindOverride_();
|
||
_m:_InitContent_();
|
||
_m:Initialization(...);
|
||
_m:SetAttribute();
|
||
Utils.BuildInheritRel(_m);
|
||
return _m
|
||
end
|
||
--绑定Override的方法
|
||
function PetEquip:_InitBindOverride_()
|
||
--重载函数的重定义
|
||
--重载函数的重定义
|
||
self._SuperObj_.IsValidDelegate = Utils.Handler(self.IsValid, self, nil, true);
|
||
self._SuperObj_.CanAuctionDelegate = Utils.Handler(self.CanAuction, self, nil, true);
|
||
self._SuperObj_.IsUsedInBatchesDelegate = Utils.Handler(self.IsUsedInBatches, self, nil, true);
|
||
self._SuperObj_.CheckClassDelegate = Utils.Handler(self.CheckClass, self, nil, true);
|
||
self._SuperObj_.CheckOccDelegate = Utils.Handler(self.CheackOcc, self, nil, true);
|
||
self._SuperObj_.CheckLevelDelegate = Utils.Handler(self.CheckLevel, self, nil, true);
|
||
self._SuperObj_.GetPowerDelegate = Utils.Handler(self.GetPower, self, nil, true);
|
||
self._SuperObj_.GetGradeDelegate = Utils.Handler(self.GetGrade, self, nil, true);
|
||
self._SuperObj_.GetPartDelegate = Utils.Handler(self.GetPart, self, nil, true);
|
||
self._SuperObj_.GetOccDelegate = Utils.Handler(self.GetOcc, self, nil, true);
|
||
self._SuperObj_.GetStarNumDelegate = Utils.Handler(self.GetStarNum, self, nil, true);
|
||
self._SuperObj_.GetQualityDelegate = Utils.Handler(self.GetQuality, self, nil, true);
|
||
self._SuperObj_.GetEffectDelegate = Utils.Handler(self.GetEffect, self, nil, true);
|
||
self._SuperObj_.GetIconDelegate = Utils.Handler(self.GetIcon, self, nil, true);
|
||
self._SuperObj_.GetNameDelegate = Utils.Handler(self.GetName, self, nil, true);
|
||
self._SuperObj_.GetItemTypeDelegate = Utils.Handler(self.GetItemType, self, nil, true);
|
||
self._SuperObj_.UnInitializationDelegate = Utils.Handler(self.UnInitialization, self, nil, true);
|
||
end
|
||
|
||
--初始化
|
||
function PetEquip:_InitContent_()
|
||
--定义临时变量,用户回调
|
||
end
|
||
function PetEquip:GetCSObj()
|
||
return self._SuperObj_;
|
||
end
|
||
--获取装备的最基本的属性值
|
||
function PetEquip:GetBaseAttribute()
|
||
if self.BaseAttrs then
|
||
return self.BaseAttrs;
|
||
end
|
||
return Dictionary:New()
|
||
end
|
||
|
||
--获取装备的特殊属性值
|
||
function PetEquip:GetSpecialAttribute()
|
||
if self.SpecialAttrs then
|
||
return self.SpecialAttrs;
|
||
end
|
||
return Dictionary:New()
|
||
end
|
||
|
||
--计算当前装备的属性值
|
||
function PetEquip:SetAttribute()
|
||
if self.ItemInfo == nil then
|
||
return;
|
||
end
|
||
if (LuaItemBase.EquipBaseAttDic == nil) then
|
||
LuaItemBase.EquipBaseAttDic = Dictionary:New()
|
||
end
|
||
if(LuaItemBase.EquipBaseAttDic:ContainsKey(self.ItemInfo.Id)) then
|
||
self.BaseAttrs = LuaItemBase.EquipBaseAttDic[self.ItemInfo.Id];
|
||
else
|
||
if self.BaseAttrs == nil then
|
||
self.BaseAttrs = Dictionary:New()
|
||
end
|
||
self.BaseAttrs:Clear();
|
||
local attrsArr = Utils.SplitStr(self.ItemInfo.Attribute1, ';')
|
||
for i = 1, #attrsArr do
|
||
local attrs = Utils.SplitNumber(attrsArr[i], '_')
|
||
if #attrs == 2 then
|
||
if not self.BaseAttrs:ContainsKey(attrs[1]) then
|
||
self.BaseAttrs:Add(attrs[1], attrs[2]);
|
||
end
|
||
end
|
||
end
|
||
--将属性缓存起来,下次使用的时候不会再次GC
|
||
LuaItemBase.EquipBaseAttDic[self.ItemInfo.Id] = self.BaseAttrs;
|
||
end
|
||
|
||
if (LuaItemBase.EquipSpecialAttDic == nil) then
|
||
LuaItemBase.EquipSpecialAttDic = Dictionary:New()
|
||
end
|
||
if (LuaItemBase.EquipSpecialAttDic:ContainsKey(self.ItemInfo.Id)) then
|
||
self.SpecialAttrs = LuaItemBase.EquipSpecialAttDic[self.ItemInfo.Id];
|
||
else
|
||
if self.SpecialAttrs == nil then
|
||
self.SpecialAttrs = Dictionary:New()
|
||
end
|
||
self.SpecialAttrs:Clear();
|
||
local attrsArr = Utils.SplitStr(self.ItemInfo.Attribute2, ';')
|
||
for i = 1, #attrsArr do
|
||
local attrs = Utils.SplitNumber(attrsArr[i], '_')
|
||
if #attrs == 2 then
|
||
if not self.SpecialAttrs:ContainsKey(attrs[1]) then
|
||
self.SpecialAttrs:Add(attrs[1], attrs[2]);
|
||
end
|
||
end
|
||
end
|
||
--将属性缓存起来,下次使用的时候不会再次GC
|
||
LuaItemBase.EquipSpecialAttDic[self.ItemInfo.Id] = self.SpecialAttrs;
|
||
end
|
||
self.Power = FightUtils.GetPropetryPower(self.BaseAttrs) + FightUtils.GetPropetryPower(self.SpecialAttrs);
|
||
end
|
||
return PetEquip |