310 lines
11 KiB
Lua
310 lines
11 KiB
Lua
|
------------------------------------------------
|
||
|
--作者: 杨全福
|
||
|
--日期: 2019-06-18
|
||
|
--文件: PetSystem.lua
|
||
|
--模块: PetSystem
|
||
|
--描述: 宠物系统代码
|
||
|
------------------------------------------------
|
||
|
local FightUtils = require "Logic.Base.FightUtils.FightUtils"
|
||
|
local PetSoulInfo = require "Logic.Pet.PetSoulInfo"
|
||
|
local PetInfo = require "Logic.Pet.PetInfo"
|
||
|
local RedPointCustomCondition = CS.Thousandto.Code.Logic.RedPointCustomCondition
|
||
|
local RedPointItemCondition = CS.Thousandto.Code.Logic.RedPointItemCondition
|
||
|
local RedPointTaskCondition = CS.Thousandto.Code.Logic.RedPointTaskCondition
|
||
|
|
||
|
local PetSystem = {
|
||
|
--当前出战的宠物
|
||
|
CurFightPet = 0,
|
||
|
--当前等级
|
||
|
CurLevel = 0,
|
||
|
--当前经验
|
||
|
CurExp = 0,
|
||
|
--当前等级配置
|
||
|
CurLevelCfg = nil,
|
||
|
--当前等级的属性
|
||
|
CurLevelPros = nil,
|
||
|
--下一级的属性
|
||
|
NextLevelPros = nil,
|
||
|
--当前激活的宠物数据
|
||
|
CurActivePets = Dictionary:New(),
|
||
|
--当前御魂的数据
|
||
|
CurSoulLevelList = List:New(),
|
||
|
|
||
|
--宠物总属性 = 等级属性 + 所有宠物的属性
|
||
|
AllProps = nil,
|
||
|
--宠物总战力
|
||
|
AllFightPower = 0,
|
||
|
|
||
|
--属性升级使用的物品列表
|
||
|
ProLevelUseItems = nil,
|
||
|
}
|
||
|
|
||
|
--初始化
|
||
|
function PetSystem:Initialize()
|
||
|
--初始化御魂列表
|
||
|
self.CurSoulLevelList:Clear()
|
||
|
DataConfig.DataPetSoul:Foreach(function(k, v)
|
||
|
self.CurSoulLevelList:Add(PetSoulInfo:New(v))
|
||
|
end)
|
||
|
|
||
|
local _gCfg = DataConfig.DataGlobal[GlobalName.Pet_Levelup_Item_Num]
|
||
|
if _gCfg ~= nil then
|
||
|
self.ProLevelUseItems = Utils.SplitStrByTableS(_gCfg.Params, {';','_'})
|
||
|
end
|
||
|
GameCenter.RegFixEventHandle(LogicEventDefine.EID_EVENT_ONLINE_ITEMINFO, self.SetPetProDetRed, self)
|
||
|
GameCenter.RegFixEventHandle(LogicEventDefine.EVENT_PETLV_ITEM_CHANGE, self.SetPetProDetRed, self)
|
||
|
end
|
||
|
|
||
|
--反初始化
|
||
|
function PetSystem:UnInitialize()
|
||
|
GameCenter.UnRegFixEventHandle(LogicEventDefine.EID_EVENT_ONLINE_ITEMINFO, self.SetPetProDetRed, self)
|
||
|
GameCenter.UnRegFixEventHandle(LogicEventDefine.EVENT_PETLV_ITEM_CHANGE, self.SetPetProDetRed, self)
|
||
|
end
|
||
|
|
||
|
--计算宠物总属性
|
||
|
function PetSystem:CalculateAllProps()
|
||
|
self.CurLevelCfg = DataConfig.DataPetLevel[self.CurLevel]
|
||
|
self.CurLevelPros = Utils.SplitStrByTableS(self.CurLevelCfg.Attribute, {';','_'})
|
||
|
self.NextLevelPros = nil
|
||
|
local _nextCfg = DataConfig.DataPetLevel[self.CurLevel + 1]
|
||
|
if _nextCfg ~= nil then
|
||
|
self.NextLevelPros = Utils.SplitStrByTableS(_nextCfg.Attribute, {';','_'})
|
||
|
end
|
||
|
|
||
|
self.AllProps = {}
|
||
|
--先加上等级属性
|
||
|
self.AllProps = Utils.MergePropTable(self.AllProps, self.CurLevelPros)
|
||
|
--加上宠物本身的所有属性
|
||
|
for k, v in pairs(self.CurActivePets) do
|
||
|
self.AllProps = Utils.MergePropTable(self.AllProps, v.CurAllPros)
|
||
|
end
|
||
|
--加上御魂属性
|
||
|
for i = 1, #self.CurSoulLevelList do
|
||
|
self.AllProps = Utils.MergePropTable(self.AllProps, self.CurSoulLevelList[i].CurPros)
|
||
|
end
|
||
|
self.AllFightPower = FightUtils.GetPropetryPowerByList(self.AllProps)
|
||
|
end
|
||
|
|
||
|
--查找御魂数据
|
||
|
function PetSystem:FindSoulIndfo(soulId)
|
||
|
for i = 1, #self.CurSoulLevelList do
|
||
|
if self.CurSoulLevelList[i].ID == soulId then
|
||
|
return self.CurSoulLevelList[i]
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
--查找宠物数据
|
||
|
function PetSystem:FindActivePetInfo(petId)
|
||
|
return self.CurActivePets[petId]
|
||
|
end
|
||
|
|
||
|
--检测属性升级红点
|
||
|
function PetSystem:CheckProLevelRedPoint()
|
||
|
GameCenter.ItemContianerSystem:ClearItemMsgCondition(FunctionStartIdCode.PetProDet)
|
||
|
self.NeedItemExp = 0
|
||
|
if self.NextLevelPros ~= nil then
|
||
|
--有下一级属性才需要显示红点
|
||
|
if self.ProLevelUseItems ~= nil then
|
||
|
local _items = {}
|
||
|
for i = 1, #self.ProLevelUseItems do
|
||
|
_items[i] = tonumber(self.ProLevelUseItems[i][1])
|
||
|
end
|
||
|
self.NeedItemExp = self.CurLevelCfg.Exp - self.CurExp
|
||
|
GameCenter.ItemContianerSystem:AddItemMsgCondition(LogicEventDefine.EVENT_PETLV_ITEM_CHANGE, _items, FunctionStartIdCode.PetProDet)
|
||
|
end
|
||
|
end
|
||
|
self:SetPetProDetRed()
|
||
|
end
|
||
|
|
||
|
function PetSystem:SetPetProDetRed()
|
||
|
if self.NeedItemExp and self.NeedItemExp > 0 and self.ProLevelUseItems ~= nil then
|
||
|
local _exp = 0
|
||
|
for i = 1, #self.ProLevelUseItems do
|
||
|
local _itemCount = GameCenter.ItemContianerSystem:GetItemCountFromCfgId(tonumber(self.ProLevelUseItems[i][1]))
|
||
|
_exp = _exp + _itemCount * tonumber(self.ProLevelUseItems[i][2])
|
||
|
if _exp >= self.NeedItemExp then
|
||
|
break
|
||
|
end
|
||
|
end
|
||
|
GameCenter.MainFunctionSystem:SetAlertFlag(FunctionStartIdCode.PetProDet, _exp >= self.NeedItemExp)
|
||
|
else
|
||
|
GameCenter.MainFunctionSystem:SetAlertFlag(FunctionStartIdCode.PetProDet, false)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
--检测升级红点
|
||
|
function PetSystem:CheckLevelUPRedPoint()
|
||
|
GameCenter.RedPointSystem:CleraFuncCondition(FunctionStartIdCode.PetLevel)
|
||
|
DataConfig.DataPet:Foreach(function(k, v)
|
||
|
local _petInfo = self:FindActivePetInfo(k)
|
||
|
if _petInfo ~= nil then
|
||
|
--已经激活
|
||
|
if _petInfo.CurLevel < v.MaxDegree then
|
||
|
local _needItemParam = Utils.SplitStr(_petInfo.CurLevelCfg.RankExp, '_')
|
||
|
GameCenter.RedPointSystem:AddFuncCondition(FunctionStartIdCode.PetLevel, k, RedPointItemCondition(tonumber(_needItemParam[1]), tonumber(_needItemParam[2])))
|
||
|
end
|
||
|
else
|
||
|
--未激活
|
||
|
local _ulockParam = Utils.SplitStr(v.Unlock, '_')
|
||
|
local _type = tonumber(_ulockParam[1])
|
||
|
local _value = tonumber(_ulockParam[2])
|
||
|
|
||
|
if _type == 0 then --完成任务
|
||
|
GameCenter.RedPointSystem:AddFuncCondition(FunctionStartIdCode.PetLevel, k, RedPointTaskCondition(_value))
|
||
|
elseif _type == 1 then --前置满阶
|
||
|
local _frontPet = self:FindActivePetInfo(_value)
|
||
|
if _frontPet ~= nil and _frontPet.IsFullDegree then
|
||
|
GameCenter.RedPointSystem:AddFuncCondition(FunctionStartIdCode.PetLevel, k, RedPointCustomCondition(true))
|
||
|
else
|
||
|
GameCenter.RedPointSystem:AddFuncCondition(FunctionStartIdCode.PetLevel, k, RedPointCustomCondition(false))
|
||
|
end
|
||
|
elseif _type == 2 then --消耗道具
|
||
|
GameCenter.RedPointSystem:AddFuncCondition(FunctionStartIdCode.PetLevel, k, RedPointItemCondition(_value, 1))
|
||
|
end
|
||
|
end
|
||
|
end)
|
||
|
end
|
||
|
|
||
|
------------------------------数据请求begin--------------------------
|
||
|
--请求激活宠物
|
||
|
function PetSystem:ReqActivePet(petId)
|
||
|
local _msg = ReqMsg.MSG_Pet.ReqPetAction:New()
|
||
|
_msg.actType = 1
|
||
|
_msg.modelId = petId
|
||
|
_msg:Send()
|
||
|
end
|
||
|
--请求升级宠物
|
||
|
function PetSystem:ReqUpPet(petId)
|
||
|
local _msg = ReqMsg.MSG_Pet.ReqPetAction:New()
|
||
|
_msg.actType = 2
|
||
|
_msg.modelId = petId
|
||
|
_msg:Send()
|
||
|
end
|
||
|
--请求出战宠物
|
||
|
function PetSystem:ReqOutPet(petId)
|
||
|
local _msg = ReqMsg.MSG_Pet.ReqPetAction:New()
|
||
|
_msg.actType = 3
|
||
|
_msg.modelId = petId
|
||
|
_msg:Send()
|
||
|
end
|
||
|
--请求收回宠物
|
||
|
function PetSystem:ReqRestPet(petId)
|
||
|
local _msg = ReqMsg.MSG_Pet.ReqPetAction:New()
|
||
|
_msg.actType = 4
|
||
|
_msg.modelId = petId
|
||
|
_msg:Send()
|
||
|
end
|
||
|
--请求升级
|
||
|
function PetSystem:ReqLevelUP(itemID)
|
||
|
local _msg = ReqMsg.MSG_Pet.ReqEatEquip:New()
|
||
|
_msg.itemId = itemID
|
||
|
_msg:Send()
|
||
|
end
|
||
|
--请求御魂
|
||
|
function PetSystem:ReqEatSoul(soulId)
|
||
|
local _msg = ReqMsg.MSG_Pet.ReqEatSoul:New()
|
||
|
_msg.soulId = soulId
|
||
|
_msg:Send()
|
||
|
end
|
||
|
------------------------------数据请求end--------------------------
|
||
|
|
||
|
------------------------------数据返回begin--------------------------
|
||
|
--发送宠物列表
|
||
|
function PetSystem:ResPetList(msg)
|
||
|
self.HaveFullPet = false
|
||
|
self.CurLevel = msg.curLevel
|
||
|
self.CurExp = msg.curExp
|
||
|
self.CurFightPet = msg.battlePetId
|
||
|
self.CurActivePets:Clear()
|
||
|
if msg.petList ~= nil then
|
||
|
for i = 1, #msg.petList do
|
||
|
local _petCfg = DataConfig.DataPet[msg.petList[i].modelId]
|
||
|
if _petCfg ~= nil then
|
||
|
local _petInfo = PetInfo:New(_petCfg, msg.petList[i].curStage)
|
||
|
if _petInfo.IsFullDegree then
|
||
|
self.HaveFullPet = true
|
||
|
end
|
||
|
self.CurActivePets:Add(_petCfg.Id, _petInfo)
|
||
|
-- if msg.funcOpen then
|
||
|
-- --如果是功能开启,展示宠物获得
|
||
|
-- GameCenter.ModelViewSystem:ShowModel(ShowModelType.Pet, _petCfg.Model, _petCfg.UiScale, _petCfg.GetUiHeight, _petCfg.Name)
|
||
|
-- end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
if msg.soulList ~= nil then
|
||
|
for i = 1, #msg.soulList do
|
||
|
local _soulInfo = self:FindSoulIndfo(msg.soulList[i].soulId)
|
||
|
if _soulInfo ~= nil then
|
||
|
_soulInfo:SetCurLevel(msg.soulList[i].soulLevel)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
if msg.assistantList then
|
||
|
GameCenter.PetEquipSystem:ResPetCellsList(msg.assistantList)
|
||
|
end
|
||
|
GameCenter.PetEquipSystem.IsAutoSplit = msg.autoSet
|
||
|
--重新计算属性
|
||
|
self:CalculateAllProps()
|
||
|
self:CheckProLevelRedPoint()
|
||
|
self:CheckLevelUPRedPoint()
|
||
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_REFRESH_PET_FORM)
|
||
|
end
|
||
|
--同步单个宠物数据
|
||
|
function PetSystem:ResSyncPet(msg)
|
||
|
local _isActive = self.CurActivePets[msg.pet.modelId] ~= nil
|
||
|
local _petCfg = DataConfig.DataPet[msg.pet.modelId]
|
||
|
if _petCfg ~= nil then
|
||
|
local _petInfo = PetInfo:New(_petCfg, msg.pet.curStage)
|
||
|
if _petInfo.IsFullDegree then
|
||
|
self.HaveFullPet = true
|
||
|
end
|
||
|
self.CurActivePets[_petInfo.ID] = _petInfo
|
||
|
end
|
||
|
--重新计算属性
|
||
|
self:CalculateAllProps()
|
||
|
self:CheckLevelUPRedPoint()
|
||
|
if msg.fight and GameCenter.NatureSystem.NaturePetData then
|
||
|
GameCenter.NatureSystem.NaturePetData.super.Fight = msg.fight
|
||
|
end
|
||
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_REFRESH_PET_FORM)
|
||
|
-- if not _isActive then
|
||
|
-- GameCenter.ModelViewSystem:ShowModel(ShowModelType.Pet, _petCfg.Model, _petCfg.UiScale, _petCfg.GetUiHeight, _petCfg.Name)
|
||
|
-- end
|
||
|
end
|
||
|
--同步当前出战的宠物
|
||
|
function PetSystem:ResBattlePet(msg)
|
||
|
self.CurFightPet = msg.battlePetId
|
||
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_REFRESH_PET_FORM)
|
||
|
end
|
||
|
--宠物吃装备返回
|
||
|
function PetSystem:ResEatEquip(msg)
|
||
|
self.CurLevel = msg.curLevel
|
||
|
self.CurExp = msg.curExp
|
||
|
--重新计算属性
|
||
|
self:CalculateAllProps()
|
||
|
self:CheckProLevelRedPoint()
|
||
|
if msg.fight and GameCenter.NatureSystem.NaturePetData then
|
||
|
GameCenter.NatureSystem.NaturePetData.super.Fight = msg.fight
|
||
|
end
|
||
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_REFRESH_PET_FORM)
|
||
|
end
|
||
|
--御魂返回
|
||
|
function PetSystem:ResEatSoul(msg)
|
||
|
local _soulInfo = self:FindSoulIndfo(msg.petSoulInfo.soulId)
|
||
|
if _soulInfo ~= nil then
|
||
|
_soulInfo:SetCurLevel(msg.petSoulInfo.soulLevel)
|
||
|
end
|
||
|
--重新计算属性
|
||
|
self:CalculateAllProps()
|
||
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_REFRESH_PET_FORM)
|
||
|
end
|
||
|
--添加宠物技能到玩家身上
|
||
|
function PetSystem:ResAddPetSkill(msg)
|
||
|
--GameCenter.PlayerSkillSystem:SetPetSkillID(msg.skillId)
|
||
|
end
|
||
|
------------------------------数据返回end--------------------------
|
||
|
|
||
|
return PetSystem
|