Files
core/hwe/ts/recruitCrewForm.ts
T
2021-08-20 03:24:03 +09:00

113 lines
3.3 KiB
TypeScript

import $ from 'jquery';
import { unwrap_any } from './util/unwrap_any';
declare global {
interface Window {
calc: (id: number) => void;
submitAction: () => void;
}
}
declare const leadership: number;
declare const fullLeadership: number;
declare const currentCrewType: number;
declare const currentCrew: number;
declare const currentGold: number;
declare const is모병 = false;
window.calc = function (id) {
const $obj = $('#crewType{0}'.format(id));
const crew = parseInt(unwrap_any<string>($obj.find('.form_double').val()));
const baseCost = $obj.data('cost');
const $cost = $obj.find('.form_cost');
let cost = crew * baseCost;
if (is모병) {
cost *= 2;
}
$cost.val(Math.round(cost));
}
$(function () {
const $postForm = $('#post_form');
const $formAmount = $('#amount');
const $formCrewtype = $('#crewType');
$('.form_double').on('keyup change', function (e) {
const $this = $(this);
const $parent = $this.parents('.input_form');
const crewtype = parseInt($parent.data('crewtype'));
window.calc(crewtype);
$formCrewtype.val(crewtype);
$formAmount.val(parseFloat(unwrap_any<string>($this.val())) * 100);
if (e.which === 13) {
window.submitAction();
}
return false;
});
$('.btn_half').click(function () {
const $this = $(this);
const $parent = $this.closest('.input_form');
const crewtype = parseInt($parent.data('crewtype'));
const $input = $parent.find('.form_double:eq(0)');
const fillValue = Math.round(leadership / 2);
$formCrewtype.val(crewtype);
$input.val(fillValue).change();
return false;
});
$('.btn_fill').click(function () {
const $this = $(this);
const $parent = $this.closest('.input_form');
const crewtype = parseInt($parent.data('crewtype'));
const $input = $parent.find('.form_double:eq(0)');
let fillValue = Math.ceil((leadership * 100 - currentCrew) / 100);
if (crewtype != currentCrewType) {
fillValue = leadership;
}
$formCrewtype.val(crewtype);
$input.val(fillValue).change();
return false;
});
$('.btn_full').click(function () {
const $this = $(this);
const $parent = $this.closest('.input_form');
const crewtype = parseInt($parent.data('crewtype'));
const $input = $parent.find('.form_double:eq(0)');
const fillValue = fullLeadership + 15;
$formCrewtype.val(crewtype);
$input.val(fillValue).change();
return false;
});
$('.submit_btn').click(function () {
const $this = $(this);
const $parent = $this.closest('tr').find('.input_form');
const crewtype = parseInt($parent.data('crewtype'));
const $input = $parent.find('.form_double');
$formCrewtype.val(crewtype);
$formAmount.val(parseFloat(unwrap_any<string>($input.val())) * 100);
window.submitAction();
});
$('.btn_fill').click();
$('#show_unavailable_troops').change(function () {
const show = $('#show_unavailable_troops').is(":checked");
if (show) {
$('.show_default_false').show();
}
else {
$('.show_default_false').hide();
}
});
$('.show_default_false').hide();
});