- Update maxSpawn cap for red jet sapwn. Now presets can set max group spawn number.
- Fix bug for event handler when event.initiator is not Unit class(like some classes do not have function getPlayerName but can trigger birth/crash event).
This commit is contained in:
+49
-23
@@ -6,7 +6,7 @@ jetSpawner = {
|
|||||||
-------------------------------------
|
-------------------------------------
|
||||||
-- 配置参数区 --
|
-- 配置参数区 --
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
version = '0.0.2',
|
version = '0.0.3',
|
||||||
|
|
||||||
DebugMode = true, -- 调试模式开关
|
DebugMode = true, -- 调试模式开关
|
||||||
|
|
||||||
@@ -35,19 +35,21 @@ jetSpawner = {
|
|||||||
|
|
||||||
-- 根据玩家调整刷新率
|
-- 根据玩家调整刷新率
|
||||||
player_ratio_table = {
|
player_ratio_table = {
|
||||||
[10] = 1, -- 当玩家数小于10人刷新率为 1
|
[3] = 4.5, -- 当玩家数小于3人刷新率为 3
|
||||||
[20] = 0.8,
|
[5] = 2.5,
|
||||||
[30] = 0.5,
|
[10] = 1.5,
|
||||||
[40] = 0.4,
|
[20] = 1,
|
||||||
[50] = 0.3,
|
[30] = 0.75,
|
||||||
[60] = 0.2,
|
[40] = 0.55,
|
||||||
[9999] = 0.05,
|
[50] = 0.45,
|
||||||
|
[60] = 0.35,
|
||||||
|
[9999] = 0.25,
|
||||||
},
|
},
|
||||||
|
|
||||||
-- 是否仅计算已升空玩家
|
-- 是否仅计算已升空玩家
|
||||||
only_count_airborne_players = false,
|
only_count_airborne_players = true,
|
||||||
|
|
||||||
RANDOM_DEVIATION = 0.1, -- 时间随机浮动比例(±10%)
|
RANDOM_DEVIATION = 0.5, -- 时间随机浮动比例(±50%)
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
-- 配置参数区 END --
|
-- 配置参数区 END --
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
@@ -57,6 +59,7 @@ jetSpawner = {
|
|||||||
allMonitors = {},
|
allMonitors = {},
|
||||||
spawnedGroups = {},
|
spawnedGroups = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
--Tools
|
--Tools
|
||||||
function deepCopy(object)
|
function deepCopy(object)
|
||||||
@@ -112,8 +115,7 @@ do
|
|||||||
[world.event.S_EVENT_BIRTH] = 'S_EVENT_BIRTH',
|
[world.event.S_EVENT_BIRTH] = 'S_EVENT_BIRTH',
|
||||||
[world.event.S_EVENT_TAKEOFF] = 'S_EVENT_TAKEOFF',
|
[world.event.S_EVENT_TAKEOFF] = 'S_EVENT_TAKEOFF',
|
||||||
}
|
}
|
||||||
Debug("Player number +1 by \'Birth handler.\' Player name: "..playerName..' current playerNum: '..jetSpawner.tableCount(self.playerList))
|
Debug("Player number +1 by \'event "..eventTable[event.id].." handler.\' Player name: "..playerName..' current playerNum: '..jetSpawner.tableCount(self.playerList))
|
||||||
Debug('Event: '..eventTable[event.id])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function jetSpawner:deleteplayerList(playerName,event)
|
function jetSpawner:deleteplayerList(playerName,event)
|
||||||
@@ -127,11 +129,11 @@ do
|
|||||||
[world.event.S_EVENT_CRASH] = 'S_EVENT_CRASH',
|
[world.event.S_EVENT_CRASH] = 'S_EVENT_CRASH',
|
||||||
[world.event.S_EVENT_PLAYER_LEAVE_UNIT] = 'S_EVENT_PLAYER_LEAVE_UNIT',
|
[world.event.S_EVENT_PLAYER_LEAVE_UNIT] = 'S_EVENT_PLAYER_LEAVE_UNIT',
|
||||||
}
|
}
|
||||||
Debug("Player number -1 by \'Birth handler.\' Player name: "..playerName..' current playerNum: '..jetSpawner.tableCount(self.playerList))
|
Debug("Player number -1 by \'event "..eventTable[event.id].." handler.\' Player name: "..playerName..' current playerNum: '..jetSpawner.tableCount(self.playerList))
|
||||||
Debug('Event: '..eventTable[event.id])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function jetSpawner.tableCount(table)
|
function jetSpawner.tableCount(table)
|
||||||
|
if not table then return end
|
||||||
if type(table) ~= 'table' then return end
|
if type(table) ~= 'table' then return end
|
||||||
|
|
||||||
local count = 0
|
local count = 0
|
||||||
@@ -148,7 +150,7 @@ do
|
|||||||
if not jetSpawner.only_count_airborne_players then
|
if not jetSpawner.only_count_airborne_players then
|
||||||
if event.id == world.event.S_EVENT_BIRTH then
|
if event.id == world.event.S_EVENT_BIRTH then
|
||||||
local unit = event.initiator
|
local unit = event.initiator
|
||||||
if not unit then return end
|
if not unit or not unit.getPlayerName then return end
|
||||||
|
|
||||||
local playerName = unit:getPlayerName()
|
local playerName = unit:getPlayerName()
|
||||||
if playerName then
|
if playerName then
|
||||||
@@ -161,7 +163,7 @@ do
|
|||||||
if jetSpawner.only_count_airborne_players then
|
if jetSpawner.only_count_airborne_players then
|
||||||
if event.id == world.event.S_EVENT_TAKEOFF then
|
if event.id == world.event.S_EVENT_TAKEOFF then
|
||||||
local unit = event.initiator
|
local unit = event.initiator
|
||||||
if not unit then return end
|
if not unit or not unit.getPlayerName then return end
|
||||||
|
|
||||||
local playerName = unit:getPlayerName()
|
local playerName = unit:getPlayerName()
|
||||||
if playerName then
|
if playerName then
|
||||||
@@ -201,31 +203,55 @@ do
|
|||||||
spawnGroupData.name = nil
|
spawnGroupData.name = nil
|
||||||
local newGroupName = preset.categoryName..'_'..spawnGroupData.units[1].type
|
local newGroupName = preset.categoryName..'_'..spawnGroupData.units[1].type
|
||||||
|
|
||||||
self.spawnedGroups[newGroupName] = self.spawnedGroups[newGroupName] or {}
|
if self.spawnedGroups[preset.categoryName] then
|
||||||
for groupName,group in pairs(self.spawnedGroups[newGroupName]) do
|
if self.spawnedGroups[preset.categoryName][newGroupName] then
|
||||||
|
for groupName,group in pairs(self.spawnedGroups[preset.categoryName][newGroupName]) do
|
||||||
if not group:isExist() then
|
if not group:isExist() then
|
||||||
spawnGroupData.name = groupName
|
spawnGroupData.name = groupName
|
||||||
self.spawnedGroups[newGroupName][groupName] = nil
|
self.spawnedGroups[preset.categoryName][newGroupName][groupName] = nil
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if not spawnGroupData.name then
|
if not spawnGroupData.name then
|
||||||
-- 获取群组序号
|
-- 获取群组序号
|
||||||
local groupNameIndex = jetSpawner.tableCount(self.spawnedGroups[newGroupName]) or 0
|
local categoryTable = self.spawnedGroups[preset.categoryName] or {}
|
||||||
|
local tempTable = categoryTable[newGroupName] or {}
|
||||||
|
local groupNameIndex = jetSpawner.tableCount(tempTable) or 0
|
||||||
spawnGroupData.name = newGroupName..'-'..(groupNameIndex + 1)
|
spawnGroupData.name = newGroupName..'-'..(groupNameIndex + 1)
|
||||||
end
|
end
|
||||||
for i,unitData in ipairs(spawnGroupData.units) do
|
for i,unitData in ipairs(spawnGroupData.units) do
|
||||||
unitData.name = spawnGroupData.name..'-'..i
|
unitData.name = spawnGroupData.name..'-'..i
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- 判断是否到达最大数量限制
|
||||||
|
local canSpawn = true
|
||||||
|
if preset.maxSpawn and preset.maxSpawn > 0 then
|
||||||
|
local count = 0
|
||||||
|
if self.spawnedGroups[preset.categoryName] then
|
||||||
|
for groupName, group in pairs(self.spawnedGroups[preset.categoryName]) do
|
||||||
|
count = count + jetSpawner.tableCount(self.spawnedGroups[preset.categoryName][groupName])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if count >= preset.maxSpawn then
|
||||||
|
canSpawn = false
|
||||||
|
end
|
||||||
|
Debug('Category: '..preset.categoryName..' have spawned: ('..count..'/'..preset.maxSpawn..')')
|
||||||
|
end
|
||||||
|
|
||||||
-- 刷新飞机
|
-- 刷新飞机
|
||||||
|
if canSpawn then
|
||||||
local presetGroup = Group.getByName(spawnGroupName)
|
local presetGroup = Group.getByName(spawnGroupName)
|
||||||
if presetGroup then
|
if presetGroup then
|
||||||
local category = presetGroup:getCategory()
|
local category = presetGroup:getCategory()
|
||||||
local newGroup = coalition.addGroup(country.id.CJTF_RED,category,spawnGroupData)
|
local newGroup = coalition.addGroup(country.id.CJTF_RED,category,spawnGroupData)
|
||||||
if newGroup then
|
if newGroup then
|
||||||
self.spawnedGroups[newGroupName] = self.spawnedGroups[newGroupName] or {}
|
self.spawnedGroups[preset.categoryName] = self.spawnedGroups[preset.categoryName] or {}
|
||||||
self.spawnedGroups[newGroupName][spawnGroupData.name] = newGroup
|
self.spawnedGroups[preset.categoryName][newGroupName] = self.spawnedGroups[preset.categoryName][newGroupName] or {}
|
||||||
|
self.spawnedGroups[preset.categoryName][newGroupName][spawnGroupData.name] = newGroup
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -277,7 +303,7 @@ do
|
|||||||
|
|
||||||
|
|
||||||
jetSpawner:startAllMonitors()
|
jetSpawner:startAllMonitors()
|
||||||
Debug('jetSpawner')
|
Debug('jetSpawner Ver: '..jetSpawner.version)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user