diff --git a/hwe/sammo/Event/Action/AssignGeneralSpeciality.php b/hwe/sammo/Event/Action/AssignGeneralSpeciality.php new file mode 100644 index 00000000..137c4974 --- /dev/null +++ b/hwe/sammo/Event/Action/AssignGeneralSpeciality.php @@ -0,0 +1,90 @@ +query('SELECT no,name,nation,leadership,strength,intel,aux from general where specage<=age and special=%s', GameConst::$defaultSpecialDomestic) as $general) { + $generalID = $general['no']; + $special = SpecialityHelper::pickSpecialDomestic( + $rng, + $general, + (Json::decode($general['aux'])['prev_types_special']) ?? [] + ); + $specialClass = buildGeneralSpecialDomesticClass($special); + $specialText = $specialClass->getName(); + $db->update('general', [ + 'special' => $special + ], 'no=%i', $generalID); + + $logger = new ActionLogger($generalID, $general['nation'], $year, $month); + + $josaUl = JosaUtil::pick($specialText, '을'); + $logger->pushGeneralActionLog("특기 【{$specialText}】{$josaUl} 익혔습니다!", ActionLogger::PLAIN); + $logger->pushGeneralHistoryLog("특기 【{$specialText}】{$josaUl} 습득"); + } + + foreach ($db->query('SELECT no,name,nation,leadership,strength,intel,npc,dex1,dex2,dex3,dex4,dex5,aux from general where specage2<=age and special2=%s', GameConst::$defaultSpecialWar) as $general) { + $generalID = $general['no']; + $generalAux = Json::decode($general['aux']); + + $updateVars = []; + if (key_exists('inheritSpecificSpecialWar', $generalAux)) { + $special2 = $generalAux['inheritSpecificSpecialWar']; + unset($generalAux['inheritSpecificSpecialWar']); + $updateVars['aux'] = Json::encode($generalAux); + } else { + $special2 = SpecialityHelper::pickSpecialWar( + $rng, + $general, + ($generalAux['prev_types_special2']) ?? [] + ); + } + + $specialClass = buildGeneralSpecialWarClass($special2); + $specialText = $specialClass->getName(); + + $updateVars['special2'] = $special2; + $db->update('general', $updateVars, 'no=%i', $general['no']); + + $logger = new ActionLogger($generalID, $general['nation'], $year, $month); + + $josaUl = JosaUtil::pick($specialText, '을'); + $logger->pushGeneralActionLog("특기 【{$specialText}】{$josaUl} 익혔습니다!", ActionLogger::PLAIN); + $logger->pushGeneralHistoryLog("특기 【{$specialText}】{$josaUl} 습득"); + } + } +} diff --git a/hwe/sammo/Event/Action/NewYear.php b/hwe/sammo/Event/Action/NewYear.php new file mode 100644 index 00000000..2eff492c --- /dev/null +++ b/hwe/sammo/Event/Action/NewYear.php @@ -0,0 +1,30 @@ +pushGlobalActionLog("{$year}년이 되었습니다."); + $logger->flush(); //TODO: globalAction류는 전역에서 관리하는것이 좋을 듯. + + $db = DB::db(); + + //나이와 호봉 증가 + $db->update('general', [ + 'age' => $db->sqleval('age+1'), + ], true); + + $db->update('general', [ + 'belong' => $db->sqleval('belong+1') + ], 'nation != 0'); + } +} diff --git a/hwe/sammo/Event/Action/RaiseDisaster.php b/hwe/sammo/Event/Action/RaiseDisaster.php new file mode 100644 index 00000000..28cc3b9a --- /dev/null +++ b/hwe/sammo/Event/Action/RaiseDisaster.php @@ -0,0 +1,159 @@ +update('city', [ + 'state' => 0, + ], 'state <= 10'); + + // 초반 3년은 스킵 + if ($startYear + 3 > $year) return; + + $boomingRate = [ + 1 => 0, + 4 => 0.25, + 7 => 0.25, + 10 => 0 + ]; + + $isGood = $rng->nextBool($boomingRate[$month]); + + + $targetCityList = []; + + foreach ($db->query('SELECT city,name,secu,secu_max FROM city') as $city) { + //호황 발생 도시 선택 ( 기본 2% ) + //재해 발생 도시 선택 ( 기본 6% ) + if ($isGood) { + $raiseProp = 0.02 + ($city['secu'] / $city['secu_max']) * 0.05; // 2 ~ 7% + } else { + $raiseProp = 0.06 - ($city['secu'] / $city['secu_max']) * 0.05; // 1 ~ 6% + } + + if ($rng->nextBool($raiseProp)) { + $targetCityList[] = $city; + } + } + + if (!$targetCityList) { + return; + } + + $targetCityNames = "" . join(' ', Util::squeezeFromArray($targetCityList, 'name')) . ""; + $disasterTextList = [ + 1 => [ + ['【재난】', 4, '역병이 발생하여 도시가 황폐해지고 있습니다.'], + ['【재난】', 5, '지진으로 피해가 속출하고 있습니다.'], + ['【재난】', 3, '추위가 풀리지 않아 얼어죽는 백성들이 늘어나고 있습니다.'], + ['【재난】', 9, '황건적이 출현해 도시를 습격하고 있습니다.'], + ], + 4 => [ + ['【재난】', 7, '홍수로 인해 피해가 급증하고 있습니다.'], + ['【재난】', 5, '지진으로 피해가 속출하고 있습니다.'], + ['【재난】', 6, '태풍으로 인해 피해가 속출하고 있습니다.'], + ], + 7 => [ + ['【재난】', 8, '메뚜기 떼가 발생하여 도시가 황폐해지고 있습니다.'], + ['【재난】', 5, '지진으로 피해가 속출하고 있습니다.'], + ['【재난】', 8, '흉년이 들어 굶어죽는 백성들이 늘어나고 있습니다.'], + ], + 10 => [ + ['【재난】', 3, '혹한으로 도시가 황폐해지고 있습니다.'], + ['【재난】', 5, '지진으로 피해가 속출하고 있습니다.'], + ['【재난】', 3, '눈이 많이 쌓여 도시가 황폐해지고 있습니다.'], + ['【재난】', 9, '황건적이 출현해 도시를 습격하고 있습니다.'], + ] + ]; + + $boomingTextList = [ + 1 => null, + 4 => [ + ['【호황】', 2, '호황으로 도시가 번창하고 있습니다.'], + ], + 7 => [ + ['【풍작】', 1, '풍작으로 도시가 번창하고 있습니다.'], + ], + 10 => null + ]; + + [$logTitle, $stateCode, $logBody] = $rng->choice(($isGood ? $boomingTextList : $disasterTextList)[$month]); + + $logger = new ActionLogger(0, 0, $year, $month, false); + + $logger->pushGlobalHistoryLog("{$logTitle}{$targetCityNames}에 {$logBody}"); + $logger->flush(); + + if (!$isGood) { + $generalListByCity = Util::arrayGroupBy($db->query('SELECT no, name, nation, city, officer_level, injury, leadership, strength, intel, horse, weapon, book, item, crew, crewtype, atmos, train, special, special2 FROM general WHERE city IN %li', Util::squeezeFromArray($targetCityList, 'city')), 'city'); + //NOTE: 쿼리 1번이지만 복잡하기 vs 쿼리 여러번이지만 조금 더 깔끔하기 + foreach ($targetCityList as $city) { + $affectRatio = Util::valueFit($city['secu'] / $city['secu_max'] / 0.8, 0, 1); + $affectRatio = 0.8 + $affectRatio * 0.15; + + $db->update('city', [ + 'state' => $stateCode, + 'pop' => $db->sqleval('pop * %d', $affectRatio), + 'trust' => $db->sqleval('trust * %d', $affectRatio), + 'agri' => $db->sqleval('agri * %d', $affectRatio), + 'comm' => $db->sqleval('comm * %d', $affectRatio), + 'secu' => $db->sqleval('secu * %d', $affectRatio), + 'def' => $db->sqleval('def * %d', $affectRatio), + 'wall' => $db->sqleval('wall * %d', $affectRatio), + ], 'city = %i', $city['city']); + + $generalList = array_map( + function ($rawGeneral) use ($city, $year, $month) { + return new General($rawGeneral, null, $city, null, $year, $month, false); + }, + $generalListByCity[$city['city']] ?? [] + ); + + SabotageInjury($rng, $generalList, '재난'); + } + } else { + foreach ($targetCityList as $city) { + $affectRatio = Util::valueFit($city['secu'] / $city['secu_max'] / 0.8, 0, 1); + $affectRatio = 1.01 + $affectRatio * 0.04; + + $db->update('city', [ + 'state' => $stateCode, + 'pop' => $db->sqleval('least(pop * %d, pop_max)', $affectRatio), + 'trust' => $db->sqleval('least(trust * %d, 100)', $affectRatio), + 'agri' => $db->sqleval('least(agri * %d, agri_max)', $affectRatio), + 'comm' => $db->sqleval('least(comm * %d, comm_max)', $affectRatio), + 'secu' => $db->sqleval('least(secu * %d, secu_max)', $affectRatio), + 'def' => $db->sqleval('least(def * %d, def_max)', $affectRatio), + 'wall' => $db->sqleval('least(wall * %d, wall_max)', $affectRatio), + ], 'city = %i', $city['city']); + } + } + } +} diff --git a/hwe/sammo/Event/Action/RandomizeCityTradeRate.php b/hwe/sammo/Event/Action/RandomizeCityTradeRate.php new file mode 100644 index 00000000..32fec945 --- /dev/null +++ b/hwe/sammo/Event/Action/RandomizeCityTradeRate.php @@ -0,0 +1,48 @@ +query('SELECT city,level FROM city') as $city) { + //시세 + $prob = [ + 1 => 0, + 2 => 0, + 3 => 0, + 4 => 0.2, + 5 => 0.4, + 6 => 0.6, + 7 => 0.8, + 8 => 1 + ][$city['level']]; + if ($prob > 0 && $rng->nextBool($prob)) { + $trade = $rng->nextRangeInt(95, 105); + } else { + $trade = null; + } + $db->update('city', [ + 'trade' => $trade + ], 'city=%i', $city['city']); + } + } +} diff --git a/hwe/sammo/Event/Action/ResetOfficerLock.php b/hwe/sammo/Event/Action/ResetOfficerLock.php new file mode 100644 index 00000000..d4ba4e6d --- /dev/null +++ b/hwe/sammo/Event/Action/ResetOfficerLock.php @@ -0,0 +1,22 @@ +update('nation', [ + 'chief_set' => 0, + ], true); + //관직 변경 제한 해제 + $db->update('city', [ + 'officer_set' => 0, + ], true); + } +}