From 99142fdde314c3a31df87fefceb57f800527d1de Mon Sep 17 00:00:00 2001 From: hide_d Date: Sat, 17 Nov 2018 15:40:34 +0900 Subject: [PATCH] =?UTF-8?q?=EB=AA=B0=EC=88=98,=20=ED=8F=AC=EC=83=81=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84,=20=EC=A6=9D=EC=97=AC=20=ED=97=8C=EB=82=A9?= =?UTF-8?q?=20=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/func_process_chief.php | 215 ----------------------- hwe/sammo/Command/General/che_증여.php | 4 +- hwe/sammo/Command/General/che_헌납.php | 2 +- hwe/sammo/Command/Nation/che_몰수.php | 168 ++++++++++++++++++ hwe/sammo/Command/Nation/che_포상.php | 140 +++++++++++++++ hwe/sammo/Constraint/ContraintHelper.php | 8 + hwe/sammo/Constraint/ReqNationalGold.php | 32 ++++ hwe/sammo/Constraint/ReqNationalRice.php | 32 ++++ 8 files changed, 383 insertions(+), 218 deletions(-) create mode 100644 hwe/sammo/Command/Nation/che_몰수.php create mode 100644 hwe/sammo/Command/Nation/che_포상.php create mode 100644 hwe/sammo/Constraint/ReqNationalGold.php create mode 100644 hwe/sammo/Constraint/ReqNationalRice.php diff --git a/hwe/func_process_chief.php b/hwe/func_process_chief.php index f2e45c26..6ebf1ca7 100644 --- a/hwe/func_process_chief.php +++ b/hwe/func_process_chief.php @@ -1,221 +1,6 @@ get(); - - $genlog = []; - $log = []; - $alllog = []; - $history = []; - - $date = substr($general['turntime'],11,5); - - $admin = $gameStor->getValues(['year','month']); - - $query = "select nation,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 gold,rice,l{$general['level']}turn0 from nation where nation='{$general['nation']}'"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $nation = MYDB_fetch_array($result); - - $command = DecodeCommand($nation["l{$general['level']}turn0"]); - $what = $command[3]; - $who = $command[2]; - $amount = $command[1]; - $amount *= 100; // 100~10000까지 - - if($amount > 10000) { $amount = 10000; } - if($amount < 100) { $amount = 100; } - if($what == 1) { - $dtype = "금"; - if($nation['gold']-GameConst::$basegold < $amount) { $amount = $nation['gold'] - GameConst::$basegold; } - } elseif($what == 2) { - $dtype = "쌀"; - if($nation['rice']-GameConst::$baserice < $amount) { $amount = $nation['rice'] - GameConst::$baserice; } - } else { - $what = 2; - $dtype = "쌀"; - if($nation['rice']-GameConst::$baserice < $amount) { $amount = $nation['rice'] - GameConst::$baserice; } - } - - $query = "select no,nation,level,name,gold,rice from general where no='$who'"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $gen = MYDB_fetch_array($result); - - if(!$gen) { - $log[] = "●{$admin['month']}월:없는 장수입니다. 포상 실패. <1>$date"; - } elseif($general['no'] == $who) { - $log[] = "●{$admin['month']}월:자기 자신입니다. 포상 실패. <1>$date"; - } elseif($general['level'] < 5) { - $log[] = "●{$admin['month']}월:수뇌부가 아닙니다. 포상 실패. <1>$date"; - } elseif($city['nation'] != $general['nation']) { - $log[] = "●{$admin['month']}월:아국이 아닙니다. 포상 실패. <1>$date"; - } elseif($city['supply'] == 0) { - $log[] = "●{$admin['month']}월:고립된 도시입니다. 포상 실패. <1>$date"; - } elseif($what == 1 && $amount <= 0) { - $log[] = "●{$admin['month']}월:국고가 부족합니다. 포상 실패. <1>$date"; - } elseif($what == 2 && $amount <= 0) { - $log[] = "●{$admin['month']}월:병량이 부족합니다. 포상 실패. <1>$date"; - } elseif($gen['nation'] != $general['nation']) { - $log[] = "●{$admin['month']}월:아국 장수가 아닙니다. 포상 실패. <1>$date"; - } else { - $genlog[] = "●$dtype $amount을 포상으로 받았습니다."; - $log[] = "●{$admin['month']}월:{$gen['name']}에게 $dtype $amount을 수여했습니다. <1>$date"; - - if($what == 1) { - $gen['gold'] += $amount; - $query = "update general set gold='{$gen['gold']}' where no='$who'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - - $nation['gold'] -= $amount; - $query = "update nation set gold='{$nation['gold']}' where nation='{$general['nation']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - } elseif($what == 2) { - $gen['rice'] += $amount; - $query = "update general set rice='{$gen['rice']}' where no='$who'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - - $nation['rice'] -= $amount; - $query = "update nation set rice='{$nation['rice']}' where nation='{$general['nation']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - } - - $query = "update general set resturn='SUCCESS' where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - -// $log = checkAbility($general, $log); - } - pushGenLog($general, $log); - pushGenLog($gen, $genlog); -} - - -function process_24(&$general) { - $db = DB::db(); - $gameStor = KVStorage::getStorage($db, 'game_env'); - $connect=$db->get(); - - $genlog = []; - $log = []; - $alllog = []; - $history = []; - $date = substr($general['turntime'],11,5); - - $admin = $gameStor->getValues(['year','month','scenario','startyear']); - - $query = "select nation,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 nation,name,color,gold,rice,l{$general['level']}turn0 from nation where nation='{$general['nation']}'"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $nation = MYDB_fetch_array($result); - - $command = DecodeCommand($nation["l{$general['level']}turn0"]); - $what = $command[3]; - $who = $command[2]; - $amount = $command[1]; - $amount *= 100; // 100~10000까지 - - $query = "select no,nation,level,name,gold,rice,npc,picture,imgsvr from general where no='$who'"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $gen = MYDB_fetch_array($result); - - if($amount > 10000) { $amount = 10000; } - if($amount < 100) { $amount = 100; } - if($what == 1) { - $dtype = "금"; - if($gen['gold'] < $amount) { $amount = $gen['gold']; } - } elseif($what == 2) { - $dtype = "쌀"; - if($gen['rice'] < $amount) { $amount = $gen['rice']; } - } else { - $what = 2; - $dtype = "쌀"; - if($gen['rice'] < $amount) { $amount = $gen['rice']; } - } - - if(!$gen) { - $log[] = "●{$admin['month']}월:없는 장수입니다. 몰수 실패. <1>$date"; - } elseif($admin['year'] < $admin['startyear']+3) { - $log[] = "●{$admin['month']}월:현재 초반 제한중입니다. 몰수 실패. <1>$date"; - } elseif($general['no'] == $who) { - $log[] = "●{$admin['month']}월:자기 자신입니다. 몰수 실패. <1>$date"; - } elseif($general['level'] < 5) { - $log[] = "●{$admin['month']}월:수뇌부가 아닙니다. 몰수 실패. <1>$date"; - } elseif($city['nation'] != $general['nation']) { - $log[] = "●{$admin['month']}월:아국이 아닙니다. 몰수 실패. <1>$date"; - } elseif($city['supply'] == 0) { - $log[] = "●{$admin['month']}월:고립된 도시입니다. 몰수 실패. <1>$date"; - } elseif($gen['nation'] != $general['nation']) { - $log[] = "●{$admin['month']}월:아국 장수가 아닙니다. 몰수 실패. <1>$date"; - } else { - if($gen['npc'] >= 2 && rand()%100 == 0) { - switch(rand()%5) { - case 0: $str = "몰수를 하다니... 이것이 윗사람이 할 짓이란 말입니까..."; break; - case 1: $str = "사유재산까지 몰수해가면서 이 나라가 잘 될거라 믿습니까? 정말 이해할 수가 없군요..."; break; - case 2: $str = "내 돈 내놔라! 내 돈! 몰수가 왠 말이냐!"; break; - case 3: $str = "몰수해간 내 자금... 언젠가 몰래 다시 빼내올 것이다..."; break; - case 4: $str = "몰수로 인한 사기 저하는 몰수로 얻은 물자보다 더 손해란걸 모른단 말인가!"; break; - } - - $src = new MessageTarget( - $gen['no'], - $gen['name'], - $gen['nation'], - $nation['name'], - $nation['color'], - GetImageURL($gen['imgsvr'], $gen['picture']) - ); - $msg = new Message( - Message::MSGTYPE_PUBLIC, - $src, - $src, - $str, - new \DateTime(), - new \DateTime('9999-12-31'), - [] - ); - $msg->send(); - } - - $genlog[] = "●$dtype {$amount}을 몰수 당했습니다."; - $log[] = "●{$admin['month']}월:{$gen['name']}에게서 $dtype $amount을 몰수했습니다. <1>$date"; - - if($what == 1) { - $gen['gold'] -= $amount; - $query = "update general set gold='{$gen['gold']}' where no='$who'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - - $nation['gold'] += $amount; - $query = "update nation set gold='{$nation['gold']}' where nation='{$general['nation']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - } elseif($what == 2) { - $gen['rice'] -= $amount; - $query = "update general set rice='{$gen['rice']}' where no='$who'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - - $nation['rice'] += $amount; - $query = "update nation set rice='{$nation['rice']}' where nation='{$general['nation']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - } - - // 경험치 상승 - $query = "update general set resturn='SUCCESS' where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - -// $log = checkAbility($general, $log); - } - pushGenLog($general, $log); - pushGenLog($gen, $genlog); -} - - function process_27(&$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 86046654..d1264b58 100644 --- a/hwe/sammo/Command/General/che_증여.php +++ b/hwe/sammo/Command/General/che_증여.php @@ -117,7 +117,7 @@ class che_증여 extends Command\GeneralCommand{ $resName = $isGold?'금':'쌀'; $destGeneral = $this->destGeneralObj; - $amount = Util::valueFit($amount, $general->getVar($resKey)); + $amount = Util::valueFit($amount, 0, $general->getVar($resKey)); $amountText = number_format($amount, 0); $logger = $general->getLogger(); @@ -125,7 +125,7 @@ class che_증여 extends Command\GeneralCommand{ $destGeneral->increaseVarWithLimit($resKey, $amount); $general->increaseVarWithLimit($resKey, -$amount, 0); - $destGeneral->getLogger()->pushGeneralActionLog("{$general->getName()}에게서 {$resName} {$amountText}을 증여 받았습니다."); + $destGeneral->getLogger()->pushGeneralActionLog("{$general->getName()}에게서 {$resName} {$amountText}을 증여 받았습니다.", ActionLogger::PLAIN); $logger->pushGeneralActionLog("{$destGeneral->getName()}에게 {$resName} $amountText을 증여했습니다. <1>$date"); $exp = 70; diff --git a/hwe/sammo/Command/General/che_헌납.php b/hwe/sammo/Command/General/che_헌납.php index 2c613301..960135a2 100644 --- a/hwe/sammo/Command/General/che_헌납.php +++ b/hwe/sammo/Command/General/che_헌납.php @@ -96,7 +96,7 @@ class che_헌납 extends Command\GeneralCommand{ $resKey = $isGold?'gold':'rice'; $resName = $isGold?'금':'쌀'; - $amount = Util::valueFit($amount, $general->getVar($resKey)); + $amount = Util::valueFit($amount, 0, $general->getVar($resKey)); $amountText = number_format($amount, 0); $logger = $general->getLogger(); diff --git a/hwe/sammo/Command/Nation/che_몰수.php b/hwe/sammo/Command/Nation/che_몰수.php new file mode 100644 index 00000000..06984c44 --- /dev/null +++ b/hwe/sammo/Command/Nation/che_몰수.php @@ -0,0 +1,168 @@ +arg)){ + return false; + } + if(!key_exists('amount', $this->arg)){ + return false; + } + if(!key_exists('destGeneralID', $this->arg)){ + return false; + } + $isGold = $this->arg['isGold']; + $amount = $this->arg['amount']; + $destGeneralID = $this->arg['destGeneralID']; + if(!is_int($amount)){ + return false; + } + $amount = Util::valueFit($amount, 100, 10000); + if(!is_bool($isGold)){ + return false; + } + if(!is_int($destGeneralID)){ + return false; + } + if($destGeneralID <= 0){ + return false; + } + if($destGeneralID == $this->generalObj->getID()){ + return false; + } + $this->arg = [ + 'isGold'=>$isGold, + 'amount'=>$amount, + 'destGeneralID'=>$destGeneralID + ]; + return true; + } + + protected function init(){ + $general = $this->generalObj; + + $env = $this->env; + + $this->setCity(); + $this->setNation(['gold', 'rice']); + + $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['gold', 'nation'], 1); + $this->setDestGeneral($destGeneral); + + $relYear = $env['year'] - $env['startyear']; + + $this->runnableConstraints=[ + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::OccupiedCity(), + ConstraintHelper::BeChief(), + ConstraintHelper::NotOpeningPart($relYear), + ConstraintHelper::SuppliedCity(), + ConstraintHelper::ExistsDestGeneral(), + ConstraintHelper::FriendlyDestGeneral() + ]; + } + + 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(); + + $general = $this->generalObj; + $date = substr($general->getVar('turntime'),11,5); + + $nation = $this->nation; + $nationID = $nation['nation']; + + $isGold = $this->arg['isGold']; + $amount = $this->arg['amount']; + $resKey = $isGold?'gold':'rice'; + $resName = $isGold?'금':'쌀'; + $destGeneral = $this->destGeneralObj; + + $amount = Util::valueFit($amount, 0, $general->getVar[$resKey]); + $amountText = number_format($amount, 0); + + if($destGeneral->getVar('npc') >= 2 && Util::randBool(0.01)){ + $npcTexts = [ + '몰수를 하다니... 이것이 윗사람이 할 짓이란 말입니까...', + '사유재산까지 몰수해가면서 이 나라가 잘 될거라 믿습니까? 정말 이해할 수가 없군요...', + '내 돈 내놔라! 내 돈! 몰수가 왠 말이냐!', + '몰수해간 내 자금... 언젠가 몰래 다시 빼내올 것이다...', + '몰수로 인한 사기 저하는 몰수로 얻은 물자보다 더 손해란걸 모른단 말인가!' + ]; + $text = Util::choiceRandom($npcTexts); + $src = new MessageTarget( + $general->getID(), + $general->getName(), + $nationID, + $nation['name'], + $nation['color'], + GetImageURL($general->getVar('imgsvr'), $general->getVar('picture')) + ); + $msg = new Message( + Message::MSGTYPE_PUBLIC, + $src, + $src, + $str, + new \DateTime(), + new \DateTime('9999-12-31'), + [] + ); + $msg->send(); + } + + $logger = $general->getLogger(); + + $destGeneral->increaseVarWithLimit($resKey, -$amount); + $db->update('nation', [ + $resKey=>$db->sqleval('%b + %i', $resKey, $amount) + ], 'nation=%i', $nationID); + + $destGeneral->getLogger()->pushGeneralActionLog("{$resName} {$amountText}을 몰수 당했습니다.", ActionLogger::PLAIN); + $logger->pushGeneralActionLog("{$destGeneral->getName()}에게서 {$resName} $amountText을 몰수했습니다. <1>$date"); + + $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); + $general->applyDB($db); + $destGeneral->applyDB($db); + + return true; + } +} \ No newline at end of file diff --git a/hwe/sammo/Command/Nation/che_포상.php b/hwe/sammo/Command/Nation/che_포상.php new file mode 100644 index 00000000..005c0ae7 --- /dev/null +++ b/hwe/sammo/Command/Nation/che_포상.php @@ -0,0 +1,140 @@ +arg)){ + return false; + } + if(!key_exists('amount', $this->arg)){ + return false; + } + if(!key_exists('destGeneralID', $this->arg)){ + return false; + } + $isGold = $this->arg['isGold']; + $amount = $this->arg['amount']; + $destGeneralID = $this->arg['destGeneralID']; + if(!is_int($amount)){ + return false; + } + $amount = Util::valueFit($amount, 100, 10000); + if(!is_bool($isGold)){ + return false; + } + if(!is_int($destGeneralID)){ + return false; + } + if($destGeneralID <= 0){ + return false; + } + if($destGeneralID == $this->generalObj->getID()){ + return false; + } + $this->arg = [ + 'isGold'=>$isGold, + 'amount'=>$amount, + 'destGeneralID'=>$destGeneralID + ]; + return true; + } + + protected function init(){ + $general = $this->generalObj; + + $this->setCity(); + $this->setNation(['gold', 'rice']); + + $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['gold', 'nation'], 1); + $this->setDestGeneral($destGeneral); + + $this->runnableConstraints=[ + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::OccupiedCity(), + ConstraintHelper::BeChief(), + ConstraintHelper::SuppliedCity(), + ConstraintHelper::ExistsDestGeneral(), + ConstraintHelper::FriendlyDestGeneral() + ]; + if($this->arg['isGold']){ + $this->runnableConstraints[] = ConstraintHelper::ReqNationGold(1); + } + else{ + $this->runnableConstraints[] = ConstraintHelper::ReqGeneralRice(1+GameConst::$baserice); + } + } + + 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(); + + $general = $this->generalObj; + $date = substr($general->getVar('turntime'),11,5); + + $nation = $this->nation; + $nationID = $nation['nation']; + + $isGold = $this->arg['isGold']; + $amount = $this->arg['amount']; + $resKey = $isGold?'gold':'rice'; + $resName = $isGold?'금':'쌀'; + $destGeneral = $this->destGeneralObj; + + $amount = Util::valueFit($amount, 0, $nation[$resKey]); + $amountText = number_format($amount, 0); + + $logger = $general->getLogger(); + + $destGeneral->increaseVarWithLimit($resKey, $amount); + $db->update('nation', [ + $resKey=>$db->sqleval('%b - %i', $resKey, $amount) + ], 'nation=%i', $nationID); + + $destGeneral->getLogger()->pushGeneralActionLog("{$resName} {$amountText}을 포상으로 받았습니다.", ActionLogger::PLAIN); + $logger->pushGeneralActionLog("{$destGeneral->getName()}에게 {$resName} $amountText을 수여했습니다. <1>$date"); + + $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); + $general->applyDB($db); + $destGeneral->applyDB($db); + + return true; + } +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/ContraintHelper.php b/hwe/sammo/Constraint/ContraintHelper.php index 38b97b36..b31373c5 100644 --- a/hwe/sammo/Constraint/ContraintHelper.php +++ b/hwe/sammo/Constraint/ContraintHelper.php @@ -188,6 +188,14 @@ class ConstraintHelper{ return [__FUNCTION__, $key, $keyNick, $comp, $reqVal]; } + static function ReqNationGold(int $reqGold):array{ + return [__FUNCTION__, $reqGold]; + } + + static function ReqNationRice(int $reqRice):array{ + return [__FUNCTION__, $reqRice]; + } + static function ReqNationValue($key, string $keyNick, string $comp, $reqVal):array{ return [__FUNCTION__, $key, $keyNick, $comp, $reqVal]; } diff --git a/hwe/sammo/Constraint/ReqNationalGold.php b/hwe/sammo/Constraint/ReqNationalGold.php new file mode 100644 index 00000000..77dcbeb5 --- /dev/null +++ b/hwe/sammo/Constraint/ReqNationalGold.php @@ -0,0 +1,32 @@ +nation)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require gold in nation"); + } + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + if($this->nation['gold'] < $this->arg){ + return true; + } + + $this->reason = "국고가 부족합니다."; + return false; + } +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/ReqNationalRice.php b/hwe/sammo/Constraint/ReqNationalRice.php new file mode 100644 index 00000000..19e21071 --- /dev/null +++ b/hwe/sammo/Constraint/ReqNationalRice.php @@ -0,0 +1,32 @@ +nation)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require rice in nation"); + } + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + if($this->nation['rice'] < $this->arg){ + return true; + } + + $this->reason = "병량이 부족합니다."; + return false; + } +} \ No newline at end of file