BuffManager.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using FSEvent;
  5. using FSFile;
  6. using FSRole;
  7. using FSAssist;
  8. using LitJson;
  9. namespace FSBuff {
  10. /*
  11. * Buff管理器,负责Buff的创建和挂载
  12. */
  13. public class BuffManager : Singleton<BuffManager> {
  14. JsonData buffValue = null; // 保存的Buff数据
  15. public BuffManager() {
  16. ReadBuffData();
  17. InitListener();
  18. }
  19. /*
  20. * 从文本中获取BUFF数据
  21. */
  22. private void ReadBuffData() {
  23. string json = FileManager.Instance.ReadResourceText("Jsons/buffs");
  24. if (json != null) {
  25. Debug.Log("读取到 json 字符串 : " + json);
  26. try {
  27. buffValue = JsonMapper.ToObject(json);
  28. } catch (JsonException e) {
  29. Debug.Log(e.ToString());
  30. }
  31. }
  32. }
  33. /*
  34. * 初始化监听
  35. */
  36. private void InitListener() {
  37. EventListener.Instance.RegisterEvent(EventEnum.EVENT_BUFF_EXECUTE, BuffExecute);
  38. EventListener.Instance.RegisterEvent(EventEnum.EVENT_BUFF_CANCLE, BuffCancle);
  39. }
  40. /*
  41. * 给角色添加挂载BUFF
  42. */
  43. public void LoadBuff(GameObject obj, string id) {
  44. JsonData oneValue = buffValue[id];
  45. if (oneValue != null && oneValue.IsObject) {
  46. Buff buff = new Buff();
  47. // 获取对应的目标
  48. Role role = obj.GetComponent<Role>();
  49. // 对应的目标
  50. buff.Target = role;
  51. // 同时从json对象中提取数据
  52. buff.Value = AssistMethods.ReadInt(oneValue, "value");
  53. buff.Round = AssistMethods.ReadInt(oneValue, "round");
  54. buff.ID = id;
  55. buff.Overlay = 1;
  56. // 给角色挂载Buff
  57. role.AddBuff(buff);
  58. //// 挂载后直接运行
  59. //buff.Execute();
  60. } else {
  61. throw new System.Exception("没有找到ID所对应的BUFF");
  62. }
  63. }
  64. /*
  65. * Buff执行,根据ID来进行相应的处理
  66. */
  67. private void BuffExecute(Dictionary<string, object> info) {
  68. Debug.Log("Buff 开始运行");
  69. Buff buff = (Buff)info["buff"];
  70. if (buff != null) {
  71. buff.Target.CurrentAttr.Hp -= buff.Value;
  72. }
  73. }
  74. /*
  75. * Buff取消,根据ID来进行相应的处理
  76. */
  77. private void BuffCancle(Dictionary<string, object> info) {
  78. Debug.Log("Buff 时间到");
  79. }
  80. }
  81. }