public function invoke() { switch (filter_input(INPUT_GET, 'ajaxAction', FILTER_SANITIZE_STRING)) { case "startFight": $nbrTours = filter_input(INPUT_GET, 'nbrTours', FILTER_SANITIZE_NUMBER_INT); $p1 = filter_input(INPUT_GET, 'player1', FILTER_SANITIZE_STRING); $p2 = filter_input(INPUT_GET, 'player2', FILTER_SANITIZE_STRING); if ($p1 && $p2 && $nbrTours > 0) { $testCombat = new Combat(new Joueur($p1), new Joueur($p2), 20); $tabActions = $testCombat->startFight(); include_once "Views/Main/combat.php"; } break; } switch (filter_input(INPUT_GET, 'page', FILTER_SANITIZE_STRING)) { case "default": include_once "Views/Main/header.php"; include_once "Views/Main/default.php"; include_once "Views/Main/footer.php"; break; } }
$building_time = round($army_owned->troops[$unit_id]->building_time * $quantity); if ($price <= $user->ressources) { $item_added = $queue->add_to_queue($unit_id, $user->id, $quantity, $building_time); $new_ressources = $user->increase_ressource(-$price); echo json_encode(['status' => 'ok', 'new_ressources' => $new_ressources, 'queue' => $item_added]); } else { echo json_encode(['status' => 'error', 'message' => "vous ne pouvez pas construire {$quantity} unité(s)"]); } } else { echo json_encode(['status' => 'error', 'message' => "votre file d'attente est pleine"]); } break; case 'remove_queue': $item = $queue->get_item_from_queue($_POST['item_id']); // on ne rend que 80% de la somme $price = round($army_owned->troops[$item['unit_id']]->price * $item['quantity'] * 0.8); $new_ressources = $user->increase_ressource($price); $queue->remove_item_from_queue($item['id']); echo json_encode(['new_ressources' => $new_ressources]); break; case 'sort_queue': $queue->sort_queue($_POST['positions']); echo json_encode($queue->get_all_queues()); break; case 'cancel_attack': $combat = new Combat($_POST['item_id']); echo $combat->reset_army(); break; } } }
// lancement de l'attaque if (isset($_POST['start_war'])) { User::exists_in_database('id', $_POST['target_id'], 'users'); $target = new User($_POST['target_id']); if (!Combat::is_available_target($user->score, $target->score)) { $errors[] = "{$target->pseudo} n'est pas a votre portée"; return; } /* TODO : décommenter pour interdire l'attaque sur soi if ($user->id == $defender->id) { $errors[] = "C'est une mutinerie ? Non sérieusement vous ne pouvez pas vous attaquer."; return; } */ $target = new User($_POST['target_id']); $combat = new Combat(); $combat->hydrate(['attacker_id' => $user->id, 'target_id' => $target->id, 'arrival_time' => date("Y-m-d H:i:s", time('now') + abs($user->score - $target->score))]); $combat_id = intval($combat->add()); $army_moving = new Army($user->id, $combat_id); $army_owned = new Army($user->id); foreach ($_POST as $post_key => $quantity) { $post_arr = explode('_', $post_key); if ($post_arr[0] == 'unitID' && $quantity > 0) { $army_moving->add_troop(intval($post_arr[1]), intval($quantity), $combat_id); $army_owned->add_troop(intval($post_arr[1]), intval(-$quantity)); } } // redirection pour éviter le renvoi d'une nouvelle flotte en actualisant la page /* TODO décommenter en prod $url = 'Location:' . _ROOT_ . 'war'; header("$url");
//ДАЛЬШЕ ИДЕТ ПЕРЕСТРАХОВКА $est_combat = true; if (in_array($state['state'], array(3, 4, 7, 8, 9))) { //в этих состояниях записей в combat уже может не быть, скрипт вызван только для отображения картинки для игрока $est_combat = false; } else { $check_combat = myquery("SELECT * FROM combat WHERE combat_id='" . $state['combat_id'] . "'"); if (!mysql_num_rows($check_combat)) { myquery("UPDATE combat_users_state SET state=7 WHERE user_id='" . $state['user_id'] . "' AND combat_id='" . $state['combat_id'] . "'"); $state['state'] = 9; $state['combat_id'] = 0; $est_combat = false; } } if ($est_combat) { $combat = new Combat($state['combat_id'], $user_id, $state); if (in_array($state['state'], array(1, 2, 5, 6, 10))) { //здесь уже должны быть записи в combat_users, иначе убираем игрока из боя $check = myquery("SELECT combat_id FROM combat_users WHERE user_id={$user_id}"); if ($check == false or mysql_num_rows($check) == 0) { $combat->clear_user($user_id); combat_delFunc($user_id); ForceFunc($user_id, 5); setLocation("act.php"); } else { list($combat_id) = mysql_fetch_array($check); $check = myquery("SELECT combat_id FROM combat WHERE combat_id={$combat_id}"); if ($check == false or mysql_num_rows($check) == 0) { $combat->clear_user($user_id); combat_delFunc($user_id); ForceFunc($user_id, 5);
function check_boy($combat_id) { $close_combat = 60 * 60 * 24 * 2; global $user_id; if (!isset($user_id)) { $user_id = 0; } $kol_out = mysql_result(myquery("SELECT COUNT(*) FROM combat_users WHERE combat_id={$combat_id} AND npc=0 AND time_last_active<" . (time() - $close_combat) . ""), 0, 0); $kol = mysql_result(myquery("SELECT COUNT(*) FROM combat_users WHERE combat_id={$combat_id} AND npc=0"), 0, 0); if ($kol == 0) { return 0; } if ($kol == $kol_out) { //ставим всем игрокам state=8 и очищаем бой $Combat = new Combat($combat_id, $user_id); $Combat->clear_combat(); return 1; } return 0; }
clearAllAbilityLocks($charData); // Calm down the Barbarians. reduceRage($charData, $fightOutput, 0); // Streak management. $streak = $charData->lazyGetStreak(); $currentStreak = $streak->currentValue; alterStreak($charData, $mapData); $newStreak = $streak->currentValue; if (floor($newStreak / 5) > floor($currentStreak / 5)) { $textOutput .= "STREAK UP! "; } // Move to the looting state. StateManager::ChangeState($charData, GameStates::Looting); $textOutput .= "Check the body for loot!\n"; } $combat = new Combat(); $combat->commands[] = new InputFragment("check", function ($charData, $mapData) { $room = $mapData->map->GetRoom($mapData->playerX, $mapData->playerY); $monster = $room->occupant; $connedName = $monster->getConnedNameStr($charData->level); $status = "Level {$monster->level} {$connedName} ({$monster->hp}/{$monster->hpMax} HP) You, Level {$charData->level} ({$charData->hp}/{$charData->hpMax} HP {$charData->mp}/{$charData->mpMax} MP)\n"; echo $status; }); $combat->commands[] = new InputFragment("attack", function ($charData, $mapData, $dynData) use($combat) { $room = $mapData->map->GetRoom($mapData->playerX, $mapData->playerY); // Must have an occupant to be in combat. $monster = $room->occupant; $combat->playerAttack($charData, $mapData, $dynData, $room, $monster); }); $combat->commands[] = new InputFragment("magic", function ($charData, $mapData) { // Barbarian check time!
include 'views/404.phtml'; die; } } else { $template = 'views/maintenance.view.phtml'; } // Mise à jour des données if (User::isLogged()) { $user = new User($_SESSION['user']['id']); $queue = new Queue($user->id); $army = new Army($user->id); // mise à jour des ressources $user->update_ressources(); // mise à jour des construction $queue->update_queue(get_time_diff($user->last_refresh)); // résolution des combats foreach (Combat::get_arrived_troops() as $combat) { $combat = new Combat($combat['id']); $combat->solve_combats(); } // mise à jour de l'armée (après les constructions et combats) $troops = $army->get_troops(); // mise à jour de l'heure $user->update_value('last_refresh', date("Y-m-d H:i:s")); } if (!_MAINTENANCE_) { include $controller; } if (!isset($_POST['ajax'])) { include 'views/layout.phtml'; }