diff --git a/hwe/sammo/DiplomacticMessage.php b/hwe/sammo/DiplomacticMessage.php index 1e62435b..774628a9 100644 --- a/hwe/sammo/DiplomacticMessage.php +++ b/hwe/sammo/DiplomacticMessage.php @@ -13,7 +13,6 @@ class DiplomacticMessage extends Message{ const TYPE_STOP_WAR = 'stopWar'; //종전 const TYPE_MERGE = 'merge'; //통합 const TYPE_SURRENDER = 'surrender'; //항복 - protected $diplomaticType = ''; protected $diplomacyName = ''; @@ -71,6 +70,145 @@ class DiplomacticMessage extends Message{ return [self::ACCEPTED, '']; } + protected function noAggression(){ + $year = Util::array_get($this->msgOption['year']); + $option = Util::array_get($this->msgOption['option']); + if($year < 1 || $year > 30){ + return [self::INVALID, '올바르지 않은 불가침 서신입니다.']; + } + + $helper = new Engine\Diplomacy($this->src->nationID, $this->dest->nationID); + $chk = $helper->noAggression($year, $option); + if($chk[0] !== self::ACCEPTED){ + return $chk; + } + + $youlog[] = "{$this->dest->nationName}(와)과 $when년 불가침에 성공했습니다."; + $mylog[] = "{$this->src->nationName}(와)과 $when년 불가침에 합의했습니다."; + pushGenLog(['no'=>$this->dest->generalID], $mylog); + pushGenLog(['no'=>$this->src->generalID], $youlog); + pushGeneralHistory(['no'=>$this->src->generalID], "●{$helper->year}년 {$helper->month}월:{$this->dest->nationName}(와)과 {$when}년 불가침 성공"); + pushGeneralHistory(['no'=>$this->dest->generalID], "●{$helper->year}년 {$helper->month}월:{$this->src->nationName}(와)과 {$when}년 불가침 수락"); + + return $chk; + } + + protected function cancelNA(){ + $helper = new Engine\Diplomacy($this->src->nationID, $this->dest->nationID); + $chk = $helper->noAggression(); + if($chk[0] !== self::ACCEPTED){ + return $chk; + } + + $alllog[] = "●{$helper->month}월:{$this->dest->generalName}(이)가 {$this->src->nationName}(와)과 조약 파기에 합의."; + $history[] = "●{$helper->year}년 {$helper->month}월:【파기】{$this->dest->nationName}(이)가 {$this->src->nationName}(와)과 불가침을 파기 하였습니다."; + $youlog[] = "{$this->dest->nationName}(와)과 파기에 성공했습니다."; + $mylog[] = "{$this->src->nationName}(와)과 파기에 합의했습니다."; + pushGeneralHistory(['no'=>$this->src->generalID], "●{$helper->year}년 {$helper->month}월:{$this->dest->nationName}(와)과 파기 성공"); + pushGeneralHistory(['no'=>$this->dest->generalID], "●{$helper->year}년 {$helper->month}월:{$this->src->nationName}(와)과 파기 수락"); + + pushGenLog(['no'=>$this->dest->generalID], $mylog); + pushGenLog(['no'=>$this->src->generalID], $youlog); + pushGeneralPublicRecord($alllog, $helper->year, $helper->month); + pushWorldHistory($history, $helper->year, $helper->month); + + return $chk; + } + + protected function stopWar(){ + $helper = new Engine\Diplomacy($this->src->nationID, $this->dest->nationID); + $chk = $helper->noAggression(); + if($chk[0] !== self::ACCEPTED){ + return $chk; + } + + $alllog[] = "●{$helper->month}월:{$this->dest->generalName}(이)가 {$this->src->nationName}(와)과 종전 합의 하였습니다."; + $history[] = "●{$helper->year}년 {$helper->month}월:【종전】{$this->dest->nationName}(이)가 {$this->src->nationName}(와)과 종전 합의 하였습니다."; + $youlog[] = "{$this->dest->nationName}(와)과 종전에 성공했습니다."; + $mylog[] = "{$this->src->nationName}(와)과 종전에 합의했습니다."; + pushGeneralHistory(['no'=>$this->src->generalID], "●{$helper->year}년 {$helper->month}월:{$this->dest->nationName}(와)과 종전 성공"); + pushGeneralHistory(['no'=>$this->dest->generalID], "●{$helper->year}년 {$helper->month}월:{$this->src->nationName}(와)과 종전 수락"); + + pushGenLog(['no'=>$this->dest->generalID], $mylog); + pushGenLog(['no'=>$this->src->generalID], $youlog); + pushGeneralPublicRecord($alllog, $helper->year, $helper->month); + pushWorldHistory($history, $helper->year, $helper->month); + + return $chk; + } + + protected function acceptMerge(){ + $helper = new Engine\Diplomacy($this->src->nationID, $this->dest->nationID); + $chk = $helper->noAggression(); + if($chk[0] !== self::ACCEPTED){ + return $chk; + } + + pushGeneralHistory( + ['no'=>$this->src->generalID], + ["●{$helper->year}년 {$helper->month}월:{$this->dest->nationName}(와)과 통합 시도"] + ); + pushGeneralHistory( + ['no'=>$this->dest->generalID], + ["●{$helper->year}년 {$helper->month}월:{$this->src->nationName}(와)과 통합 시도"] + ); + pushGenLog( + ['no'=>$this->dest->generalID], + ["{$this->src->nationName}(와)과 통합에 동의했습니다."] + ); + pushGenLog( + ['no'=>$this->src->generalID], + ["{$this->dest->nationName}(이)가 통합에 동의했습니다."] + ); + pushGeneralPublicRecord( + ["●{$helper->month}월:{$this->dest->generalName}(이)가 {$this->src->nationName}(와)과 통합에 동의하였습니다."], + $helper->year, + $helper->month); + pushWorldHistory( + ["●{$helper->year}년 {$helper->month}월:【통합시도】{$this->dest->nationName}(와)과 {$this->src->nationName}(이)가 통합을 시도합니다."], + $helper->year, + $helper->month + ); + + return $chk; + } + + protected function acceptSurrender(){ + $helper = new Engine\Diplomacy($this->src->nationID, $this->dest->nationID); + $chk = $helper->noAggression(); + if($chk[0] !== self::ACCEPTED){ + return $chk; + } + + pushGeneralHistory( + ['no'=>$this->src->generalID], + "●{$helper->year}년 {$helper->month}월:{$this->dest->nationName}(와)과 투항 제의" + ); + pushGeneralHistory( + ['no'=>$this->dest->generalID], + "●{$helper->year}년 {$helper->month}월:{$this->src->nationName}(으)로 투항 동의" + ); + pushGenLog( + ['no'=>$this->dest->generalID], + ["{$this->src->nationName}(으)로 투항에 동의했습니다."] + ); + pushGenLog( + ['no'=>$this->src->generalID], + ["{$this->dest->nationName}(이)가 투항에 동의했습니다."] + ); + pushGeneralPublicRecord( + ["●{$helper->month}월:{$this->dest->generalName}(이)가 {$this->src->nationName}(으)로 투항에 동의하였습니다."], + $helper->year, + $helper->month); + pushWorldHistory( + ["●{$helper->year}년 {$helper->month}월:【투항시도】{$this->dest->nationName}(이)가 {$this->src->nationName}(으)로 투항합니다."], + $helper->year, + $helper->month + ); + + return $chk; + } + /** * @return int 수행 결과 반환, ACCEPTED(등용장 소모), DECLINED(등용장 소모), INVALID 중 반환 */ @@ -89,30 +227,6 @@ class DiplomacticMessage extends Message{ ); list($result, $reason) = $this->checkDiplomaticMessageValidation($general); - - $helper = new Engine\Diplomacy($this->src->nationID, $this->dest->nationID); - - switch($this->diplomaticType){ - case self::TYPE_NO_AGGRESSION: - list($result, $reason) = $helper->noAggression(); - break; - case self::TYPE_CANCEL_NA: - list($result, $reason) = $helper->cancelNA(); - break; - case self::TYPE_STOP_WAR: - list($result, $reason) = $helper->stopWar(); - break; - case self::TYPE_MERGE: - list($result, $reason) = $helper->acceptMerge(); - break; - case self::TYPE_SURRENDER: - list($result, $reason) = $helper->acceptSurrender(); - break; - default: - throw \RuntimeException('diplomaticType이 올바르지 않음'); - } - - if($result !== self::ACCEPTED){ pushGenLog(['no'=>$receiverID], ["●{$reason} {$this->diplomacyName} 실패."]); if($result === self::DECLINED){ @@ -121,6 +235,33 @@ class DiplomacticMessage extends Message{ return $result; } + switch($this->diplomaticType){ + case self::TYPE_NO_AGGRESSION: + list($result, $reason) = $this->noAggression(); + break; + case self::TYPE_CANCEL_NA: + list($result, $reason) = $this->cancelNA(); + break; + case self::TYPE_STOP_WAR: + list($result, $reason) = $this->stopWar(); + break; + case self::TYPE_MERGE: + list($result, $reason) = $this->acceptMerge(); + break; + case self::TYPE_SURRENDER: + list($result, $reason) = $this->acceptSurrender(); + break; + default: + throw \RuntimeException('diplomaticType이 올바르지 않음'); + } + + if($result !== self::ACCEPTED){ + pushGenLog(['no'=>$receiverID], ["●{$reason} {$this->diplomacyName} 실패."]); + if($result === self::DECLINED){ + $this->_declineMessage(); + } + return $result; + } list( $year, @@ -142,7 +283,7 @@ class DiplomacticMessage extends Message{ new \DateTime(), new \DateTime('9999-12-31'), Json::encode([ - 'related'=>$this->id + 'delete'=>$this->id ]) ); $newMsg->send(); diff --git a/hwe/sammo/Message.php b/hwe/sammo/Message.php index b90320d8..78d659f8 100644 --- a/hwe/sammo/Message.php +++ b/hwe/sammo/Message.php @@ -241,7 +241,7 @@ class Message return [$mailbox, $db->insertId()]; } - protected function sendToSender() : int{ + private function sendToSender() : int{ if($this->sendCnt > 0){ throw new \RuntimeException('이미 전송한 메일입니다.'); } @@ -254,7 +254,7 @@ class Message return [0, 0]; } - protected function sendToReceiver() : int{ + private function sendToReceiver() : int{ if($this->sendCnt > 1 || $this->isInboxMail){ throw new \RuntimeException('이미 전송한 메일입니다.'); } @@ -274,17 +274,20 @@ class Message throw new \RuntimeException('이곳에 올 수 없습니다.'); } - public function send():int{ - list($senderMailbox, $sendID) = $this->sendToSender(); - if($sendID){ - $this->mailbox = $senderMailbox; - $this->isInboxMail = false; - $this->id = $sendID; - $this->msgOption['senderMessageID'] = $sendID; - $this->$sendCnt = 1; + public function send(bool $sendDestOnly=false):int{ + if(!$sendDestOnly){ + list($senderMailbox, $sendID) = $this->sendToSender(); + if($sendID){ + $this->mailbox = $senderMailbox; + $this->isInboxMail = false; + $this->id = $sendID; + $this->msgOption['senderMessageID'] = $sendID; + $this->$sendCnt = 1; + } } + list($receiverMailbox, $receiveID) = $this->sendToReceiver(); - if(!$receiveID){ + if(!$receiveID && !$sendDestOnly){ return $sendID; } $this->mailbox = $receiverMailbox; diff --git a/hwe/sammo/ScoutMessage.php b/hwe/sammo/ScoutMessage.php index 2c1a6807..b647e6ca 100644 --- a/hwe/sammo/ScoutMessage.php +++ b/hwe/sammo/ScoutMessage.php @@ -104,16 +104,16 @@ class ScoutMessage extends Message{ $newMsg = new Message( self::MSGTYPE_PRIVATE, - $this->dest, + $this->src, $this->dest, "{$scoutNation['name']}(으)로 등용 제의 수락", new \DateTime(), new \DateTime('9999-12-31'), Json::encode([ - 'related'=>$this->id + 'delete'=>$this->id ]) ); - $newMsg->send(); + $newMsg->send(true); return self::ACCEPTED; } @@ -125,16 +125,16 @@ class ScoutMessage extends Message{ $newMsg = new Message( self::MSGTYPE_PRIVATE, - $this->dest, + $this->src, $this->dest, "{$scoutNation['name']}(으)로 등용 제의 거부", new \DateTime(), new \DateTime('9999-12-31'), Json::encode([ - 'related'=>$this->id + 'delete'=>$this->id ]) ); - $newMsg->send(); + $newMsg->send(true); return self::DECLINED; }