difenduandada
2024-12-31 34abe6963b344c882358274957f4b992456fee40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
"use strict";
cc._RF.push(module, 'd438f2lEQNFq5Fa074aWZ5t', 'battle_effect');
// Scripts/mod/battle/view/battle_effect.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: shiraho@syg.com(必填, 创建模块的人员)
// @description:
//      战斗特效单位
// <br/>Create: new Date().toISOString()
// --------------------------------------------------------------------
var BattleRolePool = require("battle_role_pool");
 
var LoaderManager = require("loadermanager");
 
var PathTool = require("pathtool");
 
var BattleResPool = require("battle_res_pool");
 
var BattleEffect = cc.Class({
  "extends": BaseClass,
  properties: {
    skelon_cache: {
      "default": {}
    }
  },
  ctor: function ctor() {
    this.initConfig();
  },
  initConfig: function initConfig() {
    this.effect = null; // 特效单位
 
    this.skelon_cache = {}; // 动画缓存
 
    this.effect_active = true;
    this.action_call_list = {}; // 制动动作回调
 
    this.model = require("battle_controller").getInstance().getModel();
  },
 
  /**
   * 创建特效
   * @param {*} parent 特效父节点
   * @param {*} scene_pos 场景位置,像素坐标不是格子
   * @param {*} reverse 是否反转
   * @param {*} res_id 特效id
   */
  createEffect: function createEffect(parent, scene_pos, reverse, res_id) {
    this.parent = parent;
    this.scene_pos = scene_pos;
    this.reverse = reverse || 1;
    this.res_id = res_id;
    var pools = BattleRolePool.getInstance().getEffectPools();
    var effect = null;
 
    if (pools.size() > 0) {
      effect = pools.get();
      effect.active = true;
      this.createEffectWnd(effect);
    } else {
      this.createEffectWnd();
    } // 对特效资源进行计数
    // LoaderManager.getInstance().countSkeleton(this.res_id);
 
  },
  // 创建特效具体
  createEffectWnd: function createEffectWnd(effect) {
    if (effect == null) {
      effect = new cc.Node();
      effect.setAnchorPoint(0.5, 0.5);
      effect.addComponent(sp.Skeleton);
    }
 
    this.effect = effect;
    this.effect.scaleX = this.reverse;
    this.effect.rotation = 0;
 
    if (this.parent) {
      this.parent.addChild(this.effect);
    }
 
    this.skeleton = this.effect.getComponent(sp.Skeleton); // 设置位置
 
    this.effect.setPosition(this.scene_pos.x, this.scene_pos.y); // 设置当前的模型速率
 
    if (this.skeleton_time_scale) {
      this.skeleton.timeScale = this.skeleton_time_scale;
      this.skeleton_time_scale = null;
    } else {
      var timeScale = this.model.getTimeScale(); // if(this.model.isInRealBattle() == true){
      // timeScale = this.model.getTimeScale();
      // }
 
      this.skeleton.timeScale = timeScale;
    }
 
    this.resetInitStatus();
    this.registerEvent();
  },
  // 设置特效位置
  resetScenePos: function resetScenePos(scene_pos) {
    this.scene_pos = scene_pos;
 
    if (this.effect) {
      this.effect.setPosition(this.scene_pos.x, this.scene_pos.y);
    }
  },
  // 特效反转
  resetReverse: function resetReverse(reverse) {
    this.reverse = reverse;
 
    if (this.effect) {
      this.effect.scaleX = this.reverse;
    }
  },
  // 添加对象
  registerEvent: function registerEvent() {
    this.skeleton.setCompleteListener(function (trackEntry, loopCount) {
      var animationName = trackEntry.animation ? trackEntry.animation.name : "";
 
      if (this.over_func) {
        this.over_func(animationName); // 清掉动作事件
 
        this.over_func = null;
        this.event_func = null; // 单循环特效,可以直接清掉,这里可能会有问题,暂时这样处理
 
        this.play_action_name = "";
      }
    }.bind(this));
    this.skeleton.setEventListener(function (trackEntry, event) {
      if (this.event_func) {
        this.event_func(event.data.name);
      }
    }.bind(this));
  },
  // 设置动作伴随事件和动作结束事件回调
  setAnimationActionFunc: function setAnimationActionFunc(event_func, over_func) {
    this.event_func = event_func;
    this.over_func = over_func;
  },
  // 播放动作
  playActionOnce: function playActionOnce(action_name, res_name, is_loop) {
    res_name = res_name || "action";
 
    if (is_loop == null) {
      is_loop = true;
    }
 
    this.effect_play_key = Utils.getNorKey(this.res_id, action_name); //储存一下当前特效资源和动作
 
    var target_key = Utils.getNorKey(this.res_id, res_name);
 
    if (this.play_action_res == target_key) {
      if (this.play_action_name != action_name) {
        this.play_action_name = action_name;
        this.skeleton.setAnimation(0, action_name, is_loop);
      }
 
      return;
    }
 
    this.play_action_res = target_key;
    var skeleton_path = PathTool.getSpinePath(this.res_id, res_name); // var skeletonData = this.skelon_cache[skeleton_path]
    // if (skeletonData) {
    //     this.play_action_name = action_name
    //     this.skeleton.skeletonData = skeletonData;
    //     this.skeleton.setAnimation(0, action_name, is_loop);
    // } else {
    //     LoaderManager.getInstance().loadRes(skeleton_path, function (res_object) {
    //         this.play_action_name = action_name
    //         this.skeleton.skeletonData = res_object;
    //         this.skeleton.setAnimation(0, action_name, is_loop);
    //         if (!this.skelon_cache[skeleton_path]) {
    //             this.skelon_cache[skeleton_path] = res_object;
    //         }
    //     }.bind(this))
    // }
 
    if (this.skelon_cache[skeleton_path]) {
      this.play_action_name = action_name;
      this.skeleton.skeletonData = this.skelon_cache[skeleton_path];
      this.skeleton.setAnimation(0, action_name, is_loop);
    } else {
      BattleResPool.getInstance().getRes(skeleton_path, function (res_object) {
        this.play_action_name = action_name;
        this.skeleton.skeletonData = res_object;
        this.skeleton.setAnimation(0, action_name, is_loop);
 
        if (!this.skelon_cache[skeleton_path]) {
          this.skelon_cache[skeleton_path] = res_object;
        }
      }.bind(this));
    }
  },
  getEffectKey: function getEffectKey() {
    return this.effect_play_key || "";
  },
  // 当前深度值
  setLocalZOrder: function setLocalZOrder(zIndex) {
    if (this.effect) {
      this.effect.zIndex = zIndex;
    }
  },
  // 战斗动作播报
  runAction: function runAction(action) {
    if (this.effect) {
      this.effect.stopAllActions();
      this.effect.runAction(action);
    }
  },
  // 挂接到战斗单位身上的特效,当引用次数为0的时候,不需要移除掉,只要不可见,退出单位统一移除
  setActiveEffect: function setActiveEffect(status) {
    if (this.effect_active == status) {
      return;
    }
 
    this.effect_active = status;
 
    if (this.effect) {
      this.effect.active = status;
    }
  },
  // 初始化众泰
  resetInitStatus: function resetInitStatus() {
    if (this.skeleton) {
      this.skeleton.setToSetupPose();
      this.skeleton.clearTracks();
    }
  },
  // 子弹需要旋转角度
  setRotation: function setRotation(degree) {
    if (this.effect) {
      this.effect.rotation = degree;
    }
  },
  // 设置特效的播放速率
  setTimeScale: function setTimeScale(speed) {
    if (this.skeleton == null || this.skeleton.skeletonData == null) {
      this.skeleton_time_scale = speed;
    } else {
      if (this.skeleton_timeScale == speed) return;
      this.skeleton_timeScale = speed;
      this.skeleton.timeScale = speed;
    }
  },
  deleEffect: function deleEffect() {
    this.effect.stopAllActions();
    this.skeleton.skeletonData = null; // 清掉加载资源
 
    for (var skeletonIndex in this.skelon_cache) {
      BattleResPool.getInstance().delRes(skeletonIndex); // LoaderManager.getInstance().releaseRes(skeletonIndex);
    }
 
    this.skelon_cache = {}; // 回收掉
 
    BattleRolePool.getInstance().pushBackEffect(this.effect);
  }
});
 
cc._RF.pop();