Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/Attack.js
Show First 20 Lines • Show All 232 Lines • ▼ Show 20 Lines | Attack.prototype.CanAttack = function(target, wantedTypes) | ||||
let cmpIdentity = QueryMiragedInterface(target, IID_Identity); | let cmpIdentity = QueryMiragedInterface(target, IID_Identity); | ||||
if (!cmpIdentity) | if (!cmpIdentity) | ||||
return false; | return false; | ||||
let cmpHealth = QueryMiragedInterface(target, IID_Health); | let cmpHealth = QueryMiragedInterface(target, IID_Health); | ||||
let targetClasses = cmpIdentity.GetClassesList(); | let targetClasses = cmpIdentity.GetClassesList(); | ||||
if (targetClasses.indexOf("Domestic") != -1 && this.template.Slaughter && cmpHealth && cmpHealth.GetHitpoints() && | if (targetClasses.indexOf("Domestic") != -1 && this.template.Slaughter && cmpHealth && cmpHealth.GetHitpoints() && | ||||
(!wantedTypes || !wantedTypes.filter(wType => wType.indexOf("!") != 0).length)) | (!wantedTypes || !wantedTypes.filter(wType => wType.indexOf("!") != 0).length || wantedTypes.indexOf("Slaughter") != -1)) | ||||
return true; | return true; | ||||
let cmpEntityPlayer = QueryOwnerInterface(this.entity); | let cmpEntityPlayer = QueryOwnerInterface(this.entity); | ||||
let cmpTargetPlayer = QueryOwnerInterface(target); | let cmpTargetPlayer = QueryOwnerInterface(target); | ||||
if (!cmpTargetPlayer || !cmpEntityPlayer) | if (!cmpTargetPlayer || !cmpEntityPlayer) | ||||
return false; | return false; | ||||
let types = this.GetAttackTypes(wantedTypes); | let types = this.GetAttackTypes(wantedTypes); | ||||
▲ Show 20 Lines • Show All 197 Lines • ▼ Show 20 Lines | |||||
* | * | ||||
* @return {boolean} - Whether we started attacking. | * @return {boolean} - Whether we started attacking. | ||||
*/ | */ | ||||
Attack.prototype.StartAttacking = function(target, type, callerIID) | Attack.prototype.StartAttacking = function(target, type, callerIID) | ||||
{ | { | ||||
if (this.target) | if (this.target) | ||||
this.StopAttacking(); | this.StopAttacking(); | ||||
if (!this.CanAttack(target)) | if (!this.CanAttack(target, [type])) | ||||
return false; | return false; | ||||
let timings = this.GetTimers(type); | let timings = this.GetTimers(type); | ||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | ||||
// If the repeat time since the last attack hasn't elapsed, | // If the repeat time since the last attack hasn't elapsed, | ||||
// delay the action to avoid attacking too fast. | // delay the action to avoid attacking too fast. | ||||
let prepare = timings.prepare; | let prepare = timings.prepare; | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Attack our target entity. | * Attack our target entity. | ||||
* @param {string} data - The attack type to use. | * @param {string} data - The attack type to use. | ||||
* @param {number} lateness - The offset of the actual call and when it was expected. | * @param {number} lateness - The offset of the actual call and when it was expected. | ||||
*/ | */ | ||||
Attack.prototype.Attack = function(type, lateness) | Attack.prototype.Attack = function(type, lateness) | ||||
{ | { | ||||
if (!this.CanAttack(this.target)) | if (!this.CanAttack(this.target, [type])) | ||||
{ | { | ||||
this.StopAttacking("TargetInvalidated"); | this.StopAttacking("TargetInvalidated"); | ||||
return; | return; | ||||
} | } | ||||
// ToDo: Enable entities to keep facing a target. | // ToDo: Enable entities to keep facing a target. | ||||
Engine.QueryInterface(this.entity, IID_UnitAI)?.FaceTowardsTarget(this.target); | Engine.QueryInterface(this.entity, IID_UnitAI)?.FaceTowardsTarget(this.target); | ||||
▲ Show 20 Lines • Show All 236 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator