-
-
Save xjjon/6bbdeaaf2c6d31dc8284b087ed8c88f1 to your computer and use it in GitHub Desktop.
This file contains 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
public abstract class ScriptableBuff : ScriptableObject | |
{ | |
/** | |
* Time duration of the buff in seconds. | |
*/ | |
public float Duration; | |
/** | |
* Duration is increased each time the buff is applied. | |
*/ | |
public bool IsDurationStacked; | |
/** | |
* Effect value is increased each time the buff is applied. | |
*/ | |
public bool IsEffectStacked; | |
// Time between each tick | |
public float TickTime; | |
public abstract TimedBuff InitializeBuff(GameObject obj); | |
} | |
public abstract class TimedBuff | |
{ | |
protected float Duration; | |
protected float TickTime; // time until ApplyTickEffect() is called | |
protected int EffectStacks; | |
public ScriptableBuff Buff { get; } | |
protected readonly GameObject Obj; | |
public bool IsFinished; | |
public TimedBuff(ScriptableBuff buff, GameObject obj) | |
{ | |
Buff = buff; | |
Obj = obj; | |
} | |
public void Tick(float delta) | |
{ | |
Duration -= delta; | |
if (Duration <= 0) | |
{ | |
End(); | |
IsFinished = true; | |
} | |
TickTime -= delta; | |
if (TickTime <= 0) { | |
ApplyTickEffect(); | |
TickTime = Buff.TickTime; | |
} | |
} | |
/** | |
* Activates buff or extends duration if ScriptableBuff has IsDurationStacked or IsEffectStacked set to true. | |
*/ | |
public void Activate() | |
{ | |
if (Buff.IsEffectStacked || Duration <= 0) | |
{ | |
ApplyEffect(); | |
EffectStacks++; | |
} | |
if (Buff.IsDurationStacked || Duration <= 0) | |
{ | |
Duration += Buff.Duration; | |
} | |
TickTime = Buff.TickTime; | |
} | |
protected abstract void ApplyEffect(); | |
// Apply some 'tick' effect such as damage (bleed, poision, etc) | |
protected abstract void ApplyTickEffect(); | |
public abstract void End(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment