Files
Main/Assets/GameAssets/Resources/Lua/Logic/Item/DevilSoulEquip.lua
2025-01-25 04:38:09 +08:00

265 lines
8.1 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

------------------------------------------------
--作者: dhq
--日期: 2021-04-15
--文件: DevilSoulEquip.lua
--模块: DevilSoulEquip
--描述: 魔魂装备数据模型
------------------------------------------------
local FightUtils = require "Logic.Base.FightUtils.FightUtils"
local L_ParentCSType = CS.Thousandto.Code.Logic.LuaItemBase
local DevilSoulEquip = {
--CS父类对象
_SuperObj_ = 0,
--配置表
ItemInfo = nil,
--基础属性字典
BaseAttrs = nil,
--特殊属性字典
SpecialAttrs = nil,
Power = 0,
}
---------------------------继承父类接口begin------------------------
function DevilSoulEquip:Initialization(id)
self.ItemInfo = DataConfig.DataEquip[id]
return true;
end
function DevilSoulEquip:UnInitialization()
if self.BaseAttrs then
self.BaseAttrs:Clear()
end
end
function DevilSoulEquip:GetItemType()
return ItemType.DevilSoulEquip;
end
function DevilSoulEquip:GetName()
local ret = "";
if self.ItemInfo then
ret = self.ItemInfo.Name;
end
return ret;
end
function DevilSoulEquip:GetIcon()
local ret = -1;
if self.ItemInfo then
ret = self.ItemInfo.Icon;
end
return ret;
end
function DevilSoulEquip:GetEffect()
local ret = -1;
if self.ItemInfo then
ret = self.ItemInfo.Effect;
end
return ret;
end
function DevilSoulEquip:GetQuality()
local ret = -1;
if self.ItemInfo then
ret = self.ItemInfo.Quality;
end
return ret;
end
function DevilSoulEquip:GetStarNum()
local ret = 0;
if self.ItemInfo then
ret = self.ItemInfo.DiamondNumber;
end
return ret;
end
function DevilSoulEquip:GetOcc()
local ret = "";
if self.ItemInfo then
ret = self.ItemInfo.Gender;
end
return ret;
end
function DevilSoulEquip:GetPart()
local ret = -1;
if self.ItemInfo then
ret = self.ItemInfo.Part;
end
return ret;
end
function DevilSoulEquip:GetGrade()
local ret = 0;
if self.ItemInfo then
ret = self.ItemInfo.Grade;
end
return ret;
end
function DevilSoulEquip:GetPower()
return self.Power;
end
function DevilSoulEquip:CheckLevel(level)
return self.ItemInfo.Level <= level;
end
function DevilSoulEquip: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 DevilSoulEquip: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 DevilSoulEquip: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 DevilSoulEquip:IsValid()
return self.ItemInfo ~= nil
end
---------------------------继承父类接口end--------------------------
function DevilSoulEquip: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 DevilSoulEquip: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 DevilSoulEquip:_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 DevilSoulEquip:_InitContent_()
--定义临时变量,用户回调
end
function DevilSoulEquip:GetCSObj()
return self._SuperObj_;
end
--获取装备的最基本的属性值
function DevilSoulEquip:GetBaseAttribute()
if self.BaseAttrs then
return self.BaseAttrs;
end
return Dictionary:New()
end
--获取装备的特殊属性值
function DevilSoulEquip:GetSpecialAttribute()
if self.SpecialAttrs then
return self.SpecialAttrs;
end
return Dictionary:New()
end
--计算当前装备的属性值
function DevilSoulEquip: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 DevilSoulEquip