forked from devsam/core
증여 추가
This commit is contained in:
@@ -1004,96 +1004,6 @@ function process_43(&$general) {
|
||||
pushGenLog($gen, $genlog);
|
||||
}
|
||||
|
||||
function process_44(&$general) {
|
||||
$db = DB::db();
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$connect=$db->get();
|
||||
|
||||
$log = [];
|
||||
$alllog = [];
|
||||
$history = [];
|
||||
$date = substr($general['turntime'],11,5);
|
||||
|
||||
$admin = $gameStor->getValues(['year', 'month']);
|
||||
|
||||
$query = "select name,gold,rice from nation where nation='{$general['nation']}'";
|
||||
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
$nation = MYDB_fetch_array($result);
|
||||
|
||||
$query = "select nation,supply from city where city='{$general['city']}'";
|
||||
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
$city = MYDB_fetch_array($result);
|
||||
|
||||
$command = DecodeCommand($general['turn0']);
|
||||
$what = $command[2];
|
||||
$amount = $command[1];
|
||||
$amount *= 100; // 100~10000까지
|
||||
|
||||
if($amount > 10000) { $amount = 10000; }
|
||||
if($amount < 100) { $amount = 100; }
|
||||
if($what == 1) {
|
||||
$dtype = "금";
|
||||
if($general['gold'] < $amount) { $amount = $general['gold']; }
|
||||
} elseif($what == 2) {
|
||||
$dtype = "쌀";
|
||||
if($general['rice'] < $amount) { $amount = $general['rice']; }
|
||||
} else {
|
||||
$what = 2;
|
||||
$dtype = "쌀";
|
||||
if($general['rice'] < $amount) { $amount = $general['rice']; }
|
||||
}
|
||||
|
||||
if($general['nation'] == 0) {
|
||||
$log[] = "<C>●</>{$admin['month']}월:재야입니다. 헌납 실패. <1>$date</>";
|
||||
} elseif($what == 1 && $general['gold'] <= 0) {
|
||||
$log[] = "<C>●</>{$admin['month']}월:자금이 없습니다. 헌납 실패. <1>$date</>";
|
||||
} elseif($what == 2 && $general['rice'] <= 0) {
|
||||
$log[] = "<C>●</>{$admin['month']}월:군량이 없습니다. 헌납 실패. <1>$date</>";
|
||||
} elseif($general['nation'] != $city['nation']) {
|
||||
$log[] = "<C>●</>{$admin['month']}월:아국이 아닙니다. 헌납 실패. <1>$date</>";
|
||||
} elseif($city['supply'] == 0) {
|
||||
$log[] = "<C>●</>{$admin['month']}월:고립된 도시입니다. 헌납 실패. <1>$date</>";
|
||||
} else {
|
||||
// $alllog[] = "<C>●</>{$admin['month']}월:<D><b>{$nation['name']}</b></>에서 장수들이 재산을 헌납 하고 있습니다.";
|
||||
$log[] = "<C>●</>{$admin['month']}월: $dtype <C>$amount</>을 헌납했습니다. <1>$date</>";
|
||||
|
||||
if($what == 1) {
|
||||
$general['gold'] -= $amount;
|
||||
$query = "update general set gold='{$general['gold']}' where no='{$general['no']}'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
|
||||
$nation['gold'] += $amount;
|
||||
$query = "update nation set gold='{$nation['gold']}' where nation='{$general['nation']}'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
} elseif($what == 2) {
|
||||
$general['rice'] -= $amount;
|
||||
$query = "update general set rice='{$general['rice']}' where no='{$general['no']}'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
|
||||
$nation['rice'] += $amount;
|
||||
$query = "update nation set rice='{$nation['rice']}' where nation='{$general['nation']}'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
}
|
||||
|
||||
$exp = 70;
|
||||
$ded = 100;
|
||||
|
||||
// 성격 보정
|
||||
$exp = CharExperience($exp, $general['personal']);
|
||||
$ded = CharDedication($ded, $general['personal']);
|
||||
|
||||
// 경험치 상승 // 공헌도, 명성 상승
|
||||
$general['leader2']++;
|
||||
$query = "update general set resturn='SUCCESS',leader2='{$general['leader2']}',dedication=dedication+'$ded',experience=experience+'$exp' where no='{$general['no']}'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
|
||||
$log = checkAbility($general, $log);
|
||||
}
|
||||
pushGeneralPublicRecord($alllog, $admin['year'], $admin['month']);
|
||||
pushGenLog($general, $log);
|
||||
}
|
||||
|
||||
|
||||
function process_48(&$general) {
|
||||
$db = DB::db();
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
|
||||
@@ -12,7 +12,7 @@ use \sammo\Constraint\Constraint;
|
||||
abstract class BaseCommand{
|
||||
/**
|
||||
* @var General|null $generalObj
|
||||
* @var array|null $destGeneral
|
||||
* @var General|null $destGeneralObj
|
||||
*/
|
||||
static protected $actionName = 'CommandName';
|
||||
|
||||
@@ -22,7 +22,7 @@ abstract class BaseCommand{
|
||||
protected $arg = null;
|
||||
protected $env = null;
|
||||
|
||||
protected $destGeneral = null;
|
||||
protected $destGeneralObj = null;
|
||||
protected $destCity = null;
|
||||
protected $destNation = null;
|
||||
|
||||
@@ -114,15 +114,9 @@ abstract class BaseCommand{
|
||||
$this->destNation = $destNation;
|
||||
}
|
||||
|
||||
protected function setDestGeneralFromObj(General $destGeneral){
|
||||
protected function setDestGeneral(General $destGeneralObj){
|
||||
$this->resetTestCache();
|
||||
$this->destGeneral = $destGeneral->getRaw();
|
||||
}
|
||||
|
||||
protected function setDestGeneral(int $generalNo, array $args){
|
||||
$this->resetTestCache();
|
||||
$db = DB::db();
|
||||
$this->destGeneral = $db->queryFirstRow('SELECT %lb FROM general WHERE no=%i', $args, $generalNo);
|
||||
$this->destGeneralObj = $destGeneralObj;
|
||||
}
|
||||
|
||||
protected function setDestCity(int $cityNo, ?array $args){
|
||||
@@ -219,7 +213,7 @@ abstract class BaseCommand{
|
||||
'nation'=>$this->nation,
|
||||
'arg'=>$this->arg,
|
||||
|
||||
'destGeneral'=>$this->destGeneral,
|
||||
'destGeneral'=>$this->destGeneralObj->getRaw(),
|
||||
'destCity'=>$this->destCity,
|
||||
'destNation'=>$this->destNation,
|
||||
];
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -107,10 +107,10 @@ class che_헌납 extends Command\GeneralCommand{
|
||||
$logger = $general->getLogger();
|
||||
|
||||
$db->update('nation', [
|
||||
$resourceKey=>$db->sqleval('%b + %i', $reKey, $amount)
|
||||
$resKey=>$db->sqleval('%b + %i', $resKey, $amount)
|
||||
], 'nation=%i', $general->getNationID());
|
||||
|
||||
$general->increaseVarWithLimit($resourceKey, -$amount, 0);
|
||||
$general->increaseVarWithLimit($resKey, -$amount, 0);
|
||||
|
||||
$logger->pushGeneralActionLog("{$resName} <C>$amountText</>을 헌납했습니다. <1>$date</>");
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Constraint;
|
||||
|
||||
class ExistsDestGeneral extends Constraint{
|
||||
const REQ_VALUES = Constraint::REQ_DEST_GENERAL;
|
||||
|
||||
public function checkInputValues(bool $throwExeception=true){
|
||||
if(!parent::checkInputValues($throwExeception) && !$throwException){
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function test():bool{
|
||||
$this->checkInputValues();
|
||||
$this->tested = true;
|
||||
|
||||
if($this->destGeneral['no']){
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->reason = "없는 장수입니다.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Constraint;
|
||||
|
||||
class FriendlyDestGeneral extends Constraint{
|
||||
const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_DEST_GENERAL;
|
||||
|
||||
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->destGeneral)){
|
||||
if(!$throwExeception){return false; }
|
||||
throw new \InvalidArgumentException("require nation in dest general");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function test():bool{
|
||||
$this->checkInputValues();
|
||||
$this->tested = true;
|
||||
|
||||
if($this->general['nation'] == $this->destGeneral['nation']){
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->reason = "아국 장수가 아닙니다.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace sammo;
|
||||
|
||||
class DummyGeneral extends General{
|
||||
public function __construct(bool $initLogger=true){
|
||||
$raw = [
|
||||
'no'=>0,
|
||||
'name'=>'Dummy',
|
||||
'city'=>0,
|
||||
'nation'=>0,
|
||||
'level'=>0,
|
||||
];
|
||||
|
||||
$staticNation = getNationStaticInfo($raw['nation']);
|
||||
$this->raw = $raw;
|
||||
|
||||
$this->resultTurn = new LastTurn();
|
||||
|
||||
if($initLogger){
|
||||
$this->logger = new ActionLogger(
|
||||
$this->getVar('no'),
|
||||
$this->getVar('nation'),
|
||||
1,
|
||||
1,
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function applyDB($db):bool{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -542,7 +542,7 @@ class General implements iAction{
|
||||
|
||||
$rawGeneral = $db->queryFirstRow('SELECT $lb FROM general WHERE no = %i', $generalID);
|
||||
if(!$rawGeneral){
|
||||
throw new \InvalidArgumentException("generalID에 해당하는 장수가 없음: {$generalID}");
|
||||
throw new NoDBResultException("generalID에 해당하는 장수가 없음: {$generalID}");
|
||||
}
|
||||
|
||||
$general = new static($rawGeneral, null, $year, $month, $constructMode > 1);
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace sammo;
|
||||
|
||||
class NoDBResultException extends \InvalidArgumentException
|
||||
{}
|
||||
Reference in New Issue
Block a user