Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/ResourceGatherer.js
Show All 19 Lines | ResourceGatherer.prototype.Schema = | ||||
"</a:example>" + | "</a:example>" + | ||||
"<element name='MaxDistance' a:help='Max resource-gathering distance'>" + | "<element name='MaxDistance' a:help='Max resource-gathering distance'>" + | ||||
"<ref name='positiveDecimal'/>" + | "<ref name='positiveDecimal'/>" + | ||||
"</element>" + | "</element>" + | ||||
"<element name='BaseSpeed' a:help='Base resource-gathering rate (in resource units per second)'>" + | "<element name='BaseSpeed' a:help='Base resource-gathering rate (in resource units per second)'>" + | ||||
"<ref name='positiveDecimal'/>" + | "<ref name='positiveDecimal'/>" + | ||||
"</element>" + | "</element>" + | ||||
"<element name='Rates' a:help='Per-resource-type gather rate multipliers. If a resource type is not specified then it cannot be gathered by this unit'>" + | "<element name='Rates' a:help='Per-resource-type gather rate multipliers. If a resource type is not specified then it cannot be gathered by this unit'>" + | ||||
Resources.BuildSchema("positiveDecimal", ["treasure"], true) + | Resources.BuildSchema("positiveDecimal", [], true) + | ||||
Stan: I guess we need to clean that function up | |||||
"</element>" + | "</element>" + | ||||
"<element name='Capacities' a:help='Per-resource-type maximum carrying capacity'>" + | "<element name='Capacities' a:help='Per-resource-type maximum carrying capacity'>" + | ||||
Resources.BuildSchema("positiveDecimal") + | Resources.BuildSchema("positiveDecimal") + | ||||
"</element>"; | "</element>"; | ||||
ResourceGatherer.prototype.Init = function() | ResourceGatherer.prototype.Init = function() | ||||
{ | { | ||||
this.carrying = {}; // { generic type: integer amount currently carried } | this.carrying = {}; // { generic type: integer amount currently carried } | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
this.baseSpeed = ApplyValueModificationsToEntity("ResourceGatherer/BaseSpeed", +this.template.BaseSpeed, this.entity); | this.baseSpeed = ApplyValueModificationsToEntity("ResourceGatherer/BaseSpeed", +this.template.BaseSpeed, this.entity); | ||||
this.rates = {}; | this.rates = {}; | ||||
for (let r in this.template.Rates) | for (let r in this.template.Rates) | ||||
{ | { | ||||
let type = r.split("."); | let type = r.split("."); | ||||
if (type[0] != "treasure" && type.length > 1 && !Resources.GetResource(type[0]).subtypes[type[1]]) | if (!Resources.GetResource(type[0]).subtypes[type[1]]) | ||||
{ | { | ||||
error("Resource subtype not found: " + type[0] + "." + type[1]); | error("Resource subtype not found: " + type[0] + "." + type[1]); | ||||
continue; | continue; | ||||
} | } | ||||
let rate = ApplyValueModificationsToEntity("ResourceGatherer/Rates/" + r, +this.template.Rates[r], this.entity); | let rate = ApplyValueModificationsToEntity("ResourceGatherer/Rates/" + r, +this.template.Rates[r], this.entity); | ||||
this.rates[r] = rate * this.baseSpeed; | this.rates[r] = rate * this.baseSpeed; | ||||
} | } | ||||
Show All 25 Lines | |||||
ResourceGatherer.prototype.GetRange = function() | ResourceGatherer.prototype.GetRange = function() | ||||
{ | { | ||||
return { "max": +this.template.MaxDistance, "min": 0 }; | return { "max": +this.template.MaxDistance, "min": 0 }; | ||||
// maybe this should depend on the unit or target or something? | // maybe this should depend on the unit or target or something? | ||||
}; | }; | ||||
/** | /** | ||||
* Try to gather treasure | |||||
* @return 'true' if treasure is successfully gathered, otherwise 'false' | |||||
*/ | |||||
ResourceGatherer.prototype.TryInstantGather = function(target) | |||||
{ | |||||
let cmpResourceSupply = Engine.QueryInterface(target, IID_ResourceSupply); | |||||
let type = cmpResourceSupply.GetType(); | |||||
if (type.generic != "treasure") | |||||
return false; | |||||
let status = cmpResourceSupply.TakeResources(cmpResourceSupply.GetCurrentAmount()); | |||||
let cmpPlayer = QueryOwnerInterface(this.entity, IID_Player); | |||||
if (cmpPlayer) | |||||
cmpPlayer.AddResource(type.specific, status.amount); | |||||
let cmpStatisticsTracker = QueryOwnerInterface(this.entity, IID_StatisticsTracker); | |||||
if (cmpStatisticsTracker) | |||||
cmpStatisticsTracker.IncreaseTreasuresCollectedCounter(); | |||||
let cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); | |||||
if (cmpTrigger && cmpPlayer) | |||||
cmpTrigger.CallEvent("TreasureCollected", { "player": cmpPlayer.GetPlayerID(), "type": type.specific, "amount": status.amount }); | |||||
return true; | |||||
}; | |||||
/** | |||||
* Gather from the target entity. This should only be called after a successful range check, | * Gather from the target entity. This should only be called after a successful range check, | ||||
* and if the target has a compatible ResourceSupply. | * and if the target has a compatible ResourceSupply. | ||||
* Call interval will be determined by gather rate, so always gather 1 amount when called. | * Call interval will be determined by gather rate, so always gather 1 amount when called. | ||||
*/ | */ | ||||
ResourceGatherer.prototype.PerformGather = function(target) | ResourceGatherer.prototype.PerformGather = function(target) | ||||
{ | { | ||||
if (!this.GetTargetGatherRate(target)) | if (!this.GetTargetGatherRate(target)) | ||||
return { "exhausted": true }; | return { "exhausted": true }; | ||||
▲ Show 20 Lines • Show All 211 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
I guess we need to clean that function up