전투 종료 코드 구현(마무리?)

This commit is contained in:
2018-08-20 23:57:36 +09:00
parent 7cfd8c7f79
commit 513124161e
3 changed files with 103 additions and 38 deletions
+35 -16
View File
@@ -10,7 +10,7 @@ function processWar(array $rawAttacker, array $rawDefenderCity){
$attackerNationID = $rawAttacker['nation']; $attackerNationID = $rawAttacker['nation'];
$defenderNationID = $rawDefenderCity['nation']; $defenderNationID = $rawDefenderCity['nation'];
$rawAttackerNation = $db->queryFullColumns('SELECT nation,`level`,`name`,capital,totaltech,gencount,tech,`type`,gold,rice FROM nation WHERE nation = %i', $attackerNationID); $rawAttackerNation = $db->queryFullColumns('SELECT nation,`level`,`name`,capital,totaltech,gennum,tech,`type`,gold,rice FROM nation WHERE nation = %i', $attackerNationID);
if($defenderNationID == 0){ if($defenderNationID == 0){
$rawDefenderNation = [ $rawDefenderNation = [
@@ -23,11 +23,11 @@ function processWar(array $rawAttacker, array $rawDefenderCity){
'type'=>0, 'type'=>0,
'tech'=>0, 'tech'=>0,
'totaltech'=>0, 'totaltech'=>0,
'gencount'=>1 'gennum'=>1
]; ];
} }
else{ else{
$rawDefenderNation = $db->queryFullColumns('SELECT nation,`level`,`name`,capital,totaltech,gencount,tech,`type`,gold,rice FROM nation WHERE nation = %i', $defenderNationID); $rawDefenderNation = $db->queryFullColumns('SELECT nation,`level`,`name`,capital,totaltech,gennum,tech,`type`,gold,rice FROM nation WHERE nation = %i', $defenderNationID);
} }
$gameStor = KVStorage::getStorage($db, 'game_env'); $gameStor = KVStorage::getStorage($db, 'game_env');
@@ -73,15 +73,19 @@ function processWar(array $rawAttacker, array $rawDefenderCity){
$updateAttackerNation = []; $updateAttackerNation = [];
$updateDefenderNation = []; $updateDefenderNation = [];
if($city->getPhase() > 0 && $city->getVar('supply')){ if($city->getVar('supply')){
$rice = $city->getKilled() / 10 * 0.8; if($city->getPhase() > 0){
$rice *= \sammo\getCrewtypeRice($city->getCrewType(), 0); $rice = $city->getKilled() / 100 * 0.8;
$rice *= $cityRate / 100 - 0.2; $rice *= $city->getCrewType()->rice;
$rice *= getTechCost($rawDefenderNation['tech']);
$updateDefenderNation['rice'] = max(0, $rawDefenderNation['rice'] - $rice); $rice *= $cityRate / 100 - 0.2;
} Util::setRound($rice);
else if($conquerCity && $city->getVar('supply')){
$updateDefenderNation['rice'] = $rawDefenderNation['rice'] + $rice; $updateDefenderNation['rice'] = max(0, $rawDefenderNation['rice'] - $rice);
}
else if($conquerCity){
$updateDefenderNation['rice'] = $rawDefenderNation['rice'] + 500;
}
} }
$totalDead = $attacker->getKilled() + $attacker->getDead(); $totalDead = $attacker->getKilled() + $attacker->getDead();
@@ -97,14 +101,21 @@ function processWar(array $rawAttacker, array $rawDefenderCity){
$attackerIncTech = $attacker->getDead() * 0.01 * getNationTechMultiplier($rawAttackerNation['type']); $attackerIncTech = $attacker->getDead() * 0.01 * getNationTechMultiplier($rawAttackerNation['type']);
$defenderIncTech = $attacker->getKilled() * 0.01 * getNationTechMultiplier($rawDefenderNation['type']); $defenderIncTech = $attacker->getKilled() * 0.01 * getNationTechMultiplier($rawDefenderNation['type']);
if(TechLimit($startYear, $year, $rawAttackerNation['tech'])){
$attackerIncTech /= 4;
}
if(TechLimit($startYear, $year, $rawDefenderNation['tech'])){
$defenderIncTech /= 4;
}
$attackerTotalTech = $rawAttackerNation['totaltech'] + $attackerIncTech; $attackerTotalTech = $rawAttackerNation['totaltech'] + $attackerIncTech;
$defenderTotalTech = $rawDefenderNation['totaltech'] + $defenderIncTech; $defenderTotalTech = $rawDefenderNation['totaltech'] + $defenderIncTech;
$updateAttackerNation['totaltech'] = Utill::round($attackerTotalTech); $updateAttackerNation['totaltech'] = Utill::round($attackerTotalTech);
$updateDefenderNation['totaltech'] = Utill::round($defenderTotalTech); $updateDefenderNation['totaltech'] = Utill::round($defenderTotalTech);
$updateAttackerNation['tech'] = Util::round($attackerTotalTech / $rawAttackerNation['gencount']); $updateAttackerNation['tech'] = Util::round($attackerTotalTech / max(GameConst::$initialNationGenLimit, $rawAttackerNation['gennum']));
$updateDefenderNation['tech'] = Util::round($defenderTotalTech / $rawDefenderNation['gencount']); $updateDefenderNation['tech'] = Util::round($defenderTotalTech / max(GameConst::$initialNationGenLimit, $rawDefenderNation['gennum']));
$db->update('nation', $updateAttackerNation, 'nation=%i', $attackerNationID); $db->update('nation', $updateAttackerNation, 'nation=%i', $attackerNationID);
$db->update('nation', $updateDefenderNation, 'nation=%i', $defenderNationID); $db->update('nation', $updateDefenderNation, 'nation=%i', $defenderNationID);
@@ -179,6 +190,7 @@ function processWar_NG(
for($currPhase = 0; $currPhase < $attacker->getMaxPhase(); $currPhase+=1){ for($currPhase = 0; $currPhase < $attacker->getMaxPhase(); $currPhase+=1){
$battleBegin = true; $battleBegin = true;
if($defender === null){ if($defender === null){
$defender = $city; $defender = $city;
@@ -193,6 +205,11 @@ function processWar_NG(
$defender->addLose(); $defender->addLose();
$defender->heavyDecreseWealth(); $defender->heavyDecreseWealth();
$logger->pushGlobalActionLog("병량 부족으로 <G><b>{$defender->getName()}</b></>의 수비병들이 <R>패퇴</>합니다.");
$josaUl = JosaUtil::pick($defender->getName(), '을');
$josaYi = JosaUtil::pick($defender->getNationVar('name'), '이');
$logger->pushGlobalHistoryLog("<M><b>【패퇴】</b></><D><b>{$defender->getNationVar('name')}</b></>{$josaYi} 병량 부족으로 <G><b>{$defender->getName()}</b></>{$josaUl} 뺏기고 말았습니다.");
$conquerCity = true; $conquerCity = true;
break; break;
} }
@@ -208,16 +225,18 @@ function processWar_NG(
$josaWa = JosaUtil::pick($attacker->getCrewTypeName(), '와'); $josaWa = JosaUtil::pick($attacker->getCrewTypeName(), '와');
$josaYi = JosaUtil::pick($defender->getCrewTypeName(), '이'); $josaYi = JosaUtil::pick($defender->getCrewTypeName(), '이');
$logger->pushGlobalActionLog("<Y>{$attacker->getName()}</>의 {$attacker->getCrewTypeName()}{$josaWa} <Y>{$defender->getName()}</>의 {$defender->getCrewTypeName()}{$josaYi} 대결합니다."); $logger->pushGlobalActionLog("<Y>{$attacker->getName()}</>의 {$attacker->getCrewTypeName()}{$josaWa} <Y>{$defender->getName()}</>의 {$defender->getCrewTypeName()}{$josaYi} 대결합니다.");
$josaUl = JosaUtil::pick($defender->getCrewTypeName(), '을');
$josaRo = JosaUtil::pick($attacker->getCrewTypeName(), '로'); $josaRo = JosaUtil::pick($attacker->getCrewTypeName(), '로');
$josaUl = JosaUtil::pick($defender->getCrewTypeName(), '을');
$attacker->getLogger()->pushGeneralActionLog("{$attacker->getCrewTypeName()}{$josaRo} <Y>{$defender->name}</>의 {$defender->getCrewTypeName()}{$josaUl} <M>공격</>합니다."); $attacker->getLogger()->pushGeneralActionLog("{$attacker->getCrewTypeName()}{$josaRo} <Y>{$defender->name}</>의 {$defender->getCrewTypeName()}{$josaUl} <M>공격</>합니다.");
$josaRo = JosaUtil::pick($defender->getCrewTypeName(), '로');
$josaUl = JosaUtil::pick($attacker->getCrewTypeName(), '을');
$defender->getLogger()->pushGeneralActionLog("{$defender->getCrewTypeName()}{$josaRo} <Y>{$attacker->name}</>의 {$attacker->getCrewTypeName()}{$josaUl} <M>수비</>합니다."); $defender->getLogger()->pushGeneralActionLog("{$defender->getCrewTypeName()}{$josaRo} <Y>{$attacker->name}</>의 {$attacker->getCrewTypeName()}{$josaUl} <M>수비</>합니다.");
} }
else{ else{
$josaYi = JosaUtil::pick($attacker->getName(), '이'); $josaYi = JosaUtil::pick($attacker->getName(), '이');
$josaRo = JosaUtil::pick($attacker->getCrewTypeName(), '로'); $josaRo = JosaUtil::pick($attacker->getCrewTypeName(), '로');
$logger->pushGlobalActionLog("<Y>{$attacker->getName()}</>{$josaYi} {$attacker->getCrewTypeName()}{$josaRo} 성벽을 공격합니다."); $logger->pushGlobalActionLog("<Y>{$attacker->getName()}</>{$josaYi} {$attacker->getCrewTypeName()}{$josaRo} 성벽을 공격합니다.");
$logger->pushGeneralActionLog("<C>●</>{$generalCrewType->name}{$josaRo} 성벽을 <M>공격</>합니다.", ActionLogger::PLAIN); $logger->pushGeneralActionLog("<C>●</>{$attacker->getCrewTypeName()}{$josaRo} 성벽을 <M>공격</>합니다.", ActionLogger::PLAIN);
} }
$defender->useBattleInitItem(); $defender->useBattleInitItem();
+1 -1
View File
@@ -103,7 +103,7 @@ class WarUnitCity extends WarUnit{
$nationID = $oppose->getNationVar('nation'); $nationID = $oppose->getNationVar('nation');
$newConflict = false; $newConflict = false;
$dead = $this->dead; $dead = max(1, $this->dead);
if(!$conflict || $this->getHP() == 0){ // 선타, 막타 보너스 if(!$conflict || $this->getHP() == 0){ // 선타, 막타 보너스
$dead *= 1.05; $dead *= 1.05;
+67 -21
View File
@@ -124,7 +124,7 @@ class WarUnitGeneral extends WarUnit{
$critialRatio += 0.1; $critialRatio += 0.1;
} }
} }
if($specialWar == 71){ else if($specialWar == 71){
$critialRatio += 0.2; $critialRatio += 0.2;
} }
return $critialRatio; return $critialRatio;
@@ -194,7 +194,12 @@ class WarUnitGeneral extends WarUnit{
$specialWar = $this->getSpecialWar(); $specialWar = $this->getSpecialWar();
if($specialWar == 52){ if($specialWar == 53){
if($this->getOppose() instanceof WarUnitCity){
$myWarPowerMultiply *= 2;
}
}
else if($specialWar == 52){
if($this->isAttacker){ if($this->isAttacker){
$myWarPowerMultiply *= 1.20; $myWarPowerMultiply *= 1.20;
} }
@@ -203,8 +208,11 @@ class WarUnitGeneral extends WarUnit{
} }
} }
else if($specialWar == 60 && $this->isAttacker){ else if($specialWar == 60){
$myWarPowerMultiply *= 1.10; if($this->isAttacker){
$myWarPowerMultiply *= 1.10;
}
} }
else if($specialWar == 61){ else if($specialWar == 61){
$myWarPowerMultiply *= 1.10; $myWarPowerMultiply *= 1.10;
@@ -271,8 +279,15 @@ class WarUnitGeneral extends WarUnit{
} }
$expLevel = $this->getVar('explevel'); $expLevel = $this->getVar('explevel');
$warPower /= max(0.01, 1 - $expLevel / 300);
$opposeWarPowerMultiply *= max(0.01, 1 - $expLevel / 300); if($this->getOppose() instanceof WarUnitCity){
$warPower *= 1 + $expLevel / 600;
}
else{
$warPower /= max(0.01, 1 - $expLevel / 300);
$opposeWarPowerMultiply *= max(0.01, 1 - $expLevel / 300);
}
[$specialMyWarPowerMultiply, $specialOpposeWarPowerMultiply] = $this->getWarPowerMultiplyBySpecialWar(); [$specialMyWarPowerMultiply, $specialOpposeWarPowerMultiply] = $this->getWarPowerMultiplyBySpecialWar();
$warPower *= $specialMyWarPowerMultiply; $warPower *= $specialMyWarPowerMultiply;
@@ -349,7 +364,7 @@ class WarUnitGeneral extends WarUnit{
!$this->hasActivateSkill('저격') && !$this->hasActivateSkill('저격') &&
Util::randBool(1/3) Util::randBool(1/3)
) { ) {
$oppose->activateSkill('저격'); $this->activateSkill('저격');
$skillResult = true; $skillResult = true;
} }
@@ -393,7 +408,7 @@ class WarUnitGeneral extends WarUnit{
$result = false; $result = false;
$oppose = $this->getOppose(); $oppose = $this->getOppose();
if($this->hasActivatedSkill('저격')){ if($oppose->hasActivatedSkill('저격')){
$result = true; $result = true;
$oppose->getLogger()->pushGeneralActionLog("상대를 <C>저격</>했다!", ActionLogger::PLAIN); $oppose->getLogger()->pushGeneralActionLog("상대를 <C>저격</>했다!", ActionLogger::PLAIN);
@@ -401,7 +416,7 @@ class WarUnitGeneral extends WarUnit{
$this->getLogger()->pushGeneralActionLog("상대에게 <R>저격</>당했다!", ActionLogger::PLAIN); $this->getLogger()->pushGeneralActionLog("상대에게 <R>저격</>당했다!", ActionLogger::PLAIN);
$this->getLogger()->pushGeneralBattleDetailLog("상대에게 <R>저격</>당했다!", ActionLogger::PLAIN); $this->getLogger()->pushGeneralBattleDetailLog("상대에게 <R>저격</>당했다!", ActionLogger::PLAIN);
$oppose->increaseVarWithLimit('injury', Util::randRangeInt(20, 60), null, 80); $this->increaseVarWithLimit('injury', Util::randRangeInt(20, 60), null, 80);
} }
return $result; return $result;
@@ -469,7 +484,7 @@ class WarUnitGeneral extends WarUnit{
if(!$this->isAttacker){ if(!$this->isAttacker){
$addDex *= 0.9; $addDex *= 0.9;
} }
$this->addDex($this->oppose->getCrewType(), $addDex); $this->addDex($this->getCrewType(), $addDex);
$this->killed += $damage; $this->killed += $damage;
return $this->killed; return $this->killed;
@@ -549,7 +564,7 @@ class WarUnitGeneral extends WarUnit{
} }
if(Util::randBool($magicRatio)){ if(Util::randBool($magicRatio)){
$magicSuccessRatio = 0.3; $magicSuccessRatio = 0.7;
if($specialWar == 40){ if($specialWar == 40){
$magicSuccessRatio += 0.2; $magicSuccessRatio += 0.2;
} }
@@ -563,8 +578,14 @@ class WarUnitGeneral extends WarUnit{
$magicSuccessRatio += 1; $magicSuccessRatio += 1;
} }
$magic = Util::choiceRandom(['위보', '매복', '반목', '화계', '혼란']); if($oppose instanceof WarUnitCity){
$magic = Util::choiceRandom(['급습', '위보',' 혼란']);
}
else{
$magic = Util::choiceRandom(['위보', '매복', '반목', '화계', '혼란']);
}
$this->activateSkill('계략시도', $magic); $this->activateSkill('계략시도', $magic);
if(Util::randBool($magicSuccessRatio)){ if(Util::randBool($magicSuccessRatio)){
$this->activateSkill('계략'); $this->activateSkill('계략');
} }
@@ -574,6 +595,12 @@ class WarUnitGeneral extends WarUnit{
} }
} }
//의술
if($specialWar == 73 && Util::randBool(0.2)){
$this->activateSkill('치료');
$activated = true;
}
return $activated; return $activated;
} }
@@ -585,11 +612,6 @@ class WarUnitGeneral extends WarUnit{
$item = $this->getItem(); $item = $this->getItem();
$crewType = $this->getCrewType(); $crewType = $this->getCrewType();
if($specialWar == 73 && Util::randBool(0.2)){
$this->activateSkill('치료');
$activated = true;
}
if($specialWar == 74 && $oppose->hasActivatedSkill('필살')){ if($specialWar == 74 && $oppose->hasActivatedSkill('필살')){
if($this->isAttacker){ if($this->isAttacker){
if(Util::randBool(1/3)){ if(Util::randBool(1/3)){
@@ -694,16 +716,29 @@ class WarUnitGeneral extends WarUnit{
//계략 세트 //계략 세트
if($this->hasActivatedSkill('계략')){ if($this->hasActivatedSkill('계략')){
$table = [ $tableToGeneral = [
'위보'=>1.2, '위보'=>1.2,
'매복'=>1.4, '매복'=>1.4,
'반목'=>1.6, '반목'=>1.6,
'화계'=>1.8, '화계'=>1.8,
'혼란'=>2.0 '혼란'=>2.0
]; ];
$tableToCity = [
'급습'=>1.2,
'위보'=>1.4,
'혼란'=>1.6
];
if($specialWar == 45){ if($specialWar == 45){
$table['반목'] *= 2; $tableToGeneral['반목'] *= 2;
} }
if($oppose instanceof WarUnitCity){
$table = $tableToCity;
}
else{
$table = $tableToGeneral;
}
foreach($table as $skillKey => $skillMultiply){ foreach($table as $skillKey => $skillMultiply){
if($this->hasActivatedSkill($skillKey)){ if($this->hasActivatedSkill($skillKey)){
$josaUl = \sammo\JosaUtil::pick($skillKey, '을'); $josaUl = \sammo\JosaUtil::pick($skillKey, '을');
@@ -743,13 +778,24 @@ class WarUnitGeneral extends WarUnit{
//계략 실패 세트 //계략 실패 세트
if($this->hasActivatedSkill('계략실패')){ if($this->hasActivatedSkill('계략실패')){
$table = [ $tableToGeneral = [
'위보'=>1.1, '위보'=>1.1,
'매복'=>1.2, '매복'=>1.2,
'반목'=>1.3, '반목'=>1.3,
'화계'=>1.4, '화계'=>1.4,
'혼란'=>1.5 '혼란'=>1.5
]; ];
$tableToCity = [
'급습'=>1.1,
'위보'=>1.2,
'혼란'=>1.3
];
if($oppose instanceof WarUnitCity){
$table = $tableToCity;
}
else{
$table = $tableToGeneral;
}
foreach($table as $skillKey => $skillMultiply){ foreach($table as $skillKey => $skillMultiply){
if($this->hasActivatedSkill($skillKey)){ if($this->hasActivatedSkill($skillKey)){
$josaUl = \sammo\JosaUtil::pick($skillKey, '을'); $josaUl = \sammo\JosaUtil::pick($skillKey, '을');
@@ -840,7 +886,7 @@ class WarUnitGeneral extends WarUnit{
} }
function continueWar(&$noRice):bool{ function continueWar(&$noRice):bool{
if($this->getVar('crew') <= 0){ if($this->getHP() <= 0){
$noRice = false; $noRice = false;
return false; return false;
} }