통합, 항복 제거

This commit is contained in:
2020-05-07 23:48:08 +09:00
parent 7199a770c0
commit e7f8900286
14 changed files with 22 additions and 537 deletions
-4
View File
@@ -77,10 +77,6 @@ class che_선양 extends Command\GeneralCommand
ConstraintHelper::BeLord(),
ConstraintHelper::ExistsDestGeneral(),
ConstraintHelper::FriendlyDestGeneral(),
ConstraintHelper::DisallowDiplomacyStatus(
$this->generalObj->getNationID(),
[4 => '현재 통합 진행중입니다.']
)
];
}
+9 -25
View File
@@ -72,33 +72,17 @@ class che_하야 extends Command\GeneralCommand{
$nationID = $this->nation['nation'];
$nationName = $this->nation['name'];
$josaUl = JosaUtil::pick($nationName, '을');
$dipState = Util::arrayGroupBy($db->query('SELECT no, state FROM diplomacy WHERE me = %i', $nationID), 'state');
$logger = $general->getLogger();
if(key_exists('3', $dipState) || key_exists('4', $dipState)){
$logger->pushGeneralActionLog("통합에 반대하며 <D><b>{$nationName}</b></>에서 떠났습니다. <1>$date</>");
$logger->pushGeneralHistoryLog("통합에 반대하며 <D><b>{$nationName}</b></>{$josaUl} 떠남");
$logger->pushGlobalActionLog("<Y>{$generalName}</>{$josaYi} 통합에 반대하며 <D><b>{$nationName}</b></>{$josaUl} <R>떠났</>습니다.");
}
else if(key_exists('5', $dipState) || key_exists('6', $dipState)){
$logger->pushGeneralActionLog("합병에 반대하며 <D><b>{$nationName}</b></>에서 떠났습니다. <1>$date</>");
$logger->pushGeneralHistoryLog("합병에 반대하며 <D><b>{$nationName}</b></>{$josaUl} 떠남");
$logger->pushGlobalActionLog("<Y>{$generalName}</>{$josaYi} 합병에 반대하며 <D><b>{$nationName}</b></>{$josaUl} <R>떠났</>습니다.");
}
else{
$logger->pushGeneralActionLog("<D><b>{$nationName}</b></>에서 하야했습니다. <1>$date</>");
$logger->pushGeneralHistoryLog("<D><b>{$nationName}</b></>에서 하야");
$logger->pushGlobalActionLog("<Y>{$generalName}</>{$josaYi} <D><b>{$nationName}</b></>에서 <R>하야</>했습니다.");
$general->setVar('experience', $general->getVar('experience') * (1 - 0.1 * $general->getVar('betray')));
$general->addExperience(0, false);
$general->setVar('dedication', $general->getVar('dedication') * (1 - 0.1 * $general->getVar('betray')));
$general->addDedication(0, false);
$general->increaseVarWithLimit('betray', 1, null, GameConst::$maxBetrayCnt);
}
$logger->pushGeneralActionLog("<D><b>{$nationName}</b></>에서 하야했습니다. <1>$date</>");
$logger->pushGeneralHistoryLog("<D><b>{$nationName}</b></>에서 하야");
$logger->pushGlobalActionLog("<Y>{$generalName}</>{$josaYi} <D><b>{$nationName}</b></>에서 <R>하야</>했습니다.");
$general->setVar('experience', $general->getVar('experience') * (1 - 0.1 * $general->getVar('betray')));
$general->addExperience(0, false);
$general->setVar('dedication', $general->getVar('dedication') * (1 - 0.1 * $general->getVar('betray')));
$general->addDedication(0, false);
$general->increaseVarWithLimit('betray', 1, null, GameConst::$maxBetrayCnt);
$newGold = Util::valueFit($general->getVar('gold'), null, GameConst::$defaultGold);
$newRice = Util::valueFit($general->getVar('rice'), null, GameConst::$defaultRice);
@@ -140,10 +140,6 @@ class che_불가침수락 extends Command\NationCommand
ConstraintHelper::DisallowDiplomacyBetweenStatus([
0 => '아국과 이미 교전중입니다.',
1 => '아국과 이미 선포중입니다.',
3 => '아국과 외교 진행중입니다.',
4 => '아국과 외교 진행중입니다.',
5 => '아국과 외교 진행중입니다.',
6 => '아국과 외교 진행중입니다.',
]),
];
}
@@ -126,10 +126,6 @@ class che_불가침제의 extends Command\NationCommand
ConstraintHelper::DisallowDiplomacyBetweenStatus([
0 => '아국과 이미 교전중입니다.',
1 => '아국과 이미 선포중입니다.',
3 => '아국과 외교 진행중입니다.',
4 => '아국과 외교 진행중입니다.',
5 => '아국과 외교 진행중입니다.',
6 => '아국과 외교 진행중입니다.',
]),
];
}
@@ -95,11 +95,6 @@ class che_선전포고 extends Command\NationCommand
ConstraintHelper::DisallowDiplomacyBetweenStatus([
0 => '아국과 이미 교전중입니다.',
1 => '아국과 이미 선포중입니다.',
7 => '아국과 불가침중입니다.',
]),
ConstraintHelper::DisallowDiplomacyStatus($this->destNation['nation'], [
3 => '상대국이 외교 진행중입니다.',
5 => '상대국이 외교 진행중입니다.'
]),
];
}
-95
View File
@@ -11,8 +11,6 @@ class DiplomaticMessage extends Message{
const TYPE_NO_AGGRESSION = 'noAggression'; //불가침
const TYPE_CANCEL_NA = 'cancelNA'; //불가침 파기
const TYPE_STOP_WAR = 'stopWar'; //종전
const TYPE_MERGE = 'merge'; //통합
const TYPE_SURRENDER = 'surrender'; //항복
protected $diplomaticType = '';
protected $diplomacyName = '';
@@ -38,8 +36,6 @@ class DiplomaticMessage extends Message{
case self::TYPE_NO_AGGRESSION: $this->diplomacyName = '불가침'; break;
case self::TYPE_CANCEL_NA: $this->diplomacyName = '불가침 파기'; break;
case self::TYPE_STOP_WAR: $this->diplomacyName = '종전'; break;
case self::TYPE_MERGE: $this->diplomacyName = '통합'; break;
case self::TYPE_SURRENDER: $this->diplomacyName = '투항'; break;
default: throw new \RuntimeException('diplomaticType이 올바르지 않음');
}
@@ -139,91 +135,6 @@ class DiplomaticMessage extends Message{
return [self::ACCEPTED, ''];
}
protected function acceptMerge(){
$helper = new Engine\Diplomacy($this->src->nationID, $this->dest->nationID);
$chk = $helper->acceptMerge($this->src->generalID, $this->dest->generalID);
if($chk[0] !== self::ACCEPTED){
return $chk;
}
$josaWa = JosaUtil::pick($this->src->nationName, '와');
pushGeneralHistory(
$this->dest->generalID,
["<C>●</>{$helper->year}{$helper->month}월:<D><b>{$this->src->nationName}</b></>{$josaWa} 통합 시도"]
);
pushGenLog(
$this->dest->generalID,
["<C>●</><D><b>{$this->src->nationName}</b></>{$josaWa} 통합에 동의했습니다."]
);
$josaWa = JosaUtil::pick($this->src->nationName, '와');
$josaYi = JosaUtil::pick($this->dest->generalName, '이');
pushGeneralPublicRecord(
["<C>●</>{$helper->month}월:<Y>{$this->dest->generalName}</>{$josaYi} <D><b>{$this->src->nationName}</b></>{$josaWa} <M>통합</>에 동의하였습니다."],
$helper->year,
$helper->month);
$josaYi = JosaUtil::pick($this->src->generalName, '이');
$josaWa = JosaUtil::pick($this->dest->nationName, '와');
pushGeneralHistory(
$this->src->generalID,
["<C>●</>{$helper->year}{$helper->month}월:<D><b>{$this->dest->nationName}</b></>{$josaWa} 통합 시도"]
);
$josaYi = JosaUtil::pick($this->dest->nationName, '이');
pushGenLog(
$this->src->generalID,
["<C>●</><D><b>{$this->dest->nationName}</b></>{$josaYi} 통합에 동의했습니다."]
);
pushWorldHistory(
["<C>●</>{$helper->year}{$helper->month}월:<Y><b>【통합시도】</b></><D><b>{$this->dest->nationName}</b></>{$josaWa}과 <D><b>{$this->src->nationName}</b></>{$josaYi} 통합을 시도합니다."],
$helper->year,
$helper->month
);
return $chk;
}
protected function acceptSurrender(){
$helper = new Engine\Diplomacy($this->src->nationID, $this->dest->nationID);
$chk = $helper->acceptSurrender($this->src->generalID, $this->dest->generalID);
if($chk[0] !== self::ACCEPTED){
return $chk;
}
$josaRo = JosaUtil::pick($this->src->nationName, '로');
pushGeneralHistory(
$this->src->generalID,
["<C>●</>{$helper->year}{$helper->month}월:<D><b>{$this->dest->nationName}</b></>에게 투항 제의"]
);
pushGeneralHistory(
$this->dest->generalID,
["<C>●</>{$helper->year}{$helper->month}월:<D><b>{$this->src->nationName}</b></>{$josaRo} 투항 동의"]
);
pushGenLog(
$this->dest->generalID,
["<C>●</><D><b>{$this->src->nationName}</b></>{$josaRo} 투항에 동의했습니다."]
);
$josaYi = JosaUtil::pick($this->dest->nationName, '이');
pushGenLog(
$this->src->generalID,
["<C>●</><D><b>{$this->dest->nationName}</b></>{$josaYi} 투항에 동의했습니다."]
);
$josaYi = JosaUtil::pick($this->dest->generalName, '이');
pushGeneralPublicRecord(
["<C>●</>{$helper->month}월:<Y>{$this->dest->generalName}</>{$josaYi} <D><b>{$this->src->nationName}</b></>{$josaRo} <M>투항</>에 동의하였습니다."],
$helper->year,
$helper->month);
$josaYi = JosaUtil::pick($this->dest->nationName, '이');
pushWorldHistory(
["<C>●</>{$helper->year}{$helper->month}월:<Y><b>【투항시도】</b></><D><b>{$this->dest->nationName}</b></>{$josaYi} <D><b>{$this->src->nationName}</b></>{$josaRo} 투항합니다."],
$helper->year,
$helper->month
);
return $chk;
}
/**
* @return int 수행 결과 반환, ACCEPTED(등용장 소모), DECLINED(등용장 소모), INVALID 중 반환
*/
@@ -270,12 +181,6 @@ class DiplomaticMessage extends Message{
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 new \RuntimeException('diplomaticType이 올바르지 않음');
}
-6
View File
@@ -1,6 +0,0 @@
<?php
namespace sammo\Engine;
class Battle{
}
-358
View File
@@ -1,358 +0,0 @@
<?php
namespace sammo\Engine;
use \sammo\DB;
use \sammo\DiplomaticMessage;
use \sammo\KVStorage;
use \sammo\Json;
use \sammo\GameConst;
//NOTE: A가 B에게 항복, 통합 서신을 보냈을 때 통합 후 대상이 A이므로 A가 주체임.
class Diplomacy{
protected $srcNation = null;//TODO: 클래스로 변경
protected $destNation = null;
protected $srcToDestDiplomacy = null;
protected $destToSrcDiplomacy = null;
public $valid = false;
public $startYear = 0;
public $year = 0;
public $month = 0;
public function __construct(int $srcNationID, int $destNationID){
if($srcNationID === $destNationID){
return;
}
$db = DB::db();
$gameStor = KVStorage::getStorage($db, 'game_env');
$srcNation = $db->queryFirstRow(
'SELECT nation, `name`, `power`, capital, gold, rice, gennum, surlimit, color, `level` FROM nation WHERE nation=%i',
$srcNationID
);
$destNation = $db->queryFirstRow(
'SELECT nation, `name`, `power`, capital, gold, rice, gennum, surlimit, color, `level` FROM nation WHERE nation=%i',
$destNationID
);
if(!$srcNation || !$destNation){
return;
}
$this->srcToDestDiplomacy = $db->queryFirstRow(
'SELECT * FROM diplomacy WHERE me = %i AND you = %i',
$srcNationID,
$destNationID
);
$this->destToSrcDiplomacy = $db->queryFirstRow(
'SELECT * FROM diplomacy WHERE me = %i AND you = %i',
$destNationID,
$srcNationID
);
$this->srcNation = $srcNation;
$this->destNation = $destNation;
$this->valid = true;
list(
$this->startYear,
$this->year,
$this->month
) = $gameStor->getValuesAsArray(['startyear', 'year', 'month']);
}
//방랑군이 아니어야함
//상대도 방랑군이 아니어야함
//불가침시 : 교전중이 아니어야함, 선포중이 아니어야함. (서로) 합병중이 아니어얗.
//불가침 파기시 : 불가침 중이어야함.
//종전시 : 교전중이거나 선포중이어야함.
//합병시 : 양국 다 외교제한이 지나지 않았어야함. 국력, 장수수가 적절해야함. 인접한 국가여야함. 서로 교전중이어선 안됨.
// 송신자가 선포, 전쟁중이어선 안됨. 송신자가 C국과 불가침인데 수신자가 C국과 전쟁중이면 안됨
//항복시 : 양국 다 외교제한이 지나지 않았어야함. 국력, 장수수가 적절해야함. 인접한 국가여야함. 서로 교전중이어선 안됨.
// 송신자가 선포, 전쟁중이어선 안됨. 송신자가 C국과 불가침인데 수신자가 C국과 전쟁중이면 안됨
protected function checkValidNation(array $prev = [DiplomaticMessage::ACCEPTED, '']){
if($prev[0] !== DiplomaticMessage::ACCEPTED){
return $prev;
}
if(!$this->srcNation || !$this->destNation || !$this->valid){
return [DiplomaticMessage::DECLINED, '올바르지 않은 국가입니다.'];
}
if($this->srcNation['level'] == 0 || $this->destNation['level'] == 0){
return [DiplomaticMessage::DECLINED, '방랑군과 외교룰 수행할 수 없습니다.'];
}
return $prev;
}
protected function checkNotWar(array $prev = [DiplomaticMessage::ACCEPTED, '']){
if($prev[0] !== DiplomaticMessage::ACCEPTED){
return $prev;
}
if($this->srcToDestDiplomacy['state'] == 0 || $this->srcToDestDiplomacy['state'] == 0
||$this->destToSrcDiplomacy['state'] == 1 || $this->destToSrcDiplomacy['state'] == 1){
return [DiplomaticMessage::DECLINED, '상대국과 선포, 전쟁 중입니다.'];
}
return $prev;
}
protected function checkNonAggressionTreaty(array $prev = [DiplomaticMessage::ACCEPTED, '']){
if($prev[0] !== DiplomaticMessage::ACCEPTED){
return $prev;
}
if($this->srcToDestDiplomacy['state'] !== 7 || $this->destToSrcDiplomacy['state'] !== 7){
return [DiplomaticMessage::DECLINED, '상대국과 불가침 중이 아닙니다.'];
}
return $prev;
}
protected function checkInWar(array $prev = [DiplomaticMessage::ACCEPTED, '']){
if($prev[0] !== DiplomaticMessage::ACCEPTED){
return $prev;
}
if($this->srcToDestDiplomacy['state'] == 0 || $this->srcToDestDiplomacy['state'] == 0
||$this->destToSrcDiplomacy['state'] == 1 || $this->destToSrcDiplomacy['state'] == 1){
return $prev;
}
return [DiplomaticMessage::DECLINED, '상대국과 선포, 전쟁 중이 아닙니다.'];
}
protected function checkDiplomacyLimit(array $prev = [DiplomaticMessage::ACCEPTED, '']){
if($prev[0] !== DiplomaticMessage::ACCEPTED){
return $prev;
}
if($this->destNation['surlimit'] > 0){
return [DiplomaticMessage::DECLINED, '본국의 외교 기한이 남아있습니다.'];
}
if($this->srcNation['surlimit'] > 0){
return [DiplomaticMessage::DECLINED, '상대국의 외교 기한이 남아있습니다.'];
}
return $prev;
}
protected function checkStrictlyAdjacent(array $prev = [DiplomaticMessage::ACCEPTED, '']){
if($prev[0] !== DiplomaticMessage::ACCEPTED){
return $prev;
}
if(!\sammo\isNeighbor($this->srcNation['nation'], $this->destNation['nation'], false)){
return [DiplomaticMessage::DECLINED, '상대국의 도시들과 보급선이 이어지지 않았습니다.'];
}
return $prev;
}
protected function checkAdjacent(array $prev = [DiplomaticMessage::ACCEPTED, '']){
if($prev[0] !== DiplomaticMessage::ACCEPTED){
return $prev;
}
if(!\sammo\isNeighbor($this->srcNation['nation'], $this->destNation['nation'], true)){
return [DiplomaticMessage::DECLINED, '상대국의 도시와 인접하지 않았습니다.'];
}
return $prev;
}
protected function checkAlreadyMerging(array $prev = [DiplomaticMessage::ACCEPTED, '']){
if($prev[0] !== DiplomaticMessage::ACCEPTED){
return $prev;
}
if((3 <= $this->srcToDestDiplomacy['state'] && $this->srcToDestDiplomacy['state'] <= 6)
||(3 <= $this->destToSrcDiplomacy['state'] && $this->destToSrcDiplomacy['state'] <= 6)){
return [DiplomaticMessage::DECLINED, '상대국과 합병 중입니다.'];
}
return $prev;
}
protected function checkSrcNationHasNeutralDiplomacy(array $prev = [DiplomaticMessage::ACCEPTED, '']){
if($prev[0] !== DiplomaticMessage::ACCEPTED){
return $prev;
}
$db = \sammo\DB::db();
$states = $db->queryFirstColumn(
'SELECT `state` FROM diplomacy WHERE `state` NOT IN (2, 7) AND me=%i AND you <>%i',
$this->srcNation['nation'],
$this->destNation['nation']
);
foreach($states as $state){
if($state == 0 || $state == 1){
return [DiplomaticMessage::DECLINED, '상대국이 전쟁 중입니다.'];
}
if(3 <= $state && $state <= 6){
return [DiplomaticMessage::DECLINED, '상대국이 합병 중입니다.'];
}
}
return $prev;
}
protected function checkContradictoryDiplomacy(array $prev = [DiplomaticMessage::ACCEPTED, '']){
if($prev[0] !== DiplomaticMessage::ACCEPTED){
return $prev;
}
$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 [DiplomaticMessage::DECLINED, '상대국이 본국의 교전국과 불가침중입니다.'];
}
return $prev;
}
protected function checkMorePower(array $prev = [DiplomaticMessage::ACCEPTED, '']){
if($prev[0] !== DiplomaticMessage::ACCEPTED){
return $prev;
}
if($this->srcNation['power'] < $this->destNation['power'] * 3){
return [DiplomaticMessage::DECLINED, '상대국과 국력차가 크지 않습니다.'];
}
return $prev;
}
protected function checkMergePower(array $prev = [DiplomaticMessage::ACCEPTED, '']){
if($prev[0] !== DiplomaticMessage::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 [DiplomaticMessage::DECLINED, '두 국가의 국력 평균이 상위 60% 보다 높습니다.'];
}
$mergedGeneral = ($this->srcNation['gennum'] + $this->destNation['gennum'])/2;
$ZGeneral = ($mergedGeneral - $genAvg) / $genStddev;
if($ZGeneral >= -0.67){
return [DiplomaticMessage::DECLINED, '두 국가의 장수수 평균이 상위 75% 보다 높습니다.'];
}
return $prev;
}
public function cancelNA(){
$chk = $this->checkValidNation();
$chk = $this->checkNonAggressionTreaty($chk);
[$result, $reason] = $chk;
if($result !== DiplomaticMessage::ACCEPTED){
return $chk;
}
$db = DB::db();
$db->update('diplomacy',[
'state'=>2,
'term'=>0
],
'(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 $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 !== DiplomaticMessage::ACCEPTED){
return $chk;
}
$db = DB::db();
$db->update('diplomacy',[
'state'=>4,
'term'=>24
],
'me=%i AND you=%i',
$this->srcNation['nation'], $this->destNation['nation']);
$db->update('diplomacy',[
'state'=>3,
'term'=>24
],
'you=%i AND me=%i',
$this->srcNation['nation'], $this->destNation['nation']);
return $chk;
}
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 !== DiplomaticMessage::ACCEPTED){
return $chk;
}
$db = DB::db();
$db->update('diplomacy',[
'state'=>6,
'term'=>24
],
'me=%i AND you=%i',
$this->srcNation['nation'], $this->destNation['nation']);
$db->update('diplomacy',[
'state'=>5,
'term'=>24
],
'you=%i AND me=%i',
$this->srcNation['nation'], $this->destNation['nation']);
return $chk;
}
}
-1
View File
@@ -304,7 +304,6 @@ class GameConstBase
'che_몰수',
],
'외교'=>[
//'che_항복권고',
'che_물자원조',
'che_불가침제의',
'che_선전포고',