mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-08-14 07:11:02 +00:00
@@ -73,6 +73,17 @@ $chooseTribe = function(int $postTribe) {
|
|||||||
return max(1, min(3, $postTribe));
|
return max(1, min(3, $postTribe));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* ===================== FIX UNIT BUG ===================== */
|
||||||
|
|
||||||
|
function ensureUnitsRow($wid) {
|
||||||
|
$q = mysqli_query($GLOBALS["link"], "SELECT vref FROM ".TB_PREFIX."units WHERE vref=".(int)$wid);
|
||||||
|
if (mysqli_num_rows($q) == 0) {
|
||||||
|
mysqli_query($GLOBALS["link"], "INSERT INTO ".TB_PREFIX."units (vref) VALUES (".(int)$wid.")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ===================== CREATE VILLAGE ===================== */
|
||||||
|
|
||||||
// convenience closure: builds/units/resources for one village
|
// convenience closure: builds/units/resources for one village
|
||||||
$createVillage = function(int $uid, string $villageName, int $tribe, bool $isCapital) use ($database, $automation, $wgarray) : int {
|
$createVillage = function(int $uid, string $villageName, int $tribe, bool $isCapital) use ($database, $automation, $wgarray) : int {
|
||||||
// Random quad
|
// Random quad
|
||||||
@@ -106,14 +117,19 @@ $createVillage = function(int $uid, string $villageName, int $tribe, bool $isCap
|
|||||||
$automation->recountPop($wid);
|
$automation->recountPop($wid);
|
||||||
|
|
||||||
// units: random per tribe (same as your code)
|
// units: random per tribe (same as your code)
|
||||||
$q = "UPDATE " . TB_PREFIX . "units SET
|
/* ===================== FIX HERE ===================== */
|
||||||
u".(($tribe-1)*10+1)." = ".rand(100, 2000).",
|
ensureUnitsRow($wid);
|
||||||
u".(($tribe-1)*10+2)." = ".rand(100, 2400).",
|
|
||||||
u".(($tribe-1)*10+3)." = ".rand(100, 1600).",
|
$offset = ($tribe-1)*10;
|
||||||
u".(($tribe-1)*10+4)." = ".rand(100, 1500).",
|
|
||||||
u".(($tribe-1)*10+5)." = ".rand(48, 1700).",
|
$q = "UPDATE ".TB_PREFIX."units SET
|
||||||
u".(($tribe-1)*10+6)." = ".rand(60, 1800)."
|
u".($offset+1)." = ".rand(100, 2000).",
|
||||||
WHERE vref = '".$wid."'";
|
u".($offset+2)." = ".rand(100, 2400).",
|
||||||
|
u".($offset+3)." = ".rand(100, 1600).",
|
||||||
|
u".($offset+4)." = ".rand(100, 1500).",
|
||||||
|
u".($offset+5)." = ".rand(48, 1700).",
|
||||||
|
u".($offset+6)." = ".rand(60, 1800)."
|
||||||
|
WHERE vref = ".(int)$wid;
|
||||||
mysqli_query($GLOBALS["link"], $q) or die(mysqli_error($database->dblink));
|
mysqli_query($GLOBALS["link"], $q) or die(mysqli_error($database->dblink));
|
||||||
|
|
||||||
return $wid;
|
return $wid;
|
||||||
@@ -132,9 +148,6 @@ if ($mode === 'many_accounts') {
|
|||||||
|
|
||||||
$created = 0;
|
$created = 0;
|
||||||
$skipped = 0;
|
$skipped = 0;
|
||||||
$addUnitsWrefs = [];
|
|
||||||
$addTechWrefs = [];
|
|
||||||
$addABTechWrefs= [];
|
|
||||||
|
|
||||||
for ($i=1; $i <= $amount; $i++) {
|
for ($i=1; $i <= $amount; $i++) {
|
||||||
$userName = $baseName . $i;
|
$userName = $baseName . $i;
|
||||||
@@ -166,9 +179,9 @@ if ($mode === 'many_accounts') {
|
|||||||
$villageName = $userName . "'s village";
|
$villageName = $userName . "'s village";
|
||||||
$wid = $createVillage($uid, $villageName, $tribe, true);
|
$wid = $createVillage($uid, $villageName, $tribe, true);
|
||||||
|
|
||||||
$addUnitsWrefs[] = $wid;
|
$database->addUnits([$wid]);
|
||||||
$addTechWrefs[] = $wid;
|
$database->addTech([$wid]);
|
||||||
$addABTechWrefs[] = $wid;
|
$database->addABTech([$wid]);
|
||||||
|
|
||||||
$database->updateUserField($uid,"access",USER,1);
|
$database->updateUserField($uid,"access",USER,1);
|
||||||
|
|
||||||
@@ -223,30 +236,20 @@ if ($mode === 'single_with_villages') {
|
|||||||
|
|
||||||
$database->updateUserField($uid,"act","",1);
|
$database->updateUserField($uid,"act","",1);
|
||||||
|
|
||||||
$addUnitsWrefs = [];
|
|
||||||
$addTechWrefs = [];
|
|
||||||
$addABTechWrefs= [];
|
|
||||||
|
|
||||||
for ($v=1; $v <= $villagesRequested; $v++) {
|
for ($v=1; $v <= $villagesRequested; $v++) {
|
||||||
$isCapital = ($v === 1);
|
$isCapital = ($v === 1);
|
||||||
$villageName = $userName . ($isCapital ? " (Capital)" : " #" . $v);
|
$villageName = $userName . ($isCapital ? " (Capital)" : " #" . $v);
|
||||||
$wid = $createVillage($uid, $villageName, $tribe, $isCapital);
|
$wid = $createVillage($uid, $villageName, $tribe, $isCapital);
|
||||||
|
|
||||||
$addUnitsWrefs[] = $wid;
|
|
||||||
$addTechWrefs[] = $wid;
|
|
||||||
$addABTechWrefs[] = $wid;
|
|
||||||
|
|
||||||
// Set the first village as active/capital in the usual tables if your code expects it:
|
// Set the first village as active/capital in the usual tables if your code expects it:
|
||||||
if ($isCapital) {
|
if ($isCapital) {
|
||||||
// ensure vdata.capital already 1; if you have any “default village” linkage, set that here.
|
// ensure vdata.capital already 1; if you have any “default village” linkage, set that here.
|
||||||
}
|
}
|
||||||
|
$database->addUnits([$wid]);
|
||||||
|
$database->addTech([$wid]);
|
||||||
|
$database->addABTech([$wid]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tech & ABTech for all villages
|
|
||||||
$database->addUnits($addUnitsWrefs);
|
|
||||||
$database->addTech($addTechWrefs);
|
|
||||||
$database->addABTech($addABTechWrefs);
|
|
||||||
|
|
||||||
// Enable user after villages created
|
// Enable user after villages created
|
||||||
$database->updateUserField($uid,"access",USER,1);
|
$database->updateUserField($uid,"access",USER,1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user