public override void Run(List <string> givenArguments, Server server)
        {
            // ARGS: none

            // First off, if there is someone already connected with the same name, refuse the connection
            if (server.world.players.ContainsKey(arguments[0]))
            {
                // Send back an error saying someone with the same name is already online
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add("Connection refused. :(  Someone with the name " + givenArguments[0] + " is already connected.");
                // Send the RPCSay to all clients
                server.SendRPC(error, nameOfSender);

                return;
            }
            // If the player is not yet on the world, add them
            else
            {
                // Create the creature to play as
                World.Creatures.CreatureHuman newPlayer = new World.Creatures.CreatureHuman(server.attachedApplication);
                newPlayer.specialProperties.Add("isPlayer", "");
                newPlayer.Generate(server.world.seed);
                // Add the creature into the spawn chunk.  This method may change later, depending on how we want to spawn in stuff.
                server.world.AddPlayer(givenArguments[0], newPlayer, new World.Position(0, 0, 0));
                // Send the confirmation back to the sender
                RPCs.RPCClientConnect rPCClientConnect = new RPCs.RPCClientConnect();
                server.SendRPC(rPCClientConnect);
                // Create a new RPC
                RPCs.RPCSay newRPC = new RPCs.RPCSay();
                newRPC.arguments.Add(givenArguments[0] + " just connected!");
                // Send the RPCSay to all clients
                server.SendRPC(newRPC);
            }
        }
        public override void Run(List <string> givenArguments, Server server)
        {
            // ARGS: <objectToLungeAt>

            // If dead
            if (sender.specialProperties["isDeceased"] == "TRUE")
            {
                RPCs.RPCSay failure = new RPCs.RPCSay();
                failure.arguments.Add("You are deceased.");
                server.SendRPC(failure, nameOfSender);
                return;
            }

            // Get the object to lunge at
            World.GameObject objectToLungeAt = server.world.FindFirstGameObject(givenArguments[1], sender.position);

            /*
             * // Make sure there is an object to lunge at
             * if(objectToLungeAt == null)
             * {
             *  RPCs.RPCSay rPC = new RPCs.RPCSay();
             *  rPC.arguments.Add(response);
             *  server.SendRPC(rPC, nameOfSender);
             * }*/
            // The message we're going to send back
            string response = "You lunge at ";

            // If the sender is already standing, change the response accordingly
            if (sender.specialProperties["stance"] == World.Creature.StanceToString(World.Creature.Stances.STANDING))
            {
                response = "You are already standing.";
            }
            // Otherwise, if you aren't in a stance that can transition
            else if (!World.Creature.CheckStanceTransition(World.Creature.StringToStance(sender.specialProperties["stance"]), World.Creature.Stances.STANDING))
            {
                response = "You can't stand while " + sender.specialProperties["stance"].ToLower() + ".";
            }
            // Send info back to the sender
            RPCs.RPCSay rPC = new RPCs.RPCSay();
            rPC.arguments.Add(response);
            server.SendRPC(rPC, nameOfSender);
            // If we actually were able to perform the action
            if (response == "You stand up.")
            {
                // Change the stance of the sender
                sender.specialProperties["stance"] = World.Creature.StanceToString(World.Creature.Stances.STANDING);
                // Notify everyone in the chunk
                foreach (World.GameObject gameObject in server.world.GetChunkOrGenerate(sender.position).children)
                {
                    if (gameObject.specialProperties.ContainsKey("isPlayer") && gameObject.identifier.name != sender.identifier.name)
                    {
                        // Send a message to this player saying that we left the chunk
                        RPCs.RPCSay newRPC = new RPCs.RPCSay();
                        newRPC.arguments.Add(nameOfSender + " stood up.");
                        server.SendRPC(newRPC, gameObject.identifier.name);
                    }
                }
            }
        }
        public override void Run(List <string> givenArguments, Server server)
        {
            // ARGS:

            // Create a new RPC
            RPCs.RPCSay newRPC = new RPCs.RPCSay();
            newRPC.arguments.Add(server.sendCommandsTopic + " is online!");
            server.SendRPC(newRPC);
        }
        public override void Run(List <string> givenArguments, Server server)
        {
            // ARGS: none

            // If dead
            if (sender.specialProperties["isDeceased"] == "TRUE")
            {
                RPCs.RPCSay failure = new RPCs.RPCSay();
                failure.arguments.Add("You are deceased.");
                server.SendRPC(failure, nameOfSender);
                return;
            }

            // The message we're going to send back
            string response = "You lie down.";

            // If the sender is already in the stance, change the response accordingly
            if (sender.specialProperties["stance"] == World.Creature.StanceToString(World.Creature.Stances.LAYING))
            {
                response = "You are already laying down.";
            }
            // Otherwise, if you aren't in a stance that can transition
            else if (!World.Creature.CheckStanceTransition(World.Creature.StringToStance(sender.specialProperties["stance"]), World.Creature.Stances.LAYING))
            {
                response = "You can't lie down while " + sender.specialProperties["stance"].ToLower() + ".";
            }
            else
            {
                string      lieDownstring = "You are lying down...";
                RPCs.RPCSay lieDownRPC    = new RPCs.RPCSay();
                lieDownRPC.arguments.Add(lieDownstring);
                server.SendRPC(lieDownRPC, nameOfSender);
                Thread.Sleep(1000);
            }
            // Send info back to the sender
            RPCs.RPCSay rPC = new RPCs.RPCSay();
            rPC.arguments.Add(response);
            server.SendRPC(rPC, nameOfSender);
            // If we actually were able to perform the action
            if (response == "You lie down.")
            {
                // Change the stance of the sender
                sender.specialProperties["stance"] = World.Creature.StanceToString(World.Creature.Stances.LAYING);
                // Notify everyone in the chunk
                foreach (World.GameObject gameObject in server.world.GetChunkOrGenerate(sender.position).children)
                {
                    if (gameObject.specialProperties.ContainsKey("isPlayer") && gameObject.identifier.name != sender.identifier.name)
                    {
                        // Send a message to this player saying that we left the chunk
                        RPCs.RPCSay newRPC = new RPCs.RPCSay();
                        newRPC.arguments.Add(nameOfSender + " lays down.");
                        server.SendRPC(newRPC, gameObject.identifier.name);
                    }
                }
            }
        }
        public override void Run(List <string> givenArguments, Server server)
        {
            // ARGS:

            // Create a new RPC
            RPCs.RPCSay newRPC = new RPCs.RPCSay();
            // Send back the position
            newRPC.arguments.Add("Your position is " + sender.position.x + " | " + sender.position.y + " | " + sender.position.z + ".");
            // Send the Rpc back to the sender
            server.SendRPC(newRPC, sender.identifier.name);
        }
Beispiel #6
0
        public override void Run(List <string> givenArguments, Server server)
        {
            // ARGS: <typeOfObjectToLookFor>

            // If dead
            if (sender.specialProperties["isDeceased"] == "TRUE")
            {
                RPCs.RPCSay failure = new RPCs.RPCSay();
                failure.arguments.Add("You are deceased.");
                server.SendRPC(failure, nameOfSender);
                return;
            }

            // If the person said "look at", get the following string and go find all objects with that string in it's name.
            if (givenArguments.Count == 2)
            {
                if (givenArguments[0] == "at")
                {
                    // Return a list of all objects on this chunk with givenArgument[1] keyword in it's full name
                    // Get the keyword the player was asking for
                    string keyword = givenArguments[1].Singularize();
                    if (keyword == null)
                    {
                        keyword = givenArguments[1];
                    }
                    string description = "You see:\n";
                    // Get all the children of this chunk
                    List <World.GameObject> children = sender.parent.GetAllChildren();
                    // Go through the children and find all the ones with givenArgument[1] in it's full name
                    foreach (World.GameObject child in children)
                    {
                        if (child.identifier.fullName.Contains(keyword))
                        {
                            description += Processing.Describer.GetArticle(child.identifier.fullName) + " " + child.identifier.fullName + "\n";
                        }
                    }
                    // Send this new string back to the sender
                    RPCs.RPCSay newRPC = new RPCs.RPCSay();
                    newRPC.arguments.Add(description);
                    server.SendRPC(newRPC, nameOfSender);
                }
            }
            // If the person gave no arguments, just describe the chunk they are in
            if (givenArguments.Count == 0)
            {
                // Describe the current chunk that the sender is on
                string description = Processing.Describer.Describe(server.world.chunks[sender.position.x][sender.position.y][sender.position.z], sender);
                // Send this new string back to the sender
                RPCs.RPCSay newRPC = new RPCs.RPCSay();
                newRPC.arguments.Add(description);
                server.SendRPC(newRPC, nameOfSender);
            }
        }
Beispiel #7
0
        public override void Run(List <string> givenArguments, Server server)
        {
            // ARGS: none

            // If dead
            if (sender.specialProperties["isDeceased"] == "TRUE")
            {
                RPCs.RPCSay failure = new RPCs.RPCSay();
                failure.arguments.Add("You are deceased.");
                server.SendRPC(failure, nameOfSender);
                return;
            }

            // The summary of the inventory that we'll send back to the player
            string inventorySummary = "You are is possession of:\n";
            // Get the list of utilisable parts
            List <World.GameObject> list = sender.FindChildrenWithSpecialProperty("isUtilizable");

            // Loop through the game objects to sumarize them
            foreach (World.GameObject gameObject in list)
            {
                if (gameObject.children.Count != 0)
                {
                    string article = Processing.Describer.GetArticle(gameObject.children.First().identifier.fullName);
                    inventorySummary += "\t" + char.ToUpper(article[0]) + article.Substring(1) + " " + gameObject.children.First().identifier.fullName + " in your " + gameObject.identifier.fullName + ".\n";

                    // If the item is a container, show it's contents
                    if (gameObject.children.First().specialProperties.ContainsKey("isContainer"))
                    {
                        // Loop through the game objects to sumarize them
                        foreach (World.GameObject containerGameObjects in gameObject.children.First().children)
                        {
                            string nextArticle = Processing.Describer.GetArticle(containerGameObjects.identifier.fullName);
                            inventorySummary += "\t\t|- " + char.ToUpper(nextArticle[0]) + nextArticle.Substring(1) + " " + containerGameObjects.identifier.fullName + ".\n";
                        }
                    }
                }
            }

            // Check if any children are being described and change the output acordingly
            if (inventorySummary == "You are is possession of:\n")
            {
                inventorySummary = "You are not in possession of anything.";
            }

            // Send info back to the sender
            RPCs.RPCSay rPC = new RPCs.RPCSay();
            rPC.arguments.Add(inventorySummary);
            server.SendRPC(rPC, nameOfSender);
        }
Beispiel #8
0
        public override void Run(List <string> givenArguments, Server server)
        {
            // ARGS: <nameOfObjectToExamine>

            // If dead
            if (sender.specialProperties["isDeceased"] == "TRUE")
            {
                RPCs.RPCSay failure = new RPCs.RPCSay();
                failure.arguments.Add("You are deceased.");
                server.SendRPC(failure, nameOfSender);
                return;
            }

            // The gameObject that we will be examined
            World.GameObject gameObjectToExamine = server.world.FindFirstGameObject(givenArguments[0], sender.position);

            #region Find all the children of the ObjectToExamine and describe them

            string descriptionOfGameObject = "";

            // Make room for the children sorted by type
            Dictionary <Type, List <World.GameObject> > childrenSortedByType = new Dictionary <Type, List <World.GameObject> >();
            foreach (World.GameObject child in gameObjectToExamine.children)
            {
                // If the dictionary dose not have the child type then make a new type
                if (!childrenSortedByType.ContainsKey(child.type))
                {
                    childrenSortedByType.Add(child.type, new List <World.GameObject>());
                }
                childrenSortedByType[child.type].Add(child);
            }

            RPCs.RPCSay response = new RPCs.RPCSay();
            response.arguments.Add(descriptionOfGameObject);
            server.SendRPC(response, nameOfSender);
            // Let everyone else in the chunk know that this player dropped something
            RPCs.RPCSay information = new RPCs.RPCSay();
            information.arguments.Add(nameOfSender + " examined " + Processing.Describer.GetArticle(gameObjectToExamine.identifier.fullName) + " " + gameObjectToExamine.identifier.fullName + ".");
            // Find everyone in the same chunk and let them know
            foreach (KeyValuePair <string, Core.Player> playerEntry in server.world.players)
            {
                // If this player is not the one that picked something up, and it's position is the same as the original player's position
                if (playerEntry.Key != nameOfSender && playerEntry.Value.controlledGameObject.position == sender.position)
                {
                    // Send an informational RPC to them letting them know
                    server.SendRPC(information, playerEntry.Key);
                }
            }
            #endregion
        }
Beispiel #9
0
        public override void Run(List <string> givenArguments, Server server)
        {
            // ARGS: <stringToSay> <OPTIONAL:nameOfReciever>

            // Create a new RPC
            RPCs.RPCSay newRPC = new RPCs.RPCSay();
            newRPC.arguments = givenArguments;
            // Send to the reciever if necessary
            if (givenArguments.Count == 2)
            {
                server.SendRPC(newRPC, givenArguments[1]);
            }
            else
            {
                // Send the RPCSay to all clients
                server.SendRPC(newRPC);
            }
        }
Beispiel #10
0
        public override void Run(List <string> givenArguments, Server server)
        {
            // ARGS: <nameOfPersonToHug>

            // If dead
            if (sender.specialProperties["isDeceased"] == "TRUE")
            {
                RPCs.RPCSay failure = new RPCs.RPCSay();
                failure.arguments.Add("You are deceased.");
                server.SendRPC(failure, nameOfSender);
                return;
            }

            // Make sure the object is a player
            if (!server.world.players.ContainsKey(givenArguments[0]))
            {
                // Make a message back to the sender
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add(givenArguments[0] + " is not a person.");
                server.SendRPC(error, nameOfSender);

                return;
            }
            // Make a message back to the sender
            RPCs.RPCSay rpcBackToSender = new RPCs.RPCSay();
            rpcBackToSender.arguments.Add("You hugged " + givenArguments[0]);
            server.SendRPC(rpcBackToSender, nameOfSender);

            // Make a message back to the reciever
            RPCs.RPCSay rpcToReciever = new RPCs.RPCSay();
            rpcToReciever.arguments.Add(nameOfSender + " hugged you.");
            server.SendRPC(rpcToReciever, givenArguments[0]);

            // Make a message back to the sender
            RPCs.RPCSay rpcToEveryoneElse = new RPCs.RPCSay();
            rpcBackToSender.arguments.Add(nameOfSender + " hugged " + givenArguments[0]);
            server.SendRPC(rpcBackToSender, sender.position, new List <string>()
            {
                nameOfSender, givenArguments[0]
            });
        }
Beispiel #11
0
        public override void Run(List <string> givenArguments, Server server)
        {
            // ARGS: <nameOfObjectToDull> <nameOfObjectToDullWith>

            // If dead
            if (sender.specialProperties["isDeceased"] == "TRUE")
            {
                RPCs.RPCSay failure = new RPCs.RPCSay();
                failure.arguments.Add("You are deceased.");
                server.SendRPC(failure, nameOfSender);
                return;
            }

            // Get the object to dull
            World.GameObject objectToDull = server.world.FindFirstGameObject(givenArguments[0], sender.position);
            // Get the object to dull with
            World.GameObject objectToDullWith = server.world.FindFirstGameObject(givenArguments[1], sender.position);

            // Make sure both the objects exist
            if (objectToDull == null)
            {
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add("There is no nearby " + givenArguments[0] + ".");
                server.SendRPC(error, nameOfSender);
                return;
            }
            if (objectToDullWith == null)
            {
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add("There is no nearby " + givenArguments[1] + ".");
                server.SendRPC(error, nameOfSender);
                return;
            }
            // Check if the object to dull with can be used
            if (!objectToDullWith.specialProperties.ContainsKey("canBeDulledWith") || objectToDull == objectToDullWith)
            {
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add("You can't use the " + objectToDullWith.identifier.fullName + " to dull the " + objectToDull.identifier.fullName + ".");
                server.SendRPC(error, nameOfSender);
                return;
            }

            // Tell the player in the present tense that they are completing the action
            string presentTenseConfirmationString = "You are dulling " + Processing.Describer.GetArticle(objectToDull.identifier.fullName) + " " + objectToDull.identifier.fullName + "...";

            RPCs.RPCSay presentTenseConfirmation = new RPCs.RPCSay();
            presentTenseConfirmation.arguments.Add(presentTenseConfirmationString);
            server.SendRPC(presentTenseConfirmation, nameOfSender);
            // Loop the elipsis three times and send it to the player, implying work being done
            for (int i = 0; i < 5000 / 1000; i++)
            {
                Thread.Sleep(1000);
                RPCs.RPCSay elipsis = new RPCs.RPCSay();
                elipsis.arguments.Add("...");
                server.SendRPC(elipsis, nameOfSender);
            }

            // Make the object dull
            objectToDull.identifier.descriptiveAdjectives.Add("blunt");
            // If the object was sharp make shure its not
            if (objectToDull.identifier.descriptiveAdjectives.Contains("sharp"))
            {
                objectToDull.identifier.descriptiveAdjectives.Remove("sharp");
            }

            // Confirm to the sender that they dulled the object
            RPCs.RPCSay confirmation = new RPCs.RPCSay();
            confirmation.arguments.Add("You dulled the " + objectToDull.identifier.fullName + " with the " + objectToDullWith.identifier.fullName + ".");
            server.SendRPC(confirmation, nameOfSender);
            // Let everyone else in the chunk know that this player dulled something
            RPCs.RPCSay information = new RPCs.RPCSay();
            information.arguments.Add(nameOfSender + " sharpened a " + objectToDull.identifier.fullName + " with a " + objectToDullWith.identifier.fullName + ".");
            // Find everyone in the same chunk and let them know
            foreach (KeyValuePair <string, Core.Player> playerEntry in server.world.players)
            {
                // If this player is not the one that picked something up, and it's position is the same as the original player's position
                if (playerEntry.Key != nameOfSender && playerEntry.Value.controlledGameObject.position == sender.position)
                {
                    // Send an informational RPC to them letting them know
                    server.SendRPC(information, playerEntry.Key);
                }
            }
        }
        public override void Run(List <string> givenArguments, Server server)
        {
            // ARGS: <nameOfCraftingRecipe> <nameOfIngredient>

            // If dead
            if (sender.specialProperties["isDeceased"] == "TRUE")
            {
                RPCs.RPCSay failure = new RPCs.RPCSay();
                failure.arguments.Add("You are deceased.");
                server.SendRPC(failure, nameOfSender);
                return;
            }

            // Translate the name of the ingredient to a singular version, in case someone says "craft rope from vines"
            string nameOfIngredient = givenArguments[1].Singularize(false);
            // The avaliable ingredients
            List <World.GameObject> avaliableIngredients = server.world.FindGameObjects(nameOfIngredient, sender.position);
            // The ingredients that we are going to try to use
            List <World.GameObject> ingredientsToUse = new List <World.GameObject>();

            #region Make sure the recipe exists
            // First off, make sure the crafting recipe exists
            if (!server.attachedApplication.recipeDatabase.CheckRecipe(givenArguments[0]))
            {
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add(givenArguments[0] + " is not a valid crafting recipe. :(");
                server.SendRPC(error, nameOfSender);
                return;
            }
            #endregion

            #region Get the ingredients to use
            // Make sure that the necessary ingredients are avaliable

            // Refine the avaliable ingredients down to the ones that match the recipe
            foreach (World.GameObject ingredient in avaliableIngredients)
            {
                // If the current ingredient is one that can be used for this recipe, add it
                if (server.attachedApplication.recipeDatabase.GetRecipe(givenArguments[0]).ingredients.ContainsKey(ingredient.type))
                {
                    ingredientsToUse.Add(ingredient);
                }
            }
            #endregion

            #region Make sure the ingredients can be used to craft the recipe
            if (ingredientsToUse.Count == 0)
            {
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add("You can't use " + givenArguments[1].Pluralize(false) + " to craft " + Processing.Describer.GetArticle(givenArguments[0]) + " " + givenArguments[0] + ", or else there aren't any nearby.");
                server.SendRPC(error, nameOfSender);
                return;
            }
            #endregion

            #region Consume the ingredients
            // Get the amount of ingredients we need
            int amountOfIngredients = server.attachedApplication.recipeDatabase.GetRecipe(givenArguments[0]).ingredients[ingredientsToUse[0].type];
            // If there are enough ingredients, consume them
            if (ingredientsToUse.Count >= amountOfIngredients)
            {
                // Loop through the ingredients and consume the proper amount
                for (int i = 0; i < amountOfIngredients; i++)
                {
                    ingredientsToUse[i].parent.RemoveChild(ingredientsToUse[i]);
                    server.world.RemoveChild(ingredientsToUse[i]);
                }
            }
            // Otherwise, throw an error saying there aren't enough avaliable ingredients
            else
            {
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add("There aren't enough " + nameOfIngredient.Pluralize(false)
                                    + " avaliable.  It takes " + amountOfIngredients.ToString() + " and only " + ingredientsToUse.Count.ToString() + " avaliable.");
                server.SendRPC(error, nameOfSender);
                return;
            }
            #endregion

            #region Create the output object
            // With the ingredients consumed, now create the new object to output
            dynamic objectToOutput = Activator.CreateInstance(server.attachedApplication.recipeDatabase.GetRecipe(givenArguments[0]).output);
            // Let it inherit the adjectives, like "long acacia"
            objectToOutput.identifier.classifierAdjectives.Add(ingredientsToUse[0].identifier.name);
            objectToOutput.identifier.classifierAdjectives.InsertRange(0, ingredientsToUse[0].identifier.classifierAdjectives);
            objectToOutput.identifier.descriptiveAdjectives.InsertRange(0, ingredientsToUse[0].identifier.descriptiveAdjectives);

            // Tell the player in the present tense that they are completing the action
            string      presentTenseConfirmationString = "You are crafting " + Processing.Describer.GetArticle(objectToOutput.identifier.fullName) + " " + objectToOutput.identifier.fullName + "...";
            RPCs.RPCSay presentTenseConfirmation       = new RPCs.RPCSay();
            presentTenseConfirmation.arguments.Add(presentTenseConfirmationString);
            server.SendRPC(presentTenseConfirmation, nameOfSender);
            // Loop the elipsis three times and send it to the player, implying work being done
            for (int i = 0; i < 5000 / 1000; i++)
            {
                Thread.Sleep(1000);
                RPCs.RPCSay elipsis = new RPCs.RPCSay();
                elipsis.arguments.Add("...");
                server.SendRPC(elipsis, nameOfSender);
            }

            // Attach it to our chunk
            server.world.GetChunkOrGenerate(sender.position).AddChild(objectToOutput);
            #endregion

            #region Confirm that the object was crafted with a message
            // Confirm to the sender that they crafted the object
            RPCs.RPCSay confirmation = new RPCs.RPCSay();
            if (amountOfIngredients == 1)
            {
                confirmation.arguments.Add("You crafted " + Processing.Describer.GetArticle(objectToOutput.identifier.fullName) + " " + objectToOutput.identifier.fullName + " from " + amountOfIngredients.ToString() + " " + nameOfIngredient + ".");
            }
            else
            {
                confirmation.arguments.Add("You crafted " + Processing.Describer.GetArticle(objectToOutput.identifier.fullName) + " " + objectToOutput.identifier.fullName + " from " + amountOfIngredients.ToString() + " " + nameOfIngredient.Pluralize(false) + ".");
            }
            server.SendRPC(confirmation, nameOfSender);
            // Let everyone else in the chunk know that this player crafted something
            RPCs.RPCSay information = new RPCs.RPCSay();
            information.arguments.Add(nameOfSender + " crafted " + Processing.Describer.GetArticle(objectToOutput.identifier.fullName) + " " + objectToOutput.identifier.fullName + ".");
            // Find everyone in the same chunk and let them know
            foreach (KeyValuePair <string, Core.Player> playerEntry in server.world.players)
            {
                // If this player is at the same position but doesn't have the same name as the sender
                if (playerEntry.Key != nameOfSender && playerEntry.Value.controlledGameObject.position == sender.position)
                {
                    // Send an informational RPC to them letting them know
                    server.SendRPC(information, playerEntry.Key);
                }
            }
            #endregion
        }
        public override void Run(List <string> givenArguments, Server server)
        {
            // ARGS: <nameOfObject> <nameOfContainer>

            // If dead
            if (sender.specialProperties["isDeceased"] == "TRUE")
            {
                RPCs.RPCSay failure = new RPCs.RPCSay();
                failure.arguments.Add("You are deceased.");
                server.SendRPC(failure, nameOfSender);
                return;
            }

            // The object itself
            World.GameObject objectToPut = server.world.FindFirstGameObject(givenArguments[0], sender.position);
            // The container to put the object into
            World.GameObject containerToPutInto = server.world.FindFirstGameObject(givenArguments[1], sender.position);

            #region Make sure the objects exist
            // First off, make sure the crafting recipe exists
            if (containerToPutInto == null)
            {
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add("The " + givenArguments[1] + " is not nearby.");
                server.SendRPC(error, nameOfSender);
                return;
            }
            else if (objectToPut == null)
            {
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add("The " + givenArguments[0] + " is not nearby.");
                server.SendRPC(error, nameOfSender);
                return;
            }
            #endregion

            #region Make sure the container really is a container
            if (!containerToPutInto.specialProperties.ContainsKey("isContainer"))
            {
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add("The " + givenArguments[1] + " is not a container.");
                server.SendRPC(error, nameOfSender);
                return;
            }
            #endregion

            #region Make sure the object can really be put in the container
            if (objectToPut.parent.type == typeof(World.Plants.PlantRope))
            {
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add("The " + givenArguments[1] + " is attached to something.");
                server.SendRPC(error, nameOfSender);
                return;
            }
            else if (objectToPut.parent == containerToPutInto)
            {
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add("The " + givenArguments[1] + " is already inside the " + containerToPutInto.identifier.fullName + ".");
                server.SendRPC(error, nameOfSender);
                return;
            }
            else if (objectToPut == containerToPutInto)
            {
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add("You can't put the " + givenArguments[1] + " inside itself!.");
                server.SendRPC(error, nameOfSender);
                return;
            }
            #endregion

            #region Put the object inside the container
            // Add it as a child
            containerToPutInto.AddChild(objectToPut);
            #endregion

            #region Confirm that the object was put into the container
            // Confirm to the sender that they crafted the object
            RPCs.RPCSay confirmation = new RPCs.RPCSay();
            confirmation.arguments.Add("You put " + Processing.Describer.GetArticle(objectToPut.identifier.fullName) + " " + objectToPut.identifier.fullName + " into  " + Processing.Describer.GetArticle(containerToPutInto.identifier.fullName) + " " + containerToPutInto.identifier.fullName + ".");
            // Let everyone else in the chunk know that this player crafted something
            RPCs.RPCSay information = new RPCs.RPCSay();
            information.arguments.Add(nameOfSender + " put " + Processing.Describer.GetArticle(objectToPut.identifier.fullName) + " " + objectToPut.identifier.fullName + " into  " + Processing.Describer.GetArticle(containerToPutInto.identifier.fullName) + " " + containerToPutInto.identifier.fullName + ".");
            // Send the RPCs out
            server.SendRPC(confirmation, nameOfSender);
            server.SendRPC(information, sender.position, new List <string>()
            {
                nameOfSender
            });
            #endregion
        }
        public override void Run(List <string> givenArguments, Server server)
        {
            // ARGS: <nameOfObjectToApproach>

            // If dead
            if (sender.specialProperties["isDeceased"] == "TRUE")
            {
                RPCs.RPCSay failure = new RPCs.RPCSay();
                failure.arguments.Add("You are deceased.");
                server.SendRPC(failure, nameOfSender);
                return;
            }
            // Find the gameObject we are going to approach

            // Check if name is a player's name
            World.GameObject gameObjectToApproach = null;
            foreach (World.GameObject gameObject in server.world.GetChunk(sender.position).children)
            {
                if (gameObject.specialProperties.ContainsKey("isPlayer") && gameObject.identifier.name != sender.identifier.name && gameObject.identifier.name == givenArguments[0])
                {
                    // Send a message to this player saying that we left the chunk
                    gameObjectToApproach = gameObject;
                }
            }
            // If not a player, find the first object with the name
            if (gameObjectToApproach == null)
            {
                List <World.GameObject> listOfPotentialObjects = server.world.GetChunkOrGenerate(sender.position).FindChildrenWithName(givenArguments[0]);
                if (listOfPotentialObjects.Count > 0)
                {
                    gameObjectToApproach = listOfPotentialObjects.First();
                }
            }

            // If no gameObject was found, send back an error
            if (gameObjectToApproach == null)
            {
                // If this fails, let the player know
                RPCs.RPCSay failure = new RPCs.RPCSay();
                failure.arguments.Add("There is no nearby " + givenArguments[0] + ".");
                server.SendRPC(failure, nameOfSender);
                return;
            }

            // Now that we have the game object we are going to approach, make sure it isn't already in our proximity
            if (sender.gameObjectsInProximity.Contains(gameObjectToApproach))
            {
                // If this fails, let the player know
                RPCs.RPCSay failure = new RPCs.RPCSay();
                failure.arguments.Add("You are already near the " + gameObjectToApproach.identifier.fullName + ".");
                server.SendRPC(failure, nameOfSender);
                return;
            }

            // The message we're going to send back
            string intermediateResponse = "You walk up to the " + gameObjectToApproach.identifier.fullName + "...";

            RPCs.RPCSay intermediateRPC = new RPCs.RPCSay();
            intermediateRPC.arguments.Add(intermediateResponse);
            server.SendRPC(intermediateRPC, nameOfSender);

            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                Thread.Sleep(1000);

                // Add it to the list of object's in our proximity
                sender.gameObjectsInProximity.Add(gameObjectToApproach);
                gameObjectToApproach.gameObjectsInProximity.Add(sender);
                gameObjectToApproach.OnEnterProximity(sender);
                // Notify every, and modify the message a little if we are approaching a player
                if (gameObjectToApproach.specialProperties.ContainsKey("isPlayer"))
                {
                    server.world.SendMessageToPosition("You approached a " + gameObjectToApproach.identifier.fullName + ".", nameOfSender, nameOfSender + " approached " + gameObjectToApproach.identifier.fullName + ".", sender.position);
                }
                else
                {
                    server.world.SendMessageToPosition("You approached the " + gameObjectToApproach.identifier.fullName + ".", nameOfSender, nameOfSender + " approached " + Processing.Describer.GetArticle(gameObjectToApproach.identifier.fullName) + " " + gameObjectToApproach.identifier.fullName + ".", sender.position);
                }
            }).Start();
        }
Beispiel #15
0
        public override void Run(List <string> givenArguments, Server server)
        {
            // ARGS: <nameOfObjectToStrike> <nameOfObjectToUse> <(l)eft|(r)ight|(h)ead>

            // If dead
            if (sender.specialProperties["isDeceased"] == "TRUE")
            {
                RPCs.RPCSay failure = new RPCs.RPCSay();
                failure.arguments.Add("You are deceased.");
                server.SendRPC(failure, nameOfSender);
                return;
            }

            // The object to strike
            World.GameObject objectToStrike = server.world.FindFirstGameObject(givenArguments[0], sender.position);
            // The object to use
            World.GameObject objectToUse = null;

            #region Get the object to use
            // Loop through all the utilizable objects on the sender
            foreach (World.GameObject potentialObjectToUse in sender.FindChildrenWithSpecialProperty("isUtilizable"))
            {
                // If this potential object or what it's holding matches, use it
                if (potentialObjectToUse.identifier.DoesStringPartiallyMatchFullName(givenArguments[1]))
                {
                    objectToUse = potentialObjectToUse;
                    break;
                }
                // Otherwise, if this potential object's first child, the thing it's holding, matches, use it
                else if (potentialObjectToUse.children.Count > 0)
                {
                    if (potentialObjectToUse.children.First().identifier.DoesStringPartiallyMatchFullName(givenArguments[1]))
                    {
                        objectToUse = potentialObjectToUse.children.First();
                        break;
                    }
                }
            }
            #endregion

            #region Make sure the arguments are valid
            // Make sure the object to strike exists
            if (objectToStrike == null)
            {
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add("\"" + givenArguments[0] + "\" is not nearby.");
                server.SendRPC(error, nameOfSender);
                return;
            }
            // Make sure the object to use exists
            else if (objectToUse == null)
            {
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add("\"" + givenArguments[1] + "\" is not something you are holding.");
                server.SendRPC(error, nameOfSender);
                return;
            }
            // Make sure the direction to strike is valid
            else if (givenArguments[2] != "left" &&
                     givenArguments[2] != "right" &&
                     givenArguments[2] != "head" &&
                     givenArguments[2] != "l" &&
                     givenArguments[2] != "r" &&
                     givenArguments[2] != "h")
            {
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add("\"" + givenArguments[2] + "\" is not a direction to strike. Use \"left\", \"right\", or \"head\".");
                server.SendRPC(error, nameOfSender);
                return;
            }
            // Translate the short hand of the direction to block if one was used
            if (givenArguments[2] == "l")
            {
                givenArguments[2] = "left";
            }
            else if (givenArguments[2] == "r")
            {
                givenArguments[2] = "right";
            }
            else if (givenArguments[2] == "h")
            {
                givenArguments[2] = "head";
            }
            #endregion

            #region Check the stance
            if (sender.specialProperties["stance"] != "STANDING" && sender.specialProperties["stance"] != "CROUCHING")
            {
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add("You can't strike from the stance you're in.");
                server.SendRPC(error, nameOfSender);
                return;
            }
            #endregion

            #region Check the object is in proximity
            if (!sender.gameObjectsInProximity.Contains(objectToStrike))
            {
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add("You are not close enough to the " + objectToStrike.identifier.fullName + ". You must approach it first.");
                server.SendRPC(error, nameOfSender);
                return;
            }
            #endregion

            #region Calculate the time to wait
            // Calculate the time to wait, which is just the sender's reaction time plus the object's weight over our strength
            // reactionTime + (objectWeight/senderStrength)
            float timeToWait =
                float.Parse(sender.specialProperties["reactionTime"], CultureInfo.InvariantCulture.NumberFormat) +
                (float.Parse(objectToUse.specialProperties["weight"], CultureInfo.InvariantCulture.NumberFormat) /
                 float.Parse(sender.specialProperties["strength"], CultureInfo.InvariantCulture.NumberFormat));
            #endregion

            #region Tell everyone that the object is about to be struck
            // Create unique messages for the sender, reciever, and everyone else
            RPCs.RPCSay rpcToSender       = new RPCs.RPCSay();
            RPCs.RPCSay rpcToReciever     = new RPCs.RPCSay();
            RPCs.RPCSay rpcToEveryoneElse = new RPCs.RPCSay();
            // Build the messages to each person
            rpcToReciever.arguments.Add(nameOfSender + " is about to $mastrike your " +
                                        objectToStrike.identifier.fullName +
                                        " from the $oa" + givenArguments[2] + " with " +
                                        Processing.Describer.GetArticle(objectToUse.identifier.fullName) + " " +
                                        objectToUse.identifier.fullName + " in $oa" + timeToWait.ToString() + " seconds!");

            // Build the message back to the sender
            // If the object to strike was attached to a player, change the messages accordingly
            if (objectToStrike.FindParentsWithSpecialProperty("isPlayer").Count > 0)
            {
                rpcToSender.arguments.Add("You swing at " + objectToStrike.FindParentsWithSpecialProperty("isPlayer").First().identifier.name + "'s " + objectToStrike.identifier.fullName + " from the " + givenArguments[2] + " with your " +
                                          objectToUse.identifier.fullName + "!");

                rpcToEveryoneElse.arguments.Add(nameOfSender + " swings at " +
                                                objectToStrike.FindParentsWithSpecialProperty("isPlayer").First().identifier.name + "'s " +
                                                objectToStrike.identifier.fullName + " with " +
                                                Processing.Describer.GetArticle(objectToUse.identifier.fullName) + " " +
                                                objectToUse.identifier.fullName + "!");
            }
            else
            {
                rpcToSender.arguments.Add("You swing at the " + objectToStrike.identifier.fullName + " from the " + givenArguments[2] + " with your " +
                                          objectToUse.identifier.fullName + "!");

                rpcToEveryoneElse.arguments.Add(nameOfSender + " swings at " +
                                                Processing.Describer.GetArticle(objectToStrike.identifier.fullName) + " " +
                                                objectToStrike.identifier.fullName + " with " +
                                                Processing.Describer.GetArticle(objectToUse.identifier.fullName) + " " +
                                                objectToUse.identifier.fullName + "!");
            }
            // Send the confirmation back to the sender
            server.SendRPC(rpcToSender, nameOfSender);
            // If the object to strike was attached to a player, send a message to the reciever and ignore the sender and reciever of the strike command
            if (objectToStrike.FindParentsWithSpecialProperty("isPlayer").Count > 0)
            {
                server.SendRPC(rpcToReciever, objectToStrike.FindParentsWithSpecialProperty("isPlayer").First().identifier.name);
                server.SendRPC(rpcToEveryoneElse, sender.position, new List <string>()
                {
                    objectToStrike.FindParentsWithSpecialProperty("isPlayer").First().identifier.name,
                    nameOfSender
                });
            }
            // Otherwise, just send the message to everyone else saying we struck something
            else
            {
                server.SendRPC(rpcToEveryoneElse, sender.position, new List <string>()
                {
                    nameOfSender
                });
            }
            #endregion

            #region Wait for the appropriate amount of time based off of the sender strength and the object to use
            // TODO: Output ellipses in increments

            // Send back to the player how long it's going to take
            RPCs.RPCSay info = new RPCs.RPCSay();
            info.arguments.Add("Striking in " + timeToWait.ToString() + " seconds.");
            server.SendRPC(info, nameOfSender);
            // Sleep this thread for the time to wait
            Thread.Sleep((int)(timeToWait * 1000.0f));

            #endregion

            #region Check for blocking
            // Get the object that's being used to block, if any
            World.GameObject objectBeingUsedToBlock = null;
            // If we're hitting something that is a player
            if (objectToStrike.FindParentsWithSpecialProperty("isPlayer").Count > 0)
            {
                if (objectToStrike.FindParentsWithSpecialProperty("isPlayer").First().FindChildrenWithSpecialPropertyAndValue("blocking", givenArguments[2]).Count > 0)
                {
                    // Set the object being used to block
                    objectBeingUsedToBlock = objectToStrike.FindParentsWithSpecialProperty("isPlayer").First().FindChildrenWithSpecialPropertyAndValue("blocking", givenArguments[2]).First();
                    // Create unique messages for the sender, reciever, and everyone else
                    RPCs.RPCSay rpcToSenderForBlocking       = new RPCs.RPCSay();
                    RPCs.RPCSay rpcToRecieverForBlocking     = new RPCs.RPCSay();
                    RPCs.RPCSay rpcToEveryoneElseForBlocking = new RPCs.RPCSay();

                    // Build the messages to each person

                    // Build the message for the person recieving the block
                    rpcToSenderForBlocking.arguments.Add(objectToStrike.FindParentsWithSpecialProperty("isPlayer").First().identifier.fullName + " blocked your " +
                                                         objectToUse.identifier.fullName + " with " +
                                                         Processing.Describer.GetArticle(objectBeingUsedToBlock.identifier.fullName) + " " +
                                                         objectBeingUsedToBlock.identifier.fullName + "!");

                    // Build the message for the sender and everyone else.  The if is to determine whether or not we hit another player.  Change the output a little if we hit another player
                    if (objectToStrike.FindParentsWithSpecialProperty("isPlayer").Count > 0)
                    {
                        rpcToRecieverForBlocking.arguments.Add("You blocked " +
                                                               nameOfSender + "'s " +
                                                               objectToUse.identifier.fullName + " with your " +
                                                               objectBeingUsedToBlock.identifier.fullName + "!");

                        rpcToEveryoneElseForBlocking.arguments.Add(objectToStrike.FindParentsWithSpecialProperty("isPlayer").First().identifier.name + " blocked " +
                                                                   nameOfSender + "'s " +
                                                                   objectToUse.identifier.fullName + " with " +
                                                                   Processing.Describer.GetArticle(objectToStrike.identifier.fullName) + " " +
                                                                   objectToStrike.identifier.fullName + "!");
                    }
                    else
                    {
                        rpcToEveryoneElseForBlocking.arguments.Add(objectToStrike.FindParentsWithSpecialProperty("isPlayer").First().identifier.name + " blocked the " +
                                                                   nameOfSender + "'s " +
                                                                   objectToUse.identifier.fullName + " with " +
                                                                   Processing.Describer.GetArticle(objectToStrike.identifier.fullName) + " " +
                                                                   objectToStrike.identifier.fullName + "!");
                    }
                    // Send the confirmation back to the sender
                    server.SendRPC(rpcToSenderForBlocking, nameOfSender);
                    // If the object to strike was attached to a player, send a message to the reciever and ignore the sender and reciever of the strike command
                    if (objectToStrike.FindParentsWithSpecialProperty("isPlayer").Count > 0)
                    {
                        server.SendRPC(rpcToRecieverForBlocking, objectToStrike.FindParentsWithSpecialProperty("isPlayer").First().identifier.name);
                        server.SendRPC(rpcToEveryoneElseForBlocking, sender.position, new List <string>()
                        {
                            objectToStrike.FindParentsWithSpecialProperty("isPlayer").First().identifier.name,
                            nameOfSender
                        });
                    }
                    // Otherwise, just send the message to everyone else saying we struck something
                    else
                    {
                        server.SendRPC(rpcToEveryoneElseForBlocking, sender.position, new List <string>()
                        {
                            nameOfSender
                        });
                    }
                    // Stop the function here
                    return;
                }
            }
            #endregion

            #region Calculate damage
            // Get the object that will actually do damage, which could be the head of an axe, or just the stick or hand
            World.GameObject objectToDoDamage = objectToUse;
            // If the object to use has children, use the bottommost child
            if (objectToUse.children.Count > 0)
            {
                objectToDoDamage = objectToUse.GetAllChildren().Last();
            }
            // Calculate the damage
            float damage = float.Parse(objectToDoDamage.specialProperties["weight"], CultureInfo.InvariantCulture.NumberFormat);

            // Calculate damage multipliers
            // If the weapon is long, do a damage multiplier
            if (objectToUse.identifier.descriptiveAdjectives.Contains("long"))
            {
                damage *= 2;
            }
            // If weapon is sharp, do damage multiplier
            if (objectToDoDamage.identifier.descriptiveAdjectives.Contains("sharp"))
            {
                damage *= 3;
            }
            #endregion

            #region Confirm to everyone that the object was struck
            // Create unique messages for the sender, reciever, and everyone else
            RPCs.RPCSay rpcToSenderForBeingStruck       = new RPCs.RPCSay();
            RPCs.RPCSay rpcToRecieverForBeingStruck     = new RPCs.RPCSay();
            RPCs.RPCSay rpcToEveryoneElseForBeingStruck = new RPCs.RPCSay();
            // Build the messages to each person
            rpcToRecieverForBeingStruck.arguments.Add(Processing.Describer.ToColor(nameOfSender + " struck your " +
                                                                                   objectToStrike.identifier.fullName + " with " +
                                                                                   Processing.Describer.GetArticle(objectToUse.identifier.fullName) + " " +
                                                                                   objectToUse.identifier.fullName + "!", "$ma"));

            // Build the message back to the sender
            // If the object to strike was attached to a player, change the messages accordingly
            if (objectToStrike.FindParentsWithSpecialProperty("isPlayer").Count > 0)
            {
                rpcToSenderForBeingStruck.arguments.Add(Processing.Describer.ToColor("You struck " + objectToStrike.FindParentsWithSpecialProperty("isPlayer").First().identifier.name + "'s " + objectToStrike.identifier.fullName + " with your " +
                                                                                     objectToUse.identifier.fullName + "!\nYou did " + damage.ToString() + " damage!", "$ka"));

                rpcToEveryoneElseForBeingStruck.arguments.Add(nameOfSender + " struck " +
                                                              objectToStrike.FindParentsWithSpecialProperty("isPlayer").First().identifier.name + "'s " +
                                                              objectToStrike.identifier.fullName + " with " +
                                                              Processing.Describer.GetArticle(objectToUse.identifier.fullName) + " " +
                                                              objectToUse.identifier.fullName + "!");
            }
            else
            {
                rpcToSenderForBeingStruck.arguments.Add("You struck the " + objectToStrike.identifier.fullName + " with your " +
                                                        objectToUse.identifier.fullName + ", dealing " + damage.ToString() + " damage!");

                rpcToEveryoneElseForBeingStruck.arguments.Add(nameOfSender + " struck " +
                                                              Processing.Describer.GetArticle(objectToStrike.identifier.fullName) + " " +
                                                              objectToStrike.identifier.fullName + " with a " +
                                                              Processing.Describer.GetArticle(objectToUse.identifier.fullName) + " " +
                                                              objectToUse.identifier.fullName + "!");
            }
            // Send the confirmation back to the sender
            server.SendRPC(rpcToSenderForBeingStruck, nameOfSender);
            // If the object to strike was attached to a player, send a message to the reciever and ignore the sender and reciever of the strike command
            if (objectToStrike.FindParentsWithSpecialProperty("isPlayer").Count > 0)
            {
                server.SendRPC(rpcToRecieverForBeingStruck, objectToStrike.FindParentsWithSpecialProperty("isPlayer").First().identifier.name);
                server.SendRPC(rpcToEveryoneElseForBeingStruck, sender.position, new List <string>()
                {
                    objectToStrike.FindParentsWithSpecialProperty("isPlayer").First().identifier.name,
                    nameOfSender
                });
            }
            // Otherwise, just send the message to everyone else saying we struck something
            else
            {
                server.SendRPC(rpcToEveryoneElseForBeingStruck, sender.position, new List <string>()
                {
                    nameOfSender
                });
            }
            #endregion

            #region Apply damage to the object

            // Call the take damage function on the object being struck
            objectToStrike.OnStrikeThisGameObjectWithGameObject(sender, objectToDoDamage, damage);

            #region Physically change the object being struck, such as knock the player over, etc

            // If it's a player, knock them over if necessary
            // If we're hitting a player
            if (objectToStrike.FindParentsWithSpecialProperty("isPlayer").Count > 0 && objectToStrike.identifier.name.Contains("leg") ||
                objectToStrike.FindParentsWithSpecialProperty("isPlayer").Count > 0 && objectToStrike.identifier.name.Contains("head"))
            {
                if (objectToStrike.FindParentsWithSpecialProperty("isPlayer").Last().specialProperties["stance"] != "LAYING")
                {
                    #region Confirm to everyone that the player has been knocked over
                    // Create unique messages for the sender, reciever, and everyone else
                    RPCs.RPCSay rpcToSenderForBeingKnocked       = new RPCs.RPCSay();
                    RPCs.RPCSay rpcToRecieverForBeingKnocked     = new RPCs.RPCSay();
                    RPCs.RPCSay rpcToEveryoneElseForBeingKnocked = new RPCs.RPCSay();

                    rpcToSenderForBeingKnocked.arguments.Add("You knocked " + objectToStrike.FindParentsWithSpecialProperty("isPlayer").Last().identifier.fullName + " over with your " + objectToUse.identifier.fullName + " from a strike to the " + objectToStrike.identifier.fullName + "!");
                    rpcToRecieverForBeingKnocked.arguments.Add(nameOfSender + " knocked you over with " + Processing.Describer.GetArticle(objectToUse.identifier.fullName) + " " + objectToUse.identifier.fullName + " from a strike to the " + objectToStrike.identifier.fullName + "!");
                    rpcToEveryoneElseForBeingKnocked.arguments.Add(nameOfSender + " knocked " + objectToStrike.FindParentsWithSpecialProperty("isPlayer").Last().identifier.fullName + " over with " + Processing.Describer.GetArticle(objectToUse.identifier.fullName) + " " + objectToUse.identifier.fullName + " from a strike to the " + objectToStrike.identifier.fullName + "!");

                    server.SendRPC(rpcToSenderForBeingKnocked, nameOfSender);
                    server.SendRPC(rpcToRecieverForBeingKnocked, objectToStrike.FindParentsWithSpecialProperty("isPlayer").Last().identifier.name);
                    server.SendRPC(rpcToEveryoneElseForBeingKnocked, sender.position, new List <string>()
                    {
                        nameOfSender, objectToStrike.FindParentsWithSpecialProperty("isPlayer").Last().identifier.name
                    });
                    #endregion

                    #region Make the person who has been knocked fall over
                    RPCs.RPCSay rpcToRecieverForFalling = new RPCs.RPCSay();
                    rpcToRecieverForFalling.arguments.Add("You are falling...");
                    server.SendRPC(rpcToRecieverForFalling, objectToStrike.FindParentsWithSpecialProperty("isPlayer").First().identifier.name);
                    // Put them in the falling stance
                    objectToStrike.FindParentsWithSpecialProperty("isPlayer").First().specialProperties["stance"] = "FALLING";
                    new Thread(() =>
                    {
                        Thread.CurrentThread.IsBackground = true;
                        Thread.Sleep(2000);

                        RPCs.RPCSay rpcToRecieverForLaying = new RPCs.RPCSay();
                        rpcToRecieverForLaying.arguments.Add("You have fallen.");
                        server.SendRPC(rpcToRecieverForLaying, objectToStrike.FindParentsWithSpecialProperty("isPlayer").First().identifier.name);
                        // Put them in the lying stance
                        objectToStrike.FindParentsWithSpecialProperty("isPlayer").First().specialProperties["stance"] = "LAYING";
                    }).Start();

                    #endregion
                }
            }


            #endregion

            #endregion
        }
        public override void Run(List <string> givenArguments, Server server)
        {
            // ARGS: <nameOfObjectToDrop>

            // If dead
            if (sender.specialProperties["isDeceased"] == "TRUE")
            {
                RPCs.RPCSay failure = new RPCs.RPCSay();
                failure.arguments.Add("You are deceased.");
                server.SendRPC(failure, nameOfSender);
                return;
            }

            // Get the hashset of the utilizable parts of the player, like the hands, tail, etc
            List <World.GameObject> utilizableParts = sender.FindChildrenWithSpecialProperty("isUtilizable");

            // The gameObject that we will drop the object from, which will be determined
            World.GameObject utilizablePart = null;
            // The gameObject that we will drop
            World.GameObject gameObjectToDrop = null;

            #region Determine the utilizablePart to drop the object
            // First off, check if we even have a hand that can hold an object
            if (utilizableParts.Count == 0)
            {
                return;
            }
            // Find the first utilizable part that is holding the object with the name
            foreach (World.GameObject part in utilizableParts)
            {
                if (part.children.Count == 1 && part.children.First().identifier.DoesStringPartiallyMatchFullName(givenArguments[0]))
                {
                    utilizablePart = part;
                    break;
                }
            }
            // If it fails, send an appropriate message back
            if (utilizablePart == null)
            {
                RPCs.RPCSay failure = new RPCs.RPCSay();
                failure.arguments.Add("You are not holding " + Processing.Describer.GetArticle(givenArguments[0]) + " " + givenArguments[0] + ".");
                server.SendRPC(failure, nameOfSender);
                return;
            }
            #endregion

            #region Drop the object and send appripriate messages to the sender and everyone else in the chunk
            // Get the object to drop
            gameObjectToDrop = utilizablePart.children.First();
            // Add the object to the chunk
            server.world.GetChunkOrGenerate(sender.position).AddChild(gameObjectToDrop);
            // Remove it from the utilizable part
            utilizablePart.RemoveChild(gameObjectToDrop);
            // Confirm to the sender that they dropped the object
            RPCs.RPCSay confirmation = new RPCs.RPCSay();
            confirmation.arguments.Add("You dropped the " + gameObjectToDrop.identifier.fullName + " in your " + utilizablePart.identifier.fullName + ".");
            server.SendRPC(confirmation, nameOfSender);
            // Let everyone else in the chunk know that this player dropped something
            RPCs.RPCSay information = new RPCs.RPCSay();
            information.arguments.Add(nameOfSender + " dropped " + Processing.Describer.GetArticle(gameObjectToDrop.identifier.fullName) + " " + gameObjectToDrop.identifier.fullName + ".");
            // Find everyone in the same chunk and let them know
            foreach (KeyValuePair <string, Core.Player> playerEntry in server.world.players)
            {
                // If this player is not the one that picked something up, and it's position is the same as the original player's position
                if (playerEntry.Key != nameOfSender && playerEntry.Value.controlledGameObject.position == sender.position)
                {
                    // Send an informational RPC to them letting them know
                    server.SendRPC(information, playerEntry.Key);
                }
            }
            #endregion
        }
        public override void Run(List <string> givenArguments, Server server)
        {
            // ARGS: <objectToAttach> <objectToAttachTo> <objectToAttachWith>

            // If dead
            if (sender.specialProperties["isDeceased"] == "TRUE")
            {
                RPCs.RPCSay failure = new RPCs.RPCSay();
                failure.arguments.Add("You are deceased.");
                server.SendRPC(failure, nameOfSender);
                return;
            }

            // Get each of the objects necessary to do the attaching
            World.GameObject objectToAttach     = server.world.FindFirstGameObject(givenArguments[0], sender.position);
            World.GameObject objectToAttachTo   = server.world.FindFirstGameObject(givenArguments[1], sender.position);
            World.GameObject objectToAttachWith = server.world.FindFirstGameObject(givenArguments[2], sender.position);

            // Make sure the objects exist
            if (objectToAttach == null)
            {
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add("There is no nearby " + givenArguments[0] + ".");
                server.SendRPC(error, nameOfSender);
                return;
            }
            if (objectToAttachTo == null)
            {
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add("There is no nearby " + givenArguments[1] + ".");
                server.SendRPC(error, nameOfSender);
                return;
            }
            if (objectToAttachWith == null)
            {
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add("There is no nearby " + givenArguments[2] + ".");
                server.SendRPC(error, nameOfSender);
                return;
            }
            // If the object we're trying to attach with can't be used to fasten with, throw an error
            if (!objectToAttachWith.specialProperties.ContainsKey("isFastenable"))
            {
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add("You can't use " + Processing.Describer.GetArticle(objectToAttachWith.identifier.fullName) + " " + objectToAttachWith.identifier.fullName + " to fasten with.");
                server.SendRPC(error, nameOfSender);
                return;
            }

            // Tell the player in the present tense that they are completing the action
            string presentTenseConfirmationString = "You are attaching " + Processing.Describer.GetArticle(objectToAttach.identifier.fullName) + " " + objectToAttach.identifier.fullName
                                                    + " to " + Processing.Describer.GetArticle(objectToAttachTo.identifier.fullName) + " " + objectToAttachTo.identifier.fullName
                                                    + " using " + Processing.Describer.GetArticle(objectToAttachWith.identifier.fullName) + " " + objectToAttachWith.identifier.fullName + "...";

            RPCs.RPCSay presentTenseConfirmation = new RPCs.RPCSay();
            presentTenseConfirmation.arguments.Add(presentTenseConfirmationString);
            server.SendRPC(presentTenseConfirmation, nameOfSender);
            // Loop the elipsis three times and send it to the player, implying work being done
            for (int i = 0; i < 5000 / 1000; i++)
            {
                Thread.Sleep(1000);
                RPCs.RPCSay elipsis = new RPCs.RPCSay();
                elipsis.arguments.Add("...");
                server.SendRPC(elipsis, nameOfSender);
            }
            // Attach the objects together
            objectToAttachWith.AddChild(objectToAttach);
            objectToAttachTo.AddChild(objectToAttachWith);
            // The string we will send back as confirmation
            string confirmationString = "You attached " + Processing.Describer.GetArticle(objectToAttach.identifier.fullName) + " " + objectToAttach.identifier.fullName
                                        + " to " + Processing.Describer.GetArticle(objectToAttachTo.identifier.fullName) + " " + objectToAttachTo.identifier.fullName
                                        + " using " + Processing.Describer.GetArticle(objectToAttachWith.identifier.fullName) + " " + objectToAttachWith.identifier.fullName + ".";
            // The string we may or may not add
            string additionalConfirmation = "";

            // Check to see whether or not the object becomes a crafting combination
            World.Crafting.CraftingCombination possibleCombination = server.attachedApplication.recipeDatabase.CheckObjectForCombination(objectToAttachTo);
            // If so, rename the new object and have it inherit the classifier adjectives of the object we are attaching to it
            if (possibleCombination != null)
            {
                objectToAttachTo.identifier.classifierAdjectives.Clear();
                objectToAttachTo.identifier.classifierAdjectives = objectToAttach.identifier.classifierAdjectives;
                objectToAttachTo.identifier.name = possibleCombination.newName;
                additionalConfirmation           = "\nYou completed " + Processing.Describer.GetArticle(objectToAttachTo.identifier.fullName) + " " + objectToAttachTo.identifier.fullName + ".";
            }
            // Confirm to the sender that they successfully attached the object
            RPCs.RPCSay confirmation = new RPCs.RPCSay();
            confirmation.arguments.Add(confirmationString + additionalConfirmation);
            server.SendRPC(confirmation, nameOfSender);
            // Let everyone else in the chunk know that this player picked up something
            RPCs.RPCSay information = new RPCs.RPCSay();
            information.arguments.Add(nameOfSender + confirmationString.Substring(1));

            // Find everyone in the same chunk and let them know
            foreach (KeyValuePair <string, Core.Player> playerEntry in server.world.players)
            {
                // If this player is not the one that picked something up, and it's position is the same as the original player's position
                if (playerEntry.Key != nameOfSender && playerEntry.Value.controlledGameObject.position == sender.position)
                {
                    // Send an informational RPC to them letting them know
                    server.SendRPC(information, playerEntry.Key);
                }
            }
        }
Beispiel #18
0
        public override void Run(List <string> givenArguments, Server server)
        {
            // ARGS: <direction>

            // If dead
            if (sender.specialProperties["isDeceased"] == "TRUE")
            {
                RPCs.RPCSay failure = new RPCs.RPCSay();
                failure.arguments.Add("You are deceased.");
                server.SendRPC(failure, nameOfSender);
                return;
            }

            // Make sure the direction is correct
            if (World.Direction.StringToDirection(givenArguments[0]) == null)
            {
                RPCs.RPCSay newRPC = new RPCs.RPCSay();
                newRPC.arguments.Add("Invalid direction.  north | northeast | east...");
                server.SendRPC(newRPC, nameOfSender);
                return;
            }
            // Make sure the player is standing up
            if (sender.specialProperties["stance"] != "STANDING")
            {
                RPCs.RPCSay newRPC = new RPCs.RPCSay();
                newRPC.arguments.Add("You must be standing to go in a direction.");
                server.SendRPC(newRPC, nameOfSender);
                return;
            }
            // Get the direction that the player wants to go
            World.Direction desiredDirection = World.Direction.StringToDirection(givenArguments[0]);
            // Notify everyone in the current chunk that we left
            foreach (World.GameObject gameObject in server.world.GetChunkOrGenerate(sender.position).children)
            {
                if (gameObject.specialProperties.ContainsKey("isPlayer") && gameObject.identifier.name != sender.identifier.name)
                {
                    // Send a message to this player saying that we left the chunk
                    RPCs.RPCSay newRPC = new RPCs.RPCSay();
                    newRPC.arguments.Add(nameOfSender + " went " + givenArguments[0] + ".");
                    server.SendRPC(newRPC, gameObject.identifier.name);
                }
            }
            // Tell the player in the present tense that they are completing the action
            string presentTenseConfirmationString = "You are going " + givenArguments[0] + "...";

            RPCs.RPCSay presentTenseConfirmation = new RPCs.RPCSay();
            presentTenseConfirmation.arguments.Add(presentTenseConfirmationString);
            server.SendRPC(presentTenseConfirmation, nameOfSender);
            // Loop the elipsis three times and send it to the player, implying work being done
            for (int i = 0; i < 1; i++)
            {
                Thread.Sleep(1000);
                RPCs.RPCSay elipsis = new RPCs.RPCSay();
                elipsis.arguments.Add("...");
                server.SendRPC(elipsis, nameOfSender);
            }
            // Move the player in the desired direction
            server.world.MovePlayer(nameOfSender, new World.Position(sender.position.x + desiredDirection.x, sender.position.y + desiredDirection.y, sender.position.z + desiredDirection.z));
            // Notify everyone in the chunk we just arrived at that we have come
            foreach (World.GameObject gameObject in server.world.GetChunkOrGenerate(sender.position).children)
            {
                if (gameObject.specialProperties.ContainsKey("isPlayer") && gameObject.identifier.name != sender.identifier.name)
                {
                    // Send a message to this player saying that we left the chunk
                    RPCs.RPCSay newRPC = new RPCs.RPCSay();
                    newRPC.arguments.Add(nameOfSender + " came from the " + World.Direction.DirectionToString(World.Direction.GetOpposite(desiredDirection)) + ".");
                    server.SendRPC(newRPC, gameObject.identifier.name);
                }
            }
            // Send a look command

            // Describe the current chunk that the sender is on
            string description = Processing.Describer.Describe(server.world.GetChunkOrGenerate(sender.position), sender);

            // Send this new string back to the sender
            RPCs.RPCSay lookRPC = new RPCs.RPCSay();
            lookRPC.arguments.Add(description);
            server.SendRPC(lookRPC, nameOfSender);
        }
Beispiel #19
0
        public override void Run(List <string> givenArguments, Server server)
        {
            // ARGS: <nameOfObjectToPickUp> <OPTIONAL:nameOfObjectToPickUpWith>

            // If dead
            if (sender.specialProperties["isDeceased"] == "TRUE")
            {
                RPCs.RPCSay failure = new RPCs.RPCSay();
                failure.arguments.Add("You are deceased.");
                server.SendRPC(failure, nameOfSender);
                return;
            }

            // Get the hashset of the utilizable parts of the player, like the hands, tail, etc
            List <World.GameObject> utilizableParts = sender.FindChildrenWithSpecialProperty("isUtilizable");

            // The gameObject that we will take the object with, which will be determined
            World.GameObject utilizablePart = null;

            #region Determine the object to take the object
            // First off, check if we even have a hand that can hold an object
            if (utilizableParts.Count == 0)
            {
                return;
            }
            // If there was a specified part we were asked to take the object with, use that
            if (givenArguments.Count == 3)
            {
                // Loop through and find the part with the name
                foreach (World.GameObject part in utilizableParts)
                {
                    if (part.identifier.DoesStringPartiallyMatchFullName(givenArguments[1]))
                    {
                        utilizablePart = part;
                        break;
                    }
                }
                // If it fails, send an appropriate message back
                if (utilizablePart == null)
                {
                    RPCs.RPCSay confirmation = new RPCs.RPCSay();
                    confirmation.arguments.Add("You have no " + givenArguments[1] + ".");
                    server.SendRPC(confirmation, nameOfSender);
                    return;
                }
                else if (utilizablePart.children.Count > 0)
                {
                    RPCs.RPCSay confirmation = new RPCs.RPCSay();
                    confirmation.arguments.Add("Your " + givenArguments[1] + " is being used.");
                    server.SendRPC(confirmation, nameOfSender);
                    return;
                }
            }
            // Otherwise
            else
            {
                // Find the first utilizable part that is not holding something already and go with that
                foreach (World.GameObject part in utilizableParts)
                {
                    if (part.children.Count == 0)
                    {
                        utilizablePart = part;
                        break;
                    }
                }
                // If it fails, send an appropriate message back
                if (utilizablePart == null)
                {
                    RPCs.RPCSay confirmation = new RPCs.RPCSay();
                    confirmation.arguments.Add("You have nothing to hold the " + givenArguments[0] + " with.");
                    server.SendRPC(confirmation, nameOfSender);
                    return;
                }
            }
            #endregion

            #region Find the object, pick it up, and send appripriate messages to the sender and everyone else in the chunk

            // Find possible gameObjects to pick up
            List <World.GameObject> gameObjectToPickUp = server.world.GetChunkOrGenerate(sender.position).FindChildrenWithName(givenArguments[0]);
            // If no gameObject was found, send back an error
            if (gameObjectToPickUp.Count == 0)
            {
                // If this fails, let the player know
                RPCs.RPCSay failure = new RPCs.RPCSay();
                failure.arguments.Add("There is no nearby " + givenArguments[0] + ".");
                server.SendRPC(failure, nameOfSender);
                return;
            }
            // If the first gameObject we found that is a canidate to pick up isn't holding us or anything weird like that
            if (gameObjectToPickUp.First().ContainsChild(nameOfSender) == null && gameObjectToPickUp.First() != sender)
            {
                // Put the object in the players utilizable part, usually a hand
                utilizablePart.AddChild(gameObjectToPickUp.First());
                // Remove it from the chunk
                server.world.GetChunkOrGenerate(sender.position).RemoveChild(gameObjectToPickUp.First());
                // Confirm to the sender that they picked up the object
                RPCs.RPCSay confirmation = new RPCs.RPCSay();
                confirmation.arguments.Add("You picked up " + Processing.Describer.GetArticle(gameObjectToPickUp.First().identifier.fullName) + " " + gameObjectToPickUp.First().identifier.fullName + " in your " + utilizablePart.identifier.fullName + ".");
                server.SendRPC(confirmation, nameOfSender);
                // Let everyone else in the chunk know that this player picked up something
                RPCs.RPCSay information = new RPCs.RPCSay();
                information.arguments.Add(nameOfSender + " picked up " + Processing.Describer.GetArticle(gameObjectToPickUp.First().identifier.fullName) + " " + gameObjectToPickUp.First().identifier.fullName + ".");
                // Find everyone in the same chunk and let them know
                foreach (KeyValuePair <string, Core.Player> playerEntry in server.world.players)
                {
                    // If this player is not the one that picked something up, and it's position is the same as the original player's position
                    if (playerEntry.Key != nameOfSender && playerEntry.Value.controlledGameObject.position == sender.position)
                    {
                        // Send an informational RPC to them letting them know
                        server.SendRPC(information, playerEntry.Key);
                    }
                }
            }

            #endregion
        }
        public override void Run(List <string> givenArguments, Server server)
        {
            // ARGS: <(l)eft|(r)ight|(h)ead>

            // If dead
            if (sender.specialProperties["isDeceased"] == "TRUE")
            {
                RPCs.RPCSay failure = new RPCs.RPCSay();
                failure.arguments.Add("You are deceased.");
                server.SendRPC(failure, nameOfSender);
                return;
            }

            // The object to block with
            World.GameObject objectToBlockWith = null;

            #region Validate the argument
            if (givenArguments[0] != "left" &&
                givenArguments[0] != "right" &&
                givenArguments[0] != "head" &&
                givenArguments[0] != "l" &&
                givenArguments[0] != "r" &&
                givenArguments[0] != "h")
            {
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add("\"" + givenArguments[0] + "\" is not a valid direction to block. Use \"left\", \"right\", or \"head\".");
                server.SendRPC(error, nameOfSender);
                return;
            }
            // Translate the short hand of the direction to block if one was used
            if (givenArguments[0] == "l")
            {
                givenArguments[0] = "left";
            }
            else if (givenArguments[0] == "r")
            {
                givenArguments[0] = "right";
            }
            else if (givenArguments[0] == "h")
            {
                givenArguments[0] = "head";
            }
            #endregion

            #region Get the object to block with
            // Make sure there is an object to block with
            if (sender.FindChildrenWithSpecialProperty("isUtilizable").Count <= 0)
            {
                RPCs.RPCSay error = new RPCs.RPCSay();
                error.arguments.Add("You have nothing to block with.");
                server.SendRPC(error, nameOfSender);
                return;
            }
            // Loop through all the utilizable objects on the sender
            foreach (World.GameObject potentialObjectToUse in sender.FindChildrenWithSpecialProperty("isUtilizable"))
            {
                // If this potential object's thing being held matches, use it
                if (potentialObjectToUse.children.Count > 0)
                {
                    objectToBlockWith = potentialObjectToUse.children.First();
                    break;
                }
            }
            // If the loop didn't find anything that the sender is holding to block with, just use the first utilizable part
            if (objectToBlockWith == null)
            {
                objectToBlockWith = sender.FindChildrenWithSpecialProperty("isUtilizable").First();
            }
            #endregion

            #region Set the attribute on the object to block with, and set a timer to cancel it
            objectToBlockWith.specialProperties["blocking"] = givenArguments[0];
            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                Thread.Sleep(2000);
                objectToBlockWith.specialProperties["blocking"] = "NULL";

                RPCs.RPCSay rpcToSenderForReset       = new RPCs.RPCSay();
                RPCs.RPCSay rpcToEveryoneElseForReset = new RPCs.RPCSay();

                rpcToSenderForReset.arguments.Add("You let down your guard.");
                rpcToEveryoneElseForReset.arguments.Add(nameOfSender + " let down their guard.");

                server.SendRPC(rpcToSenderForReset, nameOfSender);
                server.SendRPC(rpcToEveryoneElseForReset, sender.position, new List <string>()
                {
                    nameOfSender
                });
            }).Start();
            #endregion

            #region Confirm the block
            RPCs.RPCSay rpcToSender       = new RPCs.RPCSay();
            RPCs.RPCSay rpcToEveryoneElse = new RPCs.RPCSay();

            rpcToSender.arguments.Add("You blocked to your " + givenArguments[0] + " with your " + objectToBlockWith.identifier.fullName + "!");
            rpcToEveryoneElse.arguments.Add(nameOfSender + " blocked to the " + givenArguments[0] + " with " + Processing.Describer.GetArticle(objectToBlockWith.identifier.fullName) + " " + objectToBlockWith.identifier.fullName + "!");

            server.SendRPC(rpcToSender, nameOfSender);
            server.SendRPC(rpcToEveryoneElse, sender.position, new List <string>()
            {
                nameOfSender
            });
            #endregion
        }