using UnityEngine; using System.Collections; public class Buff { public enum YesOrNo { No = 0, Yes = 1 } private static System.Array yesOrNoArr = System.Enum.GetValues(typeof(YesOrNo)); public static YesOrNo GetYesOrNoByCode(int code) { return (YesOrNo)yesOrNoArr.GetValue(code); } public enum TargetType { Target = 0, Launcher = 1 } private static System.Array targetTypeArr = System.Enum.GetValues(typeof(TargetType)); public static TargetType GetTargetTypeByCode(int code) { return (TargetType)targetTypeArr.GetValue(code); } public enum BuffType { None = 0, Damage = 1, Heal = 2, SpeedUp = 3, SlowDown = 4, Stuck = 5, Invisible = 6, Bigger = 7, HoldAction = 8, CloseTarget = 9, } private static System.Array buffTypeArr = System.Enum.GetValues(typeof(BuffType)); public static BuffType GetBuffTypeByCode(int code) { return (BuffType)buffTypeArr.GetValue(code); } public enum RemoveType { None = 0, Move = 1, Power = 2, Damage = 3, Dismove = 4, Overtime = 5, } private static System.Array removeTypeArr = System.Enum.GetValues(typeof(RemoveType)); public static RemoveType GetRemoveTypeByCode(int code) { return (RemoveType)removeTypeArr.GetValue(code); } public enum EndType { TimeUp = 0, CloseTarget = 1, } public BattleObject target; public BattleObject launcher; public object paramObj; private BuffData data; private ConfigValue[] configValueArr; private float startTime; public bool hasCloseTarget; public Buff(BuffData data) { startTime = GameTime.time; this.data = data; for(int i=0; i("Prefabs/Buffs/"+GetGraphicEffect()); if(prefab != null) { if(graphicEffect != null) { GameObject.Destroy(graphicEffect); Debuger.LogError(this.ToString()+" already created graphic effect"); } graphicEffect = GameObject.Instantiate(prefab); graphicEffect.transform.SetParent(parent); graphicEffect.transform.localPosition = Vector3.zero; graphicEffect.transform.localEulerAngles = Vector3.zero; graphicEffect.transform.localScale = new Vector3(1f, 1f, 1f); } return graphicEffect; } public void RemoveGraphicsEffect() { if(graphicEffect != null) { BuffEffect buffEffect = graphicEffect.GetComponent(); if(buffEffect != null) buffEffect.Remove(); else GameObject.Destroy(graphicEffect); } } public string GetSoundEffect() { return this.data.s_effect; } public void Update() { if(data.end == EndType.TimeUp.GetHashCode()) { if(GameTime.time - startTime > GetDuration()) { Remove(); } } else if(data.end == EndType.CloseTarget.GetHashCode()) { if(NumberUtil.distanceVector3(launcher.position, target.position, true) < 1f) { Remove(); } } if(GameTime.time - startTime > GetDuration()) { OnOvertime(); } } private void Remove() { BattleObject tempTarget = this.target; BattleObject tempLauncher = this.launcher; BuffManager.GetInstance().RemoveBuff(this); if(data.endBuffArr.Length > 0) { for(int i=0; i