def new(self, **kwargs): entry = kwargs.pop('entry', None) region_id = kwargs.pop('region_id', None) x = kwargs.pop('x', None) y = kwargs.pop('y', None) z = kwargs.pop('z', None) # notice: at this step unit already created in constructor # also notice: here processed query to another DB (from current realm_db to external world_db) unit_template = self.session.query(UnitTemplate).filter_by( entry=entry).first() self.world_object.unit_template = unit_template region = self.session.query(Region).filter_by( region_id=region_id).first() self.world_object.region = region self.world_object.x = x self.world_object.y = y self.world_object.z = z self.stats_builder = StatsBuilder(unit_template) self._set_display_id() self._set_faction_template() return self
def new(self, **kwargs): self.player.race = kwargs.pop('race', None) self.player.char_class = kwargs.pop('char_class', None) self.player.gender = kwargs.pop('gender', None) self.player.name = kwargs.pop('name') self.player.skin = kwargs.pop('skin') self.player.face = kwargs.pop('face') self.player.hair_style = kwargs.pop('hair_style') self.player.hair_color = kwargs.pop('hair_color') self.player.facial_hair = kwargs.pop('facial_hair') self.player.level = Config.World.Object.Unit.Player.Defaults.min_level self.player.account = self.session.merge(kwargs.pop('account')) self._set_start_location() self._set_display_id() self._set_faction_template_id() # save player for id generating self.session.add(self.player) self.session.flush() self.stats_builder = StatsBuilder(self.player) self.set_stats() self.save() self.set_default_equipment() self.set_default_skills() self.set_default_spells() return self
def add_player_fields(self): stats = StatsBuilder(self.player).build().get_stats() self.set_object_field(PlayerField.FLAGS, stats.player_flags) bytes_1 = ( self.player.skin | self.player.face << 8 | self.player.hair_style << 16 | self.player.hair_color << 24 ) bytes_2 = ( self.player.facial_hair | # TODO: debug values below 0x00 << 8 | 0x00 << 16 | 0x02 << 24 ) bytes_3 = self.player.gender self.set_object_field(PlayerField.BYTES_1, bytes_1) self.set_object_field(PlayerField.BYTES_2, bytes_2) self.set_object_field(PlayerField.BYTES_3, bytes_3) self.set_object_field(PlayerField.XP, stats.xp) self.set_object_field(PlayerField.NEXT_LEVEL_XP, stats.next_level_xp) self.set_object_field(PlayerField.CHARACTER_POINTS1, stats.character_points_1) self.set_object_field(PlayerField.CHARACTER_POINTS2, stats.character_points_2) self.set_object_field(PlayerField.BLOCK_PERCENTAGE, stats.block) self.set_object_field(PlayerField.DODGE_PERCENTAGE, stats.dodge) self.set_object_field(PlayerField.PARRY_PERCENTAGE, stats.parry) self.set_object_field(PlayerField.CRIT_PERCENTAGE, stats.crit) # TODO: set to own param self.set_object_field(PlayerField.RANGED_CRIT_PERCENTAGE, stats.crit) self.set_object_field(PlayerField.REST_STATE_EXPERIENCE, stats.rest_state_exp) self.set_object_field(PlayerField.COINAGE, stats.money) # TODO: set to actual self.set_object_field(PlayerField.WATCHED_FACTION_INDEX, -1) # -1 is default (according to Mangos) self.set_object_field(PlayerField.BYTES, 0) self.set_object_field(PlayerField.MAX_LEVEL, Config.World.Object.Unit.Player.Defaults.max_level) # equipment for slot in range(CharacterEquipSlot.HEAD.value, CharacterEquipSlot.BAG1.value): item = self.equipment[CharacterEquipSlot(slot)].item if item is not None: # set VISIBLE_ITEM_1_0 + offset visible_item_index = PlayerField.VISIBLE_ITEM_1_0.value + (slot * 16) self.set_object_field(PlayerField(visible_item_index), item.item_template.entry) # set INV_SLOT_HEAD + offset inv_slot_index = PlayerField.INV_SLOT_HEAD.value + (slot * 2) self.set_object_field(PlayerField(inv_slot_index), item.guid) self.set_object_field(PlayerField.MOD_DAMAGE_NORMAL_DONE_PCT, 1)
def add_unit_fields(self): # notice: world_object can be instance of Unit or Player here stats = StatsBuilder(self.world_object).build().get_stats() self.set_object_field(UnitField.HEALTH, stats.health) self.set_object_field(UnitField.POWER1, stats.mana) self.set_object_field(UnitField.POWER2, stats.rage) self.set_object_field(UnitField.POWER3, stats.focus) self.set_object_field(UnitField.POWER4, stats.energy) self.set_object_field(UnitField.POWER5, stats.happiness) self.set_object_field(UnitField.MAXHEALTH, stats.max_health) self.set_object_field(UnitField.MAXPOWER1, stats.max_mana) self.set_object_field(UnitField.MAXPOWER2, stats.max_rage) self.set_object_field(UnitField.MAXPOWER3, stats.max_focus) self.set_object_field(UnitField.MAXPOWER4, stats.max_energy) self.set_object_field(UnitField.MAXPOWER5, stats.max_happiness) if self.unit.race is not None and self.unit.char_class is not None and self.unit.gender is not None: bytes0 = (self.unit.race | self.unit.char_class << 8 | self.unit.gender << 16 | stats.power_type << 24) self.set_object_field(UnitField.BYTES_0, bytes0) self.set_object_field(UnitField.LEVEL, stats.level) self.set_object_field(UnitField.FACTIONTEMPLATE, self.unit.faction_template) self.set_object_field(UnitField.FLAGS, stats.unit_flags) self.set_object_field(UnitField.BASEATTACKTIME, stats.attack_time_mainhand) self.set_object_field(UnitField.OFFHANDATTACKTIME, stats.attack_time_offhand) self.set_object_field( UnitField.BOUNDINGRADIUS, Config.World.Object.Unit.Defaults.bounding_radius) self.set_object_field(UnitField.COMBATREACH, Config.World.Object.Unit.Defaults.combat_reach) if isinstance(self.unit, Unit): self.set_object_field(UnitField.DISPLAYID, self.unit.display_id) self.set_object_field(UnitField.NATIVEDISPLAYID, self.unit.native_display_id) elif isinstance(self.unit, UnitTemplate): # TODO: this should be checked self.set_object_field(UnitField.DISPLAYID, self.unit.display_id_1) self.set_object_field(UnitField.NATIVEDISPLAYID, self.unit.display_id_1) self.set_object_field(UnitField.MINDAMAGE, self.unit.min_damage) self.set_object_field(UnitField.MAXDAMAGE, self.unit.max_damage) self.set_object_field(UnitField.MINOFFHANDDAMAGE, self.unit.min_offhand_damage) self.set_object_field(UnitField.MAXOFFHANDDAMAGE, self.unit.max_offhand_damage) self.set_object_field(UnitField.BYTES_1, self.unit.unit_bytes_1) self.set_object_field(UnitField.MOD_CAST_SPEED, self.unit.mod_cast_speed) self.set_object_field(UnitField.STAT0, stats.strength) self.set_object_field(UnitField.STAT1, stats.agility) self.set_object_field(UnitField.STAT2, stats.stamina) self.set_object_field(UnitField.STAT3, stats.intellect) self.set_object_field(UnitField.STAT4, stats.spirit) self.set_object_field(UnitField.RESISTANCE_FIRE, stats.resistance_fire) self.set_object_field(UnitField.RESISTANCE_NATURE, stats.resistance_nature) self.set_object_field(UnitField.RESISTANCE_FROST, stats.resistance_frost) self.set_object_field(UnitField.RESISTANCE_SHADOW, stats.resistance_shadow) self.set_object_field(UnitField.RESISTANCE_ARCANE, stats.resistance_arcane) self.set_object_field(UnitField.RESISTANCE_NORMAL, stats.armor) self.set_object_field(UnitField.ATTACK_POWER, self.unit.attack_power) self.set_object_field(UnitField.BASE_MANA, self.unit.base_mana) self.set_object_field(UnitField.BASE_HEALTH, self.unit.base_health) self.set_object_field(UnitField.ATTACK_POWER_MODS, stats.attack_power_mod) self.set_object_field(UnitField.BYTES_2, self.unit.unit_bytes_2) # sheath, forms self.set_object_field(UnitField.RANGED_ATTACK_POWER, self.unit.ranged_attack_power) self.set_object_field(UnitField.RANGED_ATTACK_POWER_MODS, stats.ranged_attack_power_mod) self.set_object_field(UnitField.MINRANGEDDAMAGE, self.unit.min_ranged_damage) self.set_object_field(UnitField.MAXRANGEDDAMAGE, self.unit.max_ranged_damage)
class UnitManager(ObjectManager): def __init__(self, **kwargs): super(UnitManager, self).__init__(**kwargs) self.world_object = Unit() self.stats_builder = None @property def unit(self): if self.world_object is None: raise Exception('Unit is None') return self.world_object def add_unit_fields(self): # notice: world_object can be instance of Unit or Player here stats = StatsBuilder(self.world_object).build().get_stats() self.set_object_field(UnitField.HEALTH, stats.health) self.set_object_field(UnitField.POWER1, stats.mana) self.set_object_field(UnitField.POWER2, stats.rage) self.set_object_field(UnitField.POWER3, stats.focus) self.set_object_field(UnitField.POWER4, stats.energy) self.set_object_field(UnitField.POWER5, stats.happiness) self.set_object_field(UnitField.MAXHEALTH, stats.max_health) self.set_object_field(UnitField.MAXPOWER1, stats.max_mana) self.set_object_field(UnitField.MAXPOWER2, stats.max_rage) self.set_object_field(UnitField.MAXPOWER3, stats.max_focus) self.set_object_field(UnitField.MAXPOWER4, stats.max_energy) self.set_object_field(UnitField.MAXPOWER5, stats.max_happiness) if self.unit.race is not None and self.unit.char_class is not None and self.unit.gender is not None: bytes0 = (self.unit.race | self.unit.char_class << 8 | self.unit.gender << 16 | stats.power_type << 24) self.set_object_field(UnitField.BYTES_0, bytes0) self.set_object_field(UnitField.LEVEL, stats.level) self.set_object_field(UnitField.FACTIONTEMPLATE, self.unit.faction_template) self.set_object_field(UnitField.FLAGS, stats.unit_flags) self.set_object_field(UnitField.BASEATTACKTIME, stats.attack_time_mainhand) self.set_object_field(UnitField.OFFHANDATTACKTIME, stats.attack_time_offhand) self.set_object_field( UnitField.BOUNDINGRADIUS, Config.World.Object.Unit.Defaults.bounding_radius) self.set_object_field(UnitField.COMBATREACH, Config.World.Object.Unit.Defaults.combat_reach) if isinstance(self.unit, Unit): self.set_object_field(UnitField.DISPLAYID, self.unit.display_id) self.set_object_field(UnitField.NATIVEDISPLAYID, self.unit.native_display_id) elif isinstance(self.unit, UnitTemplate): # TODO: this should be checked self.set_object_field(UnitField.DISPLAYID, self.unit.display_id_1) self.set_object_field(UnitField.NATIVEDISPLAYID, self.unit.display_id_1) self.set_object_field(UnitField.MINDAMAGE, self.unit.min_damage) self.set_object_field(UnitField.MAXDAMAGE, self.unit.max_damage) self.set_object_field(UnitField.MINOFFHANDDAMAGE, self.unit.min_offhand_damage) self.set_object_field(UnitField.MAXOFFHANDDAMAGE, self.unit.max_offhand_damage) self.set_object_field(UnitField.BYTES_1, self.unit.unit_bytes_1) self.set_object_field(UnitField.MOD_CAST_SPEED, self.unit.mod_cast_speed) self.set_object_field(UnitField.STAT0, stats.strength) self.set_object_field(UnitField.STAT1, stats.agility) self.set_object_field(UnitField.STAT2, stats.stamina) self.set_object_field(UnitField.STAT3, stats.intellect) self.set_object_field(UnitField.STAT4, stats.spirit) self.set_object_field(UnitField.RESISTANCE_FIRE, stats.resistance_fire) self.set_object_field(UnitField.RESISTANCE_NATURE, stats.resistance_nature) self.set_object_field(UnitField.RESISTANCE_FROST, stats.resistance_frost) self.set_object_field(UnitField.RESISTANCE_SHADOW, stats.resistance_shadow) self.set_object_field(UnitField.RESISTANCE_ARCANE, stats.resistance_arcane) self.set_object_field(UnitField.RESISTANCE_NORMAL, stats.armor) self.set_object_field(UnitField.ATTACK_POWER, self.unit.attack_power) self.set_object_field(UnitField.BASE_MANA, self.unit.base_mana) self.set_object_field(UnitField.BASE_HEALTH, self.unit.base_health) self.set_object_field(UnitField.ATTACK_POWER_MODS, stats.attack_power_mod) self.set_object_field(UnitField.BYTES_2, self.unit.unit_bytes_2) # sheath, forms self.set_object_field(UnitField.RANGED_ATTACK_POWER, self.unit.ranged_attack_power) self.set_object_field(UnitField.RANGED_ATTACK_POWER_MODS, stats.ranged_attack_power_mod) self.set_object_field(UnitField.MINRANGEDDAMAGE, self.unit.min_ranged_damage) self.set_object_field(UnitField.MAXRANGEDDAMAGE, self.unit.max_ranged_damage) def delete(self, **kwargs): self.session.query(Unit).filter_by(**kwargs).delete() return self # inheritable # def init_movement(self): # super(UnitManager, self).init_movement() # position = Position( # x=self.world_object.x, # y=self.world_object.y, # z=self.world_object.z, # orientation=self.world_object.orientation, # map_id=self.world_object.map_id, # region_id=self.world_object.region.id # ) # # self.movement.set_position(position) # overridable def load(self, **kwargs): id = kwargs.pop('id') self.world_object = self.session.query(Unit).filter_by(id=id).first() return self # overridable def new(self, **kwargs): entry = kwargs.pop('entry', None) region_id = kwargs.pop('region_id', None) x = kwargs.pop('x', None) y = kwargs.pop('y', None) z = kwargs.pop('z', None) # notice: at this step unit already created in constructor # also notice: here processed query to another DB (from current realm_db to external world_db) unit_template = self.session.query(UnitTemplate).filter_by( entry=entry).first() self.world_object.unit_template = unit_template region = self.session.query(Region).filter_by( region_id=region_id).first() self.world_object.region = region self.world_object.x = x self.world_object.y = y self.world_object.z = z self.stats_builder = StatsBuilder(unit_template) self._set_display_id() self._set_faction_template() return self # inheritable def prepare(self): super(UnitManager, self).prepare() self.add_unit_fields() return self def set_stats(self): stats = self.stats_builder.build().get_stats() for key in stats: setattr(self.world_object, key, getattr(stats, key)) return self def _set_display_id(self): self.unit.display_id = self.unit.native_display_id = self.unit.unit_template.display_id_1 def _set_faction_template(self): self.unit.faction_template = self.unit.unit_template.faction_template