def create_table_if_not_exists(cls, connection): """timestamp can be null, if stream goes offline for example""" Trait.create_table_if_not_exists(connection) Special.create_table_if_not_exists(connection) connection.execute( """create table if not exists characters (character_id integer PRIMARY KEY NOT NULL, name text UNIQUE NOT NULL, user_id text UNIQUE NOT NULL, experience integer NOT NULL, lvl integer NOT NULL, weapon_id integer, armor_id integer, trait_id text NOT NULL, exp_gain_time timestamp, x integer NOT NULL, y integer NOT NULL, trait_bonus real, alive boolean NOT NULL DEFAULT 1, FOREIGN KEY (weapon_id) REFERENCES weapons(weapon_id), FOREIGN KEY (armor_id) REFERENCES armors(armor_id), FOREIGN KEY (trait_id) REFERENCES traits(orig_name) );""" ) if "alive" not in [i[1] for i in connection.execute("""PRAGMA table_info(characters)""")]: connection.execute("""ALTER TABLE characters ADD COLUMN alive boolean NOT NULL DEFAULT 1;""") SpecialCooldown.create_table_if_not_exists(connection) ActiveEffect.create_table_if_not_exists(connection)
def delete(self): attack = Attack.find_by_attacker_or_target(self, self.connection) if attack is not None and attack.boss_id is None: # TODO: fix problem is person is attacked during boss battle and dies by boss. self.Parent.Log( "rpgGame", "something is wrong in the code, char got deleted while still in a fight." ) elif attack is not None: attack.delete() for bounty in Bounty.find_all_by_character(self, self.connection): bounty.delete() SpecialCooldown.delete_all_from_character(self, self.connection) ActiveEffect.delete_all_by_target(self, self.connection) self.connection.execute( """DELETE FROM characters WHERE character_id = ?""", (self.char_id, ))
def create_table_if_not_exists(cls, connection): """timestamp can be null, if stream goes offline for example""" Trait.create_table_if_not_exists(connection) Special.create_table_if_not_exists(connection) connection.execute("""create table if not exists characters (character_id integer PRIMARY KEY NOT NULL, name text UNIQUE NOT NULL, user_id text UNIQUE NOT NULL, experience integer NOT NULL, lvl integer NOT NULL, weapon_id integer, armor_id integer, trait_id text NOT NULL, exp_gain_time timestamp, x integer NOT NULL, y integer NOT NULL, trait_bonus integer, FOREIGN KEY (weapon_id) REFERENCES weapons(weapon_id), FOREIGN KEY (armor_id) REFERENCES armors(armor_id), FOREIGN KEY (trait_id) REFERENCES traits(orig_name) );""") SpecialCooldown.create_table_if_not_exists(connection) ActiveEffect.create_table_if_not_exists(connection)
def gain_special(self): # TODO: possibility to only gain selection of specials from a specific boss new_specials = Special.available_specials(self) if len(new_specials) > 0: new_special_id = random.choice(list(new_specials)) special = SpecialCooldown.create(self.char_id, new_special_id, self.connection) self.Parent.SendStreamMessage(self.format_message( "{0}, {1} has gained the ability {2} ({3}) on a {4} seconds cooldown.", self.Parent.GetDisplayName(self.user_id), self.name, special.special.name, special.special.identifier, special.special.cooldown_time )) else: self.Parent.SendStreamMessage(self.format_message( "{0}, your character {1} already has every available special and cannot get a new one.", self.Parent.GetDisplayName(self.user_id), self.name ))
def specials(self): if self._specials is None: self._specials = SpecialCooldown.find_by_character_id( self.char_id, self.connection) return self._specials