Exemple #1
0
    def delete_operation(self, op):
        res = Oplist()

        # Restore status if it's zero.
        if self.has_prop_float("status"):
            res += Operation("set", Entity(self.id, status=1.0), to=self.id)

        # Respawn in a spawn area
        respawn_alias = self.get_prop_string("_respawning")
        if respawn_alias:
            respawn_entity = server.get_alias_entity(respawn_alias)
            if respawn_entity:
                pos = Spawner.get_spawn_pos(respawn_entity)
                if pos:
                    location = Location()
                    location.pos = pos
                    # Randomize orientation
                    rotation = random.random() * math.pi * 2
                    location.orientation = physics.Quaternion(physics.Vector3D(0, 1, 0), rotation)
                    location.parent = respawn_entity.location.parent
                    # Emit a sight of this entity being defeated
                    res += Operation("sight", Operation("defeated", Entity(self.id)))
                    res += Operation("move", Entity(self.id, location=location), to=self.id)
                    res += Operation("imaginary", Entity(description="You were killed and will be respawned."), to=self.id, from_=self.id)
                    return server.OPERATION_BLOCKED, res
Exemple #2
0
    def spawn_new_entity(self, res):
        pos = get_spawn_pos(self)

        if pos:
            entity_map = self.get_prop_map("__spawner_entity")
            entity_map["pos"] = pos

            # Randomize orientation
            rotation = random.random() * math.pi * 2
            orientation = physics.Quaternion(physics.Vector3D(0, 1, 0),
                                             rotation)
            entity_map["orientation"] = orientation.as_list()

            return Operation("create", entity_map, to=self.id)
    def create_operation(self, op):

        arg = op[0]
        if not arg:
            print("No argument in Create op.")
            return server.OPERATION_BLOCKED

        spawn_prop = self.get_prop_map("__spawn")
        if spawn_prop:
            ent = Entity()
            properties = spawn_prop["properties"]
            for entry in properties:
                name = entry["name"]
                provided_value = arg[name]
                if provided_value is None:
                    print("Lacking required value '{}'.".format(name))
                    # If the required value isn't present in the ones provided, abort
                    return server.OPERATION_BLOCKED
                # Check if it's one of the options
                if "options" in entry:
                    options_list = entry["options"]
                    if provided_value in options_list:
                        ent[name] = provided_value
                    else:
                        print(
                            "Supplied value {} = {} does not exist in allowed values in '__spawn' property. Someone trying to hack?"
                            .format(name, provided_value))
                else:
                    ent[name] = provided_value

            spawn_properties = self.get_prop_map("__spawn_properties")
            if spawn_properties is not None:
                # There's a "__spawn_properties" property declared; use its properties directly
                for key, value in spawn_properties.items():
                    ent[key] = value

            # Make sure that we prepend a script for player control for the new entity.
            if "__scripts!prepend" in ent:
                ent["__scripts!prepend"] = ent["__scripts!prepend"] + [{
                    "language":
                    "python",
                    "name":
                    "world.traits.PlayerControlled.PlayerControlled"
                }]
            else:
                ent["__scripts!prepend"] = [{
                    "language":
                    "python",
                    "name":
                    "world.traits.PlayerControlled.PlayerControlled"
                }]

            # Any entity created as a character should have it's "mind" property disabled; i.e. we don't want AI to control this character.
            ent["mind"] = None

            pos = Spawner.get_spawn_pos(self)
            if pos:
                # Randomize orientation
                rotation = random.random() * math.pi * 2
                orientation = physics.Quaternion(physics.Vector3D(0, 1, 0),
                                                 rotation)
                ent["loc"] = self.parent.id
                ent["pos"] = pos
                ent["orientation"] = orientation.as_list()
                ent["__account"] = arg["__account"]

                print("creating new character")
                return server.OPERATION_BLOCKED, Operation("create",
                                                           ent,
                                                           to="0")
        else:
            print(
                "CharacterCreator script attached to entity without '__spawn' property."
            )
            return server.OPERATION_BLOCKED