がんばった。
ttp://yaruonichijou.blog.fc2.com/blog-entry-5092.html
'skill' => array( 'skill_name' => 'dice_attack', 'skill_text' => '文章', 'skill_type' => 'attack_add_bonus', //攻撃ボーナス値に加算 'skill_rate' => '20', //20%で発動 'skill_damege_range' => '100', //1d100を加算 ), 'skill' => array( 'skill_name' => 'dice_attack', 'skill_text' => '文章', 'skill_type' => 'attack_multiply_total', // $array['turn'.$i]['ply_atk']['total']に乗算する 'skill_rate' => '20', //20%で発動 'skill_damege_range' => '150', // % ), 'skill' => array( 'skill_name' => 'dice_attack', 'skill_text' => '文章', 'skill_type' => 'attack_add_dice', //ダイスを追加 'skill_rate' => '20', //20%で発動 'skill_damege_range' => '5', //ダイスを5追加 ), $ply = array( 'AI' => array( 'action' => 'attack', ), 'skill' => array( 'skill_name' => 'dice_attack', 'skill_text' => '文章', 'skill_type' => 'attack_add_bonus', //攻撃ボーナス値に加算 'skill_rate' => '20', //20%で発動 'skill_damege_range' => '100', //1d100を加算 ), 'initiative' => array( 'ini_dice' => 2, 'ini_range' => 6, 'ini_bonus' => 4, ), 'unit_type' => 'fire', 'stats' => array( 'atk_dice' => 2, 'atk_range' => 6, 'atk_bonus' => 4, 'def_dice' => 1, 'def_range' => 6, 'def_bonus' => 4, 'rec_dice' => 1, 'rec_range' => 6, 'rec_bonus' => 4, 'max_hp' => 40, ), 'unit_name' => 'くまま', ); $emy = array( 'AI' => array( 'action' => 'attack', ), 'skill' => array( 'skill_name' => 'dice_attack', 'skill_text' => '文章', 'skill_type' => 'attack_multiply_total', // ['total']に乗算する 'skill_rate' => '20', //20%で発動 'skill_damege_range' => '150', // % ), 'initiative' => array( 'ini_dice' => 2, 'ini_range' => 6, 'ini_bonus' => 4, ), 'unit_type' => 'water', 'stats' => array( 'atk_dice' => 2, 'atk_range' => 6, 'atk_bonus' => 4, 'def_dice' => 1, 'def_range' => 6, 'def_bonus' => 4, 'rec_dice' => 1, 'rec_range' => 6, 'rec_bonus' => 4, 'max_hp' => 40, ), 'unit_name' => 'てげ', ); //規定戦闘回数 $max_turn = 10; //全体の配列を作成 $array= array(); //最大HPの取得 $array['ply_max_hp'] = $ply['stats']['max_hp']; $array['emy_max_hp'] = $emy['stats']['max_hp']; //属性補正基本 $ply_damege_bonus = 100; $ply_def_bonus = 100; $emy_damege_bonus = 100; $emy_def_bonus = 100; //属性判定 if($ply['unit_type']='fire'){ switch($emy['unit_type']){ case 'wood': $ply_damege_bonus = 125; $ply_def_bonus = 125; $emy_damege_bonus = 75; $emy_def_bonus = 75; break; case 'water': $ply_damege_bonus = 75; $ply_def_bonus = 75; $emy_damege_bonus = 125; $emy_def_bonus = 125; break; } }elseif($ply['unit_type']='water'){ switch($emy['unit_type']){ case 'fire': $ply_damege_bonus = 125; $ply_def_bonus = 125; $emy_damege_bonus = 75; $emy_def_bonus = 75; break; case 'thunder': $ply_damege_bonus = 75; $ply_def_bonus = 75; $emy_damege_bonus = 125; $emy_def_bonus = 125; break; } }elseif($ply['unit_type']='wood'){ switch($emy['unit_type']){ case 'thunder': $ply_damege_bonus = 125; $ply_def_bonus = 125; $emy_damege_bonus = 75; $emy_def_bonus = 75; break; case 'fire': $ply_damege_bonus = 75; $ply_def_bonus = 75; $emy_damege_bonus = 125; $emy_def_bonus = 125; break; } }elseif($ply['unit_type']='thunder'){ switch($emy['unit_type']){ case 'water': $ply_damege_bonus = 125; $ply_def_bonus = 125; $emy_damege_bonus = 75; $emy_def_bonus = 75; break; case 'wood': $ply_damege_bonus = 75; $ply_def_bonus = 75; $emy_damege_bonus = 125; $emy_def_bonus = 125; break; } }elseif($ply['unit_type']='dark'){ switch($emy['unit_type']){ case 'light': $ply_damege_bonus = 125; $ply_def_bonus = 125; $emy_damege_bonus = 125; $emy_def_bonus = 125; break; } }elseif($ply['unit_type']='light'){ switch($emy['unit_type']){ case 'dark': $ply_damege_bonus = 125; $ply_def_bonus = 125; $emy_damege_bonus = 125; $emy_def_bonus = 125; break; } } //ターン for($i=1; $i <=$max_turn; $i++){ // 先制判定 $array['turn'.$i]['ini'] = ini_role($ply,$emy); // プレイヤーの攻撃値 $array['turn'.$i]['ply_atk'] = dice_role($ply['stats']['atk_dice'],$ply['stats']['atk_range'],$ply['stats']['atk_bonus']); // プレイヤーの防御値 $array['turn'.$i]['ply_def'] = dice_role($ply['stats']['def_dice'],$ply['stats']['def_range'],$ply['stats']['def_bonus']); // エネミーの攻撃値 $array['turn'.$i]['emy_atk'] = dice_role($emy['stats']['atk_dice'],$emy['stats']['atk_range'],$emy['stats']['atk_bonus']); // エネミーの防御値 $array['turn'.$i]['emy_def'] = dice_role($emy['stats']['def_dice'],$emy['stats']['def_range'],$emy['stats']['def_bonus']); //1ターン目以外は以前のターンの現在HPを取得 if($i==1){ $ply_now_hp = $array['ply_max_hp']; $emy_now_hp = $array['emy_max_hp']; }else{ $ply_now_hp = $array['turn'.($i-1)]['ply_now_hp']; $emy_now_hp = $array['turn'.($i-1)]['emy_now_hp']; } // ダメージ計算 //プレイヤーのダメージがエネミーの防御値を超えているかどうか if($array['turn'.$i]['ply_atk']['total'] > $array['turn'.$i]['emy_def']['total']){ //超えていた場合ダメージ判定 //発動レート $ply_skill_rate = mt_rand(1, 100); $array['turn'.$i]['ply_skill_rate']=$ply_skill_rate; //スキル発動判定 if($ply['skill']['skill_rate'] >= $ply_skill_rate){ switch($ply['skill']['skill_type']){ case 'attack_add_bonus': //攻撃ボーナス値に加算するタイプ $ply_skill_damage = mt_rand(1,$ply['skill']['skill_damege_range']); $array['turn'.$i]['ply_atk']['skill_damage'] = $ply_skill_damage; $array['turn'.$i]['ply_atk']['total'] = $array['turn'.$i]['ply_atk']['total'] + $ply_skill_damage; break; case 'attack_multiply_total': //最終トータルに乗算する $ply_skill_damage = $ply['skill']['skill_damege_range']; $array['turn'.$i]['ply_atk']['skill_damage'] = $ply_skill_damage; $array['turn'.$i]['ply_atk']['total'] = floor($array['turn'.$i]['ply_atk']['total']*($ply_skill_damage/100)); break; case 'attack_add_dice': //ダイスを追加 $ply_skill_damage = $ply['skill']['skill_damege_range'];//追加ダイスの個数 $ply_skill_damage_total = 0; //追加ダイスのカウント用 for($j=1;$j<=$ply_skill_damage;$j++){ $count = mt_rand(1,$ply['stats']['atk_range']); $array['turn'.$i]['ply_atk']['skill_damage'][] = $count; $ply_skill_damage_total = $ply_skill_damage_total + $count; } $array['turn'.$i]['ply_atk']['skill_damage_total'] = $ply_skill_damage_total; $array['turn'.$i]['ply_atk']['total'] = $array['turn'.$i]['ply_atk']['total']+$ply_skill_damage_total; break; } } //最終ダメージ決定 $ply_total_damage = floor($array['turn'.$i]['ply_atk']['total']*($ply_damege_bonus/100)); $emy_total_def = floor($array['turn'.$i]['emy_def']['total']*($emy_damege_bonus/100)); //攻撃値が装甲値を上回った場合 if( ($ply_total_damage - $emy_total_def)> 0){ $emy_end_hp = $emy_now_hp - ($ply_total_damage - $emy_total_def); }else{ $emy_end_hp = $emy_now_hp; } $array['turn'.$i]['ply_total_damage'] = $ply_total_damage; $array['turn'.$i]['emy_total_def'] = $emy_total_def; $array['turn'.$i]['ply_atk_hit'] = 1; //hit }else{ //超えていない場合 $emy_end_hp = $emy_now_hp; $array['turn'.$i]['ply_atk_hit'] = 0; //miss } // エネミーターン if($array['turn'.$i]['emy_atk']['total'] > $array['turn'.$i]['ply_def']['total']){ //超えていた場合ダメージ判定 //スキル発動レート $emy_skill_rate = mt_rand(1, 100); $array['turn'.$i]['emy_skill_rate']=$emy_skill_rate; //スキル発動判定 if($emy['skill']['skill_rate'] >= $emy_skill_rate){ switch($emy['skill']['skill_type']){ case 'attack_add_bonus': //攻撃ボーナス値に加算するタイプ $emy_skill_damage = mt_rand(1,$emy['skill']['skill_damege_range']); $array['turn'.$i]['emy_atk']['skill_damage'] = $skill_damage; $array['turn'.$i]['emy_atk']['total'] = $array['turn'.$i]['emy_atk']['total'] + $emy_skill_damage; break; case 'attack_multiply_total': //最終トータルに乗算する $emy_skill_damage = $emy['skill']['skill_damege_range']; $array['turn'.$i]['emy_atk']['skill_damage'] = $emy_skill_damage; $array['turn'.$i]['emy_atk']['total'] = floor($array['turn'.$i]['emy_atk']['total']*($emy_skill_damage/100)); break; case 'attack_add_dice': //ダイスを追加 $emy_skill_damage = $emy['skill']['skill_damege_range'];//追加ダイスの個数 $emy_skill_damage_total = 0; //追加ダイスのカウント用 for($j=1;$j<=$emy_skill_damage;$j++){ $count = mt_rand(1,$emy['stats']['atk_range']); $array['turn'.$i]['emy_atk']['skill_damage'][] = $count; $emy_skill_damage_total = $emy_skill_damage_total + $count; } $array['turn'.$i]['emy_atk']['skill_damage_total'] = $emy_skill_damage_total; $array['turn'.$i]['emy_atk']['total'] = $array['turn'.$i]['emy_atk']['total']+$emy_skill_damage_total; break; } } //最終ダメージ決定 $emy_total_damage = floor($array['turn'.$i]['emy_atk']['total']*($emy_damege_bonus/100)); $ply_total_def = floor($array['turn'.$i]['ply_def']['total']*($ply_def_bonus/100)); //攻撃値が装甲値を上回った場合 if( ($emy_total_damage - $ply_total_def)> 0){ $ply_end_hp = $ply_now_hp - ($emy_total_damage - $ply_total_def); }else{ $ply_end_hp = $ply_now_hp; } $array['turn'.$i]['emy_total_damage'] = $emy_total_damage; $array['turn'.$i]['ply_total_def'] = $ply_total_def; $array['turn'.$i]['emy_atk_hit'] = 1; //hit }else{ //超えていない場合 $ply_end_hp = $ply_now_hp; $array['turn'.$i]['emy_atk_hit'] = 0; //miss } // 現在HP $array['turn'.$i]['ply_now_hp'] = $ply_end_hp; $array['turn'.$i]['emy_now_hp'] = $emy_end_hp; //戦闘終了判定 if($emy_end_hp <= 0){ $array['victory_flag'] = 1; break; }elseif($ply_end_hp<=0){ $array['victory_flag'] = 0; break; } } //規定回数のターンを過ぎて戦闘終了判定がない場合 //配列にvictory_flagのキーがあるかどうか if(!array_key_exists('victory_flag',$array)){ //タイムアップフラグ if($ply_end_hp>=$emy_end_hp ){ $array['time_up_flag'] = 1; }else{ $array['time_up_flag'] = 0; } }else{ // $array['last'] = 'kumaaaaa'; } print_r($array);