class DropInventory(BTAction): def __init__(self, **kwargs): super(DropInventory, self).__init__(**kwargs) self.name = "drop inventory" def on_start(self): self.inventory_man = InventoryManipulation(inventory=self.blackboard.inventory_player, blackboard=self.blackboard) def dropsteps(self): for slot, itemstack in self.inventory_man.inventory.slot_items(): yield self.inventory_man.click_slot(slot) yield self.inventory_man.click_drop() log.msg('dropped %s' % itemstack) @inlineCallbacks def action(self): for drop in self.dropsteps(): confirmed = yield drop if not confirmed: log.err("bad news, inventory transaction not confirmed by the server, click slot") self.status = Status.failure return self.status = Status.success def on_end(self): if self.status == Status.success: self.inventory_man.close()
class InventorySelectActive(BTAction): def __init__(self, itemstack=None, **kwargs): super(InventorySelectActive, self).__init__(**kwargs) self.itemstack = itemstack self.name = "hold item %s" % self.itemstack @classmethod def parse_parameters(cls, itemname): try: istack = items.item_db.item_by_name(itemname) except KeyError: istack = None return istack def on_start(self): self.inventory_man = InventoryManipulation(inventory=self.blackboard.inventory_player, blackboard=self.blackboard) @inlineCallbacks def action(self): if not self.inventory_man.has_item(self.itemstack): self.status = Status.failure self.blackboard.send_chat_message("don't have %s in my inventory" % self.itemstack.name) return if self.inventory_man.item_active(self.itemstack): self.status = Status.success return active_slot = self.inventory_man.item_at_active_slot(self.itemstack) if active_slot is not None: self.inventory_man.set_active_slot(active_slot) self.status = Status.success return slot_position = self.inventory_man.slot_at_item(self.itemstack) confirmed = yield self.inventory_man.click_slot(slot_position) if not confirmed: log.msg("bad news, inventory transaction not confirmed by the server") self.status = Status.failure return active_slot = self.inventory_man.choose_active_slot() confirmed = yield self.inventory_man.click_active_slot(active_slot) if not confirmed: log.msg("bad news, inventory transaction not confirmed by the server") self.status = Status.failure return if not self.inventory_man.is_cursor_empty: confirmed = yield self.inventory_man.click_slot(slot_position) if not confirmed: log.msg("bad news, inventory transaction not confirmed by the server") self.status = Status.failure return self.inventory_man.set_active_slot(active_slot) self.status = Status.success def on_end(self): """ make sure the item is on active slot and close the inventory """ if self.status == Status.success: self.blackboard.send_chat_message("holding %s" % self.itemstack.name) self.inventory_man.close()