diff --git a/hwe/func_process_personnel.php b/hwe/func_process_personnel.php index 0fd5e0a7..73cac8c3 100644 --- a/hwe/func_process_personnel.php +++ b/hwe/func_process_personnel.php @@ -1,102 +1,6 @@ get(); - - $log = []; - $alllog = []; - $history = []; - $date = substr($general['turntime'],11,5); - - $admin = $gameStor->getValues(['startyear', 'year', 'month']); - - $query = "select * from city where city='{$general['city']}'"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $city = MYDB_fetch_array($result); - - $query = "select no from general where nation='{$general['nation']}'"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $gencount = MYDB_num_rows($result); - - $query = "select nation from nation where nation!={$general['nation']} AND name='{$general['makenation']}'"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $nationcount = MYDB_num_rows($result); - - $command = DecodeCommand($general['turn0']); - $color = $command[1]; - $type = $command[2]; // 1 ~ 13 - - $colors = GetNationColors(); - if($color >= count($colors)) { $color = 0; } - $color = $colors[$color]; - - if($type < 1) { $type = 9; } - elseif($type > 13) { $type = 9; } - - if($gencount < 2) { - $log[] = "●{$admin['month']}월:수하 장수가 부족합니다. 건국 실패. <1>$date"; - } elseif($admin['year'] >= $admin['startyear']+2) { - $log[] = "●{$admin['month']}월:건국 기간이 지났습니다. 건국 실패. <1>$date"; - } elseif($city['nation'] != 0) { - $log[] = "●{$admin['month']}월:공백지가 아닙니다. 건국 실패. <1>$date"; - } elseif($nationcount > 0) { - $log[] = "●{$admin['month']}월:존재하는 국가명입니다. 건국 실패. <1>$date"; - } elseif($general['makelimit'] > 0) { - $log[] = "●{$admin['month']}월:재야가 된지 12시간이 지나야 합니다. 건국 실패. <1>$date"; - } elseif($general['level'] != 12) { - $log[] = "●{$admin['month']}월:군주가 아닙니다. 건국 실패. <1>$date"; - } elseif($city['level'] != 5 && $city['level'] != 6) { - $log[] = "●{$admin['month']}월:중, 소 도시에서만 가능합니다. 건국 실패. <1>$date"; - } else { - $db->update('nation', [ - 'name'=>$general['makenation'], - 'color'=>$color, - 'level'=>1, - 'type'=>$type, - 'capital'=>$general['city'], - ], 'nation=%i', $general['nation']); - - refreshNationStaticInfo(); - $nation = getNationStaticInfo($general['nation']); - - // 현 도시 소속지로 - $query = "update city set nation='{$nation['nation']}',conflict='{}' where city='{$general['city']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - - $josaYi = JosaUtil::pick($general['name'], '이'); - $josaUl = JosaUtil::pick($nation['name'], '을'); - $log[] = "●{$admin['month']}월:{$nation['name']}{$josaUl} 건국하였습니다. <1>$date"; - $alllog[] = "●{$admin['month']}월:{$general['name']}{$josaYi} {$city['name']}에 국가를 건설하였습니다."; - $josaYi = JosaUtil::pick($nation['name'], '이'); - $history[] = "●{$admin['year']}년 {$admin['month']}월:【건국】".getNationType($type)." {$nation['name']}{$josaYi} 새로이 등장하였습니다."; - pushGeneralHistory($general, "●{$admin['year']}년 {$admin['month']}월:{$nation['name']}{$josaUl} 건국"); - $josaYi = JosaUtil::pick($general['name'], '이'); - pushNationHistory($nation, "●{$admin['year']}년 {$admin['month']}월:{$general['name']}{$josaYi} {$nation['name']}{$josaUl} 건국"); - - $exp = 1000; - $ded = 1000; - - - - // 성격 보정 - $exp = CharExperience($exp, $general['personal']); - $ded = CharDedication($ded, $general['personal']); - - // 명성 상승 - $query = "update general set resturn='SUCCESS',dedication=dedication+'$ded', experience=experience+'$exp' where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - - $log = uniqueItem($general, $log, 3); - } - - pushWorldHistory($history, $admin['year'], $admin['month']); - pushGeneralPublicRecord($alllog, $admin['year'], $admin['month']); - pushGenLog($general, $log); -} - function process_47(&$general) { $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); @@ -236,95 +140,6 @@ function process_54(&$general) { pushWorldHistory($history, $admin['year'], $admin['month']); } -function process_55(&$general) { - $db = DB::db(); - $gameStor = KVStorage::getStorage($db, 'game_env'); - $connect=$db->get(); - - $log = []; - $alllog = []; - $history = []; - - $date = substr($general['turntime'],11,5); - - $admin = $gameStor->getValues(['startyear', 'year', 'month']); - - $query = "select name from city where city='{$general['city']}'"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $city = MYDB_fetch_array($result); - - $query = "select nation from nation where name='{$general['name']}'"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $nationcount = MYDB_num_rows($result); - - if($nationcount > 0) { $makename = mb_substr("$nationcount".$general['name'], 0, 6); } - else { $makename = $general['name']; } - - if($general['level'] != 0) { - $log[] = "●{$admin['month']}월:재야가 아닙니다. 거병 실패. <1>$date"; - } elseif($admin['year'] >= $admin['startyear']+2) { - $log[] = "●{$admin['month']}월:거병 기간이 지났습니다. 거병 실패. <1>$date"; - } elseif($general['makelimit'] > 0) { - $log[] = "●{$admin['month']}월:재야가 된지 12시간이 지나야 합니다. 거병 실패. <1>$date"; - } else { - - DB::db()->insert('nation', [ - 'name'=>$makename, - 'color'=>'#330000', - 'gold'=>0, - 'rice'=>GameConst::$baserice, - 'rate'=>20, - 'bill'=>100, - 'sabotagelimit'=>36, - 'surlimit'=>72, - 'type'=>0, - 'gennum'=>1 - ]); - $nationID = DB::db()->insertId(); - - refreshNationStaticInfo(); - $nation = getNationStaticInfo($nationID); - - $exp = 100; - $ded = 100; - - // 성격 보정 - $exp = CharExperience($exp, $general['personal']); - $ded = CharDedication($ded, $general['personal']); - - // 명성 상승 - // 군주로 - // 현 국가 소속으로 - $query = "update general set resturn='SUCCESS',belong=1,level=12,nation='{$nation['nation']}',dedication=dedication+'$ded', experience=experience+'$exp' where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - - $josaYi = JosaUtil::pick($general['name'], '이'); - $log[] = "●{$admin['month']}월:거병에 성공하였습니다. <1>$date"; - $alllog[] = "●{$admin['month']}월:{$general['name']}{$josaYi} {$city['name']}에서 거병하였습니다."; - $history[] = "●{$admin['year']}년 {$admin['month']}월:【거병】{$general['name']}{$josaYi} 세력을 결성하였습니다."; - pushGeneralHistory($general, "●{$admin['year']}년 {$admin['month']}월:{$city['name']}에서 거병"); - pushNationHistory($nation, "●{$admin['year']}년 {$admin['month']}월:{$general['name']}{$josaYi} {$city['name']}에서 거병"); - - // 외교테이블 추가 - - - foreach(getAllNationStaticInfo() as $younation){ - if($nation['nation'] == $younation['nation']){ - continue; - } - - //FIXME: 쿼리 개선. foreach문은 굳이 필요없을것 - $query = "insert into diplomacy (me, you, state, term) values ('{$nation['nation']}', '{$younation['nation']}', '2', '0')"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $query = "insert into diplomacy (me, you, state, term) values ('{$younation['nation']}', '{$nation['nation']}', '2', '0')"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - } - } - pushWorldHistory($history, $admin['year'], $admin['month']); - pushGeneralPublicRecord($alllog, $admin['year'], $admin['month']); - pushGenLog($general, $log); -} - function process_56(&$general) { $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); diff --git a/hwe/sammo/Command/BaseCommand.php b/hwe/sammo/Command/BaseCommand.php index 950763af..e7c89004 100644 --- a/hwe/sammo/Command/BaseCommand.php +++ b/hwe/sammo/Command/BaseCommand.php @@ -84,6 +84,18 @@ abstract class BaseCommand{ $this->generalObj->setRawCity($this->city); return; } + + $this->city = $this->generalObj->getRawCity(); + $hasArgs = true; + foreach($args as $arg){ + if(!key_exists($arg, $this->city)){ + $hasArgs = false; + break; + } + } + if($hasArgs){ + return; + } $this->city = $db->queryFirstRow('SELECT %lb FROM city WHERE city=%i', $args, $this->generalObj->getVar('city')); if($this->generalObj->getRawCity() === null){ $this->generalObj->setRawCity($this->city); diff --git a/hwe/sammo/Command/General/che_거병.php b/hwe/sammo/Command/General/che_거병.php new file mode 100644 index 00000000..cb101b6c --- /dev/null +++ b/hwe/sammo/Command/General/che_거병.php @@ -0,0 +1,155 @@ +arg = []; + + return true; + } + + protected function init(){ + + $general = $this->generalObj; + $env = $this->env; + + $this->setCity(); + $this->setNation(); + + if(!key_exists($colorType, GetNationColors())){ + return false; + } + + $relYear = $env['year'] - $env['startyear']; + + $this->runnableConstraints=[ + ['BeNeutral'], + ['BeOpeningPart', $relYear], + ['AllowJoinAction'], + ]; + } + + public function getCost():array{ + return [0, 0]; + } + + public function getPreReqTurn():int{ + return 0; + } + + public function getPostReqTurn():int{ + return 0; + } + + public function run():bool{ + if(!$this->isRunnable()){ + throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도'); + } + + $db = DB::db(); + $env = $this->env; + + $general = $this->generalObj; + $date = substr($general->getVar('turntime'),11,5); + + $generalName = $general->getName(); + $josaYi = JosaUtil::pick($generalName, '이'); + + $nationName = $generalName; + $cityName = $this->city['name']; + + $nationNameExistsCnt = $db->queryFirstField('SELECT count(*) FROM nation WHERE name = %s', $nationName); + if($nationNameExistsCnt){ + $nationName = mb_strimwidth('㉥'.$nationName, 0, 18); + } + $nationNameExistsCnt = $db->queryFirstField('SELECT count(*) FROM nation WHERE name = %s', $nationName); + if($nationNameExistsCnt){ + //여전히 중복된다면, 그냥 글자 길이 넘어가든 말든 신경쓰지 말고 넘기기. + $nationName = '㉥'.$nationName; + } + + + $diplomacyInit = []; + foreach(getAllNationStaticInfo() as $destNation){ + $destNationID = $destNation['nation']; + $diplomacyInit[] = [ + 'me'=>$destNationID, + 'you'=>$nationID, + 'state'=>2, + 'term'=>0, + ]; + + $diplomacyInit[] = [ + 'me'=>$nationID, + 'you'=>$destNationID, + 'state'=>2, + 'term'=>0, + ]; + } + $db->insert('diplomacy', $diplomacyInit); + + DB::db()->insert('nation', [ + 'name'=>$nationName, + 'color'=>'#330000', + 'gold'=>0, + 'rice'=>GameConst::$baserice, + 'rate'=>20, + 'bill'=>100, + 'sabotagelimit'=>12, + 'surlimit'=>72, + 'type'=>0, + 'gennum'=>1 + ]); + $nationID = DB::db()->insertId(); + + refreshNationStaticInfo(); + + $logger->pushGeneralActionLog("거병에 성공하였습니다. <1>$date"); + $logger->pushGlobalActionLog("{$generalName}{$josaYi} {$cityName}에 거병하였습니다."); + + $logger->pushGlobalHistoryLog("【거병】{$generalName}{$josaYi} 세력을 결성하였습니다."); + $logger->pushGeneralHistoryLog("{$cityName}에서 거병"); + $logger->pushNationalHistoryLog("{$generalName}{$josaYi} {$cityName}에서 거병"); + + $exp = 100; + $ded = 100; + + $exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp); + $ded = $general->onPreGeneralStatUpdate($general, 'dedication', $ded); + + $general->increaseVar('experience', $exp); + $general->increaseVar('dedication', $ded); + $general->setVar('belong', 1); + $general->setVar('level', 12); + $general->setVar('nation', $nationID); + + $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); + $general->checkStatChange(); + $general->applyDB($db); + + return true; + } + + +} \ No newline at end of file diff --git a/hwe/sammo/Command/General/che_건국.php b/hwe/sammo/Command/General/che_건국.php index f870ed1a..d9eadb38 100644 --- a/hwe/sammo/Command/General/che_건국.php +++ b/hwe/sammo/Command/General/che_건국.php @@ -43,6 +43,10 @@ class che_건국 extends Command\GeneralCommand{ return false; } + if(!key_exists($colorType, GetNationColors())){ + return false; + } + try{ $nationTypeClass = getNationTypeClass($nationType); } @@ -71,25 +75,11 @@ class che_건국 extends Command\GeneralCommand{ $this->setCity(); $this->setNation(); - $destGeneralID = $this->arg['destGeneralID']??null; - $destNationID = $this->arg['destNationID']??null; - if($destGeneralID !== null){ - $this->setDestGeneral($destGeneralID); - $this->setDestNation($this->destGeneralObj->getVar('nation')); - } - else{ - $this->setDestNation($destNationID, ['gennum', 'scout']); - } - - if(!key_exists($colorType, GetNationColors())){ - return false; - } - $relYear = $env['year'] - $env['startyear']; $this->runnableConstraints=[ ['ReqNationValue', 'gennum', '수하 장수', '>=', 2], - ['BeOpeningPart'], + ['BeOpeningPart', $relYear], ['WanderingNation'], ['CheckNationNameDuplicate', $nationName], ['BeLord'],