123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- 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<data.buff_type.Length; i++)
- {
- if(data.buff_type[i] == BuffType.CloseTarget.GetHashCode())
- hasCloseTarget = true;
- }
- configValueArr = new ConfigValue[data.buff_type.Length];
- for(int i=0; i<configValueArr.Length; i++)
- {
- int value = i < data.value.Length ? data.value[i] : 0;
- int valueType = i < data.value_type.Length ? data.value_type[i] : 0;
- configValueArr[i] = new ConfigValue(value, valueType);
- }
- }
- public int GetId()
- {
- return data.id;
- }
- public string GetName()
- {
- return data.name;
- }
- public string GetDescription()
- {
- return this.data.description;
- }
- public BattleObject GetOwner()
- {
- if(this.data.target == TargetType.Target.GetHashCode())
- return target;
- else if(this.data.target == TargetType.Launcher.GetHashCode())
- return launcher;
- return null;
- }
- public YesOrNo GetIsGood()
- {
- return GetYesOrNoByCode(this.data.is_good);
- }
- public YesOrNo GetIsNormal()
- {
- return GetYesOrNoByCode(this.data.is_normal);
- }
- public BuffType GetBuffType(int index)
- {
- return GetBuffTypeByCode(this.data.buff_type[index]);
- }
- public float GetDuration()
- {
- if(this.data.duration == 0)
- return float.MaxValue;
- return this.data.duration;
- }
- public ConfigValue GetConfigValue(int index)
- {
- return configValueArr[index];
- }
- public int GetNumBuffTypes()
- {
- return this.data.buff_type.Length;
- }
- public string GetGraphicEffect()
- {
- return this.data.g_effect;
- }
- private GameObject graphicEffect;
- public GameObject CreateGraphicsEffect(Transform parent)
- {
- GameObject prefab = Resources.Load<GameObject>("Prefabs/Buffs/"+GetGraphicEffect());
- if(prefab != null)
- {
- if(graphicEffect != null)
- {
- GameObject.Destroy(graphicEffect);
- Debuger.LogError(this.ToString()+" already created graphic effect");
- }
- graphicEffect = GameObject.Instantiate<GameObject>(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<BuffEffect>();
- 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<data.endBuffArr.Length; i++)
- {
- BuffManager.GetInstance().AddBuff(data.endBuffArr[i], tempTarget, tempLauncher);
- }
- }
- }
- public void OnMove()
- {
- for(int i=0; i<data.removeArr.Length; i++)
- {
- if(data.removeArr[i] == RemoveType.Move.GetHashCode())
- {
- BuffManager.GetInstance().RemoveBuff(this);
- return;
- }
- }
- }
- public void OnDamage()
- {
- if(GameTime.time - startTime < 1f)
- return;
- for(int i=0; i<data.removeArr.Length; i++)
- {
- if(data.removeArr[i] == RemoveType.Damage.GetHashCode())
- {
- BuffManager.GetInstance().RemoveBuff(this);
- return;
- }
- }
- }
- public void OnUserPower()
- {
- for(int i=0; i<data.removeArr.Length; i++)
- {
- if(data.removeArr[i] == RemoveType.Power.GetHashCode())
- {
- BuffManager.GetInstance().RemoveBuff(this);
- return;
- }
- }
- }
- public void OnDismove()
- {
- for(int i=0; i<data.removeArr.Length; i++)
- {
- if(data.removeArr[i] == RemoveType.Dismove.GetHashCode())
- {
- BuffManager.GetInstance().RemoveBuff(this);
- return;
- }
- }
- }
- public void OnOvertime()
- {
- for(int i=0; i<data.removeArr.Length; i++)
- {
- if(data.removeArr[i] == RemoveType.Overtime.GetHashCode())
- {
- BuffManager.GetInstance().RemoveBuff(this);
- return;
- }
- }
- }
- public override string ToString ()
- {
- return string.Format ("[Buff] id["+GetId()+"] name["+GetName()+"]");
- }
- }
|