Bugfix on hit event

This commit is contained in:
Sven Van de Velde 2016-02-20 09:36:16 +01:00
parent 14a48901dc
commit 17118e5784

View File

@ -393,6 +393,7 @@ end
function DATABASE:OnHit( event ) function DATABASE:OnHit( event )
trace.f( self.ClassName, { event } ) trace.f( self.ClassName, { event } )
local InitUnit = nil
local InitUnitName = nil local InitUnitName = nil
local InitGroupName = nil local InitGroupName = nil
local InitPlayerName = nil local InitPlayerName = nil
@ -404,6 +405,7 @@ trace.f( self.ClassName, { event } )
local InitUnitCategory = nil local InitUnitCategory = nil
local InitUnitType = nil local InitUnitType = nil
local TargetUnit = nil
local TargetUnitName = nil local TargetUnitName = nil
local TargetGroupName = nil local TargetGroupName = nil
local TargetPlayerName = nil local TargetPlayerName = nil
@ -419,13 +421,15 @@ trace.f( self.ClassName, { event } )
if event.initiator and Object.getCategory(event.initiator) == Object.Category.UNIT then if event.initiator and Object.getCategory(event.initiator) == Object.Category.UNIT then
InitUnitName = event.initiator:getName() InitUnit = event.initiator
InitGroupName = Unit.getGroup(event.initiator):getName()
InitPlayerName = event.initiator:getPlayerName()
InitCoalition = Unit:getCoalition() InitUnitName = InitUnit:getName()
InitCategory = Unit:getCategory() InitGroupName = Unit.getGroup(InitUnit):getName()
InitType = event.initiator:getTypeName() InitPlayerName = InitUnit:getPlayerName()
InitCoalition = InitUnit:getCoalition()
InitCategory = InitUnit:getCategory()
InitType = InitUnit:getTypeName()
InitUnitCoalition = DATABASECoalition[InitCoalition] InitUnitCoalition = DATABASECoalition[InitCoalition]
InitUnitCategory = DATABASECategory[InitCategory] InitUnitCategory = DATABASECategory[InitCategory]
@ -437,13 +441,15 @@ trace.f( self.ClassName, { event } )
if event.target and Object.getCategory(event.target) == Object.Category.UNIT then if event.target and Object.getCategory(event.target) == Object.Category.UNIT then
TargetUnitName = event.target:getName() TargetUnit = event.target
TargetGroupName = Unit.getGroup(event.target):getName()
TargetPlayerName = event.target:getPlayerName()
TargetCoalition = Unit.getGroup(event.target):getCoalition() TargetUnitName = TargetUnit:getName()
TargetCategory = Unit.getGroup(event.target):getCategory() TargetGroupName = Unit.getGroup(TargetUnit):getName()
TargetType = event.target:getTypeName() TargetPlayerName = TargetUnit:getPlayerName()
TargetCoalition = TargetUnit:getCoalition()
TargetCategory = TargetUnit:getCategory()
TargetType = TargetUnit:getTypeName()
TargetUnitCoalition = DATABASECoalition[TargetCoalition] TargetUnitCoalition = DATABASECoalition[TargetCoalition]
TargetUnitCategory = DATABASECategory[TargetCategory] TargetUnitCategory = DATABASECategory[TargetCategory]
@ -453,10 +459,10 @@ trace.f( self.ClassName, { event } )
end end
if InitPlayerName ~= nil then -- It is a player that is hitting something if InitPlayerName ~= nil then -- It is a player that is hitting something
self:_AddPlayerFromUnit( event.initiator ) self:_AddPlayerFromUnit( InitUnit )
if self.Players[InitPlayerName] then -- This should normally not happen, but i'll test it anyway. if self.Players[InitPlayerName] then -- This should normally not happen, but i'll test it anyway.
if TargetPlayerName ~= nil then -- It is a player hitting another player ... if TargetPlayerName ~= nil then -- It is a player hitting another player ...
self:_AddPlayerFromUnit( event.target ) self:_AddPlayerFromUnit( TargetUnit )
self.Players[InitPlayerName].HitPlayers = self.Players[InitPlayerName].HitPlayers + 1 self.Players[InitPlayerName].HitPlayers = self.Players[InitPlayerName].HitPlayers + 1
end end