자동 모병, 자동 징병을 자동 무작위 모병, 자동 무작위 징병으로 변경

This commit is contained in:
2020-01-30 01:39:47 +09:00
parent 09e693cb74
commit 37ea64346c
+54 -19
View File
@@ -162,15 +162,17 @@ function SetCrew($no, $nationID, $personal, $gold, $leader, $genType, $tech, $de
$cities = []; $cities = [];
$regions = []; $regions = [];
foreach($db->queryAllLists('SELECT city, region FROM city WHERE nation = %i', $nationID) as [$cityID, $regionID]){ foreach(CityConst::all() as $city){
$cities[$cityID] = true; $cities[$city->id] = 1;
$regions[$regionID] = true; $regions[$city->region] = 1;
} }
$gameStor = KVStorage::getStorage($db, 'game_env'); $gameStor = KVStorage::getStorage($db, 'game_env');
[$startyear, $year] = $gameStor->getValuesAsArray(['startyear', 'year']); [$startyear, $year] = $gameStor->getValuesAsArray(['startyear', 'year']);
$relYear = Util::valueFit($year-$startyear, 0); $relYear = Util::valueFit($year-$startyear, 0);
$chosenCrewType = null;
$maxCost = 0;
switch($genType) { switch($genType) {
case 0: //무장 case 0: //무장
case 2: //무내정장 case 2: //무내정장
@@ -193,28 +195,52 @@ function SetCrew($no, $nationID, $personal, $gold, $leader, $genType, $tech, $de
} }
} }
$types = [];
switch($sel) { switch($sel) {
case 0: case 0:
foreach(GameUnitConst::byType(GameUnitConst::T_FOOTMAN) as $crewtype){ foreach(GameUnitConst::byType(GameUnitConst::T_FOOTMAN) as $crewtype){
if($crewtype->isValid($cities, $regions, $relYear, $tech)){ if(!$crewtype->isValid($cities, $regions, $relYear, $tech)){
$types[] = $crewtype->id; continue;
}
if($chosenCrewType === null){
$chosenCrewType = $crewtype->id;
$maxCost = $crewtype->cost;
}
if($maxCost < $crewtype->cost){
$chosenCrewType = $crewtype->id;
$maxCost = $crewtype->cost;
} }
} }
break; break;
case 1: case 1:
foreach(GameUnitConst::byType(GameUnitConst::T_ARCHER) as $crewtype){ foreach(GameUnitConst::byType(GameUnitConst::T_ARCHER) as $crewtype){
if($crewtype->isValid($cities, $regions, $relYear, $tech)){ if(!$crewtype->isValid($cities, $regions, $relYear, $tech)){
$types[] = $crewtype->id; continue;
}
if($chosenCrewType === null){
$chosenCrewType = $crewtype->id;
$maxCost = $crewtype->cost;
}
if($maxCost < $crewtype->cost){
$chosenCrewType = $crewtype->id;
$maxCost = $crewtype->cost;
} }
} }
break; break;
case 2: case 2:
foreach(GameUnitConst::byType(GameUnitConst::T_CAVALRY) as $crewtype){ foreach(GameUnitConst::byType(GameUnitConst::T_CAVALRY) as $crewtype){
if($crewtype->isValid($cities, $regions, $relYear, $tech)){ if(!$crewtype->isValid($cities, $regions, $relYear, $tech)){
$types[] = $crewtype->id; continue;
}
if($chosenCrewType === null){
$chosenCrewType = $crewtype->id;
$maxCost = $crewtype->cost;
}
if($maxCost < $crewtype->cost){
$chosenCrewType = $crewtype->id;
$maxCost = $crewtype->cost;
} }
} }
break; break;
@@ -223,19 +249,28 @@ function SetCrew($no, $nationID, $personal, $gold, $leader, $genType, $tech, $de
case 1: //지장 case 1: //지장
case 3: //지내정장 case 3: //지내정장
foreach(GameUnitConst::byType(GameUnitConst::T_WIZARD) as $crewtype){ foreach(GameUnitConst::byType(GameUnitConst::T_WIZARD) as $crewtype){
if($crewtype->isValid($cities, $regions, $relYear, $tech)){ if(!$crewtype->isValid($cities, $regions, $relYear, $tech)){
$types[] = $crewtype->id; continue;
}
if($chosenCrewType === null){
$chosenCrewType = $crewtype->id;
$maxCost = $crewtype->cost;
}
if($maxCost < $crewtype->cost){
$chosenCrewType = $crewtype->id;
$maxCost = $crewtype->cost;
} }
} }
break; break;
} }
if($types){ if($chosenCrewType){
if(!$allowedAction->randomRecruit && in_array($currentCrewType, $types) && ($currentCrewType != GameUnitConst::DEFAULT_CREWTYPE && $currentCrewType != $types[0])){ if(!$allowedAction->randomRecruit && $currentCrewType != GameUnitConst::DEFAULT_CREWTYPE){
$type = $currentCrewType; $type = $currentCrewType;
} }
else{ else{
$type = Util::choiceRandom($types); $type = $chosenCrewType;
} }
} }
@@ -254,10 +289,10 @@ function SetCrew($no, $nationID, $personal, $gold, $leader, $genType, $tech, $de
if($leader < $crew) { $crew = $leader; } if($leader < $crew) { $crew = $leader; }
if($allowedAction->recruit_high && $crew * $cost * 6 < $gold){ if($allowedAction->recruit_high && $crew * $cost * 6 < $gold){
$command = EncodeCommand(0, $type, $crew, 12); $command = EncodeCommand(0, $type, $crew, 19);
} }
else{ else{
$command = EncodeCommand(0, $type, $crew, 11); $command = EncodeCommand(0, $type, $crew, 18);
} }
$query = "update general set turn0='$command' where no='$no'"; $query = "update general set turn0='$command' where no='$no'";