general_pool 에서 장수 선택 기능 추가

This commit is contained in:
2020-12-31 07:43:56 +09:00
parent 187db3d011
commit 3e35dec9fa
66 changed files with 5597 additions and 1319 deletions
+1 -1
View File
@@ -126,7 +126,7 @@ class ChangeCity extends \sammo\Event\Action{
if($op == '/' && $value == 0){
throw new \InvalidArgumentException('0으로 나눌 수 없습니다.');
}
return DB::db()->sqleval('least(%b, greatest(0, ROUND($b %l %d, 0)))', $keyMax, $key, $op, $value);
return DB::db()->sqleval('least(%b, greatest(0, ROUND(%b '.$op.' %i, 0)))', $keyMax, $key, $value);
}
throw new \InvalidArgumentException('알 수 없는 패턴입니다.');
+23 -67
View File
@@ -2,6 +2,10 @@
namespace sammo\Event\Action;
use \sammo\GameConst;
use \sammo\Util;
use \sammo\DB;
use function sammo\pickGeneralFromPool;
//기존 event_3.php
class CreateManyNPC extends \sammo\Event\Action{
protected $npcCount;
@@ -10,75 +14,30 @@ class CreateManyNPC extends \sammo\Event\Action{
$this->npcCount = $npcCount;
}
protected function generateNPC($env){
protected function generateNPC($env, int $cnt){
$pickTypeList = ['무'=>1, '지'=>1];
$pickType = Util::choiceRandomUsingWeight($pickTypeList);
$totalStat = GameConst::$defaultStatNPCTotal;
$minStat = GameConst::$defaultStatNPCMin;
$mainStat = GameConst::$defaultStatNPCMax - Util::randRangeInt(0, GameConst::$defaultStatNPCMin);
$otherStat = $minStat + Util::randRangeInt(0, Util::toInt(GameConst::$defaultStatNPCMin/2));
$subStat = $totalStat - $mainStat - $otherStat;
if ($subStat < $minStat) {
$subStat = $otherStat;
$otherStat = $minStat;
$mainStat = $totalStat - $subStat - $otherStat;
if ($mainStat) {
throw new \LogicException('기본 스탯 설정값이 잘못되어 있음');
}
}
if($pickType == '무'){
$leadership = $subStat;
$strength = $mainStat;
$intel = $otherStat;
}
else if($pickType == '지'){
$leadership = $subStat;
$strength = $otherStat;
$intel = $mainStat;
}
else{
$leadership = $otherStat;
$strength = $subStat;
$intel = $mainStat;
}
$leadership = Util::round($leadership);
$strength = Util::round($strength);
$intel = Util::round($intel);
$age = Util::randRangeInt(20, 25);
$birthYear = $env['year'] - $age;
$deathYear = $env['year'] + Util::randRangeInt(10, 50);
$cityID = Util::choiceRandom(array_keys(\sammo\CityConst::all()));
$newNPC = new \sammo\Scenario\NPC(
Util::randRangeInt(1, 150),
\sammo\getRandGenName(),
null,
0,
$cityID,
$leadership,
$strength,
$intel,
0,
$birthYear,
$deathYear,
null,
null
);
$newNPC->npc = 3;
$newNPC->setMoney(1000, 1000);
$newNPC->setExpDed(0, 0);
$newNPC->setSpecYear(
Util::round((GameConst::$retirementYear - $age) / 12) + $age,
Util::round((GameConst::$retirementYear - $age) / 6) + $age
);
$newNPC->build($env);
return [$newNPC->realName, $newNPC->generalID];
$result = [];
foreach(pickGeneralFromPool(DB::db(), 0, $cnt) as $pickedNPC){
$newNPC = $pickedNPC->getGeneralBuilder();
$newNPC->setNationID(0)
->setNPCType(3)
->setMoney(1000, 1000)
->setExpDed(0, 0)
->setLifeSpan($birthYear, $deathYear)
->fillRandomStat($pickTypeList)
->fillRemainSpecAsZero($env);
$newNPC->build($env);
$pickedNPC->occupyGeneralName();
$result[] = [
$newNPC->getGeneralName(), $newNPC->getGeneralID()
];
}
return $result;
}
@@ -86,10 +45,7 @@ class CreateManyNPC extends \sammo\Event\Action{
if($this->npcCount <= 0){
return [__CLASS__, []];
}
$result = [];
foreach(Util::range($this->npcCount) as $idx){
$result[] = $this->generateNPC($env);
}
$result = $this->generateNPC($env, $this->npcCount);
$logger = new \sammo\ActionLogger(0, 0, $env['year'], $env['month']);
$genCnt = count($result);
+13 -14
View File
@@ -3,7 +3,6 @@ namespace sammo\Event\Action;
//이전 RegNPC 함수를 EventAction으로 재구성
class RegNPC extends \sammo\Event\Action{
private $npc;
public function __construct(
@@ -21,21 +20,21 @@ class RegNPC extends \sammo\Event\Action{
$char = '',
$text = ''
){
$this->npc = new \sammo\Scenario\NPC(
$affinity,
return (new \sammo\Scenario\GeneralBuilder(
$name,
0,
$picturePath,
$nationID,
$locatedCity,
$leadership,
$strength,
$intel,
$birth,
$death,
$ego,
$char,
$text?:''
);
$nationID
))
->setCity($locatedCity)
->setStat($leadership, $strength, $intel)
->setEgo($ego)
->setSpecialSingle($char)
->setNPCText($text?:'')
->setAffinity($affinity)
->setLifeSpan($birth, $death)
->fillRemainSpecAsZero();
}
public function run($env=null){
+13 -14
View File
@@ -20,22 +20,21 @@ class RegNeutralNPC extends \sammo\Event\Action{
$char = '',
$text = ''
){
$this->npc = new \sammo\Scenario\NPC(
$affinity,
return (new \sammo\Scenario\GeneralBuilder(
$name,
0,
$picturePath,
$nationID,
$locatedCity,
$leadership,
$strength,
$intel,
$birth,
$death,
$ego,
$char,
$text?:''
);
$this->npc = 6;
$nationID
))
->setCity($locatedCity)
->setStat($leadership, $strength, $intel)
->setEgo($ego)
->setSpecialSingle($char)
->setNPCText($text?:'')
->setAffinity($affinity)
->setLifeSpan($birth, $death)
->setNPCType(6)
->fillRemainSpecAsZero();
}
public function run($env=null){