Skip to content

Instantly share code, notes, and snippets.

@jsandersr

jsandersr/Effect.cs Secret

Last active Sep 12, 2020
Embed
What would you like to do?
Below are some classes that describe how my data is currently set up
public abstract class Effect {
// These ideas will indicate particular behavior patterns, priorities, etc.
public enum ModifierIds {
Normal,
Passive,
Aura,
Reactionary,
Quick
}
[SerializeField]
protected ModifierIds _modifierId = ModifierIds.Normal;
[SerializeField]
protected float _value = 0.0f;
[SerializeField]
protected float _range = 1.0f;
[SerializeField]
protected float _duration = 1.0f;
// Effects should not be applied unless they are active.
[SerializeField]
protected bool _isActive = false;
public abstract void Apply(HeroActor source, HeroActor target);
}
public class HealEffect : Effect {
public override void Apply(HeroActor source, HeroActor target) {
target.CurrentHp += Math.Min(target.Model.BaseHp, target.CurrentHp += _value);
_duration = Math.Max(0, --_duration);
}
}
public class DamageEffect : Effect
{
public override void Apply(HeroActor source, HeroActor target) {
target.CurrentHp = Math.Max(0, target.CurrentHp -=_value);
_duration = Math.Max(0, --_duration);
}
}
[CreateAssetMenu(menuName = "Spell/New Spell")]
public class SpellModel : SerializedScriptableObject {
[BoxGroup("Basic Info")]
[PreviewField(128, ObjectFieldAlignment.Left)]
[HideLabel]
[SerializeField]
private Sprite _spellIcon;
[BoxGroup("Basic Info")]
[SerializeField]
private float _baseSpellCooldown;
[BoxGroup("Basic Info")]
[Title("Spell Name", bold: false)]
[HideLabel]
[LabelWidth(100)]
[SerializeField]
private string _spellName;
[BoxGroup("Basic Info")]
[Title("Spell Description", bold: false)]
[HideLabel]
[MultiLineProperty(3)]
[SerializeField]
private string _spellDescription;
[BoxGroup("Spell Effects")]
[Title("Consecutively Evaluated Spell Effects")]
[HideLabel]
[SerializeField]
// Each of these effects will be applied consecutively according to their behavior.
private List<Effect> _effects;
[BoxGroup("Spell Effects")]
[Title("Mutually Exclusive Spell Effects")]
[HideLabel]
[SerializeField]
// Some spells have the player choose which effect to run.
private List<Effect> _mutuallyExclusiveEffects;
public string SpellName
{
get => _spellName;
set => _spellName = value;
}
public string SpellDescription
{
get => _spellDescription;
set => _spellDescription = value;
}
public Sprite SpellIcon
{
get => _spellIcon;
set => _spellIcon = value;
}
public List<Effect> Effects
{
get => _effects;
set => _effects = value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment