From e4cce2e96e9f5c478ccce441c3062aab1cb949f7 Mon Sep 17 00:00:00 2001 From: "Igor Barkov (iwork)" Date: Tue, 25 Jan 2022 19:59:18 +0200 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D1=81=D1=82=D1=8B=D0=BB=D0=B8=20?= =?UTF-8?q?=D0=B8=20=D0=B2=D0=B5=D0=BB=D0=BE=D1=81=D0=B8=D0=BF=D0=B5=D0=B4?= =?UTF-8?q?=D1=8B!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arena.php | 12 +++++ classes/Battles/Arena.php | 109 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 arena.php create mode 100644 classes/Battles/Arena.php diff --git a/arena.php b/arena.php new file mode 100644 index 0000000..02985da --- /dev/null +++ b/arena.php @@ -0,0 +1,12 @@ +Init([[2,1],[3,2]]); \ No newline at end of file diff --git a/classes/Battles/Arena.php b/classes/Battles/Arena.php new file mode 100644 index 0000000..cdb0cd7 --- /dev/null +++ b/classes/Battles/Arena.php @@ -0,0 +1,109 @@ +db = new SQLite3($dbname); + $this->db->query(self::DB_INIT); + + } + } + + // array type: [[uid1,teamid1], [uid2,teamid2], ..., [uid_N,teamid_N]]. + public function Init(array $fighters) + { + $init_query = 'insert into fighters (uid, strength, dexterity, intuition, endurance, intelligence, wisdom, accuracy, evasion, criticals, health, max_health, mana, max_mana, melee_min, melee_max, teamid, rowid) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + $stmt = $this->db->prepare($init_query); + foreach ($fighters as list($uid, $team)) { + $fighter = new UserStats($uid); + $stats = $fighter->getFullStats(); + $stmt->bindValue(1, $fighter->getId()); + $stmt->bindValue(2, $stats->strength); + $stmt->bindValue(3, $stats->dexterity); + $stmt->bindValue(4, $stats->intuition); + $stmt->bindValue(5, $stats->endurance); + $stmt->bindValue(6, $stats->intelligence); + $stmt->bindValue(7, $stats->wisdom); + $stmt->bindValue(8, $stats->accuracy); + $stmt->bindValue(9, $stats->evasion); + $stmt->bindValue(10, $stats->criticals); + $stmt->bindValue(11, $fighter->getHealth()); + $stmt->bindValue(12, $fighter->getMaxHealth()); + $stmt->bindValue(13, $fighter->getMana()); + $stmt->bindValue(14, $fighter->getMaxMana()); + $stmt->bindValue(15, $stats->min_physical_damage); + $stmt->bindValue(16, $stats->min_physical_damage); + $stmt->bindValue(17, $team); + $stmt->bindValue(18, 1); + $stmt->execute(); + } + } + + public function Turn(int $action, int $uid): void + { + $now_minus_3_minutes = date('U', strtotime('-3 minute')); + $check_turn_timer = $this->db->querySingle('select last_turn_time from fighters where uid = ' . $uid); + /* select from last_turn_time and look at $now_plus_3_minutes - if ok, continue, if no, do nothing */ + if ($now_minus_3_minutes > $check_turn_timer && !in_array($action, [self::MELEE_ATTACK, self::RANGED_ATTACK, self::USE_MAGIC, self::MOVE, self::PASS])) { + $action = self::PASS; + $stmt_update_timer = $this->db->prepare('update fighters set last_turn_time = ? where uid = ?'); + $stmt_update_timer->bindValue(1, date('U')); + $stmt_update_timer->bindValue(2, $uid); + } + + if ($action === self::MELEE_ATTACK) { + echo 'Melee!'; + } + + if ($action === self::RANGED_ATTACK) { + echo 'Ranged!'; + } + + if ($action === self::USE_MAGIC) { + echo '!MAGIC!'; + } + + if ($action === self::MOVE) { + echo 'I have legs!!'; + } + + if ($action === self::PASS) { + echo 'I pass this turn.'; + } + $stmt_update_timer->execute(); + } +} \ No newline at end of file