0

    // 兵士編成兵士一括セット データ生成
    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 =  '<option value="no_type">なし</option>' + createSoldiersList()[1],
        default_list;
      if (options.unit_list_default) {
        default_list = '<option value="default_type">基本兵種</option>' + type_list2;
      } else {
        default_list = type_list2;
      }
      $('<div id="soldier_bulk_set">' +
        '<span>表示中の</span>' +
        '<select id="select_target_num">'+
          '<option value="3">すべての兵数</option>' +
          '<option value="0">兵数 0</option>' +
          '<option value="1">兵数 1</option>' +
          '<option value="2">兵数 2以上</option>' +
          '<option value="4">S1素材槍隊</option>' +
          '<option value="5">S1素材弓隊</option>' +
          '<option value="6">S1素材馬隊</option>' +
        '</select>' +
        '<span>の</span>' +
        '<select id="select_target_branch">' +
          '<option value="">なし</option>' +
          '<option value="all" selected>全兵種</option>' + 
          type_list1 +
        '</select>' +
        '<span>の武将に</span>' +
        '<select id="select_set_branch">' +
          '<option value="remainder">余り兵種</option>' +
          '<option value="current_type" selected>現状兵種</option>' +
          default_list  +
        '</select>' +
        '<span>を</span>' +
        '<select id="select_set_num">' +
          '<option value="max">最大</option>' +
          '<option value="0">0</option>' +
          '<option value="1">1</option>' + 
          '<option value="10">10</option>' +
          '<option value="100">100</option>' +
          '<option value="300">300</option>' +
          '<option value="600">600</option>' +
        '</select>' +
        '<span>兵</span>' +
        '<input type="button" id="heisi_set" value="一括セット" />' +
        '</div>'
      ).appendTo('#bulk_set_panel');

      $('<div id="select_skill_s1">' +
          '<label><input type="checkbox" id="select_skill_syuugeki" value="襲撃">襲撃</label> ' +
          '<label><input type="checkbox" id="select_skill_singeki" value="進撃">進撃</label> ' +
          '<label><input type="checkbox" id="select_skill_kensyu" value="堅守">堅守</label> ' +
          '<label><input type="checkbox" id="select_skill_sonae" value="備え">備え</label>' +
        '<div>'
      ).css({
        'display': 'flex',
        'margin-left': '30px'
      }).appendTo('#soldier_bulk_set');
  
      var setUnitValue = function() {
        var id_name = $(this).attr('id');
        each_setting.set_unit[id_name] = $(this).val();
        setStorage('ixamoko_each_setting', each_setting);
      },
      $select = $('#soldier_bulk_set select').change(setUnitValue);

      var select_skill_s1 = getStorage(null, 'ixamoko_select_skill_s1');
      if (select_skill_s1) {
        for (var key in select_skill_s1) {
          $('input[id="' + key + '"]').prop('checked', select_skill_s1[key]);
        }
      }
      else {
        select_skill_s1 = {
          'select_skill_syuugeki': false,
          'select_skill_singeki': false,
          'select_skill_kensyu': false,
          'select_skill_sonae': false
        }
      }

      $('#select_skill_s1 input').on('change', function(){
        var id_name = $(this).attr('id');
        select_skill_s1[id_name] = $(this).prop('checked');
        setStorage('ixamoko_select_skill_s1', select_skill_s1);
      });

      if (!each_setting.set_unit) {
        each_setting.set_unit = {};
        $select.each(setUnitValue);
      }
  
      for (var key in each_setting.set_unit) {
        $('select[id="' + key + '"]').val(each_setting.set_unit[key]);
      }
  
      var $select_target_branch = $('#select_target_branch'),
        $select_target_num = $('#select_target_num'),
        $select_set_branch = $('#select_set_branch'),
        $select_set_num = $('#select_set_num');
  
      $select_target_num.on('change', function() {
        var value = $(this).val();
        if ((value == 1 || value == 2) && !$select_target_branch.val()) {
          $select_target_branch.val('all').change();
        }
        if (value >= 4) {
          $('input[id^="select_skill_"]').prop('disabled', false);
        }
        else {
          $('input[id^="select_skill_"]').prop('disabled', true);
        }
      });
      $select_target_branch.on('change', function() {
        var value = $(this).val();
        if (!value) {
          $select_target_num.val('0').change();
        }
      });
      $select_set_branch.on('change', function() {
        var value = $(this).val();
        if (value == 'no_type') {
          $select_set_num.val('0').change();
        }
      });
      $select_set_num.on('change', function() {
        var value = $(this).val();
        if (value != '0' && $select_set_branch.val() == 'no_type') {
          $select_set_branch.val('current_type').change();
        }
      });
  
      // 一括セットクリック
      $('#heisi_set').on('click', function() {
        nowLoading();
        var select_target_branch = $select_target_branch.val(),
          select_target_num = $select_target_num.val(),
          select_set_branch = $select_set_branch.val(),
          select_set_num = $select_set_num.val();
  
        // プールの取得 ※存在兵種
        var pool_unit = {};
        $('td[id^="unit_count_"]').each(function() {
          var type = $(this).attr('id').match(/\d+/g);
          if (type >= 347) {
            return true;
          }
          pool_unit[type] = parseInt($(this).text());
        });
  
        var $tr = $('table.busho_info').find('tr.tr_gradient').slice(1),
        
        // 兵種変更の指揮兵数があれば全て0にする
        numReduction = function(keys) {
          var select_card_group = $('#select_card_group').val(),
          c = keys.length,
          post_query = function(data) {
            $.ajax({
              type: 'post',
              url: '/facility/set_unit_list.php',
              data: data,
              beforeSend: xrwStatusText,
            })
            .then(function(html) {
              c--;
              if (c === 0) {
                return setCardArray(pool_unit);
              }
            });
          };
  
          for (var i = 0, len = keys.length; i < len; i++) {
            var data = {
              show_deck_card_count: $('input[name="show_deck_card_count"]').val(),
              show_num: $('input[name="show_num"]').val(),
              select_card_group: select_card_group,
              select_filter_num: $('#select_filter_num').val(),
              p: $('#p').val(),
              now_unit_type: keys[i],
              now_group_type: select_card_group,
              edit_unit_type: 'now_unit',
              edit_unit_count: '0',
              btnlumpsum: 'true'
            };
            post_query(data);
          }
        },
        
        // 兵種変更の兵種の指揮兵数の判定
        confirmType = function(obj, pool_unit) {
          var key, keys;
          for (key in obj) {
            if (obj[key] === 0) {
              delete obj[key];
            }
          }
          keys = Object.keys(obj);
          if (!keys.length) {
            return setCardArray(pool_unit);
          } else {
            if (!confirm('兵数が不足している兵種が存在します\n選択中の組分けの武将を兵数0にしてから再セットします\n\n実行してよろしいですか?')) {
              return nowLoading(true);
            }
            for (key in obj) {
              pool_unit[key] += obj[key];
            }
            return numReduction(keys);
          }
        },
        
        // 兵種変更の兵種の指揮兵数を取得
        getSoldiersNum = function(object, pool_unit) {
          $tr.each(function() {
            var type = $(this).find('input[id^="now_unit_type"]').val(),
              $now_unit_cnt = $(this).find('span[id^="now_unit_cnt"]'),
              value = parseInt($now_unit_cnt.text());
            for (var key in object) {
              if (key != type) { continue; }
              object[key] += value;
              $now_unit_cnt.text('0');
            }
          });
          return confirmType(object, pool_unit);
        },
        object = {};
  
        /** セット兵種が基本兵種、兵種変更カード有り、兵種変更の兵種のプールが0
         *  表示ページ内の指揮兵種に兵種変更の兵種があれば、還元して利用する
         */
  
        // セット兵種 != 0 && セット兵種 == 基本兵種
        if (select_set_num != '0' && select_set_branch == 'default_type') {
          $tr.each(function() {
            var type = $(this).find('input[id^="now_unit_type"]').val(),
              defa = $(this).find('select[id^="unit_default_select"]').val();
            
            // 兵種変更の兵種のプール === 0
            if (type != defa && pool_unit[defa] === 0) {
              object[defa] = 0;
            }
          });
          return getSoldiersNum(object, pool_unit);
        } else {
          return setCardArray(pool_unit);
        }
      });
    }
ixa-moko.user.js
0

メモを他の人に見せる

このメモを見せたい人に、このURL(今開いているページのURLです)を教えてあげてください

コメント(0)

  • someone

  • someone