mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Revised client and database logic. Still work in progress.
This commit is contained in:
122
Moose/Client.lua
122
Moose/Client.lua
@@ -51,7 +51,7 @@ function CLIENT:New( ClientName, ClientBriefing )
|
||||
local self = BASE:Inherit( self, BASE:New() )
|
||||
self:F( ClientName, ClientBriefing )
|
||||
|
||||
self.ClientName = ClientName
|
||||
self.ClientName = ClientName
|
||||
self:AddBriefing( ClientBriefing )
|
||||
self.MessageSwitch = true
|
||||
|
||||
@@ -132,9 +132,9 @@ end
|
||||
function CLIENT:IsAlive()
|
||||
self:F( self.ClientName )
|
||||
|
||||
local ClientDCSGroup = self:GetDCSGroup()
|
||||
local ClientUnit = Unit.getByName( self.ClientName )
|
||||
|
||||
if ClientDCSGroup then
|
||||
if ClientUnit and ClientUnit:isExist() then
|
||||
self:T("true")
|
||||
return true
|
||||
end
|
||||
@@ -176,6 +176,8 @@ function CLIENT:GetDCSGroup()
|
||||
-- return nil
|
||||
-- end
|
||||
|
||||
local ClientUnit = Unit.getByName( self.ClientName )
|
||||
|
||||
local CoalitionsData = { AlivePlayersRed = coalition.getPlayers( coalition.side.RED ), AlivePlayersBlue = coalition.getPlayers( coalition.side.BLUE ) }
|
||||
for CoalitionId, CoalitionData in pairs( CoalitionsData ) do
|
||||
self:T3( { "CoalitionData:", CoalitionData } )
|
||||
@@ -183,49 +185,49 @@ function CLIENT:GetDCSGroup()
|
||||
self:T3( { "UnitData:", UnitData } )
|
||||
if UnitData and UnitData:isExist() then
|
||||
|
||||
local ClientGroup = Group.getByName( self.ClientName )
|
||||
if ClientGroup then
|
||||
self:T3( "ClientGroup = " .. self.ClientName )
|
||||
if ClientGroup:isExist() then
|
||||
if ClientGroup:getID() == UnitData:getGroup():getID() then
|
||||
self:T3( "Normal logic" )
|
||||
self:T3( self.ClientName .. " : group found!" )
|
||||
return ClientGroup
|
||||
end
|
||||
else
|
||||
-- Now we need to resolve the bugs in DCS 1.5 ...
|
||||
-- Consult the database for the units of the Client Group. (ClientGroup:getUnits() returns nil)
|
||||
self:T3( "Bug 1.5 logic" )
|
||||
local ClientUnits = _DATABASE.Templates.Groups[self.ClientName].Units
|
||||
self:T3( { ClientUnits[1].name, env.getValueDictByKey(ClientUnits[1].name) } )
|
||||
for ClientUnitID, ClientUnitData in pairs( ClientUnits ) do
|
||||
self:T3( { tonumber(UnitData:getID()), ClientUnitData.unitId } )
|
||||
if tonumber(UnitData:getID()) == ClientUnitData.unitId then
|
||||
local ClientGroupTemplate = _DATABASE.Templates.Groups[self.ClientName].Template
|
||||
self.ClientID = ClientGroupTemplate.groupId
|
||||
self.ClientGroupUnit = UnitData
|
||||
self:T3( self.ClientName .. " : group found in bug 1.5 resolvement logic!" )
|
||||
return ClientGroup
|
||||
end
|
||||
end
|
||||
end
|
||||
-- else
|
||||
-- error( "Client " .. self.ClientName .. " not found!" )
|
||||
end
|
||||
--self:E(self.ClientName)
|
||||
if ClientUnit then
|
||||
local ClientGroup = ClientUnit:getGroup()
|
||||
if ClientGroup then
|
||||
self:T3( "ClientGroup = " .. self.ClientName )
|
||||
if ClientGroup:isExist() then
|
||||
if ClientGroup:getID() == UnitData:getGroup():getID() then
|
||||
self:T3( "Normal logic" )
|
||||
self:T3( self.ClientName .. " : group found!" )
|
||||
self.ClientGroupID = ClientGroup:getID()
|
||||
self.ClientGroupName = ClientGroup:getName()
|
||||
return ClientGroup
|
||||
end
|
||||
else
|
||||
-- Now we need to resolve the bugs in DCS 1.5 ...
|
||||
-- Consult the database for the units of the Client Group. (ClientGroup:getUnits() returns nil)
|
||||
self:T3( "Bug 1.5 logic" )
|
||||
local ClientGroupTemplate = _DATABASE.Templates.Units[self.ClientName].GroupTemplate
|
||||
self.ClientGroupID = ClientGroupTemplate.groupId
|
||||
self.ClientGroupName = _DATABASE.Templates.Units[self.ClientName].GroupName
|
||||
self:T3( self.ClientName .. " : group found in bug 1.5 resolvement logic!" )
|
||||
return ClientGroup
|
||||
end
|
||||
-- else
|
||||
-- error( "Client " .. self.ClientName .. " not found!" )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- For non player clients
|
||||
local ClientGroup = Group.getByName( self.ClientName )
|
||||
if ClientGroup then
|
||||
self:T3( "ClientGroup = " .. self.ClientName )
|
||||
if ClientGroup:isExist() then
|
||||
self:T3( "Normal logic" )
|
||||
self:T3( self.ClientName .. " : group found!" )
|
||||
return ClientGroup
|
||||
end
|
||||
end
|
||||
if ClientUnit then
|
||||
local ClientGroup = ClientUnit:getGroup()
|
||||
if ClientGroup then
|
||||
self:T3( "ClientGroup = " .. self.ClientName )
|
||||
if ClientGroup:isExist() then
|
||||
self:T3( "Normal logic" )
|
||||
self:T3( self.ClientName .. " : group found!" )
|
||||
return ClientGroup
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self.ClientGroupID = nil
|
||||
self.ClientGroupUnit = nil
|
||||
@@ -242,14 +244,9 @@ function CLIENT:GetClientGroupID()
|
||||
|
||||
if not self.ClientGroupID then
|
||||
local ClientGroup = self:GetDCSGroup()
|
||||
if ClientGroup and ClientGroup:isExist() then
|
||||
self.ClientGroupID = ClientGroup:getID()
|
||||
else
|
||||
self.ClientGroupID = self.ClientID
|
||||
end
|
||||
end
|
||||
|
||||
self:T( self.ClientGroupID )
|
||||
self:E( self.ClientGroupID ) -- Determined in GetDCSGroup()
|
||||
return self.ClientGroupID
|
||||
end
|
||||
|
||||
@@ -261,14 +258,9 @@ function CLIENT:GetClientGroupName()
|
||||
|
||||
if not self.ClientGroupName then
|
||||
local ClientGroup = self:GetDCSGroup()
|
||||
if ClientGroup and ClientGroup:isExist() then
|
||||
self.ClientGroupName = ClientGroup:getName()
|
||||
else
|
||||
self.ClientGroupName = self.ClientName
|
||||
end
|
||||
end
|
||||
|
||||
self:T( self.ClientGroupName )
|
||||
self:T( self.ClientGroupName ) -- Determined in GetDCSGroup()
|
||||
return self.ClientGroupName
|
||||
end
|
||||
|
||||
@@ -276,14 +268,15 @@ end
|
||||
-- @param #CLIENT self
|
||||
-- @return Unit#UNIT
|
||||
function CLIENT:GetClientGroupUnit()
|
||||
self:F()
|
||||
self:F2()
|
||||
|
||||
local ClientGroup = self:GetDCSGroup()
|
||||
|
||||
if ClientGroup and ClientGroup:isExist() then
|
||||
return UNIT:New( ClientGroup:getUnit(1) )
|
||||
else
|
||||
return UNIT:New( self.ClientGroupUnit )
|
||||
local ClientDCSUnit = Unit.getByName( self.ClientName )
|
||||
|
||||
self:T( self.ClientDCSUnit )
|
||||
if ClientDCSUnit and ClientDCSUnit:isExist() then
|
||||
local ClientUnit = _DATABASE.Units[ self.ClientName ]
|
||||
self:T2( ClientUnit )
|
||||
return ClientUnit
|
||||
end
|
||||
end
|
||||
|
||||
@@ -293,12 +286,11 @@ end
|
||||
function CLIENT:GetClientGroupDCSUnit()
|
||||
self:F2()
|
||||
|
||||
local ClientGroup = self:GetDCSGroup()
|
||||
local ClientDCSUnit = Unit.getByName( self.ClientName )
|
||||
|
||||
if ClientGroup and ClientGroup:isExist() then
|
||||
return ClientGroup:getUnit(1)
|
||||
else
|
||||
return self.ClientGroupUnit
|
||||
if ClientDCSUnit and ClientDCSUnit:isExist() then
|
||||
self:T2( ClientDCSUnit )
|
||||
return ClientDCSUnit
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user