--- Title: '' Author: ixa2023 Web: 'https://mimemo.io/m/ydN6woxb3B4p7qE' --- ```javascript:ixa-moko.user.js // 兵士編成兵士一括セット データ生成 function setCardArray(pool_unit) { var unit_list_set = function(card_array, i) { if (card_array.length === i) { var shonum = $('select[name="show_num"]').val(), select_card_group = $('#select_card_group').val(), href = location.pathname + '?show_num=' + shonum + '&select_card_group=' + select_card_group + '&select_filter_num=' + $('#select_filter_num').val(); return Info.title('完了', href); } // 既存の【変更】ボタンがAjaxである為、既存の【変更】ボタン押下では、変更処理完了をキャッチできない // mokoでは画面をモーダルにし【変更】ボタンの代用Ajaxで変更処理完了をキャッチしてから次の変更処理を行うようにしている Info.title('対象カードに一括セット中...'); Info.log('[' + card_array[i].card_name + ']'); Info.count((i + 1) + '/' + card_array.length + '人目'); var data = { card_id: card_array[i].card_id, unit_type: card_array[i].unit_type, unit_count: card_array[i].unit_count }; $.ajax({ type: 'post', url: '/facility/set_unit_list_if.php', data: data, beforeSend: xrwStatusText, }).then(function(html) { i++; return unit_list_set(card_array, i); }); }; var card_array = []; // 検索兵数 var select_target_num = parseInt($('#select_target_num').val()); // Number // 検索兵種 var select_target_branch = $('#select_target_branch').val(); // セット兵種選択 var select_set_branch = $('#select_set_branch').val(); // セット兵数選択 var select_set_num = $('#select_set_num').val(); // 簡易編成行単位ループ var $tr = $('table.busho_info').find('tr.tr_gradient:visible').slice(1); // 対象をフィルター // 兵数 $tr = $tr.filter(function() { var now_unit_cnt = parseInt($(this).find('SPAN[id^="now_unit_cnt"]').text()); var sol_num = {4:'槍隊', 5:'弓隊', 6:'馬隊'}; if (select_target_num == 3) { return this; } else if (Object.keys(sol_num).includes(select_target_num.toString())) { var s1 = []; $('input[id^="select_skill_"]:checked').each(function() { s1.push($(this).val()); }); if (!s1.length) { return; } var new_array = s1.map(function(v) { return sol_num[select_target_num] + v; }); var card_id = $(this).find('td:eq(0)').attr('onclick').split(',')[1].replace(/\s|\'|\)|;/g, ''); var data = get_card_data($('#cardWindow_' + card_id)); if (data) { if (new_array.includes(data.sname[0]) && data.sname.length == 1 && data.level == 0 && data.rank == 0) { return this; } } } else if (select_target_num == 2) { if (now_unit_cnt >= select_target_num) { return this; } } else if (now_unit_cnt == select_target_num) { return this; } }); // 兵種 $tr = $tr.filter(function() { var now_unit_type = $(this).find('INPUT[id^="now_unit_type"]').val(); if (select_target_branch == 'all') { return this; } else { if (now_unit_type == select_target_branch) { return this; } } }); $tr.each(function() { // 現状取得 // 行番号 var no = $(this).find('input[id^="key_str_array_"]').val(); // カードID var card_id = $('#card_id_arr_' + no).val(); // 兵種 var now_unit_type = $('#now_unit_type_' + no).val(); // 兵数 var now_unit_cnt = parseInt($('#now_unit_cnt_' + no).text()); // Number // 基本兵種 var now_default = $('#unit_default_select_' + no).val(); // 指揮力 var lead = parseInt($('#lead_unit_' + no).text()); // Number // セット兵種 var set_unit_type = now_unit_type; // セット兵数 var set_unit_cnt = 0; //Number // 武将名 var busho_name = $(this).find('a.busho_name').text(); // セット兵数が0でない場合 if (select_set_num !== '0') { // プールに指揮兵数を加算 if (now_unit_type) { pool_unit[now_unit_type] += now_unit_cnt; } // 現状兵種 if (select_set_branch == 'current_type') { set_unit_type = now_unit_type; // 基本兵種 } else if (select_set_branch == 'default_type') { set_unit_type = now_default; // 余り兵種 } else if (select_set_branch == 'remainder') { // 兵種の決定 // プール最大兵数兵種を求める var pool_max = 0, max_key = '', key; for (key in pool_unit) { if (pool_unit[key] > pool_max) { pool_max = pool_unit[key]; max_key = key; } } // セット兵数 1 if (select_set_num === '1') { // 指揮兵数 0 if (now_unit_cnt === 0) { set_unit_type = max_key; } else { // 指揮兵数 1以上 set_unit_type = now_unit_type; } // セット兵数 最大 } else { set_unit_type = max_key; } // 特定兵種 } else { set_unit_type = select_set_branch; } // 兵数 最大 if (select_set_num === 'max') { // 指揮力がプール兵数より大きいならプール兵数をセット if (lead > pool_unit[set_unit_type]) { set_unit_cnt = pool_unit[set_unit_type]; // 指揮力がプール兵数より小さいなら指揮力兵数をセット } else if (lead <= pool_unit[set_unit_type]) { set_unit_cnt = lead; } // 兵数 定数 } else if (select_set_num != '0') { if (pool_unit[set_unit_type] === 0 || !pool_unit[set_unit_type]) { set_unit_cnt = 0; } else { set_unit_cnt = select_set_num; } } // プールから差し引き if (set_unit_type) { pool_unit[set_unit_type] -= set_unit_cnt; } // セット兵数が0 } else { // 現状兵種 if (select_set_branch == 'current_type') { set_unit_type = now_unit_type; // 基本兵種 } else if (select_set_branch == 'default_type') { set_unit_type = now_default; // 余り兵種 } else if (select_set_branch == 'remainder') { return; // なし } else if (select_set_branch == 'no_type') { set_unit_type = ''; // 特定兵種 } else { set_unit_type = select_set_branch; } } // 変更前後で差異が無い場合は次の行 if (now_unit_type == set_unit_type && now_unit_cnt == set_unit_cnt) { return true; } // 対象行のカード番号、セット兵種、セット兵数をArrayに詰め込む var object = { card_name: busho_name, card_id: card_id, unit_type: set_unit_type, unit_count: set_unit_cnt }; card_array.push(object); }); if (!card_array.length) { return Info.title('該当カードなし', true); } else { return unit_list_set(card_array, 0); } } // 兵士編成兵士一括セット function unitListAllset() { if (location.pathname != '/facility/set_unit_list.php') { return; } var type_list1 = createSoldiersList()[0], type_list2 = '' + createSoldiersList()[1], default_list; if (options.unit_list_default) { default_list = '' + type_list2; } else { default_list = type_list2; } $('