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(); } }