Changeset View
Standalone View
binaries/data/mods/public/simulation/components/Status.js
function Status() {} | |||||
Status.prototype.Init = function() | |||||
{ | |||||
this.currentStatuses = {}; | |||||
Stan: Any reason for using an object over an array ? | |||||
wraitiiAuthorUnsubmitted Done Inline ActionsWe use it such this.currentStatuses[statusName] so an array wouldn't do. wraitii: We use it such `this.currentStatuses[statusName]` so an array wouldn't do. | |||||
StanUnsubmitted Done Inline ActionsKey can be a string no ? Stan: Key can be a string no ? | |||||
Mate-86Unsubmitted Done Inline Actionsan array with string key is called object :) Mate-86: an array with string key is called object :) | |||||
StanUnsubmitted Not Done Inline ActionsThat can also be a dictionnary or a map :) Stan: That can also be a dictionnary or a map :) | |||||
wraitiiAuthorUnsubmitted Not Done Inline ActionsYea in JS you basically have Arrays, which can only be accessed by an index (numeric), and objects, which are basically everything else, and can be accessed by strings. However since JS is weakly typed, most things can get converted to strings. In this instance we use an object as a Map, but the Map() Javascript interface is a tad annoying, so I'd rather not use it unless the performance feels necessary (and it doesn't here). wraitii: Yea in JS you basically have Arrays, which can only be accessed by an index (numeric), and… | |||||
StanUnsubmitted Done Inline ActionsAh I see Array["StringIndex"] = Array.StringIndex which is not part of the array, but of the object containing said array, like Array["length"]. Thanks. Stan: Ah I see
Array["StringIndex"] = Array.StringIndex which is not part of the array, but of the… | |||||
}; | |||||
Done Inline ActionsReplace this with something like: this.currentStatuses = {} Then for each status we get added, you'll have something like this.currentStatuses["burn"] = { "duration" : X, "damage": Y } wraitii: Replace this with something like:
```this.currentStatuses = {}```
Then for each status we get… | |||||
Done Inline ActionsMissing semicolon this.currentStatuses = {}; Stan: Missing semicolon
```lang=js
this.currentStatuses = {};
``` | |||||
Done Inline Actionsmissing semicolon after brace. Stan: missing semicolon after brace. | |||||
Status.prototype.StartEffects = function(statusEffects) | |||||
{ | |||||
Done Inline ActionsStartEffect should only start one effect. You should call a "StartEffects" function from Damage.js, which calls StartEffect(statusName, statusData) for every key in statusEffects. wraitii: StartEffect should only start one effect.
You should call a "StartEffects" function from… | |||||
for (let effect in statusEffects) | |||||
this.StartEffect(effect, statusEffects[effect]); | |||||
}; | |||||
Done Inline Actionsmissing semicolon after brace. Stan: missing semicolon after brace. | |||||
Done Inline ActionsThanks for noting this! Shouldn't be there a lint check done by Jenkins for this? Mate-86: Thanks for noting this! Shouldn't be there a lint check done by Jenkins for this? | |||||
Done Inline ActionsThere is. It's in the log vulcan posts as comment It's long though cause you are editing offending files :) Stan: There is. It's in the log vulcan posts as comment It's long though cause you are editing… | |||||
Status.prototype.StartEffect = function(statusName, data) | |||||
{ | |||||
if (this.currentStatuses[statusName]) | |||||
return; | |||||
Done Inline Actionsyou need to reset it back to false when effect ends Silier: you need to reset it back to false when effect ends | |||||
this.currentStatuses[statusName] = {}; | |||||
let status = this.currentStatuses[statusName]; | |||||
status.duration = +data.Duration; | |||||
status.interval = +data.Interval; | |||||
Done Inline ActionsInstead of hardcoding this to burning, set this data on this.currentStatuses[statusName]. This way we can have several statuses at once. wraitii: Instead of hardcoding this to burning, set this data on `this.currentStatuses[statusName]`. | |||||
status.damage = +data.Damage; | |||||
status.timeElapsed = 0; | |||||
status.firstTime = true; | |||||
Done Inline ActionsSince we can have several statuses, you need to specify which to apply, so instead of passing null as data pass the status nam (the key that you used for currentStatuses) wraitii: Since we can have several statuses, you need to specify which to apply, so instead of passing… | |||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | |||||
status.timer = cmpTimer.SetInterval(this.entity, IID_Status, "ExecuteEffect", 0, +status.interval, statusName); | |||||
}; | |||||
Done Inline Actionsmissing semicolon after brace. Stan: missing semicolon after brace. | |||||
Status.prototype.StopEffect = function(statusName) { | |||||
Done Inline Actions/** * Returns time since the start of the game in milliseconds. */ Timer.prototype.GetTime = function() what you are calling is not even defined :) Silier: ```
/**
* Returns time since the start of the game in milliseconds.
*/
Timer.prototype. | |||||
Done Inline ActionsExecuteEffect will receive data, lateness as parameters. You know how often it gets called (interval). What you should do is count the time yourself (status.timeElapsed += status.interval + lateness) and compare that with status.duration (where status is this.currentStatuses[data.status]) wraitii: ExecuteEffect will receive `data, lateness` as parameters. You know how often it gets called… | |||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | |||||
cmpTimer.CancelTimer(this.currentStatuses[statusName].timer); | |||||
SilierUnsubmitted Done Inline Actionsyou should check if the status is defined, one can call this function twice by accident Silier: you should check if the status is defined, one can call this function twice by accident | |||||
this.currentStatuses[statusName] = undefined; | |||||
return; | |||||
SilierUnsubmitted Done Inline Actionsremove return Silier: remove return | |||||
}; | |||||
Status.prototype.ExecuteEffect = function(statusName, lateness) | |||||
Done Inline Actionsyou should call deal damage, or to handle target killed message ( unless you do not want to give attacker no experiences for this way of killing). At least you have to update statistics of player who looses this unit. See CauseDamage and TargetKilled in Damage.js. Silier: you should call deal damage, or to handle target killed message ( unless you do not want to… | |||||
Done Inline ActionsIndeed. Thanks fo D865 'no armor defined' means 'take full damage', so you can do something like: CauseDamage({ [status]: this.damage }) wraitii: Indeed. Thanks fo D865 'no armor defined' means 'take full damage', so you can do something… | |||||
{ | |||||
let status = this.currentStatuses[statusName]; | |||||
SilierUnsubmitted Done Inline Actionsthe same, check if status actually exists Silier: the same, check if status actually exists | |||||
if (status.firstTime) | |||||
{ | |||||
status.firstTime = false; | |||||
status.timeElapsed += lateness; | |||||
Done Inline ActionsCheck for non system components before using them. Stan: Check for non system components before using them. | |||||
} | |||||
else | |||||
Done Inline ActionsYou probably want >= here wraitii: You probably want >= here | |||||
Done Inline Actionswhen the duration is 10 sec then damage should be inflicted at the 10th sec too, or no? Mate-86: when the duration is 10 sec then damage should be inflicted at the 10th sec too, or no? | |||||
status.timeElapsed += status.interval + lateness; | |||||
let cmpDamage = Engine.QueryInterface(SYSTEM_ENTITY, IID_Damage); | |||||
cmpDamage.CauseDamage({ | |||||
"strengths": { [statusName]: status.damage }, | |||||
"target": this.entity, | |||||
Done Inline ActionsThis cleanup could be moved to a "stopStatus" function, so we can call that directly (imagine a priest healing a status for example) wraitii: This cleanup could be moved to a "stopStatus" function, so we can call that directly (imagine a… | |||||
"attacker": -1, | |||||
"multiplier": 1, | |||||
"type": statusName, | |||||
"attackerOwner": -1 | |||||
}); | |||||
if (status.timeElapsed > status.duration) | |||||
wraitiiAuthorUnsubmitted Done Inline ActionsStill needs to be >= I think. wraitii: Still needs to be >= I think. | |||||
this.StopEffect(statusName); | |||||
}; | |||||
Engine.RegisterComponentType(IID_Status, "Status", Status); |
Any reason for using an object over an array ?