Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum statistic_types {
- REAL,
- PERCENTAGE,
- FLAT_PERCENT,
- MULTIPLIER,
- TIMER
- }
- ///@func Statistic(base_value, owner_id, name, statistic_type)
- ///@param {real} _base_value
- ///@param {struct|ID.Instance} _owner_id
- ///@param {string} _name
- ///@param {real} _type
- function Statistic(_base_value, _owner_id, _name = "Unknown", _type = statistic_types.REAL) constructor {
- modifiers = [];
- single_shot_modifiers = [];
- modifier_size = 0;
- base_value = _base_value;
- current_value = _base_value;
- altered = false;
- owner = _owner_id;
- has_count = false;
- has_duration = false;
- name = _name;
- type = _type;
- if (is_instanceof(owner, Wand)) {
- tooltip_label = "wand_" +string_lower(string_replace_all(_name, " ", "_"));
- }
- else {
- tooltip_label = string_lower(string_replace_all(_name, " ", "_"));
- }
- ///@func AddModifier(mod);
- ///@param {Struct.Modifier} _mod
- static AddModifier = function(_mod) {
- array_push(modifiers,_mod);
- array_sort(modifiers,function(a,b) {
- return a.type-b.type;
- });
- modifier_size++;
- for (var i=0;i<modifier_size;i++) {
- var __mod = modifiers[i];
- var _mod_type = __mod.type;
- if (_mod_type == modifier_types.DURATION) {
- has_duration = true;
- break;
- }
- }
- altered = true;
- }
- ///@func FindModifierBySource(source)
- ///@param {Struct.Modifier} _source
- ///@returns {Array<Struct.Modifier>}
- static FindModifierBySource = function(_source) {
- var _mods = [];
- for (var i=0;i<modifier_size;i++) {
- if (modifiers[i].source == _source) {
- array_push(_mods,modifiers[i]);
- }
- }
- return _mods;
- }
- ///@func RemoveModifierBySource(source);
- ///@param {Struct.Modifier} _source
- ///@returns {bool}
- static RemoveModifierBySource = function(_source) {
- var _deleted = false;
- for (var i=modifier_size-1;i>=0;i--) {
- if (modifiers[i].source == _source) {
- delete modifiers[i];
- array_delete(modifiers,i,1);
- _deleted = true;
- modifier_size--;
- }
- }
- if (_deleted) {
- altered = true;
- return true;
- }
- return false;
- }
- // There are other things you might want to remove or find by, such as ID or position in the modifiers array, but I'll leave it at just removing and finding using the source for brevity's sake
- ///@func GetValue()
- ///@returns {real}
- static GetValue = function() {
- if (altered) {
- var _value = base_value;
- var _add = 0;
- var _multi_flat = 1;
- var _multi_pct = 1;
- for (var i=0;i<modifier_size;i++) {
- var _mod = modifiers[i];
- switch (_mod.math_type) {
- case modifier_math.ADD:
- _add += _mod.value;
- break;
- case modifier_math.MULTIPLY_FLAT:
- _multi_flat += _mod.value;
- break;
- case modifier_math.MULTIPLY_PCT:
- _multi_pct *= _mod.value;
- break;
- }
- }
- _value += _add;
- _value *= _multi_flat;
- _value *= _multi_pct;
- current_value = _value;
- altered = false;
- }
- return current_value;
- }
- ///@func GetBaseValue()
- ///@returns {real}
- static GetBaseValue = function() {
- return base_value;
- }
- ///@func GetValueBySource(source)
- ///@param {struct} _source
- ///@returns {real}
- static GetValueBySource = function(_source) {
- var _value = 0;
- var _add = 0;
- var _multi_flat = 1;
- var _multi_pct = 1;
- for (var i=0;i<modifier_size;i++) {
- var _mod = modifiers[i];
- if (_mod.source == _source) {
- switch (_mod.math_type) {
- case modifier_math.ADD:
- _add += _mod.value;
- break;
- case modifier_math.MULTIPLY_FLAT:
- _multi_flat += _mod.value;
- break;
- case modifier_math.MULTIPLY_PCT:
- _multi_pct *= _mod.value;
- break;
- }
- }
- }
- _value += _add;
- _value *= _multi_flat;
- _value *= _multi_pct;
- return _value;
- }
- ///@func AlterValue(amount)
- ///@param {real} _amount
- static AlterValue = function(_amount) {
- base_value += _amount;
- altered = true;
- }
- ///@func SetBaseValue(amount)
- ///@param {real} _amount
- static SetBaseValue = function(_amount) {
- base_value = _amount;
- altered = true;
- }
- ///@func PrintValue(value)
- ///@param {real} _value
- ///@returns {string}
- static PrintValue = function(_value) {
- switch (type) {
- case statistic_types.PERCENTAGE:
- return $"{_value * 100}%";
- case statistic_types.MULTIPLIER:
- return $"{_value}x";
- case statistic_types.FLAT_PERCENT:
- return $"{_value}%";
- case statistic_types.TIMER:
- return $"{_value / SECOND}s";
- default:
- return $"{_value}";
- }
- }
- }
- enum modifier_math {
- ADD,
- MULTIPLY_FLAT,
- MULTIPLY_PCT,
- NUM
- }
- enum modifier_types {
- DURATION,
- PERSISTENT,
- NUM
- }
- ///@func Modifier(source_id, mod_type, math_op, value, duration, stat_type)
- ///@param {Id.Instance|Struct.SpellBoost|Struct.Wand} _source_id
- ///@param {real} _mod_type
- ///@param {real} _math_op
- ///@param {real} _value
- ///@param {real} _duration
- ///@param {real} _stat_type
- function Modifier(_source_id,_mod_type,_math_op,_value,_duration = undefined, _stat_type = statistic_types.REAL) constructor {
- source = _source_id;
- type = _mod_type;
- math_type = _math_op;
- value = _value;
- duration = _duration;
- stat_type = _stat_type;
- try {
- source_name = source.name;
- }
- catch(_err) {
- source_name = "Unknown";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement