Merge branch 'devel' of ssh://storage.hided.net:2525/devsam/core into devel
This commit is contained in:
+447
-447
@@ -1,448 +1,448 @@
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
use sammo\Command\GeneralCommand;
|
||||
use sammo\Command\NationCommand;
|
||||
|
||||
function getGeneralTurnBrief(General $generalObj, array $turnList) {
|
||||
$result = [];
|
||||
|
||||
foreach($turnList as $turnIdx => [$action, $arg]){
|
||||
$commandObj = buildGeneralCommandClass($action, $generalObj, [], $arg);
|
||||
$turnText = $commandObj->getBrief();
|
||||
$result[$turnIdx] = $turnText;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function getNationTurnBrief(General $generalObj, array $turnList) {
|
||||
$result = [];
|
||||
|
||||
$tmpTurn = new LastTurn();
|
||||
foreach($turnList as $turnIdx => [$action, $arg]){
|
||||
$commandObj = buildNationCommandClass($action, $generalObj, [], $tmpTurn, $arg);
|
||||
$turnText = $commandObj->getBrief();
|
||||
$result[$turnIdx] = $turnText;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function pushGeneralCommand(int $generalID, int $turnCnt=1){
|
||||
if($turnCnt == 0){
|
||||
return;
|
||||
}
|
||||
if($turnCnt < 0){
|
||||
pullGeneralCommand($generalID, -$turnCnt);
|
||||
return;
|
||||
}
|
||||
if($turnCnt >= GameConst::$maxTurn){
|
||||
return;
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$db->update('general_turn', [
|
||||
'turn_idx'=>$db->sqleval('turn_idx + %i', $turnCnt)
|
||||
], 'general_id=%i ORDER BY turn_idx DESC', $generalID);
|
||||
$db->update('general_turn', [
|
||||
'turn_idx'=>$db->sqleval('turn_idx - %i', GameConst::$maxTurn),
|
||||
'action'=>'휴식',
|
||||
'arg'=>'{}',
|
||||
'brief'=>'휴식'
|
||||
], 'general_id=%i AND turn_idx >= %i', $generalID, GameConst::$maxTurn);
|
||||
}
|
||||
|
||||
function pullGeneralCommand(int $generalID, int $turnCnt=1){
|
||||
if($turnCnt == 0){
|
||||
return;
|
||||
}
|
||||
if($turnCnt < 0){
|
||||
pushGeneralCommand($generalID, -$turnCnt);
|
||||
return;
|
||||
}
|
||||
if($turnCnt >= GameConst::$maxTurn){
|
||||
return;
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$db->update('general_turn', [
|
||||
'turn_idx'=>$db->sqleval('turn_idx + %i', GameConst::$maxTurn),
|
||||
'action'=>'휴식',
|
||||
'arg'=>'{}',
|
||||
'brief'=>'휴식'
|
||||
], 'general_id=%i AND turn_idx < %i', $generalID, $turnCnt);
|
||||
$db->update('general_turn', [
|
||||
'turn_idx'=>$db->sqleval('turn_idx - %i', $turnCnt)
|
||||
], 'general_id=%i ORDER BY turn_idx ASC', $generalID);
|
||||
}
|
||||
|
||||
function repeatGeneralCommand(int $generalId, int $turnCnt){
|
||||
if($turnCnt <= 0){
|
||||
return;
|
||||
}
|
||||
if($turnCnt >= GameConst::$maxTurn){
|
||||
return;
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$reqTurn = $turnCnt;
|
||||
if($turnCnt * 2 > GameConst::$maxTurn){
|
||||
$reqTurn = GameConst::$maxTurn - $turnCnt;
|
||||
}
|
||||
|
||||
$turnList = $db->query('SELECT turn_idx, `action`, arg, brief FROM general_turn WHERE general_id=%i AND turn_idx < %i', $generalId, $reqTurn);
|
||||
foreach($turnList as $turnItem){
|
||||
$turnIdx = $turnItem['turn_idx'];
|
||||
$turnTarget = iterator_to_array(Util::range($turnIdx+$turnCnt, GameConst::$maxTurn, $turnCnt));
|
||||
|
||||
$db->update('general_turn', [
|
||||
'action'=>$turnItem['action'],
|
||||
'arg'=>$turnItem['arg'],
|
||||
'brief'=>$turnItem['brief']
|
||||
], 'general_id=%i AND turn_idx IN %li', $generalId, $turnTarget);
|
||||
}
|
||||
}
|
||||
|
||||
function pushNationCommand(int $nationID, int $officerLevel, int $turnCnt=1){
|
||||
if($nationID == 0){
|
||||
return;
|
||||
}
|
||||
if($officerLevel < 5){
|
||||
return;
|
||||
}
|
||||
if($turnCnt == 0){
|
||||
return;
|
||||
}
|
||||
if($turnCnt < 0){
|
||||
pullNationCommand($nationID, $officerLevel, -$turnCnt);
|
||||
return;
|
||||
}
|
||||
if($turnCnt >= GameConst::$maxChiefTurn){
|
||||
return;
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$db->update('nation_turn', [
|
||||
'turn_idx'=>$db->sqleval('turn_idx + %i', $turnCnt)
|
||||
], 'nation_id=%i AND officer_level=%i ORDER BY turn_idx DESC', $nationID, $officerLevel);
|
||||
$db->update('nation_turn', [
|
||||
'turn_idx'=>$db->sqleval('turn_idx - %i', GameConst::$maxChiefTurn),
|
||||
'action'=>'휴식',
|
||||
'arg'=>'{}',
|
||||
'brief'=>'휴식'
|
||||
], 'nation_id=%i AND officer_level=%i AND turn_idx >= %i ORDER BY turn_idx ASC', $nationID, $officerLevel, GameConst::$maxChiefTurn);
|
||||
}
|
||||
|
||||
function pullNationCommand(int $nationID, int $officerLevel, int $turnCnt=1){
|
||||
if($nationID == 0){
|
||||
return;
|
||||
}
|
||||
if($officerLevel < 5){
|
||||
return;
|
||||
}
|
||||
if($turnCnt == 0){
|
||||
return;
|
||||
}
|
||||
if($turnCnt < 0){
|
||||
pushNationCommand($nationID, $officerLevel, -$turnCnt);
|
||||
return;
|
||||
}
|
||||
if($turnCnt >= GameConst::$maxChiefTurn){
|
||||
return;
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$db->update('nation_turn', [
|
||||
'turn_idx'=>$db->sqleval('turn_idx + %i', GameConst::$maxChiefTurn),
|
||||
'action'=>'휴식',
|
||||
'arg'=>'{}',
|
||||
'brief'=>'휴식',
|
||||
], 'nation_id=%i AND officer_level=%i AND turn_idx < %i', $nationID, $officerLevel, $turnCnt);
|
||||
$db->update('nation_turn', [
|
||||
'turn_idx'=>$db->sqleval('turn_idx - %i', $turnCnt)
|
||||
], 'nation_id=%i AND officer_level=%i ORDER BY turn_idx ASC', $nationID, $officerLevel);
|
||||
}
|
||||
|
||||
function _setGeneralCommand(GeneralCommand $command, array $turnList):void {
|
||||
if(!$turnList){
|
||||
return;
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$generalID = $command->getGeneral()->getID();
|
||||
$commandName = $command->getRawClassName();
|
||||
$arg = $command->getArg();
|
||||
$brief = $command->getBrief();
|
||||
|
||||
$db->update('general_turn', [
|
||||
'action'=>$commandName,
|
||||
'arg'=>Json::encode($arg, JSON::EMPTY_ARRAY_IS_DICT),
|
||||
'brief'=>$brief
|
||||
], 'general_id = %i AND turn_idx IN %li', $generalID, $turnList);
|
||||
}
|
||||
|
||||
function _setNationCommand(NationCommand $command, array $turnList):void {
|
||||
if(!$turnList){
|
||||
return;
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$nationID = $command->getNationID();
|
||||
$officerLevel = $command->getOfficerLevel();
|
||||
$commandName = $command->getRawClassName();
|
||||
$arg = $command->getArg();
|
||||
$brief = $command->getBrief();
|
||||
|
||||
$db->update('nation_turn', [
|
||||
'action'=>$commandName,
|
||||
'arg'=>Json::encode($arg, JSON::EMPTY_ARRAY_IS_DICT),
|
||||
'brief'=>$brief
|
||||
], 'nation_id = %i AND officer_level = %i AND turn_idx IN %li', $nationID, $officerLevel, $turnList);
|
||||
}
|
||||
|
||||
function sanitizeArg(?array $args):?array{
|
||||
if($args === null){
|
||||
return $args;
|
||||
}
|
||||
|
||||
$result = [];
|
||||
foreach($args as $key=>$value){
|
||||
if(is_array($value)){
|
||||
$result[$key] = sanitizeArg($value);
|
||||
}
|
||||
else if(is_string($value)){
|
||||
$result[$key] = StringUtil::neutralize(StringUtil::removeSpecialCharacter($value));
|
||||
}
|
||||
else{
|
||||
$result[$key] = $value;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function checkCommandArg(?array $arg):?string{
|
||||
if($arg === null){
|
||||
return null;
|
||||
}
|
||||
$defaultCheck = [
|
||||
/*'string'=>[
|
||||
'nationName', 'optionText', 'itemType', 'nationType'
|
||||
],*/
|
||||
'integer'=>[
|
||||
'crewType', 'destGeneralID', 'destCityID', 'destNationID',
|
||||
'amount', 'colorType',
|
||||
'srcArmType', 'destArmType', //숙련전환 전용
|
||||
],
|
||||
'boolean'=>[
|
||||
'isGold', 'buyRice',
|
||||
],
|
||||
'between'=>[
|
||||
['month', [1, 12]]
|
||||
],
|
||||
'min'=>[
|
||||
['year', 0],
|
||||
['destGeneralID', 1],
|
||||
['destCityID', 1],
|
||||
['destNationID', 1],
|
||||
['amount', 1],
|
||||
['crewType', 0]
|
||||
],
|
||||
'integerArray'=>[
|
||||
'destNationIDList', 'destGeneralIDList', 'amountList'
|
||||
],
|
||||
'stringWidthBetween'=>[
|
||||
['nationName', 1, 18]
|
||||
]
|
||||
];
|
||||
$v = new Validator($arg);
|
||||
$v->rules($defaultCheck);
|
||||
if (!$v->validate()){
|
||||
return $v->errorStr();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function setGeneralCommand(int $generalID, array $rawTurnList, string $command, ?array $arg = null):array{
|
||||
|
||||
$turnList = [];
|
||||
foreach($rawTurnList as $turnIdx){
|
||||
if(!is_int($turnIdx) || $turnIdx < -3 || $turnIdx >= GameConst::$maxTurn){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'올바른 턴이 아닙니다. : '.$turnIdx,
|
||||
'test'=>'turnIdx',
|
||||
'target'=>$turnIdx,
|
||||
];
|
||||
}
|
||||
if($turnIdx >= 0){
|
||||
$turnList[$turnIdx] = true;
|
||||
}
|
||||
else if($turnIdx == -1){
|
||||
//홀수
|
||||
foreach(Util::range(1, GameConst::$maxTurn, 2) as $subIdx){
|
||||
$turnList[$subIdx] = true;
|
||||
}
|
||||
}
|
||||
else if($turnIdx == -2){
|
||||
//짝수
|
||||
foreach(Util::range(0, GameConst::$maxTurn, 2) as $subIdx){
|
||||
$turnList[$subIdx] = true;
|
||||
}
|
||||
}
|
||||
else if($turnIdx == -3){
|
||||
//모두
|
||||
foreach(Util::range(GameConst::$maxTurn) as $subIdx){
|
||||
$turnList[$subIdx] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
$turnList = array_keys($turnList);
|
||||
|
||||
$arg = sanitizeArg($arg);
|
||||
$argBasicTestResult = checkCommandArg($arg);
|
||||
if($argBasicTestResult !== null){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'턴이 입력되지 않았습니다.',
|
||||
'test'=>'checkCommandArg',
|
||||
'target'=>'arg'
|
||||
];
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$env = $gameStor->getAll();
|
||||
$general = General::createGeneralObjFromDB($generalID);
|
||||
|
||||
try{
|
||||
$commandObj = buildGeneralCommandClass($command, $general, $env, $arg);
|
||||
}
|
||||
catch (\InvalidArgumentException $e){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>$e->getMessage(),
|
||||
'test'=>'build',
|
||||
'target'=>'arg'
|
||||
];
|
||||
}
|
||||
catch (\Exception $e){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>$e->getCode().$e->getMessage(),
|
||||
'test'=>'build',
|
||||
'target'=>'arg'
|
||||
];
|
||||
}
|
||||
|
||||
if(!$commandObj->isArgValid()){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'올바르지 않은 argument',
|
||||
'test'=>'isArgValid',
|
||||
'target'=>'arg'
|
||||
];
|
||||
}
|
||||
|
||||
if(!$commandObj->hasPermissionToReserve()){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'예약 불가능한 커맨드 :'.$commandObj->testPermissionToReserve(),
|
||||
'test'=>'hasPermissionToReserve',
|
||||
'target'=>'command'
|
||||
];
|
||||
}
|
||||
|
||||
_setGeneralCommand($commandObj, $turnList);
|
||||
return [
|
||||
'result'=>true,
|
||||
'reason'=>'success'
|
||||
];
|
||||
}
|
||||
|
||||
function setNationCommand(int $generalID, array $turnList, string $command, ?array $arg = null):array{
|
||||
$turnList = array_unique($turnList);
|
||||
foreach($turnList as $turnIdx){
|
||||
if(!is_int($turnIdx) || $turnIdx < 0 || $turnIdx >= GameConst::$maxChiefTurn){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'올바른 턴이 아닙니다. : '.$turnIdx,
|
||||
'test'=>'turnIdx',
|
||||
'target'=>$turnIdx,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$arg = sanitizeArg($arg);
|
||||
$argBasicTestResult = checkCommandArg($arg);
|
||||
if($argBasicTestResult !== null){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'턴이 입력되지 않았습니다.',
|
||||
'test'=>'checkCommandArg',
|
||||
'target'=>'arg'
|
||||
];
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$env = $gameStor->getAll();
|
||||
$general = General::createGeneralObjFromDB($generalID);
|
||||
|
||||
if($general->getVar('officer_level') < 5){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'수뇌가 아닙니다'
|
||||
];
|
||||
}
|
||||
|
||||
try{
|
||||
$commandObj = buildNationCommandClass($command, $general, $env, $general->getLastTurn(), $arg);
|
||||
}
|
||||
catch (\InvalidArgumentException $e){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>$e->getMessage(),
|
||||
'test'=>'build',
|
||||
'target'=>'arg'
|
||||
];
|
||||
}
|
||||
catch (\Exception $e){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>$e->getCode().$e->getMessage(),
|
||||
'test'=>'build',
|
||||
'target'=>'arg'
|
||||
];
|
||||
}
|
||||
|
||||
if(!$commandObj->isArgValid()){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'올바르지 않은 argument',
|
||||
'test'=>'isArgValid',
|
||||
'target'=>'arg'
|
||||
];
|
||||
}
|
||||
|
||||
if(!$commandObj->hasPermissionToReserve()){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'예약 불가능한 커맨드 :'.$commandObj->testPermissionToReserve(),
|
||||
'test'=>'hasPermissionToReserve',
|
||||
'target'=>'command'
|
||||
];
|
||||
}
|
||||
|
||||
_setNationCommand($commandObj, $turnList);
|
||||
return [
|
||||
'result'=>true,
|
||||
'arg_test'=>true,
|
||||
'reason'=>'success'
|
||||
];
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
use sammo\Command\GeneralCommand;
|
||||
use sammo\Command\NationCommand;
|
||||
|
||||
function getGeneralTurnBrief(General $generalObj, array $turnList) {
|
||||
$result = [];
|
||||
|
||||
foreach($turnList as $turnIdx => [$action, $arg]){
|
||||
$commandObj = buildGeneralCommandClass($action, $generalObj, [], $arg);
|
||||
$turnText = $commandObj->getBrief();
|
||||
$result[$turnIdx] = $turnText;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function getNationTurnBrief(General $generalObj, array $turnList) {
|
||||
$result = [];
|
||||
|
||||
$tmpTurn = new LastTurn();
|
||||
foreach($turnList as $turnIdx => [$action, $arg]){
|
||||
$commandObj = buildNationCommandClass($action, $generalObj, [], $tmpTurn, $arg);
|
||||
$turnText = $commandObj->getBrief();
|
||||
$result[$turnIdx] = $turnText;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function pushGeneralCommand(int $generalID, int $turnCnt=1){
|
||||
if($turnCnt == 0){
|
||||
return;
|
||||
}
|
||||
if($turnCnt < 0){
|
||||
pullGeneralCommand($generalID, -$turnCnt);
|
||||
return;
|
||||
}
|
||||
if($turnCnt >= GameConst::$maxTurn){
|
||||
return;
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$db->update('general_turn', [
|
||||
'turn_idx'=>$db->sqleval('turn_idx + %i', $turnCnt)
|
||||
], 'general_id=%i ORDER BY turn_idx DESC', $generalID);
|
||||
$db->update('general_turn', [
|
||||
'turn_idx'=>$db->sqleval('turn_idx - %i', GameConst::$maxTurn),
|
||||
'action'=>'휴식',
|
||||
'arg'=>'{}',
|
||||
'brief'=>'휴식'
|
||||
], 'general_id=%i AND turn_idx >= %i', $generalID, GameConst::$maxTurn);
|
||||
}
|
||||
|
||||
function pullGeneralCommand(int $generalID, int $turnCnt=1){
|
||||
if($turnCnt == 0){
|
||||
return;
|
||||
}
|
||||
if($turnCnt < 0){
|
||||
pushGeneralCommand($generalID, -$turnCnt);
|
||||
return;
|
||||
}
|
||||
if($turnCnt >= GameConst::$maxTurn){
|
||||
return;
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$db->update('general_turn', [
|
||||
'turn_idx'=>$db->sqleval('turn_idx + %i', GameConst::$maxTurn),
|
||||
'action'=>'휴식',
|
||||
'arg'=>'{}',
|
||||
'brief'=>'휴식'
|
||||
], 'general_id=%i AND turn_idx < %i', $generalID, $turnCnt);
|
||||
$db->update('general_turn', [
|
||||
'turn_idx'=>$db->sqleval('turn_idx - %i', $turnCnt)
|
||||
], 'general_id=%i ORDER BY turn_idx ASC', $generalID);
|
||||
}
|
||||
|
||||
function repeatGeneralCommand(int $generalId, int $turnCnt){
|
||||
if($turnCnt <= 0){
|
||||
return;
|
||||
}
|
||||
if($turnCnt >= GameConst::$maxTurn){
|
||||
return;
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$reqTurn = $turnCnt;
|
||||
if($turnCnt * 2 > GameConst::$maxTurn){
|
||||
$reqTurn = GameConst::$maxTurn - $turnCnt;
|
||||
}
|
||||
|
||||
$turnList = $db->query('SELECT turn_idx, `action`, arg, brief FROM general_turn WHERE general_id=%i AND turn_idx < %i', $generalId, $reqTurn);
|
||||
foreach($turnList as $turnItem){
|
||||
$turnIdx = $turnItem['turn_idx'];
|
||||
$turnTarget = iterator_to_array(Util::range($turnIdx+$turnCnt, GameConst::$maxTurn, $turnCnt));
|
||||
|
||||
$db->update('general_turn', [
|
||||
'action'=>$turnItem['action'],
|
||||
'arg'=>$turnItem['arg'],
|
||||
'brief'=>$turnItem['brief']
|
||||
], 'general_id=%i AND turn_idx IN %li', $generalId, $turnTarget);
|
||||
}
|
||||
}
|
||||
|
||||
function pushNationCommand(int $nationID, int $officerLevel, int $turnCnt=1){
|
||||
if($nationID == 0){
|
||||
return;
|
||||
}
|
||||
if($officerLevel < 5){
|
||||
return;
|
||||
}
|
||||
if($turnCnt == 0){
|
||||
return;
|
||||
}
|
||||
if($turnCnt < 0){
|
||||
pullNationCommand($nationID, $officerLevel, -$turnCnt);
|
||||
return;
|
||||
}
|
||||
if($turnCnt >= GameConst::$maxChiefTurn){
|
||||
return;
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$db->update('nation_turn', [
|
||||
'turn_idx'=>$db->sqleval('turn_idx + %i', $turnCnt)
|
||||
], 'nation_id=%i AND officer_level=%i ORDER BY turn_idx DESC', $nationID, $officerLevel);
|
||||
$db->update('nation_turn', [
|
||||
'turn_idx'=>$db->sqleval('turn_idx - %i', GameConst::$maxChiefTurn),
|
||||
'action'=>'휴식',
|
||||
'arg'=>'{}',
|
||||
'brief'=>'휴식'
|
||||
], 'nation_id=%i AND officer_level=%i AND turn_idx >= %i ORDER BY turn_idx ASC', $nationID, $officerLevel, GameConst::$maxChiefTurn);
|
||||
}
|
||||
|
||||
function pullNationCommand(int $nationID, int $officerLevel, int $turnCnt=1){
|
||||
if($nationID == 0){
|
||||
return;
|
||||
}
|
||||
if($officerLevel < 5){
|
||||
return;
|
||||
}
|
||||
if($turnCnt == 0){
|
||||
return;
|
||||
}
|
||||
if($turnCnt < 0){
|
||||
pushNationCommand($nationID, $officerLevel, -$turnCnt);
|
||||
return;
|
||||
}
|
||||
if($turnCnt >= GameConst::$maxChiefTurn){
|
||||
return;
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$db->update('nation_turn', [
|
||||
'turn_idx'=>$db->sqleval('turn_idx + %i', GameConst::$maxChiefTurn),
|
||||
'action'=>'휴식',
|
||||
'arg'=>'{}',
|
||||
'brief'=>'휴식',
|
||||
], 'nation_id=%i AND officer_level=%i AND turn_idx < %i', $nationID, $officerLevel, $turnCnt);
|
||||
$db->update('nation_turn', [
|
||||
'turn_idx'=>$db->sqleval('turn_idx - %i', $turnCnt)
|
||||
], 'nation_id=%i AND officer_level=%i ORDER BY turn_idx ASC', $nationID, $officerLevel);
|
||||
}
|
||||
|
||||
function _setGeneralCommand(GeneralCommand $command, array $turnList):void {
|
||||
if(!$turnList){
|
||||
return;
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$generalID = $command->getGeneral()->getID();
|
||||
$commandName = $command->getRawClassName();
|
||||
$arg = $command->getArg();
|
||||
$brief = $command->getBrief();
|
||||
|
||||
$db->update('general_turn', [
|
||||
'action'=>$commandName,
|
||||
'arg'=>Json::encode($arg, JSON::EMPTY_ARRAY_IS_DICT),
|
||||
'brief'=>$brief
|
||||
], 'general_id = %i AND turn_idx IN %li', $generalID, $turnList);
|
||||
}
|
||||
|
||||
function _setNationCommand(NationCommand $command, array $turnList):void {
|
||||
if(!$turnList){
|
||||
return;
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$nationID = $command->getNationID();
|
||||
$officerLevel = $command->getOfficerLevel();
|
||||
$commandName = $command->getRawClassName();
|
||||
$arg = $command->getArg();
|
||||
$brief = $command->getBrief();
|
||||
|
||||
$db->update('nation_turn', [
|
||||
'action'=>$commandName,
|
||||
'arg'=>Json::encode($arg, JSON::EMPTY_ARRAY_IS_DICT),
|
||||
'brief'=>$brief
|
||||
], 'nation_id = %i AND officer_level = %i AND turn_idx IN %li', $nationID, $officerLevel, $turnList);
|
||||
}
|
||||
|
||||
function sanitizeArg(?array $args):?array{
|
||||
if($args === null){
|
||||
return $args;
|
||||
}
|
||||
|
||||
$result = [];
|
||||
foreach($args as $key=>$value){
|
||||
if(is_array($value)){
|
||||
$result[$key] = sanitizeArg($value);
|
||||
}
|
||||
else if(is_string($value)){
|
||||
$result[$key] = StringUtil::neutralize(StringUtil::removeSpecialCharacter($value));
|
||||
}
|
||||
else{
|
||||
$result[$key] = $value;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function checkCommandArg(?array $arg):?string{
|
||||
if($arg === null){
|
||||
return null;
|
||||
}
|
||||
$defaultCheck = [
|
||||
/*'string'=>[
|
||||
'nationName', 'optionText', 'itemType', 'nationType'
|
||||
],*/
|
||||
'integer'=>[
|
||||
'crewType', 'destGeneralID', 'destCityID', 'destNationID',
|
||||
'amount', 'colorType',
|
||||
'srcArmType', 'destArmType', //숙련전환 전용
|
||||
],
|
||||
'boolean'=>[
|
||||
'isGold', 'buyRice',
|
||||
],
|
||||
'between'=>[
|
||||
['month', [1, 12]]
|
||||
],
|
||||
'min'=>[
|
||||
['year', 0],
|
||||
['destGeneralID', 1],
|
||||
['destCityID', 1],
|
||||
['destNationID', 1],
|
||||
['amount', 1],
|
||||
['crewType', 0]
|
||||
],
|
||||
'integerArray'=>[
|
||||
'destNationIDList', 'destGeneralIDList', 'amountList'
|
||||
],
|
||||
'stringWidthBetween'=>[
|
||||
['nationName', 1, 18]
|
||||
]
|
||||
];
|
||||
$v = new Validator($arg);
|
||||
$v->rules($defaultCheck);
|
||||
if (!$v->validate()){
|
||||
return $v->errorStr();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function setGeneralCommand(int $generalID, array $rawTurnList, string $command, ?array $arg = null):array{
|
||||
|
||||
$turnList = [];
|
||||
foreach($rawTurnList as $turnIdx){
|
||||
if(!is_int($turnIdx) || $turnIdx < -3 || $turnIdx >= GameConst::$maxTurn){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'올바른 턴이 아닙니다. : '.$turnIdx,
|
||||
'test'=>'turnIdx',
|
||||
'target'=>$turnIdx,
|
||||
];
|
||||
}
|
||||
if($turnIdx >= 0){
|
||||
$turnList[$turnIdx] = true;
|
||||
}
|
||||
else if($turnIdx == -1){
|
||||
//홀수, 0부터 맞다.
|
||||
foreach(Util::range(0, GameConst::$maxTurn, 2) as $subIdx){
|
||||
$turnList[$subIdx] = true;
|
||||
}
|
||||
}
|
||||
else if($turnIdx == -2){
|
||||
//짝수, 1부터 맞다.
|
||||
foreach(Util::range(1, GameConst::$maxTurn, 2) as $subIdx){
|
||||
$turnList[$subIdx] = true;
|
||||
}
|
||||
}
|
||||
else if($turnIdx == -3){
|
||||
//모두
|
||||
foreach(Util::range(GameConst::$maxTurn) as $subIdx){
|
||||
$turnList[$subIdx] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
$turnList = array_keys($turnList);
|
||||
|
||||
$arg = sanitizeArg($arg);
|
||||
$argBasicTestResult = checkCommandArg($arg);
|
||||
if($argBasicTestResult !== null){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'턴이 입력되지 않았습니다.',
|
||||
'test'=>'checkCommandArg',
|
||||
'target'=>'arg'
|
||||
];
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$env = $gameStor->getAll();
|
||||
$general = General::createGeneralObjFromDB($generalID);
|
||||
|
||||
try{
|
||||
$commandObj = buildGeneralCommandClass($command, $general, $env, $arg);
|
||||
}
|
||||
catch (\InvalidArgumentException $e){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>$e->getMessage(),
|
||||
'test'=>'build',
|
||||
'target'=>'arg'
|
||||
];
|
||||
}
|
||||
catch (\Exception $e){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>$e->getCode().$e->getMessage(),
|
||||
'test'=>'build',
|
||||
'target'=>'arg'
|
||||
];
|
||||
}
|
||||
|
||||
if(!$commandObj->isArgValid()){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'올바르지 않은 argument',
|
||||
'test'=>'isArgValid',
|
||||
'target'=>'arg'
|
||||
];
|
||||
}
|
||||
|
||||
if(!$commandObj->hasPermissionToReserve()){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'예약 불가능한 커맨드 :'.$commandObj->testPermissionToReserve(),
|
||||
'test'=>'hasPermissionToReserve',
|
||||
'target'=>'command'
|
||||
];
|
||||
}
|
||||
|
||||
_setGeneralCommand($commandObj, $turnList);
|
||||
return [
|
||||
'result'=>true,
|
||||
'reason'=>'success'
|
||||
];
|
||||
}
|
||||
|
||||
function setNationCommand(int $generalID, array $turnList, string $command, ?array $arg = null):array{
|
||||
$turnList = array_unique($turnList);
|
||||
foreach($turnList as $turnIdx){
|
||||
if(!is_int($turnIdx) || $turnIdx < 0 || $turnIdx >= GameConst::$maxChiefTurn){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'올바른 턴이 아닙니다. : '.$turnIdx,
|
||||
'test'=>'turnIdx',
|
||||
'target'=>$turnIdx,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$arg = sanitizeArg($arg);
|
||||
$argBasicTestResult = checkCommandArg($arg);
|
||||
if($argBasicTestResult !== null){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'턴이 입력되지 않았습니다.',
|
||||
'test'=>'checkCommandArg',
|
||||
'target'=>'arg'
|
||||
];
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$env = $gameStor->getAll();
|
||||
$general = General::createGeneralObjFromDB($generalID);
|
||||
|
||||
if($general->getVar('officer_level') < 5){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'수뇌가 아닙니다'
|
||||
];
|
||||
}
|
||||
|
||||
try{
|
||||
$commandObj = buildNationCommandClass($command, $general, $env, $general->getLastTurn(), $arg);
|
||||
}
|
||||
catch (\InvalidArgumentException $e){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>$e->getMessage(),
|
||||
'test'=>'build',
|
||||
'target'=>'arg'
|
||||
];
|
||||
}
|
||||
catch (\Exception $e){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>$e->getCode().$e->getMessage(),
|
||||
'test'=>'build',
|
||||
'target'=>'arg'
|
||||
];
|
||||
}
|
||||
|
||||
if(!$commandObj->isArgValid()){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'올바르지 않은 argument',
|
||||
'test'=>'isArgValid',
|
||||
'target'=>'arg'
|
||||
];
|
||||
}
|
||||
|
||||
if(!$commandObj->hasPermissionToReserve()){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'예약 불가능한 커맨드 :'.$commandObj->testPermissionToReserve(),
|
||||
'test'=>'hasPermissionToReserve',
|
||||
'target'=>'command'
|
||||
];
|
||||
}
|
||||
|
||||
_setNationCommand($commandObj, $turnList);
|
||||
return [
|
||||
'result'=>true,
|
||||
'arg_test'=>true,
|
||||
'reason'=>'success'
|
||||
];
|
||||
}
|
||||
+104
-104
@@ -1,104 +1,104 @@
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
abstract class BaseWarUnitTrigger extends ObjectTrigger{
|
||||
/** @var WarUnit $object */
|
||||
|
||||
const TYPE_NONE = 0;
|
||||
const TYPE_ITEM = 1;
|
||||
const TYPE_CONSUMABLE_ITEM = 1 | 2;
|
||||
|
||||
protected $raiseType = self::TYPE_NONE;
|
||||
|
||||
public function __construct(WarUnit $unit, int $raiseType = 0){
|
||||
$this->object = $unit;
|
||||
$this->raiseType = $raiseType;
|
||||
}
|
||||
|
||||
public function getUniqueID():string{
|
||||
$priority = $this->priority;
|
||||
$fqn = static::class;
|
||||
if($this->object === null){
|
||||
$objID = '';
|
||||
}
|
||||
else{
|
||||
$objID = spl_object_id($this->object);
|
||||
}
|
||||
return "{$priority}_{$fqn}_{$objID}_{$this->raiseType}";
|
||||
}
|
||||
|
||||
public function action(?array $env=null, $arg=null):?array{
|
||||
if($env === null){
|
||||
$env = [];
|
||||
}
|
||||
if(!key_exists('e_attacker', $env)){
|
||||
$env['e_attacker'] = [];
|
||||
}
|
||||
if(!key_exists('e_defender', $env)){
|
||||
$env['e_defender'] = [];
|
||||
}
|
||||
|
||||
if($env['stopNextAction']??false){
|
||||
return $env;
|
||||
}
|
||||
|
||||
/** @var WarUnitGeneral $attacker */
|
||||
/** @var WarUnit $defender */
|
||||
[$attacker, $defender] = $arg;
|
||||
|
||||
/** @var WarUnit $self */
|
||||
$self = $this->object;
|
||||
$isAttacker = $self->isAttacker();
|
||||
$oppose = $isAttacker?$defender:$attacker;
|
||||
|
||||
$selfEnv = $isAttacker?$env['e_attacker']:$env['e_defender'];
|
||||
$opposeEnv = $isAttacker?$env['e_defender']:$env['e_attacker'];
|
||||
|
||||
$callNextAction = $this->actionWar($self, $oppose, $selfEnv, $opposeEnv);
|
||||
|
||||
$env['e_attacker'] = $isAttacker?$selfEnv:$opposeEnv;
|
||||
$env['e_defender'] = $isAttacker?$opposeEnv:$selfEnv;
|
||||
|
||||
if(!$callNextAction){
|
||||
$env['stopNextAction'] = true;
|
||||
}
|
||||
|
||||
return $env;
|
||||
}
|
||||
|
||||
abstract protected function actionWar(WarUnit $self, WarUnit $oppose, array &$selfEnv, array &$opposeEnv):bool;
|
||||
|
||||
public function processConsumableItem():bool{
|
||||
if(!($this->raiseType & static::TYPE_ITEM)){
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var WarUnit $self */
|
||||
$self = $this->object;
|
||||
|
||||
if($self->hasActivatedSkill('아이템사용')){
|
||||
return false;
|
||||
}
|
||||
|
||||
$self->activateSkill('아이템사용');
|
||||
$item = $self->getGeneral()->getItem();
|
||||
$itemName = $item->getName();
|
||||
$itemRawName = $item->getRawName();
|
||||
$self->activateSkill($itemName);
|
||||
|
||||
if (!($this->raiseType & static::TYPE_CONSUMABLE_ITEM)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if($self->hasActivatedSkill('아이템소모')){
|
||||
return false;
|
||||
}
|
||||
|
||||
$self->activateSkill('아이템소모');
|
||||
$josaUl = JosaUtil::pick($itemRawName, '을');
|
||||
$self->getLogger()->pushGeneralActionLog("<C>{$itemName}</>{$josaUl} 사용!", ActionLogger::PLAIN);
|
||||
$self->getGeneral()->deleteItem();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
abstract class BaseWarUnitTrigger extends ObjectTrigger{
|
||||
/** @var WarUnit $object */
|
||||
|
||||
const TYPE_NONE = 0;
|
||||
const TYPE_ITEM = 1;
|
||||
const TYPE_CONSUMABLE_ITEM = 1 | 2;
|
||||
|
||||
protected $raiseType = self::TYPE_NONE;
|
||||
|
||||
public function __construct(WarUnit $unit, int $raiseType = 0){
|
||||
$this->object = $unit;
|
||||
$this->raiseType = $raiseType;
|
||||
}
|
||||
|
||||
public function getUniqueID():string{
|
||||
$priority = $this->priority;
|
||||
$fqn = static::class;
|
||||
if($this->object === null){
|
||||
$objID = '';
|
||||
}
|
||||
else{
|
||||
$objID = spl_object_id($this->object);
|
||||
}
|
||||
return "{$priority}_{$fqn}_{$objID}_{$this->raiseType}";
|
||||
}
|
||||
|
||||
public function action(?array $env=null, $arg=null):?array{
|
||||
if($env === null){
|
||||
$env = [];
|
||||
}
|
||||
if(!key_exists('e_attacker', $env)){
|
||||
$env['e_attacker'] = [];
|
||||
}
|
||||
if(!key_exists('e_defender', $env)){
|
||||
$env['e_defender'] = [];
|
||||
}
|
||||
|
||||
if($env['stopNextAction']??false){
|
||||
return $env;
|
||||
}
|
||||
|
||||
/** @var WarUnitGeneral $attacker */
|
||||
/** @var WarUnit $defender */
|
||||
[$attacker, $defender] = $arg;
|
||||
|
||||
/** @var WarUnit $self */
|
||||
$self = $this->object;
|
||||
$isAttacker = $self->isAttacker();
|
||||
$oppose = $isAttacker?$defender:$attacker;
|
||||
|
||||
$selfEnv = $isAttacker?$env['e_attacker']:$env['e_defender'];
|
||||
$opposeEnv = $isAttacker?$env['e_defender']:$env['e_attacker'];
|
||||
|
||||
$callNextAction = $this->actionWar($self, $oppose, $selfEnv, $opposeEnv);
|
||||
|
||||
$env['e_attacker'] = $isAttacker?$selfEnv:$opposeEnv;
|
||||
$env['e_defender'] = $isAttacker?$opposeEnv:$selfEnv;
|
||||
|
||||
if(!$callNextAction){
|
||||
$env['stopNextAction'] = true;
|
||||
}
|
||||
|
||||
return $env;
|
||||
}
|
||||
|
||||
abstract protected function actionWar(WarUnit $self, WarUnit $oppose, array &$selfEnv, array &$opposeEnv):bool;
|
||||
|
||||
public function processConsumableItem():bool{
|
||||
if(!($this->raiseType & static::TYPE_ITEM)){
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var WarUnit $self */
|
||||
$self = $this->object;
|
||||
|
||||
if($self->hasActivatedSkill('아이템사용')){
|
||||
return false;
|
||||
}
|
||||
|
||||
$self->activateSkill('아이템사용');
|
||||
$item = $self->getGeneral()->getItem();
|
||||
$itemName = $item->getName();
|
||||
$itemRawName = $item->getRawName();
|
||||
$self->activateSkill($itemName);
|
||||
|
||||
if ($this->raiseType != static::TYPE_CONSUMABLE_ITEM) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if($self->hasActivatedSkill('아이템소모')){
|
||||
return false;
|
||||
}
|
||||
|
||||
$self->activateSkill('아이템소모');
|
||||
$josaUl = JosaUtil::pick($itemRawName, '을');
|
||||
$self->getLogger()->pushGeneralActionLog("<C>{$itemName}</>{$josaUl} 사용!", ActionLogger::PLAIN);
|
||||
$self->getGeneral()->deleteItem();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,137 +1,137 @@
|
||||
<?php
|
||||
namespace sammo\Command\General;
|
||||
|
||||
use \sammo\{
|
||||
DB, Util, JosaUtil,
|
||||
General,
|
||||
ActionLogger,
|
||||
LastTurn,
|
||||
Command, GameConst
|
||||
};
|
||||
|
||||
use function sammo\{
|
||||
TechLimit,
|
||||
getDomesticExpLevelBonus,
|
||||
CriticalRatioDomestic,
|
||||
CriticalScoreEx,
|
||||
tryUniqueItemLottery
|
||||
};
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
|
||||
|
||||
class che_기술연구 extends che_상업투자{
|
||||
static protected $statKey = 'intel';
|
||||
static protected $actionKey = '기술';
|
||||
static protected $actionName = '기술 연구';
|
||||
|
||||
protected function argTest():bool{
|
||||
$this->arg = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
|
||||
$general = $this->generalObj;
|
||||
|
||||
$this->setCity();
|
||||
$this->setNation(['tech']);
|
||||
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$this->fullConditionConstraints=[
|
||||
ConstraintHelper::NotBeNeutral(),
|
||||
ConstraintHelper::NotWanderingNation(),
|
||||
ConstraintHelper::OccupiedCity(),
|
||||
ConstraintHelper::SuppliedCity(),
|
||||
ConstraintHelper::ReqGeneralGold($reqGold),
|
||||
ConstraintHelper::ReqGeneralRice($reqRice)
|
||||
];
|
||||
|
||||
$this->reqGold = $reqGold;
|
||||
}
|
||||
|
||||
public function run():bool{
|
||||
if(!$this->hasFullConditionMet()){
|
||||
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$general = $this->generalObj;
|
||||
|
||||
$trust = Util::valueFit($this->city['trust'], 50);
|
||||
|
||||
$score = Util::valueFit($this->calcBaseScore(), 1);
|
||||
|
||||
['success'=>$successRatio, 'fail'=>$failRatio] = CriticalRatioDomestic($general, static::$statKey);
|
||||
if($trust < 80){
|
||||
$successRatio *= $trust / 80;
|
||||
}
|
||||
$successRatio = $general->onCalcDomestic(static::$cityKey, 'success', $successRatio);
|
||||
$failRatio = $general->onCalcDomestic(static::$cityKey, 'fail', $failRatio);
|
||||
|
||||
$successRatio = Util::valueFit($successRatio, 0, 1);
|
||||
$failRatio = Util::valueFit($failRatio, 0, 1 - $successRatio);
|
||||
$normalRatio = 1 - $failRatio - $successRatio;
|
||||
|
||||
$pick = Util::choiceRandomUsingWeight([
|
||||
'fail'=>$failRatio,
|
||||
'success'=>$successRatio,
|
||||
'normal'=>$normalRatio
|
||||
]);
|
||||
|
||||
$logger = $general->getLogger();
|
||||
|
||||
$date = $general->getTurnTime($general::TURNTIME_HM);
|
||||
|
||||
$score *= CriticalScoreEx($pick);
|
||||
$score = Util::round($score);
|
||||
|
||||
$exp = $score * 0.7;
|
||||
$ded = $score * 1.0;
|
||||
|
||||
$scoreText = number_format($score, 0);
|
||||
|
||||
$josaUl = JosaUtil::pick(static::$actionName, '을');
|
||||
if($pick == 'fail'){
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <span class='ev_failed'>실패</span>하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
|
||||
}
|
||||
else if($pick == 'success'){
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <S>성공</>하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
|
||||
}
|
||||
else{
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} 하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
|
||||
}
|
||||
|
||||
if(TechLimit($this->env['startyear'], $this->env['year'], $this->nation['tech'])){
|
||||
$score /= 4;
|
||||
}
|
||||
|
||||
$genCount = Util::valueFit(
|
||||
$db->queryFirstField('SELECT gennum FROM nation WHERE nation=%i', $general->getVar('nation')),
|
||||
GameConst::$initialNationGenLimit
|
||||
);
|
||||
|
||||
$nationUpdated = [
|
||||
'tech' => $this->nation['tech'] + $score/$genCount
|
||||
];
|
||||
$db->update('nation', $nationUpdated, 'nation=%i', $general->getVar('nation'));
|
||||
|
||||
$general->increaseVarWithLimit('gold', -$this->reqGold, 0);
|
||||
$general->addExperience($exp);
|
||||
$general->addDedication($ded);
|
||||
$general->increaseVar(static::$statKey.'_exp', 1);
|
||||
|
||||
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
tryUniqueItemLottery($general);
|
||||
$general->applyDB($db);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
<?php
|
||||
namespace sammo\Command\General;
|
||||
|
||||
use \sammo\{
|
||||
DB, Util, JosaUtil,
|
||||
General,
|
||||
ActionLogger,
|
||||
LastTurn,
|
||||
Command, GameConst
|
||||
};
|
||||
|
||||
use function sammo\{
|
||||
TechLimit,
|
||||
getDomesticExpLevelBonus,
|
||||
CriticalRatioDomestic,
|
||||
CriticalScoreEx,
|
||||
tryUniqueItemLottery
|
||||
};
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
|
||||
|
||||
class che_기술연구 extends che_상업투자{
|
||||
static protected $statKey = 'intel';
|
||||
static protected $actionKey = '기술';
|
||||
static protected $actionName = '기술 연구';
|
||||
|
||||
protected function argTest():bool{
|
||||
$this->arg = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
|
||||
$general = $this->generalObj;
|
||||
|
||||
$this->setCity();
|
||||
$this->setNation(['tech']);
|
||||
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$this->fullConditionConstraints=[
|
||||
ConstraintHelper::NotBeNeutral(),
|
||||
ConstraintHelper::NotWanderingNation(),
|
||||
ConstraintHelper::OccupiedCity(),
|
||||
ConstraintHelper::SuppliedCity(),
|
||||
ConstraintHelper::ReqGeneralGold($reqGold),
|
||||
ConstraintHelper::ReqGeneralRice($reqRice)
|
||||
];
|
||||
|
||||
$this->reqGold = $reqGold;
|
||||
}
|
||||
|
||||
public function run():bool{
|
||||
if(!$this->hasFullConditionMet()){
|
||||
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$general = $this->generalObj;
|
||||
|
||||
$trust = Util::valueFit($this->city['trust'], 50);
|
||||
|
||||
$score = Util::valueFit($this->calcBaseScore(), 1);
|
||||
|
||||
['success'=>$successRatio, 'fail'=>$failRatio] = CriticalRatioDomestic($general, static::$statKey);
|
||||
if($trust < 80){
|
||||
$successRatio *= $trust / 80;
|
||||
}
|
||||
$successRatio = $general->onCalcDomestic(static::$actionKey, 'success', $successRatio);
|
||||
$failRatio = $general->onCalcDomestic(static::$actionKey, 'fail', $failRatio);
|
||||
|
||||
$successRatio = Util::valueFit($successRatio, 0, 1);
|
||||
$failRatio = Util::valueFit($failRatio, 0, 1 - $successRatio);
|
||||
$normalRatio = 1 - $failRatio - $successRatio;
|
||||
|
||||
$pick = Util::choiceRandomUsingWeight([
|
||||
'fail'=>$failRatio,
|
||||
'success'=>$successRatio,
|
||||
'normal'=>$normalRatio
|
||||
]);
|
||||
|
||||
$logger = $general->getLogger();
|
||||
|
||||
$date = $general->getTurnTime($general::TURNTIME_HM);
|
||||
|
||||
$score *= CriticalScoreEx($pick);
|
||||
$score = Util::round($score);
|
||||
|
||||
$exp = $score * 0.7;
|
||||
$ded = $score * 1.0;
|
||||
|
||||
$scoreText = number_format($score, 0);
|
||||
|
||||
$josaUl = JosaUtil::pick(static::$actionName, '을');
|
||||
if($pick == 'fail'){
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <span class='ev_failed'>실패</span>하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
|
||||
}
|
||||
else if($pick == 'success'){
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <S>성공</>하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
|
||||
}
|
||||
else{
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} 하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
|
||||
}
|
||||
|
||||
if(TechLimit($this->env['startyear'], $this->env['year'], $this->nation['tech'])){
|
||||
$score /= 4;
|
||||
}
|
||||
|
||||
$genCount = Util::valueFit(
|
||||
$db->queryFirstField('SELECT gennum FROM nation WHERE nation=%i', $general->getVar('nation')),
|
||||
GameConst::$initialNationGenLimit
|
||||
);
|
||||
|
||||
$nationUpdated = [
|
||||
'tech' => $this->nation['tech'] + $score/$genCount
|
||||
];
|
||||
$db->update('nation', $nationUpdated, 'nation=%i', $general->getVar('nation'));
|
||||
|
||||
$general->increaseVarWithLimit('gold', -$this->reqGold, 0);
|
||||
$general->addExperience($exp);
|
||||
$general->addDedication($ded);
|
||||
$general->increaseVar(static::$statKey.'_exp', 1);
|
||||
|
||||
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
tryUniqueItemLottery($general);
|
||||
$general->applyDB($db);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,208 +1,208 @@
|
||||
<?php
|
||||
namespace sammo\Command\General;
|
||||
|
||||
use \sammo\{
|
||||
DB, Util, JosaUtil,
|
||||
General,
|
||||
ActionLogger,
|
||||
GameConst,
|
||||
LastTurn,
|
||||
GameUnitConst,
|
||||
Command
|
||||
};
|
||||
|
||||
use function \sammo\{
|
||||
getDomesticExpLevelBonus,
|
||||
CriticalRatioDomestic,
|
||||
CriticalScoreEx,
|
||||
tryUniqueItemLottery
|
||||
};
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
|
||||
|
||||
class che_상업투자 extends Command\GeneralCommand{
|
||||
static protected $cityKey = 'comm';
|
||||
static protected $statKey = 'intel';
|
||||
static protected $actionKey = '상업';
|
||||
static protected $actionName = '상업 투자';
|
||||
static protected $debuffFront = 0.5;
|
||||
|
||||
protected $reqGold;
|
||||
|
||||
protected function argTest():bool{
|
||||
$this->arg = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function init(){
|
||||
|
||||
$general = $this->generalObj;
|
||||
|
||||
$this->setCity();
|
||||
$this->setNation();
|
||||
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$this->fullConditionConstraints=[
|
||||
ConstraintHelper::NotBeNeutral(),
|
||||
ConstraintHelper::NotWanderingNation(),
|
||||
ConstraintHelper::OccupiedCity(),
|
||||
ConstraintHelper::SuppliedCity(),
|
||||
ConstraintHelper::ReqGeneralGold($reqGold),
|
||||
ConstraintHelper::ReqGeneralRice($reqRice),
|
||||
ConstraintHelper::RemainCityCapacity(static::$cityKey, static::$actionName)
|
||||
];
|
||||
|
||||
$this->reqGold = $reqGold;
|
||||
}
|
||||
|
||||
public function getCommandDetailTitle():string{
|
||||
$name = $this->getName();
|
||||
$statTypeBase = [
|
||||
'leadership'=>'통솔경험',
|
||||
'strength'=>'무력경험',
|
||||
'intel'=>'지력경험',
|
||||
];
|
||||
$statType = $statTypeBase[static::$statKey];
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$title = "{$name}({$statType}";
|
||||
if($reqGold > 0){
|
||||
$title .= ", 자금{$reqGold}";
|
||||
}
|
||||
if($reqRice > 0){
|
||||
$title .= ", 군량{$reqRice}";
|
||||
}
|
||||
$title .= ')';
|
||||
return $title;
|
||||
}
|
||||
|
||||
public function getCost():array{
|
||||
$develCost = $this->env['develcost'];
|
||||
$reqGold = Util::round($this->generalObj->onCalcDomestic(static::$actionKey, 'cost', $develCost));
|
||||
$reqRice = 0;
|
||||
|
||||
return [$reqGold, $reqRice];
|
||||
}
|
||||
|
||||
|
||||
public function getCompensationStyle():?int{
|
||||
return $this->generalObj->onCalcDomestic(static::$actionKey, 'score', 100)<=>100;
|
||||
}
|
||||
|
||||
public function getPreReqTurn():int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getPostReqTurn():int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function calcBaseScore():float{
|
||||
$trust = Util::valueFit($this->city['trust'], 50);
|
||||
$general = $this->generalObj;
|
||||
|
||||
if(static::$statKey == 'intel'){
|
||||
$score = $general->getIntel(true, true, true, false);
|
||||
}
|
||||
else if(static::$statKey == 'strength'){
|
||||
$score = $general->getStrength(true, true, true, false);
|
||||
}
|
||||
else if(static::$statKey == 'leadership'){
|
||||
$score = $general->getLeadership(true, true, true, false);
|
||||
}
|
||||
else{
|
||||
throw new \sammo\MustNotBeReachedException();
|
||||
}
|
||||
|
||||
$score *= $trust / 100;
|
||||
$score *= getDomesticExpLevelBonus($general->getVar('explevel'));
|
||||
$score *= Util::randRange(0.8, 1.2);
|
||||
$score = $general->onCalcDomestic(static::$actionKey, 'score', $score);
|
||||
|
||||
return $score;
|
||||
}
|
||||
|
||||
public function run():bool{
|
||||
if(!$this->hasFullConditionMet()){
|
||||
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$general = $this->generalObj;
|
||||
|
||||
$trust = Util::valueFit($this->city['trust'], 50);
|
||||
|
||||
$score = Util::valueFit($this->calcBaseScore(), 1);
|
||||
|
||||
['success'=>$successRatio, 'fail'=>$failRatio] = CriticalRatioDomestic($general, static::$statKey);
|
||||
if($trust < 80){
|
||||
$successRatio *= $trust / 80;
|
||||
}
|
||||
$successRatio = $general->onCalcDomestic(static::$cityKey, 'success', $successRatio);
|
||||
$failRatio = $general->onCalcDomestic(static::$cityKey, 'fail', $failRatio);
|
||||
|
||||
$successRatio = Util::valueFit($successRatio, 0, 1);
|
||||
$failRatio = Util::valueFit($failRatio, 0, 1 - $successRatio);
|
||||
$normalRatio = 1 - $failRatio - $successRatio;
|
||||
|
||||
$pick = Util::choiceRandomUsingWeight([
|
||||
'fail'=>$failRatio,
|
||||
'success'=>$successRatio,
|
||||
'normal'=>$normalRatio
|
||||
]);
|
||||
|
||||
$logger = $general->getLogger();
|
||||
|
||||
$date = $general->getTurnTime($general::TURNTIME_HM);
|
||||
|
||||
$score *= CriticalScoreEx($pick);
|
||||
$score = Util::round($score);
|
||||
|
||||
$exp = $score * 0.7;
|
||||
$ded = $score * 1.0;
|
||||
|
||||
$scoreText = number_format($score, 0);
|
||||
|
||||
$josaUl = JosaUtil::pick(static::$actionName, '을');
|
||||
if($pick == 'fail'){
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <span class='ev_failed'>실패</span>하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
|
||||
}
|
||||
else if($pick == 'success'){
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <S>성공</>하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
|
||||
}
|
||||
else{
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} 하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
|
||||
}
|
||||
|
||||
if(in_array($this->city['front'], [1, 3]) && $this->nation['capital'] != $this->city['city']){
|
||||
$score *= static::$debuffFront;
|
||||
}
|
||||
|
||||
//NOTE: 내정량 상승시 초과 가능?
|
||||
$cityUpdated = [
|
||||
static::$cityKey => Util::valueFit(
|
||||
$this->city[static::$cityKey] + $score,
|
||||
0,
|
||||
$this->city[static::$cityKey.'_max']
|
||||
)
|
||||
];
|
||||
$db->update('city', $cityUpdated, 'city=%i', $general->getVar('city'));
|
||||
|
||||
$general->increaseVarWithLimit('gold', -$this->reqGold, 0);
|
||||
$general->addExperience($exp);
|
||||
$general->addDedication($ded);
|
||||
$general->increaseVar(static::$statKey.'_exp', 1);
|
||||
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
tryUniqueItemLottery($general);
|
||||
$general->applyDB($db);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
<?php
|
||||
namespace sammo\Command\General;
|
||||
|
||||
use \sammo\{
|
||||
DB, Util, JosaUtil,
|
||||
General,
|
||||
ActionLogger,
|
||||
GameConst,
|
||||
LastTurn,
|
||||
GameUnitConst,
|
||||
Command
|
||||
};
|
||||
|
||||
use function \sammo\{
|
||||
getDomesticExpLevelBonus,
|
||||
CriticalRatioDomestic,
|
||||
CriticalScoreEx,
|
||||
tryUniqueItemLottery
|
||||
};
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
|
||||
|
||||
class che_상업투자 extends Command\GeneralCommand{
|
||||
static protected $cityKey = 'comm';
|
||||
static protected $statKey = 'intel';
|
||||
static protected $actionKey = '상업';
|
||||
static protected $actionName = '상업 투자';
|
||||
static protected $debuffFront = 0.5;
|
||||
|
||||
protected $reqGold;
|
||||
|
||||
protected function argTest():bool{
|
||||
$this->arg = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function init(){
|
||||
|
||||
$general = $this->generalObj;
|
||||
|
||||
$this->setCity();
|
||||
$this->setNation();
|
||||
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$this->fullConditionConstraints=[
|
||||
ConstraintHelper::NotBeNeutral(),
|
||||
ConstraintHelper::NotWanderingNation(),
|
||||
ConstraintHelper::OccupiedCity(),
|
||||
ConstraintHelper::SuppliedCity(),
|
||||
ConstraintHelper::ReqGeneralGold($reqGold),
|
||||
ConstraintHelper::ReqGeneralRice($reqRice),
|
||||
ConstraintHelper::RemainCityCapacity(static::$cityKey, static::$actionName)
|
||||
];
|
||||
|
||||
$this->reqGold = $reqGold;
|
||||
}
|
||||
|
||||
public function getCommandDetailTitle():string{
|
||||
$name = $this->getName();
|
||||
$statTypeBase = [
|
||||
'leadership'=>'통솔경험',
|
||||
'strength'=>'무력경험',
|
||||
'intel'=>'지력경험',
|
||||
];
|
||||
$statType = $statTypeBase[static::$statKey];
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$title = "{$name}({$statType}";
|
||||
if($reqGold > 0){
|
||||
$title .= ", 자금{$reqGold}";
|
||||
}
|
||||
if($reqRice > 0){
|
||||
$title .= ", 군량{$reqRice}";
|
||||
}
|
||||
$title .= ')';
|
||||
return $title;
|
||||
}
|
||||
|
||||
public function getCost():array{
|
||||
$develCost = $this->env['develcost'];
|
||||
$reqGold = Util::round($this->generalObj->onCalcDomestic(static::$actionKey, 'cost', $develCost));
|
||||
$reqRice = 0;
|
||||
|
||||
return [$reqGold, $reqRice];
|
||||
}
|
||||
|
||||
|
||||
public function getCompensationStyle():?int{
|
||||
return $this->generalObj->onCalcDomestic(static::$actionKey, 'score', 100)<=>100;
|
||||
}
|
||||
|
||||
public function getPreReqTurn():int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getPostReqTurn():int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function calcBaseScore():float{
|
||||
$trust = Util::valueFit($this->city['trust'], 50);
|
||||
$general = $this->generalObj;
|
||||
|
||||
if(static::$statKey == 'intel'){
|
||||
$score = $general->getIntel(true, true, true, false);
|
||||
}
|
||||
else if(static::$statKey == 'strength'){
|
||||
$score = $general->getStrength(true, true, true, false);
|
||||
}
|
||||
else if(static::$statKey == 'leadership'){
|
||||
$score = $general->getLeadership(true, true, true, false);
|
||||
}
|
||||
else{
|
||||
throw new \sammo\MustNotBeReachedException();
|
||||
}
|
||||
|
||||
$score *= $trust / 100;
|
||||
$score *= getDomesticExpLevelBonus($general->getVar('explevel'));
|
||||
$score *= Util::randRange(0.8, 1.2);
|
||||
$score = $general->onCalcDomestic(static::$actionKey, 'score', $score);
|
||||
|
||||
return $score;
|
||||
}
|
||||
|
||||
public function run():bool{
|
||||
if(!$this->hasFullConditionMet()){
|
||||
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$general = $this->generalObj;
|
||||
|
||||
$trust = Util::valueFit($this->city['trust'], 50);
|
||||
|
||||
$score = Util::valueFit($this->calcBaseScore(), 1);
|
||||
|
||||
['success'=>$successRatio, 'fail'=>$failRatio] = CriticalRatioDomestic($general, static::$statKey);
|
||||
if($trust < 80){
|
||||
$successRatio *= $trust / 80;
|
||||
}
|
||||
$successRatio = $general->onCalcDomestic(static::$actionKey, 'success', $successRatio);
|
||||
$failRatio = $general->onCalcDomestic(static::$actionKey, 'fail', $failRatio);
|
||||
|
||||
$successRatio = Util::valueFit($successRatio, 0, 1);
|
||||
$failRatio = Util::valueFit($failRatio, 0, 1 - $successRatio);
|
||||
$normalRatio = 1 - $failRatio - $successRatio;
|
||||
|
||||
$pick = Util::choiceRandomUsingWeight([
|
||||
'fail'=>$failRatio,
|
||||
'success'=>$successRatio,
|
||||
'normal'=>$normalRatio
|
||||
]);
|
||||
|
||||
$logger = $general->getLogger();
|
||||
|
||||
$date = $general->getTurnTime($general::TURNTIME_HM);
|
||||
|
||||
$score *= CriticalScoreEx($pick);
|
||||
$score = Util::round($score);
|
||||
|
||||
$exp = $score * 0.7;
|
||||
$ded = $score * 1.0;
|
||||
|
||||
$scoreText = number_format($score, 0);
|
||||
|
||||
$josaUl = JosaUtil::pick(static::$actionName, '을');
|
||||
if($pick == 'fail'){
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <span class='ev_failed'>실패</span>하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
|
||||
}
|
||||
else if($pick == 'success'){
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <S>성공</>하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
|
||||
}
|
||||
else{
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} 하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
|
||||
}
|
||||
|
||||
if(in_array($this->city['front'], [1, 3]) && $this->nation['capital'] != $this->city['city']){
|
||||
$score *= static::$debuffFront;
|
||||
}
|
||||
|
||||
//NOTE: 내정량 상승시 초과 가능?
|
||||
$cityUpdated = [
|
||||
static::$cityKey => Util::valueFit(
|
||||
$this->city[static::$cityKey] + $score,
|
||||
0,
|
||||
$this->city[static::$cityKey.'_max']
|
||||
)
|
||||
];
|
||||
$db->update('city', $cityUpdated, 'city=%i', $general->getVar('city'));
|
||||
|
||||
$general->increaseVarWithLimit('gold', -$this->reqGold, 0);
|
||||
$general->addExperience($exp);
|
||||
$general->addDedication($ded);
|
||||
$general->increaseVar(static::$statKey.'_exp', 1);
|
||||
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
tryUniqueItemLottery($general);
|
||||
$general->applyDB($db);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,191 +1,191 @@
|
||||
<?php
|
||||
namespace sammo\Command\General;
|
||||
|
||||
use \sammo\{
|
||||
DB, Util, JosaUtil,
|
||||
General,
|
||||
ActionLogger,
|
||||
GameConst,
|
||||
LastTurn,
|
||||
GameUnitConst,
|
||||
Command
|
||||
};
|
||||
|
||||
use function \sammo\{
|
||||
getDomesticExpLevelBonus,
|
||||
CriticalRatioDomestic,
|
||||
CriticalScoreEx,
|
||||
tryUniqueItemLottery
|
||||
};
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
|
||||
|
||||
class che_정착장려 extends Command\GeneralCommand{
|
||||
static protected $cityKey = 'pop';
|
||||
static protected $statKey = 'leadership';
|
||||
static protected $actionKey = '인구';
|
||||
static protected $actionName = '정착 장려';
|
||||
|
||||
protected $reqRice;
|
||||
|
||||
protected function argTest():bool{
|
||||
$this->arg = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function init(){
|
||||
|
||||
$general = $this->generalObj;
|
||||
|
||||
$this->setCity();
|
||||
$this->setNation();
|
||||
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$this->fullConditionConstraints=[
|
||||
ConstraintHelper::NotBeNeutral(),
|
||||
ConstraintHelper::NotWanderingNation(),
|
||||
ConstraintHelper::OccupiedCity(),
|
||||
ConstraintHelper::SuppliedCity(),
|
||||
ConstraintHelper::ReqGeneralGold($reqGold),
|
||||
ConstraintHelper::ReqGeneralRice($reqRice),
|
||||
ConstraintHelper::RemainCityCapacity(static::$cityKey, static::$actionName)
|
||||
];
|
||||
|
||||
$this->reqRice = $reqRice;
|
||||
}
|
||||
|
||||
public function getCommandDetailTitle():string{
|
||||
$name = $this->getName();
|
||||
$statTypeBase = [
|
||||
'leadership'=>'통솔경험',
|
||||
'strength'=>'무력경험',
|
||||
'intel'=>'지력경험',
|
||||
];
|
||||
$statType = $statTypeBase[static::$statKey];
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$title = "{$name}({$statType}";
|
||||
if($reqGold > 0){
|
||||
$title .= ", 자금{$reqGold}";
|
||||
}
|
||||
if($reqRice > 0){
|
||||
$title .= ", 군량{$reqRice}";
|
||||
}
|
||||
$title .= ')';
|
||||
return $title;
|
||||
}
|
||||
|
||||
public function getCost():array{
|
||||
$develCost = $this->env['develcost'] * 2;
|
||||
$reqGold = 0;
|
||||
$reqRice = Util::round($this->generalObj->onCalcDomestic(static::$actionKey, 'cost', $develCost));
|
||||
|
||||
return [$reqGold, $reqRice];
|
||||
}
|
||||
|
||||
public function getCompensationStyle():?int{
|
||||
return $this->generalObj->onCalcDomestic(static::$actionKey, 'score', 100)<=>100;
|
||||
}
|
||||
|
||||
public function getPreReqTurn():int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getPostReqTurn():int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function calcBaseScore():float{
|
||||
$general = $this->generalObj;
|
||||
|
||||
if(static::$statKey == 'leadership'){
|
||||
$score = $general->getLeadership(true, true, true, false);
|
||||
}
|
||||
else{
|
||||
throw new \sammo\MustNotBeReachedException();
|
||||
}
|
||||
|
||||
$score *= getDomesticExpLevelBonus($general->getVar('explevel'));
|
||||
$score *= Util::randRange(0.8, 1.2);
|
||||
$score = $general->onCalcDomestic(static::$actionKey, 'score', $score);
|
||||
|
||||
return $score;
|
||||
}
|
||||
|
||||
public function run():bool{
|
||||
if(!$this->hasFullConditionMet()){
|
||||
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$general = $this->generalObj;
|
||||
|
||||
$score = Util::valueFit($this->calcBaseScore(), 1);
|
||||
|
||||
['success'=>$successRatio, 'fail'=>$failRatio] = CriticalRatioDomestic($general, static::$statKey);
|
||||
$successRatio = $general->onCalcDomestic(static::$cityKey, 'success', $successRatio);
|
||||
$failRatio = $general->onCalcDomestic(static::$cityKey, 'fail', $failRatio);
|
||||
|
||||
$successRatio = Util::valueFit($successRatio, 0, 1);
|
||||
$failRatio = Util::valueFit($failRatio, 0, 1 - $successRatio);
|
||||
$normalRatio = 1 - $failRatio - $successRatio;
|
||||
|
||||
$pick = Util::choiceRandomUsingWeight([
|
||||
'fail'=>$failRatio,
|
||||
'success'=>$successRatio,
|
||||
'normal'=>$normalRatio
|
||||
]);
|
||||
|
||||
$logger = $general->getLogger();
|
||||
|
||||
$date = $general->getTurnTime($general::TURNTIME_HM);
|
||||
|
||||
$score *= CriticalScoreEx($pick);
|
||||
$score = Util::round($score);
|
||||
|
||||
$exp = $score * 0.7;
|
||||
$ded = $score * 1.0;
|
||||
|
||||
$score *= 10;
|
||||
|
||||
$scoreText = number_format($score, 0);
|
||||
|
||||
$josaUl = JosaUtil::pick(static::$actionName, '을');
|
||||
if($pick == 'fail'){
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <span class='ev_failed'>실패</span>하여 주민이 <C>$scoreText</>명 증가했습니다. <1>$date</>");
|
||||
}
|
||||
else if($pick == 'success'){
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <S>성공</>하여 주민이 <C>$scoreText</>명 증가했습니다. <1>$date</>");
|
||||
}
|
||||
else{
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} 하여 주민이 <C>$scoreText</>명 증가했습니다. <1>$date</>");
|
||||
}
|
||||
|
||||
//NOTE: 내정량 상승시 초과 가능?
|
||||
$cityUpdated = [
|
||||
static::$cityKey => Util::valueFit(
|
||||
$this->city[static::$cityKey] + $score,
|
||||
0,
|
||||
$this->city[static::$cityKey.'_max']
|
||||
)
|
||||
];
|
||||
$db->update('city', $cityUpdated, 'city=%i', $general->getVar('city'));
|
||||
|
||||
$general->increaseVarWithLimit('rice', -$this->reqRice, 0);
|
||||
$general->addExperience($exp);
|
||||
$general->addDedication($ded);
|
||||
$general->increaseVar(static::$statKey.'_exp', 1);
|
||||
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
tryUniqueItemLottery($general);
|
||||
$general->applyDB($db);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
<?php
|
||||
namespace sammo\Command\General;
|
||||
|
||||
use \sammo\{
|
||||
DB, Util, JosaUtil,
|
||||
General,
|
||||
ActionLogger,
|
||||
GameConst,
|
||||
LastTurn,
|
||||
GameUnitConst,
|
||||
Command
|
||||
};
|
||||
|
||||
use function \sammo\{
|
||||
getDomesticExpLevelBonus,
|
||||
CriticalRatioDomestic,
|
||||
CriticalScoreEx,
|
||||
tryUniqueItemLottery
|
||||
};
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
|
||||
|
||||
class che_정착장려 extends Command\GeneralCommand{
|
||||
static protected $cityKey = 'pop';
|
||||
static protected $statKey = 'leadership';
|
||||
static protected $actionKey = '인구';
|
||||
static protected $actionName = '정착 장려';
|
||||
|
||||
protected $reqRice;
|
||||
|
||||
protected function argTest():bool{
|
||||
$this->arg = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function init(){
|
||||
|
||||
$general = $this->generalObj;
|
||||
|
||||
$this->setCity();
|
||||
$this->setNation();
|
||||
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$this->fullConditionConstraints=[
|
||||
ConstraintHelper::NotBeNeutral(),
|
||||
ConstraintHelper::NotWanderingNation(),
|
||||
ConstraintHelper::OccupiedCity(),
|
||||
ConstraintHelper::SuppliedCity(),
|
||||
ConstraintHelper::ReqGeneralGold($reqGold),
|
||||
ConstraintHelper::ReqGeneralRice($reqRice),
|
||||
ConstraintHelper::RemainCityCapacity(static::$cityKey, static::$actionName)
|
||||
];
|
||||
|
||||
$this->reqRice = $reqRice;
|
||||
}
|
||||
|
||||
public function getCommandDetailTitle():string{
|
||||
$name = $this->getName();
|
||||
$statTypeBase = [
|
||||
'leadership'=>'통솔경험',
|
||||
'strength'=>'무력경험',
|
||||
'intel'=>'지력경험',
|
||||
];
|
||||
$statType = $statTypeBase[static::$statKey];
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$title = "{$name}({$statType}";
|
||||
if($reqGold > 0){
|
||||
$title .= ", 자금{$reqGold}";
|
||||
}
|
||||
if($reqRice > 0){
|
||||
$title .= ", 군량{$reqRice}";
|
||||
}
|
||||
$title .= ')';
|
||||
return $title;
|
||||
}
|
||||
|
||||
public function getCost():array{
|
||||
$develCost = $this->env['develcost'] * 2;
|
||||
$reqGold = 0;
|
||||
$reqRice = Util::round($this->generalObj->onCalcDomestic(static::$actionKey, 'cost', $develCost));
|
||||
|
||||
return [$reqGold, $reqRice];
|
||||
}
|
||||
|
||||
public function getCompensationStyle():?int{
|
||||
return $this->generalObj->onCalcDomestic(static::$actionKey, 'score', 100)<=>100;
|
||||
}
|
||||
|
||||
public function getPreReqTurn():int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getPostReqTurn():int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function calcBaseScore():float{
|
||||
$general = $this->generalObj;
|
||||
|
||||
if(static::$statKey == 'leadership'){
|
||||
$score = $general->getLeadership(true, true, true, false);
|
||||
}
|
||||
else{
|
||||
throw new \sammo\MustNotBeReachedException();
|
||||
}
|
||||
|
||||
$score *= getDomesticExpLevelBonus($general->getVar('explevel'));
|
||||
$score *= Util::randRange(0.8, 1.2);
|
||||
$score = $general->onCalcDomestic(static::$actionKey, 'score', $score);
|
||||
|
||||
return $score;
|
||||
}
|
||||
|
||||
public function run():bool{
|
||||
if(!$this->hasFullConditionMet()){
|
||||
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$general = $this->generalObj;
|
||||
|
||||
$score = Util::valueFit($this->calcBaseScore(), 1);
|
||||
|
||||
['success'=>$successRatio, 'fail'=>$failRatio] = CriticalRatioDomestic($general, static::$statKey);
|
||||
$successRatio = $general->onCalcDomestic(static::$actionKey, 'success', $successRatio);
|
||||
$failRatio = $general->onCalcDomestic(static::$actionKey, 'fail', $failRatio);
|
||||
|
||||
$successRatio = Util::valueFit($successRatio, 0, 1);
|
||||
$failRatio = Util::valueFit($failRatio, 0, 1 - $successRatio);
|
||||
$normalRatio = 1 - $failRatio - $successRatio;
|
||||
|
||||
$pick = Util::choiceRandomUsingWeight([
|
||||
'fail'=>$failRatio,
|
||||
'success'=>$successRatio,
|
||||
'normal'=>$normalRatio
|
||||
]);
|
||||
|
||||
$logger = $general->getLogger();
|
||||
|
||||
$date = $general->getTurnTime($general::TURNTIME_HM);
|
||||
|
||||
$score *= CriticalScoreEx($pick);
|
||||
$score = Util::round($score);
|
||||
|
||||
$exp = $score * 0.7;
|
||||
$ded = $score * 1.0;
|
||||
|
||||
$score *= 10;
|
||||
|
||||
$scoreText = number_format($score, 0);
|
||||
|
||||
$josaUl = JosaUtil::pick(static::$actionName, '을');
|
||||
if($pick == 'fail'){
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <span class='ev_failed'>실패</span>하여 주민이 <C>$scoreText</>명 증가했습니다. <1>$date</>");
|
||||
}
|
||||
else if($pick == 'success'){
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <S>성공</>하여 주민이 <C>$scoreText</>명 증가했습니다. <1>$date</>");
|
||||
}
|
||||
else{
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} 하여 주민이 <C>$scoreText</>명 증가했습니다. <1>$date</>");
|
||||
}
|
||||
|
||||
//NOTE: 내정량 상승시 초과 가능?
|
||||
$cityUpdated = [
|
||||
static::$cityKey => Util::valueFit(
|
||||
$this->city[static::$cityKey] + $score,
|
||||
0,
|
||||
$this->city[static::$cityKey.'_max']
|
||||
)
|
||||
];
|
||||
$db->update('city', $cityUpdated, 'city=%i', $general->getVar('city'));
|
||||
|
||||
$general->increaseVarWithLimit('rice', -$this->reqRice, 0);
|
||||
$general->addExperience($exp);
|
||||
$general->addDedication($ded);
|
||||
$general->increaseVar(static::$statKey.'_exp', 1);
|
||||
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
tryUniqueItemLottery($general);
|
||||
$general->applyDB($db);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,191 +1,191 @@
|
||||
<?php
|
||||
namespace sammo\Command\General;
|
||||
|
||||
use \sammo\{
|
||||
DB, Util, JosaUtil,
|
||||
General,
|
||||
ActionLogger,
|
||||
GameConst,
|
||||
LastTurn,
|
||||
GameUnitConst,
|
||||
Command
|
||||
};
|
||||
|
||||
use function \sammo\{
|
||||
getDomesticExpLevelBonus,
|
||||
CriticalRatioDomestic,
|
||||
CriticalScoreEx,
|
||||
tryUniqueItemLottery
|
||||
};
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
|
||||
|
||||
class che_주민선정 extends Command\GeneralCommand{
|
||||
static protected $cityKey = 'trust';
|
||||
static protected $statKey = 'leadership';
|
||||
static protected $actionKey = '민심';
|
||||
static protected $actionName = '주민 선정';
|
||||
|
||||
protected $reqRice;
|
||||
|
||||
protected function argTest():bool{
|
||||
$this->arg = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function init(){
|
||||
|
||||
$general = $this->generalObj;
|
||||
|
||||
$this->setCity();
|
||||
$this->setNation();
|
||||
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$this->fullConditionConstraints=[
|
||||
ConstraintHelper::NotBeNeutral(),
|
||||
ConstraintHelper::NotWanderingNation(),
|
||||
ConstraintHelper::OccupiedCity(),
|
||||
ConstraintHelper::SuppliedCity(),
|
||||
ConstraintHelper::ReqGeneralGold($reqGold),
|
||||
ConstraintHelper::ReqGeneralRice($reqRice),
|
||||
ConstraintHelper::RemainCityTrust(static::$actionName)
|
||||
];
|
||||
|
||||
$this->reqRice = $reqRice;
|
||||
}
|
||||
|
||||
public function getCommandDetailTitle():string{
|
||||
$name = $this->getName();
|
||||
$statTypeBase = [
|
||||
'leadership'=>'통솔경험',
|
||||
'strength'=>'무력경험',
|
||||
'intel'=>'지력경험',
|
||||
];
|
||||
$statType = $statTypeBase[static::$statKey];
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$title = "{$name}({$statType}";
|
||||
if($reqGold > 0){
|
||||
$title .= ", 자금{$reqGold}";
|
||||
}
|
||||
if($reqRice > 0){
|
||||
$title .= ", 군량{$reqRice}";
|
||||
}
|
||||
$title .= ')';
|
||||
return $title;
|
||||
}
|
||||
|
||||
public function getCost():array{
|
||||
$develCost = $this->env['develcost'] * 2;
|
||||
$reqGold = 0;
|
||||
$reqRice = $this->generalObj->onCalcDomestic(static::$actionKey, 'cost', $develCost);
|
||||
|
||||
return [$reqGold, Util::round($reqRice)];
|
||||
}
|
||||
|
||||
public function getCompensationStyle():?int{
|
||||
return $this->generalObj->onCalcDomestic(static::$actionKey, 'score', 100)<=>100;
|
||||
}
|
||||
|
||||
public function getPreReqTurn():int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getPostReqTurn():int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function calcBaseScore():float{
|
||||
$general = $this->generalObj;
|
||||
|
||||
if(static::$statKey == 'leadership'){
|
||||
$score = $general->getLeadership(true, true, true, false);
|
||||
}
|
||||
else{
|
||||
throw new \sammo\MustNotBeReachedException();
|
||||
}
|
||||
|
||||
$score *= getDomesticExpLevelBonus($general->getVar('explevel'));
|
||||
$score *= Util::randRange(0.8, 1.2);
|
||||
$score = $general->onCalcDomestic(static::$actionKey, 'score', $score);
|
||||
$score = Util::valueFit($score, 1);
|
||||
|
||||
return $score;
|
||||
}
|
||||
|
||||
public function run():bool{
|
||||
if(!$this->hasFullConditionMet()){
|
||||
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$general = $this->generalObj;
|
||||
|
||||
$score = Util::valueFit($this->calcBaseScore(), 1);
|
||||
|
||||
['success'=>$successRatio, 'fail'=>$failRatio] = CriticalRatioDomestic($general, static::$statKey);
|
||||
$successRatio = $general->onCalcDomestic(static::$cityKey, 'success', $successRatio);
|
||||
$failRatio = $general->onCalcDomestic(static::$cityKey, 'fail', $failRatio);
|
||||
|
||||
$successRatio = Util::valueFit($successRatio, 0, 1);
|
||||
$failRatio = Util::valueFit($failRatio, 0, 1 - $successRatio);
|
||||
$normalRatio = 1 - $failRatio - $successRatio;
|
||||
|
||||
$pick = Util::choiceRandomUsingWeight([
|
||||
'fail'=>$failRatio,
|
||||
'success'=>$successRatio,
|
||||
'normal'=>$normalRatio
|
||||
]);
|
||||
|
||||
$logger = $general->getLogger();
|
||||
|
||||
$date = $general->getTurnTime($general::TURNTIME_HM);
|
||||
|
||||
$score *= CriticalScoreEx($pick);
|
||||
|
||||
$exp = $score * 0.7;
|
||||
$ded = $score * 1.0;
|
||||
|
||||
$score /= 10;
|
||||
|
||||
$scoreText = number_format($score, 1);
|
||||
|
||||
$josaUl = JosaUtil::pick(static::$actionName, '을');
|
||||
if($pick == 'fail'){
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <span class='ev_failed'>실패</span>하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
|
||||
}
|
||||
else if($pick == 'success'){
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <S>성공</>하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
|
||||
}
|
||||
else{
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} 하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
|
||||
}
|
||||
|
||||
//NOTE: 내정량 상승시 초과 가능?
|
||||
$cityUpdated = [
|
||||
static::$cityKey => Util::valueFit(
|
||||
$this->city[static::$cityKey] + $score,
|
||||
0,
|
||||
100
|
||||
)
|
||||
];
|
||||
$db->update('city', $cityUpdated, 'city=%i', $general->getVar('city'));
|
||||
|
||||
$general->increaseVarWithLimit('rice', -$this->reqRice, 0);
|
||||
$general->addExperience($exp);
|
||||
$general->addDedication($ded);
|
||||
$general->increaseVar(static::$statKey.'_exp', 1);
|
||||
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
tryUniqueItemLottery($general);
|
||||
$general->applyDB($db);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
<?php
|
||||
namespace sammo\Command\General;
|
||||
|
||||
use \sammo\{
|
||||
DB, Util, JosaUtil,
|
||||
General,
|
||||
ActionLogger,
|
||||
GameConst,
|
||||
LastTurn,
|
||||
GameUnitConst,
|
||||
Command
|
||||
};
|
||||
|
||||
use function \sammo\{
|
||||
getDomesticExpLevelBonus,
|
||||
CriticalRatioDomestic,
|
||||
CriticalScoreEx,
|
||||
tryUniqueItemLottery
|
||||
};
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
|
||||
|
||||
class che_주민선정 extends Command\GeneralCommand{
|
||||
static protected $cityKey = 'trust';
|
||||
static protected $statKey = 'leadership';
|
||||
static protected $actionKey = '민심';
|
||||
static protected $actionName = '주민 선정';
|
||||
|
||||
protected $reqRice;
|
||||
|
||||
protected function argTest():bool{
|
||||
$this->arg = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function init(){
|
||||
|
||||
$general = $this->generalObj;
|
||||
|
||||
$this->setCity();
|
||||
$this->setNation();
|
||||
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$this->fullConditionConstraints=[
|
||||
ConstraintHelper::NotBeNeutral(),
|
||||
ConstraintHelper::NotWanderingNation(),
|
||||
ConstraintHelper::OccupiedCity(),
|
||||
ConstraintHelper::SuppliedCity(),
|
||||
ConstraintHelper::ReqGeneralGold($reqGold),
|
||||
ConstraintHelper::ReqGeneralRice($reqRice),
|
||||
ConstraintHelper::RemainCityTrust(static::$actionName)
|
||||
];
|
||||
|
||||
$this->reqRice = $reqRice;
|
||||
}
|
||||
|
||||
public function getCommandDetailTitle():string{
|
||||
$name = $this->getName();
|
||||
$statTypeBase = [
|
||||
'leadership'=>'통솔경험',
|
||||
'strength'=>'무력경험',
|
||||
'intel'=>'지력경험',
|
||||
];
|
||||
$statType = $statTypeBase[static::$statKey];
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$title = "{$name}({$statType}";
|
||||
if($reqGold > 0){
|
||||
$title .= ", 자금{$reqGold}";
|
||||
}
|
||||
if($reqRice > 0){
|
||||
$title .= ", 군량{$reqRice}";
|
||||
}
|
||||
$title .= ')';
|
||||
return $title;
|
||||
}
|
||||
|
||||
public function getCost():array{
|
||||
$develCost = $this->env['develcost'] * 2;
|
||||
$reqGold = 0;
|
||||
$reqRice = $this->generalObj->onCalcDomestic(static::$actionKey, 'cost', $develCost);
|
||||
|
||||
return [$reqGold, Util::round($reqRice)];
|
||||
}
|
||||
|
||||
public function getCompensationStyle():?int{
|
||||
return $this->generalObj->onCalcDomestic(static::$actionKey, 'score', 100)<=>100;
|
||||
}
|
||||
|
||||
public function getPreReqTurn():int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getPostReqTurn():int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function calcBaseScore():float{
|
||||
$general = $this->generalObj;
|
||||
|
||||
if(static::$statKey == 'leadership'){
|
||||
$score = $general->getLeadership(true, true, true, false);
|
||||
}
|
||||
else{
|
||||
throw new \sammo\MustNotBeReachedException();
|
||||
}
|
||||
|
||||
$score *= getDomesticExpLevelBonus($general->getVar('explevel'));
|
||||
$score *= Util::randRange(0.8, 1.2);
|
||||
$score = $general->onCalcDomestic(static::$actionKey, 'score', $score);
|
||||
$score = Util::valueFit($score, 1);
|
||||
|
||||
return $score;
|
||||
}
|
||||
|
||||
public function run():bool{
|
||||
if(!$this->hasFullConditionMet()){
|
||||
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$general = $this->generalObj;
|
||||
|
||||
$score = Util::valueFit($this->calcBaseScore(), 1);
|
||||
|
||||
['success'=>$successRatio, 'fail'=>$failRatio] = CriticalRatioDomestic($general, static::$statKey);
|
||||
$successRatio = $general->onCalcDomestic(static::$actionKey, 'success', $successRatio);
|
||||
$failRatio = $general->onCalcDomestic(static::$actionKey, 'fail', $failRatio);
|
||||
|
||||
$successRatio = Util::valueFit($successRatio, 0, 1);
|
||||
$failRatio = Util::valueFit($failRatio, 0, 1 - $successRatio);
|
||||
$normalRatio = 1 - $failRatio - $successRatio;
|
||||
|
||||
$pick = Util::choiceRandomUsingWeight([
|
||||
'fail'=>$failRatio,
|
||||
'success'=>$successRatio,
|
||||
'normal'=>$normalRatio
|
||||
]);
|
||||
|
||||
$logger = $general->getLogger();
|
||||
|
||||
$date = $general->getTurnTime($general::TURNTIME_HM);
|
||||
|
||||
$score *= CriticalScoreEx($pick);
|
||||
|
||||
$exp = $score * 0.7;
|
||||
$ded = $score * 1.0;
|
||||
|
||||
$score /= 10;
|
||||
|
||||
$scoreText = number_format($score, 1);
|
||||
|
||||
$josaUl = JosaUtil::pick(static::$actionName, '을');
|
||||
if($pick == 'fail'){
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <span class='ev_failed'>실패</span>하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
|
||||
}
|
||||
else if($pick == 'success'){
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <S>성공</>하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
|
||||
}
|
||||
else{
|
||||
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} 하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
|
||||
}
|
||||
|
||||
//NOTE: 내정량 상승시 초과 가능?
|
||||
$cityUpdated = [
|
||||
static::$cityKey => Util::valueFit(
|
||||
$this->city[static::$cityKey] + $score,
|
||||
0,
|
||||
100
|
||||
)
|
||||
];
|
||||
$db->update('city', $cityUpdated, 'city=%i', $general->getVar('city'));
|
||||
|
||||
$general->increaseVarWithLimit('rice', -$this->reqRice, 0);
|
||||
$general->addExperience($exp);
|
||||
$general->addDedication($ded);
|
||||
$general->increaseVar(static::$statKey.'_exp', 1);
|
||||
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
tryUniqueItemLottery($general);
|
||||
$general->applyDB($db);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,80 +1,78 @@
|
||||
<?php
|
||||
namespace sammo\WarUnitTrigger;
|
||||
use sammo\BaseWarUnitTrigger;
|
||||
use sammo\WarUnitGeneral;
|
||||
use sammo\WarUnitCity;
|
||||
use sammo\WarUnit;
|
||||
use sammo\GameUnitDetail;
|
||||
use sammo\ObjectTrigger;
|
||||
use sammo\Util;
|
||||
|
||||
class che_계략시도 extends BaseWarUnitTrigger{
|
||||
protected $priority = ObjectTrigger::PRIORITY_PRE + 300;
|
||||
|
||||
static protected $tableToGeneral = [
|
||||
'위보'=>[1.2, 1.1],
|
||||
'매복'=>[1.4, 1.2],
|
||||
'반목'=>[1.6, 1.3],
|
||||
'화계'=>[1.8, 1.4],
|
||||
'혼란'=>[2.0, 1.5]
|
||||
];
|
||||
static protected $tableToCity = [
|
||||
'급습'=>[1.2, 1.1],
|
||||
'위보'=>[1.4, 1.2],
|
||||
'혼란'=>[1.6, 1.3]
|
||||
];
|
||||
|
||||
protected function actionWar(WarUnit $self, WarUnit $oppose, array &$selfEnv, array &$opposeEnv):bool{
|
||||
assert($self instanceof WarUnitGeneral, 'General만 발동 가능');
|
||||
|
||||
$general = $self->getGeneral();
|
||||
$crewType = $general->getCrewTypeObj();
|
||||
|
||||
if($crewType->magicCoef <= 0){
|
||||
//NOTE: -인 경우를 고려해야하나? 계략 맞을 확률 증가?
|
||||
return true;
|
||||
}
|
||||
|
||||
if($self->hasActivatedSkill('계략불가')){
|
||||
return true;
|
||||
}
|
||||
|
||||
$magicTrialProb = $general->getIntel(true, true, true, false) / 100;
|
||||
$magicTrialProb *= $crewType->magicCoef;
|
||||
|
||||
$magicTrialProb = $general->onCalcStat($general, 'warMagicTrialProb', $magicTrialProb);
|
||||
|
||||
if(!Util::randBool($magicTrialProb)){
|
||||
return true;
|
||||
}
|
||||
|
||||
$magicSuccessProb = 0.7;
|
||||
$magicSuccessProb = $general->onCalcStat($general, 'warMagicSuccessProb', $magicSuccessProb);
|
||||
if($self->hasActivatedSkill('계략약화')){
|
||||
$magicSuccessProb -= 0.1; //NOTE: 앞으로 이건 oppose의 onCalcStat에 들어가야하지 않을까?
|
||||
}
|
||||
|
||||
if($oppose instanceof WarUnitCity){
|
||||
$magic = Util::choiceRandom(array_keys(static::$tableToCity));
|
||||
[$successDamage, $failDamage] = static::$tableToCity[$magic];
|
||||
}
|
||||
else{
|
||||
$magic = Util::choiceRandom(array_keys(static::$tableToGeneral));
|
||||
[$successDamage, $failDamage] = static::$tableToGeneral[$magic];
|
||||
}
|
||||
|
||||
$successDamage = $general->onCalcStat($general, 'warMagicSuccessDamage', $successDamage, $magic);
|
||||
|
||||
$self->activateSkill('계략시도', $magic);
|
||||
if(Util::randBool($magicSuccessProb)){
|
||||
$self->activateSkill('계략');
|
||||
$selfEnv['magic'] = [$magic, $successDamage];
|
||||
}
|
||||
else{
|
||||
$self->activateSkill('계략실패');
|
||||
$selfEnv['magic'] = [$magic, $failDamage];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
<?php
|
||||
namespace sammo\WarUnitTrigger;
|
||||
use sammo\BaseWarUnitTrigger;
|
||||
use sammo\WarUnitGeneral;
|
||||
use sammo\WarUnitCity;
|
||||
use sammo\WarUnit;
|
||||
use sammo\GameUnitDetail;
|
||||
use sammo\ObjectTrigger;
|
||||
use sammo\Util;
|
||||
|
||||
class che_계략시도 extends BaseWarUnitTrigger{
|
||||
protected $priority = ObjectTrigger::PRIORITY_PRE + 300;
|
||||
|
||||
static protected $tableToGeneral = [
|
||||
'위보'=>[1.2, 1.1],
|
||||
'매복'=>[1.4, 1.2],
|
||||
'반목'=>[1.6, 1.3],
|
||||
'화계'=>[1.8, 1.4],
|
||||
'혼란'=>[2.0, 1.5]
|
||||
];
|
||||
static protected $tableToCity = [
|
||||
'급습'=>[1.2, 1.1],
|
||||
'위보'=>[1.4, 1.2],
|
||||
'혼란'=>[1.6, 1.3]
|
||||
];
|
||||
|
||||
protected function actionWar(WarUnit $self, WarUnit $oppose, array &$selfEnv, array &$opposeEnv):bool{
|
||||
assert($self instanceof WarUnitGeneral, 'General만 발동 가능');
|
||||
|
||||
$general = $self->getGeneral();
|
||||
$crewType = $general->getCrewTypeObj();
|
||||
|
||||
if($self->hasActivatedSkill('계략불가')){
|
||||
return true;
|
||||
}
|
||||
|
||||
$magicTrialProb = $general->getIntel(true, true, true, false) / 100;
|
||||
$magicTrialProb *= $crewType->magicCoef;
|
||||
|
||||
$magicTrialProb = $general->onCalcStat($general, 'warMagicTrialProb', $magicTrialProb);
|
||||
if($magicTrialProb <= 0){
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!Util::randBool($magicTrialProb)){
|
||||
return true;
|
||||
}
|
||||
|
||||
$magicSuccessProb = 0.7;
|
||||
$magicSuccessProb = $general->onCalcStat($general, 'warMagicSuccessProb', $magicSuccessProb);
|
||||
if($self->hasActivatedSkill('계략약화')){
|
||||
$magicSuccessProb -= 0.1; //NOTE: 앞으로 이건 oppose의 onCalcStat에 들어가야하지 않을까?
|
||||
}
|
||||
|
||||
if($oppose instanceof WarUnitCity){
|
||||
$magic = Util::choiceRandom(array_keys(static::$tableToCity));
|
||||
[$successDamage, $failDamage] = static::$tableToCity[$magic];
|
||||
}
|
||||
else{
|
||||
$magic = Util::choiceRandom(array_keys(static::$tableToGeneral));
|
||||
[$successDamage, $failDamage] = static::$tableToGeneral[$magic];
|
||||
}
|
||||
|
||||
$successDamage = $general->onCalcStat($general, 'warMagicSuccessDamage', $successDamage, $magic);
|
||||
|
||||
$self->activateSkill('계략시도', $magic);
|
||||
if(Util::randBool($magicSuccessProb)){
|
||||
$self->activateSkill('계략');
|
||||
$selfEnv['magic'] = [$magic, $successDamage];
|
||||
}
|
||||
else{
|
||||
$self->activateSkill('계략실패');
|
||||
$selfEnv['magic'] = [$magic, $failDamage];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user