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);
}
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());
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();
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());
var now_default = $('#unit_default_select_' + no).val();
var lead = parseInt($('#lead_unit_' + no).text());
var set_unit_type = now_unit_type;
var set_unit_cnt = 0;
var busho_name = $(this).find('a.busho_name').text();
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;
}
}
if (select_set_num === '1') {
if (now_unit_cnt === 0) {
set_unit_type = max_key;
} else {
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;
}
} 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;
}
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),
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 = {};
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();
if (type != defa && pool_unit[defa] === 0) {
object[defa] = 0;
}
});
return getSoldiersNum(object, pool_unit);
} else {
return setCardArray(pool_unit);
}
});
}
ixa-moko.user.js