Differential D3223 Diff 16124 ps/trunk/binaries/data/mods/public/simulation/components/Garrisonable.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/Garrisonable.js
Show All 18 Lines | |||||
* @return {boolean} - Whether garrisoning succeeded. | * @return {boolean} - Whether garrisoning succeeded. | ||||
*/ | */ | ||||
Garrisonable.prototype.Garrison = function(entity) | Garrisonable.prototype.Garrison = function(entity) | ||||
{ | { | ||||
if (this.holder) | if (this.holder) | ||||
return false; | return false; | ||||
this.holder = entity; | this.holder = entity; | ||||
let cmpProductionQueue = Engine.QueryInterface(this.entity, IID_ProductionQueue); | |||||
if (cmpProductionQueue) | |||||
cmpProductionQueue.PauseProduction(); | |||||
let cmpAura = Engine.QueryInterface(this.entity, IID_Auras); | |||||
if (cmpAura && cmpAura.HasGarrisonAura()) | |||||
cmpAura.ApplyGarrisonAura(entity); | |||||
let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | |||||
if (cmpPosition) | |||||
cmpPosition.MoveOutOfWorld(); | |||||
return true; | return true; | ||||
}; | }; | ||||
/** | /** | ||||
* Resets the garrisonHolder. | * @param {boolean} forced - Optionally whether the spawning is forced. | ||||
* @return {boolean} - Whether the ungarrisoning succeeded. | |||||
*/ | */ | ||||
Garrisonable.prototype.UnGarrison = function() | Garrisonable.prototype.UnGarrison = function(forced) | ||||
{ | |||||
let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | |||||
if (cmpPosition) | |||||
{ | { | ||||
let pos; | |||||
let cmpGarrisonHolder = Engine.QueryInterface(this.holder, IID_GarrisonHolder); | |||||
if (cmpGarrisonHolder) | |||||
pos = cmpGarrisonHolder.GetSpawnPosition(this.entity, forced); | |||||
if (!pos) | |||||
return false; | |||||
cmpPosition.JumpTo(pos.x, pos.z); | |||||
cmpPosition.SetHeightOffset(0); | |||||
let cmpHolderPosition = Engine.QueryInterface(this.holder, IID_Position); | |||||
if (cmpHolderPosition) | |||||
cmpPosition.SetYRotation(cmpHolderPosition.GetPosition().horizAngleTo(pos)); | |||||
} | |||||
let cmpUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI); | |||||
if (cmpUnitAI) | |||||
cmpUnitAI.Ungarrison(); | |||||
let cmpProductionQueue = Engine.QueryInterface(this.entity, IID_ProductionQueue); | |||||
if (cmpProductionQueue) | |||||
cmpProductionQueue.UnpauseProduction(); | |||||
let cmpAura = Engine.QueryInterface(this.entity, IID_Auras); | |||||
if (cmpAura && cmpAura.HasGarrisonAura()) | |||||
cmpAura.RemoveGarrisonAura(this.holder); | |||||
delete this.holder; | delete this.holder; | ||||
return true; | |||||
}; | }; | ||||
Engine.RegisterComponentType(IID_Garrisonable, "Garrisonable", Garrisonable); | Engine.RegisterComponentType(IID_Garrisonable, "Garrisonable", Garrisonable); |
Wildfire Games · Phabricator