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

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