Ejemplo n.º 1
0
        // This is a child function of the one above. It does the inverse of GetAllContents
        private static void ListAllContents(Contents contents, XmlWriter xw)
        {
            xw.WriteStartElement("Contents");
            if (contents == null)
            {
                xw.WriteEndElement();
                return;
            }

            xw.WriteAttributeString("Name", contents.Name);
            xw.WriteAttributeString("ID", contents.ID.ToString());
            xw.WriteAttributeString("VisualChar", contents.VisualChar.ToString());
            xw.WriteAttributeString("Transparent", contents.Transparent.ToString());
            xw.WriteAttributeString("Durability", contents.Durability.ToString());
            xw.WriteAttributeString("Size", contents.Size.ToString());
            xw.WriteAttributeString("Weight", contents.Weight.ToString());
            xw.WriteAttributeString("Container", contents.Container.ToString());
            xw.WriteAttributeString("ContainerSpace", contents.ContainerSpace.ToString());


            if (UseActions.TryGetIdentifier(contents.UseAction, out string actionResult) && Behavior.TryGetIdentifiers(contents.Behaviors, out string behaviorResult))
            {
                xw.WriteAttributeString("UseAction", actionResult);
                xw.WriteAttributeString("Behavior", behaviorResult);
            }
            xw.WriteStartElement("Contained");
            if (contents.Container)
            {
                foreach (Contents contained in contents.Contained)
                {
                    ListAllContents(contained, xw);
                }
            }
            xw.WriteEndElement();
            xw.WriteStartElement("Tags");

            xw.WriteAttributeString("Tags", string.Join(',', contents.Tags));

            xw.WriteEndElement();
            xw.WriteEndElement();
        }
Ejemplo n.º 2
0
        public void PerformResult()
        {
            if (!World.GetContentsFromID(ResultContentsID, out Contents contents))
            {
                // Contents was destroyed - or does not exist
                return;
            }
            // Making lowercase provides less ability to mess up
            switch (ResultType.ToLower())
            {
            case "useaction":
                if (!UseActions.TryGetAction(ResultInformation, out Action <string[], Contents> useAction))
                {
                    Output.WriteLineTagged("Contents: " + contents.Name + " (" + contents.ID + ") has an incorrect UseAction.", Output.Tag.Error);
                    return;
                }
                useAction(new string[0], contents);
                break;

            case "behavior":
                if (!Behavior.TryGetBehaviors(ResultInformation.Split(","), out Action <Contents>[] behaviors))
Ejemplo n.º 3
0
        // This is a child function of the one above. It recursively gets all contents, since a contents can contain a contents.
        // This is the only reasonable way to get all contents (thus, the name)
        private static List <Contents> GetAllContents(XmlReader xr)
        {
            List <Contents> contentsList = new List <Contents>();

            if (!xr.HasAttributes)
            {
                contentsList.Add(null);
                xr.Read();
                return(contentsList);
            }
            while (xr.Name == "Contents")
            {
                Contents contents = new Contents("", 0, ' ', true, 1, 1, 1f, UseActions.DoesNothing, new Action <Contents>[] { Behavior.DoesNothing });
                xr.MoveToNextAttribute();
                contents.Name = xr.Value;

                xr.MoveToNextAttribute();
                contents.ID = int.Parse(xr.Value);
                if (contents.ID > Contents.uniqueIndex)
                {
                    Contents.uniqueIndex = contents.ID;
                }

                xr.MoveToNextAttribute();
                contents.VisualChar = xr.Value[0];

                xr.MoveToNextAttribute();
                contents.Transparent = bool.Parse(xr.Value);

                xr.MoveToNextAttribute();
                contents.Durability = int.Parse(xr.Value);

                xr.MoveToNextAttribute();
                contents.Size = int.Parse(xr.Value);

                xr.MoveToNextAttribute();
                contents.Weight = float.Parse(xr.Value);

                xr.MoveToNextAttribute();
                contents.Container = bool.Parse(xr.Value);

                xr.MoveToNextAttribute();
                contents.ContainerSpace = int.Parse(xr.Value);

                xr.MoveToNextAttribute();
                UseActions.TryGetAction(xr.Value, out Action <string[], Contents> action);
                contents.UseAction = action;

                xr.MoveToNextAttribute();
                Behavior.TryGetBehaviors(xr.Value.Split(','), out Action <Contents>[] behaviors);
                contents.Behaviors = behaviors;

                xr.Read();
                if (xr.HasValue)
                {
                    contents.Contained = GetAllContents(xr);
                }

                xr.Read();

                xr.MoveToNextAttribute();
                contents.Tags = xr.Value.Split(',');

                xr.Read();
                xr.Read();
                contentsList.Add(contents);
            }
            return(contentsList);
        }
Ejemplo n.º 4
0
        // Used in InterpretTile() and other cases. Prompts user for all aspects of Contents
        public static bool InterpretContents(out Contents result)
        {
            Output.WriteLineToConsole("\nContents");
            result = null;
            int uniqueID = Contents.UniqueID();

            Dictionary <string, string> preContainerParamMap = new Dictionary <string, string>()
            {
                { "Name", GetUserResponse("Name (unique identifier)<string>:") },
                { "VisualChar", GetUserResponse("Visual character (to represent on the grid)<character>:") },
                { "Transparent", GetUserResponse("Would you like this tile to be transparent? (visible and targetable through)<boolean>:") },
                { "Durability", GetUserResponse("Durability (health points)<integer>:") },
                { "Size", GetUserResponse("Size (space it takes up in containers)<integer>:") },
                { "Weight", GetUserResponse("Weight (Depending on player strength, they may or may not be able to pick this up)<float>:\nCurrent player strength is " + World.Player.Strength) },
                { "Action", string.Empty },
                { "Behavior", string.Empty },
                { "Tags", string.Empty }
            };

            Output.WriteLineTagged("Choose an action that this contents takes", Output.Tag.Prompt);
            if (!CommandInterpretation.InterpretString(UseActions.GetIdentifiers(), out string actionString))
            {
                Output.WriteLineTagged("Action was not a valid response", Output.Tag.Error);
                return(false);
            }
            preContainerParamMap["Action"] = actionString;

            if (preContainerParamMap["Action"] == "Dialogue")
            {
                string dialogue = CommandInterpretation.GetUserResponse("Please enter the line of dialogue for this contents");
                World.Dialogue.Add(uniqueID, dialogue);
            }

            Output.WriteLineTagged("Choose a behavior for this contents", Output.Tag.Prompt);
            do
            {
                if (!CommandInterpretation.InterpretString(Behavior.GetIdentifiers(), out string behaviorString))
                {
                    Output.WriteLineTagged("Behavior was not a valid response", Output.Tag.Error);
                    return(false);
                }
                preContainerParamMap["Behavior"] += behaviorString + ",";
            } while (CommandInterpretation.AskYesNo("Would you like to add any more behavior?"));

            string tempBehavior = preContainerParamMap["Behavior"];

            tempBehavior = tempBehavior.Substring(0, tempBehavior.Length - 1);

            #region Checking params
            if (!InterpretInt(preContainerParamMap["Durability"], out int durability))
            {
                Output.WriteLineTagged("Durability was not in integer format", Output.Tag.Error);
                return(false);
            }
            if (!InterpretInt(preContainerParamMap["Size"], out int size))
            {
                Output.WriteLineTagged("Size was not in integer format", Output.Tag.Error);
                return(false);
            }
            if (!InterpretFloat(preContainerParamMap["Weight"], out float weight))
            {
                Output.WriteLineTagged("Weight was not in float format", Output.Tag.Error);
                return(false);
            }

            if (!UseActions.TryGetAction(preContainerParamMap["Action"], out Action <string[], Contents> action))
            {
                Output.WriteLineTagged("Action was not found", Output.Tag.Error);
                return(false);
            }

            if (!Behavior.TryGetBehaviors(tempBehavior.Split(","), out Action <Contents>[] behavior))