diff --git a/hwe/func_process.php b/hwe/func_process.php index 3979e638..7b427061 100644 --- a/hwe/func_process.php +++ b/hwe/func_process.php @@ -551,138 +551,6 @@ function process_16(&$general) { pushGenLog($general, $log); } -function process_26(&$general) { - $db = DB::db(); - $gameStor = KVStorage::getStorage($db, 'game_env'); - $connect=$db->get(); - - $log = []; - $alllog = []; - $history = []; - $date = substr($general['turntime'],11,5); - - $troop = getTroop($general['troop']); - - $admin = $gameStor->getValues(['year', 'month']); - - $query = "select nation,name,supply 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,name,nation,city from general where troop='{$general['troop']}' and no!='{$general['no']}'"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $gencount = MYDB_num_rows($result); - - if($general['nation'] != $city['nation']) { - $log[] = "●{$admin['month']}월:아국이 아닙니다. 집합 실패. <1>$date"; - } elseif($city['supply'] == 0) { - $log[] = "●{$admin['month']}월:고립된 도시입니다. 집합 실패. <1>$date"; - } elseif($general['no'] != $troop['no']) { - $log[] = "●{$admin['month']}월:부대장이 아닙니다. 집합 실패. <1>$date"; - } elseif($gencount == 0) { - $log[] = "●{$admin['month']}월:집합 가능한 부대원이 없습니다. 집합 실패. <1>$date"; - } else { - $log[] = "●{$admin['month']}월:{$city['name']}에서 집합을 실시했습니다. <1>$date"; - $exp = 70; - $ded = 100; - - // 성격 보정 - $exp = CharExperience($exp, $general['personal']); - $ded = CharDedication($ded, $general['personal']); - - //부대원에게 로그 전달 - $josaRo = JosaUtil::pick($city['name'], '로'); - $genlog = ["{$troop['name']}의 부대원들은 {$city['name']}{$josaRo} 집합되었습니다."]; - - for($i=0; $i < $gencount; $i++) { - $troopgen = MYDB_fetch_array($result); - if($general['city'] != $troopgen['city']) { - pushGenLog($troopgen, $genlog); - } - } - - // 같은 부대원 모두 집합 - $query = "update general set city='{$general['city']}' where troop='{$general['troop']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - // 경험치 명성 공헌 상승 - $general['leader2']++; - $query = "update general set resturn='SUCCESS',leader2='{$general['leader2']}',dedication=dedication+'$ded',experience=experience+'$exp' where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - - $log = checkAbility($general, $log); - $log = uniqueItem($general, $log); - } - - pushGeneralPublicRecord($alllog, $admin['year'], $admin['month']); - pushGenLog($general, $log); -} - -function process_28(&$general) { - $db = DB::db(); - $gameStor = KVStorage::getStorage($db, 'game_env'); - $connect=$db->get(); - - $log = []; - $alllog = []; - $history = []; - $youlog = []; - - $date = substr($general['turntime'],11,5); - - $admin = $gameStor->getValues(['year', 'month']); - - $nation = getNationStaticInfo($general['nation']); - - if($nation['level'] == 0) { - $log[] = "●{$admin['month']}월:방랑군입니다. 귀환 실패. <1>$date"; - } elseif($general['level'] == 0) { - $log[] = "●{$admin['month']}월:재야입니다. 귀환 실패. <1>$date"; - } elseif(($general['level'] == 1 || $general['level'] >= 5) && $general['city'] == $nation['capital']) { - $log[] = "●{$admin['month']}월:이미 수도입니다. 귀환 실패. <1>$date"; - } else { - if($general['level'] == 2) { - $query = "select city,name from city where gen3='{$general['no']}'"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $city = MYDB_fetch_array($result); - } elseif($general['level'] == 3) { - $query = "select city,name from city where gen2='{$general['no']}'"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $city = MYDB_fetch_array($result); - } elseif($general['level'] == 4) { - $query = "select city,name from city where gen1='{$general['no']}'"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $city = MYDB_fetch_array($result); - } else { - $query = "select city,name from city where city='{$nation['capital']}'"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $city = MYDB_fetch_array($result); - } - - $josaRo = JosaUtil::pick($city['name'], '로'); - $log[] = "●{$admin['month']}월:{$city['name']}{$josaRo} 귀환했습니다. <1>$date"; - $exp = 70; - $ded = 100; - - // 성격 보정 - $exp = CharExperience($exp, $general['personal']); - $ded = CharDedication($ded, $general['personal']); - - // 귀환 - $query = "update general set city='{$city['city']}' where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - - // 경험치 상승 // 명성,공헌 상승 - $general['leader2']++; - $query = "update general set resturn='SUCCESS',leader2='{$general['leader2']}',experience=experience+'$exp',dedication=dedication+'$ded' where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - - $log = checkAbility($general, $log); - } - - pushGenLog($general, $log); - //pushGenLog($you, $youlog); -} - function process_31(&$general) { $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); diff --git a/hwe/sammo/Command/General/che_강행.php b/hwe/sammo/Command/General/che_강행.php index 0f70b5cc..2efffda2 100644 --- a/hwe/sammo/Command/General/che_강행.php +++ b/hwe/sammo/Command/General/che_강행.php @@ -92,7 +92,7 @@ class che_강행 extends Command\GeneralCommand{ $general->setVar('city', $destCityID); if($general->getVar('level') == 12 && $this->nation['level'] == 0){ - $generalList = $db->queryFirstColumn('SELECT no, name, city, nation, level FROM general WHERE nation=%i AND no!=%i', $general->getNationID(), $general->getID()); + $generalList = $db->query('SELECT no, name, city, nation, level FROM general WHERE nation=%i AND no!=%i', $general->getNationID(), $general->getID()); foreach($generalList as $targetRawGeneral){ $targetGeneralID = $targetRawGeneral['no']; $targetGeneral = $this->getGeneralObjFromGeneralSource($targetGeneralID); diff --git a/hwe/sammo/Command/General/che_귀환.php b/hwe/sammo/Command/General/che_귀환.php new file mode 100644 index 00000000..0ef34dcc --- /dev/null +++ b/hwe/sammo/Command/General/che_귀환.php @@ -0,0 +1,101 @@ +generalObj; + + $this->setCity(); + $this->setNation(); + + [$reqGold, $reqRice] = $this->getCost(); + + $this->runnableConstraints=[ + ['NoNeutral'], + ['NoWanderingNation'], + ['NotCapital', 1], + ]; + } + + protected function argTest():bool{ + $this->arg = null; + return true; + } + + 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; + $generalID = $general->getID(); + $date = substr($general->getVar('turntime'),11,5); + + switch($general->getVar('level')){ + case 2: [$cityID, $cityName] = $db->queryFirstList('SELECT city, name FROM city WHERE gen3=%i', $generalID); break; + case 3: [$cityID, $cityName] = $db->queryFirstList('SELECT city, name FROM city WHERE gen2=%i', $generalID); break; + case 4: [$cityID, $cityName] = $db->queryFirstList('SELECT city, name FROM city WHERE gen1=%i', $generalID); break; + default: [$cityID, $cityName] = $db->queryFirstList('SELECT city, name FROM city WHERE city=%i', $this->nation['capital']); break; + } + + $josaRo = JosaUtil::pick($cityName, '로'); + + $logger = $general->getLogger(); + + $logger->pushGeneralActionLog("{$cityName}{$josaRo} 귀환했습니다. <1>$date"); + + $exp = 70; + $ded = 100; + $exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp); + $ded = $general->onPreGeneralStatUpdate($general, 'dedication', $ded); + + $general->setVar('city', $cityID); + + $general->increaseVar('experience', $exp); + $general->increaseVar('dedication', $ded); + $general->increaseVar('leader2', 1); + $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); + $general->checkStatChange(); + $general->applyDB($db); + + } + + +} \ No newline at end of file diff --git a/hwe/sammo/Command/General/che_이동.php b/hwe/sammo/Command/General/che_이동.php index c7ba80d0..7297ca0c 100644 --- a/hwe/sammo/Command/General/che_이동.php +++ b/hwe/sammo/Command/General/che_이동.php @@ -92,7 +92,7 @@ class che_이동 extends Command\GeneralCommand{ $general->setVar('city', $destCityID); if($general->getVar('level') == 12 && $this->nation['level'] == 0){ - $generalList = $db->queryFirstColumn('SELECT no, name, city, nation, level FROM general WHERE nation=%i AND no!=%i', $general->getNationID(), $general->getID()); + $generalList = $db->query('SELECT no, name, city, nation, level FROM general WHERE nation=%i AND no!=%i', $general->getNationID(), $general->getID()); foreach($generalList as $targetRawGeneral){ $targetGeneralID = $targetRawGeneral['no']; $targetGeneral = $this->getGeneralObjFromGeneralSource($targetGeneralID); diff --git a/hwe/sammo/Command/General/che_집합.php b/hwe/sammo/Command/General/che_집합.php new file mode 100644 index 00000000..4b7a8bd3 --- /dev/null +++ b/hwe/sammo/Command/General/che_집합.php @@ -0,0 +1,113 @@ +generalObj; + + $this->setCity(); + $this->setNation(); + $this->setDestCity($this->arg['destCityID'], []); + + [$reqGold, $reqRice] = $this->getCost(); + + $this->runnableConstraints=[ + ['NoNeutral'], + ['OccupiedCity'], + ['SuppliedCity'], + ['MustBeTroopLeader'], + ['ReqTroopMembers'], + ]; + } + + protected function argTest():bool{ + $this->arg = null; + return true; + } + + 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); + + $cityID = $this->city['city']; + $cityName = $this->city['name']; + $josaRo = JosaUtil::pick($cityName, '로'); + + $troopID = $general->getVar('troop'); + $troopName = $db->queryFirstField('SELECT name FROM troop WHERE troop = %i', $troopID); + + $logger = $general->getLogger(); + + $logger->pushGeneralActionLog("{$cityName}에서 집합을 실시했습니다. <1>$date"); + + $generalList = $db->query('SELECT no, name, city, nation, level FROM general WHERE nation=%i AND troop=%i AND no!=%i', $general->getNationID(), $troopID, $general->getID()); + foreach($generalList as $targetRawGeneral){ + $targetGeneralID = $targetRawGeneral['no']; + $targetGeneral = $this->getGeneralObjFromGeneralSource($targetGeneralID); + if($targetGeneral === null){ + $targetGeneral = new General($targetRawGeneral, null, $env['year'], $env['month'], false); + } + $targetGeneral->setVar('city', $destCityID); + $targetGeneral->getLogger()->pushGeneralActionLog("{$troopName}의 부대원들은 {$cityName}{$josaRo} 집합되었습니다.", ActionLogger::PLAIN); + $targetGeneral = null; + } + + $exp = 70; + $ded = 100; + + $exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp); + $ded = $general->onPreGeneralStatUpdate($general, 'dedication', $ded); + + $general->increaseVar('experience', $exp); + $general->increaseVar('dedication', $ded); + $general->increaseVar('leader2', 1); + $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); + $general->checkStatChange(); + $general->applyDB($db); + + uniqueItemEx($general->getVar('no'), $logger); + } + + +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/MustBeTroopLeader.php b/hwe/sammo/Constraint/MustBeTroopLeader.php new file mode 100644 index 00000000..66bdd46d --- /dev/null +++ b/hwe/sammo/Constraint/MustBeTroopLeader.php @@ -0,0 +1,38 @@ +general)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require troop in general"); + } + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + //XXX: 부대장인지 알 수가 없음 + $db = DB::db(); + $troopLeader = $db->queryFirstField('SELECT no FROM troop WHERE troop = %i', $this->general['troop']); + + if($troopLeader == $this->general['no']){ + return true; + } + + $this->reason = "부대장이 아닙니다."; + return false; + } +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/NotCapital.php b/hwe/sammo/Constraint/NotCapital.php new file mode 100644 index 00000000..5e459cf1 --- /dev/null +++ b/hwe/sammo/Constraint/NotCapital.php @@ -0,0 +1,46 @@ +general)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require city in general"); + } + + if(!key_exists('level', $this->general)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require level in general"); + } + + if(!key_exists('capital', $this->nation)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require capital in nation"); + } + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + if($this->nation['capital'] != $this->general['city']){ + return true; + } + + if($this->arg && 2 <= $this->general['level'] && $this->general['level'] <= 4){ + return true; + } + + $this->reason = "이미 수도입니다."; + return false; + } +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/OccupiedCity.php b/hwe/sammo/Constraint/OccupiedCity.php index 76953123..e48eb156 100644 --- a/hwe/sammo/Constraint/OccupiedCity.php +++ b/hwe/sammo/Constraint/OccupiedCity.php @@ -2,7 +2,7 @@ namespace sammo\Constraint; -class NoWanderingNation extends Constraint{ +class OccupiedCity extends Constraint{ const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_CITY; public function checkInputValues(bool $throwExeception=true){ diff --git a/hwe/sammo/Constraint/ReqTroopMembers.php b/hwe/sammo/Constraint/ReqTroopMembers.php new file mode 100644 index 00000000..f764e3bf --- /dev/null +++ b/hwe/sammo/Constraint/ReqTroopMembers.php @@ -0,0 +1,37 @@ +general)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require troop in general"); + } + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + $db = DB::db(); + //NOTE:이 경우에 DB를 사용하지 않을 수 있는가? + $troopMember = $db->queryFirstField('SELECT no FROM troop WHERE troop = %i AND no != %i LIMIT 1', $this->general['troop'], $this->general['no']); + + if($troopMember !== null){ + return true; + } + + $this->reason = "집합 가능한 부대원이 없습니다."; + return false; + } +} \ No newline at end of file