public static function leavePlanet(\PDO $pdo_db, int $ship_id) { $sql = "SELECT * FROM ::prefix::planets WHERE owner=:owner"; $stmt = $pdo_db->prepare($sql); $stmt->bindParam(':owner', $ship_id); $stmt->execute(); $planets_owned = $stmt->fetchAll(\PDO::FETCH_ASSOC); if ($planets_owned !== null) { foreach ($planets_owned as $tmp_planet) { $sql = "SELECT * FROM ::prefix::ships WHERE on_planet='Y' AND planet_id = :planet_id AND ship_id <> :ship_id"; $stmt = $pdo_db->prepare($sql); $stmt->bindParam(':planet_id', $tmp_planet['planet_id']); $stmt->bindParam(':ship_id', $ship_id); $stmt->execute(); $ships_on_planet = $stmt->fetchAll(\PDO::FETCH_ASSOC); if ($ships_on_planet !== null) { foreach ($ships_on_planet as $tmp_ship) { $sql = "UPDATE ::prefix::ships SET on_planet='N', planet_id = '0' WHERE ship_id = :ship_id"; $stmt = $pdo_db->prepare($sql); $stmt->bindParam(':ship_id', $tmp_ship['ship_id']); $stmt->execute(); PlayerLog::WriteLog($pdo_db, $tmp_ship['ship_id'], LOG_PLANET_EJECT, $tmp_ship['sector'] . '|' . $tmp_ship['character_name']); } } } } }
public static function defenseVsDefense(\PDO $pdo_db, int $ship_id, array $langvars) { $sql = "SELECT * FROM ::prefix::sector_defense WHERE ship_id=:ship_d"; $stmt = $pdo_db->prepare($sql); $stmt->bindParam(':ship_id', $ship_id); $stmt->execute(); $secdef_present = $stmt->fetchAll(\PDO::FETCH_ASSOC); if ($secdef_present !== null) { foreach ($secdef_present as $tmp_defense) { $deftype = $tmp_defense['defense_type'] == 'F' ? 'Fighters' : 'Mines'; $qty = $tmp_defense['quantity']; $sql = "SELECT * FROM ::prefix::sector_defense WHERE sector_id=:sector_id AND ship_id<>:ship_d ORDER BY quantity DESC"; $stmt = $pdo_db->prepare($sql); $stmt->bindParam(':sector_id', $tmp_defense['sector_id']); $stmt->bindParam(':ship_id', $ship_id); $stmt->execute(); $other_secdef_present = $stmt->fetchAll(\PDO::FETCH_ASSOC); if ($other_secdef_present !== null && $qty > 0) { foreach ($other_secdef_present as $tmp_other_defense) { $targetdeftype = $tmp_other_defense['defense_type'] == 'F' ? $langvars['l_fighters'] : $langvars['l_mines']; if ($qty > $tmp_other_defense['quantity']) { $sql = "DELETE FROM ::prefix::sector_defense WHERE defense_id = :defense_id"; $stmt = $pdo_db->prepare($sql); $stmt->bindParam(':defense_id', $tmp_other_defense['sector_id']); $stmt->execute(); $qty -= $tmp_other_defense['quantity']; $sql = "UPDATE ::prefix::sector_defense SET quantity = :quantity_id WHERE defense_id = :defense_id"; $stmt = $pdo_db->prepare($sql); $stmt->bindParam(':quantity_id', $qty); $stmt->bindParam(':defense_id', $tmp_defense['sector_id']); $stmt->execute(); PlayerLog::WriteLog($pdo_db, $tmp_other_defense['ship_id'], LOG_DEFS_DESTROYED, $tmp_other_defense['quantity'] . '|' . $targetdeftype . '|' . $tmp_defense['sector_id']); PlayerLog::WriteLog($pdo_db, $tmp_defense['ship_id'], LOG_DEFS_DESTROYED, $tmp_other_defense['quantity'] . '|' . $deftype . '|' . $tmp_defense['sector_id']); } else { $sql = "DELETE FROM ::prefix::sector_defense WHERE defense_id = :defense_id"; $stmt = $pdo_db->prepare($sql); $stmt->bindParam(':defense_id', $tmp_defense['defense_id']); $stmt->execute(); $sql = "UPDATE ::prefix::sector_defense SET quantity = quantity - :quantity_id WHERE defense_id = :defense_id"; $stmt = $pdo_db->prepare($sql); $stmt->bindParam(':quantity_id', $qty); $stmt->bindParam(':defense_id', $tmp_other_defense['defense_id']); $stmt->execute(); PlayerLog::WriteLog($pdo_db, $tmp_other_defense['ship_id'], LOG_DEFS_DESTROYED, $qty . '|' . $targetdeftype . '|' . $tmp_defense['sector_id']); PlayerLog::WriteLog($pdo_db, $tmp_defense['ship_id'], LOG_DEFS_DESTROYED, $qty . '|' . $deftype . '|' . $tmp_defense['sector_id']); $qty = 0; } } } } $sql = "DELETE FROM ::prefix::sector_defense WHERE quantity <= 0"; $stmt = $pdo_db->prepare($sql); $stmt->execute(); } }
public static function messageDefenseOwner(\PDO $pdo_db, int $sector, string $message) { $sql = "SELECT ship_id FROM ::prefix::sector_defense WHERE sector_id=:sector_id"; $stmt = $pdo_db->prepare($sql); $stmt->bindParam(':sector_id', $sector); $stmt->execute(); $defense_present = $stmt->fetchAll(\PDO::FETCH_ASSOC); if ($defense_present !== null) { foreach ($defense_present as $tmp_defense) { PlayerLog::WriteLog($pdo_db, $tmp_defense['ship_id'], LOG_RAW, $message); } } }
public static function distribute(\PDO $pdo_db, int $sector, $toll, $total_fighters) { $sql = "SELECT * FROM ::prefix::sector_defense WHERE sector_id=:sector_id AND defense_type='F'"; $stmt = $pdo_db->prepare($sql); $stmt->bindParam(':sector_id', $sector); $stmt->execute(); $defense_present = $stmt->fetchAll(\PDO::FETCH_ASSOC); if ($defense_present !== null) { foreach ($defense_present as $tmp_defense) { $toll_amount = round($tmp_defense['quantity'] / $total_fighters * $toll); $sql = "UPDATE ::prefix::ships SET credits=credits + :toll_amount WHERE ship_id = :ship_id"; $stmt = $pdo_db->prepare($sql); $stmt->bindParam(':toll_amount', $toll_amount); $stmt->bindParam(':ship_id', $tmp_defense['ship_id']); $stmt->execute(); PlayerLog::WriteLog($pdo_db, $tmp_defense['ship_id'], LOG_TOLL_RECV, "{$toll_amount}|{$sector}"); } } }
public static function collect(\PDO $pdo_db, array $langvars, int $attacker, int $bounty_on) { $sql = "SELECT * FROM ::prefix::bounty,::prefix::ships WHERE bounty_on=:bounty_on AND bounty_on=ship_id AND planced_by <> 0"; $stmt = $pdo_db->prepare($sql); $stmt->bindParam(':bounty_on', $bounty_on); $stmt->execute(); $bounty_present = $stmt->fetchAll(\PDO::FETCH_ASSOC); if ($bounty_present !== null) { foreach ($bounty_present as $tmp_bounty) { if ($tmp_bounty['placed_by'] == 0) { $placed = $langvars['l_by_thefeds']; } else { $sql = "SELECT character_name FROM ::prefix::ships WHERE ship_id=:ship_id LIMIT 1"; $stmt = $pdo_db->prepare($sql); $stmt->bindParam(':ship_id', $tmp_bounty['placed_by']); $stmt->execute(); $placed = $stmt->fetch(\PDO::FETCH_ASSOC); } $sql = "UPDATE ::prefix::ships SET credits=credits+:bounty_amount WHERE ship_id = :ship_id"; $stmt = $pdo_db->prepare($sql); $stmt->bindParam(':bounty_amount', $tmp_bounty['amount']); $stmt->bindParam(':ship_id', $attacker); $stmt->execute(); $sql = "DELETE FROM ::prefix::bounty WHERE bounty_id = :bounty_id"; $stmt = $pdo_db->prepare($sql); $stmt->bindParam(':bounty_id', $tmp_bounty['bounty_id']); $stmt->execute(); PlayerLog::WriteLog($pdo_db, $attacker, LOG_BOUNTY_CLAIMED, "{$tmp_bounty['amount']}|{$tmp_bounty['character_name']}|{$placed}"); PlayerLog::WriteLog($pdo_db, $tmp_bounty['placed_by'], LOG_BOUNTY_PAID, "{$tmp_bounty['amount']}|{$tmp_bounty['character_name']}"); } } $sql = "DELETE FROM ::prefix::bounty WHERE bounty_on = :bounty_on"; $stmt = $pdo_db->prepare($sql); $stmt->bindParam(':bounty_on', $bounty_on); $stmt->execute(); }