- 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, -- 调试模式开关
|
||||
|
||||
@@ -35,19 +35,21 @@ jetSpawner = {
|
||||
|
||||
-- 根据玩家调整刷新率
|
||||
player_ratio_table = {
|
||||
[10] = 1, -- 当玩家数小于10人刷新率为 1
|
||||
[20] = 0.8,
|
||||
[30] = 0.5,
|
||||
[40] = 0.4,
|
||||
[50] = 0.3,
|
||||
[60] = 0.2,
|
||||
[9999] = 0.05,
|
||||
[3] = 4.5, -- 当玩家数小于3人刷新率为 3
|
||||
[5] = 2.5,
|
||||
[10] = 1.5,
|
||||
[20] = 1,
|
||||
[30] = 0.75,
|
||||
[40] = 0.55,
|
||||
[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 --
|
||||
-------------------------------------
|
||||
@@ -57,6 +59,7 @@ jetSpawner = {
|
||||
allMonitors = {},
|
||||
spawnedGroups = {},
|
||||
}
|
||||
|
||||
do
|
||||
--Tools
|
||||
function deepCopy(object)
|
||||
@@ -112,8 +115,7 @@ do
|
||||
[world.event.S_EVENT_BIRTH] = 'S_EVENT_BIRTH',
|
||||
[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('Event: '..eventTable[event.id])
|
||||
Debug("Player number +1 by \'event "..eventTable[event.id].." handler.\' Player name: "..playerName..' current playerNum: '..jetSpawner.tableCount(self.playerList))
|
||||
end
|
||||
|
||||
function jetSpawner:deleteplayerList(playerName,event)
|
||||
@@ -127,11 +129,11 @@ do
|
||||
[world.event.S_EVENT_CRASH] = 'S_EVENT_CRASH',
|
||||
[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('Event: '..eventTable[event.id])
|
||||
Debug("Player number -1 by \'event "..eventTable[event.id].." handler.\' Player name: "..playerName..' current playerNum: '..jetSpawner.tableCount(self.playerList))
|
||||
end
|
||||
|
||||
function jetSpawner.tableCount(table)
|
||||
if not table then return end
|
||||
if type(table) ~= 'table' then return end
|
||||
|
||||
local count = 0
|
||||
@@ -148,7 +150,7 @@ do
|
||||
if not jetSpawner.only_count_airborne_players then
|
||||
if event.id == world.event.S_EVENT_BIRTH then
|
||||
local unit = event.initiator
|
||||
if not unit then return end
|
||||
if not unit or not unit.getPlayerName then return end
|
||||
|
||||
local playerName = unit:getPlayerName()
|
||||
if playerName then
|
||||
@@ -161,7 +163,7 @@ do
|
||||
if jetSpawner.only_count_airborne_players then
|
||||
if event.id == world.event.S_EVENT_TAKEOFF then
|
||||
local unit = event.initiator
|
||||
if not unit then return end
|
||||
if not unit or not unit.getPlayerName then return end
|
||||
|
||||
local playerName = unit:getPlayerName()
|
||||
if playerName then
|
||||
@@ -201,31 +203,55 @@ do
|
||||
spawnGroupData.name = nil
|
||||
local newGroupName = preset.categoryName..'_'..spawnGroupData.units[1].type
|
||||
|
||||
self.spawnedGroups[newGroupName] = self.spawnedGroups[newGroupName] or {}
|
||||
for groupName,group in pairs(self.spawnedGroups[newGroupName]) do
|
||||
if self.spawnedGroups[preset.categoryName] then
|
||||
if self.spawnedGroups[preset.categoryName][newGroupName] then
|
||||
for groupName,group in pairs(self.spawnedGroups[preset.categoryName][newGroupName]) do
|
||||
if not group:isExist() then
|
||||
spawnGroupData.name = groupName
|
||||
self.spawnedGroups[newGroupName][groupName] = nil
|
||||
self.spawnedGroups[preset.categoryName][newGroupName][groupName] = nil
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
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)
|
||||
end
|
||||
for i,unitData in ipairs(spawnGroupData.units) do
|
||||
unitData.name = spawnGroupData.name..'-'..i
|
||||
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)
|
||||
if presetGroup then
|
||||
local category = presetGroup:getCategory()
|
||||
local newGroup = coalition.addGroup(country.id.CJTF_RED,category,spawnGroupData)
|
||||
if newGroup then
|
||||
self.spawnedGroups[newGroupName] = self.spawnedGroups[newGroupName] or {}
|
||||
self.spawnedGroups[newGroupName][spawnGroupData.name] = newGroup
|
||||
self.spawnedGroups[preset.categoryName] = self.spawnedGroups[preset.categoryName] or {}
|
||||
self.spawnedGroups[preset.categoryName][newGroupName] = self.spawnedGroups[preset.categoryName][newGroupName] or {}
|
||||
self.spawnedGroups[preset.categoryName][newGroupName][spawnGroupData.name] = newGroup
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -277,7 +303,7 @@ do
|
||||
|
||||
|
||||
jetSpawner:startAllMonitors()
|
||||
Debug('jetSpawner')
|
||||
Debug('jetSpawner Ver: '..jetSpawner.version)
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user