외교 서신 메시지 파트 구현 완료
- 메시지 전송시 수신자에게만 전송 가능한 옵션 추가 - 메시지 추가 옵션으로 delete 옵션 제시.
This commit is contained in:
@@ -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[] = "<C>●</><D><b>{$this->dest->nationName}</b></>(와)과 <C>$when</>년 불가침에 성공했습니다.";
|
||||
$mylog[] = "<C>●</><D><b>{$this->src->nationName}</b></>(와)과 <C>$when</>년 불가침에 합의했습니다.";
|
||||
pushGenLog(['no'=>$this->dest->generalID], $mylog);
|
||||
pushGenLog(['no'=>$this->src->generalID], $youlog);
|
||||
pushGeneralHistory(['no'=>$this->src->generalID], "<C>●</>{$helper->year}년 {$helper->month}월:<D><b>{$this->dest->nationName}</b></>(와)과 {$when}년 불가침 성공");
|
||||
pushGeneralHistory(['no'=>$this->dest->generalID], "<C>●</>{$helper->year}년 {$helper->month}월:<D><b>{$this->src->nationName}</b></>(와)과 {$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[] = "<C>●</>{$helper->month}월:<Y>{$this->dest->generalName}</>(이)가 <D><b>{$this->src->nationName}</b></>(와)과 <M>조약 파기</>에 합의.";
|
||||
$history[] = "<C>●</>{$helper->year}년 {$helper->month}월:<Y><b>【파기】</b></><D><b>{$this->dest->nationName}</b></>(이)가 <D><b>{$this->src->nationName}</b></>(와)과 불가침을 파기 하였습니다.";
|
||||
$youlog[] = "<C>●</><D><b>{$this->dest->nationName}</b></>(와)과 파기에 성공했습니다.";
|
||||
$mylog[] = "<C>●</><D><b>{$this->src->nationName}</b></>(와)과 파기에 합의했습니다.";
|
||||
pushGeneralHistory(['no'=>$this->src->generalID], "<C>●</>{$helper->year}년 {$helper->month}월:<D><b>{$this->dest->nationName}</b></>(와)과 파기 성공");
|
||||
pushGeneralHistory(['no'=>$this->dest->generalID], "<C>●</>{$helper->year}년 {$helper->month}월:<D><b>{$this->src->nationName}</b></>(와)과 파기 수락");
|
||||
|
||||
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[] = "<C>●</>{$helper->month}월:<Y>{$this->dest->generalName}</>(이)가 <D><b>{$this->src->nationName}</b></>(와)과 <M>종전 합의</> 하였습니다.";
|
||||
$history[] = "<C>●</>{$helper->year}년 {$helper->month}월:<Y><b>【종전】</b></><D><b>{$this->dest->nationName}</b></>(이)가 <D><b>{$this->src->nationName}</b></>(와)과 <M>종전 합의</> 하였습니다.";
|
||||
$youlog[] = "<C>●</><D><b>{$this->dest->nationName}</b></>(와)과 종전에 성공했습니다.";
|
||||
$mylog[] = "<C>●</><D><b>{$this->src->nationName}</b></>(와)과 종전에 합의했습니다.";
|
||||
pushGeneralHistory(['no'=>$this->src->generalID], "<C>●</>{$helper->year}년 {$helper->month}월:<D><b>{$this->dest->nationName}</b></>(와)과 종전 성공");
|
||||
pushGeneralHistory(['no'=>$this->dest->generalID], "<C>●</>{$helper->year}년 {$helper->month}월:<D><b>{$this->src->nationName}</b></>(와)과 종전 수락");
|
||||
|
||||
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],
|
||||
["<C>●</>{$helper->year}년 {$helper->month}월:<D><b>{$this->dest->nationName}</b></>(와)과 통합 시도"]
|
||||
);
|
||||
pushGeneralHistory(
|
||||
['no'=>$this->dest->generalID],
|
||||
["<C>●</>{$helper->year}년 {$helper->month}월:<D><b>{$this->src->nationName}</b></>(와)과 통합 시도"]
|
||||
);
|
||||
pushGenLog(
|
||||
['no'=>$this->dest->generalID],
|
||||
["<C>●</><D><b>{$this->src->nationName}</b></>(와)과 통합에 동의했습니다."]
|
||||
);
|
||||
pushGenLog(
|
||||
['no'=>$this->src->generalID],
|
||||
["<C>●</><D><b>{$this->dest->nationName}</b></>(이)가 통합에 동의했습니다."]
|
||||
);
|
||||
pushGeneralPublicRecord(
|
||||
["<C>●</>{$helper->month}월:<Y>{$this->dest->generalName}</>(이)가 <D><b>{$this->src->nationName}</b></>(와)과 <M>통합</>에 동의하였습니다."],
|
||||
$helper->year,
|
||||
$helper->month);
|
||||
pushWorldHistory(
|
||||
["<C>●</>{$helper->year}년 {$helper->month}월:<Y><b>【통합시도】</b></><D><b>{$this->dest->nationName}</b></>(와)과 <D><b>{$this->src->nationName}</b></>(이)가 통합을 시도합니다."],
|
||||
$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],
|
||||
"<C>●</>{$helper->year}년 {$helper->month}월:<D><b>{$this->dest->nationName}</b></>(와)과 투항 제의"
|
||||
);
|
||||
pushGeneralHistory(
|
||||
['no'=>$this->dest->generalID],
|
||||
"<C>●</>{$helper->year}년 {$helper->month}월:<D><b>{$this->src->nationName}</b></>(으)로 투항 동의"
|
||||
);
|
||||
pushGenLog(
|
||||
['no'=>$this->dest->generalID],
|
||||
["<C>●</><D><b>{$this->src->nationName}</b></>(으)로 투항에 동의했습니다."]
|
||||
);
|
||||
pushGenLog(
|
||||
['no'=>$this->src->generalID],
|
||||
["<C>●</><D><b>{$this->dest->nationName}</b></>(이)가 투항에 동의했습니다."]
|
||||
);
|
||||
pushGeneralPublicRecord(
|
||||
["<C>●</>{$helper->month}월:<Y>{$this->dest->generalName}</>(이)가 <D><b>{$this->src->nationName}</b></>(으)로 <M>투항</>에 동의하였습니다."],
|
||||
$helper->year,
|
||||
$helper->month);
|
||||
pushWorldHistory(
|
||||
["<C>●</>{$helper->year}년 {$helper->month}월:<Y><b>【투항시도】</b></><D><b>{$this->dest->nationName}</b></>(이)가 <D><b>{$this->src->nationName}</b></>(으)로 투항합니다."],
|
||||
$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], ["<C>●</>{$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], ["<C>●</>{$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();
|
||||
|
||||
+14
-11
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user