} if (!$granite) { $granite = 0; } $sql = "LOCK TABLES kingdoms WRITE, accounts WRITE, kdresourcelog WRITE"; $result = $db->query($sql); $sql = "SELECT brimstone, crystal, essence, granite FROM accounts WHERE id = '{$acc['id']}'"; $result = $db->query($sql); $row = $db->fetch_array($result); $total = $brimstone + $crystal + $essence + $granite; if ($brimstone > $row[brimstone] || $crystal > $row[crystal] || $essence > $row[essence] || $granite > $row[granite]) { // skip } else { $sql = "UPDATE accounts SET brimstone = brimstone - '{$brimstone}', crystal = crystal - '{$crystal}', essence = essence - '{$essence}', granite = granite - '{$granite}' WHERE id = '{$acc['id']}'"; $result = $db->query($sql); UpdateTreasury($acc["id"], $kid, $total, 0); } $sql = "UNLOCK TABLES"; $result = $db->query($sql); $acc["brimstone"] -= $brimstone; $acc["crystal"] -= $crystal; $acc["essence"] -= $essence; $acc["granite"] -= $granite; $output .= 'Donation successful!<br>'; } } if ($action == "changerelation") { $no = 0; if ($acc["leadertype"] != 2) { $putput .= 'You are not a king!<br>'; $no = 1;
} } $sql = "SELECT count(*) FROM kdbattles WHERE target = '{$acc['kingdom']}' AND status = '1' AND building = '0'"; $result = $db->query($sql); $numrows = $db->result($result, 0); if ($numrows != 0) { $output .= 'You can\'t spend resources when your treasure room is under attack.<br>'; $no = 1; } if ($acc["level"] < gdArcaneLevelMin) { $output .= 'Your level is too low.<br>'; $no = 1; } if ($no == 0) { // remove resources UpdateTreasury($acc["id"], $acc["kingdom"], $orb["cost"] * -1, 4); // generate uses $orb["uses"] = rand($orb["min_uses"], $orb["max_uses"]); // create orb $sql = "INSERT INTO accorbs (account, orb, uses) VALUES ('{$acc['id']}', '{$oid}', '{$orb['uses']}')"; $result = $db->query($sql); $orb["id"] = $db->insert_id(); // generate amount of gems $amount = rand($orb["min_gems"], $orb["max_gems"]); // select all gems by rarity $signs = array(); $totalchance = 0.0; $sql = "SELECT id, rarity, type FROM signs ORDER BY type ASC, rarity ASC"; $nresult = $db->query($sql); while ($row = $db->fetch_array($nresult)) { // get rarity multiplier
$result = $db->query($sql); $numrows = $db->result($result, 0); if ($numrows != 0) { echo 'You can\'t spend resources when your kingdom is under attack.<br>'; $no = 1; } $sql = "SELECT SUM(xp) AS xp FROM accounts WHERE kingdom = '{$acc['kingdom']}' AND status != '2'"; $result = $db->query($sql); $xp = $db->result($result, 0); $kingdomlevel = gCalcLvl($xp, $gdKingdomXpVar, $gdKingdomStartXp); if ($kingdomlevel < $gdGemSpells[$eid]["level"]) { echo 'Your level is too low.<br>'; $no = 1; } if ($no == 0) { UpdateTreasury($acc["id"], $acc["kingdom"], $totalcost * -1, 6); $sql = "UPDATE gems SET type = '{$eid}' WHERE {$where}"; $result = $db->query($sql); echo 'Gems successfully enchanted!<br>'; $action = "gemtemple"; unset($submit); } } if ($action == "gemspells" && !$gdSpecialKingdoms[$acc["kingdom"]]) { $sql = "SELECT count(*) FROM kdbattles WHERE target = '{$acc['kingdom']}' AND status = '1' AND building = '0'"; $result = $db->query($sql); $numrows = $db->result($result, 0); if ($numrows != 0) { echo ' You can\'t spend resources while your treasure room is under attack.<br>
// calculate the base level of the spell (1->gdGemSpellKDBMaxLevel), depending on the correct/total creature ratio $baselevel = round(1 + (gdGemSpellKDBMaxLevel - 1) * ($ratio / gdGemSpellKDBMaxLevelCreatures)); // calculate the luck factor in terms of the max level above the base level that can be reached $maxbonuslevel = round(gdGemSpellKDBMaxLevelBonus * ($resources - $mincost) / ($maxcost - $mincost)); // calculate the actual bonus level based on luck $bonuslevel = rand(0, $maxbonuslevel); // set the final level $reallevel = $baselevel + $bonuslevel; // cap real level if ($reallevel > gdGemSpellKDBMaxLevel) { $reallevel = gdGemSpellKDBMaxLevel; } // update in database $sql = "UPDATE kdbattlewaves SET " . $caster . "_enchantment = '{$gemspell}', " . $caster . "_enchantment_creature = '{$cid}', " . $caster . "_enchantment_level = '{$reallevel}' WHERE kdbattle = '{$kdbid}' AND wave = '{$wave}'"; $result = $db->query($sql); UpdateTreasury($acc["id"], $acc["kingdom"], $resources * -1, 6); // display kingdom battle info echo 'You have placed a level ', $reallevel, ' spell on the wave.<br><br>'; $action = "kdbattleinfo"; } } if ($action == "kdbattleinfo") { $no = 0; if (!$kdbid) { echo 'Invalid data.<br>'; $no = 1; } else { $sql = "SELECT * FROM kdbattles WHERE id = '{$kdbid}'"; $result = $db->query($sql); $numrows = $db->num_rows($result); if ($numrows != 1) {