diff --git a/hwe/_admin4_submit.php b/hwe/_admin4_submit.php index 2e33444e..08e5a9bc 100644 --- a/hwe/_admin4_submit.php +++ b/hwe/_admin4_submit.php @@ -63,7 +63,6 @@ switch($btn) { ], 'general_id IN %li AND turn_idx = 0', $genlist); break; case "메세지 전달": - //TODO:새 갠메 시스템으로 변경 $date = TimeUtil::now(); $src = MessageTarget::buildQuick($session->generalID); for($i=0; $i < count($genlist); $i++) { diff --git a/hwe/b_currentCity.php b/hwe/b_currentCity.php index 744dcc25..f8f21e9a 100644 --- a/hwe/b_currentCity.php +++ b/hwe/b_currentCity.php @@ -133,13 +133,6 @@ if($myNation['level'] > 0) { if($rawSpy == ''){ $spyCities = []; } - else if(strpos($rawSpy, '|') !== false || is_numeric($rawSpy)){ - //TODO: 0.8 버전 이후에는 삭제할 것. 이후 버전은 json으로 변경됨. - $spyCities = array_map(function($val){ - $val = intval($val); - return intdiv($val, 10); - }, explode('|', $myNation['spy'])); - } else{ $spyCities = array_keys(Json::decode($rawSpy)); } diff --git a/hwe/b_genList.php b/hwe/b_genList.php index 20e927bc..387ab906 100644 --- a/hwe/b_genList.php +++ b/hwe/b_genList.php @@ -158,15 +158,7 @@ foreach ($generals as &$general) { $general['expLevelText'] = getExpLevel($general['experience']); - if ($general['npc'] >= 2) { - $name = "{$general['name']}"; - } elseif ($general['npc'] == 1) { - $name = "{$general['name']}"; - } else { - $name = $general['name']; - } - //TODO: npc 코드를 일원화 - $general['nameText'] = $name; + $general['nameText'] = getColoredName($general['name'], $general['npc']); $general['modeText'] = formatDefenceTrain($general['defence_train']); $general['crewtypeText'] = GameUnitConst::byId($general['crewtype'])->name??'-'; diff --git a/hwe/processing.php b/hwe/b_processing.php similarity index 56% rename from hwe/processing.php rename to hwe/b_processing.php index b6dace87..814a6a88 100644 --- a/hwe/processing.php +++ b/hwe/b_processing.php @@ -5,41 +5,72 @@ include "lib.php"; include "func.php"; //로그인 검사 -$commandType = Util::getReq('commandtype', 'string'); -$turnList = Util::getReq('turn', 'array_int'); +$commandType = Util::getReq('command', 'string'); +$turnList = array_map('intval', explode('_', Util::getReq('turnList', 'string', '0'))); +$isChiefTurn = Util::getReq('is_chief', 'bool', false); -if(!$turn || $commandtype === null){ - header('location:index.php', true, 303); +function die_redirect(){ + global $isChiefTurn; + if(!$isChiefTurn){ + header('location:index.php', true, 303); + } + else{ + header('location:b_chiefcenter.php', true, 303); + } die(); } +if(!$turnList || !$commandType){ + die_redirect(); +} +if(!is_array($turnList)){ + die_redirect(); +} + $session = Session::requireGameLogin()->setReadOnly(); $db = DB::db(); +if(!$isChiefTurn && !in_array($commandType, Util::array_flatten(GameConst::$availableGeneralCommand))){ + die_redirect(); +} + +if($isChiefTurn && !in_array($commandType, Util::array_flatten(GameConst::$availableChiefCommand))){ + die_redirect(); +} + $gameStor = KVStorage::getStorage($db, 'game_env')->turnOnCache(); $env = $gameStor->getValues(['init_year','init_month','startyear','year','month','show_img_level','join_mode','maxnation']); $general = General::createGeneralObjFromDB($session->generalID); -$commandObj = buildGeneralCommandClass($commandType, $general, $env); -if($general->getVar('level') < 5 && ($commandObj instanceof Command\NationCommand)){ - header('location:index.php', true, 303); - die(); +if(!$isChiefTurn){ + $commandObj = buildGeneralCommandClass($commandType, $general, $env); } +else{ + if($general->getVar('level') < 5){ + die_redirect(); + } + $commandObj = buildNationCommandClass($commandType, $general, $env, new LastTurn()); +} + if($commandObj->isArgValid()){ //인자가 필요없는 타입의 경우 processing에서 '전혀' 처리하지 않음! - header('location:index.php', true, 303); - die(); + die_redirect(); } -[$jsList, $cssList] = $commandObj->getResourceFiles(); +if(!$commandObj->isReservable()){ + die_redirect(); +} + +$jsList = $commandObj->getJSFiles(); +$cssList = $commandObj->getCSSFiles(); ?> -<?=$name?> +<?=$commandObj->getName()?> @@ -49,9 +80,13 @@ if($commandObj->isArgValid()){ +
-
-
- - - > - +
getForm()?> -

+
diff --git a/hwe/c_double.php b/hwe/c_double.php deleted file mode 100644 index 2fdbc3d1..00000000 --- a/hwe/c_double.php +++ /dev/null @@ -1,71 +0,0 @@ -setReadOnly(); -$userID = Session::getUserID(); - -//TODO: 삭제. 새로 짜 -throw new \sammo\NotImplementedException(); - -$db = DB::db(); - -if($command < 0) { $command = 0; } -if($double < 0) { $double = 0; } -if($third < 0) { $third = 0; } -if($fourth < 0) { $fourth = 0; } -if($command > 99) { $command = 0; } -if($double > 9999) { $double = 9999; } -if($fourth > 9999) { $fourth = 9999; } - -// 건국 -if($command == 46) { - die(); - -} - -//통합제의 -if($command == 53) { - header('location:b_chiefcenter.php'); - die(); -} - -//불가침 -if($command == 61) { - header('location:b_chiefcenter.php'); - die(); -} - -//포상, 몰수, 발령, 항복권고, 원조 -//선전포고, 종전, 파기, 초토화, 천도, 증축, 감축 -//백성동원, 수몰, 허보, 피장파장, 의병모집, 이호경식, 급습 -//국기변경 -if($command == 23 || $command == 24 || $command == 27 || $command == 51 || $command == 52 || $command > 60) { - header('location:b_chiefcenter.php'); - die(); -} - -//일반 턴 -header('Location:./'); - diff --git a/hwe/func_command.php b/hwe/func_command.php index 32717e18..c44c781a 100644 --- a/hwe/func_command.php +++ b/hwe/func_command.php @@ -206,10 +206,11 @@ function checkCommandArg(?array $arg):?string{ return null; } -function setGeneralCommand(int $generalID, array $turnList, string $command, ?array $arg = null):array{ - $turnList = array_unique($turnList); - foreach($turnList as $turnIdx){ - if(!is_int($turnIdx) || $turnIdx < 0 || $turnIdx >= GameConst::$maxTurn){ +function setGeneralCommand(int $generalID, array $rawTurnList, string $command, ?array $arg = null):array{ + + $turnList = []; + foreach($rawTurnList as $turnIdx){ + if(!is_int($turnIdx) || $turnIdx < -3 || $turnIdx >= GameConst::$maxTurn){ return [ 'result'=>false, 'reason'=>'올바른 턴이 아닙니다. : '.$turnIdx, @@ -217,7 +218,29 @@ function setGeneralCommand(int $generalID, array $turnList, string $command, ?ar 'target'=>$turnIdx, ]; } + if($turnIdx >= 0){ + $turnList[$turnIdx] = true; + } + else if($turnIdx == -1){ + //홀수 + for ($subIdx = 1; $subIdx < GameConst::$maxTurn; $subIdx+=2) { + $turnList[$subIdx] = true; + } + } + else if($turnIdx == -2){ + //짝수 + for ($subIdx = 0; $subIdx < GameConst::$maxTurn; $subIdx+=2) { + $turnList[$subIdx] = true; + } + } + else if($turnIdx == -3){ + //모두 + for ($subIdx = 0; $subIdx < GameConst::$maxTurn; $subIdx++) { + $turnList[$subIdx] = true; + } + } } + $turnList = array_keys($turnList); $argBasicTestResult = checkCommandArg($arg); if($argBasicTestResult !== null){ diff --git a/hwe/js/main.js b/hwe/js/main.js index 27753056..300a9e02 100644 --- a/hwe/js/main.js +++ b/hwe/js/main.js @@ -105,13 +105,17 @@ function reserveTurn(turnList, command){ $('#reserveTurn').click(function(){ var turnList = $('#generalTurnSelector').val().map(function(v){return parseInt(v);}); var $command = $('#generalCommandList option:selected'); - /*if($command.data('reqarg')){ - alert('TODO!'); + if($command.data('reqarg')){ + $.redirect( + "b_processing.php", { + command: $command.val(), + turnList: turnList.join('_') + }, "GET"); } - else*/{ + else{ reserveTurn(turnList, $command.val()); } - + return false; }) diff --git a/hwe/js/processing.js b/hwe/js/processing.js new file mode 100644 index 00000000..48d0f8b2 --- /dev/null +++ b/hwe/js/processing.js @@ -0,0 +1,83 @@ +function reserveTurn(turnList, command, arg){ + $.post({ + url:'j_set_general_command.php', + dataType:'json', + data:{ + action:command, + turnList:turnList, + arg:JSON.stringify(arg) + } + }).then(function(data){ + if(!data.result){ + alert(data.reason); + return; + } + + if(!isChiefTurn){ + window.location.href = './'; + } + else{ + window.location.href = 'b_chiefcenter.php'; + } + + }, errUnknown); +} + +jQuery(function($){ + +$('#commonSubmit').click(function(){ + + //checkCommandArg 참고 + var availableArgumentList = { + 'string':[ + 'nationName', 'optionText', 'itemType', 'nationType', + ], + 'int':[ + 'crewType', 'destGeneralID', 'destCityID', 'destNationID', + 'amount', 'colorType', 'itemCode', + 'month', + 'year', 'itemCode', 'destGeneralID', 'destCityID', 'destNationID', 'amount', 'crewType', + ], + 'boolean':[ + 'isGold', 'buyRice', + ], + 'integerArray':[ + 'destNationIDList', 'destGeneralIDList' + ] + } + + var handlerList = { + 'string':function($obj){ + return $.trim($obj.eq(0).val()); + }, + 'int':function($obj){ + return parseInt($obj.eq(0).val()); + }, + 'boolean':function($obj){ + return !!($obj.eq(0).val()); + }, + 'integerArray':function($obj){ + return $obj.map(function(){ + return parseInt($(this).val()); + }); + } + } + + var argument = {}; + for (var typeName in availableArgumentList) { + availableArgumentList[typeName].forEach(function(argName){ + var $obj = $('#'+argName); + if($obj.length == 0){ + return; + } + + argument[argName] = handlerList[typeName]($obj); + }); + } + + console.log(argument); + reserveTurn(turnList, command, argument); +}); + + +}); \ No newline at end of file diff --git a/hwe/preprocessing.php b/hwe/preprocessing.php deleted file mode 100644 index 4d708909..00000000 --- a/hwe/preprocessing.php +++ /dev/null @@ -1,124 +0,0 @@ -setReadOnly(); -$userID = Session::getUserID(); - -$db = DB::db(); - -$turn = Util::getReq('turn', 'array_int'); -$sel = Util::getReq('sel', 'int'); -$commandtype = Util::getReq('commandtype', 'int'); - -increaseRefresh("턴입력", 1); - -if(!$turn || $commandtype === null || $sel === null){ - header('location:commandlist.php', true, 303); - die(); -} - -$count = count($turn); -for($i=0; $i < $count; $i++) { - if($turn[$i] == 100 || $turn[$i] == 99 || $turn[$i] == 98) { - } elseif($turn[$i] >= 0 && $turn[$i] <= 23) { - } else { - unset($turn); - $turn[0] = 100; - break; - } -} - -if($turn[0] == 100) { - unset($turn); - for($i=0; $i < 24; $i++) $turn[$i] = $i; -} elseif($turn[0] == 99) { - unset($turn); - for($i=0, $j=0; $i < 24; $i+=2, $j++) $turn[$j] = $i; -} elseif($turn[0] == 98) { - unset($turn); - for($i=1, $j=0; $i < 24; $i+=2, $j++) $turn[$j] = $i; -} - -switch($commandtype) { - case 0: command_Single($turn, 0); break; //휴식 - case 1: command_Single($turn, 1); break; //농업 - case 2: command_Single($turn, 2); break; //상업 - case 3: command_Single($turn, 3); break; //기술 - case 4: command_Single($turn, 4); break; //선정 - case 5: command_Single($turn, 5); break; //수비 - case 6: command_Single($turn, 6); break; //성벽 - case 7: command_Single($turn, 7); break; //정착 장려 - case 8: command_Single($turn, 8); break; //치안 강화 - case 9: command_Single($turn, 9); break; //자금 조달 - -// case 11: command_11( $turn, 11, false); break; //징병 -// case 12: command_11( $turn, 12, true); break; //모병 - case 13: command_Single($turn, 13); break; //훈련 - case 14: command_Single($turn, 14); break; //사기진작 - case 15: command_Single($turn, 0); break; //전투태세 -// case 16: command_16( $turn, 16); break; //전쟁 - case 17: command_Single($turn, 17); break; //소집해제 - -// case 21: command_21( $turn, 21); break; //이동 -// case 22: command_22( $turn, 22); break; //등용 -// case 23: command_23( $turn, 23); break; //포상 -// case 24: command_24( $turn, 24); break; //몰수 -// case 25: command_25( $turn, 25); break; //임관 - case 26: command_Single($turn, 26); break; //집합 -// case 27: command_27( $turn, 27); break; //발령 - case 28: command_Single($turn, 28); break; //귀환 - case 29: command_Single($turn, 29); break; //인재탐색 -// case 30: command_30( $turn, 30); break; //강행 - -// case 31: command_31($turn, 31); break; //첩보 -// case 32: command_32($turn, 32); break; //화계 -// case 33: command_33($turn, 33); break; //탈취 -// case 34: command_34($turn, 34); break; //파괴 -// case 35: command_35($turn, 35); break; //선동 - - case 41: command_Single($turn, 41); break; //단련 - case 42: command_Single($turn, 42); break; //견문 -// case 43: command_43( $turn, 43); break; //증여 -// case 44: command_44( $turn, 44); break; //헌납 - case 45: command_Single($turn, 45); break; //하야 -// case 46: command_46( $turn, 46); break; //건국 - case 47: command_Single($turn, 47); break; //방랑 -// case 48: command_48( $turn, 48); break; //장비구입 -// case 49: command_49( $turn, 49); break; //군량매매 - case 50: command_Single($turn, 50); break; //요양 - -// case 51: command_51($turn, 51); break; //항복권고 -// case 52: command_52($turn, 52); break; //원조 -// case 53: command_53($turn, 53); break; //통합제의 -// case 54: command_54($turn, 54); break; //선양 - case 55: command_Single($turn, 55); break; //거병 - case 56: command_Single($turn, 56); break; //해산 - case 57: command_Single($turn, 57); break; //모반 시도 - -// case 61: command_61($turn, 61); break; //불가침 -// case 62: command_62($turn, 62); break; //선포 -// case 63: command_63($turn, 63); break; //종전 -// case 64: command_64($turn, 64); break; //파기 -// case 65: command_65($turn, 65); break; //초토화 -// case 66: command_66($turn, 66); break; //천도 -// case 67: command_67($turn, 67); break; //증축 -// case 68: command_68($turn, 68); break; //감축 - - case 71: command_Chief($turn, 71); break; //필사즉생 -// case 72: command_72($turn, 72); break; //백성동원 -// case 73: command_73($turn, 73); break; //수몰 -// case 74: command_74($turn, 74); break; //허보 -// case 75: command_75($turn, 75); break; //피장파장 - case 76: command_Chief($turn, 76); break; //의병모집 -// case 77: command_77($turn, 77); break; //이호경식 -// case 78: command_78($turn, 78); break; //급습 - -// case 81: command_81($turn, 81); break; //국기변경 - -// case 99: command_99($turn); break; //수뇌부 후식 - default: command_Other($turn, $commandtype); break; -} - diff --git a/hwe/sammo/Command/General/che_이동.php b/hwe/sammo/Command/General/che_이동.php index c53de534..e899c9f7 100644 --- a/hwe/sammo/Command/General/che_이동.php +++ b/hwe/sammo/Command/General/che_이동.php @@ -12,7 +12,8 @@ use \sammo\{ use function \sammo\{ - tryUniqueItemLottery + tryUniqueItemLottery, + printCitiesBasedOnDistance }; use \sammo\Constraint\Constraint; @@ -72,6 +73,13 @@ class che_이동 extends Command\GeneralCommand{ return 0; } + public function getBrief():string{ + $commandName = $this->getName(); + $destCityName = CityConst::byID($this->arg['destCityID'])->name; + $josaRo = JosaUtil::pick($destCityName, '로'); + return "【{$destCityName}】{$josaRo} {$commandName}"; + } + public function getFailString():string{ $commandName = $this->getName(); $failReason = $this->testRunnable(); @@ -142,20 +150,23 @@ class che_이동 extends Command\GeneralCommand{ public function getForm(): string { + $currentCityID = $this->generalObj->getCityID(); + $form = []; $form[] = \sammo\getMapHtml(); + $currentCityName = CityConst::byID($currentCityID)->name; $form[] = << 인접 도시로만 이동이 가능합니다.
목록을 선택하거나 도시를 클릭하세요.
- EOT; $form[] = \sammo\optionsForCities(); - $form[] = ''; - $form[] = ''; - $form[] = printCitiesBasedOnDistance($this->generalObj->getCityID(), 1); + $form[] = ' '; + $form[] = ''; + $form[] = printCitiesBasedOnDistance($currentCityID, 1); - return join("\n",$form); + return join("
\n",$form); } } \ No newline at end of file diff --git a/hwe/sammo/GameConstBase.php b/hwe/sammo/GameConstBase.php index 5a722f08..3770bdc0 100644 --- a/hwe/sammo/GameConstBase.php +++ b/hwe/sammo/GameConstBase.php @@ -254,7 +254,7 @@ class GameConstBase ] ]; - /** @var array[string] 선택 가능한 커맨드 */ + /** @var array 선택 가능한 커맨드 */ public static $availableChiefCommand = [ '휴식'=>[ '휴식',