견문 추가

This commit is contained in:
2018-10-20 03:24:34 +09:00
parent 7e5c19f507
commit aecbf8ccb3
3 changed files with 231 additions and 310 deletions
+120
View File
@@ -0,0 +1,120 @@
<?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\TextDecoration\SightseeingMessage;
class che_견문 extends Command\GeneralCommand{
static protected $actionName = '견문';
protected function init(){
$general = $this->generalObj;
$this->runnableConstraints=[
];
}
protected function argTest():bool{
$this->arg = null;
return true;
}
public function getCost():array{
return [0, 0];
}
public function getPreReqTurn():int{
return 0;
}
public function getPostReqTurn():int{
return 0;
}
public function run():bool{
if(!$this->isRunnable()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$general = $this->generalObj;
$date = substr($general->getVar('turntime'),11,5);
$sightseeing = new SightseeingMessage();
[$type, $text] = $sightseeing->pickAction();
$exp = 0;
if($type & SightseeingMessage::IncExp){
$exp += 30;
}
if($type & SightseeingMessage::IncHeavyExp){
$exp += 60;
}
if($type & SightseeingMessage::IncLeadership){
$general->increaseVar('leader2', 2);
}
if($type & SightseeingMessage::IncPower){
$general->increaseVar('power2', 2);
}
if($type & SightseeingMessage::IncIntel){
$general->increaseVar('intel2', 2);
}
if($type & SightseeingMessage::IncGold){
$general->increaseVar('gold', 300);
$text = str_replace(':amount:', '300', $text);
}
if($type & SightseeingMessage::IncRice){
$general->increaseVar('rice', 300);
$text = str_replace(':amount:', '300', $text);
}
if($type & SightseeingMessage::DecGold){
$general->increaseVarWithLimit('gold', -200, 0);
$text = str_replace(':amount:', '200', $text);
}
if($type & SightseeingMessage::DecRice){
$general->increaseVarWithLimit('rice', -200, 0);
$text = str_replace(':amount:', '200', $text);
}
if($type & SightseeingMessage::Wounded){
$general->increaseVarWithLimit('injury', Util::randRangeInt(10, 20), null, 80);
}
if($type & SightseeingMessage::HeavyWounded){
$general->increaseVarWithLimit('injury', Util::randRangeInt(20, 50), null, 80);
}
$logger = $general->getLogger();
$logger->pushGeneralActionLog("{$text} <1>$date</>");
$exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp);
$general->increaseVar('experience', $exp);
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
$general->applyDB($db);
return true;
}
}
@@ -0,0 +1,111 @@
<?php
namespace sammo\TextDecoration;
class SightseeingMessage{
const IncExp = 0x1;
const IncHeavyExp = 0x2;
const IncLeadership = 0x10;
const IncPower = 0x20;
const IncIntel = 0x40;
const IncGold = 0x100;
const IncRice = 0x200;
const DecGold = 0x400;
const DecRice = 0x800;
const Wounded = 0x1000;
const HeavyWounded = 0x2000;
static protected $messages = null;
protected static function getMessageList():array{
/* [[속성, [
텍스트 리스트,
텍스트 리스트2,
]], 가중치]
(가중치는 텍스트 수와 연관이 없음)
*/
return [
[[self::IncExp,[
'아무일도 일어나지 않았습니다.',
'명사와 설전을 벌였으나 망신만 당했습니다.',
'동네 장사와 힘겨루기를 했지만 망신만 당했습니다.',
]], 1],
[[self::IncHeavyExp, [
'주점에서 사람들과 어울려 술을 마셨습니다.',
'위기에 빠진 사람을 구해주었습니다.',
]], 1],
[[self::IncHeavyExp|self::IncLeadership, [
'백성들에게 현인의 가르침을 설파했습니다.',
'어느 집의 도망친 가축을 되찾아 주었습니다.',
]], 2],
[[self::IncHeavyExp|self::IncPower,[
'동네 장사와 힘겨루기를 하여 멋지게 이겼습니다.',
'어느 집의 무너진 울타리를 고쳐주었습니다.',
]], 2],
[[self::IncHeavyExp|self::IncIntel,[
'어느 명사와 설전을 벌여 멋지게 이겼습니다.',
'거리에서 글 모르는 아이들을 모아 글을 가르쳤습니다.',
]], 2],
[[self::IncExp|self::IncGold,[
'지나가는 행인에게서 금을 <C>:amount:</> 받았습니다.',
]], 1],
[[self::IncExp|self::IncRice,[
'지나가는 행인에게서 쌀을 <C>:amount:</> 받았습니다.',
]], 1],
[[self::IncExp|self::DecGold,[
'산적을 만나 금 <C>:amount:</>을 빼앗겼습니다.',
'돈을 <C>:amount:</> 빌려주었다가 떼어먹혔습니다.',
]], 1],
[[self::IncExp|self::DecRice,[
'쌀을 <C>:amount:</> 빌려주었다가 떼어먹혔습니다.',
]], 1],
[[self::IncExp|self::Wounded,[
'호랑이에게 물려 다쳤습니다.',
'곰에게 할퀴어 다쳤습니다.',
]], 1],
[[self::IncHeavyExp|self::Wounded,[
'위기에 빠진 사람을 구해주다가 다쳤습니다.',
]], 1],
[[self::IncExp|self::HeavyWounded,[
'호랑이에게 물려 크게 다쳤습니다.',
'곰에게 할퀴어 크게 다쳤습니다.',
]], 1],
[[self::IncHeavyExp|self::Wounded|self::HeavyWounded,[
'위기에 빠진 사람을 구하다가 죽을뻔 했습니다.',
]], 1],
[[self::IncHeavyExp|self::IncPower|self::IncGold,[
'산적과 싸워 금 <C>:amount:</>을 빼앗았습니다.',
]], 1],
[[self::IncHeavyExp|self::IncPower|self::IncRice,[
'호랑이를 잡아 고기 <C>:amount:</>을 얻었습니다.',
'곰을 잡아 고기 <C>:amount:</>을 얻었습니다.',
]], 1],
[[self::IncHeavyExp|self::IncIntel|self::IncGold,[
'돈을 빌려주었다가 이자 <C>:amount:</>을 받았습니다.',
]], 1],
[[self::IncHeavyExp|self::IncIntel|self::IncRice,[
'쌀을 빌려주었다가 이자 <C>300</>을 받았습니다.',
]], 1],
];
}
protected static function initMessageList():void{
static::$messages = static::getMessageList();
}
function __construct()
{
//TODO: 장수 이름이 들어가는 경우도 고려?
if(static::$messages === null){
static::buildMessageList();
}
}
public function pickAction():array{
[$type, $texts] = Util::choiceRandomUsingWeightPair(static::$messages);
$text = Util::choiceRandom($texts);
return [$type, $text];
}
}