def dropObject(self, obj): """Drops the object being dropped @type obj: string @param obj: The name of the object @return: None""" try: drop_widget = self.gui.findChildByName(obj) drop_slot = drop_widget.slot replace_item = None if data_drag.dragging: drag_item = data_drag.dragged_item.entity if drag_item.equipable: drag_item = drag_item.equipable else: return # this will get the replacement item and the data for drag_drop # if there is an item all ready occupying the slot replace_item = equip.equip(self.equip, drag_item, drop_slot) # if there was no item the stop dragging and reset cursor if replace_item: image = drop_widget.image self.setDragData(replace_item.entity.containable, image, image) else: data_drag.dragging = False # reset the mouse cursor to the normal cursor self.controller.resetMouseCursor() drop_widget.item = drag_item.entity self.updateImage(drop_widget) except (equip.AlreadyEquippedError, equip.CannotBeEquippedInSlot): # Do we want to notify the player why the item can't be dropped? pass
def createAgent(self, agent, inst_id, world): if self.game_state.hasObject(inst_id): return None entity_data = deepcopy(agent["Entity"]) entity_data["fifeagent"] = {} template = None if agent.has_key("Template"): template = agent["Template"] entity_data = self.checkAttributes(entity_data, template) object_id = (entity_data["graphics"]["gfx"] if entity_data.has_key("graphics") and entity_data["graphics"].has_key("gfx") else self.GENERIC_ITEM_GFX ) map_obj = self.fife_model.getObject(str(object_id), "PARPG") if not map_obj: logging.warning("Object with inst_id={0}, ns=PARPG, " "could not be found. " "Omitting...".format(str(object_id))) x_pos = agent["Position"][0] y_pos = agent["Position"][1] z_pos = agent["Position"][2] if len(agent["Position"]) == 3 \ else 0.0 stack_pos = agent["Stackposition"] if \ agent.has_key("StackPosition") \ else None inst = self.active_map.agent_layer.\ createInstance(map_obj, fife.ExactModelCoordinate(x_pos, y_pos, z_pos), inst_id) inst.setId(inst_id) rotation = agent["Rotation"] inst.setRotation(rotation) fife.InstanceVisual.create(inst) if (stack_pos): inst.get2dGfxVisual().setStackPosition(int(stack_pos)) if (map_obj.getAction('default')): target = fife.Location(self.active_map.agent_layer) inst.act('default', target, True) if entity_data.has_key("behaviour"): entity_data["fifeagent"]["behaviour"] = \ getattr(behaviours, entity_data["behaviour"]["behaviour_type"])() else: entity_data["fifeagent"]["behaviour"] = behaviours.Base() if self.dialogues.has_key(inst_id): entity_data["dialogue"] = {} entity_data["dialogue"]["dialogue"] = self.dialogues[inst_id] if (entity_data.has_key("containable") and not entity_data["containable"].has_key("item_type") ): entity_data["containable"]["item_type"] = template obj = self.createMapObject(self.active_map.agent_layer, entity_data, inst_id, world) if agent.has_key("Statistics"): self.create_stats(obj) for name, val in agent["Statistics"].iteritems(): obj.characterstats.primary_stats[name].value = val if agent.has_key("Inventory"): inv = agent["Inventory"] self.createInventoryItems(inv, obj, world) if agent.has_key("Equipment"): for slot, data in agent["Equipment"].iteritems(): item = None if data.has_key("type"): item_type = data["type"] item_data = {} item_data = self.checkAttributes(item_data, item_type) if (item_data.has_key("containable") and item_data.has_key("equipable")): item = self.createItem( self.createUniqueID(data["ID"]), item_data, world, item_type) else: raise Exception( "Item %s is not containable or equipable." % item_type ) else: identifier = data["ID"] if self.game_state.hasObject(identifier): item = self.game_state.getObjectById(identifier) else: item_data = self.items[identifier]["Entity"] item_type = item_data["containable"]["item_type"] item = self.createItem(identifier, item_data, world, item_type) equip.equip(obj.equip, item.equipable, slot) if (obj.fifeagent and (obj.lockable and not obj.lockable.closed)): obj.fifeagent.behaviour.animate("opened", repeating=True) return obj