Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Capturable.js
Show All 13 Lines | |||||
Capturable.prototype.Init = function() | Capturable.prototype.Init = function() | ||||
{ | { | ||||
this.maxCp = +this.template.CapturePoints; | this.maxCp = +this.template.CapturePoints; | ||||
this.garrisonRegenRate = +this.template.GarrisonRegenRate; | this.garrisonRegenRate = +this.template.GarrisonRegenRate; | ||||
this.regenRate = +this.template.RegenRate; | this.regenRate = +this.template.RegenRate; | ||||
this.cp = []; | this.cp = []; | ||||
}; | }; | ||||
//// Interface functions //// | //// Interface functions //// | ||||
Lint: ESLintBear (spaced-comment): `Expected space or tab after '//' in comment.` | |||||
/** | /** | ||||
* Returns the current capture points array. | * Returns the current capture points array. | ||||
*/ | */ | ||||
Capturable.prototype.GetCapturePoints = function() | Capturable.prototype.GetCapturePoints = function() | ||||
{ | { | ||||
return this.cp; | return this.cp; | ||||
}; | }; | ||||
Show All 17 Lines | |||||
Capturable.prototype.SetCapturePoints = function(capturePointsArray) | Capturable.prototype.SetCapturePoints = function(capturePointsArray) | ||||
{ | { | ||||
this.cp = capturePointsArray; | this.cp = capturePointsArray; | ||||
}; | }; | ||||
/** | /** | ||||
* Compute the amount of capture points to be reduced and reduce them. | * Compute the amount of capture points to be reduced and reduce them. | ||||
* @param {number} effectData - Base number of capture points to be taken. | * @param {number} effectData - Base number of capture points to be taken. | ||||
* @param {number} captor - The entity capturing us. | * @param {number} captorData - Data concerning the captor of the form: { "entity" number, "owner": number }. | ||||
* @param {number} captorOwner - Owner of the captor. | |||||
* @param {number} bonusMultiplier - Multiplier to be multiplied with effectData. | * @param {number} bonusMultiplier - Multiplier to be multiplied with effectData. | ||||
* @return {Object} - Object of the form { "captureChange": number }, where number indicates the actual amount of capture points taken. | * @return {Object} - Object of the form { "captureChange": number }, where number indicates the actual amount of capture points taken. | ||||
*/ | */ | ||||
Capturable.prototype.Capture = function(effectData, captor, captorOwner, bonusMultiplier) | Capturable.prototype.Capture = function(effectData, captorData, bonusMultiplier) | ||||
{ | { | ||||
let cmpHealth = Engine.QueryInterface(this.entity, IID_Health); | let cmpHealth = Engine.QueryInterface(this.entity, IID_Health); | ||||
let hitpoints = cmpHealth && cmpHealth.GetHitpoints(); | let hitpoints = cmpHealth && cmpHealth.GetHitpoints(); | ||||
if (captorOwner == INVALID_PLAYER || !this.CanCapture(captorOwner) || !hitpoints) | if (captorData.owner == INVALID_PLAYER || !this.CanCapture(captorData.owner) || !hitpoints) | ||||
return {}; | return {}; | ||||
bonusMultiplier /= 0.1 + 0.9 * hitpoints / cmpHealth.GetMaxHitpoints(); | bonusMultiplier /= 0.1 + 0.9 * hitpoints / cmpHealth.GetMaxHitpoints(); | ||||
let total = Attacking.GetTotalAttackEffects({ "Capture": effectData }, "Capture") * bonusMultiplier; | let total = Attacking.GetTotalAttackEffects({ "Capture": effectData }, "Capture") * bonusMultiplier; | ||||
let change = this.Reduce(total, captorOwner); | let change = this.Reduce(total, captorData.owner); | ||||
// TODO: implement loot | // TODO: implement loot | ||||
return { "captureChange": change }; | return { "captureChange": change }; | ||||
}; | }; | ||||
/** | /** | ||||
* Reduces the amount of capture points of an entity, | * Reduces the amount of capture points of an entity, | ||||
* in favour of the player of the source. | * in favour of the player of the source. | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | Capturable.prototype.CanCapture = function(playerID) | ||||
let cp = this.GetCapturePoints(); | let cp = this.GetCapturePoints(); | ||||
let sourceEnemyCp = 0; | let sourceEnemyCp = 0; | ||||
for (let i in this.GetCapturePoints()) | for (let i in this.GetCapturePoints()) | ||||
if (cmpPlayerSource.IsEnemy(i)) | if (cmpPlayerSource.IsEnemy(i)) | ||||
sourceEnemyCp += cp[i]; | sourceEnemyCp += cp[i]; | ||||
return sourceEnemyCp > 0; | return sourceEnemyCp > 0; | ||||
}; | }; | ||||
//// Private functions //// | //// Private functions //// | ||||
Lint: ESLintBear (spaced-comment) Expected space or tab after '//' in comment. Lint: ESLintBear (spaced-comment): `Expected space or tab after '//' in comment.` | |||||
/** | /** | ||||
* This has to be called whenever the capture points are changed. | * This has to be called whenever the capture points are changed. | ||||
* It notifies other components of the change, and switches ownership when needed. | * It notifies other components of the change, and switches ownership when needed. | ||||
*/ | */ | ||||
Capturable.prototype.RegisterCapturePointsChanged = function() | Capturable.prototype.RegisterCapturePointsChanged = function() | ||||
{ | { | ||||
let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); | let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); | ||||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | if (oldMaxCp != this.maxCp) | ||||
if (!dontSendCpChanged) | if (!dontSendCpChanged) | ||||
Engine.PostMessage(this.entity, MT_CapturePointsChanged, { "capturePoints": this.cp }); | Engine.PostMessage(this.entity, MT_CapturePointsChanged, { "capturePoints": this.cp }); | ||||
} | } | ||||
if (oldGarrisonRegenRate != this.garrisonRegenRate || oldRegenRate != this.regenRate) | if (oldGarrisonRegenRate != this.garrisonRegenRate || oldRegenRate != this.regenRate) | ||||
this.CheckTimer(); | this.CheckTimer(); | ||||
}; | }; | ||||
//// Message Listeners //// | //// Message Listeners //// | ||||
Lint: ESLintBear (spaced-comment) Expected space or tab after '//' in comment. Lint: ESLintBear (spaced-comment): `Expected space or tab after '//' in comment.` | |||||
Capturable.prototype.OnValueModification = function(msg) | Capturable.prototype.OnValueModification = function(msg) | ||||
{ | { | ||||
if (msg.component == "Capturable") | if (msg.component == "Capturable") | ||||
this.UpdateCachedValuesAndNotify(); | this.UpdateCachedValuesAndNotify(); | ||||
}; | }; | ||||
Capturable.prototype.OnGarrisonedUnitsChanged = function(msg) | Capturable.prototype.OnGarrisonedUnitsChanged = function(msg) | ||||
▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Expected space or tab after '//' in comment.