Changeset View
Standalone View
binaries/data/mods/public/simulation/components/Treasure.js
- This file was added.
function Treasure() {} | |||||||||||||||||||||||
Treasure.prototype.Schema = | |||||||||||||||||||||||
"<a:help>Provides a bonus when taken. E.g. a supply of resources.</a:help>" + | |||||||||||||||||||||||
"<a:example>" + | |||||||||||||||||||||||
"<Resources>" + | |||||||||||||||||||||||
"<Food>1000</Food>" + | |||||||||||||||||||||||
"</Resources>" + | |||||||||||||||||||||||
"</a:example>" + | |||||||||||||||||||||||
"<element name='CollectTime' a:help='Amount of milliseconds that it takes to collect this treasure.'>" + | |||||||||||||||||||||||
"<ref name='nonNegativeDecimal'/>" + | |||||||||||||||||||||||
"</element>" + | |||||||||||||||||||||||
"<optional>" + | |||||||||||||||||||||||
"<element name='Resources' a:help='Amount of resources that are in this.'>" + | |||||||||||||||||||||||
Resources.BuildSchema("positiveDecimal") + | |||||||||||||||||||||||
"</element>" + | |||||||||||||||||||||||
"</optional>"; | |||||||||||||||||||||||
Treasure.prototype.Init = function() | |||||||||||||||||||||||
{ | |||||||||||||||||||||||
this.CalculateReward(); | |||||||||||||||||||||||
}; | |||||||||||||||||||||||
Treasure.prototype.CalculateReward = function() | |||||||||||||||||||||||
{ | |||||||||||||||||||||||
Stan: s/Calculate/Compute? | |||||||||||||||||||||||
for (let resource in this.template.Resources) | |||||||||||||||||||||||
{ | |||||||||||||||||||||||
let amount = ApplyValueModificationsToEntity("Treasure/Resources/" + resource, this.template.Resources[resource], this.entity); | |||||||||||||||||||||||
if (amount) | |||||||||||||||||||||||
{ | |||||||||||||||||||||||
if (!this.resources) | |||||||||||||||||||||||
this.resources = {}; | |||||||||||||||||||||||
this.resources[resource] = amount; | |||||||||||||||||||||||
} | |||||||||||||||||||||||
} | |||||||||||||||||||||||
Done Inline Actions
Maybe, not sure if more readable. Stan: Maybe, not sure if more readable. | |||||||||||||||||||||||
}; | |||||||||||||||||||||||
/** | |||||||||||||||||||||||
* ToDo: generalise. | |||||||||||||||||||||||
Done Inline Actionsgeneralise? wraitii: generalise? | |||||||||||||||||||||||
Done Inline ActionsI guess the ToDo can be removed, but the idea is that treasures should not need to be limited to giving resources. Freagarach: I guess the ToDo can be removed, but the idea is that treasures should not need to be limited… | |||||||||||||||||||||||
* @return {Object} - The rewards given by this treasure. | |||||||||||||||||||||||
*/ | |||||||||||||||||||||||
Treasure.prototype.Reward = function() | |||||||||||||||||||||||
{ | |||||||||||||||||||||||
Done Inline ActionsGetReward? Stan: GetReward? | |||||||||||||||||||||||
Done Inline ActionsI'm not sure what the Get adds? Freagarach: I'm not sure what the `Get` adds? | |||||||||||||||||||||||
return this.resources || {}; | |||||||||||||||||||||||
}; | |||||||||||||||||||||||
/** | |||||||||||||||||||||||
* @return {number} - The time in miliseconds it takes to collect this treasure. | |||||||||||||||||||||||
*/ | |||||||||||||||||||||||
Treasure.prototype.Time = function() | |||||||||||||||||||||||
{ | |||||||||||||||||||||||
return +this.template.CollectTime; | |||||||||||||||||||||||
}; | |||||||||||||||||||||||
/** | |||||||||||||||||||||||
* @param {number} entity - The entity taking us. | |||||||||||||||||||||||
Done Inline Actionscollecting from us wraitii: `collecting from us` | |||||||||||||||||||||||
* @return {boolean} - Whether we are succesfully taken. | |||||||||||||||||||||||
Done Inline Actionsthe reward was granted? wraitii: `the reward was granted`? | |||||||||||||||||||||||
*/ | |||||||||||||||||||||||
Treasure.prototype.Collect = function(entity) | |||||||||||||||||||||||
Done Inline Actionswouldn't it be better to pass the player directly here? wraitii: wouldn't it be better to pass the player directly here? | |||||||||||||||||||||||
Done Inline ActionsSee comment above. Freagarach: See comment above. | |||||||||||||||||||||||
{ | |||||||||||||||||||||||
if (!Engine.QueryInterface(entity, IID_TreasureCollecter)) | |||||||||||||||||||||||
return false; | |||||||||||||||||||||||
Done Inline ActionsShould that be the responsibility of the caller? Stan: Should that be the responsibility of the caller? | |||||||||||||||||||||||
Done Inline ActionsYeah, I was pondering that, probably right. Freagarach: Yeah, I was pondering that, probably right. | |||||||||||||||||||||||
let cmpFogging = Engine.QueryInterface(this.entity, IID_Fogging); | |||||||||||||||||||||||
if (cmpFogging) | |||||||||||||||||||||||
cmpFogging.Activate(); | |||||||||||||||||||||||
let cmpStatisticsTracker = QueryOwnerInterface(this.entity, IID_StatisticsTracker); | |||||||||||||||||||||||
if (cmpStatisticsTracker) | |||||||||||||||||||||||
cmpStatisticsTracker.IncreaseTreasuresCollectedCounter(); | |||||||||||||||||||||||
let cmpPlayer = QueryOwnerInterface(entity); | |||||||||||||||||||||||
let cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); | |||||||||||||||||||||||
Done Inline ActionsDoes it make sense to collect treasures without players in the current state? If not could early return false maybe. Stan: Does it make sense to collect treasures without players in the current state? If not could… | |||||||||||||||||||||||
Done Inline ActionsTrue, can be added later if deemed a necessity. Freagarach: True, can be added later if deemed a necessity. | |||||||||||||||||||||||
if (cmpPlayer) | |||||||||||||||||||||||
{ | |||||||||||||||||||||||
if (this.resources) | |||||||||||||||||||||||
cmpPlayer.AddResources(this.resources); | |||||||||||||||||||||||
cmpTrigger.CallEvent("TreasureCollected", { | |||||||||||||||||||||||
"player": cmpPlayer.GetPlayerID(), | |||||||||||||||||||||||
Done Inline Actions
Stan: | |||||||||||||||||||||||
"treasure": this.entity | |||||||||||||||||||||||
Done Inline ActionsI'd suggest moving out of the world - might make isTaken redundant. wraitii: I'd suggest moving out of the world - might make isTaken redundant. | |||||||||||||||||||||||
Done Inline ActionsWho says a treasure needs to be InWorld for it to be taken? ;) Freagarach: Who says a treasure needs to be `InWorld` for it to be taken? ;) | |||||||||||||||||||||||
}); | |||||||||||||||||||||||
} | |||||||||||||||||||||||
Engine.DestroyEntity(this.entity); | |||||||||||||||||||||||
return true; | |||||||||||||||||||||||
}; | |||||||||||||||||||||||
Engine.RegisterComponentType(IID_Treasure, "Treasure", Treasure); | |||||||||||||||||||||||
Done Inline Actionsprobably need a msg param :) Stan: probably need a msg param :) |
s/Calculate/Compute?