Exemplo n.º 1
0
    def set_default_equipment(self, player: Player):
        default_equipment = self.session\
            .query(DefaultEquipment).filter_by(race=player.race, char_class=player.char_class).all()

        items = []

        for default_item in default_equipment:
            item = Item()
            item.item_template = default_item.item_template

            inventory_type_id = InventoryType(item.item_template.item_type)

            available_slots = INVENTORY_TYPE_ITEM_SLOT_MAP[inventory_type_id]

            if len(available_slots) > 0:
                empty_slot = next((slot for slot in available_slots
                                   if self.slots[slot].is_empty()), None)
                slot_id = available_slots[0].value
                if empty_slot is None:
                    # set item to the first not empty slot
                    # in case if multiple items with same inventoty_type was passed (for example, by mistake)
                    self.slots[available_slots[0]].item = item
                else:
                    self.slots[empty_slot].item = item
                    slot_id = empty_slot.value

                equipment = Equipment()
                equipment.item = item
                equipment.player = player
                equipment.slot_id = slot_id
                items.append(equipment)

        self.session.add_all(items)
        self.session.commit()
        return self
Exemplo n.º 2
0
    def _create_test_item(self, entry: int):
        item = Item()
        item.set_owner(owner=session.player)
        item.set_entry(entry=entry)
        item.set_low_guid(counter=1)

        item = ItemManager().create_item(item_data=item)

        return item
Exemplo n.º 3
0
class Equipment(BaseModel):

    ''' Contains equipment for each player '''

    item_id             = Item.column(type='integer',
                                        foreign_key=Config.Database.DBNames.realm_db + '.item.id')

    player_id           = Item.column(type='integer',
                                        foreign_key=Config.Database.DBNames.realm_db + '.player.id')

    slot_id             = Item.column(type='integer')

    durability          = Item.column(type='integer')

    item                = relationship('Item', lazy='subquery')
    player              = relationship('Player', lazy='subquery')

    __table_args__ = {
        'schema': Config.Database.DBNames.realm_db
    }
Exemplo n.º 4
0
 def __init__(self):
     super(ItemManager, self).__init__()
     self.world_object = Item()