Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/AttackDetection.js
Show All 33 Lines | |||||
}; | }; | ||||
AttackDetection.prototype.UpdateSuppressionEvent = function(index, event) | AttackDetection.prototype.UpdateSuppressionEvent = function(index, event) | ||||
{ | { | ||||
this.suppressedList[index] = event; | this.suppressedList[index] = event; | ||||
this.ActivateTimer(); | this.ActivateTimer(); | ||||
}; | }; | ||||
//// Message handlers //// | // Message handlers | ||||
AttackDetection.prototype.OnGlobalAttacked = function(msg) | AttackDetection.prototype.OnGlobalAttacked = function(msg) | ||||
{ | { | ||||
var cmpPlayer = Engine.QueryInterface(this.entity, IID_Player); | var cmpPlayer = Engine.QueryInterface(this.entity, IID_Player); | ||||
var cmpOwnership = Engine.QueryInterface(msg.target, IID_Ownership); | var cmpOwnership = Engine.QueryInterface(msg.target, IID_Ownership); | ||||
if (cmpOwnership.GetOwner() != cmpPlayer.GetPlayerID()) | if (cmpOwnership.GetOwner() != cmpPlayer.GetPlayerID()) | ||||
return; | return; | ||||
Engine.PostMessage(msg.target, MT_MinimapPing); | Engine.PostMessage(msg.target, MT_MinimapPing); | ||||
this.AttackAlert(msg.target, msg.attacker, msg.type, msg.attackerOwner); | this.AttackAlert(msg.target, msg.attacker, msg.type, msg.attackerOwner); | ||||
}; | }; | ||||
//// External interface //// | // External interface | ||||
AttackDetection.prototype.AttackAlert = function(target, attacker, type, attackerOwner) | AttackDetection.prototype.AttackAlert = function(target, attacker, type, attackerOwner) | ||||
{ | { | ||||
let playerID = Engine.QueryInterface(this.entity, IID_Player).GetPlayerID(); | let playerID = Engine.QueryInterface(this.entity, IID_Player).GetPlayerID(); | ||||
// Don't register attacks dealt against other players | // Don't register attacks dealt against other players | ||||
if (Engine.QueryInterface(target, IID_Ownership).GetOwner() != playerID) | if (Engine.QueryInterface(target, IID_Ownership).GetOwner() != playerID) | ||||
return; | return; | ||||
Show All 33 Lines | for (var i = 0; i < this.suppressedList.length; ++i) | ||||
// then check if the element should be updated and return | // then check if the element should be updated and return | ||||
var dist = event.position.horizDistanceToSquared(element.position); | var dist = event.position.horizDistanceToSquared(element.position); | ||||
if (dist >= this.suppressionRangeSquared) | if (dist >= this.suppressionRangeSquared) | ||||
continue; | continue; | ||||
isPriorityIncreased = element.targetIsDomesticAnimal && !targetIsDomesticAnimal; | isPriorityIncreased = element.targetIsDomesticAnimal && !targetIsDomesticAnimal; | ||||
var isPriorityDescreased = !element.targetIsDomesticAnimal && targetIsDomesticAnimal; | var isPriorityDescreased = !element.targetIsDomesticAnimal && targetIsDomesticAnimal; | ||||
if (isPriorityIncreased | if (isPriorityIncreased || | ||||
|| (!isPriorityDescreased && dist < this.suppressionTransferRangeSquared)) | (!isPriorityDescreased && dist < this.suppressionTransferRangeSquared)) | ||||
this.UpdateSuppressionEvent(i, event); | this.UpdateSuppressionEvent(i, event); | ||||
// If priority has increased, exit the loop to send the upgraded notification below | // If priority has increased, exit the loop to send the upgraded notification below | ||||
if (isPriorityIncreased) | if (isPriorityIncreased) | ||||
break; | break; | ||||
return; | return; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator