Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/ResourceGatherer.js
Show First 20 Lines • Show All 187 Lines • ▼ Show 20 Lines | if (!cmpResourceSupply || !cmpResourceSupply.AddActiveGatherer(this.entity)) | ||||
return false; | return false; | ||||
let resourceType = cmpResourceSupply.GetType(); | let resourceType = cmpResourceSupply.GetType(); | ||||
// If we've already got some resources but they're the wrong type, | // If we've already got some resources but they're the wrong type, | ||||
// drop them first to ensure we're only ever carrying one type. | // drop them first to ensure we're only ever carrying one type. | ||||
if (this.IsCarryingAnythingExcept(resourceType.generic)) | if (this.IsCarryingAnythingExcept(resourceType.generic)) | ||||
this.DropResources(); | this.DropResources(); | ||||
this.AddToPlayerCounter(resourceType.generic); | |||||
let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); | let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); | ||||
if (cmpVisual) | if (cmpVisual) | ||||
cmpVisual.SelectAnimation("gather_" + resourceType.specific, false, 1.0); | cmpVisual.SelectAnimation("gather_" + resourceType.specific, false, 1.0); | ||||
// Calculate timing based on gather rates. | // Calculate timing based on gather rates. | ||||
// This allows the gather rate to control how often we gather, instead of how much. | // This allows the gather rate to control how often we gather, instead of how much. | ||||
let timing = 1000 / rate; | let timing = 1000 / rate; | ||||
Show All 17 Lines | ResourceGatherer.prototype.StopGathering = function(reason) | ||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | ||||
cmpTimer.CancelTimer(this.timer); | cmpTimer.CancelTimer(this.timer); | ||||
delete this.timer; | delete this.timer; | ||||
let cmpResourceSupply = Engine.QueryInterface(this.target, IID_ResourceSupply); | let cmpResourceSupply = Engine.QueryInterface(this.target, IID_ResourceSupply); | ||||
if (cmpResourceSupply) | if (cmpResourceSupply) | ||||
cmpResourceSupply.RemoveGatherer(this.entity); | cmpResourceSupply.RemoveGatherer(this.entity); | ||||
this.RemoveFromPlayerCounter(); | |||||
delete this.target; | delete this.target; | ||||
let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); | let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); | ||||
if (cmpVisual) | if (cmpVisual) | ||||
cmpVisual.SelectAnimation("idle", false, 1.0); | cmpVisual.SelectAnimation("idle", false, 1.0); | ||||
// The callerIID component may start again, | // The callerIID component may start again, | ||||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
ResourceGatherer.prototype.DropResources = function() | ResourceGatherer.prototype.DropResources = function() | ||||
{ | { | ||||
this.carrying = {}; | this.carrying = {}; | ||||
Engine.PostMessage(this.entity, MT_ResourceCarryingChanged, { "to": this.GetCarryingStatus() }); | Engine.PostMessage(this.entity, MT_ResourceCarryingChanged, { "to": this.GetCarryingStatus() }); | ||||
}; | }; | ||||
/** | |||||
* @return {string} - A generic resource type if we were tasked to gather. | |||||
*/ | |||||
ResourceGatherer.prototype.LastGatheredType = function() | |||||
{ | |||||
return this.lastGathered; | |||||
}; | |||||
/** | /** | ||||
* @param {string} type - A generic resource type. | * @param {string} type - A generic resource type. | ||||
*/ | */ | ||||
ResourceGatherer.prototype.AddToPlayerCounter = function(type) | ResourceGatherer.prototype.AddToPlayerCounter = function(type) | ||||
{ | { | ||||
// We need to be removed from the player counter first. | // We need to be removed from the player counter first. | ||||
if (this.lastGathered) | if (this.lastGathered) | ||||
▲ Show 20 Lines • Show All 85 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator