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: <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: <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); } } }