강행, 단련 추가

This commit is contained in:
2018-10-17 02:01:00 +09:00
parent 9846d7f8e4
commit cbd2e136ed
6 changed files with 245 additions and 197 deletions
-192
View File
@@ -551,69 +551,6 @@ function process_16(&$general) {
pushGenLog($general, $log);
}
function process_21(&$general) {
$db = DB::db();
$gameStor = KVStorage::getStorage($db, 'game_env');
$connect=$db->get();
$log = [];
$alllog = [];
$history = [];
$date = substr($general['turntime'],11,5);
$db = DB::db();
$admin = $gameStor->getValues(['year', 'month', 'develcost']);
$city = CityConst::byID($general['city']);
$command = DecodeCommand($general['turn0']);
$destination = $command[1];
$destCity = CityConst::byID($destination);
$josaRo = JosaUtil::pick($destCity->name, '로');
if(!key_exists($destCity->id, $city->path)) {
$log[] = "<C>●</>{$admin['month']}월:인접도시가 아닙니다. <G><b>{$destCity->name}</b></>{$josaRo} 이동 실패. <1>$date</>";
} elseif($general['gold'] < $admin['develcost']) {
$log[] = "<C>●</>{$admin['month']}월:자금이 부족합니다. <G><b>{$destCity->name}</b></>{$josaRo} 이동 실패. <1>$date</>";
} else {
$log[] = "<C>●</>{$admin['month']}월:<G><b>{$destCity->name}</b></>{$josaRo} 이동했습니다. <1>$date</>";
$exp = 50;
// 성격 보정
$exp = CharExperience($exp, $general['personal']);
// 이동, 경험치 상승, 명성 상승, 사기 감소
$general['leader2']++;
$db->update('general',[
'resturn'=>'SUCCESS',
'gold'=>$db->sqleval('gold - %i',$admin['develcost']),
'city'=>$destCity->id,
'atmos'=>$db->sqleval('atmos*0.95'),
'leader2'=>$general['leader2'],
'experience'=>$db->sqleval('experience + %i',$exp)
], 'no = %i', $general['no']);
if($general['level'] == 12) {
$nation = getNationStaticInfo($general['nation']);
if($nation['level'] == 0) {
$db->update('general', [
'city'=>$destCity->id
], 'nation = %i', $general['nation']);
$genlog = ["<C>●</>방랑군 세력이 <G><b>{$destCity->name}</b></>{$josaRo} 이동했습니다."];
foreach($db->query('SELECT `no` FROM general WHERE nation=%i and `level`<12', $general['nation']) as $follower){
pushGenLog($follower, $genlog);
}
}
}
$log = checkAbility($general, $log);
}
pushGenLog($general, $log);
}
function process_26(&$general) {
$db = DB::db();
$gameStor = KVStorage::getStorage($db, 'game_env');
@@ -746,74 +683,6 @@ function process_28(&$general) {
//pushGenLog($you, $youlog);
}
function process_30(&$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', 'develcost']);
$query = "select path from city where city='{$general['city']}'";
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$city = MYDB_fetch_array($result);
$dist = searchDistance($general['city'], 3, false);
$command = DecodeCommand($general['turn0']);
$destination = $command[1];
$query = "select name from city where city='$destination'";
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$destcity = MYDB_fetch_array($result);
$cost = $admin['develcost'] * 5;
$josaRo = JosaUtil::pick($destcity['name'], '로');
if($destination == $general['city']){
$log[] = "<C>●</>{$admin['month']}월:같은 도시입니다. <G><b>{$destcity['name']}</b></>{$josaRo} 강행 실패. <1>$date</>";
} elseif(!key_exists($destination, $dist)) {
$log[] = "<C>●</>{$admin['month']}월:거리가 멉니다. <G><b>{$destcity['name']}</b></>{$josaRo} 강행 실패. <1>$date</>";
} elseif($general['gold'] < $cost) {
$log[] = "<C>●</>{$admin['month']}월:자금이 부족합니다. <G><b>{$destcity['name']}</b></>{$josaRo} 강행 실패. <1>$date</>";
} else {
$log[] = "<C>●</>{$admin['month']}월:<G><b>{$destcity['name']}</b></>{$josaRo} 강행했습니다. <1>$date</>";
$exp = 100;
// 성격 보정
$exp = CharExperience($exp, $general['personal']);
// 이동, 경험치 상승, 명성 상승, 병력/사기/훈련 감소
$general['leader2']++;
$query = "update general set resturn='SUCCESS',gold=gold-'$cost',city='$destination',crew=crew*0.95,atmos=atmos*0.9,train=train*0.95,leader2='{$general['leader2']}',experience=experience+'$exp' where no='{$general['no']}'";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
if($general['level'] == 12) {
$nation = getNationStaticInfo($general['nation']);
if($nation['level'] == 0) {
$query = "update general set city='$destination' where nation='{$general['nation']}'";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$query = "select no,name from general where nation='{$general['nation']}' and level<'12'";
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$gencount = MYDB_num_rows($result);
$genlog = ["<C>●</>방랑군 세력이 <G><b>{$destcity['name']}</b></>{$josaRo} 강행했습니다."];
for($j=0; $j < $gencount; $j++) {
$gen = MYDB_fetch_array($result);
pushGenLog($gen, $genlog);
}
}
}
$log = checkAbility($general, $log);
}
pushGenLog($general, $log);
}
function process_31(&$general) {
$db = DB::db();
$gameStor = KVStorage::getStorage($db, 'game_env');
@@ -957,67 +826,6 @@ function process_31(&$general) {
pushGenLog($general, $log);
}
function process_41(&$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', 'develcost']);
$ratio = rand() % 100;
$exp = $general['crew'] / 400;
$crewexp = $general['crew'] * $general['train'] * $general['atmos'] / 20 / 10000;
// 랜덤치
$exp = Util::round($exp * (80 + rand() % 41)/100); // 80 ~ 120%
$crewexp = Util::round($crewexp * (80 + rand() % 41)/100); // 80 ~ 120%
// 성격 보정
$exp = CharExperience($exp, $general['personal']);
$ratio = CharCritical($ratio, $general['personal']);
if($general['nation'] == 0) {
$log[] = "<C>●</>{$admin['month']}월:재야입니다. 단련 실패. <1>$date</>";
} elseif($general['gold'] < $admin['develcost']) {
$log[] = "<C>●</>{$admin['month']}월:자금이 모자랍니다. 단련 실패. <1>$date</>";
} elseif($general['rice'] < $admin['develcost']) {
$log[] = "<C>●</>{$admin['month']}월:군량이 모자랍니다. 단련 실패. <1>$date</>";
} elseif($general['train'] < 40) {
$log[] = "<C>●</>{$admin['month']}월:훈련이 너무 낮습니다. 단련 실패. <1>$date</>";
} elseif($general['atmos'] < 40) {
$log[] = "<C>●</>{$admin['month']}월:사기가 너무 낮습니다. 단련 실패. <1>$date</>";
} elseif($crewexp == 0) {
$log[] = "<C>●</>{$admin['month']}월:병사가 모자랍니다. 단련 실패. <1>$date</>";
} else {
$crewstr = GameUnitConst::allType()[GameUnitConst::byID($general['crewtype'])->armType];
if($ratio < 33) {
// 숙련도 증가
addGenDex($general['no'], GameConst::$maxAtmosByCommand, GameConst::$maxTrainByCommand, $general['crewtype'], $crewexp);
$log[] = "<C>●</>{$admin['month']}월:$crewstr 숙련도 향상이 <span class='ev_failed'>지지부진</span>했습니다. <1>$date</>";
} elseif($ratio < 66) {
$exp = $exp * 2;
// 숙련도 증가
addGenDex($general['no'], GameConst::$maxAtmosByCommand, GameConst::$maxTrainByCommand, $general['crewtype'], $crewexp * 2);
$log[] = "<C>●</>{$admin['month']}월:$crewstr 숙련도가 향상되었습니다. <1>$date</>";
} else {
$exp = $exp * 3;
// 숙련도 증가
addGenDex($general['no'], GameConst::$maxAtmosByCommand, GameConst::$maxTrainByCommand, $general['crewtype'], $crewexp * 3);
$log[] = "<C>●</>{$admin['month']}월:$crewstr 숙련도가 <S>일취월장</>했습니다. <1>$date</>";
}
// 경험치 상승 // 명성 상승
$query = "update general set resturn='SUCCESS',gold=gold-'{$admin['develcost']}',rice=rice-'{$admin['develcost']}',experience=experience+'$exp' where no='{$general['no']}'";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
}
pushGenLog($general, $log);
}
function process_42(&$general) {
$db = DB::db();
$gameStor = KVStorage::getStorage($db, 'game_env');
+119
View File
@@ -0,0 +1,119 @@
<?php
namespace sammo\GeneralCommand;
use \sammo\{
DB, Util, JosaUtil,
General,
ActionLogger,
GameConst, GameUnitConst,
LastTurn,
Command
};
use function \sammo\{
uniqueItemEx
};
use \sammo\Constraint\Constraint;
use sammo\CityConst;
class che_강행 extends Command\GeneralCommand{
static protected $actionName = '강행';
protected function init(){
$general = $this->generalObj;
$this->setCity();
$this->setNation();
$this->setDestCity($this->arg['destCityID'], []);
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
['NotSameCity'],
['NearCity', 3],
['ReqGeneralGold', $reqGold],
['ReqGeneralRice', $reqRice],
];
}
protected function argTest():bool{
if(!key_exists('destCityID', $this->arg)){
return false;
}
if(!key_exists($this->arg['destCityID'], CityConst::all())){
return false;
}
$this->arg = [
'destCityID'=>$this->arg['destCityID']
];
return true;
}
public function getCost():array{
$env = $this->env;
return [$env['develcost'] * 5, 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();
$env = $this->env;
$general = $this->generalObj;
$date = substr($general->getVar('turntime'),11,5);
$destCityName = $this->destCity['name'];
$destCityID = $this->destCity['city'];
$josaRo = JosaUtil::pick($destCityName, '로');
$logger = $general->getLogger();
$logger->pushGeneralActionLog("<G><b>{$destCityName}</b></>{$josaRo} 강행했습니다. <1>$date</>");
$exp = 100;
$exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp);
$general->setVar('city', $destCityID);
if($general->getVar('level') == 12 && $this->nation['level'] == 0){
$generalList = $db->queryFirstColumn('SELECT no, name, city, nation, level FROM general WHERE nation=%i AND no!=%i', $general->getNationID(), $general->getID());
foreach($generalList as $targetRawGeneral){
$targetGeneralID = $targetRawGeneral['no'];
$targetGeneral = $this->getGeneralObjFromGeneralSource($targetGeneralID);
if($targetGeneral === null){
$targetGeneral = new General($targetRawGeneral, null, $env['year'], $env['month'], false);
}
$targetGeneral->setVar('city', $destCityID);
$targetGeneral->getLogger()->pushGeneralActionLog("방랑군 세력이 <G><b>{$destCityName}</b></>{$josaRo} 강행했습니다.", ActionLogger::PLAIN);
$targetGeneral = null;
}
}
[$reqGold, $reqRice] = $this->getCost();
$general->increaseVarWithLimit('gold', -$reqGold, 0);
$general->increaseVar('experience', $exp);
$general->increaseVar('leader2', 1);
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
$general->applyDB($db);
}
}
+121
View File
@@ -0,0 +1,121 @@
<?php
namespace sammo\GeneralCommand;
use \sammo\{
DB, Util, JosaUtil,
General,
ActionLogger,
GameConst, GameUnitConst,
LastTurn,
Command
};
use function \sammo\{
uniqueItemEx
};
use \sammo\Constraint\Constraint;
class che_단련 extends Command\GeneralCommand{
static protected $actionName = '단련';
protected function init(){
$general = $this->generalObj;
$this->setCity();
$this->setNation();
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
['NoNeutral'],
['ReqGeneralCrew'],
//TODO:훈련이 너무 낮습니다?
//TODO:사기가 너무 낮습니다?
['ReqGeneralGold', $reqGold],
['ReqGeneralRice', $reqRice],
];
}
protected function argTest():bool{
$this->arg = null;
return true;
}
public function getCost():array{
$env = $this->env;
return [$env['develcost'], $env['develcost']];
}
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);
[$pick, $multiplier] = Util::choiceRandomUsingWeightPair([
[['success', 1], 0.34],
[['normal', 2], 0.33],
[['fail', 3], 0.33]
]);
$score = Util::round($general->getVar('crew') * $general->getVar('train') * $general->getVar('atmos') / 20 / 10000);
$score *= $multiplier;
$scoreText = number_format($score, 0);
$armTypeText = GameUnitConst::allType()[$general->getCrewTypeObj()->armType];
$logger = $general->getLogger();
if($pick == 'fail'){
$logger->pushGeneralActionLog("단련이 <span class='ev_failed'>지지부진</span>하여 {$armTypeText} 숙련도가 <C>{$scoreText}</> 향상되었습니다. <1>$date</>");
}
else if($pick == 'success'){
$logger->pushGeneralActionLog("단련이 <S>일취월장</>하여 {$armTypeText} 숙련도가 <C>{$scoreText}</> 향상되었습니다. <1>$date</>");
}
else{
$logger->pushGeneralActionLog("{$armTypeText} 숙련도가 <C>{$scoreText}</> 향상되었습니다. <1>$date</>");
}
$exp = $general->getVar('crew') / 400;
$exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp);
$general->addDex($general->getCrewTypeObj(), $score, false);
$incStat = Util::choiceRandomUsingWeight([
'leader2'=>$general->getLeadership(false, false, false, false),
'power2'=>$general->getPower(false, false, false, false),
'intel2'=>$general->getIntel(false, false, false, false)
]);
[$reqGold, $reqRice] = $this->getCost();
$general->increaseVarWithLimit('gold', -$reqGold, 0);
$general->increaseVarWithLimit('rice', -$reqRice, 0);
$general->increaseVar('experience', $exp);
$general->increaseVar($incStat, 1);
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
$general->applyDB($db);
uniqueItemEx($general->getVar('no'), $logger);
}
}
@@ -87,7 +87,7 @@ class che_사기진작 extends Command\GeneralCommand{
$general->increaseVarWithLimit('atmos', $score, 0, GameConst::$maAtmosByCommand);
$general->setVar('train', $sideEffect);
$general->addDex($general->getVar('crew')/100, $score, false);
$general->addDex($general->getCrewTypeObj(), $score, false);
$general->increaseVar('experience', $exp);
$general->increaseVar('dedication', $ded);
@@ -95,7 +95,7 @@ class che_사기진작 extends Command\GeneralCommand{
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
$general->applyDB($db);
uniqueItemEx($general->getVar('no'), $logger);
}
+2 -2
View File
@@ -84,7 +84,7 @@ class che_훈련 extends Command\GeneralCommand{
$general->increaseVarWithLimit('train', $score, 0, GameConst::$maxTrainByCommand);
$general->setVar('atmos', $sideEffect);
$general->addDex($general->getVar('crew')/100, $score, false);
$general->addDex($general->getCrewTypeObj(), $score, false);
$general->increaseVar('experience', $exp);
$general->increaseVar('dedication', $ded);
@@ -92,7 +92,7 @@ class che_훈련 extends Command\GeneralCommand{
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
$general->applyDB($db);
uniqueItemEx($general->getVar('no'), $logger);
}
+1 -1
View File
@@ -26,7 +26,7 @@ class ReqGeneralCrew extends Constraint{
return true;
}
$this->reason = "병사들이 없습니다.";
$this->reason = "병사가 모자랍니다.";
return false;
}
}