Created
May 7, 2026 03:24
-
-
Save hariedo/630609cc83c425fda4c28d5ae62e6b3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [System.Serializable] | |
| public class Effect | |
| { | |
| public string name; | |
| public float multiplier = 1f; | |
| public float additional = 0f; | |
| public float expiration = 0f; | |
| public bool stackable = false; | |
| public GameObject addPrefab = null; | |
| public GameObject removePrefab = null; | |
| public Effect(): | |
| this(null, 1f, 0f, 0f) | |
| { ; } | |
| public Effect(Effect original): | |
| this(original.name, original.multiplier, | |
| original.additional, original.expiration, | |
| original.stackable, | |
| original.addPrefab, original.removePrefab) | |
| { ; } | |
| public Effect(string name, | |
| float factor=1f, float bonus=0f, | |
| float expire=0f, bool stacks=false, | |
| GameObject addPrefab=null, GameObject removePrefab=null) | |
| { | |
| if (expire == 0f) | |
| expire = float.PositiveInfinity; | |
| this.name = name; | |
| this.multiplier = factor; | |
| this.additional = bonus; | |
| this.expiration = expire; | |
| this.stackable = stacks; | |
| this.addPrefab = addPrefab; | |
| this.removePrefab = removePrefab; | |
| } | |
| } | |
| // queue of effects ordered by their expiration | |
| // | |
| public SimplePriorityQueue<Effect,float> effects = | |
| new SimplePriorityQueue<Effect,float>(); | |
| // base value before any effects applied | |
| // | |
| public float baseValue = 0f; | |
| public float GetEffectiveValue() | |
| { | |
| float value = baseValue; | |
| // All factors first, all bonuses afterwards. | |
| // Priority queue iterates in undefined order. | |
| // | |
| if (effects != null) | |
| { | |
| // remove expired effects if any | |
| ExpireEffects(); | |
| foreach (Effect effect in effects) | |
| if (effect.name.Equals(name)) | |
| value *= effect.multiplier; | |
| foreach (Effect effect in effects) | |
| if (effect.name.Equals(name)) | |
| value += effect.additional; | |
| } | |
| // Within the limits. | |
| value = ClampToLegalRange(value); | |
| return value; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment