feat,refac: 게임 로직 내 '랜덤'을 RandUtil을 활용하여 재설정

- 기존의 랜덤 코드는 deprecated 처리
- 서버 시작 시 랜덤하게 정해진 hiddenSeed를 활용
- 랜덤 생성 단위
  - 월 실행
  - 사령턴 실행 결과
  - 커맨드 실행 결과
  - 작위 보상
  - 부대장 생성
  - 유니크 획득 시도
  - 설문 조사
  - 장수 생성
  - NPC국 생성, NPC 생성, NPC의 토너먼트 베팅
  - 전투
  - 도시 점령
  - 자율 행동 선택
  - 랜덤 턴 변경
- 거래장, 토너먼트 등 구 랜덤 코드를 이용하는 잔여 코드 있음
This commit is contained in:
2022-05-17 03:46:59 +09:00
parent 2cb697f3dc
commit c5ceff6fb5
136 changed files with 1000 additions and 784 deletions
+2 -2
View File
@@ -75,7 +75,7 @@ class che_NPC능동 extends Command\GeneralCommand{
return 0;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -98,7 +98,7 @@ class che_NPC능동 extends Command\GeneralCommand{
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
}
tryRollbackInheritUniqueItem($general);
tryRollbackInheritUniqueItem($rng, $general);
$general->applyDB($db);
return true;
+2 -2
View File
@@ -111,7 +111,7 @@ class che_강행 extends Command\GeneralCommand
return "{$failReason} <G><b>{$destCityName}</b></>{$josaRo} {$commandName} 실패.";
}
public function run(): bool
public function run(\Sammo\RandUtil $rng): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
@@ -156,7 +156,7 @@ class che_강행 extends Command\GeneralCommand
$general->increaseVar('leadership_exp', 1);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
+2 -2
View File
@@ -59,7 +59,7 @@ class che_거병 extends Command\GeneralCommand{
return 0;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -174,7 +174,7 @@ class che_거병 extends Command\GeneralCommand{
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
+3 -2
View File
@@ -20,6 +20,7 @@ use \sammo\Constraint\ConstraintHelper;
use sammo\Enums\InheritanceKey;
use function sammo\buildNationTypeClass;
use function sammo\genGenericUniqueRNGFromGeneral;
use function sammo\refreshNationStaticInfo;
use function sammo\GetNationColors;
@@ -126,7 +127,7 @@ class che_건국 extends Command\GeneralCommand
return 0;
}
public function run(): bool
public function run(\Sammo\RandUtil $rng): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
@@ -190,7 +191,7 @@ class che_건국 extends Command\GeneralCommand
$general->increaseInheritancePoint(InheritanceKey::active_action, 1);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general, '건국');
tryUniqueItemLottery(genGenericUniqueRNGFromGeneral($general), $general, '건국');
$general->applyDB($db);
return true;
+4 -4
View File
@@ -51,7 +51,7 @@ class che_견문 extends Command\GeneralCommand{
return 0;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -99,10 +99,10 @@ class che_견문 extends Command\GeneralCommand{
$text = str_replace(':riceAmount:', '200', $text);
}
if($type & SightseeingMessage::Wounded){
$general->increaseVarWithLimit('injury', Util::randRangeInt(10, 20), null, 80);
$general->increaseVarWithLimit('injury', $rng->nextRangeInt(10, 20), null, 80);
}
if($type & SightseeingMessage::HeavyWounded){
$general->increaseVarWithLimit('injury', Util::randRangeInt(20, 50), null, 80);
$general->increaseVarWithLimit('injury', $rng->nextRangeInt(20, 50), null, 80);
}
$logger = $general->getLogger();
@@ -112,7 +112,7 @@ class che_견문 extends Command\GeneralCommand{
$general->addExperience($exp);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
@@ -98,7 +98,7 @@ class che_군량매매 extends Command\GeneralCommand{
return 0;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -166,7 +166,7 @@ class che_군량매매 extends Command\GeneralCommand{
$exp = 30;
$ded = 50;
$incStat = Util::choiceRandomUsingWeight([
$incStat = $rng->choiceUsingWeight([
'leadership_exp'=>$general->getLeadership(false, false, false, false),
'strength_exp'=>$general->getStrength(false, false, false, false),
'intel_exp'=>$general->getIntel(false, false, false, false)
@@ -178,7 +178,7 @@ class che_군량매매 extends Command\GeneralCommand{
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
+2 -2
View File
@@ -58,7 +58,7 @@ class che_귀환 extends Command\GeneralCommand{
return 0;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -95,7 +95,7 @@ class che_귀환 extends Command\GeneralCommand{
$general->increaseVar('leadership_exp', 1);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
+13 -13
View File
@@ -3,7 +3,7 @@ namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil,
General,
General,
ActionLogger,
LastTurn,
Command, GameConst
@@ -11,7 +11,7 @@ use \sammo\{
use function sammo\{
TechLimit,
CriticalRatioDomestic,
CriticalRatioDomestic,
CriticalScoreEx,
tryUniqueItemLottery,
updateMaxDomesticCritical
@@ -38,11 +38,11 @@ class che_기술연구 extends che_상업투자{
$this->setCity();
$this->setNation(['tech']);
[$reqGold, $reqRice] = $this->getCost();
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
@@ -53,7 +53,7 @@ class che_기술연구 extends che_상업투자{
$this->reqGold = $reqGold;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -64,7 +64,7 @@ class che_기술연구 extends che_상업투자{
$trust = Util::valueFit($this->city['trust'], 50);
$score = Util::valueFit($this->calcBaseScore(), 1);
$score = Util::valueFit($this->calcBaseScore($rng), 1);
['success'=>$successRatio, 'fail'=>$failRatio] = CriticalRatioDomestic($general, static::$statKey);
if($trust < 80){
@@ -77,9 +77,9 @@ class che_기술연구 extends che_상업투자{
$failRatio = Util::valueFit($failRatio, 0, 1 - $successRatio);
$normalRatio = 1 - $failRatio - $successRatio;
$pick = Util::choiceRandomUsingWeight([
'fail'=>$failRatio,
'success'=>$successRatio,
$pick = $rng->choiceUsingWeight([
'fail'=>$failRatio,
'success'=>$successRatio,
'normal'=>$normalRatio
]);
@@ -87,14 +87,14 @@ class che_기술연구 extends che_상업투자{
$date = $general->getTurnTime($general::TURNTIME_HM);
$score *= CriticalScoreEx($pick);
$score *= CriticalScoreEx($rng, $pick);
$score = Util::round($score);
$exp = $score * 0.7;
$ded = $score * 1.0;
if($pick == 'success'){
updateMaxDomesticCritical($general, $score);
updateMaxDomesticCritical($general, $score);
}
else{
$general->setAuxVar('max_domestic_critical', 0);
@@ -134,11 +134,11 @@ class che_기술연구 extends che_상업투자{
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
return true;
}
}
+9 -9
View File
@@ -3,7 +3,7 @@ namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil,
General,
General,
ActionLogger,
GameConst, GameUnitConst,
LastTurn,
@@ -35,9 +35,9 @@ class che_단련 extends Command\GeneralCommand{
$this->setNation();
[$reqGold, $reqRice] = $this->getCost();
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::ReqGeneralCrew(),
ConstraintHelper::ReqGeneralValue('train', '훈련', '>=', GameConst::$defaultTrainLow),
ConstraintHelper::ReqGeneralValue('atmos', '사기', '>=', GameConst::$defaultAtmosLow),
@@ -66,7 +66,7 @@ class che_단련 extends Command\GeneralCommand{
$env = $this->env;
return [$env['develcost'], $env['develcost']];
}
public function getPreReqTurn():int{
return 0;
}
@@ -75,7 +75,7 @@ class che_단련 extends Command\GeneralCommand{
return 0;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -85,7 +85,7 @@ class che_단련 extends Command\GeneralCommand{
$general = $this->generalObj;
$date = $general->getTurnTime($general::TURNTIME_HM);
[$pick, $multiplier] = Util::choiceRandomUsingWeightPair([
[$pick, $multiplier] = $rng->choiceUsingWeightPair([
[['success', 3], 0.34],
[['normal', 2], 0.33],
[['fail', 1], 0.33]
@@ -113,7 +113,7 @@ class che_단련 extends Command\GeneralCommand{
$general->addDex($general->getCrewTypeObj(), $score, false);
$incStat = Util::choiceRandomUsingWeight([
$incStat = $rng->choiceUsingWeight([
'leadership_exp'=>$general->getLeadership(false, false, false, false),
'strength_exp'=>$general->getStrength(false, false, false, false),
'intel_exp'=>$general->getIntel(false, false, false, false)
@@ -126,11 +126,11 @@ class che_단련 extends Command\GeneralCommand{
$general->increaseVar($incStat, 1);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
return true;
}
}
+2 -2
View File
@@ -136,7 +136,7 @@ class che_등용 extends Command\GeneralCommand
return "{$destGeneralName}{$josaUl} {$name}";
}
public function run(): bool
public function run(\Sammo\RandUtil $rng): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
@@ -173,7 +173,7 @@ class che_등용 extends Command\GeneralCommand
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
@@ -100,7 +100,7 @@ class che_등용수락 extends Command\GeneralCommand{
return 0;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -14,6 +14,7 @@ use \sammo\GameUnitConst;
use \sammo\LastTurn;
use \sammo\Command;
use function sammo\genGenericUniqueRNGFromGeneral;
use function \sammo\tryUniqueItemLottery;
use \sammo\Constraint\Constraint;
@@ -110,7 +111,7 @@ class che_랜덤임관 extends Command\GeneralCommand
return 0;
}
public function run(): bool
public function run(\Sammo\RandUtil $rng): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
@@ -162,7 +163,7 @@ class che_랜덤임관 extends Command\GeneralCommand
$score = log($affinity + 1, 2); //0~
//쉐킷쉐킷
$score += Util::randF();
$score += $rng->nextFloat1();
$score += sqrt($testNation['gennum'] / $allGen);
@@ -219,7 +220,7 @@ class che_랜덤임관 extends Command\GeneralCommand
}
if ($generalsCnt) {
$destNation = Util::choiceRandomUsingWeightPair($generalsCnt);
$destNation = $rng->choiceUsingWeightPair($generalsCnt);
}
}
@@ -251,7 +252,7 @@ class che_랜덤임관 extends Command\GeneralCommand
'천하의 균형을 맞추기 위해',
'오랜 은거를 마치고',
];
$randomTalk = Util::choiceRandom($talkList);
$randomTalk = $rng->choice($talkList);
$logger->pushGeneralActionLog("<D>{$destNationName}</>에 랜덤 임관했습니다. <1>$date</>");
$logger->pushGeneralHistoryLog("<D><b>{$destNationName}</b></>에 랜덤 임관");
@@ -290,7 +291,7 @@ class che_랜덤임관 extends Command\GeneralCommand
$general->addExperience($exp);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general, '랜덤 임관');
tryUniqueItemLottery(genGenericUniqueRNGFromGeneral($general), $general, '랜덤 임관');
$general->applyDB($db);
return true;
@@ -55,7 +55,7 @@ class che_모반시도 extends Command\GeneralCommand{
return 0;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -99,7 +99,7 @@ class che_모반시도 extends Command\GeneralCommand{
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->increaseInheritancePoint(InheritanceKey::active_action, 1);
$general->checkStatChange();
tryRollbackInheritUniqueItem($general);
tryRollbackInheritUniqueItem($rng, $general);
$general->applyDB($db);
$lordGeneral->applyDB($db);
@@ -60,7 +60,7 @@ class che_물자조달 extends Command\GeneralCommand{
return 0;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -70,14 +70,14 @@ class che_물자조달 extends Command\GeneralCommand{
$general = $this->generalObj;
$date = $general->getTurnTime($general::TURNTIME_HM);
[$resName, $resKey] = Util::choiceRandom([
[$resName, $resKey] = $rng->choice([
['금', 'gold'],
['쌀', 'rice']
]);
$score = $general->getLeadership() + $general->getStrength() + $general->getIntel();
$score *= getDomesticExpLevelBonus($general->getVar('explevel'));
$score *= Util::randRange(0.8, 1.2);
$score *= $rng->nextRange(0.8, 1.2);
$successRatio = 0.1;
$failRatio = 0.3;
@@ -86,12 +86,12 @@ class che_물자조달 extends Command\GeneralCommand{
$failRatio = $general->onCalcDomestic('조달', 'fail', $failRatio);
$normalRatio = 1 - $failRatio - $successRatio;
$pick = Util::choiceRandomUsingWeight([
$pick = $rng->choiceUsingWeight([
'fail'=>$failRatio,
'success'=>$successRatio,
'normal'=>$normalRatio
]);
$score *= CriticalScoreEx($pick);
$score *= CriticalScoreEx($rng, $pick);
$score = $general->onCalcDomestic('조달', 'score', $score);
$score = Util::round($score);
@@ -112,7 +112,7 @@ class che_물자조달 extends Command\GeneralCommand{
$exp = $score * 0.7 / 3;
$ded = $score * 1.0 / 3;
$incStat = Util::choiceRandomUsingWeight([
$incStat = $rng->choiceUsingWeight([
'leadership_exp'=>$general->getLeadership(false, false, false, false),
'strength_exp'=>$general->getStrength(false, false, false, false),
'intel_exp'=>$general->getIntel(false, false, false, false)
@@ -128,7 +128,7 @@ class che_물자조달 extends Command\GeneralCommand{
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
+2 -2
View File
@@ -59,7 +59,7 @@ class che_방랑 extends Command\GeneralCommand{
return 0;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -125,7 +125,7 @@ class che_방랑 extends Command\GeneralCommand{
refreshNationStaticInfo();
$general->increaseInheritancePoint(InheritanceKey::active_action, 1);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
tryRollbackInheritUniqueItem($general);
tryRollbackInheritUniqueItem($rng, $general);
$general->applyDB($db);
return true;
@@ -3,7 +3,7 @@ namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil,
General,
General,
ActionLogger,
GameConst, GameUnitConst,
LastTurn,
@@ -34,13 +34,13 @@ class che_사기진작 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->minConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
];
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::ReqGeneralCrew(),
@@ -62,7 +62,7 @@ class che_사기진작 extends Command\GeneralCommand{
$general = $this->generalObj;
return [Util::round($general->getVar('crew')/100), 0];
}
public function getPreReqTurn():int{
return 0;
}
@@ -71,7 +71,7 @@ class che_사기진작 extends Command\GeneralCommand{
return 0;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -103,11 +103,11 @@ class che_사기진작 extends Command\GeneralCommand{
$general->increaseVar('leadership_exp', 1);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
return true;
}
}
+19 -18
View File
@@ -3,12 +3,13 @@ namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil,
General,
General,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command
Command,
RandUtil
};
use function \sammo\getDomesticExpLevelBonus;
@@ -41,11 +42,11 @@ class che_상업투자 extends Command\GeneralCommand{
$this->setCity();
$this->setNation();
[$reqGold, $reqRice] = $this->getCost();
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
@@ -82,15 +83,15 @@ class che_상업투자 extends Command\GeneralCommand{
$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;
}
@@ -99,7 +100,7 @@ class che_상업투자 extends Command\GeneralCommand{
return 0;
}
protected function calcBaseScore():float{
protected function calcBaseScore(RandUtil $rng):float{
$trust = Util::valueFit($this->city['trust'], 50);
$general = $this->generalObj;
@@ -115,16 +116,16 @@ class che_상업투자 extends Command\GeneralCommand{
else{
throw new \sammo\MustNotBeReachedException();
}
$score *= $trust / 100;
$score *= getDomesticExpLevelBonus($general->getVar('explevel'));
$score *= Util::randRange(0.8, 1.2);
$score *= $rng->nextRange(0.8, 1.2);
$score = $general->onCalcDomestic(static::$actionKey, 'score', $score);
return $score;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -135,7 +136,7 @@ class che_상업투자 extends Command\GeneralCommand{
$trust = Util::valueFit($this->city['trust'], 50);
$score = Util::valueFit($this->calcBaseScore(), 1);
$score = Util::valueFit($this->calcBaseScore($rng), 1);
['success'=>$successRatio, 'fail'=>$failRatio] = CriticalRatioDomestic($general, static::$statKey);
if($trust < 80){
@@ -148,9 +149,9 @@ class che_상업투자 extends Command\GeneralCommand{
$failRatio = Util::valueFit($failRatio, 0, 1 - $successRatio);
$normalRatio = 1 - $failRatio - $successRatio;
$pick = Util::choiceRandomUsingWeight([
'fail'=>$failRatio,
'success'=>$successRatio,
$pick = $rng->choiceUsingWeight([
'fail'=>$failRatio,
'success'=>$successRatio,
'normal'=>$normalRatio
]);
@@ -158,14 +159,14 @@ class che_상업투자 extends Command\GeneralCommand{
$date = $general->getTurnTime($general::TURNTIME_HM);
$score *= CriticalScoreEx($pick);
$score *= CriticalScoreEx($rng, $pick);
$score = Util::round($score);
$exp = $score * 0.7;
$ded = $score * 1.0;
if($pick == 'success'){
updateMaxDomesticCritical($general, $score);
updateMaxDomesticCritical($general, $score);
}
else{
$general->setAuxVar('max_domestic_critical', 0);
@@ -204,7 +205,7 @@ class che_상업투자 extends Command\GeneralCommand{
$general->increaseVar(static::$statKey.'_exp', 1);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
return true;
+7 -6
View File
@@ -9,6 +9,7 @@ use \sammo\ActionLogger;
use \sammo\GameConst;
use \sammo\GameUnitConst;
use \sammo\Command;
use sammo\RandUtil;
class che_선동 extends che_화계{
static protected $actionName = '선동';
@@ -16,7 +17,7 @@ class che_선동 extends che_화계{
static protected $statType = 'leadership';
static protected $injuryGeneral = true;
protected function affectDestCity(int $injuryCount){
protected function affectDestCity(RandUtil $rng, int $injuryCount){
$general = $this->generalObj;
$date = $general->getTurnTime($general::TURNTIME_HM);
@@ -30,15 +31,15 @@ class che_선동 extends che_화계{
$commandName = $this->getName();
// 선동 최대 10
$secuAmount = Util::valueFit(Util::randRangeInt(GameConst::$sabotageDamageMin, GameConst::$sabotageDamageMax), null, $destCity['secu']);
$secuAmount = Util::valueFit($rng->nextRangeInt(GameConst::$sabotageDamageMin, GameConst::$sabotageDamageMax), null, $destCity['secu']);
$trustAmount = Util::valueFit(
Util::randRange(GameConst::$sabotageDamageMin, GameConst::$sabotageDamageMax) / 50,
null,
$rng->nextRange(GameConst::$sabotageDamageMin, GameConst::$sabotageDamageMax) / 50,
null,
$destCity['trust']
);
$destCity['secu'] -= $secuAmount;
$destCity['trust'] -= $trustAmount;
DB::db()->update('city', [
'state'=>32,
'secu'=>$destCity['secu'],
@@ -57,5 +58,5 @@ class che_선동 extends che_화계{
ActionLogger::PLAIN
);
}
}
+2 -2
View File
@@ -99,7 +99,7 @@ class che_선양 extends Command\GeneralCommand
return "{$destGeneralName}】에게 {$name}";
}
public function run(): bool
public function run(\Sammo\RandUtil $rng): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
@@ -139,7 +139,7 @@ class che_선양 extends Command\GeneralCommand
$general->increaseInheritancePoint(InheritanceKey::active_action, 1);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryRollbackInheritUniqueItem($general);
tryRollbackInheritUniqueItem($rng, $general);
$general->applyDB($db);
$destGeneral->applyDB($db);
@@ -54,7 +54,7 @@ class che_소집해제 extends Command\GeneralCommand{
return 0;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -82,7 +82,7 @@ class che_소집해제 extends Command\GeneralCommand{
$general->addDedication($ded);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryRollbackInheritUniqueItem($general);
tryRollbackInheritUniqueItem($rng, $general);
$general->applyDB($db);
return true;
@@ -144,7 +144,7 @@ class che_숙련전환 extends Command\GeneralCommand
return 0;
}
public function run(): bool
public function run(\Sammo\RandUtil $rng): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
@@ -179,7 +179,7 @@ class che_숙련전환 extends Command\GeneralCommand
$general->increaseVar('leadership_exp', 2);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
return true;
+2 -2
View File
@@ -46,7 +46,7 @@ class che_요양 extends Command\GeneralCommand{
return 0;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -71,7 +71,7 @@ class che_요양 extends Command\GeneralCommand{
$general->addDedication($ded);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryRollbackInheritUniqueItem($general);
tryRollbackInheritUniqueItem($rng, $general);
$general->applyDB($db);
return true;
+2 -2
View File
@@ -53,7 +53,7 @@ class che_은퇴 extends Command\GeneralCommand{
return 0;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -69,7 +69,7 @@ class che_은퇴 extends Command\GeneralCommand{
$logger->pushGeneralActionLog("은퇴하였습니다. <1>$date</>");
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
return true;
+2 -2
View File
@@ -119,7 +119,7 @@ class che_이동 extends Command\GeneralCommand
return "{$failReason} <G><b>{$destCityName}</b></>{$josaRo} {$commandName} 실패.";
}
public function run(): bool
public function run(\Sammo\RandUtil $rng): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
@@ -164,7 +164,7 @@ class che_이동 extends Command\GeneralCommand
$general->increaseVar('leadership_exp', 1);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
@@ -109,7 +109,7 @@ class che_인재탐색 extends Command\GeneralCommand
return $foundProp;
}
public function run(): bool
public function run(\Sammo\RandUtil $rng): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
@@ -128,14 +128,14 @@ class che_인재탐색 extends Command\GeneralCommand
$totalNpcCnt = $db->queryFirstField('SELECT count(`no`) FROM general WHERE 3 <= npc AND npc <= 4');
$foundProp = $this->calcFoundProp($env['maxgeneral'], $totalGenCnt, $totalNpcCnt);
$foundNpc = Util::randBool($foundProp);
$foundNpc = $rng->nextBool($foundProp);
$logger = $general->getLogger();
if (!$foundNpc) {
$logger->pushGeneralActionLog("인재를 찾을 수 없었습니다. <1>$date</>");
$incStat = Util::choiceRandomUsingWeight([
$incStat = $rng->choiceUsingWeight([
'leadership_exp' => $general->getLeadership(false, false, false, false),
'strength_exp' => $general->getStrength(false, false, false, false),
'intel_exp' => $general->getIntel(false, false, false, false)
@@ -152,7 +152,7 @@ class che_인재탐색 extends Command\GeneralCommand
$general->increaseVar($incStat, 1);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
return true;
}
@@ -163,9 +163,9 @@ class che_인재탐색 extends Command\GeneralCommand
$scoutType = "발견";
$age = Util::randRangeInt(20, 25);
$age = $rng->nextRangeInt(20, 25);
$birthYear = $env['year'] - $age;
$deathYear = $env['year'] + Util::randRangeInt(10, 50);
$deathYear = $env['year'] + $rng->nextRangeInt(10, 50);
$avgGen = $db->queryFirstRow(
'SELECT avg(dedication) as ded,avg(experience) as exp,
@@ -175,7 +175,7 @@ class che_인재탐색 extends Command\GeneralCommand
$pickTypeList = ['무' => 6, '지' => 6, '무지' => 3];
$pickedNPC = pickGeneralFromPool($db, 0, 1)[0];
$pickedNPC = pickGeneralFromPool($db, $rng, 0, 1)[0];
$newNPC = $pickedNPC->getGeneralBuilder();
$newNPC->setSpecial('None', 'None');
@@ -200,7 +200,7 @@ class che_인재탐색 extends Command\GeneralCommand
$logger->pushGlobalActionLog("<Y>{$generalName}</>{$josaYi} <Y>$npcName</>{$josaRa}는 <C>인재</>를 {$scoutType}하였습니다!");
$logger->pushGeneralHistoryLog("<Y>$npcName</>{$josaRa}는 <C>인재</>를 {$scoutType}");
$incStat = Util::choiceRandomUsingWeight([
$incStat = $rng->choiceUsingWeight([
'leadership_exp' => $general->getLeadership(false, false, false, false),
'strength_exp' => $general->getStrength(false, false, false, false),
'intel_exp' => $general->getIntel(false, false, false, false)
@@ -218,7 +218,7 @@ class che_인재탐색 extends Command\GeneralCommand
$general->increaseVar($incStat, 3);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
return true;
}
+2 -2
View File
@@ -119,7 +119,7 @@ class che_임관 extends Command\GeneralCommand
return "{$destNationName}{$josaRo} {$commandName}";
}
public function run(): bool
public function run(\Sammo\RandUtil $rng): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
@@ -179,7 +179,7 @@ class che_임관 extends Command\GeneralCommand
$general->addExperience($exp);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
return true;
@@ -141,7 +141,7 @@ class che_장비매매 extends Command\GeneralCommand
return "{$itemName}{$josaUl} 구입";
}
public function run(): bool
public function run(\sammo\RandUtil $rng): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
@@ -174,11 +174,11 @@ class che_장비매매 extends Command\GeneralCommand
$logger->pushGeneralActionLog("<C>{$itemName}</>{$josaUl} 구입했습니다. <1>$date</>");
$general->increaseVarWithLimit('gold', -$cost, 0);
$general->setItem($itemType, $itemCode);
$general->onArbitraryAction($general, '장비매매', '구매', ['itemCode' => $itemCode]);
$general->onArbitraryAction($general, $rng, '장비매매', '구매', ['itemCode' => $itemCode]);
} else {
$logger->pushGeneralActionLog("<C>{$itemName}</>{$josaUl} 판매했습니다. <1>$date</>");
$general->increaseVarWithLimit('gold', $cost / 2);
$general->onArbitraryAction($general, '장비매매', '판매', ['itemCode' => $itemCode]);
$general->onArbitraryAction($general, $rng, '장비매매', '판매', ['itemCode' => $itemCode]);
$general->setItem($itemType, null);
if(!$itemObj->isBuyable()){
@@ -195,7 +195,7 @@ class che_장비매매 extends Command\GeneralCommand
$general->addExperience($exp);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
return true;
@@ -116,7 +116,7 @@ class che_장수대상임관 extends Command\GeneralCommand{
return "{$destGeneralName}{$josaUl} 따라 임관";
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -176,7 +176,7 @@ class che_장수대상임관 extends Command\GeneralCommand{
$general->addExperience($exp);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
return true;
@@ -3,7 +3,7 @@ namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil,
General,
General,
ActionLogger,
GameConst, GameUnitConst,
LastTurn,
@@ -34,9 +34,9 @@ class che_전투태세 extends Command\GeneralCommand{
$this->setNation();
[$reqGold, $reqRice] = $this->getCost();
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::ReqGeneralCrew(),
@@ -53,7 +53,7 @@ class che_전투태세 extends Command\GeneralCommand{
$techCost = getTechCost($this->nation['tech']);
return [Util::round($crew / 100 * 3 * $techCost), 0];
}
public function getPreReqTurn():int{
return 3;
}
@@ -62,7 +62,7 @@ class che_전투태세 extends Command\GeneralCommand{
return 0;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -102,7 +102,7 @@ class che_전투태세 extends Command\GeneralCommand{
return true;
}
$logger->pushGeneralActionLog("전투태세 완료! ({$term}/3) <1>$date</>");
$general->increaseVarWithLimit('train', 0, GameConst::$maxTrainByCommand - 5); //95보다 높으면 '깎이지는 않음'
@@ -117,15 +117,15 @@ class che_전투태세 extends Command\GeneralCommand{
$crew = $general->getVar('crew');
$general->addDex($general->getCrewTypeObj(), $crew / 100 * 3, false);
$general->increaseVar('leadership_exp', 3);
$this->setResultTurn($turnResult);
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
return true;
}
}
@@ -3,7 +3,7 @@ namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil,
General,
General,
ActionLogger,
GameConst, GameUnitConst,
LastTurn,
@@ -32,7 +32,7 @@ class che_전투특기초기화 extends Command\GeneralCommand{
$this->minConditionConstraints=[
ConstraintHelper::ReqGeneralValue(static::$specialType, static::$specialText, '!=', 'None', '특기가 없습니다.'),
];
$this->fullConditionConstraints=[
ConstraintHelper::ReqGeneralValue(static::$specialType, static::$specialText, '!=', 'None', '특기가 없습니다.')
];
@@ -54,7 +54,7 @@ class che_전투특기초기화 extends Command\GeneralCommand{
public function getCost():array{
return [0, 0];
}
public function getPreReqTurn():int{
return 1;
}
@@ -69,7 +69,7 @@ class che_전투특기초기화 extends Command\GeneralCommand{
return "새로운 적성을 찾는 중... ({$term}/{$termMax})";
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -83,7 +83,7 @@ class che_전투특기초기화 extends Command\GeneralCommand{
$specialName = static::$specialText;
$env = $this->env;
$yearMonth = Util::joinYearMonth($env['year'], $env['month']);
$oldSpecialList = $general->getAuxVar($oldTypeKey)??[];
$oldSpecialList[] = $general->getVar(static::$specialType);
@@ -97,11 +97,11 @@ class che_전투특기초기화 extends Command\GeneralCommand{
$logger->pushGeneralActionLog("새로운 {$specialName}를 가질 준비가 되었습니다. <1>$date</>");
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
return true;
}
}
+18 -17
View File
@@ -3,12 +3,13 @@ namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil,
General,
General,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command
Command,
RandUtil
};
use function \sammo\getDomesticExpLevelBonus;
@@ -40,11 +41,11 @@ class che_정착장려 extends Command\GeneralCommand{
$this->setCity();
$this->setNation();
[$reqGold, $reqRice] = $this->getCost();
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
@@ -81,14 +82,14 @@ class che_정착장려 extends Command\GeneralCommand{
$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;
}
@@ -97,7 +98,7 @@ class che_정착장려 extends Command\GeneralCommand{
return 0;
}
protected function calcBaseScore():float{
protected function calcBaseScore(RandUtil $rng):float{
$general = $this->generalObj;
if(static::$statKey == 'leadership'){
@@ -106,15 +107,15 @@ class che_정착장려 extends Command\GeneralCommand{
else{
throw new \sammo\MustNotBeReachedException();
}
$score *= getDomesticExpLevelBonus($general->getVar('explevel'));
$score *= Util::randRange(0.8, 1.2);
$score *= $rng->nextRange(0.8, 1.2);
$score = $general->onCalcDomestic(static::$actionKey, 'score', $score);
return $score;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -123,7 +124,7 @@ class che_정착장려 extends Command\GeneralCommand{
$general = $this->generalObj;
$score = Util::valueFit($this->calcBaseScore(), 1);
$score = Util::valueFit($this->calcBaseScore($rng), 1);
['success'=>$successRatio, 'fail'=>$failRatio] = CriticalRatioDomestic($general, static::$statKey);
$successRatio = $general->onCalcDomestic(static::$actionKey, 'success', $successRatio);
@@ -133,9 +134,9 @@ class che_정착장려 extends Command\GeneralCommand{
$failRatio = Util::valueFit($failRatio, 0, 1 - $successRatio);
$normalRatio = 1 - $failRatio - $successRatio;
$pick = Util::choiceRandomUsingWeight([
'fail'=>$failRatio,
'success'=>$successRatio,
$pick = $rng->choiceUsingWeight([
'fail'=>$failRatio,
'success'=>$successRatio,
'normal'=>$normalRatio
]);
@@ -143,14 +144,14 @@ class che_정착장려 extends Command\GeneralCommand{
$date = $general->getTurnTime($general::TURNTIME_HM);
$score *= CriticalScoreEx($pick);
$score *= CriticalScoreEx($rng, $pick);
$score = Util::round($score);
$exp = $score * 0.7;
$ded = $score * 1.0;
if($pick == 'success'){
updateMaxDomesticCritical($general, $score);
updateMaxDomesticCritical($general, $score);
}
else{
$general->setAuxVar('max_domestic_critical', 0);
@@ -187,7 +188,7 @@ class che_정착장려 extends Command\GeneralCommand{
$general->increaseVar(static::$statKey.'_exp', 1);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
return true;
+19 -18
View File
@@ -3,12 +3,13 @@ namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil,
General,
General,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command
Command,
RandUtil
};
use function \sammo\getDomesticExpLevelBonus;
@@ -40,11 +41,11 @@ class che_주민선정 extends Command\GeneralCommand{
$this->setCity();
$this->setNation();
[$reqGold, $reqRice] = $this->getCost();
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
@@ -81,14 +82,14 @@ class che_주민선정 extends Command\GeneralCommand{
$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;
}
@@ -97,7 +98,7 @@ class che_주민선정 extends Command\GeneralCommand{
return 0;
}
protected function calcBaseScore():float{
protected function calcBaseScore(RandUtil $rng):float{
$general = $this->generalObj;
if(static::$statKey == 'leadership'){
@@ -106,16 +107,16 @@ class che_주민선정 extends Command\GeneralCommand{
else{
throw new \sammo\MustNotBeReachedException();
}
$score *= getDomesticExpLevelBonus($general->getVar('explevel'));
$score *= Util::randRange(0.8, 1.2);
$score *= $rng->nextRange(0.8, 1.2);
$score = $general->onCalcDomestic(static::$actionKey, 'score', $score);
$score = Util::valueFit($score, 1);
return $score;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -124,7 +125,7 @@ class che_주민선정 extends Command\GeneralCommand{
$general = $this->generalObj;
$score = Util::valueFit($this->calcBaseScore(), 1);
$score = Util::valueFit($this->calcBaseScore($rng), 1);
['success'=>$successRatio, 'fail'=>$failRatio] = CriticalRatioDomestic($general, static::$statKey);
$successRatio = $general->onCalcDomestic(static::$actionKey, 'success', $successRatio);
@@ -134,9 +135,9 @@ class che_주민선정 extends Command\GeneralCommand{
$failRatio = Util::valueFit($failRatio, 0, 1 - $successRatio);
$normalRatio = 1 - $failRatio - $successRatio;
$pick = Util::choiceRandomUsingWeight([
'fail'=>$failRatio,
'success'=>$successRatio,
$pick = $rng->choiceUsingWeight([
'fail'=>$failRatio,
'success'=>$successRatio,
'normal'=>$normalRatio
]);
@@ -144,13 +145,13 @@ class che_주민선정 extends Command\GeneralCommand{
$date = $general->getTurnTime($general::TURNTIME_HM);
$score *= CriticalScoreEx($pick);
$score *= CriticalScoreEx($rng, $pick);
$exp = $score * 0.7;
$ded = $score * 1.0;
if($pick == 'success'){
updateMaxDomesticCritical($general, $score);
updateMaxDomesticCritical($general, $score);
}
else{
$general->setAuxVar('max_domestic_critical', 0);
@@ -187,11 +188,11 @@ class che_주민선정 extends Command\GeneralCommand{
$general->increaseVar(static::$statKey.'_exp', 1);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
return true;
}
}
+2 -2
View File
@@ -132,7 +132,7 @@ class che_증여 extends Command\GeneralCommand
return "{$destGeneralName}】에게 {$resText} {$this->arg['amount']}{$name}";
}
public function run(): bool
public function run(\Sammo\RandUtil $rng): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
@@ -169,7 +169,7 @@ class che_증여 extends Command\GeneralCommand
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
$destGeneral->applyDB($db);
+7 -7
View File
@@ -3,7 +3,7 @@ namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil,
General,
General,
ActionLogger,
GameConst, GameUnitConst,
LastTurn,
@@ -34,9 +34,9 @@ class che_집합 extends Command\GeneralCommand{
$this->setNation();
[$reqGold, $reqRice] = $this->getCost();
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::MustBeTroopLeader(),
@@ -52,7 +52,7 @@ class che_집합 extends Command\GeneralCommand{
public function getCost():array{
return [0, 0];
}
public function getPreReqTurn():int{
return 0;
}
@@ -61,7 +61,7 @@ class che_집합 extends Command\GeneralCommand{
return 0;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -103,11 +103,11 @@ class che_집합 extends Command\GeneralCommand{
$general->increaseVar('leadership_exp', 1);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
return true;
}
}
+2 -2
View File
@@ -162,7 +162,7 @@ class che_징병 extends Command\GeneralCommand
return 0;
}
public function run(): bool
public function run(\Sammo\RandUtil $rng): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
@@ -222,7 +222,7 @@ class che_징병 extends Command\GeneralCommand
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
$general->setAuxVar('armType', $reqCrewType->armType);
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
return true;
+4 -4
View File
@@ -120,7 +120,7 @@ class che_첩보 extends Command\GeneralCommand
return "{$failReason} <G><b>{$destCityName}</b></>에 {$commandName} 실패.";
}
public function run(): bool
public function run(\Sammo\RandUtil $rng): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
@@ -202,8 +202,8 @@ class che_첩보 extends Command\GeneralCommand
'spy'=>Json::encode($spyInfo)
], 'nation=%i',$nationID);
$exp = Util::randRangeInt(1, 100);
$ded = Util::randRangeInt(1, 70);
$exp = $rng->nextRangeInt(1, 100);
$ded = $rng->nextRangeInt(1, 70);
[$reqGold, $reqRice] = $this->getCost();
$general->increaseInheritancePoint(InheritanceKey::active_action, 0.5);//NOTE: 첩보만 예외!
@@ -214,7 +214,7 @@ class che_첩보 extends Command\GeneralCommand
$general->increaseVar('leadership_exp', 1);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryRollbackInheritUniqueItem($general);
tryRollbackInheritUniqueItem($rng, $general);
$general->applyDB($db);
return true;
+19 -4
View File
@@ -20,6 +20,9 @@ use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\CityConst;
use sammo\Enums\InheritanceKey;
use sammo\LiteHashDRBG;
use sammo\RandUtil;
use sammo\UniqueConst;
class che_출병 extends Command\GeneralCommand
{
@@ -127,7 +130,7 @@ class che_출병 extends Command\GeneralCommand
return "{$failReason} <G><b>{$destCityName}</b></>{$josaRo} {$commandName} 실패.";
}
public function run(): bool
public function run(RandUtil $rng): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
@@ -188,7 +191,7 @@ class che_출병 extends Command\GeneralCommand
}
} while (false);
$defenderCityID = (int) Util::choiceRandom($candidateCities);
$defenderCityID = (int) $rng->choice($candidateCities);
$this->setDestCity($defenderCityID);
$defenderCityName = $this->destCity['name'];
$josaRo = JosaUtil::pick($defenderCityName, '로');
@@ -236,9 +239,21 @@ class che_출병 extends Command\GeneralCommand
$general->applyDB($db);
processWar($general, $this->nation, $this->destCity);
tryUniqueItemLottery($general);
//어디로 출병하느냐에 따라 사실 결과가 다르다
$warRngPre = new LiteHashDRBG(Util::simpleSerialize(
UniqueConst::$hiddenSeed,
'war',
$logger->getYear(),
$logger->getMonth(),
$general->getID(),
$defenderCityID,
));
$warRngSeed = bin2hex($warRngPre->nextBytes(16));
processWar($warRngSeed, $general, $this->nation, $this->destCity);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
return true;
+5 -4
View File
@@ -6,7 +6,8 @@ use \sammo\{
General,
ActionLogger,
GameConst, GameUnitConst,
Command
Command,
RandUtil
};
class che_탈취 extends che_화계{
@@ -15,7 +16,7 @@ class che_탈취 extends che_화계{
static protected $statType = 'strength';
static protected $injuryGeneral = false;
protected function affectDestCity(int $injuryCount){
protected function affectDestCity(RandUtil $rng, int $injuryCount){
$general = $this->generalObj;
$nationID = $general->getNationID();
$date = $general->getTurnTime($general::TURNTIME_HM);
@@ -35,8 +36,8 @@ class che_탈취 extends che_화계{
$yearCoef = sqrt(1 + ($this->env['year'] - $this->env['startyear']) / 4) / 2;
$commRatio = $destCity['comm'] / $destCity['comm_max'];
$agriRatio = $destCity['agri'] / $destCity['agri_max'];
$gold = Util::randRangeInt(GameConst::$sabotageDamageMin, GameConst::$sabotageDamageMax) * $destCity['level'] * $yearCoef * (0.25 + $commRatio / 4);
$rice = Util::randRangeInt(GameConst::$sabotageDamageMin, GameConst::$sabotageDamageMax) * $destCity['level'] * $yearCoef * (0.25 + $agriRatio / 4);
$gold = $rng->nextRangeInt(GameConst::$sabotageDamageMin, GameConst::$sabotageDamageMax) * $destCity['level'] * $yearCoef * (0.25 + $commRatio / 4);
$rice = $rng->nextRangeInt(GameConst::$sabotageDamageMin, GameConst::$sabotageDamageMax) * $destCity['level'] * $yearCoef * (0.25 + $agriRatio / 4);
if($destCity['supply']){
[$destNationGold, $destNationRice] = $db->queryFirstList('SELECT gold,rice FROM nation WHERE nation=%i', $destNationID);
+7 -6
View File
@@ -3,10 +3,11 @@ namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil,
General,
General,
ActionLogger,
GameConst, GameUnitConst,
Command
Command,
RandUtil
};
class che_파괴 extends che_화계{
@@ -15,7 +16,7 @@ class che_파괴 extends che_화계{
static protected $statType = 'strength';
static protected $injuryGeneral = true;
protected function affectDestCity(int $injuryCount){
protected function affectDestCity(RandUtil $rng, int $injuryCount){
$general = $this->generalObj;
$date = $general->getTurnTime($general::TURNTIME_HM);
@@ -29,8 +30,8 @@ class che_파괴 extends che_화계{
$commandName = $this->getName();
// 파괴
$defAmount = Util::valueFit(Util::randRangeInt(GameConst::$sabotageDamageMin, GameConst::$sabotageDamageMax), null, $destCity['def']);
$wallAmount = Util::valueFit(Util::randRangeInt(GameConst::$sabotageDamageMin, GameConst::$sabotageDamageMax), null, $destCity['wall']);
$defAmount = Util::valueFit($rng->nextRangeInt(GameConst::$sabotageDamageMin, GameConst::$sabotageDamageMax), null, $destCity['def']);
$wallAmount = Util::valueFit($rng->nextRangeInt(GameConst::$sabotageDamageMin, GameConst::$sabotageDamageMax), null, $destCity['wall']);
if($defAmount < 0){ $defAmount = 0; }
if($wallAmount < 0){ $wallAmount = 0; }
@@ -56,5 +57,5 @@ class che_파괴 extends che_화계{
ActionLogger::PLAIN
);
}
}
+2 -2
View File
@@ -53,7 +53,7 @@ class che_하야 extends Command\GeneralCommand{
return 0;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -118,7 +118,7 @@ class che_하야 extends Command\GeneralCommand{
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryRollbackInheritUniqueItem($general);
tryRollbackInheritUniqueItem($rng, $general);
$general->applyDB($db);
return true;
+2 -2
View File
@@ -57,7 +57,7 @@ class che_해산 extends Command\GeneralCommand{
return 0;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -99,7 +99,7 @@ class che_해산 extends Command\GeneralCommand{
$oldGeneral->setVar('makelimit', 12);
$oldGeneral->applyDB($db);
}
tryRollbackInheritUniqueItem($general);
tryRollbackInheritUniqueItem($rng, $general);
$general->applyDB($db);
// 이벤트 핸들러 동작
+2 -2
View File
@@ -107,7 +107,7 @@ class che_헌납 extends Command\GeneralCommand
return 0;
}
public function run(): bool
public function run(\Sammo\RandUtil $rng): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
@@ -146,7 +146,7 @@ class che_헌납 extends Command\GeneralCommand
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
return true;
+14 -13
View File
@@ -17,6 +17,7 @@ use function sammo\tryRollbackInheritUniqueItem;
use \sammo\Constraint\ConstraintHelper;
use sammo\CityConst;
use sammo\Enums\RankColumn;
use sammo\RandUtil;
class che_화계 extends Command\GeneralCommand
{
@@ -200,7 +201,7 @@ class che_화계 extends Command\GeneralCommand
return "{$failReason} <G><b>{$destCityName}</b></>에 {$commandName} 실패.";
}
protected function affectDestCity(int $injuryCount)
protected function affectDestCity(RandUtil $rng, int $injuryCount)
{
$general = $this->generalObj;
$date = $general->getTurnTime($general::TURNTIME_HM);
@@ -214,8 +215,8 @@ class che_화계 extends Command\GeneralCommand
$commandName = $this->getName();
$agriAmount = Util::valueFit(Util::randRangeInt(GameConst::$sabotageDamageMin, GameConst::$sabotageDamageMax), null, $destCity['agri']);
$commAmount = Util::valueFit(Util::randRangeInt(GameConst::$sabotageDamageMin, GameConst::$sabotageDamageMax), null, $destCity['comm']);
$agriAmount = Util::valueFit($rng->nextRangeInt(GameConst::$sabotageDamageMin, GameConst::$sabotageDamageMax), null, $destCity['agri']);
$commAmount = Util::valueFit($rng->nextRangeInt(GameConst::$sabotageDamageMin, GameConst::$sabotageDamageMax), null, $destCity['comm']);
$destCity['agri'] -= $agriAmount;
$destCity['comm'] -= $commAmount;
@@ -239,7 +240,7 @@ class che_화계 extends Command\GeneralCommand
);
}
public function run(): bool
public function run(\Sammo\RandUtil $rng): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
@@ -279,12 +280,12 @@ class che_화계 extends Command\GeneralCommand
$prob /= $dist;
$prob = Util::valueFit($prob, 0, 0.5);
if (!Util::randBool($prob)) {
if (!$rng->nextBool($prob)) {
$josaYi = JosaUtil::pick($commandName, '이');
$logger->pushGeneralActionLog("<G><b>{$destCityName}</b></>에 {$commandName}{$josaYi} 실패했습니다. <1>$date</>");
$exp = Util::randRangeInt(1, 100);
$ded = Util::randRangeInt(1, 70);
$exp = $rng->nextRangeInt(1, 100);
$ded = $rng->nextRangeInt(1, 70);
[$reqGold, $reqRice] = $this->getCost();
$general->increaseVarWithLimit('gold', -$reqGold, 0);
@@ -295,18 +296,18 @@ class che_화계 extends Command\GeneralCommand
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryRollbackInheritUniqueItem($general);
tryRollbackInheritUniqueItem($rng, $general);
$general->applyDB($db);
return false;
}
if (static::$injuryGeneral) {
$injuryCount = \sammo\SabotageInjury($destCityGeneralList, '계략');
$injuryCount = \sammo\SabotageInjury($rng, $destCityGeneralList, '계략');
} else {
$injuryCount = 0;
}
$this->affectDestCity($injuryCount);
$this->affectDestCity($rng, $injuryCount);
$itemObj = $general->getItem();
if ($itemObj->tryConsumeNow($general, 'GeneralCommand', '계략')) {
@@ -317,8 +318,8 @@ class che_화계 extends Command\GeneralCommand
$general->deleteItem();
}
$exp = Util::randRangeInt(201, 300);
$ded = Util::randRangeInt(141, 210);
$exp = $rng->nextRangeInt(201, 300);
$ded = $rng->nextRangeInt(141, 210);
[$reqGold, $reqRice] = $this->getCost();
$general->increaseVarWithLimit('gold', -$reqGold, 0);
@@ -329,7 +330,7 @@ class che_화계 extends Command\GeneralCommand
$general->increaseRankVar(RankColumn::firenum, 1);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryRollbackInheritUniqueItem($general);
tryRollbackInheritUniqueItem($rng, $general);
$general->applyDB($db);
return true;
+8 -8
View File
@@ -3,7 +3,7 @@ namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil,
General,
General,
ActionLogger,
GameConst, GameUnitConst,
LastTurn,
@@ -33,13 +33,13 @@ class che_훈련 extends Command\GeneralCommand{
$this->setNation();
$this->minConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
];
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::ReqGeneralCrew(),
@@ -66,7 +66,7 @@ class che_훈련 extends Command\GeneralCommand{
public function getCost():array{
return [0, 0];
}
public function getPreReqTurn():int{
return 0;
}
@@ -75,7 +75,7 @@ class che_훈련 extends Command\GeneralCommand{
return 0;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -107,11 +107,11 @@ class che_훈련 extends Command\GeneralCommand{
$general->increaseVar('leadership_exp', 1);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery($general);
tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general), $general);
$general->applyDB($db);
return true;
}
}
+2 -2
View File
@@ -34,14 +34,14 @@ class 휴식 extends Command\GeneralCommand{
return 0;
}
public function run():bool{
public function run(\Sammo\RandUtil $rng):bool{
$general = $this->generalObj;
$logger = $general->getLogger();
$date = $general->getTurnTime($general::TURNTIME_HM);
$logger->pushGeneralActionLog("아무것도 실행하지 않았습니다. <1>$date</>");
$this->setResultTurn(new LastTurn());
tryRollbackInheritUniqueItem($general);
tryRollbackInheritUniqueItem($rng, $general);
$general->applyDB(DB::db());
return true;
}