Update Ver1.2
- add sound effects - change to new method to calculate kill number - add hard disk write(if its not mentioned before)
This commit is contained in:
+348
-213
@@ -1,7 +1,7 @@
|
||||
Range = {}
|
||||
|
||||
|
||||
Range.DebugMod = true
|
||||
Range.DebugMod = false
|
||||
Range.ZoneIndex = 1
|
||||
|
||||
Range.MonitorRepeatTime = 5
|
||||
@@ -21,14 +21,8 @@ if lfs and io then
|
||||
end
|
||||
|
||||
Range.SpawnedGroups_Default = {
|
||||
[coalition.side.RED] = {
|
||||
static = nil,
|
||||
moving = nil,
|
||||
},
|
||||
[coalition.side.BLUE] = {
|
||||
static = nil,
|
||||
moving = nil,
|
||||
},
|
||||
[coalition.side.RED] = {},
|
||||
[coalition.side.BLUE] = {},
|
||||
}
|
||||
Range.PlayerData_Default = {
|
||||
startTime = nil,
|
||||
@@ -73,7 +67,7 @@ do
|
||||
return
|
||||
end
|
||||
|
||||
local obj = {}
|
||||
local obj = {}
|
||||
|
||||
local polygonPoints = Range.ZoneToPolygon(rangeZone)
|
||||
if not polygonPoints then return end
|
||||
@@ -99,35 +93,6 @@ do
|
||||
setmetatable(obj, self)
|
||||
self.__index = self
|
||||
|
||||
|
||||
local playerSpawnEventHandler = {
|
||||
listeningZone = obj
|
||||
}
|
||||
function playerSpawnEventHandler:onEvent(event)
|
||||
if event.id == world.event.S_EVENT_BIRTH then
|
||||
local rangeObj = self.listeningZone
|
||||
local object = event.initiator
|
||||
if not object:isExist() then return end
|
||||
|
||||
local SpawnPoint = object:getPoint()
|
||||
|
||||
if not object.getPlayerName then return end
|
||||
local playerName = object:getPlayerName()
|
||||
if not playerName then return end
|
||||
|
||||
if rangeObj:CanBindPlayer(object) then
|
||||
|
||||
obj:Init(object,true)
|
||||
trigger.action.outText('靶场: '..obj.zoneName..' 已分配给玩家: '..playerName,10)
|
||||
|
||||
if Range.DebugMod then
|
||||
Utils.Debug('Bind player: '..playerName..' to Zone: '..rangeObj.zoneName)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
world.addEventHandler(playerSpawnEventHandler)
|
||||
|
||||
if Range.DebugMod then
|
||||
Utils.Debug('New Range: '..obj.zoneName)
|
||||
end
|
||||
@@ -140,8 +105,6 @@ do
|
||||
|
||||
function Range:Init(playerUnit,notdrawZone)
|
||||
self.playerUnit = playerUnit
|
||||
self.playerData = Range.PlayerData_Default
|
||||
self.spawnedGroups = Range.SpawnedGroups_Default
|
||||
self.playSound = true
|
||||
|
||||
if playerUnit then
|
||||
@@ -149,19 +112,36 @@ do
|
||||
end
|
||||
|
||||
if not notdrawZone then
|
||||
if self.assignedRangeZoneDrawID then
|
||||
|
||||
if not self.playerUnit then
|
||||
trigger.action.setMarkupColorFill(self.assignedRangeZoneDrawID,{0,1,0,0.2})
|
||||
trigger.action.setMarkupTypeLine(self.assignedRangeZoneDrawID,2)
|
||||
end
|
||||
|
||||
if self.playerUnit then
|
||||
trigger.action.setMarkupColorFill(self.assignedRangeZoneDrawID,{1,0,0,0.2})
|
||||
trigger.action.setMarkupTypeLine(self.assignedRangeZoneDrawID,1)
|
||||
end
|
||||
end
|
||||
|
||||
if self.assignedRangeZoneDrawID then
|
||||
if not self.playerUnit then
|
||||
trigger.action.setMarkupText(self.assignedRangeZoneTextID, '靶场: '..self.zoneName..' 当前使用: 无')
|
||||
end
|
||||
if self.playerUnit then
|
||||
trigger.action.setMarkupText(self.assignedRangeZoneTextID, '靶场: '..self.zoneName..' 当前使用: '..self.playerName)
|
||||
end
|
||||
end
|
||||
|
||||
if not self.assignedRangeZoneDrawID then
|
||||
self.assignedRangeZoneDrawID = Utils.getMarkID()
|
||||
Utils.drawPolygon(-1,self.assignedRangeZoneDrawID,self.zonePolygon,{1,0,0,0.2},{0,1,0,0.2},2)
|
||||
else
|
||||
trigger.action.setMarkupColorFill(self.assignedRangeZoneDrawID,{0,1,0,0.2})
|
||||
trigger.action.setMarkupTypeLine(self.assignedRangeZoneDrawID,2)
|
||||
end
|
||||
|
||||
if not self.assignedRangeZoneTextID then
|
||||
self.assignedRangeZoneTextID = Utils.getMarkID()
|
||||
trigger.action.textToAll(-1,self.assignedRangeZoneTextID,self.zonePolygon[1],{0,0,0,1},{1,1,1,0.5},12,false,'靶场: '..self.zoneName..' 当前使用: 无')
|
||||
else
|
||||
trigger.action.setMarkupText(self.assignedRangeZoneTextID, '靶场: '..self.zoneName..' 当前使用: 无')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -169,8 +149,10 @@ do
|
||||
Utils.Debug('playerData')
|
||||
Utils.Debug(self.playerData)
|
||||
end
|
||||
|
||||
|
||||
self.EndTraining({context = self,notShowResults = true})
|
||||
self.spawnedGroups = Utils.deepCopy(Range.SpawnedGroups_Default)
|
||||
self.playerData = Utils.deepCopy(Range.PlayerData_Default)
|
||||
end
|
||||
|
||||
function Range:Remove()
|
||||
@@ -212,19 +194,25 @@ do
|
||||
return polygon
|
||||
end
|
||||
|
||||
function Range:CanBindPlayer(object)
|
||||
function Range.CanBindPlayer(object)
|
||||
if not object then return end
|
||||
if not object:isExist() then return end
|
||||
if self.playerUnit then return false end
|
||||
|
||||
local playerPoint = object:getPoint()
|
||||
|
||||
if Range.DebugMod then
|
||||
local Distance = Utils.get2DDist(playerPoint,self.center)
|
||||
Utils.Debug('Distance: '..Distance)
|
||||
|
||||
for zoneName,zone in pairs(Range.AllRangeZones) do
|
||||
if Range.DebugMod then
|
||||
local Distance = Utils.get2DDist(playerPoint,zone.center)
|
||||
Utils.Debug(zoneName..' Distance: '..Distance)
|
||||
end
|
||||
|
||||
if Utils.get2DDist(playerPoint,zone.center) <= zone.radius+7000 then
|
||||
if zone.playerUnit then return end
|
||||
return zone
|
||||
end
|
||||
end
|
||||
|
||||
return Utils.get2DDist(playerPoint,self.center) <= 11000
|
||||
return
|
||||
end
|
||||
|
||||
function Range:CreatePlayerMenu(playerUnit)
|
||||
@@ -382,50 +370,43 @@ do
|
||||
Utils.Debug('Range:SpawnStatic, tCoalition: '..tCoalition..' spawnNumber: '..spawnNumber)
|
||||
end
|
||||
|
||||
local spawnPoint = self:GetRandSpawnPoint()
|
||||
|
||||
if not spawnPoint then
|
||||
spawnPoint = {x=self.center.x,y=self.center.z}
|
||||
end
|
||||
|
||||
local coalitionName = {
|
||||
[coalition.side.RED] = 'Red',
|
||||
[coalition.side.BLUE] = 'Blue',
|
||||
}
|
||||
|
||||
local spawnData = {}
|
||||
spawnData.name = self.zoneName..'_'..coalitionName[tCoalition]..'_Static'
|
||||
spawnData.task = "Ground Nothing"
|
||||
spawnData.units = {}
|
||||
local spawnedGroups = {}
|
||||
|
||||
for i=1,spawnNumber,1 do
|
||||
local unitSpawnPoint = Utils.getRandPointInCircle(spawnPoint,50)
|
||||
local spawnPoint = self:GetRandSpawnPoint()
|
||||
|
||||
local unitData = {}
|
||||
unitData.name = spawnData.name..'-'..i
|
||||
unitData.type = self.TargetTemplates[tCoalition][math.random(1,#self.TargetTemplates[tCoalition])]
|
||||
|
||||
unitData.x = unitSpawnPoint.x
|
||||
unitData.y = unitSpawnPoint.y
|
||||
|
||||
if i == 1 then
|
||||
unitData.x = spawnPoint.x
|
||||
unitData.y = spawnPoint.y
|
||||
if not spawnPoint then
|
||||
spawnPoint = {x=self.center.x,y=self.center.z}
|
||||
end
|
||||
|
||||
spawnData.units[i] = unitData
|
||||
end
|
||||
local coalitionName = {
|
||||
[coalition.side.RED] = 'Red',
|
||||
[coalition.side.BLUE] = 'Blue',
|
||||
}
|
||||
|
||||
local newGroup = self:SpawnGroup(tCoalition,spawnData)
|
||||
if not newGroup then return end
|
||||
if not newGroup:isExist() then return end
|
||||
local spawnData = {}
|
||||
spawnData.name = self.zoneName..'_'..coalitionName[tCoalition]..'_Static-'..i
|
||||
spawnData.task = "Ground Nothing"
|
||||
spawnData.units = {
|
||||
[1] = {
|
||||
x = spawnPoint.x,
|
||||
y = spawnPoint.y,
|
||||
name = spawnData.name..'-1',
|
||||
type = self.TargetTemplates[tCoalition][math.random(1,#self.TargetTemplates[tCoalition])]
|
||||
},
|
||||
}
|
||||
|
||||
local Controller = newGroup:getController()
|
||||
timer.scheduleFunction(self.setGroupGreen,Controller,timer.getTime()+1)
|
||||
local newGroup = self:SpawnGroup(tCoalition,spawnData)
|
||||
if not newGroup then return end
|
||||
if not newGroup:isExist() then return end
|
||||
|
||||
self.spawnedGroups[tCoalition].static = newGroup
|
||||
local Controller = newGroup:getController()
|
||||
timer.scheduleFunction(self.setGroupGreen,Controller,timer.getTime()+1)
|
||||
|
||||
return newGroup
|
||||
table.insert(self.spawnedGroups[tCoalition], newGroup)
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
function Range:SpawnMoving(tCoalition,spawnNumber)
|
||||
if not tCoalition or not spawnNumber then return end
|
||||
@@ -466,83 +447,78 @@ do
|
||||
-- },
|
||||
}
|
||||
|
||||
local path = pathTable[math.random(1,#pathTable)]
|
||||
|
||||
local spawnPoint = Utils.getRandPointInCircle(path.start,self.radius/2,100,path.startAngleMin+path.add,path.startAngleMin)
|
||||
|
||||
if not spawnPoint then
|
||||
spawnPoint = {x=self.center.x,y=self.center.z}
|
||||
end
|
||||
|
||||
local destinationPoint = Utils.getRandPointInCircle(path.destination,self.radius/2,100,path.destAngleMin+path.add,path.destAngleMin)
|
||||
|
||||
local coalitionName = {
|
||||
[coalition.side.RED] = 'Red',
|
||||
[coalition.side.BLUE] = 'Blue',
|
||||
}
|
||||
|
||||
local spawnData = {}
|
||||
spawnData.name = self.zoneName..'_'..coalitionName[tCoalition]..'_Moving'
|
||||
spawnData.task = "Ground Nothing"
|
||||
spawnData.units = {}
|
||||
|
||||
for i=1,spawnNumber,1 do
|
||||
local unitSpawnPoint = Utils.getRandPointInCircle(spawnPoint,50)
|
||||
local path = pathTable[math.random(1,#pathTable)]
|
||||
|
||||
local unitData = {}
|
||||
unitData.name = spawnData.name..'-'..i
|
||||
unitData.type = self.TargetTemplates[tCoalition][math.random(1,#self.TargetTemplates[tCoalition])]
|
||||
local spawnPoint = Utils.getRandPointInCircle(path.start,self.radius/2,100,path.startAngleMin+path.add,path.startAngleMin)
|
||||
|
||||
unitData.x = unitSpawnPoint.x
|
||||
unitData.y = unitSpawnPoint.y
|
||||
|
||||
if i == 1 then
|
||||
unitData.x = spawnPoint.x
|
||||
unitData.y = spawnPoint.y
|
||||
if not spawnPoint then
|
||||
spawnPoint = {x=self.center.x,y=self.center.z}
|
||||
end
|
||||
|
||||
local destinationPoint = Utils.getRandPointInCircle(path.destination,self.radius/2,100,path.destAngleMin+path.add,path.destAngleMin)
|
||||
|
||||
local coalitionName = {
|
||||
[coalition.side.RED] = 'Red',
|
||||
[coalition.side.BLUE] = 'Blue',
|
||||
}
|
||||
|
||||
local spawnData = {}
|
||||
spawnData.name = self.zoneName..'_'..coalitionName[tCoalition]..'_Moving-'..i
|
||||
spawnData.task = "Ground Nothing"
|
||||
spawnData.units = {
|
||||
[1] = {
|
||||
x = spawnPoint.x,
|
||||
y = spawnPoint.y,
|
||||
name = spawnData.name..'-1',
|
||||
type = self.TargetTemplates[tCoalition][math.random(1,#self.TargetTemplates[tCoalition])]
|
||||
},
|
||||
}
|
||||
|
||||
local newGroup = self:SpawnGroup(tCoalition,spawnData)
|
||||
if not newGroup then return end
|
||||
if not newGroup:isExist() then return end
|
||||
|
||||
local Controller = newGroup:getController()
|
||||
timer.scheduleFunction(self.setGroupGreen,Controller,timer.getTime()+1)
|
||||
|
||||
local speed = math.random(20/3.6,60/3.6)
|
||||
local MovingMission = self:getTaskOnRoad(spawnPoint,destinationPoint,speed)
|
||||
timer.scheduleFunction(function (vars)
|
||||
local Controller = vars.Controller
|
||||
local Mission = vars.Mission
|
||||
if not Controller or not Mission then return end
|
||||
|
||||
Controller:setTask(Mission)
|
||||
end,{Controller = Controller, Mission = MovingMission},timer.getTime()+1)
|
||||
|
||||
table.insert(self.spawnedGroups[tCoalition], newGroup)
|
||||
|
||||
spawnData.units[i] = unitData
|
||||
end
|
||||
|
||||
local newGroup = self:SpawnGroup(tCoalition,spawnData)
|
||||
if not newGroup then return end
|
||||
if not newGroup:isExist() then return end
|
||||
|
||||
local Controller = newGroup:getController()
|
||||
timer.scheduleFunction(self.setGroupGreen,Controller,timer.getTime()+1)
|
||||
|
||||
local speed = math.random(5/1.944,15/1.944)
|
||||
local MovingMission = self:getTaskOnRoad(spawnPoint,destinationPoint,speed)
|
||||
timer.scheduleFunction(function (vars)
|
||||
local Controller = vars.Controller
|
||||
local Mission = vars.Mission
|
||||
if not Controller or not Mission then return end
|
||||
|
||||
Controller:setTask(Mission)
|
||||
end,{Controller = Controller, Mission = MovingMission},timer.getTime()+1)
|
||||
|
||||
self.spawnedGroups[tCoalition].moving = newGroup
|
||||
|
||||
return newGroup
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function Range:DespawnTargets()
|
||||
self.spawnedGroups = self.spawnedGroups or Range.SpawnedGroups_Default
|
||||
self.spawnedGroups = self.spawnedGroups or Utils.deepCopy(Range.SpawnedGroups_Default)
|
||||
|
||||
if Range.DebugMod then
|
||||
Utils.Debug('Range.DespawnTargets')
|
||||
Utils.Debug('self.spawnedGroups: ')
|
||||
Utils.Debug(self.spawnedGroups)
|
||||
end
|
||||
|
||||
for coalition,types in pairs(self.spawnedGroups) do
|
||||
for type,group in pairs(types) do
|
||||
if group:isExist() then
|
||||
for tCoalition,groups in pairs(self.spawnedGroups) do
|
||||
for i,group in ipairs(groups) do
|
||||
if group and group.isExist then
|
||||
if group:isExist() then
|
||||
|
||||
if Range.DebugMod then
|
||||
Utils.Debug('destroy: '..group:getName())
|
||||
if Range.DebugMod then
|
||||
Utils.Debug('destroy: '..group:getName())
|
||||
end
|
||||
|
||||
group:destroy()
|
||||
end
|
||||
|
||||
group:destroy()
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -587,7 +563,7 @@ do
|
||||
end
|
||||
|
||||
-- 格式化输出(秒保留两位小数)
|
||||
return string.format("%s %d°%02d.%d\"", direction, degrees, minutes, seconds)
|
||||
return string.format("%s %02d°%02d.%03d\"", direction, degrees, minutes, seconds)
|
||||
end
|
||||
|
||||
--@param vec3
|
||||
@@ -604,7 +580,8 @@ do
|
||||
local lat,lon,alt = coord.LOtoLL(oriPoint)
|
||||
local MGRSTable = coord.LLtoMGRS(lat,lon)
|
||||
|
||||
return MGRSTable.UTMZone .. ' ' .. MGRSTable.MGRSDigraph .. ' ' .. MGRSTable.Easting .. ' ' .. MGRSTable.Northing
|
||||
-- return MGRSTable.UTMZone .. ' ' .. MGRSTable.MGRSDigraph .. ' ' .. MGRSTable.Easting .. ' ' .. MGRSTable.Northing
|
||||
return string.format('%03s %s %05s %05s',MGRSTable.UTMZone,MGRSTable.MGRSDigraph,MGRSTable.Easting,MGRSTable.Northing)
|
||||
end
|
||||
|
||||
if tType == 'latlon' or tType == 'LL' then
|
||||
@@ -622,7 +599,7 @@ do
|
||||
Utils.Debug('Range.SpawnTargets')
|
||||
end
|
||||
|
||||
self.playerData = Range.PlayerData_Default
|
||||
self.playerData = Utils.deepCopy(Range.PlayerData_Default)
|
||||
|
||||
local RedStaticNumber = math.random(Range.TotalStaticNum-Range.TotalBlueNum,Range.TotalStaticNum)
|
||||
local RedMovingNumber = Range.TotalRedNum-RedStaticNumber
|
||||
@@ -655,10 +632,10 @@ do
|
||||
msg = msg..' 训练开始, 开始时间: '..startTime..' (游戏内)\n'
|
||||
msg = msg..'==================================\n'
|
||||
msg = msg..' 靶场范围坐标:\n'
|
||||
msg = msg..' 1: MGRS: '..Range.Format_Coord(self.zonePolygon[1],'MGRS')..' | '..Range.Format_Coord(self.zonePolygon[1],'LL')..'\n'
|
||||
msg = msg..' 2: MGRS: '..Range.Format_Coord(self.zonePolygon[2],'MGRS')..' | '..Range.Format_Coord(self.zonePolygon[2],'LL')..'\n'
|
||||
msg = msg..' 3: MGRS: '..Range.Format_Coord(self.zonePolygon[3],'MGRS')..' | '..Range.Format_Coord(self.zonePolygon[3],'LL')..'\n'
|
||||
msg = msg..' 4: MGRS: '..Range.Format_Coord(self.zonePolygon[4],'MGRS')..' | '..Range.Format_Coord(self.zonePolygon[4],'LL')..'\n'
|
||||
msg = msg..'1: MGRS: '..Range.Format_Coord(self.zonePolygon[1],'MGRS')..' | '..Range.Format_Coord(self.zonePolygon[1],'LL')..'\n'
|
||||
msg = msg..'2: MGRS: '..Range.Format_Coord(self.zonePolygon[2],'MGRS')..' | '..Range.Format_Coord(self.zonePolygon[2],'LL')..'\n'
|
||||
msg = msg..'3: MGRS: '..Range.Format_Coord(self.zonePolygon[3],'MGRS')..' | '..Range.Format_Coord(self.zonePolygon[3],'LL')..'\n'
|
||||
msg = msg..'4: MGRS: '..Range.Format_Coord(self.zonePolygon[4],'MGRS')..' | '..Range.Format_Coord(self.zonePolygon[4],'LL')..'\n'
|
||||
trigger.action.outTextForUnit(playerUnit:getID(),msg,300,true)
|
||||
|
||||
local playerName = playerUnit:getPlayerName()
|
||||
@@ -668,7 +645,7 @@ do
|
||||
|
||||
--Sound
|
||||
if self.playSound then
|
||||
trigger.action.outSoundForGroup(playerUnit:getGroup():getID(),'audio/SFX/success.ogg')
|
||||
trigger.action.outSoundForUnit(playerUnit:getID(),'audio/SFX/success.ogg')
|
||||
end
|
||||
|
||||
if Range.DebugMod then
|
||||
@@ -773,24 +750,27 @@ do
|
||||
local enemyKilled = self.playerData.enemyKilled
|
||||
local allyKilled = self.playerData.allyKilled
|
||||
local cloesestEnemyDistanceTest = (math.floor(self.playerData.cloesestEnemyDistance*10)/10)..'米'
|
||||
if self.playerData.cloesestEnemyDistance > 15000 then
|
||||
if self.playerData.cloesestEnemyDistance >= 15000 then
|
||||
cloesestEnemyDistanceTest = '非常远.'
|
||||
end
|
||||
|
||||
local reason_text = '无'
|
||||
if reason then reason_text = reason end
|
||||
|
||||
local txt_file = io.open(dir_path.."/"..fildName..".txt","w")
|
||||
local txt_data = {
|
||||
['玩家'] = playerName,
|
||||
['开始时间'] = startTime,
|
||||
['持续时间'] = usedTime,
|
||||
['击杀敌方目标'] = enemyKilled,
|
||||
['击杀友方目标'] = allyKilled,
|
||||
['敌方最近时的距离'] = cloesestEnemyDistanceTest,
|
||||
['结束原因'] = reason_text,
|
||||
}
|
||||
txt_data = net.lua2json(txt_data)
|
||||
-- local txt_file = io.open(dir_path.."/"..fildName..".txt","w")
|
||||
-- local txt_data = {
|
||||
-- ['玩家'] = playerName,
|
||||
-- ['开始时间'] = startTime,
|
||||
-- ['持续时间'] = usedTime,
|
||||
-- ['击杀敌方目标'] = enemyKilled,
|
||||
-- ['击杀友方目标'] = allyKilled,
|
||||
-- ['敌方最近时的距离'] = cloesestEnemyDistanceTest,
|
||||
-- ['结束原因'] = reason_text,
|
||||
-- }
|
||||
-- txt_data = net.lua2json(txt_data)
|
||||
|
||||
-- txt_file:write(txt_data)
|
||||
-- txt_file:close()
|
||||
|
||||
local csv_file = io.open(dir_path.."/"..fildName..".csv","w")
|
||||
local csv_data = "玩家,开始时间,持续时间,击杀敌方目标,击杀友方目标,敌方最近时的距离,结束原因\n"
|
||||
@@ -803,8 +783,6 @@ do
|
||||
csv_data = csv_data..cloesestEnemyDistanceTest..','
|
||||
csv_data = csv_data..reason_text
|
||||
|
||||
-- txt_file:write(txt_data)
|
||||
txt_file:close()
|
||||
|
||||
csv_file:write(csv_data)
|
||||
csv_file:close()
|
||||
@@ -838,7 +816,7 @@ do
|
||||
msg = msg..'\n击杀友方目标: '..self.playerData.allyKilled
|
||||
|
||||
local cloesestEnemyDistanceTest = (math.floor(self.playerData.cloesestEnemyDistance*10)/10)..'米'
|
||||
if self.playerData.cloesestEnemyDistance > 15000 then
|
||||
if self.playerData.cloesestEnemyDistance >= 15000 then
|
||||
cloesestEnemyDistanceTest = '非常远.'
|
||||
end
|
||||
msg = msg..'\n敌方最近时的距离: '..cloesestEnemyDistanceTest
|
||||
@@ -853,17 +831,193 @@ do
|
||||
--Sound
|
||||
if self.playSound then
|
||||
if not Error then
|
||||
trigger.action.outSoundForGroup(playerUnit:getGroup():getID(),'audio/SFX/success.ogg')
|
||||
trigger.action.outSoundForUnit(playerUnit:getID(),'audio/SFX/success.ogg')
|
||||
end
|
||||
|
||||
if Error then
|
||||
trigger.action.outSoundForGroup(playerUnit:getGroup():getID(),'audio/SFX/fail.ogg')
|
||||
trigger.action.outSoundForUnit(playerUnit:getID(),'audio/SFX/fail.ogg')
|
||||
end
|
||||
end
|
||||
|
||||
self:writeFile(reason)
|
||||
end
|
||||
|
||||
local ev = {}
|
||||
function ev:onEvent(event)
|
||||
if event.id == world.event.S_EVENT_BIRTH then
|
||||
-- local rangeObj = self.listeningZone
|
||||
local object = event.initiator
|
||||
if not object:isExist() then return end
|
||||
|
||||
local SpawnPoint = object:getPoint()
|
||||
|
||||
if not object.getPlayerName then return end
|
||||
local playerName = object:getPlayerName()
|
||||
if not playerName then return end
|
||||
|
||||
local rangeZone = Range.CanBindPlayer(object)
|
||||
|
||||
if rangeZone then
|
||||
rangeZone.playerName = playerName
|
||||
|
||||
rangeZone:Init(object)
|
||||
trigger.action.outText('靶场: '..rangeZone.zoneName..' 已分配给玩家: '..playerName,10)
|
||||
|
||||
local msg = ''
|
||||
msg = msg..'===================================\n'
|
||||
msg = msg..' 靶场范围坐标:\n'
|
||||
msg = msg..'===================================\n'
|
||||
msg = msg..'1: MGRS: '..Range.Format_Coord(rangeZone.zonePolygon[1],'MGRS')..' | '..Range.Format_Coord(rangeZone.zonePolygon[1],'LL')..'\n'
|
||||
msg = msg..'2: MGRS: '..Range.Format_Coord(rangeZone.zonePolygon[2],'MGRS')..' | '..Range.Format_Coord(rangeZone.zonePolygon[2],'LL')..'\n'
|
||||
msg = msg..'3: MGRS: '..Range.Format_Coord(rangeZone.zonePolygon[3],'MGRS')..' | '..Range.Format_Coord(rangeZone.zonePolygon[3],'LL')..'\n'
|
||||
msg = msg..'4: MGRS: '..Range.Format_Coord(rangeZone.zonePolygon[4],'MGRS')..' | '..Range.Format_Coord(rangeZone.zonePolygon[4],'LL')..'\n'
|
||||
trigger.action.outTextForUnit(object:getID(),msg,300)
|
||||
|
||||
if Range.DebugMod then
|
||||
Utils.Debug('Bind player: '..playerName..' to Zone: '..rangeZone.zoneName)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if event.id == world.event.S_EVENT_PLAYER_LEAVE_UNIT then
|
||||
local initiator = event.initiator
|
||||
if not initiator then return end
|
||||
if not initiator:isExist() then return end
|
||||
if not initiator.getPlayerName then return end
|
||||
|
||||
local playerName = initiator:getPlayerName()
|
||||
if not playerName then return end
|
||||
|
||||
for zoneName,zone in pairs(Range.AllRangeZones) do
|
||||
if zone.playerName then
|
||||
if playerName == zone.playerName then
|
||||
|
||||
zone:Init()
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- if event.id == world.event.S_EVENT_KILL then
|
||||
-- local initiator = event.initiator
|
||||
-- if not initiator then return end
|
||||
-- if not initiator:isExist() then return end
|
||||
-- if not initiator.getPlayerName then return end
|
||||
|
||||
-- local playerName = initiator:getPlayerName()
|
||||
-- if not playerName then return end
|
||||
|
||||
-- local targetUnit = event.target
|
||||
-- if not targetUnit then return end
|
||||
-- local tCoalition = targetUnit:getCoalition()
|
||||
-- local pCoalition = initiator:getCoalition()
|
||||
|
||||
-- local otherSide = {
|
||||
-- [coalition.side.BLUE] = coalition.side.RED,
|
||||
-- [coalition.side.RED] = coalition.side.BLUE,
|
||||
-- }
|
||||
|
||||
-- for zoneName,zone in pairs(Range.AllRangeZones) do
|
||||
-- if zone.playerName then
|
||||
-- if playerName == zone.playerName then
|
||||
-- if tCoalition == otherSide[pCoalition] then
|
||||
-- zone.playerData.enemyKilled = zone.playerData.enemyKilled + 1
|
||||
|
||||
-- Utils.Debug('enemyKilled: '..zone.playerData.enemyKilled)
|
||||
-- if Range.DebugMod then
|
||||
-- end
|
||||
|
||||
-- return
|
||||
-- end
|
||||
-- if tCoalition == pCoalition then
|
||||
-- zone.playerData.allyKilled = zone.playerData.allyKilled + 1
|
||||
|
||||
-- Utils.Debug('allyKilled: '..zone.playerData.allyKilled)
|
||||
-- if Range.DebugMod then
|
||||
-- end
|
||||
|
||||
-- return
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
|
||||
-- end
|
||||
end
|
||||
world.addEventHandler(ev)
|
||||
|
||||
local hitEvent = {
|
||||
AddHandlerTimerDelay = 1, --Second
|
||||
}
|
||||
function hitEvent:AddEventHandler(Delay)
|
||||
local tDelay = Delay or self.AddHandlerTimerDelay
|
||||
|
||||
timer.scheduleFunction(function (eventHandler)
|
||||
world.addEventHandler(eventHandler)
|
||||
end,self,timer.getTime() + tDelay)
|
||||
end
|
||||
|
||||
function hitEvent:isUnitAlive(unit)
|
||||
if not unit then return false end
|
||||
|
||||
if not unit:isExist() then return false end
|
||||
|
||||
if unit:getLife() < 1 then return false end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function hitEvent:onEvent(event)
|
||||
if event.id == world.event.S_EVENT_HIT then
|
||||
local initiator = event.initiator
|
||||
if not initiator then return end
|
||||
if not initiator:isExist() then return end
|
||||
if not initiator.getPlayerName then return end
|
||||
|
||||
local playerName = initiator:getPlayerName()
|
||||
if not playerName then return end
|
||||
|
||||
local targetUnit = event.target
|
||||
if not targetUnit then return end
|
||||
local tCoalition = targetUnit:getCoalition()
|
||||
local pCoalition = initiator:getCoalition()
|
||||
|
||||
local otherSide = {
|
||||
[coalition.side.BLUE] = coalition.side.RED,
|
||||
[coalition.side.RED] = coalition.side.BLUE,
|
||||
}
|
||||
|
||||
for zoneName,zone in pairs(Range.AllRangeZones) do
|
||||
if zone.playerName then
|
||||
if playerName == zone.playerName then
|
||||
if tCoalition == otherSide[pCoalition] then
|
||||
if not self:isUnitAlive(targetUnit) then
|
||||
zone.playerData.enemyKilled = zone.playerData.enemyKilled + 1
|
||||
trigger.action.outTextForUnit(initiator:getID(),'击杀敌方目标: '..targetUnit:getTypeName(),2)
|
||||
|
||||
world.removeEventHandler(hitEvent)
|
||||
self:AddEventHandler()
|
||||
return
|
||||
end
|
||||
end
|
||||
if tCoalition == pCoalition then
|
||||
if not self:isUnitAlive(targetUnit) then
|
||||
zone.playerData.allyKilled = zone.playerData.allyKilled + 1
|
||||
trigger.action.outTextForUnit(initiator:getID(),'击杀友方目标: '..targetUnit:getTypeName(),2)
|
||||
|
||||
world.removeEventHandler(hitEvent)
|
||||
self:AddEventHandler()
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
world.addEventHandler(hitEvent)
|
||||
|
||||
function Range._MonitorFunction(vars,time)
|
||||
local self = vars.context
|
||||
local repeatTime = vars.repeatTime
|
||||
@@ -912,51 +1066,32 @@ do
|
||||
Utils.Debug(self.spawnedGroups)
|
||||
end
|
||||
|
||||
local enemyKillCount = 0
|
||||
local allyKillCount = 0
|
||||
for tCoalition,group in pairs(self.spawnedGroups[coalition.side.RED]) do
|
||||
if group and group.isExist then
|
||||
if group:isExist() then
|
||||
if Range.DebugMod then
|
||||
Utils.Debug('group: '..group:getName())
|
||||
end
|
||||
|
||||
for type,group in pairs(self.spawnedGroups[coalition.side.RED]) do
|
||||
if group:isExist() then
|
||||
if Range.DebugMod then
|
||||
Utils.Debug('group: '..group:getName())
|
||||
end
|
||||
for j, unit in ipairs(group:getUnits()) do
|
||||
if unit:isExist() then
|
||||
if Range.DebugMod then
|
||||
Utils.Debug('unit: '..unit:getName())
|
||||
end
|
||||
if unit:getLife() >= 1 then
|
||||
targetIsExist = true
|
||||
for j, unit in ipairs(group:getUnits()) do
|
||||
if unit:isExist() then
|
||||
if Range.DebugMod then
|
||||
Utils.Debug('unit: '..unit:getName())
|
||||
end
|
||||
if unit:getLife() >= 1 then
|
||||
targetIsExist = true
|
||||
|
||||
local targetPoint = unit:getPoint()
|
||||
local distance = Utils.get3DDist(playerPoint,targetPoint)
|
||||
if distance < self.playerData.cloesestEnemyDistance then
|
||||
self.playerData.cloesestEnemyDistance = distance
|
||||
local targetPoint = unit:getPoint()
|
||||
local distance = Utils.get3DDist(playerPoint,targetPoint)
|
||||
if distance < self.playerData.cloesestEnemyDistance then
|
||||
self.playerData.cloesestEnemyDistance = distance
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
enemyKillCount = enemyKillCount + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
self.enemyKilled = enemyKillCount
|
||||
|
||||
for type,group in pairs(self.spawnedGroups[coalition.side.BLUE]) do
|
||||
if group:isExist() then
|
||||
if Range.DebugMod then
|
||||
Utils.Debug('group: '..group:getName())
|
||||
end
|
||||
for j, unit in ipairs(group:getUnits()) do
|
||||
if unit:isExist() then
|
||||
if unit:getLife() < 1 then
|
||||
allyKillCount = allyKillCount + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
self.allyKilled = allyKillCount
|
||||
|
||||
-- 所有敌方目标被摧毁
|
||||
if not targetIsExist then
|
||||
@@ -965,7 +1100,7 @@ do
|
||||
end
|
||||
|
||||
-- 玩家飞行速度低于40节
|
||||
if playerPoint.y-land.getHeight({x=playerPoint.x,y=playerPoint.z}) > 10 then
|
||||
if playerPoint.y-land.getHeight({x=playerPoint.x,y=playerPoint.z}) > 100 then
|
||||
local playerSpeed = Utils.mag(playerUnit:getVelocity())
|
||||
if not playerSpeed then
|
||||
self:Init()
|
||||
@@ -977,7 +1112,7 @@ do
|
||||
|
||||
if self.playerSpeedHint <= 0 then
|
||||
if playerSpeed <= 40/1.944 then
|
||||
trigger.action.outTextForUnit(playerUnit:getID(),'============\n速度小于 40 节, 当前速度: '..(math.floor((playerSpeed/1.944)*10)/10)..'节\n============',5)
|
||||
trigger.action.outTextForUnit(playerUnit:getID(),'============\n速度小于 40 节, 当前速度: '..(math.floor((playerSpeed*1.944)*10)/10)..'节\n============',5)
|
||||
self.playerSpeedHint = Range.playerSpeedHintRepeatTime
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user