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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
"use strict";
cc._RF.push(module, '5a5b5z2plxG9L+PaGlrhlMS', 'battle_loop');
// Scripts/mod/battle/battle_loop.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: shiraho@syg.com(必填, 创建模块的人员)
// @description:
//      假战斗单位生成器
// <br/>Create: new Date().toISOString()
// --------------------------------------------------------------------
window.BattleLoop = {
  /**
   * 初始化对象生成器
   * @param {*} data 
   */
  init: function init(data) {
    this.next_target_type_pos = 1;
    this.next_target_type_kill = 2;
    this.talk_cd = 0;
    this.col_info = [0, 1, 2, 3, 1, 2, 3, 1, 2, 3], this.col_pos_info = [[], [1, 4, 7], [2, 5, 8], [3, 6, 9]], this.idx = 0;
    this.data = data;
    this.a_objects = {};
    this.target_objects = {}; // this.icon_res_list = [5,2,7];
    // this.icon_idx = 0;
 
    this.randWaveTargets();
    this.b_formation_type = data.b_formation_type || 1;
    this.now_num = 0;
    this.max_num = Math.min(data.partner_list.length, 3);
    this.needPlays = {};
    this.last_pos = 0;
    this.last_time = 0;
    this.a_col = {};
    this.target_play = {};
    this.cd_time = 1;
 
    if (data.partner_list.length < 2) {
      this.cd_time = 2;
    }
 
    var config = Config.dungeon_data.data_drama_dungeon_info[data.dun_bid.toString()];
    this.talk_list = config.talk_ids;
    var play = {};
    play.objects = {};
    play.target_list = {};
    play.comabt_type = data.combat_type;
 
    for (var index = 0; index < data.partner_list.length; index++) {
      var element = data.partner_list[index];
      element.playing = 0;
      var temp_pos = index + 1;
      this.a_objects[temp_pos] = element;
      play.objects[temp_pos] = {
        pos: element.pos,
        object_bid: element.bid,
        bid: element.bid,
        star: element.star,
        object_type: 2,
        group: 1,
        hp: element.hp,
        hp_max: element.hp,
        skill_list: [],
        fashion: element.use_skin
      };
      var col = this.col_info[element.pos];
      this.a_col[col] = this.a_col[col] || {
        rnum: 0,
        "enum": 0
      };
      this.a_col[col].rnum += 1;
      this.a_col[col][element.pos] = temp_pos; // this.a_col[col][v.pos] = i;
 
      for (var i = 0; i < element.skill_list.length; i++) {
        var temp = element.skill_list[i];
        play.objects[temp_pos].skill_list.push(temp.sid);
      }
    }
 
    play.target_list[0] = this.nextTarget();
    return play;
  },
  // 产出下一波怪
  nextTarget: function nextTarget() {
    var now = gcore.SmartSocket.getTime();
    if (this.now_num >= this.max_num) return;
    if (this.now_num > 0 && now - this.last_time < this.cd_time) return;
    var pos_list = [];
    var pos_list2 = [];
    var pos = 0;
    var col = 0;
 
    for (var index = 1; index < 10; index++) {
      pos = index + GIRD_POS_OFFSET;
      col = this.col_info[index];
 
      if (this.target_objects[pos] == null && this.a_col[col] != null && this.last_pos != pos && this.a_col[col].rnum > this.a_col[col]["enum"]) {
        pos_list.push(pos);
 
        if (this.col_info[this.last_pos - GIRD_POS_OFFSET] != col) {
          pos_list2.push(pos);
        }
      }
    }
 
    if (pos_list2.length > 0) {
      pos_list = pos_list2;
    }
 
    if (pos_list.length > 0) {
      pos = this.rand_item(pos_list);
      col = this.col_info[pos - GIRD_POS_OFFSET];
      this.a_col[col]["enum"] = this.a_col[col]["enum"] + 1;
      var target = this.rand_item(this.b_objects);
      this.target_objects[pos] = target;
      this.needPlays[pos] = 1;
      this.last_pos = pos;
      this.last_time = now; // var icon = this.icon_res_list[this.icon_idx];
      // this.icon_idx = this.icon_idx % (this.icon_res_list.length) + 1
 
      this.now_num += 1;
      var play = this.init_play(pos);
      this.target_play[pos] = play;
      return {
        pos: pos,
        object_bid: target.bid,
        bid: target.bid,
        star: target.star,
        object_type: 3,
        group: 2,
        hp: target.hp,
        hp_max: target.hp,
        skill_list: [],
        actor: play.actor,
        effect_bid: play.effect_bid
      };
    }
  },
  // 技能播报计算
  init_play: function init_play(pos) {
    if (pos == null) return;
    var target = this.target_objects[pos];
    if (target == null || !this.needPlays[pos]) return;
    var a_idx = this.selectActor(pos);
    this.needPlays[pos] = a_idx;
    var actor = this.a_objects[a_idx];
    actor.playing = actor.playing + 1;
    var skill = this.rand_item_by_key(actor.skill_list, 'rand');
    var play = {
      skill_plays: [],
      actor: actor.pos,
      target: pos,
      skill_bid: skill.sid
    };
    var skill_idx = 1;
    var effect_idx = 1;
    var rand_object = this.rand_talk();
    var talk_pos = rand_object && rand_object.talk_pos ? rand_object.talk_pos : 0;
    var talk_content = rand_object && rand_object.talk_content ? rand_object.talk_content : "";
    var skill_play = {
      order: skill_idx,
      bid: actor.bid,
      actor: actor.pos,
      target: pos,
      skill_bid: skill.sid,
      effect_play: [],
      talk_pos: talk_pos,
      talk_content: talk_content
    };
    var hp = target.hp;
 
    for (var index = 0; index < skill.effect_list.length; index++) {
      var element = skill.effect_list[index];
      play.effect_bid = element.eid;
      var hurt = Utils.randomNum(element.min_hurt, element.max_hurt);
      var is_crit = 0;
      var tmp_crit = Utils.randomNum(0, 1000);
 
      if (tmp_crit < actor.crit) {
        hurt = Math.ceil(hurt * 1.5);
        is_crit = 1;
      }
 
      var dec_hp = hurt;
 
      if (index != skill.effect_list.length - 1) {
        dec_hp = Math.ceil(Math.min(hurt, hp) / skill.effect_list.length);
      }
 
      hp = Math.max(hp - dec_hp);
      var effect_play = {
        order: effect_idx,
        actor: actor.pos,
        target: pos,
        effect_bid: element.eid,
        hp: hp,
        hurt: -hurt,
        is_crit: is_crit
      };
      skill_play.effect_play.push(effect_play);
      effect_idx += 1;
    }
 
    play.skill_plays.push(skill_play);
    return play;
  },
  // 
  play: function play(pos) {
    var play = this.target_play[pos];
    this.target_play[pos] = null;
    return play;
  },
  // 选择进攻者(选在同行中,优先前排英雄)
  selectActor: function selectActor(pos) {
    var logic_pos = pos - GIRD_POS_OFFSET;
    var col = this.col_info[logic_pos];
    var col_pos = this.col_pos_info[col];
    var a_col_pos = this.a_col[col];
    var a_idx = 0;
    var a_front_idx = 0;
 
    for (var index = 0; index < col_pos.length; index++) {
      var a_pos = col_pos[index];
      a_idx = a_col_pos[a_pos];
 
      if (a_idx) {
        a_front_idx = a_front_idx || a_idx;
 
        if (this.a_objects[a_idx].playing == 0) {
          return a_idx;
        }
      }
    }
 
    return a_front_idx;
  },
  // 技能播放完成
  playEnd: function playEnd(pos) {
    var a_idx = this.needPlays[pos];
 
    if (a_idx) {
      var actor = this.a_objects[a_idx];
      actor.playing -= 1;
    }
 
    this.needPlays[pos] = null;
    this.target_objects[pos] = null;
    this.now_num -= 1;
    var col = this.col_info[pos - GIRD_POS_OFFSET];
 
    if (this.a_col[col]) {
      this.a_col[col]["enum"] -= 1;
    }
  },
  // 随机说话
  rand_talk: function rand_talk() {
    this.talk_cd = this.talk_cd - 1;
    if (this.talk_cd > 0) return;
    var talk = this.rand_item_by_key2(this.talk_list, 1, 10000);
 
    if (talk && talk[0]) {
      this.talk_cd = 5;
      var target = this.rand_item(this.a_objects);
      var idx = talk[0] || 1;
      var config = Config.dungeon_data.data_drama_talk[idx.toString()];
      return {
        talk_pos: target.pos,
        talk_content: config.talk
      };
    }
  },
  randWaveTargets: function randWaveTargets() {
    if (this.idx % 10 == 0) {
      this.b_objects = this.rand_item(this.data.wave_list).unit_list;
    }
 
    this.idx += 1;
  },
  // 随机从里面取出一项
  rand_item: function rand_item(tab) {
    if (tab instanceof Array) {
      var length = tab.length;
      var index = Utils.randomNum(1, length);
      return tab[index - 1];
    } else {
      var temp_ary = [];
 
      for (var key in tab) {
        temp_ary.push(key);
      }
 
      var _length = temp_ary.length;
      var index = Utils.randomNum(1, _length);
      var tab_key = temp_ary[index - 1];
      return tab[tab_key];
    }
  },
  // 按指定建随机一项
  rand_item_by_key: function rand_item_by_key(tab, key) {
    var sum = 0;
 
    for (var index = 0; index < tab.length; index++) {
      var element = tab[index];
      sum = sum + element[key];
    }
 
    return this.rand_item_by_key2(tab, key, sum);
  },
  rand_item_by_key2: function rand_item_by_key2(tab, key, sum) {
    var rank = Utils.randomNum(1, sum);
 
    for (var index = 0; index < tab.length; index++) {
      var element = tab[index];
      sum = sum - element[key];
 
      if (rank >= sum) {
        return element;
      }
    }
  }
}; // module.exports = BattleLoop;
 
cc._RF.pop();