Пример #1
0
 def update_agent(self):
     """Updates the player agent data in the model"""
     agent_data = (
         self.model.agents[self.model.ALL_AGENTS_KEY]["PlayerCharacter"]
     )
     agent_data["Statistics"] = (
         character_statistics.get_stat_values(
             self.char_data.characterstats
         )["primary"]
     )
Пример #2
0
    def updateObjectDB(self, world):
        """Updates the values in the object database with the worlds values"""
        
        all_agents = self.agents[self.ALL_AGENTS_KEY]
        for entity in world.entities:
            identifier = entity.general.identifier
            agent_data = {}
            map_id = self.game_state.getMapOfObject(identifier)
            if map_id:
                if all_agents.has_key(identifier):
                    agent_data = self.agents[self.ALL_AGENTS_KEY][identifier]
                else:
                    agent_data = self.agents[map_id][identifier]

            else:
                if not self.items.has_key(identifier):
                    self.items[identifier] = {}
                agent_data = self.items[identifier]
            entity_data = {}
            entity_data["general"] = {"identifier": identifier}
            for name, component in components.components.iteritems():
                if getattr(entity, name):
                    comp_data = {}
                    comp_vals = getattr(entity, name)
                    #Items that are in containers will be saved with them.
                    for field in component.saveable_fields:
                        try:
                            comp_data[field] = getattr(comp_vals, field)
                        except AttributeError:                            
                            #The entity doesn't have this specific value,
                            #ignore it
                            pass
                    if comp_data:
                        entity_data[name] = comp_data
                    if name == "fifeagent":
                        if entity.fifeagent.layer:
                            layer = entity.fifeagent.layer
                            inst = layer.getInstance(identifier)
                            loc = inst.getLocation().getExactLayerCoordinates()
                            agent_data["Position"] = (loc.x, loc.y, loc.z)
                            if all_agents.has_key(identifier):
                                agent_data["Map"] = map_id
                            agent_data["Rotation"]  = inst.getRotation()
                    elif name == "characterstats":
                        agent_data["Statistics"] = (
                            character_statistics.get_stat_values(
                                entity.characterstats
                            )["primary"]
                        )
                    elif name == "container" and hasattr(comp_vals, 
                                                         "children"):
                        inventory_data = {}
                        inventory_data["Slots"] = len(comp_vals.children)
                        items = []
                        for child in comp_vals.children:
                            if not child:
                                continue
                            items.append(
                                {"ID": child.entity.general.identifier,
                                 "Slot": child.slot}
                            )
                        inventory_data["Items"] = items
                        agent_data["Inventory"] = inventory_data
                    elif name == "equip":
                        equip_data = {}
                        for field in component.fields:
                            if(hasattr(comp_vals, field)):
                                equipable = getattr(comp_vals, field)
                                if equipable:
                                    equip_data[field] = {
                                        "ID": 
                                         equipable.entity.general.identifier
                                    }
                        agent_data["Equipment"] = equip_data
            agent_data["Entity"] = entity_data