Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SpellLogic : MonoBehaviour
- {
- public SpellData SpellData;
- SpellEffect SpellEffect;
- // Use this for initialization
- void Start ()
- {
- SpellEffect = SpellData.Effect;
- SpellEffect.OnStart();
- StartCoroutine(SpellEffect.OnTick());
- Instantiate(SpellData.ParticleSystem, gameObject.transform);
- }
- // Update is called once per frame
- void Update ()
- {
- }
- }
- public class SpellData : ScriptableObject
- {
- private string name;
- private ResourceType resourceType;
- private float resourceCost;
- private ParticleSystem particleSystem;
- private SpellEffect effect;
- public string Name
- {
- get
- {
- return name;
- }
- set
- {
- name = value;
- }
- }
- public ResourceType ResourceType
- {
- get
- {
- return resourceType;
- }
- set
- {
- resourceType = value;
- }
- }
- public float ResourceCost
- {
- get
- {
- return resourceCost;
- }
- set
- {
- resourceCost = value;
- }
- }
- public ParticleSystem ParticleSystem
- {
- get
- {
- return particleSystem;
- }
- set
- {
- particleSystem = value;
- }
- }
- public SpellEffect Effect
- {
- get
- {
- return effect;
- }
- set
- {
- effect = value;
- }
- }
- }
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- [CreateAssetMenu(fileName = "New Spell Effect", menuName = "Spell Effect")]
- public abstract class SpellEffect : ScriptableObject
- {
- public GameObject Spell;
- public float Duration = 1f;
- public List<GameObject> Targets;
- public List<StatusEffect> StatusEffects;
- public CharacterController Caster;
- public abstract void OnStart();
- public abstract IEnumerator OnTick();
- }
- public class HealSpellEffect : SpellEffect
- {
- public override void OnStart()
- {
- Destroy(Spell,Duration);
- }
- public override IEnumerator OnTick()
- {
- do
- {
- foreach (GameObject item in Targets)
- {
- item.GetComponent<IDamagable>().ApplyDamage(HealAmount, DamageType);
- }
- yield return new WaitForSeconds(Interval);
- }
- while (true);
- }
- public float HealAmount;
- public DamageType DamageType;
- public float Interval;
- }
- public class PoisonSpellEffect : SpellEffect
- {
- public float Interval;
- public float Damage;
- public DamageType DamageType;
- private StatusEffect statusEffect = new StatusEffect { Name = "Poisoned", Description = "Deals damage repeatedly"};
- public override void OnStart()
- {
- statusEffect.Duration = Duration;
- statusEffect.Interval = Interval;
- Destroy(Spell, Duration);
- foreach (GameObject member in Targets)
- {
- statusEffect.OnProc += delegate { member.GetComponent<IDamagable>().ApplyDamage(Damage, DamageType); };
- member.GetComponent<IAfflictable>().Afflict(statusEffect);
- }
- }
- public override IEnumerator OnTick()
- {
- yield return null;
- }
- }
- public class StatusEffect : ScriptableObject
- {
- public delegate void OnProcDelegate();
- public delegate void OnExpireDelegate(StatusEffect target);
- private string name;
- private string description;
- private float duration;
- private float interval;
- private OnProcDelegate onProc;
- private OnExpireDelegate onExpire;
- public string Name
- {
- get
- {
- return name;
- }
- set
- {
- name = value;
- }
- }
- public string Description
- {
- get
- {
- return description;
- }
- set
- {
- description = value;
- }
- }
- public float Duration
- {
- get
- {
- return duration;
- }
- set
- {
- duration = value;
- if (duration <= 0) OnExpire(this);
- }
- }
- public float Interval
- {
- get
- {
- return interval;
- }
- set
- {
- interval = value;
- }
- }
- public OnProcDelegate OnProc
- {
- get
- {
- return onProc;
- }
- set
- {
- onProc = value;
- }
- }
- public OnExpireDelegate OnExpire
- {
- get
- {
- return onExpire;
- }
- set
- {
- onExpire = value;
- }
- }
- public IEnumerator Proc()
- {
- OnProc();
- yield return new WaitForSeconds(Interval);
- }
- }
- public class CharacterController : MonoBehaviour, IAfflictable, IDamagable
- {
- List<SpellData> spellList = new List<SpellData>();
- List<StatusEffect> statusEffects = new List<StatusEffect>();
- public List<SpellData> SpellList
- {
- get
- {
- return spellList;
- }
- set
- {
- spellList = value;
- }
- }
- public List<StatusEffect> StatusEffects
- {
- get
- {
- return statusEffects;
- }
- set
- {
- statusEffects = value;
- }
- }
- #region Methods
- void Start()
- {
- }
- void Update()
- {
- }
- public void Afflict(StatusEffect statusEffect)
- {
- statusEffect.OnExpire += RemoveStatusEffect;
- StartCoroutine(statusEffect.Proc());
- StatusEffects.Add(statusEffect);
- }
- public void RemoveStatusEffect(StatusEffect Target)
- {
- StatusEffects.Remove(Target);
- }
- public float ApplyDamage(float Damage, DamageType DamageType)
- {
- return 0f;
- }
- #endregion
- }
Add Comment
Please, Sign In to add comment