250 lines
8.8 KiB
Lua
250 lines
8.8 KiB
Lua
---@class MiniGameMode_CompetitionResponse
|
|
---@field IsGameEnd bool
|
|
---@field PlayerAddScore table<PlayerKey, int32> 玩家获取的分数
|
|
|
|
|
|
---@type MiniGameMode_CompetitionResponse
|
|
local MiniGameMode_CompetitionResponse = {
|
|
IsGameEnd = false;
|
|
bIsInGame = false;
|
|
-- 给玩家结算添加的得分{[PlayerKey] = AddScore, ...}
|
|
PlayerAddScore = {};
|
|
MiniGameScore = {};
|
|
|
|
-- 已选择的玩家
|
|
SelectedPlayer = {};
|
|
-- 正确的ID
|
|
TargetID = -1;
|
|
-- 玩家是否可以选择
|
|
bCanSelect = false;
|
|
-- 回合参数
|
|
Round = 0;
|
|
ReadyTime = 0.;
|
|
SelectTime = 0.;
|
|
DifficultyUpgradeRound = 0;
|
|
RoundTime = 0;
|
|
|
|
-- 玩法随机的数字列表
|
|
RandomPicList = {};
|
|
RandomPicColorList = {};
|
|
RandomTextList = {};
|
|
}
|
|
|
|
--- 游戏初始化
|
|
function MiniGameMode_CompetitionResponse:Init()
|
|
|
|
self.TextureNum = #MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.CompetitionResponse].GameParam.TexturesPath
|
|
self.TextureColorNum = #MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.CompetitionResponse].GameParam.TexturesColor
|
|
self.TextNum = table.getCount(MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.CompetitionResponse].GameParam.TextParam)
|
|
|
|
self.ReadyTime = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.CompetitionResponse].GameParam.ReadyTime;
|
|
self.SelectTime = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.CompetitionResponse].GameParam.SelectTime;
|
|
self.DifficultyUpgradeRound = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.CompetitionResponse].GameParam.DifficultyUpgradeRound;
|
|
self.MaxRound = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.CompetitionResponse].GameParam.MaxRound;
|
|
|
|
for i = 1, self.TextureNum do
|
|
self.RandomPicList[#self.RandomPicList + 1] = i
|
|
end
|
|
|
|
for i = 1, self.TextureColorNum do
|
|
self.RandomPicColorList[#self.RandomPicColorList + 1] = i
|
|
end
|
|
|
|
for i = 1, self.TextNum do
|
|
self.RandomTextList[#self.RandomTextList + 1] = i
|
|
end
|
|
|
|
UGCEventSystem.AddListener(EventEnum.ResponseGamePlayerSelect, self.PlayerSelect, self)
|
|
|
|
-- self:InitMiniGameScore()
|
|
end
|
|
|
|
--- 准备时间结束游戏开始
|
|
function MiniGameMode_CompetitionResponse:GameBegin()
|
|
self.bIsInGame = true
|
|
self:NewResponseRound()
|
|
end
|
|
|
|
function MiniGameMode_CompetitionResponse:Update(DeltaTime)
|
|
-- 判断该玩法是否已结束
|
|
if self.IsGameEnd then return end
|
|
|
|
-- Update逻辑
|
|
if self.bIsInGame then
|
|
self.RoundTime = self.RoundTime + DeltaTime
|
|
if self.RoundTime >= self.ReadyTime + self.SelectTime then
|
|
self.RoundTime = 0
|
|
self:NewResponseRound()
|
|
end
|
|
end
|
|
|
|
|
|
-- Update逻辑 End
|
|
end
|
|
|
|
--- 设置游戏结束,手动触发会结束该玩法,倒计时结束将自动触发该函数
|
|
function MiniGameMode_CompetitionResponse:SetMiniGameModeEnd()
|
|
if not self.IsGameEnd then
|
|
self.IsGameEnd = true
|
|
self:MiniGameEnd()
|
|
end
|
|
end
|
|
|
|
--- 获取当前回合游戏结算,
|
|
---@return "{[PlayerKey] = AddScore, ...}"
|
|
function MiniGameMode_CompetitionResponse:GetPlayerAddScore()
|
|
return self.PlayerAddScore
|
|
end
|
|
|
|
--- 外层调用,判断该玩法是否已结束
|
|
function MiniGameMode_CompetitionResponse:CheckGameFinish()
|
|
return self.IsGameEnd
|
|
end
|
|
|
|
--- 结束触发
|
|
function MiniGameMode_CompetitionResponse:MiniGameEnd()
|
|
self.PlayerAddScore = UGCGameSystem.GameState:GetPlayerMiniGameAddScore()
|
|
UGCEventSystem.RemoveListener(EventEnum.ResponseGamePlayerSelect, self.PlayerSelect, self)
|
|
end
|
|
|
|
------------------------------------------ Player ------------------------------------------
|
|
|
|
--- 玩家死亡
|
|
function MiniGameMode_CompetitionResponse:PlayerDead(VictimKey, CauserKey, WeaponID, DamageType, IsHeadShotDamage, Distance, DamageValue, Assister)
|
|
|
|
end
|
|
|
|
--- 玩家伤害修改
|
|
function MiniGameMode_CompetitionResponse:PlayerDamageModify(DamageAmount, VictimPawn, CauserPC)
|
|
return DamageAmount
|
|
end
|
|
|
|
--- 玩家受控时
|
|
function MiniGameMode_CompetitionResponse:PlayerPossessed(PlayerKey)
|
|
|
|
end
|
|
|
|
--- 玩家BeginPlay触发
|
|
function MiniGameMode_CompetitionResponse:PlayerBeginPlay(PlayerPawn)
|
|
|
|
end
|
|
|
|
---------------------------------------- Player End ----------------------------------------
|
|
|
|
|
|
|
|
|
|
function MiniGameMode_CompetitionResponse:PlayerSelect(PlayerKey, SelectID)
|
|
if not self.IsGameEnd
|
|
and self.bIsInGame
|
|
and UGCGameSystem.GameState:GetServerGameTime() >= self.CanSelectTime - 0.1
|
|
and not table.hasValue(self.SelectedPlayer, PlayerKey) then
|
|
|
|
self.SelectedPlayer[#self.SelectedPlayer + 1] = PlayerKey
|
|
if SelectID == self.TargetID then
|
|
-- self:PlayerAddMiniGameScore(PlayerKey, self.RoundAddScore)
|
|
UGCGameSystem.GameState:PlayerAddMiniGameScore(PlayerKey, self.RoundAddScore)
|
|
self.RoundAddScore = self.RoundAddScore - 1
|
|
|
|
MiniGameConfig.CheckPlayerTask(PlayerKey, MiniGameConfig.MiniGameType.CompetitionResponse, UGCGameSystem.GameState:GetPlayerMiniGameScore(PlayerKey), false)
|
|
end
|
|
UGCSendRPCSystem.RPCEvent(nil, EventEnum.ResponseGameSelectCallBack, SelectID == self.TargetID , PlayerKey);
|
|
end
|
|
end
|
|
|
|
function MiniGameMode_CompetitionResponse:NewResponseRound()
|
|
self.SelectedPlayer = {}
|
|
self.RoundAddScore = 4;
|
|
self.Round = self.Round + 1
|
|
if self.Round > self.MaxRound then
|
|
self:SetMiniGameModeEnd()
|
|
return
|
|
end
|
|
UGCGameSystem.GameState:SetMiniGameInternalRound(self.Round)
|
|
|
|
if self.Round < self.DifficultyUpgradeRound then
|
|
-- 图案颜色玩法
|
|
local TargetTexIndex = math.random(1, self.TextureNum)
|
|
local TargetColor = math.random(1, self.TextureColorNum)
|
|
local SelectTexIndex = {TargetTexIndex, }
|
|
local SelectTexColor = {TargetColor, }
|
|
|
|
table.Shuffle(self.RandomPicList)
|
|
table.Shuffle(self.RandomPicColorList)
|
|
|
|
for i, v in pairs(self.RandomPicList) do
|
|
if #SelectTexIndex >= 4 then break end
|
|
if v ~= TargetTexIndex then
|
|
SelectTexIndex[#SelectTexIndex + 1] = v
|
|
end
|
|
end
|
|
for i, v in pairs(self.RandomPicColorList) do
|
|
if #SelectTexColor >= 4 then break end
|
|
if v ~= TargetColor then
|
|
SelectTexColor[#SelectTexColor + 1] = v
|
|
end
|
|
end
|
|
self.TargetID = math.random(1, 4)
|
|
table.Swap(SelectTexIndex, 1, self.TargetID)
|
|
table.Swap(SelectTexColor, 1, math.random(1, 4))
|
|
|
|
-- {[ID] = {Index, ColorIndex}}
|
|
local SelectParams = {}
|
|
for i = 1, 4 do
|
|
SelectParams[i] = {Index = SelectTexIndex[i], ColorIndex = SelectTexColor[i]}
|
|
end
|
|
|
|
self.CanSelectTime = UGCGameSystem.GameState:GetServerGameTime() + self.ReadyTime
|
|
UGCSendRPCSystem.RPCEvent(nil, EventEnum.ResponseGameReadyState, self.CanSelectTime, true, TargetTexIndex, TargetColor, SelectParams)
|
|
|
|
else
|
|
if self.Round == self.DifficultyUpgradeRound then
|
|
UGCSendRPCSystem.RPCEvent(nil, EventEnum.ResponseGameDifficultyUpgrade)
|
|
end
|
|
-- 文字颜色玩法
|
|
local TargetTextIndex = math.random(1, self.TextNum)
|
|
local TargetColor = math.random(1, self.TextNum)
|
|
local SelectTextIndex = {TargetTextIndex, }
|
|
local SelectTextColor = {TargetTextIndex, }
|
|
if TargetColor ~= TargetTextIndex then
|
|
SelectTextColor[2] = TargetColor
|
|
end
|
|
|
|
table.Shuffle(self.RandomTextList)
|
|
for i, v in pairs(self.RandomTextList) do
|
|
if #SelectTextIndex >= 4 then break end
|
|
if v ~= TargetTextIndex then
|
|
SelectTextIndex[#SelectTextIndex + 1] = v
|
|
end
|
|
end
|
|
table.Shuffle(self.RandomTextList)
|
|
for i, v in pairs(self.RandomTextList) do
|
|
if #SelectTextColor >= 4 then break end
|
|
if v ~= TargetTextIndex and v ~= TargetColor then
|
|
SelectTextColor[#SelectTextColor + 1] = v
|
|
end
|
|
end
|
|
|
|
table.Swap(SelectTextIndex, 1, math.random(1, 4))
|
|
table.Shuffle(SelectTextColor)
|
|
for i, v in pairs(SelectTextColor) do
|
|
if v == TargetTextIndex then
|
|
self.TargetID = i
|
|
break
|
|
end
|
|
end
|
|
|
|
local SelectParams = {}
|
|
for i = 1, 4 do
|
|
SelectParams[i] = {Index = SelectTextIndex[i], ColorIndex = SelectTextColor[i]}
|
|
end
|
|
|
|
--UGCLogSystem.Log("[MiniGameMode_CompetitionResponse_NewResponseRound] TargetID:%s", tostring(self.TargetID))
|
|
--UGCLogSystem.LogTree("[MiniGameMode_CompetitionResponse_NewResponseRound] SelectParams:", SelectParams)
|
|
|
|
self.CanSelectTime = UGCGameSystem.GameState:GetServerGameTime() + self.ReadyTime
|
|
UGCSendRPCSystem.RPCEvent(nil, EventEnum.ResponseGameReadyState, self.CanSelectTime, false, TargetTextIndex, TargetColor, SelectParams)
|
|
end
|
|
end
|
|
|
|
return MiniGameMode_CompetitionResponse |