Changeset View
Standalone View
binaries/data/mods/public/simulation/components/StatusEffectsReceiver.js
function StatusEffectsReceiver() {} | function StatusEffectsReceiver() {} | ||||
StatusEffectsReceiver.prototype.Init = function() | StatusEffectsReceiver.prototype.Init = function() | ||||
{ | { | ||||
this.activeStatusEffects = {}; | this.activeStatusEffects = {}; | ||||
}; | }; | ||||
StatusEffectsReceiver.prototype.GetActiveStatuses = function() | StatusEffectsReceiver.prototype.GetActiveStatuses = function() | ||||
{ | { | ||||
return this.activeStatusEffects; | return this.activeStatusEffects; | ||||
}; | }; | ||||
// Called by attacking effects. | // Called by attacking effects. | ||||
StatusEffectsReceiver.prototype.GiveStatus = function(effectData, attacker, attackerOwner, bonusMultiplier) | StatusEffectsReceiver.prototype.GiveStatus = function(effectData, attacker, attackerOwner, bonusMultiplier) | ||||
{ | { | ||||
let attackerData = { "entity": attacker, "owner": attackerOwner }; | |||||
for (let effect in effectData) | for (let effect in effectData) | ||||
this.AddStatus(effect, effectData[effect]); | this.AddStatus(effect, effectData[effect], attackerData); | ||||
// TODO: implement loot / resistance. | // TODO: implement loot / resistance. | ||||
return { "inflictedStatuses": Object.keys(effectData) }; | return { "inflictedStatuses": Object.keys(effectData) }; | ||||
}; | }; | ||||
StatusEffectsReceiver.prototype.AddStatus = function(statusName, data) | StatusEffectsReceiver.prototype.AddStatus = function(statusName, data, attackerData) | ||||
{ | { | ||||
if (this.activeStatusEffects[statusName]) | if (this.activeStatusEffects[statusName] && (!data.Stackable || data.Stackable == "false")) | ||||
return; | return; | ||||
if (data.Stackable && data.Stackable == "true") | |||||
for (let i = 0; i < 10; ++i) | |||||
{ | |||||
let temp = statusName + "_" + i; | |||||
if (!this.activeStatusEffects[temp]) | |||||
{ | |||||
statusName = temp; | |||||
break; | |||||
Silier: this can go without { } | |||||
} | |||||
} | |||||
this.activeStatusEffects[statusName] = {}; | this.activeStatusEffects[statusName] = {}; | ||||
let status = this.activeStatusEffects[statusName]; | let status = this.activeStatusEffects[statusName]; | ||||
Done Inline Actionsyou probably want i++, so _0 is considered as first option Silier: you probably want i++, so _0 is considered as first option | |||||
Done Inline ActionsActually only the second SE gets this postfix, hence I chose ++i, but I guess it doesn't matter and makes the linter happy :) Freagarach: Actually only the second SE gets this postfix, hence I chose `++i`, but I guess it doesn't… | |||||
Object.assign(status, data); | Object.assign(status, data); | ||||
Not Done Inline Actionsdo you really need !! ? Stan: do you really need !! ? | |||||
Not Done Inline Actionsmeh... I would suggest UUID-like -> Timestamp + random bits, but I'm not sure it's actually faster in the general case. I'm not entirely convinced by status effects stacking, to be honest. Can you be "more" on fire? It also seems like it would be ugly GUI wise. Perhaps we could have "levels", where being "low-poison" and getting poisoned again moves you to "medium-poison" or something. But that seems like work for status effects v4. I would personally remove stacking effects for now, but I'm willing to be overruled by others (though @Angen seemed to agree that this looks meh earlier) wraitii: meh... I would suggest UUID-like -> Timestamp + random bits, but I'm not sure it's actually… | |||||
Not Done Inline ActionsYes, you can be more on fire ;) I've seen a piece of wood burn faster when lit on two sides ;) How is the level system different than stacking? Freagarach: Yes, you can be more on fire ;) I've seen a piece of wood burn faster when lit on two sides ;)… | |||||
Not Done Inline ActionsYou could define custom transitions with levels over stacking, or other interesting effects such as: That's impossible with stacking. wraitii: You could define custom transitions with levels over stacking, or other interesting effects… | |||||
status.AttackerData = attackerData; | |||||
status.Interval = +data.Interval; | status.Interval = +data.Interval; | ||||
status.TimeElapsed = 0; | status.TimeElapsed = 0; | ||||
status.FirstTime = true; | status.FirstTime = true; | ||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | ||||
status.Timer = cmpTimer.SetInterval(this.entity, IID_StatusEffectsReceiver, "ExecuteEffect", 0, +status.Interval, statusName); | status.Timer = cmpTimer.SetInterval(this.entity, IID_StatusEffectsReceiver, "ExecuteEffect", 0, +status.Interval, statusName); | ||||
}; | }; | ||||
Show All 16 Lines | StatusEffectsReceiver.prototype.ExecuteEffect = function(statusName, lateness) | ||||
if (status.FirstTime) | if (status.FirstTime) | ||||
{ | { | ||||
status.FirstTime = false; | status.FirstTime = false; | ||||
status.TimeElapsed += lateness; | status.TimeElapsed += lateness; | ||||
} | } | ||||
else | else | ||||
status.TimeElapsed += status.Interval + lateness; | status.TimeElapsed += status.Interval + lateness; | ||||
Attacking.HandleAttackEffects(statusName, status, this.entity, -1, -1); | Attacking.HandleAttackEffects(statusName, status, this.entity, status.AttackerData.entity, status.AttackerData.owner); | ||||
if (status.Duration && status.TimeElapsed >= +status.Duration) | if (status.Duration && status.TimeElapsed >= +status.Duration) | ||||
this.RemoveStatus(statusName); | this.RemoveStatus(statusName); | ||||
}; | }; | ||||
Engine.RegisterComponentType(IID_StatusEffectsReceiver, "StatusEffectsReceiver", StatusEffectsReceiver); | Engine.RegisterComponentType(IID_StatusEffectsReceiver, "StatusEffectsReceiver", StatusEffectsReceiver); |
this can go without { }