def handle(world_session, socket, reader):
        if not world_session or not world_session.player_mgr or not world_session.player_mgr.trade_data:
            return 0

        TradeManager.cancel_trade(world_session.player_mgr)

        return 0
Пример #2
0
    def handle(world_session, socket, reader):
        if not world_session.player_mgr.trade_data:
            return 0

        TradeManager.send_trade_status(world_session.player_mgr, TradeStatuses.TRADE_STATUS_INITIATED)
        TradeManager.send_trade_status(world_session.player_mgr.trade_data.other_player,
                                       TradeStatuses.TRADE_STATUS_INITIATED)

        return 0
Пример #3
0
    def die(self, killer=None):
        super().die(killer)

        if killer and isinstance(killer, PlayerManager):
            death_notify_packet = PacketWriter.get_packet(OpCode.SMSG_DEATH_NOTIFY, pack('<Q', killer.guid))
            self.session.request.sendall(death_notify_packet)

        TradeManager.cancel_trade(self)

        self.flagged_for_update = True
Пример #4
0
    def die(self, killer=None):
        super().die(killer)

        if killer and killer.get_type() == ObjectTypes.TYPE_PLAYER:
            death_notify_packet = PacketWriter.get_packet(
                OpCode.SMSG_DEATH_NOTIFY, pack('<Q', killer.guid))
            self.session.request.sendall(death_notify_packet)

        TradeManager.cancel_trade(self)
        self.spirit_release_timer = 0

        self.set_dirty()
Пример #5
0
    def die(self, killer=None):
        super().die(killer)

        if killer and isinstance(killer, PlayerManager):
            death_notify_packet = PacketWriter.get_packet(
                OpCode.SMSG_DEATH_NOTIFY, pack('<Q', killer.guid))
            self.session.request.sendall(death_notify_packet)

        TradeManager.cancel_trade(self)
        self.spirit_release_timer = 0

        self.set_dirty()
    def handle(world_session, socket, reader):
        if len(reader.data) >= 8:  # Avoid handling empty initiate trade packet
            guid = unpack('<Q', reader.data[:8])[0]
            if guid > 0:
                trade_player = GridManager.get_surrounding_player_by_guid(
                    world_session.player_mgr, guid)
                trade_status = None
                if not trade_player or not trade_player.is_alive:
                    trade_status = TradeStatus.TRADE_STATUS_PLAYER_NOT_FOUND
                if not world_session.player_mgr.is_alive:
                    trade_status = TradeStatus.TRADE_STATUS_DEAD
                if world_session.player_mgr.trade_data:
                    trade_status = TradeStatus.TRADE_STATUS_ALREADY_TRADING
                if world_session.player_mgr.team != trade_player.team:
                    trade_status = TradeStatus.TRADE_STATUS_WRONG_FACTION

                if trade_status:
                    TradeManager.send_trade_status(world_session.player_mgr,
                                                   trade_status)
                    return 0

                world_session.player_mgr.trade_data = TradeManager.TradeData(
                    world_session.player_mgr, trade_player)
                trade_player.trade_data = TradeManager.TradeData(
                    trade_player, world_session.player_mgr)

                TradeManager.send_trade_request(world_session.player_mgr,
                                                trade_player)
                TradeManager.send_trade_request(trade_player,
                                                world_session.player_mgr)

        return 0
Пример #7
0
    def handle(world_session, socket, reader):
        if not world_session.player_mgr.trade_data:
            return 0

        if len(reader.data) >= 3:  # Avoid handling empty set trade item packet
            trade_slot, bag, slot = unpack('<3B', reader.data)
            item = world_session.player_mgr.inventory.get_item(bag, slot)
            if not item:
                return 0

            if trade_slot > TradeManager.TradeData.TRADE_SLOT_COUNT:
                TradeManager.send_trade_status(world_session.player_mgr, TradeStatus.TRADE_STATUS_CANCELLED)
                return 0

            world_session.player_mgr.trade_data.set_item(trade_slot, item)

        return 0
Пример #8
0
    def handle(world_session, socket, reader):
        player = world_session.player_mgr
        player_trade = player.trade_data
        other_player = player_trade.other_player
        other_player_trade = other_player.trade_data

        player_trade.set_accepted(True)

        if player_trade.money > player.coinage:
            # You do not have enough gold
            return 0

        if other_player_trade.money > other_player.coinage:
            # You do not have enough gold
            return 0

        # Cancel if any item is soulbound
        for slot in range(TradeManager.TradeData.TRADE_SLOT_COUNT):
            if player_trade.items[slot] and player_trade.items[
                    slot].is_soulbound():
                TradeManager.cancel_trade(player_trade)
                return 0

            if other_player_trade.items[slot] and other_player_trade.items[
                    slot].is_soulbound():
                TradeManager.cancel_trade(other_player)
                return 0

        if other_player_trade.is_accepted:
            # I don't think spell casts are implemented

            # Inventory checks
            for slot in range(TradeManager.TradeData.TRADE_SLOT_COUNT):
                if player_trade.items[slot]:
                    error = other_player.inventory.can_store_item(
                        player_trade.items[slot].item_template,
                        player_trade.items[slot].item_instance.stackcount)
                    if error != InventoryError.BAG_OK:
                        TradeManager.cancel_trade(other_player)
                        return 0

                if other_player_trade.items[slot]:
                    error = player.inventory.can_store_item(
                        other_player_trade.items[slot].item_template,
                        other_player_trade.items[slot].item_instance.stackcount
                    )
                    if error != InventoryError.BAG_OK:
                        TradeManager.cancel_trade(player)
                        return 0

            # Transfer items
            # TODO: Change item instance owner instead of cloning the item
            for slot in range(TradeManager.TradeData.TRADE_SLOT_COUNT):
                player_item = player_trade.items[slot]
                other_player_item = other_player_trade.items[slot]

                if other_player_item:
                    player.inventory.add_item(
                        item_template=other_player_item.item_template,
                        count=other_player_item.item_instance.stackcount,
                        show_item_get=False)

                    other_player.inventory.remove_item(
                        other_player_item.item_instance.bag,
                        other_player_item.current_slot, True)

                if player_item:
                    other_player.inventory.add_item(
                        item_template=player_item.item_template,
                        count=player_item.item_instance.stackcount,
                        show_item_get=False)

                    player.inventory.remove_item(player_item.item_instance.bag,
                                                 player_item.current_slot,
                                                 True)

            player.mod_money(other_player_trade.money)
            player.mod_money(-player_trade.money)
            other_player.mod_money(player_trade.money)
            other_player.mod_money(-other_player_trade.money)

            TradeManager.send_trade_status(player,
                                           TradeStatus.TRADE_STATUS_COMPLETE)
            TradeManager.send_trade_status(other_player,
                                           TradeStatus.TRADE_STATUS_COMPLETE)

            player.trade_data = None
            other_player.trade_data = None
        else:
            other_player_trade.set_accepted(True)
            TradeManager.send_trade_status(other_player,
                                           TradeStatus.TRADE_STATUS_ACCEPTED)

        return 0