Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Attack.js
Show First 20 Lines • Show All 547 Lines • ▼ Show 20 Lines | Attack.prototype.Attack = function(type, lateness) | ||||
// BuildingAI has its own attack routine. | // BuildingAI has its own attack routine. | ||||
if (!Engine.QueryInterface(this.entity, IID_BuildingAI)) | if (!Engine.QueryInterface(this.entity, IID_BuildingAI)) | ||||
this.PerformAttack(type, this.target); | this.PerformAttack(type, this.target); | ||||
if (!this.target) | if (!this.target) | ||||
return; | return; | ||||
// We check the range after the attack to facilitate chasing. | // NB: range checks are performed after the attack to facilitate chasing, | ||||
// as units aren't clever enough to offset the prepare time idleness. | |||||
// We'll spend this turn attacking. If we immediately stop on OutOfRange, | |||||
// the engine will stop the attacking animation earlier than expected, | |||||
// sounds will not play and the unit will start moving instantly. | |||||
// To avoid this, stop on the next turn - it will let the animation go through. | |||||
if (!this.IsTargetInRange(this.target, type)) | if (!this.IsTargetInRange(this.target, type)) | ||||
{ | { | ||||
this.StopAttacking("OutOfRange"); | // Reuse the attack timer for this. | ||||
cmpTimer.CancelTimer(this.timer); | |||||
this.timer = cmpTimer.SetTimeout(this.entity, IID_Attack, "StopAttacking", 1, "OutOfRange"); | |||||
return; | return; | ||||
} | } | ||||
if (this.resyncAnimation) | if (this.resyncAnimation) | ||||
{ | { | ||||
let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); | let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); | ||||
if (cmpVisual) | if (cmpVisual) | ||||
{ | { | ||||
let repeat = this.GetTimers(type).repeat; | let repeat = this.GetTimers(type).repeat; | ||||
cmpVisual.SetAnimationSyncRepeat(repeat); | cmpVisual.SetAnimationSyncRepeat(repeat); | ||||
cmpVisual.SetAnimationSyncOffset(repeat); | cmpVisual.SetAnimationSyncOffset(repeat); | ||||
} | } | ||||
delete this.resyncAnimation; | delete this.resyncAnimation; | ||||
} | } | ||||
}; | }; | ||||
/** | /** | ||||
* Called by CmpResistance when our target dies. | |||||
*/ | |||||
Attack.prototype.TargetDeath = function() | |||||
{ | |||||
// React next turn, same reasoning as OutOfRange in Attack | |||||
const cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | |||||
cmpTimer.CancelTimer(this.timer); | |||||
this.timer = cmpTimer.SetTimeout(this.entity, IID_Attack, "StopAttacking", 1, "TargetInvalidated"); | |||||
Freagarach: ? | |||||
}; | |||||
Not Done Inline Actions,,, Freagarach: ,,, | |||||
/** | |||||
* Attack the target entity. This should only be called after a successful range check, | * Attack the target entity. This should only be called after a successful range check, | ||||
* and should only be called after GetTimers().repeat msec has passed since the last | * and should only be called after GetTimers().repeat msec has passed since the last | ||||
* call to PerformAttack. | * call to PerformAttack. | ||||
*/ | */ | ||||
Attack.prototype.PerformAttack = function(type, target) | Attack.prototype.PerformAttack = function(type, target) | ||||
{ | { | ||||
let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | ||||
if (!cmpPosition || !cmpPosition.IsInWorld()) | if (!cmpPosition || !cmpPosition.IsInWorld()) | ||||
▲ Show 20 Lines • Show All 194 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
?