class Object(BaseModel): id = BaseModel.column(type='integer', primary_key=True) entry = BaseModel.column(type='integer') scale_x = BaseModel.column(type='float', default=Config.World.Object.Defaults.scale_x) __table_args__ = {'schema': Config.Database.DBNames.realm_db} @hybrid_property def object_type(self): return ObjectType.OBJECT.value @hybrid_property def type_mask(self): return TypeMask.OBJECT.value @hybrid_property def high_guid(self): return None # @hybrid_property # def low_guid(self): # return self.id @hybrid_property def guid(self): _guid = self.id if hasattr(self, 'low_guid'): Logger.test('has low guid') _guid = self.low_guid | (self.high_guid << 48) if bool(self.entry): _guid = (self.low_guid | (self.entry << 24) | (self.high_guid << 48)) return _guid @hybrid_property def packed_guid(self): pack_guid = bytearray(8 + 1) size = 1 index = 0 guid = self.guid while guid: if guid & 0xff > 0: pack_guid[0] |= (1 << index) pack_guid[size] = guid & 0xff size += 1 index += 1 guid >>= 8 return bytes(pack_guid[:size])
class SkillTemplate(BaseModel): __tablename__ = 'skill_template' id = BaseModel.column(type='integer', primary_key=True) entry = BaseModel.column(type='integer', unique=True) name = BaseModel.column(type='string') min = BaseModel.column(type='integer') max = BaseModel.column(type='integer') __table_args__ = {'schema': Config.Database.DBNames.world_db}
class PlayerSpell(BaseModel): __tablename__ = 'player_spell' spell_template_id = BaseModel.column( type='integer', foreign_key=Config.Database.DBNames.world_db + '.spell_template.id') player_id = BaseModel.column(type='integer', foreign_key=Config.Database.DBNames.realm_db + '.player.id') __table_args__ = {'schema': Config.Database.DBNames.realm_db}
class DefaultSpell(BaseModel): __tablename__ = 'default_spell' race = BaseModel.column(type='integer', nullable=True) char_class = BaseModel.column(type='integer', nullable=True) spell_template_id = BaseModel.column( type='integer', foreign_key=Config.Database.DBNames.world_db + '.spell_template.id') spell_template = relationship('SpellTemplate') __table_args__ = {'schema': Config.Database.DBNames.world_db}
class DefaultEquipment(BaseModel): __tablename__ = 'default_equipment' race = BaseModel.column(type='integer') char_class = BaseModel.column(type='integer') item_template_id = BaseModel.column(type='integer', foreign_key=Config.Database.DBNames.world_db + '.item_template.id') item_template = relationship('ItemTemplate') __table_args__ = { 'schema': Config.Database.DBNames.world_db }
class PlayerSkill(BaseModel): __tablename__ = 'player_skill' skill_template_id = BaseModel.column(type='integer', foreign_key=Config.Database.DBNames.world_db + '.skill_template.id') player_id = BaseModel.column(type='integer', foreign_key=Config.Database.DBNames.realm_db + '.player.id') skill_template = relationship('SkillTemplate', lazy='subquery') player = relationship('Player', lazy='subquery') __table_args__ = { 'schema': Config.Database.DBNames.realm_db }
class Region(BaseModel): id = BaseModel.column(type='integer', primary_key=True) identifier = BaseModel.column(type='integer', unique=True) y1 = BaseModel.column(type='float') y2 = BaseModel.column(type='float') x1 = BaseModel.column(type='float') x2 = BaseModel.column(type='float') map_id = BaseModel.column(type='mediumint') __table_args__ = {'schema': Config.Database.DBNames.world_db} def __init__(self): self.octree = None # this uses on session.query() etc @orm.reconstructor def init_on_load(self) -> None: self.octree = None # we can detect NPC by unit_template field which is NULL for players and NOT NULL for NPC units = relationship( 'Unit', primaryjoin= "and_((Region.id == Unit.region_id), (Unit.unit_template_id))") players = relationship('Player', lazy='joined') def get_octree(self) -> OctreeNode: return self.octree def set_octree(self, node: OctreeNode) -> None: self.octree = node
class Account(BaseModel): name = BaseModel.column(type='string', length=20, nullable=False, unique=True) salt = BaseModel.column(type='varbinary') verifier = BaseModel.column(type='string', length=100) ip = BaseModel.column(type='string', length=32) timezone = BaseModel.column(type='integer') os = BaseModel.column(type='string', length=32) platform = BaseModel.column(type='string', length=32) locale = BaseModel.column(type='string', length=4) __mapper_args__ = {'polymorphic_identity': 'account'} __table_args__ = {'schema': Config.Database.DBNames.login_db} def __init__(self, name, password=None, salt=None, verifier=None): if not name: raise Exception('Account name should be specified!') self.name = name.upper() # password does not saves to DB self.password = password.upper() self.salt = salt self.verifier = verifier self.ip_addr = None # offset in minutes from UTC time self.timezone = None # operation system self.os = None self.platform = None self.locale = None self.id = None if not password: if not salt or not verifier: raise Exception( 'Password does not exists! Password is necessary for SRP data generation' ) else: if not salt or not verifier: ' True when create account ' self._generate_srp_data() def _generate_srp_data(self): self.salt = urandom(32) self.verifier = SRP.generate_verifier(self.name, self.password, self.salt)
class Region(BaseModel): id = BaseModel.column(type='integer', primary_key=True) # TODO: region_id should be renamed, too vague identifier = BaseModel.column(type='integer', unique=True) y1 = BaseModel.column(type='float') y2 = BaseModel.column(type='float') x1 = BaseModel.column(type='float') x2 = BaseModel.column(type='float') map_id = BaseModel.column(type='mediumint') __table_args__ = {'schema': Config.Database.DBNames.world_db} def __init__(self): self.online_players = {} # this uses on session.query() etc @orm.reconstructor def init_on_load(self): self.online_players = {} # we can detect NPC by unit_template field which is NULL for players and NOT NULL for NPC units = relationship( 'Unit', primaryjoin= "and_((Region.id == Unit.region_id), (Unit.unit_template_id))") players = relationship('Player', lazy='joined') @hybrid_method def get_online_players(self): return self.online_players @hybrid_method def update_player(self, player: Player): self.online_players[player.name] = player @hybrid_method def remove_player(self, player: Player): if player.name in self.online_players: del self.online_players[player.name] @hybrid_method def get_online_player_by_guid(self, guid: int): for name in self.online_players: if self.online_players[name].guid == guid: return self.online_players[name]
class SpellTemplate(BaseModel): __tablename__ = 'spell_template' id = BaseModel.column(type='integer', primary_key=True) entry = BaseModel.column(type='integer') name = BaseModel.column(type='string') cost = BaseModel.column(type='integer') school = BaseModel.column(type='integer') range = BaseModel.column(type='integer') __table_args__ = { 'schema': Config.Database.DBNames.world_db }
class Region(BaseModel): id = BaseModel.column(type='integer', primary_key=True) region_id = BaseModel.column(type='integer', unique=True) y1 = BaseModel.column(type='float') y2 = BaseModel.column(type='float') x1 = BaseModel.column(type='float') x2 = BaseModel.column(type='float') map_id = BaseModel.column(type='mediumint') __table_args__ = {'schema': Config.Database.DBNames.world_db} # specify only creatures, we can detect them by unit_template field which is NULL for players and NOT NULL for NPC units = relationship( 'Unit', primaryjoin= "and_((Region.id == Unit.region_id), (Unit.unit_template_id))") players = relationship('Player', lazy='joined')
class DefaultLocation(BaseModel): __tablename__ = 'default_location' id = BaseModel.column(type='integer', primary_key=True) x = BaseModel.column(type='float') y = BaseModel.column(type='float') z = BaseModel.column(type='float') map_id = BaseModel.column(type='mediumint') race = BaseModel.column(type='integer') region_id = BaseModel.column(type='integer', foreign_key=Config.Database.DBNames.world_db + '.region.id') region = relationship('Region', lazy='subquery') __table_args__ = {'schema': Config.Database.DBNames.world_db}
class Object(BaseModel): id = BaseModel.column(type='integer', primary_key=True) entry = BaseModel.column(type='integer') scale_x = BaseModel.column(type='float', default=Config.World.Object.Defaults.scale_x) __table_args__ = { 'schema': Config.Database.DBNames.realm_db } def __init__(self): self._current_node: Union[OctreeNode, None] = None # this uses on session.query() etc @orm.reconstructor def init_on_load(self): self._current_node: Union[OctreeNode, None] = None @hybrid_method def get_current_node(self) -> OctreeNode: return self._current_node @hybrid_method def set_current_node(self, node: OctreeNode) -> None: self._current_node = node @hybrid_property def object_type(self) -> int: return ObjectType.OBJECT.value @hybrid_property def type_mask(self) -> int: return TypeMask.OBJECT.value @hybrid_property def high_guid(self): return None @hybrid_property def guid(self): _guid = self.id if hasattr(self, 'low_guid'): _guid = self.low_guid | (self.high_guid << 48) if bool(self.entry): _guid = (self.low_guid | (self.entry << 24) | (self.high_guid << 48)) return _guid @hybrid_property def packed_guid(self) -> bytes: pack_guid = bytearray(8 + 1) size = 1 index = 0 guid = self.guid while guid: if guid & 0xff > 0: pack_guid[0] |= (1 << index) pack_guid[size] = guid & 0xff size += 1 index += 1 guid >>= 8 return bytes(pack_guid[:size])
class UnitTemplate(BaseModel): __tablename__ = 'unit_template' id = BaseModel.column(type='integer', primary_key=True) entry = BaseModel.column(type='integer', unique=True) name = BaseModel.column(type='string') sub_name = BaseModel.column(type='string') min_level = BaseModel.column(type='integer') max_level = BaseModel.column(type='integer') display_id_1 = BaseModel.column(type='integer') display_id_2 = BaseModel.column(type='integer') display_id_3 = BaseModel.column(type='integer') display_id_4 = BaseModel.column(type='integer') faction_template = BaseModel.column(type='integer') scale_x = BaseModel.column(type='float', default=1.0) family = BaseModel.column(type='integer') creature_type = BaseModel.column(type='integer') inhabit_type = BaseModel.column(type='integer') regenerate_stats = BaseModel.column(type='integer') is_racial_leader = BaseModel.column(type='tinyint') npc_flags = BaseModel.column(type='integer') unit_flags = BaseModel.column(type='integer') dynamic_flags = BaseModel.column(type='integer') extra_flags = BaseModel.column(type='integer') creature_type_flags = BaseModel.column(type='integer') speed_walk = BaseModel.column(type='float') speed_run = BaseModel.column(type='float') unit_class = BaseModel.column(type='tinyint') rank = BaseModel.column(type='integer') health_multiplier = BaseModel.column(type='float') power_multiplier = BaseModel.column(type='float') damage_multiplier = BaseModel.column(type='float') damage_variance = BaseModel.column(type='float') armor_multiplier = BaseModel.column(type='float') experience_multiplier = BaseModel.column(type='float') min_health = BaseModel.column(type='integer') max_health = BaseModel.column(type='integer') min_mana = BaseModel.column(type='integer') max_mana = BaseModel.column(type='integer') min_damage = BaseModel.column(type='integer') max_damage = BaseModel.column(type='integer') min_ranged_damage = BaseModel.column(type='float') max_ranged_damage = BaseModel.column(type='float') armor = BaseModel.column(type='integer') melee_attack_power = BaseModel.column(type='integer') ranged_attack_power = BaseModel.column(type='integer') melee_base_attack_time = BaseModel.column(type='integer') ranged_base_attack_time = BaseModel.column(type='integer') damage_school = BaseModel.column(type='tinyint') min_loot_gold = BaseModel.column(type='integer') max_loot_gold = BaseModel.column(type='integer') mechanic_immune_mask = BaseModel.column(type='integer') resistance_holy = BaseModel.column(type='integer') resistance_fire = BaseModel.column(type='integer') resistance_nature = BaseModel.column(type='integer') resistance_frost = BaseModel.column(type='integer') resistance_shadow = BaseModel.column(type='integer') resistance_arcane = BaseModel.column(type='integer') movement_type = BaseModel.column(type='tinyint') trainer_type = BaseModel.column(type='tinyint') trainer_spell = BaseModel.column(type='integer') trainer_class = BaseModel.column(type='tinyint') trainer_race = BaseModel.column(type='tinyint') is_civilian = BaseModel.column(type='tinyint') __table_args__ = {'schema': Config.Database.DBNames.world_db}
class ItemTemplate(BaseModel): __tablename__ = 'item_template' id = BaseModel.column(type='integer', primary_key=True) entry = BaseModel.column(type='integer', unique=True) item_class = BaseModel.column(type='integer') item_subclass = BaseModel.column(type='integer') name = BaseModel.column(type='string') display_id = BaseModel.column(type='mediumint') quality = BaseModel.column(type='tinyint') flags = BaseModel.column(type='integer') buy_count = BaseModel.column(type='tinyint') buy_price = BaseModel.column(type='integer') sell_price = BaseModel.column(type='integer') item_type = BaseModel.column(type='tinyint') allowable_class = BaseModel.column(type='mediumint') allowable_race = BaseModel.column(type='mediumint') item_level = BaseModel.column(type='tinyint') required_level = BaseModel.column(type='tinyint') required_skill = BaseModel.column(type='integer') required_skill_rank = BaseModel.column(type='integer') required_spell = BaseModel.column(type='integer') maxcount = BaseModel.column(type='smallint') stackable = BaseModel.column(type='smallint') container_slots = BaseModel.column(type='tinyint') stat_type1 = BaseModel.column(type='tinyint') stat_value1 = BaseModel.column(type='smallint') stat_type2 = BaseModel.column(type='tinyint') stat_value2 = BaseModel.column(type='smallint') stat_type3 = BaseModel.column(type='tinyint') stat_value3 = BaseModel.column(type='smallint') stat_type4 = BaseModel.column(type='tinyint') stat_value4 = BaseModel.column(type='smallint') stat_type5 = BaseModel.column(type='tinyint') stat_value5 = BaseModel.column(type='smallint') stat_type6 = BaseModel.column(type='tinyint') stat_value6 = BaseModel.column(type='smallint') stat_type7 = BaseModel.column(type='tinyint') stat_value7 = BaseModel.column(type='smallint') stat_type8 = BaseModel.column(type='tinyint') stat_value8 = BaseModel.column(type='smallint') stat_type9 = BaseModel.column(type='tinyint') stat_value9 = BaseModel.column(type='smallint') stat_type10 = BaseModel.column(type='tinyint') stat_value10 = BaseModel.column(type='smallint') dmg_min1 = BaseModel.column(type='float') dmg_max1 = BaseModel.column(type='float') dmg_type1 = BaseModel.column(type='tinyint') dmg_min2 = BaseModel.column(type='float') dmg_max2 = BaseModel.column(type='float') dmg_type2 = BaseModel.column(type='tinyint') dmg_min3 = BaseModel.column(type='float') dmg_max3 = BaseModel.column(type='float') dmg_type3 = BaseModel.column(type='tinyint') dmg_min4 = BaseModel.column(type='float') dmg_max4 = BaseModel.column(type='float') dmg_type4 = BaseModel.column(type='tinyint') dmg_min5 = BaseModel.column(type='float') dmg_max5 = BaseModel.column(type='float') dmg_type5 = BaseModel.column(type='tinyint') armor = BaseModel.column(type='smallint') fire_res = BaseModel.column(type='tinyint') nature_res = BaseModel.column(type='tinyint') frost_res = BaseModel.column(type='tinyint') shadow_res = BaseModel.column(type='tinyint') arcane_res = BaseModel.column(type='tinyint') delay = BaseModel.column(type='smallint', default=1000) description = BaseModel.column(type='string') food_type = BaseModel.column(type='tinyint') max_durability = BaseModel.column(type='integer') duration = BaseModel.column(type='integer') material = BaseModel.column(type='integer') sheath = BaseModel.column(type='integer') __table_args__ = { 'schema': Config.Database.DBNames.world_db }