From eac004957771f04e4b1dee245eca7cf51147aadd Mon Sep 17 00:00:00 2001 From: hide_d Date: Fri, 14 Sep 2018 02:26:41 +0900 Subject: [PATCH] =?UTF-8?q?=EB=86=8D=EC=A7=80=EA=B0=9C=EA=B0=84,=20?= =?UTF-8?q?=EC=83=81=EC=97=85=ED=88=AC=EC=9E=90=20=EA=B5=AC=ED=98=84,=20Ge?= =?UTF-8?q?neral=20=ED=81=B4=EB=9E=98=EC=8A=A4=EB=A1=9C=20checkStatChange?= =?UTF-8?q?=20=EC=9D=B4=EB=8F=99,=20uniqueItemEx=20=EC=B6=94=EA=B0=80(?= =?UTF-8?q?=EB=B0=8F=20=EC=9E=AC=EA=B5=AC=ED=98=84)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/func.php | 90 ++++++++++++++++++++++++++++++ hwe/sammo/Command/che_농지개간.php | 4 +- hwe/sammo/Command/che_상업투자.php | 23 ++++++-- hwe/sammo/General.php | 38 +++++++++++++ 4 files changed, 150 insertions(+), 5 deletions(-) diff --git a/hwe/func.php b/hwe/func.php index 790c318f..d9614b47 100644 --- a/hwe/func.php +++ b/hwe/func.php @@ -2184,6 +2184,96 @@ function CheckHall($no) { } } +function uniqueItemEx(int $generalID, ActionLogger $logger, string $acquireType='아이템'):bool { + //TODO: 이름 바꾸기 + $db = DB::db(); + $gameStor = KVStorage::getStorage($db, 'game_env'); + + $general = $db->queryFirstRow('SELECT no,name,nation,npc,weap,book,horse,item FROM general WHERE no=%i', $generalID); + if(!$general){ + return false; + } + + if($general['npc'] >= 2) { + return false; + } + if($general['horse'] > 6 || $general['weap'] > 6 || $general['book'] > 6 || $general['item'] > 6){ + return false; + } + + $scenario = $gameStor->scenario; + + $genCount = $db->queryFirstField('SELECT count(*) FROM general WHERE npc<2'); + + if ($scenario < 100) { + $prob = 1 / ($genCount * 5); // 5~6개월에 하나씩 등장 + } + else { + $prob = 1 / $genCount; // 1~2개월에 하나씩 등장 + } + + if($acquireType == '투표'){ + $prob = 1 / ($genCount * 0.7 / 3); // 투표율 70%, 투표 한번에 2~3개 등장 + } + else if($acquireType == '랜덤 임관'){ + $prob = 1 / ($genCount / 10/ 2); // 랜임시 2개(10%) 등장(200명중 20명 랜임시도?) + } + else if($acquireType == '건국'){ + $prob = 1 / ($genCount / 10/ 4); // 건국시 4개(20%) 등장(200명시 20국 정도 됨) + } + + $prob = Util::valueFit($prob, 1/3, 1); + + if(!Util::randBool($prob)){ + return false; + } + + //아이템 습득 상황 + $availableUnique = []; + $itemTypes = [ + 'horse'=>'getHorseName', + 'weap'=>'getWeapName', + 'book'=>'getBookName', + 'item'=>'getItemName' + ]; + $itemCodeList = range(7, 26); // [7, 26] 20개 + + foreach($itemTypes as $itemType=>$itemNameFunc){ + foreach($itemCodeList as $itemCode){ + $availableUnique["{$itemType}_{$itemCode}"] = [$itemType, $itemCode]; + } + } + + //TODO: 너무 바보 같다. 장기적으로는 유니크 아이템 테이블 같은게 필요하지 않을까? + foreach ($itemTypes as $itemType=>$itemNameFunc) { + foreach($db->queryFirstColumn('SELECT %b FROM general WHERE %b > 6', $itemType, $itemType) as $itemCode){ + unset($availableUnique["{$itemType}_{$itemCode}"]); + } + } + + if(!$availableUnique){ + return false; + } + + [$itemType, $itemCode] = Util::choiceRandom($availableUnique); + + $nationName = getNationStaticInfo($general['nation'])['name']; + $generalName = $general['name']; + $josaYi = JosaUtil::pick($generalName, '이'); + $itemName = ($itemTypes[$itemType])($itemCode); + $josaUl = JosaUtil::pick($itemName, '을'); + + + $db->update('general', [ + $itemType=>$itemCode + ], 'no=%i', $generalID); + + $logger->pushGeneralActionLog("{$itemName}{$josaUl} 습득했습니다!"); + $logger->pushGlobalActionLog("{$generalName}{$josaYi} {$itemName}{$josaUl} 습득했습니다!"); + $logger->pushGlobalHistoryLog("【{$acquireType}】{$nationName}{$generalName}{$josaYi} {$itemName}{$josaUl} 습득했습니다!"); + + return true; +} function uniqueItem($general, $log, $vote=0) { //TODO: uniqueItem 재 구현 diff --git a/hwe/sammo/Command/che_농지개간.php b/hwe/sammo/Command/che_농지개간.php index 9a1e0473..df02639b 100644 --- a/hwe/sammo/Command/che_농지개간.php +++ b/hwe/sammo/Command/che_농지개간.php @@ -5,5 +5,7 @@ use \sammo\Util; use \sammo\JosaUtil; class che_농지개간 extends che_상업투자{ - + static $cityKey = 'agri'; + static $actionKey = '농업'; + static $actionName = '농지 개간'; } \ No newline at end of file diff --git a/hwe/sammo/Command/che_상업투자.php b/hwe/sammo/Command/che_상업투자.php index 6724401a..35f8834e 100644 --- a/hwe/sammo/Command/che_상업투자.php +++ b/hwe/sammo/Command/che_상업투자.php @@ -2,7 +2,7 @@ namespace sammo\Command; use \sammo\{ - Util, JosaUtil, + DB, Util, JosaUtil, General, ActionLogger, getGeneralIntel, @@ -13,6 +13,7 @@ use \sammo\{ use \sammo\Constraint\Constraint; use function sammo\CriticalScore; +use function sammo\uniqueItemEx; class che_상업투자 extends BaseCommand{ @@ -47,6 +48,8 @@ class che_상업투자 extends BaseCommand{ throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도'); } + $db = DB::db(); + $general = $this->generalObj; $trust = Util::valueFit($this->city['trust'], 50); @@ -94,12 +97,24 @@ class che_상업투자 extends BaseCommand{ $exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp); $ded = $general->onPreGeneralStatUpdate($general, 'dedication', $ded); - //TODO: 내정량 상승시 초과 가능? + //NOTE: 내정량 상승시 초과 가능? + $cityUpdated = [ + static::$cityKey => Util::valueFit( + $this->city[static::$cityKey] + $score, + 0, + $this->city[static::$cityKey.'2'] + ) + ]; $general->increaseVarWithLimit('gold', -$this->reqGold, 0); + $general->increaseVar('experience', $exp); + $general->increaseVar('dedication', $ded); + $general->increaseVar('intel2', 1); + $general->updateVar('resturn', 'SUCCESS'); + $general->applyDB($db); - - //TODO:uniqueItemEx에 해당하는 함수 추가 + $this->checkStatChange(); + uniqueItemEx($general->getVar('no'), $logger); } diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index a68d59fb..7359b67f 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -48,6 +48,12 @@ class General implements iActionTrigger{ $nationTypeClass = getNationTypeClass($staticNation['type']); $this->nationType = new $nationTypeClass; $this->levelObj = new TriggerGeneralLevel($this->raw, $city); + + $specialDomesticClass = getGeneralSpecialDomesticClass($raw['special']); + $this->specialDomesticObj = new $specialDomesticClass; + + //TODO: $specialWarClass 설정 + $personalityClass = getPersonalityClass($raw['personal']); $this->personalityObj = new $personalityClass; } @@ -148,6 +154,38 @@ class General implements iActionTrigger{ return $db->affectedRows() > 0; } + function checkStatChange():bool{ + $logger = $this->getLogger(); + $limit = GameConst::$upgradeLimit; + + $table = [ + ['통솔', 'leader'], + ['무력', 'power'], + ['지력', 'intel'], + ]; + + $result = false; + + foreach($table as [$statNickName, $statName]){ + $statExpName = $statName.'2'; + + if($this->getVar($statExpName) < 0){ + $logger->pushGeneralActionLog("{$statNickName}이 1 떨어졌습니다!", ActionLogger::PLAIN); + $this->increaseVar($statExpName, $limit); + $this->increaseVar($statName, -1); + $result = true; + } + else if($this->getVar($statExpName) >= $limit){ + $logger->pushGeneralActionLog("{$statNickName}이 1 올랐습니다!", ActionLogger::PLAIN); + $this->increaseVar($statExpName, -$limit); + $this->increaseVar($statName, 1); + $result = true; + } + } + + return $result; + } + public function onPreTurnExecute(General $general, ?array $nation):array{ $chain = []; if($this->nationType){