123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using FSEvent;
- using FSFile;
- using FSRole;
- using FSAssist;
- using LitJson;
- namespace FSBuff {
- /*
- * Buff管理器,负责Buff的创建和挂载
- */
- public class BuffManager : Singleton<BuffManager> {
- JsonData buffValue = null; // 保存的Buff数据
- public BuffManager() {
- ReadBuffData();
- InitListener();
- }
- /*
- * 从文本中获取BUFF数据
- */
- private void ReadBuffData() {
- string json = FileManager.Instance.ReadResourceText("Jsons/buffs");
- if (json != null) {
- Debug.Log("读取到 json 字符串 : " + json);
- try {
- buffValue = JsonMapper.ToObject(json);
- } catch (JsonException e) {
- Debug.Log(e.ToString());
- }
- }
- }
- /*
- * 初始化监听
- */
- private void InitListener() {
- EventListener.Instance.RegisterEvent(EventEnum.EVENT_BUFF_EXECUTE, BuffExecute);
- EventListener.Instance.RegisterEvent(EventEnum.EVENT_BUFF_CANCLE, BuffCancle);
- }
- /*
- * 给角色添加挂载BUFF
- */
- public void LoadBuff(GameObject obj, string id) {
- JsonData oneValue = buffValue[id];
- if (oneValue != null && oneValue.IsObject) {
- Buff buff = new Buff();
- // 获取对应的目标
- Role role = obj.GetComponent<Role>();
- // 对应的目标
- buff.Target = role;
- // 同时从json对象中提取数据
- buff.Value = AssistMethods.ReadInt(oneValue, "value");
- buff.Round = AssistMethods.ReadInt(oneValue, "round");
- buff.ID = id;
- buff.Overlay = 1;
- // 给角色挂载Buff
- role.AddBuff(buff);
- //// 挂载后直接运行
- //buff.Execute();
- } else {
- throw new System.Exception("没有找到ID所对应的BUFF");
- }
- }
- /*
- * Buff执行,根据ID来进行相应的处理
- */
- private void BuffExecute(Dictionary<string, object> info) {
- Debug.Log("Buff 开始运行");
- Buff buff = (Buff)info["buff"];
- if (buff != null) {
- buff.Target.CurrentAttr.Hp -= buff.Value;
- }
- }
- /*
- * Buff取消,根据ID来进行相应的处理
- */
- private void BuffCancle(Dictionary<string, object> info) {
- Debug.Log("Buff 时间到");
- }
- }
- }
|