징병 구현중

This commit is contained in:
2019-11-27 13:54:19 +09:00
parent d5aefccadc
commit 9600e18c92
4 changed files with 369 additions and 34 deletions
+86
View File
@@ -0,0 +1,86 @@
window.calc = function(id) {
var $obj = $('#crewType{0}'.format(id));
var crew = $obj.find('.form_double').val();
var baseCost = $obj.data('cost');
var $cost = $obj.find('.form_cost');
var cost = crew * baseCost;
if(window.is모병){
cost *= 2;
}
$cost.val(Math.round(cost));
}
$(function(){
var $postForm = $('#post_form');
var $formAmount = $postForm.find('.form_amount');
var $formCrewtype = $postForm.find('.form_crewtype');
$('.form_double').on('keyup change',function(e){
var $this = $(this);
var $parent = $this.parents('.input_form');
var crewtype = parseInt($parent.data('crewtype'));
calc(crewtype);
$formCrewtype.val(crewtype);
$formAmount.val($this.val());
if(e.which === 13){
$postForm.submit();
}
return false;
});
$('.btn_half').click(function(){
var $this = $(this);
var $parent = $this.closest('.input_form');
var crewtype = parseInt($parent.data('crewtype'));
var $input = $parent.find('.form_double:eq(0)');
var fillValue = Math.round(leadership / 2);
$formCrewtype.val(crewtype);
$input.val(fillValue).change();
return false;
});
$('.btn_fill').click(function(){
var $this = $(this);
var $parent = $this.closest('.input_form');
var crewtype = parseInt($parent.data('crewtype'));
var $input = $parent.find('.form_double:eq(0)');
var 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(){
var $this = $(this);
var $parent = $this.closest('.input_form');
var crewtype = parseInt($parent.data('crewtype'));
var $input = $parent.find('.form_double:eq(0)');
var fillValue = fullLeadership + 15;
$formCrewtype.val(crewtype);
$input.val(fillValue).change();
return false;
});
$('.submit_btn').click(function(){
var $this = $(this);
var $parent = $this.closest('tr').find('.input_form');
var crewtype = parseInt($parent.data('crewtype'));
var $input = $parent.find('.form_double');
$formCrewtype.val(crewtype);
$formAmount.val($input.val());
$postForm.submit();
});
$('.btn_fill').click();
});
+27 -1
View File
@@ -131,5 +131,31 @@ class che_선양 extends Command\GeneralCommand{
return true;
}
public function getForm(): string
{
//TODO: 암행부처럼 보여야...
$db = DB::db();
$destRawGenerals = $db->query('SELECT no,name,level,npc FROM general WHERE nation != 0 AND nation = %i AND no != %i ORDER BY npc,binary(name)',$this->generalObj->getNationID(), $this->generalObj->getID());
ob_start();
?>
군주의 자리를 다른 장수에게 물려줍니다.<br>
장수를 선택하세요.<br>
<select class='formInput' name="destGeneralID" id="destGeneralID" size='1' style='color:white;background-color:black;'>
<?php foreach($destRawGenerals as $destGeneral):
$color = \sammo\getNameColor($destGeneral['npc']);
if($color){
$color = " style='color:{$color}'";
}
$name = $destGeneral['name'];
if($destGeneral['level'] >= 5){
$name = "*{$name}*";
}
?>
<option value='<?=$destGeneral['no']?>' <?=$color?>><?=$name?></option>
<?php endforeach; ?>
</select> <input type=button id="commonSubmit" value="<?=$this->getName()?>"><br>
<?php
return ob_get_clean();
}
}
+31 -33
View File
@@ -168,49 +168,47 @@ class che_장비매매 extends Command\GeneralCommand{
$citySecu = $db->queryFirstField('SELECT secu FROM city WHERE city = %i', $this->generalObj->getCityID());
$gold = $this->generalObj->getVar('gold');
$form[] = <<<EOT
ob_start();
?>
<script>
function updateItemType(){
$('#itemType').val($('#itemCode option:selected').data('itemType'));
}
</script>
EOT;
$form[] = '<input type="hidden" class="formInput" name="itemType" id="itemType" value="item">';
$form[] = <<<EOT
<input type="hidden" class="formInput" name="itemType" id="itemType" value="item">
장비를 구입하거나 매각합니다.<br>
현재 구입 불가능한 것은 <font color=red>붉은색</font>으로 표시됩니다.<br>
현재 도시 치안 : {$citySecu} &nbsp;&nbsp;&nbsp;현재 자금 : {$gold}<br>
현재 도시 치안 : <?=$citySecu?> &nbsp;&nbsp;&nbsp;현재 자금 : <?=$gold?><br>
장비 : <select class='formInput' name="itemCode" id="itemCode" onchange='updateItemType();' size='1' style='color:white;background-color:black;'>
EOT;
foreach(GameConst::$allItems as $itemType=>$itemCategories){
//매각
$typeName = static::$itemMap[$itemType];
$form[] = "<option value='None' data-itemType='{$itemType}' style='color:skyblue'>_____{$typeName}매각(반값)____</option>";
//구입
foreach($itemCategories as $itemCode=>$cnt){
if($cnt > 0){
continue;
}
$itemClass = buildItemClass($itemCode);
if(!$itemClass->isBuyable()){
continue;
}
$itemName = $itemClass->getName();
$reqSecu = $itemClass->getReqSecu();
$reqGold = $itemClass->getCost();
$css = '';
if($reqSecu < $citySecu){
$css = 'color:red;';
}
$form[] = "<option value='{$itemCode}' data-itemType='{$itemType}' style='{$css}'>{$itemName} 가격: {$reqGold}</option>";
<?php foreach(GameConst::$allItems as $itemType=>$itemCategories):
//매각
$typeName = static::$itemMap[$itemType];
?>
<option value='None' data-itemType='<?=$itemType?>' style='color:skyblue'>_____<?=$typeName?>매각(반값)____</option>
//구입
<?php foreach($itemCategories as $itemCode=>$cnt) :
if($cnt > 0){
continue;
}
}
$form[] = <<<EOT
$itemClass = buildItemClass($itemCode);
if(!$itemClass->isBuyable()){
continue;
}
$itemName = $itemClass->getName();
$reqSecu = $itemClass->getReqSecu();
$reqGold = $itemClass->getCost();
$css = '';
if($reqSecu < $citySecu){
$css = 'color:red;';
}
?>
<option value='<?=$itemCode?>' data-itemType='<?=$itemType?>' style='<?=$css?>'><?=$itemName?> 가격: <?=$reqGold?></option>
<?php endforeach; ?>
<?php endforeach; ?>
</select>
<input type=submit value=거래>
EOT;
return join("\n",$form);
<?php
return ob_get_clean();
}
}
+225
View File
@@ -12,6 +12,7 @@ use \sammo\{
use function \sammo\{
function getTechCall,
tryUniqueItemLottery
};
@@ -206,5 +207,229 @@ class che_징병 extends Command\GeneralCommand{
return true;
}
public function getJSFiles(): array
{
return [
'js/recruitCrewForm.js'
];
}
public function getForm(): string
{
$db = DB::db();
$gameStor = KVStorage::getStorage($db, 'game_env');
$userID = Session::getUserID();
$general = $this->generalObj;
[$nationLevel, $tech] = $db->queryFirstList('SELECT level,tech FROM nation WHERE nation=%i', $me['nation']);
if(!$nationLevel){
$nationLevel = 0;
}
if(!$tech){
$tech = 0;
}
$lbonus = setLeadershipBonus($me, $nationLevel);
$ownCities = [];
$ownRegions = [];
[$year, $startyear] = $gameStor->getValuesAsArray(['year','startyear']);
$relativeYear = $year - $startyear;
foreach(DB::db()->query('SELECT city, region from city where nation = %i', $me['nation']) as $city){
$ownCities[$city['city']] = 1;
$ownRegions[$city['region']] = 1;
}
$leadership = $general->getLeadership();$fullLeadership = $general->getLeadership(false);
$abil = getTechAbil($tech);
$armTypes = [];
foreach(GameUnitConst::allType() as $armType => $armName){
$armTypeCrews = [];
foreach(GameUnitConst::byType($armType) as $unit){
$crewObj = new \stdClass;
if(!$unit->isValid($ownCities, $ownRegions, $relativeYear, $tech)){
continue; //TODO: 불가능한 병종도 보여줄 필요가 있음.
}
$crewObj->id = $unit->id;
if($unit->reqTech == 0){
$crewObj->bgcolor = 'green';
}
else{
$crewObj->bgcolor = 'limegreen';
}
$crewObj->baseRice = $unit->rice * getTechCost($tech);
$crewObj->baseCost = CharCost($unit->costWithTech($tech), $me['personal']);
$armType = $unit->armType;
if($me['special2'] == 50 && $armType == GameUnitConst::T_FOOTMAN){
$crewObj->baseCost *= 0.9;
}
else if($me['special2'] == 51 && $armType == GameUnitConst::T_ARCHER){
$crewObj->baseCost *= 0.9;
}
else if($me['special2'] == 52 && $armType == GameUnitConst::T_CAVALRY){
$crewObj->baseCost *= 0.9;
}
else if($me['special2'] == 53 && $armType == GameUnitConst::T_WIZARD){
$crewObj->baseCost *= 0.9;
}
else if($me['special2'] == 54 && $armType == GameUnitConst::T_SIEGE){
$crewObj->baseCost *= 0.9;
}
else if($me['special2'] == 72) {
$crewObj->baseCost *= 0.5;
}
$crewObj->name = $unit->name;
$crewObj->attack = $unit->attack + $abil;
$crewObj->defence = $unit->defence + $abil;
$crewObj->speed = $unit->speed;
$crewObj->avoid = $unit->avoid;
if($gameStor->show_img_level < 2) {
$crewObj->img = ServConfig::$sharedIconPath."/default.jpg";
}
else{
$crewObj->img = ServConfig::$gameImagePath."/weap".$unit->id.".png";
}
$crewObj->baseRiceShort = round($crewObj->baseRice, 1);
$crewObj->baseCostShort = round($crewObj->baseCost, 1);
$crewObj->info = join('<br>', $unit->info);
$armTypeCrews[] = $crewObj;
}
$armTypes[] = [$armName, $armTypeCrews];
}
$commandName = $this->getName();
$techLevelText = getTechCall($tech);
$crew = $general->getRaw('crew');
$gold = $general->getRaw('gold');
$crewTypeObj = $general->getCrewTypeObj();
$templates = new \League\Plates\Engine('templates');
return $templates->render('recruitCrewForm', [
'crewType'=>GameUnitConst::byId($me['crewtype'])->id,
'crewTypeName'=>GameUnitConst::byId($me['crewtype'])->name,
'crew'=>$me['crew'],
'gold'=>$me['gold'],
'turn'=>$turn,
'armTypes'=>$armTypes,
]);
$destRawGenerals = $db->query('SELECT no,name,level,npc,gold,rice FROM general WHERE nation != 0 AND nation = %i AND no != %i ORDER BY npc,binary(name)',$this->generalObj->getNationID(), $this->generalObj->getID());
ob_start();
?>
<font size=2>병사를 모집합니다.
<?php if($commandName=='징병'): ?>
훈련과 사기치는 낮지만 가격이 저렴합니다.<br>
<?php else: ?>
훈련과 사기치는 높지만 자금이 많이 듭니다.
<?php endif; ?>
가능한 수보다 많게 입력하면 가능한 최대 병사를 모집합니다.<br>
이미 병사가 있는 경우 추가<?=$commandName?>되며, 병종이 다를경우는 기존의 병사는 소집해제됩니다.<br>
현재 <?=$commandName?> 가능한 병종은 <font color=green>녹색</font>으로 표시되며,<br>
현재 <?=$commandName?> 가능한 특수병종은 <font color=limegreen>초록색</font>으로 표시됩니다.<br>
<table class='tb_layout' style='margin:auto;'>
<thead>
<?php if($commandName=='모병'): ?>
<tr><td align=center colspan=11>모병은 가격 2배의 자금이 소요됩니다.</td></tr>
<?php endif; ?>
<tr>
<td colspan=11 align=center class='bg2'>
현재 기술력 : <?=$techLevelText?>
현재 통솔 : <?=$leadership?><?=($leadership!=$fullLeadership)?"({$fullLeadership})":''?>
현재 병종 : <?=$crewTypeObj->name?>
현재 병사 : <?=$crew?>
현재 자금 : <?=$gold?>
</td>
</tr>
<tr>
<td width=64 align=center class='bg1'>사진</td>
<td width=64 align=center class='bg1'>병종</td>
<td width=40 align=center class='bg1'>공격</td>
<td width=40 align=center class='bg1'>방어</td>
<td width=40 align=center class='bg1'>기동</td>
<td width=40 align=center class='bg1'>회피</td>
<td width=40 align=center class='bg1'>가격</td>
<td width=40 align=center class='bg1'>군량</td>
<td width=180 align=center class='bg1'>병사수</td>
<td width=50 align=center class='bg1'>행동</td>
<td width=300 align=center class='bg1'>특징</td>
</tr>
</thead>
<tbody>
<?php foreach($armTypes as [$armName,$armTypeCrews]): ?>
<tr><td colspan=11><?=$armName?> 계열</td></tr>
<?php foreach($armTypeCrews as $crewObj): ?>
<tr
id="crewType<?=$crewObj->id?>"
style='height:64px;background-color:<?=$crewObj->bgcolor?>'
data-rice="<?=$crewObj->baseRice?>"
data-cost="<?=$crewObj->baseCost?>"
>
<td style='background:#222222 no-repeat center url("<?=$crewObj->img?>");background-size:64px'></td>
<td style='text-align:center;vertical-align:middle;'><?=$crewObj->name?></td>
<td style='text-align:center;vertical-align:middle;'><?=$crewObj->attack?></td>
<td style='text-align:center;vertical-align:middle;'><?=$crewObj->defence?></td>
<td style='text-align:center;vertical-align:middle;'><?=$crewObj->speed?></td>
<td style='text-align:center;vertical-align:middle;'><?=$crewObj->avoid?></td>
<td style='text-align:center;vertical-align:middle;'><?=$crewObj->baseCostShort?></td>
<td style='text-align:center;vertical-align:middle;'><?=$crewObj->baseRiceShort?></td>
<td style='text-align:center;vertical-align:middle;' class='input_form' data-crewtype='<?=$crewObj->id?>'>
<input type=button value='절반' class='btn_half'
><input type=button value='채우기' class='btn_fill'
><input type=button value='가득' class='btn_full'
><br>
<input type=text data-crewtype='<?=$crewObj->id?>' class=form_double name=double maxlength=3 size=3
style=text-align:right;color:white;background-color:black
>00명
<input type=text class=form_cost name=cost maxlength=5 size=5 readonly
style=text-align:right;color:white;background-color:black>원
</td>
<td style='position:relative;height:64px;'><input
type=submit value='<?=$commandName?>' class='submit_btn'
style='width:100%;height:44px;margin:10px 0;display:block;position: absolute;left:0;top:0;'
></td>
<td><?=$crewObj->info?></td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
</tbody>
</table>
<input type='hidden' name='form_amount' class='form_amount' value='1'>
<input type='hidden' name='form_crewType' class='form_crewType' value='<?=$crewTypeObj->id?>'>
<script>
window.currentTech = <?=$tech?>;
window.leadership = <?=$leadership?>;
window.fullLeadership = <?=$fullLeadership?>;
window.currentCrewType = <?=$crewTypeObj->id?>;
window.currentCrew = <?=$crew?>;
window.currentGold = <?=$gold?>;
window.is모병 = <?=($this->getName()=='모병')?'true':'false'?>;
</script>
<?php
return ob_get_clean();
}
}