async def cancel(self): """|coro| Cancels the trade.""" if self.state != TradeState.TRADING: raise TradeOnWrongState('cancel', self.state) await self.client.main.send(Packet.new(31, 6).writeString(self.trader).write8(2))
async def accept(self): """|coro| Accepts the trade.""" if self.state != TradeState.ON_INVITE: raise TradeOnWrongState('accept', self.state) self.state = TradeState.ACCEPTING await self.client.main.send(Packet.new(31, 5).writeString(self.trader))
async def unlock(self): """|coro| Unlocks (cancels the confirmation) the trade.""" if self.state != TradeState.TRADING: raise TradeOnWrongState('lock', self.state) if not self.locked[1]: raise TypeError("Can not unlock a trade that is not locked by the client.") await self.client.main.send(Packet.new(31, 9).writeBool(False))
async def lock(self): """|coro| Locks (confirms) the trade.""" if self.state != TradeState.TRADING: raise TradeOnWrongState('lock', self.state) if self.locked[1]: raise TypeError("Can not lock a trade that is already locked by the client.") await self.client.main.send(Packet.new(31, 9).writeBool(True))
async def removeItem(self, item_id, quantity): """|coro| Removes an item from the trade. :param item_id: :class:`int` The item id. :param quantity: :class:`int` The quantity of item to remove.""" if self.state != TradeState.TRADING: raise TradeOnWrongState('removeItem', self.state) quantity = min(max(quantity, 0), 200) packet = Packet.new(31, 8).write16(item_id).writeBool(False).buffer ten = packet + b'\x01' for i in range(quantity // 10): await self.client.main.send(Packet(ten)) await asyncio.sleep(.05) unit = packet + b'\x00' for i in range(quantity % 10): await self.client.main.send(Packet(unit)) await asyncio.sleep(.05)