Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Capturable.js
Show All 33 Lines | Capturable.prototype.GetMaxCapturePoints = function() | ||||
return this.maxCapturePoints; | return this.maxCapturePoints; | ||||
}; | }; | ||||
Capturable.prototype.GetGarrisonRegenRate = function() | Capturable.prototype.GetGarrisonRegenRate = function() | ||||
{ | { | ||||
return this.garrisonRegenRate; | return this.garrisonRegenRate; | ||||
}; | }; | ||||
Capturable.prototype.GetRelativeCapture = function(effectData, effectType, bonusMultiplier, attackerOwner) | |||||
{ | |||||
return this.CanCapture(attackerOwner) ? | |||||
AttackHelper.GetTotalAttackEffects( | |||||
this.entity, | |||||
effectData, | |||||
effectType, | |||||
bonusMultiplier, | |||||
QueryMiragedInterface(this.entity, IID_Resistance) | |||||
) / this.maxCapturePoints : | |||||
0; | |||||
}; | |||||
/** | /** | ||||
* Set the new capture points, used for cloning entities. | * Set the new capture points, used for cloning entities. | ||||
* The caller should assure that the sum of capture points | * The caller should assure that the sum of capture points | ||||
* matches the max. | * matches the max. | ||||
* @param {number[]} - Array with for all players the new value. | * @param {number[]} - Array with for all players the new value. | ||||
*/ | */ | ||||
Capturable.prototype.SetCapturePoints = function(capturePointsArray) | Capturable.prototype.SetCapturePoints = function(capturePointsArray) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Check if the source can (re)capture points from this building. | * Check if the source can (re)capture points from this building. | ||||
* @param {number} playerID - PlayerID of the source. | * @param {number} playerID - PlayerID of the source. | ||||
* @return {boolean} - Whether the source can (re)capture points from this building. | * @return {boolean} - Whether the source can (re)capture points from this building. | ||||
*/ | */ | ||||
Capturable.prototype.CanCapture = function(playerID) | Capturable.prototype.CanCapture = function(playerID) | ||||
{ | { | ||||
let cmpPlayerSource = QueryPlayerIDInterface(playerID); | let cmpPlayerSource = QueryPlayerIDInterface(playerID); | ||||
if (!cmpPlayerSource) | if (!cmpPlayerSource) | ||||
warn(playerID + " has no player component defined on its id."); | warn(playerID + " has no player component defined on its id."); | ||||
let cmpResistance = QueryMiragedInterface(this.entity, IID_Resistance); | |||||
if (cmpResistance && cmpResistance.IsInvulnerable()) | |||||
return false; | |||||
let capturePoints = this.GetCapturePoints(); | let capturePoints = this.GetCapturePoints(); | ||||
let sourceEnemyCapturePoints = 0; | let sourceEnemyCapturePoints = 0; | ||||
for (let i in this.GetCapturePoints()) | for (let i in this.GetCapturePoints()) | ||||
if (cmpPlayerSource.IsEnemy(i)) | if (cmpPlayerSource.IsEnemy(i)) | ||||
sourceEnemyCapturePoints += capturePoints[i]; | sourceEnemyCapturePoints += capturePoints[i]; | ||||
return sourceEnemyCapturePoints > 0; | return sourceEnemyCapturePoints > 0; | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 212 Lines • ▼ Show 20 Lines | if (cmpOwnership && (cmpOwnership.GetOwner() == INVALID_PLAYER || | ||||
return; | return; | ||||
this.capturePoints[0] += this.capturePoints[msg.playerId]; | this.capturePoints[0] += this.capturePoints[msg.playerId]; | ||||
this.capturePoints[msg.playerId] = 0; | this.capturePoints[msg.playerId] = 0; | ||||
this.RegisterCapturePointsChanged(); | this.RegisterCapturePointsChanged(); | ||||
this.CheckTimer(); | this.CheckTimer(); | ||||
}; | }; | ||||
function CapturableMirage() {} | function CapturableMirage() {} | ||||
CapturableMirage.prototype.Init = function(cmpCapturable) | CapturableMirage.prototype.Init = function(cmpCapturable, miragedEnt) | ||||
{ | { | ||||
this.entity = miragedEnt; | |||||
this.capturePoints = clone(cmpCapturable.GetCapturePoints()); | this.capturePoints = clone(cmpCapturable.GetCapturePoints()); | ||||
this.maxCapturePoints = cmpCapturable.GetMaxCapturePoints(); | this.maxCapturePoints = cmpCapturable.GetMaxCapturePoints(); | ||||
}; | }; | ||||
CapturableMirage.prototype.GetCapturePoints = function() { return this.capturePoints; }; | CapturableMirage.prototype.GetCapturePoints = function() { return this.capturePoints; }; | ||||
CapturableMirage.prototype.GetMaxCapturePoints = function() { return this.maxCapturePoints; }; | CapturableMirage.prototype.GetMaxCapturePoints = function() { return this.maxCapturePoints; }; | ||||
CapturableMirage.prototype.CanCapture = Capturable.prototype.CanCapture; | CapturableMirage.prototype.CanCapture = Capturable.prototype.CanCapture; | ||||
CapturableMirage.prototype.GetRelativeCapture = Capturable.prototype.GetRelativeCapture; | |||||
Engine.RegisterGlobal("CapturableMirage", CapturableMirage); | Engine.RegisterGlobal("CapturableMirage", CapturableMirage); | ||||
Capturable.prototype.Mirage = function() | Capturable.prototype.Mirage = function(miragedEnt) | ||||
{ | { | ||||
let mirage = new CapturableMirage(); | let mirage = new CapturableMirage(); | ||||
mirage.Init(this); | mirage.Init(this, miragedEnt); | ||||
return mirage; | return mirage; | ||||
}; | }; | ||||
Engine.RegisterComponentType(IID_Capturable, "Capturable", Capturable); | Engine.RegisterComponentType(IID_Capturable, "Capturable", Capturable); |
Wildfire Games · Phabricator