getVilFarmlist($session->uid)) { header("Location: build.php?id=39&t=99"); exit; } /* ===================================================== INIT ===================================================== */ $errormsg = $errormsg ?? null; $action = $_POST['action'] ?? null; $lid = (int)($_POST['lid'] ?? 0); /* ===================================================== HANDLE ADD SLOT ===================================================== */ if ($action === 'addSlot' && $lid) { $FLData = $database->getFLData($lid); if (!$FLData || $FLData['owner'] != $session->uid) { $errormsg = "Invalid farm list."; } else { /* ====================== TROOP CALC ====================== */ $troops = 0; $tribeOffset = ($session->tribe - 1) * 10; for ($i = 1; $i <= 6; $i++) { $unitId = $i + $tribeOffset; if (!in_array($unitId, [4, 14, 23, 44, 52, 64, 74, 82])) { $troops += (int)($_POST['t'.$i] ?? 0); } } /* ====================== TARGET RESOLVE ====================== */ $Wref = null; $WrefX = null; $WrefY = null; $vdata = null; $oasistype = null; $targetId = $_POST['target_id'] ?? ''; $x = $_POST['x'] ?? ''; $y = $_POST['y'] ?? ''; if (!empty($targetId)) { $Wref = (int)$targetId; $coor = $database->getCoor($Wref); $WrefX = $coor['x']; $WrefY = $coor['y']; } elseif ($x !== '' && $y !== '' && is_numeric($x) && is_numeric($y) && $x <= WORLD_MAX && $y <= WORLD_MAX) { $Wref = $database->getVilWref($x, $y); $WrefX = (int)$x; $WrefY = (int)$y; } if ($Wref) { $oasistype = $database->getVillageType2($Wref); $vdata = $database->getVillage($Wref); } /* ====================== VALIDATION ====================== */ if (empty($x) && empty($y) && empty($targetId)) { $errormsg = "Enter coordinates."; } elseif (($x === '' || $y === '') && empty($targetId)) { $errormsg = "Enter the correct coordinates."; } elseif ($oasistype == 0 && !$vdata) { $errormsg = "There is no village on those coordinates."; } elseif ($troops == 0) { $errormsg = "No troops has been selected."; } elseif ($database->hasBeginnerProtection($Wref)) { $errormsg = "Player under protection."; } elseif ($targetId == $FLData['wref'] || ($vdata['wref'] ?? null) == $FLData['wref']) { $errormsg = "You can't attack the same village you're sending troops from."; } else { /* ====================== FINAL INSERT ====================== */ $coor = $database->getCoor($village->wid); $distance = $database->getDistance($coor['x'], $coor['y'], $WrefX, $WrefY); $database->addSlotFarm( $lid, $Wref, $WrefX, $WrefY, $distance, (int)($_POST['t1'] ?? 0), (int)($_POST['t2'] ?? 0), (int)($_POST['t3'] ?? 0), (int)($_POST['t4'] ?? 0), (int)($_POST['t5'] ?? 0), (int)($_POST['t6'] ?? 0) ); header("Location: build.php?id=39&t=99"); exit; } } } ?>