public static void Handle(Player player)
    {
        LocationHolder location = player.GetLocation();

        // Send player success message.
        ChatManager.SendSystemMessage(player, "Your location is " + location.GetX() + " " + location.GetZ() + " " + location.GetY());
    }
    public static void Handle(Player player)
    {
        // Gather information.
        WorldObject target = player.GetTarget();

        if (target == null)
        {
            ChatManager.SendSystemMessage(player, "You must select a target.");
            return;
        }
        Npc npc = target.AsNpc();

        if (npc == null)
        {
            ChatManager.SendSystemMessage(player, "You must select an NPC.");
            return;
        }

        // Log admin activity.
        SpawnHolder    npcSpawn    = npc.GetSpawnHolder();
        LocationHolder npcLocation = npcSpawn.GetLocation();

        if (Config.LOG_ADMIN)
        {
            LogManager.LogAdmin(player.GetName() + " used command /delete " + npc + " " + npcLocation);
        }

        // Delete NPC.
        npc.DeleteMe();

        // Send player success message.
        int npcId = npc.GetNpcHolder().GetNpcId();

        ChatManager.SendSystemMessage(player, "You have deleted " + npcId + " from " + npcLocation);

        // Store in database.
        try
        {
            MySqlConnection con = DatabaseManager.GetConnection();
            MySqlCommand    cmd = new MySqlCommand(SPAWN_DELETE_QUERY, con);
            cmd.Parameters.AddWithValue("npc_id", npcId);
            cmd.Parameters.AddWithValue("x", npcLocation.GetX());
            cmd.Parameters.AddWithValue("y", npcLocation.GetY());
            cmd.Parameters.AddWithValue("z", npcLocation.GetZ());
            cmd.Parameters.AddWithValue("heading", npcLocation.GetHeading());
            cmd.Parameters.AddWithValue("respawn_delay", npcSpawn.GetRespawnDelay());
            cmd.ExecuteNonQuery();
            con.Close();
        }
        catch (Exception e)
        {
            LogManager.Log(e.ToString());
        }
    }
    public static void Handle(Player player)
    {
        LocationHolder location = player.GetLocation();

        // Send player success message.
        StringBuilder sb = new StringBuilder();

        sb.Append("Your location is ");
        sb.Append(location.GetX());
        sb.Append(" ");
        sb.Append(location.GetZ());
        sb.Append(" ");
        sb.Append(location.GetY());
        ChatManager.SendSystemMessage(player, sb.ToString());
    }
示例#4
0
 /// <summary>Calculates distance between this WorldObject and given x, y , z.</summary>
 /// <param name="x">the X coordinate</param>
 /// <param name="y">the Y coordinate</param>
 /// <param name="z">the Z coordinate</param>
 /// <returns>distance between object and given x, y, z.</returns>
 public double CalculateDistance(float x, float y, float z)
 {
     return(Math.Pow(x - location.GetX(), 2) + Math.Pow(y - location.GetY(), 2) + Math.Pow(z - location.GetZ(), 2));
 }
    public static void Handle(Player player, string command)
    {
        // Gather information from parameters.
        string[] commandSplit = command.Split(' ');
        int      npcId;

        if (commandSplit.Length > 1)
        {
            npcId = int.Parse(commandSplit[1]);
        }
        else
        {
            ChatManager.SendSystemMessage(player, "Proper syntax is /spawn npcId delaySeconds(optional).");
            return;
        }
        int respawnDelay = 60;

        if (commandSplit.Length > 2)
        {
            respawnDelay = int.Parse(commandSplit[2]);
        }

        // Log admin activity.
        LocationHolder playerLocation = player.GetLocation();
        LocationHolder npcLocation    = new LocationHolder(playerLocation.GetX(), playerLocation.GetY(), playerLocation.GetZ(), playerLocation.GetHeading());

        if (Config.LOG_ADMIN)
        {
            LogManager.LogAdmin(player.GetName() + " used command /spawn " + npcId + " " + respawnDelay + " at " + npcLocation);
        }

        // Spawn NPC.
        Npc npc = SpawnData.SpawnNpc(npcId, npcLocation, respawnDelay);

        // Broadcast NPC information.
        NpcInformation info = new NpcInformation(npc);

        player.ChannelSend(info);
        foreach (Player nearby in WorldManager.GetVisiblePlayers(player))
        {
            nearby.ChannelSend(info);
        }

        // Send player success message.
        ChatManager.SendSystemMessage(player, "You have spawned " + npcId + " at " + npcLocation);

        // Store in database.
        try
        {
            MySqlConnection con = DatabaseManager.GetConnection();
            MySqlCommand    cmd = new MySqlCommand(SPAWN_SAVE_QUERY, con);
            cmd.Parameters.AddWithValue("npc_id", npcId);
            cmd.Parameters.AddWithValue("x", npcLocation.GetX());
            cmd.Parameters.AddWithValue("y", npcLocation.GetY());
            cmd.Parameters.AddWithValue("z", npcLocation.GetZ());
            cmd.Parameters.AddWithValue("heading", npcLocation.GetHeading());
            cmd.Parameters.AddWithValue("respawn_delay", respawnDelay);
            cmd.ExecuteNonQuery();
            con.Close();
        }
        catch (Exception e)
        {
            LogManager.Log(e.ToString());
        }
    }
    public static void HandleChat(Player sender, string message)
    {
        // Check if message is empty.
        message = message.Trim();
        if (message.Length == 0)
        {
            return;
        }

        string lowercaseMessage = message.ToLowerInvariant().Replace("\\s{2,}", " "); // Also remove all double spaces.

        if (lowercaseMessage.Equals(COMMAND_LOCATION))
        {
            LocationHolder location = sender.GetLocation();
            sender.ChannelSend(new ChatResult(CHAT_TYPE_SYSTEM, SYS_NAME, "Your location is " + location.GetX() + " " + location.GetZ() + " " + location.GetY()));
        }
        else if (lowercaseMessage.Equals(COMMAND_RETURN))
        {
            sender.SetTeleporting();
            sender.SetLocation(Config.STARTING_LOCATION);
            sender.ChannelSend(new LocationUpdate(sender, true));
        }
        else if (lowercaseMessage.StartsWith(COMMAND_PERSONAL_MESSAGE))
        {
            string[] lowercaseMessageSplit = lowercaseMessage.Split(" ");
            if (lowercaseMessageSplit.Length < 3) // Check for parameters.
            {
                sender.ChannelSend(new ChatResult(CHAT_TYPE_SYSTEM, SYS_NAME, "Incorrect syntax. Use /tell [name] [message]."));
                return;
            }

            Player receiver = WorldManager.GetPlayerByName(lowercaseMessageSplit[1]);
            if (receiver == null)
            {
                sender.ChannelSend(new ChatResult(CHAT_TYPE_SYSTEM, SYS_NAME, "Player was not found."));
            }
            else
            {
                // Step by step cleanup, to avoid problems with extra/double spaces on original message.
                message = message.Substring(lowercaseMessageSplit[0].Length, message.Length - lowercaseMessageSplit[0].Length).Trim(); // Remove command.
                message = message.Substring(lowercaseMessageSplit[1].Length, message.Length - lowercaseMessageSplit[1].Length).Trim(); // Remove receiver name.
                sender.ChannelSend(new ChatResult(CHAT_TYPE_MESSAGE, MSG_TO + receiver.GetName(), message));
                receiver.ChannelSend(new ChatResult(CHAT_TYPE_MESSAGE, sender.GetName(), message));
                // Log chat.
                if (Config.LOG_CHAT)
                {
                    LogManager.LogChat("[" + sender.GetName() + "] to [" + receiver.GetName() + "] " + message);
                }
            }
        }
        else // Normal message.
        {
            sender.ChannelSend(new ChatResult(CHAT_TYPE_NORMAL, sender.GetName(), message));
            foreach (Player player in WorldManager.GetVisiblePlayers(sender))
            {
                player.ChannelSend(new ChatResult(CHAT_TYPE_NORMAL, sender.GetName(), message));
            }
            // Log chat.
            if (Config.LOG_CHAT)
            {
                LogManager.LogChat("[" + sender.GetName() + "] " + message);
            }
        }
    }
 public void SetLocation(LocationHolder location)
 {
     SetLocation(location.GetX(), location.GetY(), location.GetZ(), location.GetHeading());
 }