From 7bdde2ac8aeef1954db93a4f02f94bae7440a07a Mon Sep 17 00:00:00 2001 From: hide_d Date: Sun, 15 Apr 2018 21:01:42 +0900 Subject: [PATCH] =?UTF-8?q?=EC=99=B8=EA=B5=90=20=EC=84=9C=EC=8B=A0=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=20=EB=82=B4=EC=9A=A9=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?-=20=EB=93=B1=EC=9A=A9=EC=9E=A5=EC=9D=98=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=20=EB=B6=80=EB=B6=84=EC=9D=80=20=EB=A9=94=EC=8B=9C=EC=A7=80?= =?UTF-8?q?=EB=A1=9C=20=EB=BA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/Engine/Diplomacy.php | 221 ++++++++++++++++++++++++++++++--- hwe/sammo/Engine/Personnel.php | 16 +-- hwe/sammo/ScoutMessage.php | 15 ++- 3 files changed, 219 insertions(+), 33 deletions(-) diff --git a/hwe/sammo/Engine/Diplomacy.php b/hwe/sammo/Engine/Diplomacy.php index c4a4b8b9..e0122a6d 100644 --- a/hwe/sammo/Engine/Diplomacy.php +++ b/hwe/sammo/Engine/Diplomacy.php @@ -1,6 +1,7 @@ queryFirstRow( - 'SELECT nation, `name`, capital, gold, rice, surlimit, color, `level` FROM nation WHERE nation=%i', + 'SELECT nation, `name`, `power`, capital, gold, rice, surlimit, color, `level` FROM nation WHERE nation=%i', $srcNationID ); $destNation = $db->queryFirstRow( - 'SELECT nation, `name`, capital, gold, rice, surlimit, color, `level` FROM nation WHERE nation=%i', + 'SELECT nation, `name`, `power`, capital, gold, rice, surlimit, color, `level` FROM nation WHERE nation=%i', $destNationID ); @@ -101,6 +102,18 @@ class Diplomacy{ return $prev; } + protected function checkNonAggressionTreaty(array $prev = [DiplomacticMessage::ACCEPTED, '']){ + if($prev[0] !== DiplomacticMessage::ACCEPTED){ + return $prev; + } + + if($this->srcToDestDiplomacy['state'] !== 7 || $this->destToSrcDiplomacy['state'] !== 7){ + return [DiplomacticMessage::DECLINED, '상대국과 불가침 중이 아닙니다.']; + } + + return $prev; + } + protected function checkInWar(array $prev = [DiplomacticMessage::ACCEPTED, '']){ if($prev[0] !== DiplomacticMessage::ACCEPTED){ return $prev; @@ -172,12 +185,21 @@ class Diplomacy{ return $prev; } - if(false){ - return [DiplomacticMessage::DECLINED, '상대국이 전쟁 중입니다.']; - } + $db = \sammo\DB::db(); - if(false){ - return [DiplomacticMessage::DECLINED, '상대국이 합병 중입니다.']; + $states = $db->queryOneField( + 'SELECT `state` FROM diplomacy WHERE me = %i AND you != %i AND `state` NOT IN (2, 7) GROUP BY `state` ORDER BY `state`', + $this->srcNation['nation'], + $this->destNation['nation'] + ); + + foreach($states as $state){ + if($state == 0 || $state == 1){ + return [DiplomacticMessage::DECLINED, '상대국이 전쟁 중입니다.']; + } + if(3 <= $state && $state <= 6){ + return [DiplomacticMessage::DECLINED, '상대국이 합병 중입니다.']; + } } return $prev; @@ -188,30 +210,195 @@ class Diplomacy{ return $prev; } - if(false){ + $db = \sammo\DB::db(); + + $cnt = $db->queryFirstField( + 'SELECT count(dest.you) FROM diplomacy src + JOIN diplomacy dest ON src.you = dest.you AND src.me != dest.me + WHERE src.state = 7 AND dest.state IN (0, 1) AND src.me = %i AND dest.me = %i', + $this->srcNation['nation'], + $this->destNation['nation'] + ); + + if($cnt > 0){ return [DiplomacticMessage::DECLINED, '상대국이 본국의 교전국과 불가침중입니다.']; } return $prev; } - public function noAggression(int $destNation){ + protected function checkMorePower(array $prev = [DiplomacticMessage::ACCEPTED, '']){ + if($prev[0] !== DiplomacticMessage::ACCEPTED){ + return $prev; + } + if($this->srcNation['power'] < $this->destNation['power'] * 3){ + return [DiplomacticMessage::DECLINED, '상대국과 국력차가 크지 않습니다.']; + } + + return $prev; + } + + protected function checkMergePower(array $prev = [DiplomacticMessage::ACCEPTED, '']){ + if($prev[0] !== DiplomacticMessage::ACCEPTED){ + return $prev; + } + + $db = DB::db(); + list( + $powerAvg, + $powerStddev, + $genAvg, + $genStddev + ) = $db->queryFirstList( + 'SELECT avg(`power`), std(`power`), avg(`gennum`), std(`gennum`) FROM nation WHERE `level` >= 1' + ); + + $mergedPower = ($this->srcNation['power'] + $this->destNation['power'])/2; + $ZPower = ($mergedPower - $powerAvg) / $powerStddev; + if($ZPower >= -0.25){ + return [DiplomacticMessage::DECLINED, '두 국가의 국력 평균이 상위 60% 보다 높습니다.']; + } + + $mergedGeneral = ($this->srcNation['gennum'] + $this->destNation['gennum'])/2; + $ZGeneral = ($mergedGeneral - $genAvg) / $genStddev; + if($ZGeneral >= -0.67){ + return [DiplomacticMessage::DECLINED, '두 국가의 장수수 평균이 상위 75% 보다 높습니다.']; + } + + return $prev; + } + + public function noAggression(int $when, string $option){ + $chk = $this->checkValidNation(); + $chk = $this->checkNotWar($chk); + $chk = $this->checkAlreadyMerging($chk); + + list($result, $reason) = $chk; + if($result !== DiplomacticMessage::ACCEPTED){ + return $chk; + } + + $db = DB::db(); + $db->update('diplomacy',[ + 'state'=>7, + 'term'=>$when, + 'fixed'=>$option + ], + '(me=%i AND you=%i) OR (you=%i AND me=%i)', + $this->srcNation['nation'], $this->destNation['nation'], + $this->srcNation['nation'], $this->destNation['nation']); + + return $chk; } - public function cancelNA(int $destNation){ - + public function cancelNA(){ + $chk = $this->checkValidNation(); + $chk = $this->checkNonAggressionTreaty($chk); + + list($result, $reason) = $chk; + if($result !== DiplomacticMessage::ACCEPTED){ + return $chk; + } + + $db = DB::db(); + $db->update('diplomacy',[ + 'state'=>2, + 'term'=>0, + 'fixed'=>'' + ], + '(me=%i AND you=%i) OR (you=%i AND me=%i)', + $this->srcNation['nation'], $this->destNation['nation'], + $this->srcNation['nation'], $this->destNation['nation']); + + return $chk; } - public function stopWar(int $destNation){ - + public function stopWar(){ + $chk = $this->checkValidNation(); + $chk = $this->checkInWar($chk); + + list($result, $reason) = $chk; + if($result !== DiplomacticMessage::ACCEPTED){ + return $chk; + } + + $db = DB::db(); + $db->update('diplomacy',[ + 'state'=>2, + 'term'=>0, + 'fixed'=>'' + ], + '(me=%i AND you=%i) OR (you=%i AND me=%i)', + $this->srcNation['nation'], $this->destNation['nation'], + $this->srcNation['nation'], $this->destNation['nation']); + + return $chk; } - public function acceptMerge(int $destNation){ - + public function acceptMerge(int $srcGeneral, int $destGeneral){ + $chk = $this->checkValidNation(); + $chk = $this->checkDiplomacyLimit($chk); + $chk = $this->checkContradictoryDiplomacy($chk); + $chk = $this->checkSrcNationHasNeutralDiplomacy($chk); + $chk = $this->checkStrictlyAdjacent($chk); + $chk = $this->checkMergePower($chk); + + list($result, $reason) = $chk; + if($result !== DiplomacticMessage::ACCEPTED){ + return $chk; + } + + $db = DB::db(); + $db->update('diplomacy',[ + 'state'=>4, + 'term'=>24, + 'fixed'=>'' + ], + 'me=%i AND you=%i', + $this->srcNation['nation'], $this->destNation['nation']); + + $db->update('diplomacy',[ + 'state'=>3, + 'term'=>24, + 'fixed'=>'' + ], + 'you=%i AND me=%i', + $this->srcNation['nation'], $this->destNation['nation']); + + return $chk; } - public function acceptSurrender(int $destNation){ - + public function acceptSurrender(int $srcGeneral, int $destGeneral){ + $chk = $this->checkValidNation(); + $chk = $this->checkDiplomacyLimit($chk); + $chk = $this->checkContradictoryDiplomacy($chk); + $chk = $this->checkSrcNationHasNeutralDiplomacy($chk); + $chk = $this->checkStrictlyAdjacent($chk); + $chk = $this->checkMorePower($chk); + + list($result, $reason) = $chk; + if($result !== DiplomacticMessage::ACCEPTED){ + return $chk; + } + + $db = DB::db(); + $db->update('diplomacy',[ + 'state'=>6, + 'term'=>24, + 'fixed'=>'' + ], + 'me=%i AND you=%i', + $this->srcNation['nation'], $this->destNation['nation']); + + $db->update('diplomacy',[ + 'state'=>5, + 'term'=>24, + 'fixed'=>'' + ], + 'you=%i AND me=%i', + $this->srcNation['nation'], $this->destNation['nation']); + + return $chk; } } \ No newline at end of file diff --git a/hwe/sammo/Engine/Personnel.php b/hwe/sammo/Engine/Personnel.php index eab6cea1..66a878fa 100644 --- a/hwe/sammo/Engine/Personnel.php +++ b/hwe/sammo/Engine/Personnel.php @@ -1,6 +1,7 @@ {$general['name']} 등용에 성공했습니다."; - $receiverLog[] = "{$this->nation['name']}(으)로 망명하여 수도로 이동합니다."; - $generalPublicLog[] = "●{$month}월:{$general['name']}(이)가 {$this->nation['name']}(으)로 망명하였습니다."; - // 국가 변경, 도시 변경, 일반으로, 수도로 $setValues = [ 'belong'=>1, @@ -207,11 +199,7 @@ class Personnel{ // 부대 삭제 $db->delete('troop', 'troop=%i', $general['troop']); } - - pushGenLog($general, $receiverLog); - pushGenLog(['no'=>$this->src->generalID], $senderLog); - pushGeneralPublicRecord($generalPublicLog, $year, $month); - + return [ScoutMessage::ACCEPTED, '']; } } \ No newline at end of file diff --git a/hwe/sammo/ScoutMessage.php b/hwe/sammo/ScoutMessage.php index 47300a4c..2c1a6807 100644 --- a/hwe/sammo/ScoutMessage.php +++ b/hwe/sammo/ScoutMessage.php @@ -89,6 +89,19 @@ class ScoutMessage extends Message{ $this->invalidate(); $this->validScout = false; + pushGenLog( + ['no'=>$this->dest->generalID], + ["{$this->src->nationName}(으)로 망명하여 수도로 이동합니다."]); + pushGenLog( + ['no'=>$this->src->generalID], + ["{$this->dest->generalName} 등용에 성공했습니다."] + ); + pushGeneralPublicRecord( + ["●{$helper->month}월:{$this->dest->generalName}(이)가 {$this->src->nationName}(으)로 망명하였습니다."], + $helper->year, + $helper->month + ); + $newMsg = new Message( self::MSGTYPE_PRIVATE, $this->dest, @@ -209,6 +222,4 @@ class ScoutMessage extends Message{ return new ScoutMessage(Message::MSGTYPE_PRIVATE, $src, $dest, $msg, $date, $validUntil, $msgOption); } - - } \ No newline at end of file