From 42418394ed7a08d20a2841f44afea6c090ede376 Mon Sep 17 00:00:00 2001 From: hide_d Date: Sun, 21 Oct 2018 02:36:05 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B5=B0=EB=9F=89=EB=A7=A4=EB=A7=A4=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/func_process.php | 269 --------------------- hwe/sammo/Command/General/che_군량매매.php | 178 ++++++++++++++ hwe/sammo/Command/General/che_장비매매.php | 4 + hwe/sammo/Command/General/che_징병.php | 3 +- 4 files changed, 183 insertions(+), 271 deletions(-) create mode 100644 hwe/sammo/Command/General/che_군량매매.php diff --git a/hwe/func_process.php b/hwe/func_process.php index 1c61207a..0767545c 100644 --- a/hwe/func_process.php +++ b/hwe/func_process.php @@ -196,272 +196,3 @@ function CriticalScoreEx(string $type):float { return 1; } -function process_domestic(array $rawGeneral, int $type){ - $db = DB::db(); - $gameStor = KVStorage::getStorage($db, 'game_env'); - - $env = $gameStor->getValues(['startyear', 'year', 'month', 'develcost']); - $general = new General($rawGeneral, null, $env['year'], $env['month']); - - //TODO: 최종적으로는 클래스 명 그대로 가야함 - $commandMap = [ - 1=>'Command\che_농지개간', - 2=>'Command\che_상업투자', - 3=>'Command\che_기술연구', - 4=>'Command\che_주민선정', - 5=>'Command\che_수비강화', - 6=>'Command\che_성벽보수', - 7=>'Command\che_정착장려', - 8=>'Command\che_치안강화', - 9=>'Command\che_물자조달', - ]; - $cmdClass = $commandMap[$type]??null; - if(!$cmdClass){ - throw new \InvalidArgumentException('잘못된 내정 코드'); - } - $cmdObj = new $cmdClass($general, $env); - - if(!$cmdObj->isRunnable()){ - return; - } - $cmdObj->run(); -} - -function process_48(&$general) { - $db = DB::db(); - $gameStor = KVStorage::getStorage($db, 'game_env'); - $connect=$db->get(); - - $log = []; - $alllog = []; - $history = []; - $date = substr($general['turntime'],11,5); - - $admin = $gameStor->getValues(['year', 'month']); - - $city = getCity($general['city']); - - $command = DecodeCommand($general['turn0']); - $type = $command[1]; - - if($type < 100) { $isweap = 0; } - elseif($type < 200) { $type -= 100; $isweap = 1; } - elseif($type < 300) { $type -= 200; $isweap = 2; } - elseif($type < 400) { $type -= 300; $isweap = 3; } - else { $type = 7; } - - if($isweap == 3) { $cost = getItemCost2($type); } - else { $cost = getItemCost($type); } - - if($city['trade'] == 0) { - $log[] = "●{$admin['month']}월:도시에 상인이 없습니다. 장비매매 실패. <1>$date"; - } elseif($city['secu']/1000 < $type) { - $log[] = "●{$admin['month']}월:이 도시에서는 구할 수 없었습니다. 구입 실패. <1>$date"; - } elseif($type > 6 || $type < 0) { - $log[] = "●{$admin['month']}월:구입할 수 있는 물건이 아닙니다. 구입 실패. <1>$date"; - } elseif($general['gold'] < $cost && $type != 0) { - $log[] = "●{$admin['month']}월:자금이 모자랍니다. 구입 실패. <1>$date"; - } elseif($general['weap'] == 0 && $isweap == 0 && $type == 0) { - $log[] = "●{$admin['month']}월:무기가 없습니다. 판매 실패. <1>$date"; - } elseif($general['book'] == 0 && $isweap == 1 && $type == 0) { - $log[] = "●{$admin['month']}월:서적이 없습니다. 판매 실패. <1>$date"; - } elseif($general['horse'] == 0 && $isweap == 2 && $type == 0) { - $log[] = "●{$admin['month']}월:명마가 없습니다. 판매 실패. <1>$date"; - } elseif($general['item'] == 0 && $isweap == 3 && $type == 0) { - $log[] = "●{$admin['month']}월:도구가 없습니다. 판매 실패. <1>$date"; - } else { - if($isweap == 0) { - if($type != 0) { - $josaUl = JosaUtil::pick(getWeapName($type), '을'); - $log[] = "●{$admin['month']}월:".getWeapName($type)."{$josaUl} 구입했습니다. <1>$date"; - $query = "update general set resturn='SUCCESS',weap='$type',gold=gold-'$cost' where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - } else { - $cost = Util::round(getItemCost($general['weap']) / 2); - $josaUl = JosaUtil::pick(getWeapName($general['weap']), '을'); - $log[] = "●{$admin['month']}월:".getWeapName($general['weap'])."{$josaUl} 판매했습니다. <1>$date"; - $query = "update general set resturn='SUCCESS',weap='0',gold=gold+'$cost' where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - } - } elseif($isweap == 1) { - if($type != 0) { - $josaUl = JosaUtil::pick(getBookName($type), '을'); - $log[] = "●{$admin['month']}월:".getBookName($type)."{$josaUl} 구입했습니다. <1>$date"; - $query = "update general set resturn='SUCCESS',book='$type',gold=gold-'$cost' where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - } else { - $cost = Util::round(getItemCost($general['book']) / 2); - $josaUl = JosaUtil::pick(getBookName($general['book']), '을'); - $log[] = "●{$admin['month']}월:".getBookName($general['book'])."{$josaUl} 판매했습니다. <1>$date"; - $query = "update general set resturn='SUCCESS',book='0',gold=gold+'$cost' where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - } - } elseif($isweap == 2) { - if($type != 0) { - $josaUl = JosaUtil::pick(getHorseName($type), '을'); - $log[] = "●{$admin['month']}월:".getHorseName($type)."{$josaUl} 구입했습니다. <1>$date"; - $query = "update general set resturn='SUCCESS',horse='$type',gold=gold-'$cost' where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - } else { - $cost = Util::round(getItemCost($general['horse']) / 2); - $josaUl = JosaUtil::pick(getHorseName($general['horse']), '을'); - $log[] = "●{$admin['month']}월:".getHorseName($general['horse'])."{$josaUl} 판매했습니다. <1>$date"; - $query = "update general set resturn='SUCCESS',horse='0',gold=gold+'$cost' where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - } - } elseif($isweap == 3) { - if($type != 0) { - $josaUl = JosaUtil::pick(getItemName($type), '을'); - $log[] = "●{$admin['month']}월:".getItemName($type)."{$josaUl} 구입했습니다. <1>$date"; - $query = "update general set resturn='SUCCESS',item='$type',gold=gold-'$cost' where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - } else { - $cost = Util::round(getItemCost2($general['item']) / 2); - $josaUl = JosaUtil::pick(getItemName($general['item']), '을'); - $log[] = "●{$admin['month']}월:".getItemName($general['item'])."{$josaUl} 판매했습니다. <1>$date"; - $query = "update general set resturn='SUCCESS',item='0',gold=gold+'$cost' where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - } - } - } - - $exp = 10; - $ded = 0; - - // 성격 보정 - $exp = CharExperience($exp, $general['personal']); - $ded = CharDedication($ded, $general['personal']); - - // 명성 상승 - $query = "update general set experience=experience+'$exp' where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - - pushGenLog($general, $log); -} - -function process_49(&$general) { - $db = DB::db(); - $gameStor = KVStorage::getStorage($db, 'game_env'); - $connect=$db->get(); - - $log = []; - $alllog = []; - $history = []; - - $date = substr($general['turntime'],11,5); - - $admin = $gameStor->getValues(['year', 'month']); - - $nation = getNationStaticInfo($general['nation']); - - $city = getCity($general['city']); - - $command = DecodeCommand($general['turn0']); - $type = $command[2]; - $amount = $command[1]; - $amount *= 100; - - if($type != 1 && $type != 2) { $type = 1; } - if($amount < 100) { $amount = 100; } - elseif($amount > 10000) { $amount = 10000; } - - if($city['trade'] == 0 && $general['npc'] >= 2) { - $city['trade'] = 100; - } - - // 거상 f배 이득시 금 계산 - // a : 쌀, b : 물가, f : 배수, c : 금 - // (0.7 ~1.3) : c = a((1+f)b-f) - // (0.99~1.01) : c = a((1-f)b+f) - if($type == 1) { - $dtype = "군량 판매"; - if($general['rice'] < $amount) { $amount = $general['rice']; } - $cost = $amount * $city['trade'] / 100; - $tax = $cost * GameConst::$exchangeFee; - $cost = $cost - $tax; - } elseif($type == 2) { - $dtype = "군량 구입"; - $cost = $amount * $city['trade'] / 100; - $tax = $cost * GameConst::$exchangeFee; - $cost = $cost + $tax; - if($general['gold'] < $cost) { - $cost = $general['gold']; - $tax = $cost * GameConst::$exchangeFee; - $amount = ($cost-$tax) * 100 / $city['trade']; - } - } - - $cost = Util::round($cost); - $amount = Util::round($amount); - $tax = Util::round($tax); - - if($city['trade'] == 0 && $general['npc'] < 2) { - $log[] = "●{$admin['month']}월:도시에 상인이 없습니다. $dtype 실패. <1>$date"; - } elseif($general['nation'] != $city['nation'] && $nation['level'] != 0) { - $log[] = "●{$admin['month']}월:아국이 아닙니다. $dtype 실패. <1>$date"; - } elseif($city['supply'] == 0) { - $log[] = "●{$admin['month']}월:고립된 도시입니다. $dtype 실패. <1>$date"; - } elseif($type == 1 && $general['rice'] <= 0) { - $log[] = "●{$admin['month']}월:군량이 없습니다. $dtype 실패. <1>$date"; - } elseif($type == 2 && $general['gold'] <= 0) { - $log[] = "●{$admin['month']}월:자금이 없습니다. $dtype 실패. <1>$date"; - } else { - // 판매 - if($type == 1) { - $log[] = "●{$admin['month']}월:군량 $amount을 팔아 자금 $cost을 얻었습니다. <1>$date"; - // 군량 감소 - $query = "update general set rice=rice-{$amount} where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - // 자금 증가 - $query = "update general set gold=gold+{$cost} where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - // 구입 - } elseif($type == 2) { - $log[] = "●{$admin['month']}월:군량 $amount을 사서 자금 $cost을 썼습니다. <1>$date"; - // 군량 증가 - $query = "update general set rice=rice+{$amount} where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - // 자금 감소 - $query = "update general set gold=gold-{$cost} where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - } - - // 세금 국고로 - $query = "update nation set gold=gold+'$tax' where nation='{$general['nation']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - - $exp = 30; - $ded = 50; - - // 성격 보정 - $exp = CharExperience($exp, $general['personal']); - $ded = CharDedication($ded, $general['personal']); - - // 공헌도, 명성 상승 - $query = "update general set resturn='SUCCESS',dedication=dedication+'$ded', experience=experience+'$exp' where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - - // 경험치 상승 - switch(Util::choiceRandomUsingWeight([$general['leader'], $general['power'], $general['intel']])) { - case 0: - $general['leader2']++; - $query = "update general set leader2='{$general['leader2']}' where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - break; - case 1: - $general['power2']++; - $query = "update general set power2='{$general['power2']}' where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - break; - case 2: - $general['intel2']++; - $query = "update general set intel2='{$general['intel2']}' where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - break; - } - - $log = checkAbility($general, $log); - } - - pushGenLog($general, $log); -} diff --git a/hwe/sammo/Command/General/che_군량매매.php b/hwe/sammo/Command/General/che_군량매매.php new file mode 100644 index 00000000..266adac5 --- /dev/null +++ b/hwe/sammo/Command/General/che_군량매매.php @@ -0,0 +1,178 @@ +'명마', + 'weap'=>'무기', + 'book'=>'서적', + 'item'=>'도구', + ]; + + protected function init(){ + + $general = $this->generalObj; + + $this->setCity(); + $this->setNation(); + + + + $this->runnableConstraints=[ + ['ReqCityTrader', $general->getVar('npc')], + ['OccupiedCity', true], + ['SuppliedCity'], + ]; + + if($this->arg['buyRice']){ + $this->runnableConstraints[] = ['ReqGeneralGold', 1]; + } + else{ + $this->runnableConstraints[] = ['ReqGeneralRice', 1]; + } + } + + protected function argTest():bool{ + $buyRice = $this->arg['buyRice']??null; + if(!is_bool($buyRice)){ + return false; + } + $amount = $this->arg['amount']??null; + if(!is_int($amount)){ + return false; + } + $amount = Util::valueFit($amount, 100, 10000); + + $this->arg = [ + 'buyRice'=>$buyRice, + 'amount'=>$amount + ]; + 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; + $tradeRate = $this->city['trade']; + $date = substr($general->getVar('turntime'),11,5); + + $buyRice = $this->arg['buyRice']; + + if($tradeRate === null){ + if($general->getVar('npc') >= 2){ + $tradeRate = 1.0; + } + else{ + throw new MustNotBeReachedException(); + } + } + else{ + $tradeRate /= 100; + } + + if($buyRice){ + $buyKey = 'rice'; + $sellKey = 'gold'; + $sellAmount = Util::valueFit($this->arg['amount'] * $tradeRate, null, $general->getVar('gold')); + $tax = $sellAmount * GameConst::$exchangeFee; + if($sellAmount + $tax > $general->getVar('gold')){ + $sellAmount *= $general->getVar('gold') / ($sellAmount + $tax); + $tax = $general->getVar('gold') - $sellAmount; + } + $buyAmount = $sellAmount / $tradeRate; + $sellAmount += $tax; + } + else{ + $buyKey = 'gold'; + $sellKey = 'rice'; + $sellAmount = Util::valueFit($this->arg['amount'], null, $general->getVar('rice')); + $buyAmount = $sellAmount * $tradeRate; + $tax = $buyAmount * GameConst::$exchangeFee; + $buyAmount -= $tax; + } + + $logger = $general->getLogger(); + + $buyAmountText = number_format($buyAmount); + $sellAmountText = number_format($sellAmount); + + if($buyRice){ + $logger->pushGeneralActionLog("군량 {$buyAmountText}을 사서 자금 {$sellAmountText}을 썼습니다. <1>$date"); + } + else{ + $logger->pushGeneralActionLog("군량 {$sellAmountText}을 팔아 자금 {$buyAmountText}을 얻었습니다. <1>$date"); + } + + $general->increaseVar($buyKey, $buyAmount); + $general->increaseVarWithLimit($sellKey, $sellAmount, 0); + + $db->update('nation', [ + 'gold'=>$db->sqleval('gold + %i', $tax) + ], 'nation=%i', $general->getNationID()); + + $exp = 30; + $ded = 50; + + $exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp); + $ded = $general->onPreGeneralStatUpdate($general, 'dedication', $ded); + + $incStat = Util::choiceRandomUsingWeight([ + 'leader2'=>$general->getLeadership(false, false, false, false), + 'power2'=>$general->getPower(false, false, false, false), + 'intel2'=>$general->getIntel(false, false, false, false) + ]); + + $general->increaseVar('experience', $exp); + $general->increaseVar('dedication', $ded); + $general->increaseVar($incStat, 1); + + $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); + $general->checkStatChange(); + $general->applyDB($db); + + return true; + } + + +} \ No newline at end of file diff --git a/hwe/sammo/Command/General/che_장비매매.php b/hwe/sammo/Command/General/che_장비매매.php index 4f882c56..82450a7f 100644 --- a/hwe/sammo/Command/General/che_장비매매.php +++ b/hwe/sammo/Command/General/che_장비매매.php @@ -84,6 +84,10 @@ class che_장비매매 extends Command\GeneralCommand{ } public function getCost():array{ + if(!$this->isArgValid){ + return [0, 0]; + } + $itemType = $this->arg['itemType']; $itemCode = $this->arg['itemCode']; if($itemType == 'item'){ diff --git a/hwe/sammo/Command/General/che_징병.php b/hwe/sammo/Command/General/che_징병.php index 601627db..bc3e40c4 100644 --- a/hwe/sammo/Command/General/che_징병.php +++ b/hwe/sammo/Command/General/che_징병.php @@ -105,9 +105,8 @@ class che_징병 extends Command\GeneralCommand{ } public function getCost():array{ - if($this->reqCrewType === null || $this->reqCrew){ + if(!$this->isArgValid){ return [0, 0]; - //throw new \RuntimeException('요구사항 초기화가 이뤄지지 않았음'); } $reqGold = $this->reqCrewType->costWithTech($this->nation['tech'], $this->reqCrew); $reqGold = $general->onCalcDomestic('징병', 'cost', $reqGold, ['armType'=>$this->reqCrewType->armType]);