修复拾取设置跟存档保存不匹配的问题
This commit is contained in:
parent
fb0cc361cc
commit
7cae7ffc09
@ -28,7 +28,7 @@ function UGCPlayerPawn:ReceivePossessed(NewController)
|
||||
end
|
||||
|
||||
---@return bool 是否开启掉落盒子
|
||||
function UGCPlayerPawn:IsSkipSpawnDeadTombBox(EventInstigater) return DefaultSettings.EnableDeadBox; end
|
||||
function UGCPlayerPawn:IsSkipSpawnDeadTombBox(EventInstigator) return DefaultSettings.EnableDeadBox; end
|
||||
|
||||
----------------------------------------- 玩家伤害处理 -----------------------------------------
|
||||
|
||||
@ -134,10 +134,6 @@ end
|
||||
---@param slot ESurviveWeaponPropSlot
|
||||
---@overload fun(slot:ESurviveWeaponPropSlot) OnEquipWeapon
|
||||
function UGCPlayerPawn:OnEquipWeapon(slot)
|
||||
--UGCLogSystem.Log("[UGCPlayerPawn:OnEquipWeapon] slot = %s, ESurviveWeaponPropSlot.SWPS_HandProp = %d", tostring(slot), ESurviveWeaponPropSlot.SWPS_HandProp);
|
||||
--if slot == ESurviveWeaponPropSlot.SWPS_HandProp then
|
||||
-- UGCLogSystem.Log("[UGCPlayerPawn:OnEquipWeapon] 切换成拳头")
|
||||
--end
|
||||
UGCEventSystem.SendEvent(EventTypes.PlayerChangeWeapon, self, slot, UGCWeaponManagerSystem.GetWeaponBySlot(self, slot));
|
||||
end
|
||||
|
||||
@ -148,15 +144,6 @@ function UGCPlayerPawn:OnPostGetWeapon(Weapon)
|
||||
|
||||
--- 绑定 delegate
|
||||
if ItemTool.IsShootWeapon(Weapon) then
|
||||
--- 客户端
|
||||
--Weapon.OnBulletNumChangeDelegate:Add(function()
|
||||
-- UGCLogSystem.Log("[UGCPlayerPawn:OnPostGetWeapon] 子弹数量改变");
|
||||
--end, self);
|
||||
--
|
||||
--Weapon.OnWeaponShootDelegate:Add(function()
|
||||
-- UGCLogSystem.Log("[UGCPlayerPawn:OnPostGetWeapon] 武器开火")
|
||||
--end, self);
|
||||
|
||||
Weapon.OnDSBulletNumChangeDelegate:Add(self.OnBulletNumChanged, self);
|
||||
end
|
||||
end
|
||||
@ -219,6 +206,30 @@ function UGCPlayerPawn:UpdateSlotWeapons(Weapons)
|
||||
end
|
||||
self:AddAllTelescopes();
|
||||
self:CheckSlotWeapons();
|
||||
|
||||
self:ResetAllParts();
|
||||
end
|
||||
|
||||
UGCPlayerPawn.ResetPartsTimer = nil;
|
||||
|
||||
--- 重新设置所有的配件
|
||||
function UGCPlayerPawn:ResetAllParts()
|
||||
if self.ResetPartsTimer then
|
||||
Timer.RemoveTimer(self.ResetPartsTimer);
|
||||
self.ResetPartsTimer = nil;
|
||||
end
|
||||
self.ResetPartsTimer = Timer.InsertTimer(1, function()
|
||||
for i, Socket in pairs(ShootWeaponEnums) do
|
||||
local Weapon = UGCWeaponManagerSystem.GetWeaponBySlot(self, Socket);
|
||||
if Weapon ~= nil and UE.IsValid(Weapon) and ItemTool.IsShootWeapon(Weapon) then
|
||||
local WeaponID = Weapon:GetWeaponItemID();
|
||||
local CurrMap = ItemTool.GetWeaponPartMap(Weapon);
|
||||
local TrueConfig = ArchiveTable[self.PlayerKey].Weapons[WeaponID]
|
||||
ItemTool.ReuseWeaponParts(Weapon, TrueConfig);
|
||||
end
|
||||
end
|
||||
self.ResetPartsTimer = nil;
|
||||
end);
|
||||
end
|
||||
|
||||
function UGCPlayerPawn:AddAllTelescopes()
|
||||
@ -268,6 +279,7 @@ function UGCPlayerPawn:CheckHasSlotWeapon(Slot, WeaponID)
|
||||
local DefineID = Weapon:GetItemDefineID();
|
||||
ItemTool.RemoveWeapon(self, Weapon);
|
||||
ItemTool.AddWeaponItem(self, WeaponID, 1, true, EFillBulletType.ClipInfinite);
|
||||
self:ResetAllParts();
|
||||
end
|
||||
|
||||
UGCPlayerPawn.CurrBulletNum = -1;
|
||||
|
@ -1,185 +0,0 @@
|
||||
require('Script.Global.Table.WeaponTable')
|
||||
--- 用到的都放在这
|
||||
MiniGameMapType = {
|
||||
SoloKing = 1, -- 和平大乱斗模式
|
||||
};
|
||||
|
||||
--- 是否随机地图
|
||||
Mini_RandomMap = false;
|
||||
|
||||
--- 整体进程
|
||||
---@type MiniGameState
|
||||
MiniGameState = {
|
||||
NON_START = 1, -- 还未开始
|
||||
SELECT_GAMES = 2, -- 选择地图截断
|
||||
MINI_PREPARE = 3, -- 玩法准备阶段
|
||||
--MINI_GAMING = 4, -- 进入玩法游戏阶段
|
||||
ROUND_PREPARE = 4, -- 回合准备阶段
|
||||
ROUND_GAMING = 5, -- 回合游玩阶段
|
||||
ROUND_END = 6, -- 回合结束阶段
|
||||
MINI_END = 7, -- 玩法结束阶段
|
||||
ENDED = 8, -- 游戏结束阶段
|
||||
};
|
||||
|
||||
--- 小游戏的各种时间
|
||||
MiniGameTimes = {
|
||||
Active = 1, -- 游戏激活时间,游戏激活时间结束后进入游戏阶段
|
||||
Prepare = 35, -- 每个玩法准备时间
|
||||
RoundPrepare = 2, -- 玩法单个回合开启时间到正式开启时间
|
||||
RoundGameTime = -4 * 60,
|
||||
RoundEnd = 5, -- 玩法单个回合结束到下一个回合开启的时间
|
||||
MiniGameEnd = 0, -- 一个玩法结束的时候到下一个小游戏或者游戏结束的时间
|
||||
End = 200; -- 结束的时候执行
|
||||
};
|
||||
|
||||
GameStateTimes = {
|
||||
GangUp = {
|
||||
SelectMapTime = 12;
|
||||
}
|
||||
}
|
||||
|
||||
--- 玩法配置
|
||||
--- 可以重写玩法的时间:在单个玩法配置中添加 MiniGameTimes = { Prepare = xxx, } 这种形式即可
|
||||
MiniGameConfig = MiniGameConfig or {
|
||||
[MiniGameMapType.SoloKing] = {
|
||||
Script = "Solo", -- 会执行的代码文件
|
||||
Map = {
|
||||
-- 按热度排序
|
||||
MapName = {
|
||||
['Map_SLXLC'] = 1,
|
||||
['Map_SMDJ'] = 1,
|
||||
['Map_HDDJ'] = 1,
|
||||
['Map_JCK'] = 1,
|
||||
['Map_DBL'] = 1,
|
||||
['Map_SCL'] = 1,
|
||||
['Map_NewYear'] = 2,
|
||||
['Map_DC'] = 2,
|
||||
},
|
||||
ShowName = "单挑王", -- 显示名称
|
||||
},
|
||||
--- 小游戏回合次数,如果 <= 1 表示当前游戏只支持单局,且条件为自动设置。
|
||||
RoundTimes = 7,
|
||||
--- 初始给的武器,下面每一条都是要添加的一个初始物品
|
||||
InitArmors = {
|
||||
[1] = EArmorType.Armor3,
|
||||
[2] = EHelmetType.Helmet3,
|
||||
[3] = EBagType.Bag1,
|
||||
},
|
||||
InitMedication = {
|
||||
{ "大包", 1, }, -- 10
|
||||
{ "绷带", 5, }, -- 2 * Num
|
||||
{ "可乐", 3, }, -- 4 * Num
|
||||
},
|
||||
--- 延迟一会后再给的物品
|
||||
DelayWeapons = {
|
||||
{ "手榴弹", 1, }, -- 18
|
||||
{ "烟雾弹", 1, }, -- 14
|
||||
{ "震爆弹", 1, }, -- 14
|
||||
},
|
||||
|
||||
--- 地图新增物品
|
||||
MapAddedItem = {
|
||||
['Map_JCK'] = {
|
||||
{ "燃烧瓶", 1 },
|
||||
},
|
||||
['Map_DBL'] = {
|
||||
{ "燃烧瓶", 1 },
|
||||
},
|
||||
['Map_SCL'] = {
|
||||
{ "燃烧瓶", 1 },
|
||||
},
|
||||
},
|
||||
|
||||
--- 游戏参数,会自动展开,如果想要表结构,需要再嵌套一层表
|
||||
Params = {
|
||||
SelectWeaponCount = 7, -- 可以选择武器的个数
|
||||
RespawnTime = 2, -- 玩家复活的时间,现在用不到
|
||||
KillHealing = 0, -- 击杀可以回复的血量
|
||||
KillTimes = 2, -- 击杀多少次当前回合
|
||||
ResetTime = 3, -- 重置时间
|
||||
SelectMapTime = 8, -- 选择地图时间,正式开始前这么长时间就不允许再选择了
|
||||
|
||||
EnableInsult = false; -- 是否开启鞭尸
|
||||
|
||||
DefaultWeapon = 101004, -- 默认初始武器
|
||||
|
||||
--- 加分方式
|
||||
AddFunc = function(Diff, Current, NeedOther)
|
||||
local Add = 20 - Diff / 100;
|
||||
Add = math.ceil(Add);
|
||||
if Add < 5 then Add = 5; end
|
||||
if Add > 30 then Add = 30; end
|
||||
|
||||
if NeedOther then
|
||||
if Current < 2200 then
|
||||
Add = Add + math.random(4, 5);
|
||||
elseif Current < 3000 then
|
||||
Add = Add + math.random(1, 2);
|
||||
--else
|
||||
-- Add = Add + math.random(0, 1);
|
||||
end
|
||||
end
|
||||
return Add;
|
||||
end,
|
||||
|
||||
--- 扣分方式
|
||||
ReduceFunc = function(Diff, Current)
|
||||
local Reduce = -20 + Diff / 100;
|
||||
Reduce = math.floor(Reduce);
|
||||
if Reduce > -5 then Reduce = -5 end
|
||||
if Reduce < -30 then Reduce = -30; end
|
||||
return Reduce;
|
||||
end,
|
||||
|
||||
SpecialWeapon = {
|
||||
[EWeaponTypeNew.EWeaponTypeNew_SingleShotSniper] = {
|
||||
InitArmors = {
|
||||
[1] = EArmorType.Armor2,
|
||||
[2] = EHelmetType.Helmet2,
|
||||
},
|
||||
},
|
||||
[EWeaponTypeNew.EWeaponTypeNew_Crossbow] = {
|
||||
InitArmors = {
|
||||
[1] = EArmorType.Armor2,
|
||||
[2] = EHelmetType.Helmet2,
|
||||
},
|
||||
},
|
||||
[EWeaponTypeNew.EWeaponTypeNew_Melee] = {
|
||||
InitArmors = {
|
||||
[1] = EArmorType.Armor1,
|
||||
[2] = EHelmetType.Helmet1,
|
||||
},
|
||||
},
|
||||
}
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
GameModeConfig = {}
|
||||
-- 由于顺序问题 这里不可以跳数字
|
||||
GameModeConfig.EGameModeType = {
|
||||
DefaultMode = 1;
|
||||
GangUpMode = 2; -- 休闲模式
|
||||
};
|
||||
|
||||
GameModeConfig.GameModeInfo = {
|
||||
[GameModeConfig.EGameModeType.DefaultMode] = {
|
||||
Name = "经典模式";
|
||||
Feature = "·经典和平,双方武器一致。\n·武器从武器池中随机抽取。";
|
||||
},
|
||||
[GameModeConfig.EGameModeType.GangUpMode] = {
|
||||
Name = "休闲模式";
|
||||
Feature = "·回合武器可自选!\n·不掉分!";
|
||||
-- 时间配置
|
||||
MiniGameTimes = {
|
||||
Active = 2, -- 游戏激活时间,游戏激活时间结束后进入游戏阶段
|
||||
Prepare = 15, -- 每个玩法准备时间
|
||||
RoundPrepare = 2, -- 玩法单个回合开启时间到正式开启时间
|
||||
RoundEnd = 5, -- 玩法单个回合结束到下一个回合开启的时间
|
||||
MiniGameEnd = 0, -- 一个玩法结束的时候到下一个小游戏或者游戏结束的时间
|
||||
End = 50; -- 结束的时候执行
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return MiniGameConfig;
|
@ -1,821 +0,0 @@
|
||||
MiniManager = {};
|
||||
|
||||
---@private string 这是玩家选择的地图,按从前往后开始游玩
|
||||
MiniManager.ScriptPath = "Script.Global.Mini.Script.Mini_";
|
||||
---@type table<int32, FMiniGameMapIndex> 当前所有玩家选择的地图
|
||||
MiniManager.SelectMaps = {};
|
||||
---@type FMiniGameMapIndex 当前选择的地图
|
||||
MiniManager.CurrSelectMap = nil;
|
||||
---@type UGCGameState_C 默认是 GameSate,如果不是可以在具体实例里面实现对应方法
|
||||
MiniManager.Owner = nil;
|
||||
---@type MiniGameMode 当前小玩法的具体实现,统一入口出口管理
|
||||
MiniManager.CurrMiniMode = nil;
|
||||
---@type int32 目标小游戏数量,低于这个数量会自动添加到这个数量
|
||||
MiniManager.TargetMiniGameCount = 1;
|
||||
---@type MiniGameState 模式状态,可以在本实例和 CurrMiniMode 中获取
|
||||
MiniManager.State = 0;
|
||||
---@type table<PlayerKey, MiniGamePlayerDataItem> 玩家数据
|
||||
MiniManager.PlayerData = {};
|
||||
---@type table<int32, any> 小游戏需要同步的数据,会自动执行 OnRep_xxx 函数
|
||||
MiniManager.MiniInfo = {};
|
||||
|
||||
MiniManager.TimerHandlers = nil;
|
||||
|
||||
----------------------------------- 主要函数 -----------------------------------
|
||||
|
||||
--- 这是游戏启动,做一些初始化的操作即可
|
||||
function MiniManager:Init(InOwner)
|
||||
UGCLogSystem.Log("[MiniManager:ReceiveBeginPlay] 执行成功 self = %s", tostring(self));
|
||||
self.Owner = InOwner;
|
||||
if MiniGameConfig == nil then
|
||||
require('Script.Global.Mini.MiniGameConfig');
|
||||
UGCLogSystem.LogTree(string.format("[MiniManager:Init] MiniGameConfig ="), MiniGameConfig);
|
||||
end
|
||||
if DefaultSettings.EnableTest then
|
||||
for i, v in pairs(MiniGameConfig) do
|
||||
v.RoundTimes = 1;
|
||||
end
|
||||
|
||||
MiniGameTimes.RoundGameTime = -500;
|
||||
end
|
||||
UGCEventSystem.AddListener(EventTypes.ClientAlready, self.OnClientAlready, self)
|
||||
|
||||
if IsServer then
|
||||
self:SetState(MiniGameState.SELECT_GAMES);
|
||||
|
||||
GlobalTickTool:AddInternalCount(self, function(o, dt, ServerTime, t)
|
||||
o:OnMiniGameTimeCount(t);
|
||||
end, 1, MiniGameTimes.Active, self.OnGameStart);
|
||||
else
|
||||
-- 执行客户端逻辑
|
||||
self:MakeCachedMiniInfo();
|
||||
end
|
||||
|
||||
-- 组装一下具体函数
|
||||
self:MakeRepProps();
|
||||
end
|
||||
|
||||
function MiniManager:MakeRepProps()
|
||||
local Func = function(...) return { ... }; end
|
||||
local Props = Func(self:GetReplicatedProperties());
|
||||
if self.Props == nil then self.Props = {}; end
|
||||
for i, v in pairs(Props) do self.Props[v] = true; end
|
||||
UGCLogSystem.LogTree(string.format("[MiniManager:MakeRepProps] self.Props ="), self.Props);
|
||||
end
|
||||
|
||||
function MiniManager:IsRepProp(InName)
|
||||
if self.Props == nil then self.Props = {}; end
|
||||
return self.Props[InName] == true;
|
||||
end
|
||||
|
||||
--- 本身需要同步的数据放进来
|
||||
function MiniManager:GetReplicatedProperties()
|
||||
return "State"
|
||||
, "SelectMaps"
|
||||
, "CurrSelectMap"
|
||||
end
|
||||
|
||||
--- 客户端准备好了,此时开始有 ServerTime
|
||||
function MiniManager:OnClientAlready()
|
||||
-- 显示
|
||||
if IsClient then
|
||||
UGCLogSystem.Log("[MiniManager:OnGameBegin] 显示 UI")
|
||||
end
|
||||
|
||||
table.func(self.CurrMiniMode, "OnClientAlready")
|
||||
end
|
||||
|
||||
--- UI已经准备好了
|
||||
function MiniManager:OnUIAlready()
|
||||
table.func(self.CurrMiniMode, "OnUIAlready")
|
||||
end
|
||||
|
||||
--- 准备结束
|
||||
function MiniManager:OnPrepareEnd()
|
||||
if IsServer then
|
||||
UGCLogSystem.Log("[MiniManager:OnPrepareEnd] 执行")
|
||||
self:SetMiniInfo();
|
||||
UGCGameSystem.SendModeCustomEvent("CheckPlayers");
|
||||
end
|
||||
table.func(self.CurrMiniMode, "OnPrepareEnd")
|
||||
self:OnMiniRoundPrepare();
|
||||
end
|
||||
|
||||
function MiniManager:SendRPC(InRPCName, ...)
|
||||
UGCLogSystem.Log("[MiniManager:SendRPC] InRPCName = %s", InRPCName);
|
||||
self.Owner:SendMiniGameRPC(InRPCName, ...);
|
||||
end
|
||||
|
||||
--- 在游戏进行之前执行
|
||||
---@param InTime int32 从游戏开始到游戏正式开始的倒计时
|
||||
function MiniManager:OnBeforeGameStart(InTime)
|
||||
UGCLogSystem.Log("[MiniManager:OnBeforeGameStart] InTime = %s", tostring(InTime));
|
||||
if InTime == 1 then
|
||||
-- 玩家死亡重生
|
||||
UE.ResetGame1(0.5, function()
|
||||
GameState:ResetKill();
|
||||
end);
|
||||
end
|
||||
end
|
||||
|
||||
--- 游戏正式开始
|
||||
function MiniManager:OnGameStart()
|
||||
UGCLogSystem.Log("[MiniManager:OnGameStart] 执行")
|
||||
if IsServer then
|
||||
-- 检查当前选择的地图是否小于对应数量,如果小于,那么就随机选择为选择的
|
||||
-- 获取选择了的
|
||||
for i, v in pairs(MiniGameConfig) do
|
||||
table.insert(self.SelectMaps, i);
|
||||
end
|
||||
UGCLogSystem.LogTree(string.format("[MiniManager:OnGameStart] SelectMaps ="), self.SelectMaps)
|
||||
-- 表示如果第一个加载不成,那么就依次完后加载,直到全部加载都不行
|
||||
local bSuccess = false;
|
||||
repeat bSuccess = self:LoadMiniGame() until bSuccess or table.isEmpty(self.SelectMaps);
|
||||
if not bSuccess then
|
||||
UGCLogSystem.Log("[MiniManager:OnGameStart] 游戏结束")
|
||||
self:OnGameEnd();
|
||||
end
|
||||
else
|
||||
WidgetManager:ShowPanel(WidgetConfig.EUIType.Main, false);
|
||||
end
|
||||
end
|
||||
|
||||
function MiniManager:OnGameEnd()
|
||||
UGCLogSystem.Log("[MiniManager:OnGameEnd] 游戏结束")
|
||||
if IsServer then
|
||||
self:SetState(MiniGameState.ENDED);
|
||||
LuaQuickFireEvent("GameEnd", GameState);
|
||||
else
|
||||
-- 显示结算界面
|
||||
UGCLogSystem.Log("[MiniManager:OnGameEnd] GameWinner = %s", tostring(self.MiniInfo.GameWinner));
|
||||
UGCLogSystem.LogTree(string.format("[MiniManager:OnGameEnd] RoundWinners ="), self.MiniInfo.RoundWinners)
|
||||
SoloKingGameWinner = self.MiniInfo.GameWinner;
|
||||
SoloKingRoundWinner = self.MiniInfo.RoundWinners;
|
||||
UGCLogSystem.Log("[MiniManager:OnGameEnd] 显示 GameEnd 界面");
|
||||
if not WidgetManager:IsVisiblePanel(WidgetConfig.EUIType.GameEnd) then
|
||||
WidgetManager:ShowPanel(WidgetConfig.EUIType.GameEnd, false, self.MiniInfo.GameWinner, self.MiniInfo.RoundWinners);
|
||||
WidgetManager:ClosePanel(WidgetConfig.EUIType.Main);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param InMiniType MiniGameMapType Mini 游戏类型,只会在客户端存在
|
||||
function MiniManager:LoadMiniGame(InMiniType)
|
||||
if MiniGameConfig == nil then
|
||||
require('Script.Global.Mini.MiniGameConfig');
|
||||
end
|
||||
if IsServer then
|
||||
self:SetState(MiniGameState.MINI_PREPARE);
|
||||
self:AllPlayerDead();
|
||||
UGCLogSystem.Log("[MiniManager:LoadMiniGame] 执行")
|
||||
if table.isEmpty(self.SelectMaps) then return false; end
|
||||
UGCLogSystem.Log("[MiniManager:LoadMiniGame] 开始执行流程")
|
||||
self.CurrSelectMap = self.SelectMaps[1];
|
||||
if self.CurrSelectMap == nil then return false; end
|
||||
table.remove(self.SelectMaps, 1);
|
||||
-- 加载 CurrMiniMode
|
||||
UGCLogSystem.Log("[MiniManager:LoadMiniGame] 加载 Mini Mode")
|
||||
self.CurrMiniMode = require(self.ScriptPath .. MiniGameConfig[self.CurrSelectMap].Script);
|
||||
if self.CurrMiniMode == nil then return false; end
|
||||
if not table.func(self.CurrMiniMode, "Init", self) then return false; end
|
||||
-- 发送到客户端表示当前已经同步了
|
||||
self.Owner:SelectMiniType(self.CurrSelectMap);
|
||||
UGCLogSystem.Log("[MiniManager:LoadMiniGame] Mini Mode 加载成功")
|
||||
self:CurrMiniModeInit();
|
||||
if self.CurrMiniMode.RoundTimes == nil then self.CurrMiniMode.RoundTimes = 1; end
|
||||
self:SetRoundTimes(self.CurrMiniMode.RoundTimes);
|
||||
-- 这个是玩法的小局准备
|
||||
local Times = MiniGameConfig[self.CurrSelectMap].MiniGameTimes
|
||||
local Time = 0;
|
||||
if Times ~= nil and Times.Prepare ~= nil then
|
||||
Time = Times.Prepare;
|
||||
else
|
||||
Time = MiniGameTimes.Prepare;
|
||||
end
|
||||
UGCLogSystem.Log("[MiniManager:LoadMiniGame] Time = %s", tostring(Time))
|
||||
self.TimerHandlers = GlobalTickTool:AddInternalCount(self, function(o, dt, ServerTime, t)
|
||||
UGCLogSystem.Log("[MiniManager:LoadMiniGame] Time Internal = %s", tostring(t));
|
||||
o:OnMiniGameTimeCount(t);
|
||||
end, 1, Time, self.OnPrepareEnd);
|
||||
|
||||
UGCLogSystem.Log("[MiniManager:LoadMiniGame] 全部加载完成")
|
||||
return true;
|
||||
else
|
||||
UGCLogSystem.Log("[MiniManager:LoadMiniGame] 客户端加载")
|
||||
self.CurrSelectMap = InMiniType;
|
||||
self.CurrMiniMode = require(self.ScriptPath .. MiniGameConfig[self.CurrSelectMap].Script);
|
||||
if self.CurrMiniMode == nil then return ; end
|
||||
table.func(self.CurrMiniMode, "Init", self);
|
||||
self:CurrMiniModeInit();
|
||||
-- 检查是否有数据啊
|
||||
if UGCGameSystem.GameState then
|
||||
UGCGameSystem.GameState:OnRep_MiniInfo();
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- 服务器客户端初始化的共同操作
|
||||
function MiniManager:CurrMiniModeInit()
|
||||
--- 默认设置一些变量供使用或者驱动
|
||||
self.CurrMiniMode.Owner = self;
|
||||
self.CurrMiniMode.MapIndex = self.CurrSelectMap;
|
||||
self.CurrMiniMode.CreateTime = UE.GetServerTime();
|
||||
self.CurrMiniMode.bGameEnd = false;
|
||||
self.CurrMiniMode.bRoundEnd = false;
|
||||
self.CurrMiniMode.RoundTimes = MiniGameConfig[self.CurrSelectMap].RoundTimes; -- 当前回合数
|
||||
self.CurrMiniMode.TotalRoundTimes = MiniGameConfig[self.CurrSelectMap].RoundTimes; -- 总回合数
|
||||
self.CurrMiniMode.bCanRespawn = MiniGameConfig[self.CurrSelectMap].bCanRespawn; -- 是否可以重生
|
||||
GlobalMiniType = self.CurrSelectMap;
|
||||
GlobalMiniMode = self.CurrMiniMode
|
||||
|
||||
for i, v in pairs(self.MiniInfo) do
|
||||
if type(v) == 'table' then
|
||||
self.CurrMiniMode[i] = TableHelper.DeepCopyTable(v);
|
||||
else
|
||||
self.CurrMiniMode[i] = v;
|
||||
end
|
||||
end
|
||||
|
||||
if not table.isEmpty(MiniGameConfig[self.CurrSelectMap].Params) then
|
||||
for i, v in pairs(MiniGameConfig[self.CurrSelectMap].Params) do self.CurrMiniMode[i] = v; end
|
||||
end
|
||||
|
||||
UGCLogSystem.Log("[MiniManager:CurrMiniModeInit] 开始加载地图")
|
||||
-- 加载 Tick
|
||||
GlobalTickTool:AddTick(self.CurrMiniMode, self.CurrMiniMode.OnTick, nil, function(o)
|
||||
return not (o.bEnableTick == false);
|
||||
end);
|
||||
-- 进入准备
|
||||
table.func(self.CurrMiniMode, "OnPrepare");
|
||||
end
|
||||
|
||||
function MiniManager:UnLoadMiniGame()
|
||||
-- 先取消上一个的
|
||||
if IsServer then
|
||||
if self.CurrMiniMode ~= nil then
|
||||
GlobalTickTool:RemoveTickByOwner(self.CurrMiniMode);
|
||||
-- 然后赶紧除去地图并且加载
|
||||
self:UnLoadMap();
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function MiniManager:OnMiniGameTimeCount(InVal)
|
||||
if IsServer then
|
||||
if InVal == nil then InVal = 0; end
|
||||
InVal = math.floor(InVal);
|
||||
--- 执行
|
||||
GameState:OnGameProgress_Tick(InVal);
|
||||
end
|
||||
if self.CurrMiniMode then
|
||||
self.CurrMiniMode.CurrTimeCount = InVal;
|
||||
end
|
||||
table.func(self.CurrMiniMode, "OnCountTime", InVal)
|
||||
end
|
||||
|
||||
function MiniManager:OnMiniGameEnd()
|
||||
UGCLogSystem.Log("[MiniManager:OnMiniGameEnd] ")
|
||||
local Times = MiniGameConfig[self.CurrSelectMap].MiniGameTimes;
|
||||
local Time = 0;
|
||||
if Times and Times.MiniGameEnd then
|
||||
Time = Times.MiniGameEnd;
|
||||
else
|
||||
Time = MiniGameTimes.MiniGameEnd;
|
||||
end
|
||||
-- 从小局中取出来
|
||||
GlobalTickTool:AddInternalCount(self, function(o, dt, ServerTime, t)
|
||||
o:OnMiniGameTimeCount(t);
|
||||
end, 1, Time, self.OnMiniGameSwitch);
|
||||
self:SetState(MiniGameState.MINI_END);
|
||||
self.MiniInfo.Scores = table.func(self.CurrMiniMode, "GetScore")
|
||||
self.MiniInfo.Winner = self.CurrMiniMode.GameWinner;
|
||||
table.func(self.CurrMiniMode, "OnGameEnd", self.MiniInfo.Scores);
|
||||
self:SetMiniInfo();
|
||||
end
|
||||
|
||||
function MiniManager:ClearMiniMode()
|
||||
UGCLogSystem.Log("[MiniManager:ClearMiniMode] 执行销毁")
|
||||
self.PlayerData = nil;
|
||||
self.SelectMaps = nil;
|
||||
end
|
||||
|
||||
--- 切换到下一个 MiniGame
|
||||
function MiniManager:OnMiniGameSwitch()
|
||||
-- 检查是否还有下一个了
|
||||
UGCLogSystem.Log("[MiniManager:OnMiniGameSwitch] 执行")
|
||||
if table.isEmpty(self.SelectMaps) then
|
||||
self:OnGameEnd();
|
||||
return ;
|
||||
end
|
||||
self:UnLoadMiniGame();
|
||||
self:LoadMiniGame();
|
||||
end
|
||||
|
||||
function MiniManager:SetState(InState)
|
||||
if IsServer then
|
||||
UGCLogSystem.Log("[MiniManager:SetState] CurrState = %s", TableHelper.printEnum(MiniGameState, InState));
|
||||
self.State = InState;
|
||||
self.MiniInfo.State = InState;
|
||||
self:SetMiniInfo();
|
||||
table.func(self.CurrMiniMode, 'SetState', InState);
|
||||
if self.CurrMiniMode ~= nil then
|
||||
self.CurrMiniMode.State = InState;
|
||||
end
|
||||
GameState:SetMiniState(InState);
|
||||
end
|
||||
-- 全局的状态
|
||||
GlobalMiniState = self.State;
|
||||
end
|
||||
|
||||
function MiniManager:SetRoundTimes(InTimes)
|
||||
if IsServer then
|
||||
self.MiniInfo.RoundTimes = InTimes;
|
||||
self:SetMiniInfo();
|
||||
if self.CurrMiniMode ~= nil then
|
||||
self.CurrMiniMode.RoundTimes = InTimes;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function MiniManager:OnRep_RoundTimes(InOld)
|
||||
if self.CurrMiniMode ~= nil then
|
||||
self.CurrMiniMode.RoundTimes = self.MiniInfo.RoundTimes;
|
||||
end
|
||||
end
|
||||
|
||||
function MiniManager:OnRep_State(InOld)
|
||||
UGCLogSystem.Log("[MiniManager:OnRep_State] self.State = %s, StateName = %s", tostring(self.MiniInfo.State), TableHelper.printEnum(MiniGameState, self.State));
|
||||
self.State = self.MiniInfo.State;
|
||||
--if self.CurrMiniMode then
|
||||
-- self.CurrMiniMode.State = self.State;
|
||||
--end
|
||||
UGCEventSystem.SendEvent(EventTypes.MiniStateChange, self.State);
|
||||
if self.State == MiniGameState.MINI_PREPARE then
|
||||
elseif self.State == MiniGameState.ROUND_PREPARE then
|
||||
self:OnPrepareEnd();
|
||||
elseif self.State == MiniGameState.ROUND_GAMING then
|
||||
self:OnMiniRoundFormalStart();
|
||||
elseif self.State == MiniGameState.ROUND_END then
|
||||
self:OnMiniRoundEnd();
|
||||
elseif self.State == MiniGameState.MINI_END then
|
||||
self:OnMiniGameEnd();
|
||||
elseif self.State == MiniGameState.ENDED then
|
||||
self:OnGameEnd();
|
||||
end
|
||||
GlobalMiniState = self.State;
|
||||
end
|
||||
|
||||
--- 设置同步 MiniInfo,
|
||||
function MiniManager:SetMiniInfo()
|
||||
self.Owner:SetMiniInfo(self.MiniInfo);
|
||||
end
|
||||
|
||||
--- 设置游戏数据
|
||||
---@vararg
|
||||
function MiniManager:SetGameInfo(InName, InInfo)
|
||||
UGCLogSystem.LogTree(string.format("[MiniManager:SetGameInfo] InInfo ="), InInfo)
|
||||
if type(InInfo) == 'table' then
|
||||
self.MiniInfo[InName] = TableHelper.DeepCopyTable(InInfo);
|
||||
else
|
||||
self.MiniInfo[InName] = InInfo;
|
||||
end
|
||||
self:SetMiniInfo();
|
||||
end
|
||||
|
||||
-- 给予子模块的数据同步
|
||||
function MiniManager:DOREPONCE(Name)
|
||||
if self.CurrMiniMode then
|
||||
self:SetGameInfo(Name, self.CurrMiniMode[Name]);
|
||||
end
|
||||
end
|
||||
|
||||
----------------------------------- 地图函数 -----------------------------------
|
||||
|
||||
MiniManager.CurrLoadMapName = nil;
|
||||
|
||||
function MiniManager:RandomSelectMap()
|
||||
local MapNames = MiniGameConfig[self.CurrSelectMap].Map.MapName;
|
||||
local MapName = "";
|
||||
if type(MapNames) == 'table' then
|
||||
local Total = 0;
|
||||
local Maps = {};
|
||||
for Name, Rate in pairs(MapNames) do
|
||||
if type(Name) == 'string' then
|
||||
Total = Total + Rate;
|
||||
table.insert(Maps, {
|
||||
Name = Name,
|
||||
Rate = Rate,
|
||||
});
|
||||
elseif type(Name) == 'int32' then
|
||||
Total = Total + 1;
|
||||
table.insert(Maps, {
|
||||
Name = Rate,
|
||||
Rate = 1,
|
||||
})
|
||||
end
|
||||
end
|
||||
local MapCount = table.getCount(Maps);
|
||||
if Total == 0 then
|
||||
-- 从这两个中随机一个
|
||||
MapName = Maps[math.random(MapCount)].Name;
|
||||
else
|
||||
local Num = KismetMathLibrary.RandomFloat()
|
||||
local RandomNum = Num * Total;
|
||||
for i = 1, table.getCount(Maps) do
|
||||
RandomNum = RandomNum - Maps[i].Rate;
|
||||
if RandomNum <= 0 then
|
||||
MapName = Maps[i].Name;
|
||||
break ;
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif type(MapNames) == 'string' then
|
||||
MapName = MapNames;
|
||||
end
|
||||
return MapName;
|
||||
end
|
||||
|
||||
--- 加载地图
|
||||
function MiniManager:LoadMap(InIndex)
|
||||
UGCLogSystem.Log("[MiniManager:LoadMap] 执行")
|
||||
if InIndex == nil then InIndex = self.CurrSelectMap end
|
||||
if self.HadLoadMap == InIndex then return ; end
|
||||
-- 检查当前是什么东西,如果是随机的话
|
||||
local MapName = table.func(self.CurrMiniMode, "SelectMapName", InIndex);
|
||||
if MapName == nil or string.len(MapName) == 0 then
|
||||
MapName = self:RandomSelectMap();
|
||||
end
|
||||
|
||||
UGCLogSystem.Log("[MiniManager:LoadMap] LoadMap = %s", MapName);
|
||||
|
||||
self.CurrLoadMapName = MapName;
|
||||
UGCLogSystem.Log("[MiniManager:LoadMap] 执行 END");
|
||||
self.Owner:LoadMap(MapName);
|
||||
self.HadLoadMap = InIndex;
|
||||
end
|
||||
|
||||
--- 完成加载地图
|
||||
function MiniManager:OnMapLoadComplete()
|
||||
UGCLogSystem.Log("[MiniManager:OnMapLoadComplete] 地图加载完成")
|
||||
if IsServer then
|
||||
UE.ResetGame(0.5);
|
||||
end
|
||||
self:OnMapLoaded();
|
||||
end
|
||||
|
||||
--- 加载地图
|
||||
function MiniManager:OnMapLoaded()
|
||||
UGCLogSystem.Log("[MiniManager:OnMapLoaded] 加载地图成功")
|
||||
table.func(self.CurrMiniMode, "OnAlready");
|
||||
end
|
||||
|
||||
--- 卸载地图
|
||||
function MiniManager:UnLoadMap()
|
||||
-- 然后过一会再重新加载地图
|
||||
self.Owner:UnloadMap({ self.CurrLoadMapName });
|
||||
self.HadLoadMap = nil;
|
||||
end
|
||||
|
||||
function MiniManager:OnMapUnLoadedComplete()
|
||||
UGCLogSystem.Log("[MiniManager:OnMapUnLoadedComplete] 异步卸载地图完成")
|
||||
end
|
||||
|
||||
--- 玩家选择地图
|
||||
function MiniManager:OnPlayerSelectMap(InPlayer, InMapIndex)
|
||||
if IsServer then
|
||||
table.insert(self.SelectMaps, InMapIndex);
|
||||
-- 发送 RPC
|
||||
self:SendRPC("OnPlayerSelectMap", self.SelectMaps)
|
||||
else
|
||||
UGCEventSystem.SendEvent(EventTypes.MiniGame_SelectMap, self.SelectMaps);
|
||||
end
|
||||
end
|
||||
|
||||
----------------------------------- 回合函数 -----------------------------------
|
||||
--- 开启小局
|
||||
function MiniManager:OnMiniRoundPrepare()
|
||||
-- 小局次数 - 1
|
||||
if IsServer then
|
||||
self:LoadMap(self.CurrSelectMap);
|
||||
local Times = MiniGameConfig[self.CurrSelectMap].MiniGameTimes;
|
||||
local Time = (Times == nil or Times.Prepare == nil) and MiniGameTimes.RoundPrepare or Times.Prepare;
|
||||
GlobalTickTool:AddInternalCount(self, function(o, dt, ServerTime, t)
|
||||
local InTime = t;
|
||||
if Time > 0 then InTime = Time - t end
|
||||
o:OnMiniGameTimeCount(InTime)
|
||||
self:OnBeforeGameStart(t);
|
||||
end, 1, Time, self.OnMiniRoundFormalStart);
|
||||
self.CurrMiniMode.RoundTimes = self.CurrMiniMode.RoundTimes - 1;
|
||||
self.CurrMiniMode.bRoundEnd = false;
|
||||
self:SetState(MiniGameState.ROUND_PREPARE);
|
||||
self:SetRoundTimes(self.CurrMiniMode.RoundTimes);
|
||||
else
|
||||
-- 看看是否要执行什么
|
||||
end
|
||||
table.func(self.CurrMiniMode, "OnRoundStart", self:GetCurrRoundTimes());
|
||||
if self.CurrMiniMode then
|
||||
self.CurrMiniMode.RoundEndTime = 0;
|
||||
end
|
||||
end
|
||||
|
||||
--- 小局正式开始
|
||||
function MiniManager:OnMiniRoundFormalStart()
|
||||
-- 这是正式开启了
|
||||
UGCLogSystem.Log("[MiniManager:OnMiniRoundFormalStart] 正式开始游戏")
|
||||
if self.CurrMiniMode then
|
||||
self.CurrMiniMode.RoundStartTime = UE.GetServerTime();
|
||||
end
|
||||
if IsServer then
|
||||
-- 启动计时,让小游戏有一个时限
|
||||
local TotalTime = MiniGameTimes.RoundGameTime;
|
||||
GlobalTickTool:AddInternalCount(self, function(o, dt, ServerTime, t)
|
||||
local InTime = t;
|
||||
if TotalTime > 0 then InTime = TotalTime - t end
|
||||
o:OnMiniGameTimeCount(InTime);
|
||||
end, 1., math.abs(TotalTime), self.OnMiniRoundEnd, function(o)
|
||||
return o.CurrMiniMode.bGameEnd or o.CurrMiniMode.bRoundEnd;
|
||||
end);
|
||||
|
||||
self:SetState(MiniGameState.ROUND_GAMING);
|
||||
-- 解除玩家封禁状态
|
||||
UE.ClearSceneObjects();
|
||||
else
|
||||
-- 是否显示 “回合正式开始!”
|
||||
end
|
||||
table.func(self.CurrMiniMode, "OnRoundFormalStart", self:GetCurrRoundTimes(), self.CurrMiniMode.RoundStartTime);
|
||||
end
|
||||
|
||||
function MiniManager:OnMiniRoundEnd()
|
||||
if self.State == MiniGameState.ROUND_GAMING then
|
||||
if self.CurrMiniMode.bGameEnd == false and self.CurrMiniMode.bRoundEnd == false then
|
||||
table.func(self.CurrMiniMode, "OnTimeExhausted", self.State)
|
||||
end
|
||||
end
|
||||
-- 通知结束了
|
||||
UGCLogSystem.Log("[MiniManager:OnMiniRoundEnd] 结束")
|
||||
self.CurrMiniMode.RoundEndTime = UE.GetServerTime();
|
||||
local Winner = 0;
|
||||
if IsServer then
|
||||
local Times = MiniGameConfig[self.CurrSelectMap].MiniGameTimes;
|
||||
local Time = 0;
|
||||
if Times and Times.RoundEnd then
|
||||
Time = Times.RoundEnd;
|
||||
else
|
||||
Time = MiniGameTimes.RoundEnd;
|
||||
end
|
||||
|
||||
UGCLogSystem.Log("[MiniManager:OnMiniRoundEnd] RoundTimes = %d", self.CurrMiniMode.RoundTimes)
|
||||
UGCLogSystem.Log("[MiniManager:OnMiniRoundEnd] bGameEnd = %s", tostring(self.CurrMiniMode.bGameEnd))
|
||||
if self.CurrMiniMode.RoundTimes <= 0 or self.CurrMiniMode.bGameEnd then
|
||||
UGCLogSystem.Log("[MiniManager:OnMiniRoundEnd] 回合结束")
|
||||
GlobalTickTool:AddInternalCount(self, function(o, dt, ServerTime, t)
|
||||
o:OnMiniGameTimeCount(t);
|
||||
end, 1, Time, self.OnMiniGameEnd);
|
||||
else
|
||||
-- 继续
|
||||
-- 开始计时
|
||||
UGCLogSystem.Log("[MiniManager:OnMiniRoundEnd] 下一小局开始")
|
||||
GlobalTickTool:AddInternalCount(self, function(o, dt, ServerTime, t)
|
||||
o:OnMiniGameTimeCount(t);
|
||||
end, 1, Time, self.OnMiniRoundPrepare);
|
||||
end
|
||||
if table.hasFunc(self.CurrMiniMode, 'GetRoundWinner') then
|
||||
self.MiniInfo.RoundWinner = table.func(self.CurrMiniMode, "GetRoundWinner", self:GetCurrRoundTimes());
|
||||
end
|
||||
Winner = self.MiniInfo.RoundWinner;
|
||||
table.func(self.CurrMiniMode, "OnRoundEnd", self:GetCurrRoundTimes(), Winner, self.CurrMiniMode.RoundEndTime - self.CurrMiniMode.RoundStartTime);
|
||||
UGCLogSystem.Log("[MiniManager:OnMiniRoundEnd] Winner = %s", tostring(Winner))
|
||||
self:SetState(MiniGameState.ROUND_END);
|
||||
else
|
||||
-- 显示回合成功或者失败,执行到此一定可以拿到Winner是谁
|
||||
-- 直接获取 Winner
|
||||
Winner = self.MiniInfo.RoundWinner
|
||||
UGCLogSystem.Log("[MiniManager:OnMiniRoundEnd] RoundWinner = %s", tostring(Winner));
|
||||
table.func(self.CurrMiniMode, "OnRoundEnd", self:GetCurrRoundTimes(), Winner, self.CurrMiniMode.RoundEndTime - self.CurrMiniMode.RoundStartTime);
|
||||
end
|
||||
end
|
||||
|
||||
----------------------------------- 玩家函数 -----------------------------------
|
||||
--- 当添加玩家的时候执行
|
||||
function MiniManager:OnPlayerLogin(InPlayerKey)
|
||||
UGCLogSystem.Log("[MiniManager:OnPlayerLogin] 玩家:%d 登录", InPlayerKey);
|
||||
table.func(self.CurrMiniMode, "OnPlayerLogin", InPlayerKey);
|
||||
-- 获取玩家的排位分
|
||||
UGCRankSystem.GetUGCRank(InPlayerKey);
|
||||
end
|
||||
|
||||
function MiniManager:OnPlayerLeave(InPlayerKey)
|
||||
UGCLogSystem.Log("[MiniManager:OnPlayerLeave] 玩家:%d 登出", InPlayerKey);
|
||||
table.func(self.CurrMiniMode, "OnPlayerLeave", InPlayerKey);
|
||||
end
|
||||
|
||||
---@param PlayerStartList table<TeamId, table<int32, APlayerStart>>
|
||||
---@param Controller UGCPlayerController_C
|
||||
function MiniManager:SelectPlayerStart(PlayerStartList, Controller)
|
||||
return table.func(self.CurrMiniMode, 'SelectPlayerStart', PlayerStartList, Controller);
|
||||
end
|
||||
|
||||
--- S & C 玩家在加载好之后进行的初始化操作
|
||||
function MiniManager:OnPawnInit(Pawn)
|
||||
if IsServer then
|
||||
--UGCLogSystem.LogTree(string.format("[MiniManager:OnPawnInit] GameConfig ="), MiniGameConfig);
|
||||
UGCLogSystem.Log("[MiniManager:OnPawnInit] self.CurrSelectMap = %s", tostring(self.CurrSelectMap))
|
||||
if self.CurrSelectMap == nil then return ; end
|
||||
local InitArmors = MiniGameConfig[self.CurrSelectMap].InitArmors;
|
||||
local InitMedication = MiniGameConfig[self.CurrSelectMap].InitMedication;
|
||||
table.func(self.CurrMiniMode, 'OnPawnInit', Pawn, InitArmors, InitMedication);
|
||||
else
|
||||
table.func(self.CurrMiniMode, 'OnPawnInit', Pawn);
|
||||
end
|
||||
end
|
||||
|
||||
--- 当玩家死亡
|
||||
---@param DeadPlayerKey PlayerKey
|
||||
---@param KillerPlayerKey PlayerKey
|
||||
function MiniManager:OnPlayerDead(DeadPlayerKey, KillerPlayerKey)
|
||||
table.func(self.CurrMiniMode, 'OnPlayerDead', DeadPlayerKey, KillerPlayerKey);
|
||||
if IsServer then
|
||||
-- 发送 RPC
|
||||
self:SendRPC("OnPlayerDead", DeadPlayerKey, KillerPlayerKey);
|
||||
end
|
||||
end
|
||||
|
||||
function MiniManager:OnPlayerRespawn(InPlayerKey)
|
||||
table.func(self.CurrMiniMode, "OnPlayerRespawn", InPlayerKey)
|
||||
end
|
||||
|
||||
function MiniManager:OnPlayerPossessed(Pawn, NewController)
|
||||
-- 检查是否有初始武器,如果有,那么直接添加
|
||||
UGCLogSystem.Log("[MiniManager:OnPlayerPossessed] 执行")
|
||||
table.func(self.CurrMiniMode, "OnPlayerPossessed", Pawn, NewController);
|
||||
end
|
||||
|
||||
--- 仅在服务器存在
|
||||
function MiniManager:OnPlayerInjury(PlayerKey, CauserKey, DamageInfo)
|
||||
UGCLogSystem.LogTree(string.format("[MiniManager:OnPlayerInjury] DamageInfo ="), DamageInfo)
|
||||
table.func(self.CurrMiniMode, "OnPlayerInjury", PlayerKey, CauserKey, DamageInfo);
|
||||
end
|
||||
|
||||
---@param InPawn UGCPlayerPawn_C
|
||||
---@param Weapon ASTExtraWeapon
|
||||
function MiniManager:OnPlayerGetWeapon(InPawn, Weapon)
|
||||
if self.CurrMiniMode then
|
||||
table.func(self.CurrMiniMode, "OnPlayerGetWeapon", InPawn, Weapon);
|
||||
end
|
||||
end
|
||||
|
||||
--- 射击导致子弹数量发生改变
|
||||
---@param PlayerKey PlayerKey 玩家 Key
|
||||
---@param WeaponID int32 武器 ID
|
||||
---@param PreCount int32 射击前数量
|
||||
---@param CurrCount int32 当前数量
|
||||
function MiniManager:OnBulletNumChange(PlayerKey, WeaponID, PreCount, CurrCount)
|
||||
table.func(self.CurrMiniMode, "OnBulletNumChange", PlayerKey, WeaponID, PreCount, CurrCount);
|
||||
end
|
||||
|
||||
------------------------------------ 获取函数 ------------------------------------
|
||||
--- 获取当前模式
|
||||
function MiniManager:GetCurrentMode() return self.CurrMiniMode; end
|
||||
--- 获取当前地图名
|
||||
function MiniManager:GetCurrLevel() return MiniGameConfig[self.CurrSelectMap].Map.MapName; end
|
||||
--- 获取当前显示地图名称
|
||||
function MiniManager:GetShowName() return MiniGameConfig[self.CurrSelectMap].Map.ShowName; end
|
||||
--- 获取当前是第几回合
|
||||
function MiniManager:GetCurrRoundTimes()
|
||||
if table.isEmpty(MiniGameConfig) or self.CurrSelectMap == nil or table.isEmpty(MiniGameConfig[self.CurrSelectMap]) then
|
||||
return 1;
|
||||
end
|
||||
if MiniGameConfig[self.CurrSelectMap].RoundTimes == nil then
|
||||
return 1;
|
||||
else
|
||||
return MiniGameConfig[self.CurrSelectMap].RoundTimes - self.CurrMiniMode.RoundTimes;
|
||||
end
|
||||
end
|
||||
|
||||
--- 获取总的回合数
|
||||
function MiniManager:GetTotalRoundTimes()
|
||||
if table.isEmpty(MiniGameConfig) or self.CurrSelectMap == nil or table.isEmpty(MiniGameConfig[self.CurrSelectMap]) then
|
||||
return 1;
|
||||
end
|
||||
if MiniGameConfig[self.CurrSelectMap].RoundTimes == nil then
|
||||
return 1;
|
||||
else
|
||||
return MiniGameConfig[self.CurrSelectMap].RoundTimes
|
||||
end
|
||||
end
|
||||
|
||||
------------------------------------ 给予函数 ------------------------------------
|
||||
--- 所有玩家死亡
|
||||
function MiniManager:AllPlayerDead()
|
||||
for i, v in pairs(UGCGameSystem.GetAllPlayerPawn()) do
|
||||
if v:IsAlive() then v:K2_DestroyActor(); end
|
||||
end
|
||||
end
|
||||
|
||||
--- 所有玩家重生
|
||||
function MiniManager:AllPlayerRespawn(InTime)
|
||||
self:AllPlayerDead();
|
||||
UGCEventSystem.SetTimer(self.Owner, function()
|
||||
for i, v in pairs(UGCGameSystem.GetAllPlayerController(false)) do
|
||||
UGCGameSystem.RespawnPlayer(v.PlayerKey);
|
||||
end
|
||||
end, InTime);
|
||||
end
|
||||
|
||||
---@param InPawn UGCPlayerPawn_C
|
||||
---@param InState EPawnState
|
||||
function MiniManager:SetPawnState(InPawn, InState, IsSet)
|
||||
if IsSet then
|
||||
UGCPawnSystem.EnterPawnState(InPawn, InState)
|
||||
else
|
||||
UGCPawnSystem.LeavePawnState(InPawn, InState)
|
||||
end
|
||||
end
|
||||
|
||||
--- 这个需要放在 GameState 中进行更改
|
||||
function MiniManager:DOREPONCE(k, v)
|
||||
self.Owner[k] = v;
|
||||
DOREPONCE(self.Owner, k);
|
||||
end
|
||||
|
||||
MiniManager.CachedMiniInfo = {};
|
||||
|
||||
--- 缓存一份
|
||||
function MiniManager:MakeCachedMiniInfo()
|
||||
if self.CachedMiniInfo.State == nil then
|
||||
self.CachedMiniInfo.State = MiniGameState.NON_START;
|
||||
end
|
||||
end
|
||||
|
||||
--- 属性同步,对比是否不同,只有不同的会进行 OnRep_ 否则就不会进行。
|
||||
function MiniManager:OnRep_MiniInfo(InOld)
|
||||
--UGCLogSystem.LogTree(string.format("[MiniManager:OnRep_MiniInfo] self.MiniInfo ="), self.MiniInfo)
|
||||
--UGCLogSystem.LogTree(string.format("[MiniManager:OnRep_MiniInfo] self.CachedMiniInfo Begin ="), self.CachedMiniInfo)
|
||||
for i, v in pairs(self.MiniInfo) do
|
||||
-- 如果发生改变再执行对应的 OnRep
|
||||
if type(v) == 'table' then
|
||||
-- 比较一下这两者有什么不同
|
||||
if not table.compare(v, self.CachedMiniInfo[i]) then
|
||||
-- 更新一下
|
||||
UGCLogSystem.Log("[MiniManager:OnRep_MiniInfo] 相同变量 Index = %s", tostring(i));
|
||||
if self:IsRepProp(tostring(i)) then
|
||||
self[i] = v;
|
||||
table.func(self, "OnRep_" .. tostring(i), self.CachedMiniInfo[i]);
|
||||
end
|
||||
if self.CurrMiniMode ~= nil then
|
||||
self.CurrMiniMode[i] = TableHelper.DeepCopyTable(v);
|
||||
table.func(self.CurrMiniMode, "OnRep_" .. tostring(i), self.CachedMiniInfo[i]);
|
||||
end
|
||||
end
|
||||
else
|
||||
if self.CachedMiniInfo[i] ~= v then
|
||||
if self:IsRepProp(tostring(i)) then
|
||||
self[i] = v;
|
||||
table.func(self, "OnRep_" .. tostring(i), self.CachedMiniInfo[i]);
|
||||
end
|
||||
if self.CurrMiniMode ~= nil then
|
||||
self.CurrMiniMode[i] = v;
|
||||
table.func(self.CurrMiniMode, "OnRep_" .. tostring(i), self.CachedMiniInfo[i]);
|
||||
end
|
||||
end
|
||||
end
|
||||
UGCLogSystem.Log("[MiniManager:OnRep_MiniInfo] Index = %s", i);
|
||||
self.CachedMiniInfo[i] = nil;
|
||||
--UGCLogSystem.LogTree(string.format("[MiniManager:OnRep_MiniInfo] self.CachedMiniInfo ="), self.CachedMiniInfo)
|
||||
end
|
||||
--UGCLogSystem.LogTree(string.format("[MiniManager:OnRep_MiniInfo] self.CachedMiniInfo End ="), self.CachedMiniInfo)
|
||||
-- 检查是否有多余的
|
||||
for i, v in pairs(self.CachedMiniInfo) do
|
||||
if self.MiniInfo[i] == nil then
|
||||
if self:IsRepProp(tostring(i)) then
|
||||
self[tostring(i)] = nil;
|
||||
table.func(self, "OnRep_" .. tostring(i), v);
|
||||
end
|
||||
if self.CurrMiniMode ~= nil then
|
||||
self.CurrMiniMode[tostring(i)] = nil;
|
||||
table.func(self.CurrMiniMode, "OnRep_" .. tostring(i), v);
|
||||
end
|
||||
UGCLogSystem.Log("[MiniManager:OnRep_MiniInfo] 执行冗余的 Index = %s", tostring(i));
|
||||
end
|
||||
UGCLogSystem.Log("[MiniManager:OnRep_MiniInfo] 冗余的 Index = %s", tostring(i));
|
||||
end
|
||||
|
||||
-- 设置上去进行缓存
|
||||
self.CachedMiniInfo = TableHelper.DeepCopyTable(self.MiniInfo);
|
||||
--UGCLogSystem.LogTree(string.format("[MiniManager:OnRep_MiniInfo] self.CachedMiniInfo Final ="), self.CachedMiniInfo)
|
||||
end
|
||||
|
||||
--- 获取内部数据
|
||||
function MiniManager:GetMiniInfo(InName)
|
||||
if self.CurrMiniMode then
|
||||
local Item = table.func(self.CurrMiniMode, "GetMiniInfo", InName);
|
||||
if Item ~= nil then return Item; end
|
||||
return self.CurrMiniMode[InName];
|
||||
end
|
||||
return nil;
|
||||
end
|
||||
|
||||
function MiniManager:UpdateInternalCount(InCount)
|
||||
UGCLogSystem.Log("[MiniManager:UpdateInternalCount] self.TimerHandlers = %s", tostring(self.TimerHandlers));
|
||||
GlobalTickTool:UpdateInternalCountByHandle(self.TimerHandlers, InCount);
|
||||
end
|
File diff suppressed because it is too large
Load Diff
@ -125,8 +125,8 @@ function ItemTool.AddWeaponItem(InPawn, InWeaponId, InCount, bAppend, FillBullet
|
||||
end
|
||||
|
||||
function ItemTool.GetWeaponIdParts(PlayerKey, InWeaponId)
|
||||
if WeaponSuits[InWeaponId] == nil then return; end
|
||||
if table.isEmpty(WeaponSuits[InWeaponId][EWeaponPartType.Best]) then return; end
|
||||
if WeaponSuits[InWeaponId] == nil then return ; end
|
||||
if table.isEmpty(WeaponSuits[InWeaponId][EWeaponPartType.Best]) then return ; end
|
||||
local Parts = nil;
|
||||
if ArchiveTable[PlayerKey] and not table.isEmpty(ArchiveTable[PlayerKey].Weapons) then
|
||||
Parts = ArchiveTable[PlayerKey].Weapons[InWeaponId];
|
||||
@ -149,7 +149,6 @@ end
|
||||
---@param InPawn UGCPlayerPawn_C
|
||||
---@return table<int32, FItemDefineID>
|
||||
function ItemTool.GetWeaponPartsDefineIDs(InPawn, Weapon)
|
||||
local BackComp = UGCBackPackSystem.GetBackpackComponent(InPawn);
|
||||
local InstanceIds = {};
|
||||
local CustomList = {};
|
||||
for i = 0, 5 do
|
||||
@ -166,6 +165,27 @@ function ItemTool.GetWeaponPartsDefineIDs(InPawn, Weapon)
|
||||
return InstanceIds, CustomList;
|
||||
end
|
||||
|
||||
---@param Weapon ASTExtraWeapon
|
||||
function ItemTool.GetWeaponPartDefineIDMap(Weapon)
|
||||
local List = UGCGunSystem.GetWeaponAllAttachmentIDList(Weapon)
|
||||
local Map = {};
|
||||
for i, v in pairs(List) do Map[v.TypeSpecificID] = v; end
|
||||
return Map;
|
||||
end
|
||||
|
||||
---@param Weapon ASTExtraWeapon
|
||||
function ItemTool.GetWeaponPartSocketMap(Weapon)
|
||||
local List = UGCGunSystem.GetAvailableWeaponAttachmentSocketTypeList(Weapon);
|
||||
local Map = {};
|
||||
for i, Socket in pairs(List) do
|
||||
local DefineID = UGCGunSystem.GetWeaponAttachmentIDBySocketType(Weapon, Socket);
|
||||
if DefineID and DefineID.bValidInstance then
|
||||
Map[DefineID.TypeSpecificID] = Socket;
|
||||
end
|
||||
end
|
||||
return Map;
|
||||
end
|
||||
|
||||
---@param Weapon ASTExtraWeapon
|
||||
---@param InPawn UGCPlayerPawn_C
|
||||
function ItemTool.ClearWeapon(InPawn, Weapon)
|
||||
@ -605,6 +625,37 @@ function ItemTool.SetWeaponParts(InWeapon, Parts)
|
||||
end
|
||||
end
|
||||
|
||||
--- 从背包中寻找对应配件,如果有添加,没有的话就创建
|
||||
---@param InWeapon ASTExtraShootWeapon
|
||||
function ItemTool.ReuseWeaponParts(InWeapon, Parts)
|
||||
if not ItemTool.IsShootWeapon(InWeapon) then return ; end
|
||||
if table.isEmpty(Parts) then ItemTool.DisuseAllParts(InWeapon); return; end
|
||||
local Pawn = InWeapon:GetOwnerPawn();
|
||||
|
||||
local PartMap = {};
|
||||
for i, v in pairs(Parts) do PartMap[v] = 1; end
|
||||
local AllItems = UGCBackPackSystem.GetAllAttachmentDefineIDInBackpack(Pawn)
|
||||
|
||||
-- 查看当前枪上有哪些
|
||||
local HasMap = ItemTool.GetWeaponPartSocketMap(InWeapon);
|
||||
|
||||
local Removes = {};
|
||||
for PartID, SocketType in pairs(HasMap) do
|
||||
if PartMap[PartID] then
|
||||
PartMap[PartID] = nil;
|
||||
else
|
||||
Removes[PartID] = SocketType;
|
||||
end
|
||||
end
|
||||
for i, v in pairs(Removes) do
|
||||
UGCGunSystem.RemoveGunAttachmentBySocketType(InWeapon, v);
|
||||
end
|
||||
|
||||
for i, v in pairs(PartMap) do
|
||||
UGCGunSystem.CreateAndAddGunAttachment(InWeapon, i);
|
||||
end
|
||||
end
|
||||
|
||||
---@param InWeapon ASTExtraShootWeapon
|
||||
function ItemTool.GetAllPartTypes(InWeapon)
|
||||
local WeaponID = InWeapon:GetWeaponItemID();
|
||||
@ -640,6 +691,13 @@ function ItemTool.RemoveAllParts(InWeapon)
|
||||
end
|
||||
end
|
||||
|
||||
--- 将枪上的配件全部放回背包
|
||||
---@param InWeapon ASTExtraShootWeapon
|
||||
function ItemTool.DisuseAllParts(InWeapon)
|
||||
if not InWeapon:IsShotGun() then return end
|
||||
UGCGunSystem.DisuseAllWeaponAttachmentsOnServer(InWeapon);
|
||||
end
|
||||
|
||||
---@return ASTExtraShootWeapon
|
||||
function ItemTool.GetLocalPawnCurrWeapon()
|
||||
local Pawn = UE.GetLocalPawn();
|
||||
@ -688,7 +746,7 @@ end
|
||||
---@param WeaponID int32
|
||||
function ItemTool.RemoveBullet(Pawn, WeaponID)
|
||||
local AmmoID = WeaponAmmoIdMap[WeaponID]
|
||||
if AmmoID == nil then return; end
|
||||
if AmmoID == nil then return ; end
|
||||
local AllData = UGCBackPackSystem.GetAllItemData(Pawn);
|
||||
for i, v in pairs(AllData) do
|
||||
if v.ItemID == AmmoID then
|
||||
|
Loading…
x
Reference in New Issue
Block a user