Exemple #1
0
 def set_accepted(self, is_accepted):
     self.is_accepted = is_accepted
     if not is_accepted:
         TradeManager.send_trade_status(
             self.player, TradeStatus.TRADE_STATUS_STATE_CHANGED)
         TradeManager.send_trade_status(
             self.other_player, TradeStatus.TRADE_STATUS_STATE_CHANGED)
    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
Exemple #3
0
 def clear_item(self, slot):
     self.items[slot] = None
     # TODO: Cancel the trade if player moves the item binded to the current proposed enchantment.
     #    The client keeps in cache the slot and any item placed there will be seen as receiving the enchant.
     #    It does not matter if we send a new packet with both fields '-1', the cache will remain.
     #    So, we need more information on what was the trading behavior on enchantments trading.
     if self.proposed_enchantment.trade_slot == slot:
         TradeManager.cancel_trade(self.player)
     self.update_trade_status()
    def handle(world_session, socket, reader):
        if not world_session.player_mgr.trade_data:
            return 0

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

        return 0
    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:
                player = world_session.player_mgr
                trade_player = MapManager.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 trade_player.friends_manager.has_ignore(player.guid):
                    trade_status = TradeStatus.TRADE_STATUS_PLAYER_IGNORED
                elif not player.is_alive:
                    trade_status = TradeStatus.TRADE_STATUS_DEAD
                elif player.trade_data:
                    trade_status = TradeStatus.TRADE_STATUS_ALREADY_TRADING
                elif player.team != trade_player.team:
                    trade_status = TradeStatus.TRADE_STATUS_WRONG_FACTION

                if trade_status:
                    TradeManager.send_trade_status(player, trade_status)
                    return 0

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

                TradeManager.send_trade_request(player, trade_player)
                TradeManager.send_trade_request(trade_player, player)

        return 0
Exemple #6
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[:3])

            if bag == 0xFF:
                bag = InventorySlots.SLOT_INBACKPACK.value

            item = world_session.player_mgr.inventory.get_item(bag, slot)
            if not item:
                return 0

            if trade_slot > TradeManager.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
    def handle(world_session, socket, reader):
        player = world_session.player_mgr
        player_trade = player.trade_data
        if not player_trade:
            TradeManager.send_trade_status(player, TradeStatus.TRADE_STATUS_CANCELLED)
            return 0

        other_player = player_trade.other_player
        other_player_trade = other_player.trade_data
        item_to_receive_enchant = None
        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.TRADE_SLOT_COUNT):
            if player_trade.items[slot] and player_trade.items[slot].is_soulbound():
                TradeManager.cancel_trade(player)
                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:
            # Inventory checks.
            for slot in range(TradeManager.TRADE_SLOT_COUNT):
                # Search for item to receive enchantment.
                if not item_to_receive_enchant and player_trade.proposed_enchantment.enchantment_entry and \
                        player_trade.proposed_enchantment.trade_slot == slot:
                    if player_trade.items[slot]:
                        item_to_receive_enchant = player_trade.items[slot]
                    elif other_player_trade.items[slot]:
                        item_to_receive_enchant = other_player_trade.items[slot]
                    continue

                # Check if player can store item.
                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

                # Check if other player can store item.
                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.TRADE_SLOT_COUNT):
                player_item = player_trade.items[slot]
                other_player_item = other_player_trade.items[slot]

                # Do not transfer enchanted items.
                if item_to_receive_enchant:
                    if player_item == item_to_receive_enchant or other_player_item == item_to_receive_enchant:
                        continue

                if other_player_item:
                    if player.inventory.add_item(item_template=other_player_item.item_template,
                                                 count=other_player_item.item_instance.stackcount,
                                                 created_by=other_player_item.item_instance.creator,
                                                 perm_enchant=EnchantmentManager.get_permanent_enchant_value(other_player_item),
                                                 show_item_get=False):
                        other_player.inventory.remove_item(other_player_item.item_instance.bag,
                                                           other_player_item.current_slot, True)

                if player_item:
                    if other_player.inventory.add_item(item_template=player_item.item_template,
                                                       count=player_item.item_instance.stackcount,
                                                       created_by=player_item.item_instance.creator,
                                                       perm_enchant=EnchantmentManager.get_permanent_enchant_value(player_item),
                                                       show_item_get=False):
                        player.inventory.remove_item(player_item.item_instance.bag,
                                                     player_item.current_slot, True)

            # Apply enchantment to item (if any).
            player_trade.apply_proposed_enchant()

            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
Exemple #8
0
 def update_trade_status(self):
     TradeManager.send_update_trade(self.player, self, False)
     TradeManager.send_update_trade(self.other_player, self, True)