예제 #1
0
        public void RunIngameCommand(string Command, Object[] Arguments)
        {
            Vector2   WorldCoordinate = new Vector2(0, 0);
            Character character       = null;

            //Server Commands
            if (GameMain.Server != null)
            {
                switch (Command)
                {
                case "spawncreature":
                    //ARG0 = Character, ARG1 = WorldPosX, ARG2 = WorldPosY
                    WorldCoordinate = new Vector2(float.Parse(Arguments[1].ToString()), float.Parse(Arguments[2].ToString()));

                    if (Arguments[0].ToString().ToLowerInvariant() == "human")
                    {
                        character = Character.Create(Character.HumanConfigFile, WorldCoordinate);
                    }
                    else
                    {
                        System.Collections.Generic.List <string> characterFiles = GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.Character);

                        foreach (string characterFile in characterFiles)
                        {
                            if (System.IO.Path.GetFileNameWithoutExtension(characterFile).ToLowerInvariant() == Arguments[0].ToString().ToLowerInvariant())
                            {
                                character = Character.Create(
                                    characterFile, WorldCoordinate);
                            }
                        }
                    }
                    break;

                case "control":
                    //ARG0 = client ARG1 = Character
                    if ((Barotrauma.Networking.Client)Arguments[0] != null)
                    {
                        GameMain.Server.SetClientCharacter((Barotrauma.Networking.Client)Arguments[0], null);
                    }

                    character = (Character)Arguments[1];

                    if (character != null)
                    {
                        Character.Controlled = character;
                    }
                    break;

                case "shield":
                    //ARG0 = Character, ARG1 = shield state
                    character          = (Character)Arguments[0];
                    character.Shielded = (Boolean)Arguments[1];

                    if (GameMain.Server != null)
                    {
                        GameMain.NetworkMember.AddChatMessage(
                            ((Boolean)Arguments[1] ?
                             character.LogName + " is now shielded from health/oxygen/pressure."
                                : character.LogName + " is no longer shielded.")
                            , Barotrauma.Networking.ChatMessageType.Private);
                    }
                    break;

                case "heal":
                    //ARG0 = Character
                    character = (Character)Arguments[0];
                    character.Heal();
                    break;

                case "revive":
                    //ARG0 = Character
                    character = (Character)Arguments[0];
                    character.Revive(true);
                    break;

                case "kill":
                    //ARG0 = Character
                    character = (Character)Arguments[0];
                    character.Kill(CauseOfDeath.Disconnected, true);
                    break;

                case "removecorpse":
                    //ARG0 = Character
                    character = (Character)Arguments[0];
                    Entity.Spawner.AddToRemoveQueue(character);
                    break;

                case "teleportsub":
                    //ARG0 = SUBID, ARG1 = WorldPosX, ARG2 = WorldPosY
                    WorldCoordinate = new Vector2(float.Parse(Arguments[1].ToString()), float.Parse(Arguments[2].ToString()));
                    GameMain.Server.MoveSub(int.Parse(Arguments[0].ToString()), WorldCoordinate);
                    break;

                case "relocate":
                    //ARG0 = Character, ARG1 = WorldPosX, ARG2 = WorldPosY

                    character = (Character)Arguments[0];
                    if (!character.Enabled)
                    {
                        character.Enabled = true;
                    }
                    WorldCoordinate = new Vector2(float.Parse(Arguments[1].ToString()), float.Parse(Arguments[2].ToString()));

                    character.AnimController.CurrentHull = null;
                    character.Submarine = null;
                    character.AnimController.SetPosition(FarseerPhysics.ConvertUnits.ToSimUnits(WorldCoordinate));
                    character.AnimController.FindHull(WorldCoordinate, true);
                    break;

                //case "handcuff":
                //ARG0 = Character
                //break;

                case "freeze":
                    //ARG0 = Character

                    character = (Character)Arguments[0];

                    if (GameMain.NilMod.FrozenCharacters.Find(c => c == character) != null)
                    {
                        GameMain.NilMod.FrozenCharacters.Remove(character);

                        if (GameMain.Server.ConnectedClients.Find(c => c.Character == character) != null)
                        {
                            var chatMsg = Barotrauma.Networking.ChatMessage.Create(
                                "Server Message",
                                ("You have been frozen by the server\n\nYou may now move again and perform actions."),
                                (Barotrauma.Networking.ChatMessageType)Barotrauma.Networking.ChatMessageType.MessageBox,
                                null);

                            GameMain.Server.SendChatMessage(chatMsg, GameMain.Server.ConnectedClients.Find(c => c.Character == character));
                        }
                    }
                    else
                    {
                        GameMain.NilMod.FrozenCharacters.Add(character);

                        if (GameMain.Server.ConnectedClients.Find(c => c.Character == character) != null)
                        {
                            var chatMsg = Barotrauma.Networking.ChatMessage.Create(
                                "Server Message",
                                ("You have been frozen by the server\n\nYou may still talk if able, but no longer perform any actions or movements."),
                                (Barotrauma.Networking.ChatMessageType)Barotrauma.Networking.ChatMessageType.MessageBox,
                                null);

                            GameMain.Server.SendChatMessage(chatMsg, GameMain.Server.ConnectedClients.Find(c => c.Character == character));
                        }
                    }
                    break;

                case "setclientcharacter":
                    //ARG0 = Client, ARG1 = Character
                    GameMain.Server.SetClientCharacter((Barotrauma.Networking.Client)Arguments[0], (Character)Arguments[1]);
                    break;

                default:
                    DebugConsole.ThrowError(@"NILMOD Error: Unrecognized Command Execution: """ + Command + @"""");
                    break;
                }
            }
        }