160 lines
4.3 KiB
PHP
160 lines
4.3 KiB
PHP
<?php
|
|
namespace sammo\GeneralCommand;
|
|
|
|
use \sammo\{
|
|
DB, Util, JosaUtil,
|
|
General, DummyGeneral,
|
|
ActionLogger,
|
|
GameConst,
|
|
LastTurn,
|
|
GameUnitConst,
|
|
Command
|
|
};
|
|
|
|
use function \sammo\{
|
|
getDomesticExpLevelBonus,
|
|
CriticalRatioDomestic,
|
|
CriticalScoreEx,
|
|
uniqueItemEx
|
|
};
|
|
|
|
use \sammo\Constraint\Constraint;
|
|
|
|
|
|
class che_증여 extends Command\GeneralCommand{
|
|
static protected $actionName = '증여';
|
|
|
|
protected function init(){
|
|
|
|
$general = $this->generalObj;
|
|
|
|
$this->setCity();
|
|
$this->setNation();
|
|
|
|
try{
|
|
$destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['gold', 'nation'], 1);
|
|
}
|
|
catch(NoDBResultException $e){
|
|
$destGeneral = new DummyGeneral(false);
|
|
}
|
|
$this->setDestGeneral($destGeneral);
|
|
|
|
$this->runnableConstraints=[
|
|
['NoNeutral'],
|
|
['OccupiedCity'],
|
|
['SuppliedCity'],
|
|
['ExistsDestGeneral'],
|
|
['FriendlyDestGeneral']
|
|
];
|
|
if($this->arg['isGold']){
|
|
$this->runnableConstraints[] = ['ReqGeneralGold', 1];
|
|
}
|
|
else{
|
|
$this->runnableConstraints[] = ['ReqGeneralRice', 1];
|
|
}
|
|
|
|
}
|
|
|
|
protected function argTest():bool{
|
|
//NOTE: 사망 직전에 '증여' 턴을 넣을 수 있으므로, 존재하지 않는 장수여도 argTest에서 바로 탈락시키지 않음
|
|
if(!key_exists('isGold', $this->arg)){
|
|
return false;
|
|
}
|
|
if(!key_exists('amount', $this->arg)){
|
|
return false;
|
|
}
|
|
if(!key_exists('destGeneralID', $this->arg)){
|
|
return false;
|
|
}
|
|
$isGold = $this->arg['isGold'];
|
|
$amount = $this->arg['amount'];
|
|
$destGeneralID = $this->arg['destGeneralID'];
|
|
if(!is_int($amount)){
|
|
return false;
|
|
}
|
|
if($amount < 100){
|
|
return false;
|
|
}
|
|
if($amount > 10000){
|
|
return false;
|
|
}
|
|
$amount = (int)$amount;
|
|
if(!is_bool($isGold)){
|
|
return false;
|
|
}
|
|
if(!is_int($destGeneralID)){
|
|
return false;
|
|
}
|
|
if($destGeneralID < 0){
|
|
return false;
|
|
}
|
|
if($destGeneralID == $this->generalObj->getID()){
|
|
return false;
|
|
}
|
|
$this->arg = [
|
|
'isGold'=>$isGold,
|
|
'amount'=>$amount,
|
|
'destGeneralID'=>$destGeneralID
|
|
];
|
|
return true;
|
|
}
|
|
|
|
public function getCost():array{
|
|
return [0, 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);
|
|
|
|
$isGold = $this->arg['isGold'];
|
|
$amount = $this->arg['amount'];
|
|
$resKey = $isGold?'gold':'rice';
|
|
$resName = $isGold?'금':'쌀';
|
|
$destGeneral = $this->destGeneralObj;
|
|
|
|
$amount = Util::valueFit($amount, $general->getVar($resKey));
|
|
$amountText = number_format($amount, 0);
|
|
|
|
$logger = $general->getLogger();
|
|
|
|
$destGeneral->increaseVarWithLimit($resKey, $amount);
|
|
$general->increaseVarWithLimit($resKey, -$amount, 0);
|
|
|
|
$destGeneral->getLogger()->pushGeneralActionLog("{$general->getName()}</>에게서 {$resName} <C>{$amountText}</>을 증여 받았습니다.");
|
|
$logger->pushGeneralActionLog("{$destGeneral->getName()}에게 {$resName} <C>$amountText</>을 증여했습니다. <1>$date</>");
|
|
|
|
$exp = 70;
|
|
$ded = 100;
|
|
|
|
$exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp);
|
|
$ded = $general->onPreGeneralStatUpdate($general, 'dedication', $ded);
|
|
|
|
$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);
|
|
$destGeneral->applyDB($db);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
} |