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
"use strict";
cc._RF.push(module, '1e370LPZpZI56omBMKNFvi0', 'baserole');
// Scripts/common/baserole.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: shiraho@syg.com(必填, 创建模块的人员)
// @description:
//      通用展示角色对象
// <br/>Create: new Date().toISOString()
// --------------------------------------------------------------------
// var LoaderManager = require("loadermanager");
var PathTool = require("pathtool");
 
var BaseRole = cc.Class({
  "extends": BaseClass,
  ctor: function ctor() {
    this.loadFinish = false; // 是否加载完成
  },
  is_load_finish: false,
  action_data: null,
  // 尚未创建完成之前播放动作的携带数据
  anima_path: null,
  effect_path: null,
  statics: {
    type: {
      hero: 1,
      unit: 2
    }
  },
  setParent: function setParent(parent) {
    this.parent = parent;
    this.node = new cc.Node("");
    this.node.setAnchorPoint(0.5, 0.5);
    this.spine = this.node.addComponent(sp.Skeleton);
    var effect_nd = new cc.Node("");
    this.effect_sk = effect_nd.addComponent(sp.Skeleton);
    this.parent.addChild(this.node);
    this.node.addChild(effect_nd);
  },
  // 设置数据,这个是主接口,怪物类型和怪物id
  setData: function setData(unit_type, bidordata, action_name, loop, scale, setting) {
    // cc.log(unit_type, bidordata, action_name, loop, scale)
    var anima_path = null;
    var effect_path = null;
    scale = scale || 1;
    this.node.scale = scale;
    setting = setting || {};
    var effectScale = setting.scale || 1;
    this.effect_sk.node.scale = effectScale;
 
    if (unit_type == BaseRole.type.role) {
      var config = Config.looks_data.data_data[bidordata];
 
      if (config) {
        var key = Utils.getNorKey(config.partner_id, config.star);
        var star_config = gdata("partner_data", "data_partner_star", key);
        action_name = action_name ? action_name : PlayerAction.show;
        anima_path = cc.js.formatStr("spine/%s/%s.atlas", config.ico_id, action_name);
 
        if (star_config && star_config.show_effect != "") {
          // action_name = action_name ? action_name : PlayerAction.show; 
          // anima_path = cc.js.formatStr("spine/%s/%s.atlas", star_config.show_effect, action_name);
          if (star_config.show_effect) {
            effect_path = "spine/" + star_config.show_effect + "/action.atlas";
            var skin_id = config.skin_id;
 
            if (skin_id == 0 && setting.skin_id != null) {
              skin_id = setting.skin_id;
            }
 
            var skin_config = Config.partner_skin_data.data_skin_info[skin_id];
 
            if (skin_config && skin_config.res_id != null && skin_config.res_id != "") {
              anima_path = "spine/" + skin_config.res_id + "/show.atlas";
            }
 
            if (skin_config && skin_config.show_effect != "") {
              effect_path = "spine/" + skin_config.show_effect + "/action.atlas";
            }
          } else {
            if (this.effect_sk) {
              this.effect_sk.setToSetupPose();
              this.effect_sk.clearTracks();
            }
          }
        }
      }
    } else if (unit_type == BaseRole.type.partner) {
      // 测试使用
      var star_key = bidordata.bid + "_" + bidordata.star;
      var star_cfg = gdata("partner_data", "data_partner_star", star_key);
      anima_path = "spine/" + star_cfg.res_id + "/show.atlas";
      var test_cfg = gdata("partner_data", "data_partner_base", bidordata.bid); //英雄皮肤id
 
      var _skin_id = setting.skin_id;
      var _skin_config = Config.partner_skin_data.data_skin_info[_skin_id];
 
      if (_skin_config && _skin_config.res_id != null && _skin_config.res_id != "") {
        anima_path = "spine/" + _skin_config.res_id + "/show.atlas";
      } // 十星特效
 
 
      if (star_cfg.show_effect) {
        effect_path = "spine/" + star_cfg.show_effect + "/action.atlas";
 
        if (_skin_config && _skin_config.show_effect != "") {
          effect_path = "spine/" + _skin_config.show_effect + "/action.atlas";
        }
      } else {
        if (this.effect_sk) {
          this.effect_sk.setToSetupPose();
          this.effect_sk.clearTracks();
        }
      }
    } else if (unit_type == BaseRole.type.unit) {
      var config = Utils.getUnitConfig(bidordata);
 
      if (PathTool.specialBSModel(Number(bidordata))) {
        action_name = PlayerAction.battle_stand;
      }
 
      if (config != null) {
        anima_path = cc.js.formatStr("spine/%s/%s.atlas", config.body_id, action_name);
      }
    } else if (unit_type == BaseRole.type.skin) {
      if (typeof bidordata == "number") {
        //显示皮肤外观
        var _skin_id2 = bidordata;
        var _skin_config2 = Config.partner_skin_data.data_skin_info[_skin_id2];
 
        if (_skin_config2 && _skin_config2.res_id != null && _skin_config2.res_id != "") {
          anima_path = "spine/" + _skin_config2.res_id + "/show.atlas";
        }
 
        if (_skin_config2 && _skin_config2.show_effect != "") {
          effect_path = "spine/" + _skin_config2.show_effect + "/action.atlas";
        }
      }
    } else {}
 
    if (!anima_path) return;
 
    if (this.anima_path && this.anima_path != anima_path) {
      this.spine.enabled = false;
      LoaderManager.getInstance().releaseRes(this.anima_path);
    }
 
    if (this.effect_path && this.effect_path != effect_path) {
      this.effect_sk.enabled = false;
      LoaderManager.getInstance().releaseRes(this.effect_path);
    }
 
    LoaderManager.getInstance().loadRes(anima_path, function (res) {
      this.spine.enabled = true;
      this.spine.skeletonData = res;
      this.is_load_finish = true;
      this.setAnimationAct(action_name, loop);
    }.bind(this));
 
    if (effect_path) {
      LoaderManager.getInstance().loadRes(effect_path, function (effect_sd) {
        this.effect_sk.enabled = true;
        this.effect_sk.skeletonData = effect_sd;
        this.effect_sk.setAnimation(0, "action", true);
      }.bind(this));
    }
 
    this.effect_path = effect_path;
    this.anima_path = anima_path;
  },
  // 设置动作,如果是加载完成之后,那么直接播放,否则等加载之后播放
  setAnimation: function setAnimation(action_name, loop) {
    action_name = action_name ? action_name : PlayerAction.show;
 
    if (loop == null) {
      loop = true;
    }
 
    if (this.is_load_finish) {
      this.setAnimationAct(action_name, loop);
    } else {
      this.action_data = {
        action_name: action_name,
        loop: loop
      };
    }
  },
  // 播放动作的具体细节
  setAnimationAct: function setAnimationAct(action_name, loop) {
    if (this.spine.skeletonData) {
      this.spine.setAnimation(0, action_name, loop);
    }
  },
  setPosition: function setPosition(x, y) {
    if (this.node) {
      this.node.setPosition(x, y);
    }
  },
  showShadowUI: function showShadowUI(status) {
    if (status) {
      if (this.shadow == null) {
        var node = new cc.Node();
        this.sript_path = PathTool.getUIIconPath("common", "common_90095");
        LoaderManager.getInstance().loadRes(this.sript_path, function (res) {
          if (node && node.isValid) {
            node.addComponent(cc.Sprite).spriteFrame = res;
          }
        }.bind(this));
        this.node.addChild(node, -2);
        node.setPosition(0, -210);
        this.shadow = node;
      } else {
        this.shadow.active = true;
      }
    } else {
      if (this.shadow) {
        this.shadow.active = false;
      }
    }
  },
  // 移除对象,并且移除掉加载资源
  deleteMe: function deleteMe() {
    if (this.anima_path) LoaderManager.getInstance().releaseRes(this.anima_path);
    if (this.effect_path) LoaderManager.getInstance().releaseRes(this.effect_path);
    if (this.sript_path) LoaderManager.getInstance().releaseRes(this.sript_path);
    this.node.destroy();
  }
}); // 类型
 
BaseRole.type = {
  role: 0,
  //角色外观的       
  partner: 1,
  //伙伴的 在partner_data表里面的
  unit: 2,
  skin: 3 //显示皮肤外观
 
};
module.exports = BaseRole;
 
cc._RF.pop();