forked from devsam/core
거병 추가
This commit is contained in:
@@ -1,102 +1,6 @@
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
function process_46(&$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(['startyear', 'year', 'month']);
|
||||
|
||||
$query = "select * from city where city='{$general['city']}'";
|
||||
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
$city = MYDB_fetch_array($result);
|
||||
|
||||
$query = "select no from general where nation='{$general['nation']}'";
|
||||
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
$gencount = MYDB_num_rows($result);
|
||||
|
||||
$query = "select nation from nation where nation!={$general['nation']} AND name='{$general['makenation']}'";
|
||||
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
$nationcount = MYDB_num_rows($result);
|
||||
|
||||
$command = DecodeCommand($general['turn0']);
|
||||
$color = $command[1];
|
||||
$type = $command[2]; // 1 ~ 13
|
||||
|
||||
$colors = GetNationColors();
|
||||
if($color >= count($colors)) { $color = 0; }
|
||||
$color = $colors[$color];
|
||||
|
||||
if($type < 1) { $type = 9; }
|
||||
elseif($type > 13) { $type = 9; }
|
||||
|
||||
if($gencount < 2) {
|
||||
$log[] = "<C>●</>{$admin['month']}월:수하 장수가 부족합니다. 건국 실패. <1>$date</>";
|
||||
} elseif($admin['year'] >= $admin['startyear']+2) {
|
||||
$log[] = "<C>●</>{$admin['month']}월:건국 기간이 지났습니다. 건국 실패. <1>$date</>";
|
||||
} elseif($city['nation'] != 0) {
|
||||
$log[] = "<C>●</>{$admin['month']}월:공백지가 아닙니다. 건국 실패. <1>$date</>";
|
||||
} elseif($nationcount > 0) {
|
||||
$log[] = "<C>●</>{$admin['month']}월:존재하는 국가명입니다. 건국 실패. <1>$date</>";
|
||||
} elseif($general['makelimit'] > 0) {
|
||||
$log[] = "<C>●</>{$admin['month']}월:재야가 된지 12시간이 지나야 합니다. 건국 실패. <1>$date</>";
|
||||
} elseif($general['level'] != 12) {
|
||||
$log[] = "<C>●</>{$admin['month']}월:군주가 아닙니다. 건국 실패. <1>$date</>";
|
||||
} elseif($city['level'] != 5 && $city['level'] != 6) {
|
||||
$log[] = "<C>●</>{$admin['month']}월:중, 소 도시에서만 가능합니다. 건국 실패. <1>$date</>";
|
||||
} else {
|
||||
$db->update('nation', [
|
||||
'name'=>$general['makenation'],
|
||||
'color'=>$color,
|
||||
'level'=>1,
|
||||
'type'=>$type,
|
||||
'capital'=>$general['city'],
|
||||
], 'nation=%i', $general['nation']);
|
||||
|
||||
refreshNationStaticInfo();
|
||||
$nation = getNationStaticInfo($general['nation']);
|
||||
|
||||
// 현 도시 소속지로
|
||||
$query = "update city set nation='{$nation['nation']}',conflict='{}' where city='{$general['city']}'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
|
||||
$josaYi = JosaUtil::pick($general['name'], '이');
|
||||
$josaUl = JosaUtil::pick($nation['name'], '을');
|
||||
$log[] = "<C>●</>{$admin['month']}월:<D><b>{$nation['name']}</b></>{$josaUl} 건국하였습니다. <1>$date</>";
|
||||
$alllog[] = "<C>●</>{$admin['month']}월:<Y>{$general['name']}</>{$josaYi} <G><b>{$city['name']}</b></>에 국가를 건설하였습니다.";
|
||||
$josaYi = JosaUtil::pick($nation['name'], '이');
|
||||
$history[] = "<C>●</>{$admin['year']}년 {$admin['month']}월:<Y><b>【건국】</b></>".getNationType($type)." <D><b>{$nation['name']}</b></>{$josaYi} 새로이 등장하였습니다.";
|
||||
pushGeneralHistory($general, "<C>●</>{$admin['year']}년 {$admin['month']}월:<D><b>{$nation['name']}</b></>{$josaUl} 건국");
|
||||
$josaYi = JosaUtil::pick($general['name'], '이');
|
||||
pushNationHistory($nation, "<C>●</>{$admin['year']}년 {$admin['month']}월:<Y>{$general['name']}</>{$josaYi} <D><b>{$nation['name']}</b></>{$josaUl} 건국");
|
||||
|
||||
$exp = 1000;
|
||||
$ded = 1000;
|
||||
|
||||
|
||||
|
||||
// 성격 보정
|
||||
$exp = CharExperience($exp, $general['personal']);
|
||||
$ded = CharDedication($ded, $general['personal']);
|
||||
|
||||
// 명성 상승
|
||||
$query = "update general set resturn='SUCCESS',dedication=dedication+'$ded', experience=experience+'$exp' where no='{$general['no']}'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
|
||||
$log = uniqueItem($general, $log, 3);
|
||||
}
|
||||
|
||||
pushWorldHistory($history, $admin['year'], $admin['month']);
|
||||
pushGeneralPublicRecord($alllog, $admin['year'], $admin['month']);
|
||||
pushGenLog($general, $log);
|
||||
}
|
||||
|
||||
function process_47(&$general) {
|
||||
$db = DB::db();
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
@@ -236,95 +140,6 @@ function process_54(&$general) {
|
||||
pushWorldHistory($history, $admin['year'], $admin['month']);
|
||||
}
|
||||
|
||||
function process_55(&$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(['startyear', 'year', 'month']);
|
||||
|
||||
$query = "select name from city where city='{$general['city']}'";
|
||||
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
$city = MYDB_fetch_array($result);
|
||||
|
||||
$query = "select nation from nation where name='{$general['name']}'";
|
||||
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
$nationcount = MYDB_num_rows($result);
|
||||
|
||||
if($nationcount > 0) { $makename = mb_substr("$nationcount".$general['name'], 0, 6); }
|
||||
else { $makename = $general['name']; }
|
||||
|
||||
if($general['level'] != 0) {
|
||||
$log[] = "<C>●</>{$admin['month']}월:재야가 아닙니다. 거병 실패. <1>$date</>";
|
||||
} elseif($admin['year'] >= $admin['startyear']+2) {
|
||||
$log[] = "<C>●</>{$admin['month']}월:거병 기간이 지났습니다. 거병 실패. <1>$date</>";
|
||||
} elseif($general['makelimit'] > 0) {
|
||||
$log[] = "<C>●</>{$admin['month']}월:재야가 된지 12시간이 지나야 합니다. 거병 실패. <1>$date</>";
|
||||
} else {
|
||||
|
||||
DB::db()->insert('nation', [
|
||||
'name'=>$makename,
|
||||
'color'=>'#330000',
|
||||
'gold'=>0,
|
||||
'rice'=>GameConst::$baserice,
|
||||
'rate'=>20,
|
||||
'bill'=>100,
|
||||
'sabotagelimit'=>36,
|
||||
'surlimit'=>72,
|
||||
'type'=>0,
|
||||
'gennum'=>1
|
||||
]);
|
||||
$nationID = DB::db()->insertId();
|
||||
|
||||
refreshNationStaticInfo();
|
||||
$nation = getNationStaticInfo($nationID);
|
||||
|
||||
$exp = 100;
|
||||
$ded = 100;
|
||||
|
||||
// 성격 보정
|
||||
$exp = CharExperience($exp, $general['personal']);
|
||||
$ded = CharDedication($ded, $general['personal']);
|
||||
|
||||
// 명성 상승
|
||||
// 군주로
|
||||
// 현 국가 소속으로
|
||||
$query = "update general set resturn='SUCCESS',belong=1,level=12,nation='{$nation['nation']}',dedication=dedication+'$ded', experience=experience+'$exp' where no='{$general['no']}'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
|
||||
$josaYi = JosaUtil::pick($general['name'], '이');
|
||||
$log[] = "<C>●</>{$admin['month']}월:거병에 성공하였습니다. <1>$date</>";
|
||||
$alllog[] = "<C>●</>{$admin['month']}월:<Y>{$general['name']}</>{$josaYi} <G><b>{$city['name']}</b></>에서 거병하였습니다.";
|
||||
$history[] = "<C>●</>{$admin['year']}년 {$admin['month']}월:<Y><b>【거병】</b></><D><b>{$general['name']}</b></>{$josaYi} 세력을 결성하였습니다.";
|
||||
pushGeneralHistory($general, "<C>●</>{$admin['year']}년 {$admin['month']}월:<G><b>{$city['name']}</b></>에서 거병");
|
||||
pushNationHistory($nation, "<C>●</>{$admin['year']}년 {$admin['month']}월:<Y>{$general['name']}</>{$josaYi} <G><b>{$city['name']}</b></>에서 거병");
|
||||
|
||||
// 외교테이블 추가
|
||||
|
||||
|
||||
foreach(getAllNationStaticInfo() as $younation){
|
||||
if($nation['nation'] == $younation['nation']){
|
||||
continue;
|
||||
}
|
||||
|
||||
//FIXME: 쿼리 개선. foreach문은 굳이 필요없을것
|
||||
$query = "insert into diplomacy (me, you, state, term) values ('{$nation['nation']}', '{$younation['nation']}', '2', '0')";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
$query = "insert into diplomacy (me, you, state, term) values ('{$younation['nation']}', '{$nation['nation']}', '2', '0')";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
}
|
||||
}
|
||||
pushWorldHistory($history, $admin['year'], $admin['month']);
|
||||
pushGeneralPublicRecord($alllog, $admin['year'], $admin['month']);
|
||||
pushGenLog($general, $log);
|
||||
}
|
||||
|
||||
function process_56(&$general) {
|
||||
$db = DB::db();
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
|
||||
@@ -84,6 +84,18 @@ abstract class BaseCommand{
|
||||
$this->generalObj->setRawCity($this->city);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->city = $this->generalObj->getRawCity();
|
||||
$hasArgs = true;
|
||||
foreach($args as $arg){
|
||||
if(!key_exists($arg, $this->city)){
|
||||
$hasArgs = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if($hasArgs){
|
||||
return;
|
||||
}
|
||||
$this->city = $db->queryFirstRow('SELECT %lb FROM city WHERE city=%i', $args, $this->generalObj->getVar('city'));
|
||||
if($this->generalObj->getRawCity() === null){
|
||||
$this->generalObj->setRawCity($this->city);
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
namespace sammo\GeneralCommand;
|
||||
|
||||
use \sammo\{
|
||||
DB, Util, JosaUtil,
|
||||
General,
|
||||
ActionLogger,
|
||||
GameConst, GameUnitConst,
|
||||
LastTurn,
|
||||
Command
|
||||
};
|
||||
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use sammo\CityConst;
|
||||
use function sammo\getNationTypeClass;
|
||||
use function sammo\refreshNationStaticInfo;
|
||||
use function sammo\GetNationColors;
|
||||
use function sammo\getAllNationStaticInfo;
|
||||
|
||||
|
||||
|
||||
class che_거병 extends Command\GeneralCommand{
|
||||
static protected $actionName = '거병';
|
||||
|
||||
protected function argTest():bool{
|
||||
$this->arg = [];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function init(){
|
||||
|
||||
$general = $this->generalObj;
|
||||
$env = $this->env;
|
||||
|
||||
$this->setCity();
|
||||
$this->setNation();
|
||||
|
||||
if(!key_exists($colorType, GetNationColors())){
|
||||
return false;
|
||||
}
|
||||
|
||||
$relYear = $env['year'] - $env['startyear'];
|
||||
|
||||
$this->runnableConstraints=[
|
||||
['BeNeutral'],
|
||||
['BeOpeningPart', $relYear],
|
||||
['AllowJoinAction'],
|
||||
];
|
||||
}
|
||||
|
||||
public function getCost():array{
|
||||
return [0, 0];
|
||||
}
|
||||
|
||||
public function getPreReqTurn():int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getPostReqTurn():int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function run():bool{
|
||||
if(!$this->isRunnable()){
|
||||
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
$env = $this->env;
|
||||
|
||||
$general = $this->generalObj;
|
||||
$date = substr($general->getVar('turntime'),11,5);
|
||||
|
||||
$generalName = $general->getName();
|
||||
$josaYi = JosaUtil::pick($generalName, '이');
|
||||
|
||||
$nationName = $generalName;
|
||||
$cityName = $this->city['name'];
|
||||
|
||||
$nationNameExistsCnt = $db->queryFirstField('SELECT count(*) FROM nation WHERE name = %s', $nationName);
|
||||
if($nationNameExistsCnt){
|
||||
$nationName = mb_strimwidth('㉥'.$nationName, 0, 18);
|
||||
}
|
||||
$nationNameExistsCnt = $db->queryFirstField('SELECT count(*) FROM nation WHERE name = %s', $nationName);
|
||||
if($nationNameExistsCnt){
|
||||
//여전히 중복된다면, 그냥 글자 길이 넘어가든 말든 신경쓰지 말고 넘기기.
|
||||
$nationName = '㉥'.$nationName;
|
||||
}
|
||||
|
||||
|
||||
$diplomacyInit = [];
|
||||
foreach(getAllNationStaticInfo() as $destNation){
|
||||
$destNationID = $destNation['nation'];
|
||||
$diplomacyInit[] = [
|
||||
'me'=>$destNationID,
|
||||
'you'=>$nationID,
|
||||
'state'=>2,
|
||||
'term'=>0,
|
||||
];
|
||||
|
||||
$diplomacyInit[] = [
|
||||
'me'=>$nationID,
|
||||
'you'=>$destNationID,
|
||||
'state'=>2,
|
||||
'term'=>0,
|
||||
];
|
||||
}
|
||||
$db->insert('diplomacy', $diplomacyInit);
|
||||
|
||||
DB::db()->insert('nation', [
|
||||
'name'=>$nationName,
|
||||
'color'=>'#330000',
|
||||
'gold'=>0,
|
||||
'rice'=>GameConst::$baserice,
|
||||
'rate'=>20,
|
||||
'bill'=>100,
|
||||
'sabotagelimit'=>12,
|
||||
'surlimit'=>72,
|
||||
'type'=>0,
|
||||
'gennum'=>1
|
||||
]);
|
||||
$nationID = DB::db()->insertId();
|
||||
|
||||
refreshNationStaticInfo();
|
||||
|
||||
$logger->pushGeneralActionLog("거병에 성공하였습니다. <1>$date</>");
|
||||
$logger->pushGlobalActionLog("<Y>{$generalName}</>{$josaYi} <G><b>{$cityName}</b></>에 거병하였습니다.");
|
||||
|
||||
$logger->pushGlobalHistoryLog("<Y><b>【거병】</b></><D><b>{$generalName}</b></>{$josaYi} 세력을 결성하였습니다.");
|
||||
$logger->pushGeneralHistoryLog("<G><b>{$cityName}</b></>에서 거병");
|
||||
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <G><b>{$cityName}</b></>에서 거병");
|
||||
|
||||
$exp = 100;
|
||||
$ded = 100;
|
||||
|
||||
$exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp);
|
||||
$ded = $general->onPreGeneralStatUpdate($general, 'dedication', $ded);
|
||||
|
||||
$general->increaseVar('experience', $exp);
|
||||
$general->increaseVar('dedication', $ded);
|
||||
$general->setVar('belong', 1);
|
||||
$general->setVar('level', 12);
|
||||
$general->setVar('nation', $nationID);
|
||||
|
||||
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
$general->applyDB($db);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -43,6 +43,10 @@ class che_건국 extends Command\GeneralCommand{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!key_exists($colorType, GetNationColors())){
|
||||
return false;
|
||||
}
|
||||
|
||||
try{
|
||||
$nationTypeClass = getNationTypeClass($nationType);
|
||||
}
|
||||
@@ -71,25 +75,11 @@ class che_건국 extends Command\GeneralCommand{
|
||||
$this->setCity();
|
||||
$this->setNation();
|
||||
|
||||
$destGeneralID = $this->arg['destGeneralID']??null;
|
||||
$destNationID = $this->arg['destNationID']??null;
|
||||
if($destGeneralID !== null){
|
||||
$this->setDestGeneral($destGeneralID);
|
||||
$this->setDestNation($this->destGeneralObj->getVar('nation'));
|
||||
}
|
||||
else{
|
||||
$this->setDestNation($destNationID, ['gennum', 'scout']);
|
||||
}
|
||||
|
||||
if(!key_exists($colorType, GetNationColors())){
|
||||
return false;
|
||||
}
|
||||
|
||||
$relYear = $env['year'] - $env['startyear'];
|
||||
|
||||
$this->runnableConstraints=[
|
||||
['ReqNationValue', 'gennum', '수하 장수', '>=', 2],
|
||||
['BeOpeningPart'],
|
||||
['BeOpeningPart', $relYear],
|
||||
['WanderingNation'],
|
||||
['CheckNationNameDuplicate', $nationName],
|
||||
['BeLord'],
|
||||
|
||||
Reference in New Issue
Block a user