전투 코드를 모두 generator 기반으로 변경
This commit is contained in:
+28
-12
@@ -270,8 +270,12 @@ function processWar_NG(
|
|||||||
$attacker->setOppose($defender);
|
$attacker->setOppose($defender);
|
||||||
$defender->setOppose($attacker);
|
$defender->setOppose($attacker);
|
||||||
|
|
||||||
$attacker->checkBattleBeginSkill();
|
foreach(Util::zip(
|
||||||
$defender->checkBattleBeginSkill();
|
$attacker->checkBattleBeginSkill(),
|
||||||
|
$defender->checkBattleBeginSkill()
|
||||||
|
) as $b){
|
||||||
|
//doNothing
|
||||||
|
}
|
||||||
|
|
||||||
$attacker->checkBattleBeginItem();
|
$attacker->checkBattleBeginItem();
|
||||||
$defender->checkBattleBeginItem();
|
$defender->checkBattleBeginItem();
|
||||||
@@ -283,21 +287,33 @@ function processWar_NG(
|
|||||||
$attacker->beginPhase();
|
$attacker->beginPhase();
|
||||||
$defender->beginPhase();
|
$defender->beginPhase();
|
||||||
|
|
||||||
$attacker->checkPreActiveSkill();
|
foreach(Util::zip(
|
||||||
$defender->checkPreActiveSkill();
|
$attacker->checkPreActiveSkill(),
|
||||||
|
$defender->checkPreActiveSkill()
|
||||||
|
) as $b){
|
||||||
|
//doNothing
|
||||||
|
}
|
||||||
|
|
||||||
$attacker->checkActiveSkill();
|
foreach(Util::zip(
|
||||||
$defender->checkActiveSkill();
|
$attacker->checkActiveSkill(),
|
||||||
|
$defender->checkActiveSkill()
|
||||||
|
) as $b){
|
||||||
|
//doNothing
|
||||||
|
}
|
||||||
//NOTE: 마법은 checkActiveSkill, checkPostActiveSkill 내에서 반영
|
//NOTE: 마법은 checkActiveSkill, checkPostActiveSkill 내에서 반영
|
||||||
|
|
||||||
$attacker->checkPostActiveSkill();
|
foreach(Util::zip(
|
||||||
$defender->checkPostActiveSkill();
|
$attacker->checkPostActiveSkill(),
|
||||||
|
$defender->checkPostActiveSkill()
|
||||||
|
) as $b){
|
||||||
|
//doNothing
|
||||||
|
}
|
||||||
//NOTE: 반계류 등의 스킬을 post에서 반영
|
//NOTE: 반계류 등의 스킬을 post에서 반영
|
||||||
|
|
||||||
$activeSkillIterator = new \AppendIterator();
|
foreach(Util::zip(
|
||||||
$activeSkillIterator->append($attacker->applyActiveSkill());
|
$attacker->applyActiveSkill(),
|
||||||
$activeSkillIterator->append($defender->applyActiveSkill());
|
$defender->applyActiveSkill()
|
||||||
foreach($activeSkillIterator as $b){
|
) as $b){
|
||||||
//doNothing
|
//doNothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -337,8 +337,8 @@ class WarUnit{
|
|||||||
$this->computeWarPower();
|
$this->computeWarPower();
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkBattleBeginSkill():bool{
|
function checkBattleBeginSkill(){
|
||||||
return false;
|
yield true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkBattleBeginItem():bool{
|
function checkBattleBeginItem():bool{
|
||||||
@@ -372,16 +372,16 @@ class WarUnit{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkPreActiveSkill():bool{
|
function checkPreActiveSkill(){
|
||||||
return false;
|
yield true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkActiveSkill():bool{
|
function checkActiveSkill(){
|
||||||
return false;
|
yield true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkPostActiveSkill():bool{
|
function checkPostActiveSkill(){
|
||||||
return false;
|
yield true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyActiveSkill(){
|
function applyActiveSkill(){
|
||||||
|
|||||||
@@ -349,8 +349,7 @@ class WarUnitGeneral extends WarUnit{
|
|||||||
}
|
}
|
||||||
|
|
||||||
///전투 개시 시에 작동하여 매 장수마다 작동하는 스킬
|
///전투 개시 시에 작동하여 매 장수마다 작동하는 스킬
|
||||||
function checkBattleBeginSkill():bool{
|
function checkBattleBeginSkill(){
|
||||||
$skillResult = false;
|
|
||||||
$oppose = $this->getOppose();
|
$oppose = $this->getOppose();
|
||||||
|
|
||||||
$specialWar = $this->getSpecialWar();
|
$specialWar = $this->getSpecialWar();
|
||||||
@@ -361,11 +360,13 @@ class WarUnitGeneral extends WarUnit{
|
|||||||
){
|
){
|
||||||
$this->activateSkill('부상무효');
|
$this->activateSkill('부상무효');
|
||||||
}
|
}
|
||||||
|
yield true;
|
||||||
|
|
||||||
if($specialWar == 62){
|
if($specialWar == 62){
|
||||||
$oppose->activateSkill('저격불가');
|
$oppose->activateSkill('저격불가');
|
||||||
$this->activateSkill('부상무효');
|
$this->activateSkill('부상무효');
|
||||||
}
|
}
|
||||||
|
yield true;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
$specialWar == 70 &&
|
$specialWar == 70 &&
|
||||||
@@ -375,10 +376,8 @@ class WarUnitGeneral extends WarUnit{
|
|||||||
Util::randBool(1/3)
|
Util::randBool(1/3)
|
||||||
) {
|
) {
|
||||||
$this->activateSkill('저격');
|
$this->activateSkill('저격');
|
||||||
$skillResult = true;
|
|
||||||
}
|
}
|
||||||
|
yield true;
|
||||||
return $skillResult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///전투 개시 시에 작동하여 매 장수마다 작동하는 아이템
|
///전투 개시 시에 작동하여 매 장수마다 작동하는 아이템
|
||||||
@@ -509,7 +508,7 @@ class WarUnitGeneral extends WarUnit{
|
|||||||
return $this->killed;
|
return $this->killed;
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkPreActiveSkill():bool{
|
function checkPreActiveSkill(){
|
||||||
$activated = false;
|
$activated = false;
|
||||||
|
|
||||||
$oppose = $this->getOppose();
|
$oppose = $this->getOppose();
|
||||||
@@ -522,8 +521,8 @@ class WarUnitGeneral extends WarUnit{
|
|||||||
$oppose->activateSkill('위압불가');
|
$oppose->activateSkill('위압불가');
|
||||||
$oppose->activateSkill('격노불가');
|
$oppose->activateSkill('격노불가');
|
||||||
$oppose->activateSkill('계략약화');
|
$oppose->activateSkill('계략약화');
|
||||||
$activated = true;
|
|
||||||
}
|
}
|
||||||
|
yield true;
|
||||||
|
|
||||||
if(
|
if(
|
||||||
$specialWar == 63 &&
|
$specialWar == 63 &&
|
||||||
@@ -534,19 +533,16 @@ class WarUnitGeneral extends WarUnit{
|
|||||||
!$this->hasActivatedSkill('위압불가')
|
!$this->hasActivatedSkill('위압불가')
|
||||||
){
|
){
|
||||||
$this->activateSkill('위압');
|
$this->activateSkill('위압');
|
||||||
$activated = true;
|
|
||||||
}
|
}
|
||||||
|
yield true;
|
||||||
|
|
||||||
if($specialWar == 60){
|
if($specialWar == 60){
|
||||||
$oppose->activateSkill('회피불가');
|
$oppose->activateSkill('회피불가');
|
||||||
}
|
}
|
||||||
|
yield true;
|
||||||
return $activated;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkActiveSkill():bool{
|
function checkActiveSkill(){
|
||||||
$activated = false;
|
|
||||||
|
|
||||||
$oppose = $this->getOppose();
|
$oppose = $this->getOppose();
|
||||||
$specialWar = $this->getSpecialWar();
|
$specialWar = $this->getSpecialWar();
|
||||||
$item = $this->getItem();
|
$item = $this->getItem();
|
||||||
@@ -562,9 +558,9 @@ class WarUnitGeneral extends WarUnit{
|
|||||||
$ratio = $this->getComputedAtmos() + $this->getComputedTrain();
|
$ratio = $this->getComputedAtmos() + $this->getComputedTrain();
|
||||||
if(Util::randBool($ratio / 400)){
|
if(Util::randBool($ratio / 400)){
|
||||||
$this->activateSkill('특수', '저지');
|
$this->activateSkill('특수', '저지');
|
||||||
$activated = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
yield true;
|
||||||
|
|
||||||
if(
|
if(
|
||||||
!$this->hasActivatedSkill('특수') &&
|
!$this->hasActivatedSkill('특수') &&
|
||||||
@@ -572,8 +568,8 @@ class WarUnitGeneral extends WarUnit{
|
|||||||
Util::randBool($this->getComputedCriticalRatio())
|
Util::randBool($this->getComputedCriticalRatio())
|
||||||
){
|
){
|
||||||
$this->activateSkill('특수', '필살시도', '필살');
|
$this->activateSkill('특수', '필살시도', '필살');
|
||||||
$activated = true;
|
|
||||||
}
|
}
|
||||||
|
yield true;
|
||||||
|
|
||||||
if(
|
if(
|
||||||
!$this->hasActivatedSkill('특수') &&
|
!$this->hasActivatedSkill('특수') &&
|
||||||
@@ -581,8 +577,8 @@ class WarUnitGeneral extends WarUnit{
|
|||||||
Util::randBool($this->getComputedAvoidRatio())
|
Util::randBool($this->getComputedAvoidRatio())
|
||||||
){
|
){
|
||||||
$this->activateSkill('특수', '회피시도', '회피');
|
$this->activateSkill('특수', '회피시도', '회피');
|
||||||
$activated = true;
|
|
||||||
}
|
}
|
||||||
|
yield true;
|
||||||
|
|
||||||
//계략
|
//계략
|
||||||
if($crewType->magicCoef){
|
if($crewType->magicCoef){
|
||||||
@@ -627,17 +623,16 @@ class WarUnitGeneral extends WarUnit{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
yield true;
|
||||||
|
|
||||||
//의술
|
//의술
|
||||||
if($specialWar == 73 && Util::randBool(0.2)){
|
if($specialWar == 73 && Util::randBool(0.2)){
|
||||||
$this->activateSkill('치료');
|
$this->activateSkill('치료');
|
||||||
$activated = true;
|
|
||||||
}
|
}
|
||||||
|
yield true;
|
||||||
return $activated;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkPostActiveSkill():bool{
|
function checkPostActiveSkill(){
|
||||||
$activated = false;
|
$activated = false;
|
||||||
|
|
||||||
$oppose = $this->getOppose();
|
$oppose = $this->getOppose();
|
||||||
@@ -667,6 +662,7 @@ class WarUnitGeneral extends WarUnit{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
yield true;
|
||||||
|
|
||||||
if(
|
if(
|
||||||
$specialWar == 74 &&
|
$specialWar == 74 &&
|
||||||
@@ -693,6 +689,7 @@ class WarUnitGeneral extends WarUnit{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
yield true;
|
||||||
|
|
||||||
if(
|
if(
|
||||||
($item == 23 || $item == 24) &&
|
($item == 23 || $item == 24) &&
|
||||||
@@ -702,6 +699,7 @@ class WarUnitGeneral extends WarUnit{
|
|||||||
$this->activateSkill('치료');
|
$this->activateSkill('치료');
|
||||||
$activated = true;
|
$activated = true;
|
||||||
}
|
}
|
||||||
|
yield true;
|
||||||
|
|
||||||
//계략
|
//계략
|
||||||
if(
|
if(
|
||||||
@@ -713,6 +711,7 @@ class WarUnitGeneral extends WarUnit{
|
|||||||
$oppose->deactivateSkill('계략');
|
$oppose->deactivateSkill('계략');
|
||||||
$activated = true;
|
$activated = true;
|
||||||
}
|
}
|
||||||
|
yield true;
|
||||||
|
|
||||||
if(
|
if(
|
||||||
$specialWar == 42 &&
|
$specialWar == 42 &&
|
||||||
@@ -720,6 +719,7 @@ class WarUnitGeneral extends WarUnit{
|
|||||||
){
|
){
|
||||||
$this->warPowerMultiply *= 1.3;
|
$this->warPowerMultiply *= 1.3;
|
||||||
}
|
}
|
||||||
|
yield true;
|
||||||
|
|
||||||
if(
|
if(
|
||||||
$specialWar == 43 &&
|
$specialWar == 43 &&
|
||||||
@@ -727,8 +727,7 @@ class WarUnitGeneral extends WarUnit{
|
|||||||
){
|
){
|
||||||
$this->warPowerMultiply *= 1.5;
|
$this->warPowerMultiply *= 1.5;
|
||||||
}
|
}
|
||||||
|
yield true;
|
||||||
return $activated;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyActiveSkill(){
|
function applyActiveSkill(){
|
||||||
|
|||||||
@@ -60,6 +60,24 @@ class Util extends \utilphp\util
|
|||||||
throw new \InvalidArgumentException('올바르지 않은 type 지정');
|
throw new \InvalidArgumentException('올바르지 않은 type 지정');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function zip(iterable ...$iterators){
|
||||||
|
while(true){
|
||||||
|
$hasValue = false;
|
||||||
|
$values = [];
|
||||||
|
foreach($iterators as $iter){
|
||||||
|
if($iter->valid()){
|
||||||
|
$values[] = $iter->send(NULL);
|
||||||
|
$hasValue = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
yield $values;
|
||||||
|
|
||||||
|
if(!$hasValue){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $_POST, $_GET에서 값을 가져오는 함수. Util::array_get($_POST[$name])을 축약 가능.
|
* $_POST, $_GET에서 값을 가져오는 함수. Util::array_get($_POST[$name])을 축약 가능.
|
||||||
* 타입이 복잡해질 경우 이 함수를 통하지 않고 json으로 요청할 것을 권장.
|
* 타입이 복잡해질 경우 이 함수를 통하지 않고 json으로 요청할 것을 권장.
|
||||||
|
|||||||
Reference in New Issue
Block a user