diff --git a/hwe/func.php b/hwe/func.php index ffe942cc..440a7a10 100644 --- a/hwe/func.php +++ b/hwe/func.php @@ -1505,9 +1505,18 @@ function tryUniqueItemLottery(General $general, string $acquireType='아이템') return false; } - if($general->getVar('npc') > 6 || $general->getVar('weap') > 6 || $general->getVar('book') > 6 || $general->getVar('item') > 6){ + if($general->getVar('npc') > 6){ return false; } + + foreach($general->getItems() as $item){ + if(!$item){ + continue; + } + if(!$item->isBuyable()){ + return false; + } + } $scenario = $gameStor->scenario; $genCount = $db->queryFirstField('SELECT count(*) FROM general WHERE npc<2'); @@ -1537,24 +1546,35 @@ function tryUniqueItemLottery(General $general, string $acquireType='아이템') //아이템 습득 상황 $availableUnique = []; - $itemTypes = [ - 'horse'=>'getItemName', - 'weap'=>'getItemName', - 'book'=>'getItemName', - 'item'=>'getItemName' - ]; - $itemCodeList = range(7, 26); // [7, 26] 20개 - foreach($itemTypes as $itemType=>$itemNameFunc){ - foreach($itemCodeList as $itemCode){ - $availableUnique["{$itemType}_{$itemCode}"] = [$itemType, $itemCode]; + //TODO: 너무 바보 같다. 장기적으로는 유니크 아이템 테이블 같은게 필요하지 않을까? + //일단은 '획득' 시에만 동작하므로 이대로 사용하기로... + $occupiedUnique = []; + + foreach (array_keys(GameConst::$allItems) as $itemType) { + foreach($db->queryAllLists('SELECT %b, count(*) as cnt FROM general GROUP BY %b', $itemType, $itemType) as [$itemCode, $cnt]){ + $itemClass = buildItemClass($itemCode); + if(!$itemClass){ + continue; + } + if($itemClass->isBuyable()){ + continue; + } + $occupiedUnique[$itemCode] = $cnt; } } - //TODO: 너무 바보 같다. 장기적으로는 유니크 아이템 테이블 같은게 필요하지 않을까? - foreach ($itemTypes as $itemType=>$itemNameFunc) { - foreach($db->queryFirstColumn('SELECT %b FROM general WHERE %b > 6', $itemType, $itemType) as $itemCode){ - unset($availableUnique["{$itemType}_{$itemCode}"]); + foreach(GameConst::$allItems as $itemType=>$itemCategories){ + foreach($itemCategories as $itemCode => $cnt){ + if(!key_exists($itemCode, $occupiedUnique)){ + $availableUnique[] = [[$itemType, $itemCode], $cnt]; + continue; + } + + $remain = $cnt - $occupiedUnique[$itemCode]; + if($remain > 0){ + $availableUnique[] = [[$itemType, $itemCode], $cnt]; + } } } @@ -1562,12 +1582,12 @@ function tryUniqueItemLottery(General $general, string $acquireType='아이템') return false; } - [$itemType, $itemCode] = Util::choiceRandom($availableUnique); + [$itemType, $itemCode] = Util::choiceRandomUsingWeightPair($availableUnique); $nationName = $general->getStaticNation()['name']; $generalName = $general->getNation(); $josaYi = JosaUtil::pick($generalName, '이'); - $itemName = ($itemTypes[$itemType])($itemCode); + $itemName = getItemName($itemCode); $josaUl = JosaUtil::pick($itemName, '을'); diff --git a/hwe/sammo/ActionItem/che_계략_이추.php b/hwe/sammo/ActionItem/che_계략_이추.php index d11a57a2..028af996 100644 --- a/hwe/sammo/ActionItem/che_계략_이추.php +++ b/hwe/sammo/ActionItem/che_계략_이추.php @@ -11,6 +11,7 @@ class che_계략_이추 extends \sammo\BaseItem{ protected static $cost = 1000; protected static $consumable = true; protected static $buyable = true; + protected static $reqSecu = 1000; public function onCalcDomestic(string $turnType, string $varType, float $value, $aux=null):float{ if($turnType == '계략'){ diff --git a/hwe/sammo/ActionItem/che_계략_향낭.php b/hwe/sammo/ActionItem/che_계략_향낭.php index a1dd28a1..353eed31 100644 --- a/hwe/sammo/ActionItem/che_계략_향낭.php +++ b/hwe/sammo/ActionItem/che_계략_향낭.php @@ -11,6 +11,7 @@ class che_계략_향낭 extends \sammo\BaseItem{ protected static $cost = 3000; protected static $consumable = true; protected static $buyable = true; + protected static $reqSecu = 2000; public function onCalcDomestic(string $turnType, string $varType, float $value, $aux=null):float{ if($turnType == '계략'){ diff --git a/hwe/sammo/ActionItem/che_명마_01_노기.php b/hwe/sammo/ActionItem/che_명마_01_노기.php index e9f2186b..d6ab2ff3 100644 --- a/hwe/sammo/ActionItem/che_명마_01_노기.php +++ b/hwe/sammo/ActionItem/che_명마_01_노기.php @@ -6,4 +6,5 @@ use \sammo\General; class che_명마_01_노기 extends \sammo\BaseStatItem{ protected static $cost = 1000; protected static $buyable = true; + protected static $reqSecu = 1000; } \ No newline at end of file diff --git a/hwe/sammo/ActionItem/che_명마_02_조랑.php b/hwe/sammo/ActionItem/che_명마_02_조랑.php index b77f8a78..ca5f0e2c 100644 --- a/hwe/sammo/ActionItem/che_명마_02_조랑.php +++ b/hwe/sammo/ActionItem/che_명마_02_조랑.php @@ -6,4 +6,5 @@ use \sammo\General; class che_명마_02_조랑 extends \sammo\BaseStatItem{ protected static $cost = 3000; protected static $buyable = true; + protected static $reqSecu = 2000; } \ No newline at end of file diff --git a/hwe/sammo/ActionItem/che_명마_03_노새.php b/hwe/sammo/ActionItem/che_명마_03_노새.php index 04b151c6..0fc928da 100644 --- a/hwe/sammo/ActionItem/che_명마_03_노새.php +++ b/hwe/sammo/ActionItem/che_명마_03_노새.php @@ -6,4 +6,5 @@ use \sammo\General; class che_명마_03_노새 extends \sammo\BaseStatItem{ protected static $cost = 6000; protected static $buyable = true; + protected static $reqSecu = 3000; } \ No newline at end of file diff --git a/hwe/sammo/ActionItem/che_명마_04_나귀.php b/hwe/sammo/ActionItem/che_명마_04_나귀.php index a96b975b..116a7f47 100644 --- a/hwe/sammo/ActionItem/che_명마_04_나귀.php +++ b/hwe/sammo/ActionItem/che_명마_04_나귀.php @@ -6,4 +6,5 @@ use \sammo\General; class che_명마_04_나귀 extends \sammo\BaseStatItem{ protected static $cost = 10000; protected static $buyable = true; + protected static $reqSecu = 4000; } \ No newline at end of file diff --git a/hwe/sammo/ActionItem/che_명마_05_갈색마.php b/hwe/sammo/ActionItem/che_명마_05_갈색마.php index 473db0eb..4ad1900c 100644 --- a/hwe/sammo/ActionItem/che_명마_05_갈색마.php +++ b/hwe/sammo/ActionItem/che_명마_05_갈색마.php @@ -6,4 +6,5 @@ use \sammo\General; class che_명마_05_갈색마 extends \sammo\BaseStatItem{ protected static $cost = 15000; protected static $buyable = true; + protected static $reqSecu = 5000; } \ No newline at end of file diff --git a/hwe/sammo/ActionItem/che_명마_06_흑색마.php b/hwe/sammo/ActionItem/che_명마_06_흑색마.php index 6f6748d4..fd5f9046 100644 --- a/hwe/sammo/ActionItem/che_명마_06_흑색마.php +++ b/hwe/sammo/ActionItem/che_명마_06_흑색마.php @@ -6,4 +6,5 @@ use \sammo\General; class che_명마_06_흑색마 extends \sammo\BaseStatItem{ protected static $cost = 21000; protected static $buyable = true; + protected static $reqSecu = 6000; } \ No newline at end of file diff --git a/hwe/sammo/ActionItem/che_무기_01_단도.php b/hwe/sammo/ActionItem/che_무기_01_단도.php index f30ac47d..9e1aa5a9 100644 --- a/hwe/sammo/ActionItem/che_무기_01_단도.php +++ b/hwe/sammo/ActionItem/che_무기_01_단도.php @@ -6,4 +6,5 @@ use \sammo\General; class che_무기_01_단도 extends \sammo\BaseStatItem{ protected static $cost = 1000; protected static $buyable = true; + protected static $reqSecu = 1000; } \ No newline at end of file diff --git a/hwe/sammo/ActionItem/che_무기_02_단궁.php b/hwe/sammo/ActionItem/che_무기_02_단궁.php index ffbc1090..249c2aee 100644 --- a/hwe/sammo/ActionItem/che_무기_02_단궁.php +++ b/hwe/sammo/ActionItem/che_무기_02_단궁.php @@ -6,4 +6,5 @@ use \sammo\General; class che_무기_02_단궁 extends \sammo\BaseStatItem{ protected static $cost = 3000; protected static $buyable = true; + protected static $reqSecu = 2000; } \ No newline at end of file diff --git a/hwe/sammo/ActionItem/che_무기_03_단극.php b/hwe/sammo/ActionItem/che_무기_03_단극.php index 71fa4dcb..a61f01e4 100644 --- a/hwe/sammo/ActionItem/che_무기_03_단극.php +++ b/hwe/sammo/ActionItem/che_무기_03_단극.php @@ -6,4 +6,5 @@ use \sammo\General; class che_무기_03_단극 extends \sammo\BaseStatItem{ protected static $cost = 6000; protected static $buyable = true; + protected static $reqSecu = 3000; } \ No newline at end of file diff --git a/hwe/sammo/ActionItem/che_무기_04_목검.php b/hwe/sammo/ActionItem/che_무기_04_목검.php index c3342a0f..ab24db35 100644 --- a/hwe/sammo/ActionItem/che_무기_04_목검.php +++ b/hwe/sammo/ActionItem/che_무기_04_목검.php @@ -6,4 +6,5 @@ use \sammo\General; class che_무기_04_목검 extends \sammo\BaseStatItem{ protected static $cost = 10000; protected static $buyable = true; + protected static $reqSecu = 4000; } \ No newline at end of file diff --git a/hwe/sammo/ActionItem/che_무기_05_죽창.php b/hwe/sammo/ActionItem/che_무기_05_죽창.php index 82965a7a..1b0a0210 100644 --- a/hwe/sammo/ActionItem/che_무기_05_죽창.php +++ b/hwe/sammo/ActionItem/che_무기_05_죽창.php @@ -6,4 +6,5 @@ use \sammo\General; class che_무기_05_죽창 extends \sammo\BaseStatItem{ protected static $cost = 15000; protected static $buyable = true; + protected static $reqSecu = 5000; } \ No newline at end of file diff --git a/hwe/sammo/ActionItem/che_무기_06_소부.php b/hwe/sammo/ActionItem/che_무기_06_소부.php index 414d354b..ca99d3a8 100644 --- a/hwe/sammo/ActionItem/che_무기_06_소부.php +++ b/hwe/sammo/ActionItem/che_무기_06_소부.php @@ -6,4 +6,5 @@ use \sammo\General; class che_무기_06_소부 extends \sammo\BaseStatItem{ protected static $cost = 21000; protected static $buyable = true; + protected static $reqSecu = 6000; } \ No newline at end of file diff --git a/hwe/sammo/ActionItem/che_사기_탁주.php b/hwe/sammo/ActionItem/che_사기_탁주.php index f3758e19..50f75844 100644 --- a/hwe/sammo/ActionItem/che_사기_탁주.php +++ b/hwe/sammo/ActionItem/che_사기_탁주.php @@ -12,6 +12,7 @@ class che_사기_탁주 extends \sammo\BaseItem{ protected static $cost = 1000; protected static $consumable = true; protected static $buyable = true; + protected static $reqSecu = 1000; public function getBattleInitSkillTriggerList(WarUnit $unit):?WarUnitTriggerCaller{ return new WarUnitTriggerCaller( diff --git a/hwe/sammo/ActionItem/che_서적_01_효경전.php b/hwe/sammo/ActionItem/che_서적_01_효경전.php index a566b6dc..f5f919bb 100644 --- a/hwe/sammo/ActionItem/che_서적_01_효경전.php +++ b/hwe/sammo/ActionItem/che_서적_01_효경전.php @@ -6,4 +6,5 @@ use \sammo\General; class che_서적_01_효경전 extends \sammo\BaseStatItem{ protected static $cost = 1000; protected static $buyable = true; + protected static $reqSecu = 1000; } \ No newline at end of file diff --git a/hwe/sammo/ActionItem/che_서적_02_회남자.php b/hwe/sammo/ActionItem/che_서적_02_회남자.php index ad6b7f48..85cc76ed 100644 --- a/hwe/sammo/ActionItem/che_서적_02_회남자.php +++ b/hwe/sammo/ActionItem/che_서적_02_회남자.php @@ -6,4 +6,5 @@ use \sammo\General; class che_서적_02_회남자 extends \sammo\BaseStatItem{ protected static $cost = 3000; protected static $buyable = true; + protected static $reqSecu = 2000; } \ No newline at end of file diff --git a/hwe/sammo/ActionItem/che_서적_03_변도론.php b/hwe/sammo/ActionItem/che_서적_03_변도론.php index 2fa985a3..11249809 100644 --- a/hwe/sammo/ActionItem/che_서적_03_변도론.php +++ b/hwe/sammo/ActionItem/che_서적_03_변도론.php @@ -6,4 +6,5 @@ use \sammo\General; class che_서적_03_변도론 extends \sammo\BaseStatItem{ protected static $cost = 6000; protected static $buyable = true; + protected static $reqSecu = 3000; } \ No newline at end of file diff --git a/hwe/sammo/ActionItem/che_서적_04_건상역주.php b/hwe/sammo/ActionItem/che_서적_04_건상역주.php index c9bfa2b1..c61eabf6 100644 --- a/hwe/sammo/ActionItem/che_서적_04_건상역주.php +++ b/hwe/sammo/ActionItem/che_서적_04_건상역주.php @@ -6,4 +6,5 @@ use \sammo\General; class che_서적_04_건상역주 extends \sammo\BaseStatItem{ protected static $cost = 10000; protected static $buyable = true; + protected static $reqSecu = 4000; } \ No newline at end of file diff --git a/hwe/sammo/ActionItem/che_서적_05_여씨춘추.php b/hwe/sammo/ActionItem/che_서적_05_여씨춘추.php index f93d76a5..71410579 100644 --- a/hwe/sammo/ActionItem/che_서적_05_여씨춘추.php +++ b/hwe/sammo/ActionItem/che_서적_05_여씨춘추.php @@ -6,4 +6,5 @@ use \sammo\General; class che_서적_05_여씨춘추 extends \sammo\BaseStatItem{ protected static $cost = 15000; protected static $buyable = true; + protected static $reqSecu = 5000; } \ No newline at end of file diff --git a/hwe/sammo/ActionItem/che_서적_06_사민월령.php b/hwe/sammo/ActionItem/che_서적_06_사민월령.php index cee8b3ce..bd411a34 100644 --- a/hwe/sammo/ActionItem/che_서적_06_사민월령.php +++ b/hwe/sammo/ActionItem/che_서적_06_사민월령.php @@ -6,4 +6,5 @@ use \sammo\General; class che_서적_06_사민월령 extends \sammo\BaseStatItem{ protected static $cost = 21000; protected static $buyable = true; + protected static $reqSecu = 6000; } \ No newline at end of file diff --git a/hwe/sammo/ActionItem/che_저격_수극.php b/hwe/sammo/ActionItem/che_저격_수극.php index 768d8205..44469f32 100644 --- a/hwe/sammo/ActionItem/che_저격_수극.php +++ b/hwe/sammo/ActionItem/che_저격_수극.php @@ -16,6 +16,7 @@ class che_저격_수극 extends \sammo\BaseItem{ protected static $cost = 1000; protected static $consumable = true; protected static $buyable = true; + protected static $reqSecu = 1000; public function getBattleInitSkillTriggerList(WarUnit $unit):?WarUnitTriggerCaller{ return new WarUnitTriggerCaller( diff --git a/hwe/sammo/ActionItem/che_치료_환약.php b/hwe/sammo/ActionItem/che_치료_환약.php index 03466ff0..18792f5b 100644 --- a/hwe/sammo/ActionItem/che_치료_환약.php +++ b/hwe/sammo/ActionItem/che_치료_환약.php @@ -13,6 +13,7 @@ class che_치료_환약 extends \sammo\BaseItem{ protected static $cost = 100; protected static $consumable = true; protected static $buyable = true; + protected static $reqSecu = 0; public function getPreTurnExecuteTriggerList(General $general):?GeneralTriggerCaller{ return new GeneralTriggerCaller( diff --git a/hwe/sammo/ActionItem/che_훈련_청주.php b/hwe/sammo/ActionItem/che_훈련_청주.php index 2f669a4c..bb9e68e9 100644 --- a/hwe/sammo/ActionItem/che_훈련_청주.php +++ b/hwe/sammo/ActionItem/che_훈련_청주.php @@ -12,6 +12,7 @@ class che_훈련_청주 extends \sammo\BaseItem{ protected static $cost = 1000; protected static $consumable = true; protected static $buyable = true; + protected static $reqSecu = 1000; public function getBattleInitSkillTriggerList(WarUnit $unit):?WarUnitTriggerCaller{ return new WarUnitTriggerCaller( diff --git a/hwe/sammo/BaseItem.php b/hwe/sammo/BaseItem.php index a7e89c00..89b71d45 100644 --- a/hwe/sammo/BaseItem.php +++ b/hwe/sammo/BaseItem.php @@ -13,6 +13,7 @@ class BaseItem implements iAction{ protected static $cost = null; protected static $consumable = false; protected static $buyable = false; + protected static $reqSecu = 0; function getID(){ return $this->id; @@ -34,6 +35,10 @@ class BaseItem implements iAction{ return $this->buyable; } + function getReqSecu(){ + return static::$reqSecu; + } + function isValidTurnItem(string $actionType, string $command):bool{ return false; } diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index 8de5c4d5..e306d0ac 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -100,6 +100,10 @@ class General implements iAction{ return $this->itemObjs['item']; } + function getItems():array{ + return $this->itemObjs; + } + function getLastTurn():LastTurn{ return $this->lastTurn; }