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 //// | ||||
Lint: ESLintBear (spaced-comment): `Expected space or tab after '//' in comment.` | |||||
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 //// | ||||
Lint: ESLintBear (spaced-comment) Expected space or tab after '//' in comment. Lint: ESLintBear (spaced-comment): `Expected space or tab after '//' in comment.` | |||||
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 34 Lines | for (var i = 0; i < this.suppressedList.length; ++i) | ||||
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)) | ||||
Lint: ESLintBear (operator-linebreak) '||' should be placed at the end of the line. Lint: ESLintBear (operator-linebreak): `'||' should be placed at the end of the line.` | |||||
Lint: JSHintBear Misleading line break before '||'; readers may interpret this as an expression boundary. Lint: JSHintBear: `Misleading line break before '||'; readers may interpret this as an expression boundary.` | |||||
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; | ||||
} | } | ||||
// If priority has increased for an existing event, then we already have it | // If priority has increased for an existing event, then we already have it | ||||
// in the suppression list | // in the suppression list | ||||
if (!isPriorityIncreased) | if (!isPriorityIncreased) | ||||
this.AddSuppression(event); | this.AddSuppression(event); | ||||
Engine.PostMessage(this.entity, MT_AttackDetected, { "player": playerID, "event": event }); | Engine.PostMessage(this.entity, MT_AttackDetected, { "player": playerID, "event": event }); | ||||
Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface).PushNotification({ | Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface).PushNotification({ | ||||
"type": "attack", | "type": "attack", | ||||
"target": target, | "target": target, | ||||
"players": [playerID], | "players": [playerID], | ||||
"attacker": atkOwner, | "attacker": atkOwner, | ||||
"targetIsDomesticAnimal": targetIsDomesticAnimal | "targetIsDomesticAnimal": targetIsDomesticAnimal | ||||
}); | }); | ||||
let soundGroup = "attacked"; | let soundGroup = AttackEffects.GetSound(type); | ||||
if (g_EffectReceiver[type] && g_EffectReceiver[type].sound) | |||||
soundGroup += '_' + g_EffectReceiver[type].sound; | |||||
if (attackerOwner === 0) | if (attackerOwner === 0) | ||||
soundGroup += "_gaia"; | soundGroup += "_gaia"; | ||||
PlaySound(soundGroup, target); | PlaySound(soundGroup, target); | ||||
}; | }; | ||||
AttackDetection.prototype.GetSuppressionTime = function() | AttackDetection.prototype.GetSuppressionTime = function() | ||||
{ | { | ||||
Show All 26 Lines |
Wildfire Games · Phabricator
Expected space or tab after '//' in comment.