전투태세, 첩보 추가, 기존 코드 일부 정리

This commit is contained in:
2018-10-20 16:45:57 +09:00
parent aecbf8ccb3
commit aa19ae129b
18 changed files with 476 additions and 216 deletions
-2
View File
@@ -333,12 +333,10 @@ class CityConstBase{
$queries = array_map(function(CityInitialDetail $city){
$initValue = static::$buildInit[$city->level];
$path = join('|', array_keys($city->path));
return [
'city'=>$city->id,
'name'=>$city->name,
'level'=>$city->level,
'path'=>$path,
'pop2'=>$city->population,
'agri2'=>$city->agriculture,
'comm2'=>$city->commerce,
+1 -1
View File
@@ -34,7 +34,7 @@ class che_강행 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
['NotSameCity'],
['NotSameDestCity'],
['NearCity', 3],
['ReqGeneralGold', $reqGold],
['ReqGeneralRice', $reqRice],
+4 -4
View File
@@ -81,19 +81,19 @@ class che_견문 extends Command\GeneralCommand{
}
if($type & SightseeingMessage::IncGold){
$general->increaseVar('gold', 300);
$text = str_replace(':amount:', '300', $text);
$text = str_replace(':goldAmount:', '300', $text);
}
if($type & SightseeingMessage::IncRice){
$general->increaseVar('rice', 300);
$text = str_replace(':amount:', '300', $text);
$text = str_replace(':riceAmount:', '300', $text);
}
if($type & SightseeingMessage::DecGold){
$general->increaseVarWithLimit('gold', -200, 0);
$text = str_replace(':amount:', '200', $text);
$text = str_replace(':goldAmount:', '200', $text);
}
if($type & SightseeingMessage::DecRice){
$general->increaseVarWithLimit('rice', -200, 0);
$text = str_replace(':amount:', '200', $text);
$text = str_replace(':riceAmount:', '200', $text);
}
if($type & SightseeingMessage::Wounded){
$general->increaseVarWithLimit('injury', Util::randRangeInt(10, 20), null, 80);
@@ -37,7 +37,7 @@ class che_사기진작 extends Command\GeneralCommand{
['ReqGeneralCrew'],
['ReqGeneralGold', $reqGold],
['ReqGeneralRice', $reqRice],
['ReqGeneralAtmosMargin'],
['ReqGeneralAtmosMargin', GameConst::$maxAtmosByCommand],
];
}
+1 -1
View File
@@ -34,7 +34,7 @@ class che_이동 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
['NotSameCity'],
['NotSameDestCity'],
['NearCity', 1],
['ReqGeneralGold', $reqGold],
['ReqGeneralRice', $reqRice],
@@ -0,0 +1,134 @@
<?php
namespace sammo\GeneralCommand;
use \sammo\{
DB, Util, JosaUtil,
General,
ActionLogger,
GameConst, GameUnitConst,
LastTurn,
Command,
MustNotBeReachedException
};
use function \sammo\{
uniqueItemEx, getTechCost
};
use \sammo\Constraint\Constraint;
class che_전투태세 extends Command\GeneralCommand{
static protected $actionName = '전투태세';
protected function init(){
$general = $this->generalObj;
$this->setCity();
$this->setNation();
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
['NoNeutral'],
['NoWanderingNation'],
['OccupiedCity'],
['ReqGeneralCrew'],
['ReqGeneralGold', $reqGold],
['ReqGeneralRice', $reqRice],
['ReqGeneralTrainMargin', GameConst::$maxTrainByCommand - 10],
['ReqGeneralAtmosMargin', GameConst::$maxAtmosByCommand - 10],
];
}
protected function argTest():bool{
$this->arg = null;
return true;
}
public function getCost():array{
$crew = $this->getVar('crew');
$techCost = getTechCost($this->nation['tech']);
return [Util::round($crew / 100 * 3 * $techCost), 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);
$lastTurn = $general->getLastTurn();
$turnResult = new LastTurn(static::getName(), $this->arg);
if($lastTurn->getCommand() != static::getName()){
$turnResult->setTerm(1);
}
else if($lastTurn->getTerm() == 3){
$turnResult->setTerm(1);
}
else if($lastTurn->getTerm() < 3){
$turnResult->setTerm($lastTurn->getTerm()+1);
}
else{
throw new MustNotBeReachedException('전투 태세는 1~3까지만 가능함');
}
$term = $turnResult->getTerm();
$logger = $general->getLogger();
if($term < 3){
$logger->pushGeneralActionLog("병사들을 열심히 훈련중... ({$term}/3) <1>$date</>");
$general->setResultTurn($turnResult);
$general->applyDB($db);
return true;
}
$logger->pushGeneralActionLog("전투태세 완료! ({$term}/3) <1>$date</>");
$general->increaseVarWithLimit('train', 0, GameConst::$maxTrainByCommand - 5); //95보다 높으면 '깎이지는 않음'
$general->increaseVarWithLimit('atmos', 0, GameConst::$maxAtmosByCommand - 5);
$exp = 100 * 3;
$ded = 70 * 3;
$exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp);
$ded = $general->onPreGeneralStatUpdate($general, 'dedication', $ded);
$general->increaseVar('experience', $exp);
$general->increaseVar('dedication', $ded);
$crew = $general->getVar('crew');
$general->addDex($general->getCrewTypeObj(), $crew / 100 * 3, false);
$general->increaseVar('leader2', 3);
$general->setResultTurn($turnResult);
$general->checkStatChange();
$general->applyDB($db);
uniqueItemEx($general->getID(), $logger);
return true;
}
}
+181
View File
@@ -0,0 +1,181 @@
<?php
namespace sammo\GeneralCommand;
use \sammo\{
DB, Util, JosaUtil,
General,
ActionLogger,
GameConst, GameUnitConst,
LastTurn,
Command
};
use function \sammo\{
uniqueItemEx,
searchDistance
};
use \sammo\Constraint\Constraint;
use sammo\CityConst;
class che_첩보 extends Command\GeneralCommand{
static protected $actionName = '첩보';
protected function init(){
$general = $this->generalObj;
$this->setCity();
$this->setNation(['tech']);
$this->setDestCity($this->arg['destCityID'], []);
$this->setDestNation($this->destCity['nation'], ['tech']);
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
['NotOccupiedDestCity'],
['ReqGeneralGold', $reqGold],
['ReqGeneralRice', $reqRice],
];
}
protected function argTest():bool{
if(!key_exists('destCityID', $this->arg)){
return false;
}
if(!key_exists($this->arg['destCityID'], CityConst::all())){
return false;
}
$this->arg = [
'destCityID'=>$this->arg['destCityID']
];
return true;
}
public function getCost():array{
$env = $this->env;
return [$env['develcost'], 0];
}
public function getPreReqTurn():int{
return 0;
}
public function getPostReqTurn():int{
return 0;
}
public function getFailString():string{
$commandName = $this->getName();
$failReason = $this->testRunnable();
if($failReason === null){
throw new \RuntimeException('실행 가능한 커맨드에 대해 실패 이유를 수집');
}
$destCityName = CityConst::byID($this->arg['destCityID'])->name;
return "{$failReason} <G><b>{$destCityName}</b></>에 {$commandName} 실패.";
}
public function run():bool{
if(!$this->isRunnable()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$env = $this->env;
$general = $this->generalObj;
$date = substr($general->getVar('turntime'),11,5);
$destCity = $this->destCity;
$destCityName = $destCity['name'];
$destCityID = $destCity['city'];
$destNationID = $destCity['nation'];
$josaUl = JosaUtil::pick($destCityName, '을');
$logger = $general->getLogger();
$dist = searchDistance($general->getCityID(), 2, false)[$destCityID]??3;
$destCityGeneralList = $db->query('SELECT crew, crewtype FROM general WHERE city = %i AND nation = %i');
$totalCrew = Util::arraySum($destCityGeneralList, 'crew');
$totalGenCnt = count($destCityGeneralList);
$byCrewType = Util::arrayGroupBy($destCityGeneralList, 'crewtype');
$popText = number_format($destCity['pop']);
$trustText = number_format($destCity['trust'], 1);
$agriText = number_format($destCity['agri']);
$commText = number_format($destCity['comm']);
$secuText = number_format($destCity['secu']);
$defText = number_format($destCity['def']);
$wallText = number_format($destCity['wall']);
$cityBrief = "【<G>{$destCityName}</>】주민:{$popText}, 민심:{$trustText}, 장수:{$totalGenCnt}, 병력:{$totalCrew}";
$cityDevel = "【<M>첩보</>】농업:{$agriText}, 상업:{$commText}, 치안:{$secuText}, 수비:{$defText}, 성벽:{$wallText}";
$logger->pushGeneralActionLog("누군가가 <G><b>{$destCityName}</b></>{$josaUl} 살피는 것 같습니다.");
if($dist < 1){
$logger->pushGeneralActionLog("<G><b>{$destCityName}</b></>의 정보를 많이 얻었습니다. <1>$date</>");
$logger->pushGeneralActionLog($cityBrief, ActionLogger::RAWTEXT);
$logger->pushGeneralActionLog($cityDevel, ActionLogger::RAWTEXT);
$logger->pushGeneralActionLog('【<S>병종</>】 '. join(' ', Util::mapWithKey(function($crewType, $value){
$crewTypeText = mb_substr(GameUnitConst::byID($crewType)->name, 0, 2);
$cnt = count($value);
return "{$crewTypeText}:{$cnt}";
})), ActionLogger::RAWTEXT);
if($this->destNation['nation'] && $general->getNationID()){
$techDiff = floor($this->destNation['tech']) - floor($this->nation['tech']);
if($techDiff >= 1000){
$techText = '<M>↑</>압도';
}
else if($techDiff >= 250){
$techText = '<Y>▲</>우위';
}
else if($techDiff >= -250){
$techText = '<W>↕</>대등';
}
else if($techDiff >= -1000){
$techText = '<G>▼</>열위';
}
else{
$techText = '<C>↓</>미미';
}
$logger->pushGeneralActionLog("【<span class='ev_notice'>{$this->destNation['name']}</span>】아국대비기술:{$techText}");
}
}
else if($dist == 2){
$logger->pushGeneralActionLog("<G><b>{$destCityName}</b></>의 정보를 어느 정도 얻었습니다. <1>$date</>");
$logger->pushGeneralActionLog($cityBrief, ActionLogger::RAWTEXT);
$logger->pushGeneralActionLog($cityDevel, ActionLogger::RAWTEXT);
}
else{
$logger->pushGeneralActionLog("<G><b>{$destCityName}</b></>의 소문만 들을 수 있었습니다. <1>$date</>");
$logger->pushGeneralActionLog($cityBrief, ActionLogger::RAWTEXT);
}
$exp = Util::randRangeInt(1, 100);
$ded = Util::randRangeInt(1, 70);
$exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp);
$ded = $general->onPreGeneralStatUpdate($general, 'dedication', $ded);
[$reqGold, $reqRice] = $this->getCost();
$general->increaseVarWithLimit('gold', -$reqGold, 0);
$general->increaseVarWithLimit('rice', -$reqRice, 0);
$general->increaseVar('experience', $exp);
$general->increaseVar('dedication', $ded);
$general->increaseVar('leader2', 1);
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
$general->applyDB($db);
return true;
}
}
+1 -1
View File
@@ -34,7 +34,7 @@ class che_훈련 extends Command\GeneralCommand{
['NoWanderingNation'],
['OccupiedCity'],
['ReqGeneralCrew'],
['ReqGeneralTrainMargin'],
['ReqGeneralTrainMargin', GameConst::$maxTrainByCommand],
];
}
@@ -0,0 +1,37 @@
<?php
namespace sammo\Constraint;
class NotOccupiedDestCity extends Constraint{
const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_DEST_CITY;
public function checkInputValues(bool $throwExeception=true){
if(!parent::checkInputValues($throwExeception) && !$throwException){
return false;
}
if(!key_exists('nation', $this->general)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require nation in general");
}
if(!key_exists('nation', $this->destCity)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require nation in city");
}
return true;
}
public function test():bool{
$this->checkInputValues();
$this->tested = true;
if($this->destCity['nation'] == $this->general['nation']){
return true;
}
$this->reason = "아국입니다.";
return false;
}
}
@@ -2,7 +2,7 @@
namespace sammo\Constraint;
class NearCity extends Constraint{
class NotSameDestCity extends Constraint{
const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_DEST_CITY;
public function checkInputValues(bool $throwExeception=true){
+32
View File
@@ -0,0 +1,32 @@
<?php
namespace sammo\Constraint;
class ReqCityTrader extends Constraint{
const REQ_VALUES = Constraint::REQ_CITY;
public function checkInputValues(bool $throwExeception=true){
if(!parent::checkInputValues($throwExeception) && !$throwException){
return false;
}
if(!key_exists('trade', $this->city)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require trade in city");
}
return true;
}
public function test():bool{
$this->checkInputValues();
$this->tested = true;
if($this->city['trade'] !== null){
return true;
}
$this->reason = "도시에 상인이 없습니다.";
return false;
}
}
@@ -4,7 +4,7 @@ namespace sammo\Constraint;
use sammo\GameConst;
class ReqGeneralAtmosMargin extends Constraint{
const REQ_VALUES = Constraint::REQ_GENERAL;
const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_INT_ARG;
public function checkInputValues(bool $throwExeception=true){
if(!parent::checkInputValues($throwExeception) && !$throwException){
@@ -23,7 +23,7 @@ class ReqGeneralAtmosMargin extends Constraint{
$this->checkInputValues();
$this->tested = true;
if($this->general['atmos'] < GameConst::$maxAtmosByCommand){
if($this->general['atmos'] < $this->arg){
return true;
}
@@ -4,7 +4,7 @@ namespace sammo\Constraint;
use sammo\GameConst;
class ReqGeneralTrainMargin extends Constraint{
const REQ_VALUES = Constraint::REQ_GENERAL;
const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_INT_ARG;
public function checkInputValues(bool $throwExeception=true){
if(!parent::checkInputValues($throwExeception) && !$throwException){
@@ -23,7 +23,7 @@ class ReqGeneralTrainMargin extends Constraint{
$this->checkInputValues();
$this->tested = true;
if($this->general['train'] < GameConst::$maxTrainByCommand){
if($this->general['train'] < $this->arg){
return true;
}
+1 -1
View File
@@ -2,7 +2,7 @@
namespace sammo\Constraint;
class NoWanderingNation extends Constraint{
class SuppliedCity extends Constraint{
const REQ_VALUES = Constraint::REQ_CITY;
public function checkInputValues(bool $throwExeception=true){
+10 -10
View File
@@ -47,17 +47,17 @@ class SightseeingMessage{
'거리에서 글 모르는 아이들을 모아 글을 가르쳤습니다.',
]], 2],
[[self::IncExp|self::IncGold,[
'지나가는 행인에게서 금을 <C>:amount:</> 받았습니다.',
'지나가는 행인에게서 금을 <C>:goldAmount:</> 받았습니다.',
]], 1],
[[self::IncExp|self::IncRice,[
'지나가는 행인에게서 쌀을 <C>:amount:</> 받았습니다.',
'지나가는 행인에게서 쌀을 <C>:riceAmount:</> 받았습니다.',
]], 1],
[[self::IncExp|self::DecGold,[
'산적을 만나 금 <C>:amount:</>을 빼앗겼습니다.',
'돈을 <C>:amount:</> 빌려주었다가 떼어먹혔습니다.',
'산적을 만나 금 <C>:goldAmount:</>을 빼앗겼습니다.',
'돈을 <C>:goldAmount:</> 빌려주었다가 떼어먹혔습니다.',
]], 1],
[[self::IncExp|self::DecRice,[
'쌀을 <C>:amount:</> 빌려주었다가 떼어먹혔습니다.',
'쌀을 <C>:riceAmount:</> 빌려주었다가 떼어먹혔습니다.',
]], 1],
[[self::IncExp|self::Wounded,[
'호랑이에게 물려 다쳤습니다.',
@@ -74,17 +74,17 @@ class SightseeingMessage{
'위기에 빠진 사람을 구하다가 죽을뻔 했습니다.',
]], 1],
[[self::IncHeavyExp|self::IncPower|self::IncGold,[
'산적과 싸워 금 <C>:amount:</>을 빼앗았습니다.',
'산적과 싸워 금 <C>:goldAmount:</>을 빼앗았습니다.',
]], 1],
[[self::IncHeavyExp|self::IncPower|self::IncRice,[
'호랑이를 잡아 고기 <C>:amount:</>을 얻었습니다.',
'곰을 잡아 고기 <C>:amount:</>을 얻었습니다.',
'호랑이를 잡아 고기 <C>:riceAmount:</>을 얻었습니다.',
'곰을 잡아 고기 <C>:riceAmount:</>을 얻었습니다.',
]], 1],
[[self::IncHeavyExp|self::IncIntel|self::IncGold,[
'돈을 빌려주었다가 이자 <C>:amount:</>을 받았습니다.',
'돈을 빌려주었다가 이자 <C>:goldAmount:</>을 받았습니다.',
]], 1],
[[self::IncHeavyExp|self::IncIntel|self::IncRice,[
'쌀을 빌려주었다가 이자 <C>300</>을 받았습니다.',
'쌀을 빌려주었다가 이자 <C>:riceAmount:</>을 받았습니다.',
]], 1],
];