diff --git a/hwe/j_simulate_battle.php b/hwe/j_simulate_battle.php index eb25b5b5..c48ee59b 100644 --- a/hwe/j_simulate_battle.php +++ b/hwe/j_simulate_battle.php @@ -33,7 +33,19 @@ $defaultCheck = [ 'integer'=>[ 'year','month','repeatCnt' ], - 'array'=>['attackerGeneral', 'attackerCity', 'attackerNation', 'defenderGenerals', 'defenderCity', 'defenderNation'], + 'between'=>[ + ['month', [1, 12]] + ], + 'in'=>[ + ['repeatCnt', [1, 1000]] + ], + 'min'=>[ + ['year', 0] + ], + 'array'=>[ + 'attackerGeneral', 'attackerCity', 'attackerNation', + 'defenderGenerals', 'defenderCity', 'defenderNation' + ], ]; $v = new Validator($query); @@ -53,20 +65,173 @@ $attackerGeneral = $query['attackerGeneral']; $attackerCity = $query['attackerCity']; $attackerNation = $query['attackerNation']; +$defenderGenerals = $query['defenderGenerals']; +$defenderCity = $query['defenderCity']; +$defenderNation = $query['defenderNation']; + + $generalCheck = [ 'required'=>[ 'no', 'name', 'nation', 'turntime', 'personal', 'special2', 'crew', 'crewtype', 'atmos', 'train', 'intel', 'intel2', 'book', 'power', 'power2', 'weap', 'injury', 'leader', 'leader2', 'horse', 'item', 'explevel', 'experience', 'dedication', 'level', 'gold', 'rice', 'dex0', 'dex10', 'dex20', 'dex30', 'dex40', 'warnum', 'killnum', 'deathnum', 'killcrew', 'deathcrew', 'recwar' + ], + 'integer'=>[ + 'no', 'nation', 'personal', 'special2', 'crew', 'crewtype', 'atmos', 'train', + 'intel', 'intel2', 'book', 'power', 'power2', 'weap', 'injury', 'leader', 'leader2', 'horse', 'item', + 'explevel', 'experience', 'dedication', 'level', 'gold', 'rice', 'dex0', 'dex10', 'dex20', 'dex30', 'dex40', + 'warnum', 'killnum', 'deathnum', 'killcrew', 'deathcrew' + ], + 'min'=>[ + ['no', 1], + ['nation', 1], + ['crew', 0], + ['intel', 0], + ['power', 0], + ['leader', 0], + ['experience', 0], + ['gold', 0], + ['rice', 0], + ['dex0', 0], + ['dex10', 0], + ['dex20', 0], + ['dex30', 0], + ['dex40', 0], + ], + 'between'=>[ + ['train', [40, GameConst::$maxTrainByWar]], + ['atmos', [40, GameConst::$maxAtmosByWar]], + ['book', [0, 26]], + ['weap', [0, 26]], + ['horse', [0, 26]], + ['item', [0, 26]], + ['explevel', [0, 300]], + ['injury', [0, 80]], + ['level', [1, 12]] + ], + 'in'=>[ + ['personal', array_keys(getCharacterList())], + ['special2', array_keys(SpecialityConst::WAR)], + ['crewtype', array_keys(GameUnitConst::all())], ] ]; -$v = new Validator($query['attackerGeneral']); + +$v = new Validator($attackerGeneral); +$v->rules($generalCheck); +if(!$v->validate()){ + Json::die([ + 'result'=>false, + 'reason'=>'[출병자]'.$v->errorStr() + ]); +} + +foreach($defenderGenerals as $idx=>$defenderGeneral){ + $v = new Validator($defenderGeneral); + $v->rules($generalCheck); + if(!$v->validate()){ + $idx+=1; + Json::die([ + 'result'=>false, + 'reason'=>"[수비자{$idx}]".$v->errorStr() + ]); + } +} +$cityCheck = [ + 'required'=>[ + 'city', 'nation', 'supply', 'name', + 'pop', 'agri', 'comm', 'secu', 'def', 'wall', + 'rate', 'level', + 'pop2', 'agri2', 'comm2', 'secu2', 'def2', 'wall2', + 'dead', 'state', 'gen1', 'gen2', 'gen3', 'conflict', + ], + 'numeric'=>[ + 'pop', 'agri', 'comm', 'secu', 'def', 'wall', 'rate', 'dead' + ], + 'integer'=>[ + 'city', 'nation', 'supply', + 'pop2', 'agri2', 'comm2', 'secu2', 'def2', 'wall2', + 'state', 'gen1', 'gen2', 'gen3' + ], + 'min'=>[ + ['def', 0], + ['wall', 0], + ['rate', 0], + ['pop', 0], + ['comm', 0], + ['secu', 0], + ['city', 1], + ['nation', 0] + ], + 'in'=>[ + ['level', array_keys(getCityLevelList())] + ] +]; +$v = new Validator($attackerCity); +$v->rules($cityCheck); +if(!$v->validate()){ + Json::die([ + 'result'=>false, + 'reason'=>'[출병도시]'.$v->errorStr() + ]); +} +$v = new Validator($defenderCity); +$v->rules($cityCheck); +if(!$v->validate()){ + Json::die([ + 'result'=>false, + 'reason'=>'[수비도시]'.$v->errorStr() + ]); +} +$nationCheck = [ + 'required'=>[ + 'type', 'tech', 'level', 'capital', + 'nation', 'name', 'gold', 'rice', 'totaltech', 'gennum' + ], + 'integer'=>[ + 'type', 'level', 'capital', 'nation', 'gennum', + ], + 'numeric'=>[ + 'tech', 'gold', 'rice', 'totaltech' + ], + 'min'=>[ + ['tech', 0], + ['totaltech', 0], + ['gold', 0], + ['rice', 0], + ['gennum', 1], + ['gen1', 0], + ['gen2', 0], + ['gen3', 0], + ], + 'in'=>[ + ['type', array_keys(getNationTypeList())], + ['level', array_keys(getNationLevelList())] + ] +]; + +$v = new Validator($attackerNation); +$v->rules($nationCheck); +if(!$v->validate()){ + Json::die([ + 'result'=>false, + 'reason'=>'[출병국]'.$v->errorStr() + ]); +} + +$v = new Validator($defenderNation); +$v->rules($nationCheck); +if(!$v->validate()){ + Json::die([ + 'result'=>false, + 'reason'=>'[수비국]'.$v->errorStr() + ]); +} Json::die([ 'result'=>true, diff --git a/hwe/js/battle_simulator.js b/hwe/js/battle_simulator.js index bbe15a62..3a4d988d 100644 --- a/hwe/js/battle_simulator.js +++ b/hwe/js/battle_simulator.js @@ -418,7 +418,7 @@ jQuery(function($){ var extendAllDataForDB = function(allData){ var defaultNation = { nation:0, - nation:'재야', + name:'재야', capital:0, level:0, gold:0, @@ -462,6 +462,7 @@ jQuery(function($){ var attackerNation = $.extend({}, defaultNation, allData.attackerNation); attackerNation.nation = 1; + attackerNation.name = '출병국'; attackerNation.totaltech = attackerNation.tech * attackerNation.gennum; var attackerCity = $.extend({}, defaultCity, allData.attackerCity); @@ -481,6 +482,7 @@ jQuery(function($){ var defenderNation = $.extend({}, defaultNation, allData.defenderNation); defenderNation.nation = 2; + defenderNation.name = '수비국'; defenderNation.totaltech = defenderNation.tech * defenderNation.gennum; var defenderCity = $.extend({}, defaultCity, allData.defenderCity); @@ -519,6 +521,7 @@ jQuery(function($){ var beginBattle = function(){ var data = extendAllDataForDB(exportAllData()); + console.log(data); $.ajax({ type:'post', url:'j_simulate_battle.php',