Example #1
0
    public virtual bool Register(Verb verb, Dictionary <string, object> data, bool fromPlayer = false)
    {
        if (!data.ContainsKey("gameObject"))
        {
            data["gameObject"] = verb.self;
        }
        if (!data.ContainsKey("verb"))
        {
            data["verb"] = verb;
        }
        if (!data.ContainsKey("label"))
        {
            data["label"] = verb.displayLabel;
        }

        Double actionTime = 0;

        try {
            actionTime = (Double)verb.blackboard["actionTime"];
        } catch (SystemException e) { }

        bool success = false;

        try {
            success = TimelineManager.instance.RegisterEvent((d) => { verb.Action(d); }, data, actionTime);
        } catch (SystemException e) {
            WaywardManager.instance.Log($@"<red>Verb '{verb.displayLabel}' failed registering action:</red> {e}");
            return(false);
        }

        // XXX: Set the game objects current action here

        if (fromPlayer)
        {
            if (success)
            {
                try {
                    GameManager.instance.Update(actionTime);
                } catch (SystemException e) {
                    WaywardManager.instance.Log($@"<red>Verb '{verb.displayLabel}' failed updating GameManager:</red> {e}");
                    return(false);
                }
            }
            WaywardManager.instance.Update();
        }

        return(success);
    }
Example #2
0
    public override bool ParseInput(Verb verb, InputEventArgs inputEventArgs)
    {
        if (inputEventArgs.parsed)
        {
            return(true);
        }
        if (inputEventArgs.parameters.Length <= 0)
        {
            WaywardManager.instance.DisplayMessage("Phase where?");
            return(true);
        }

        if (CheckForOutInput(verb, inputEventArgs))
        {
            return(true);
        }

        GameObject foundObject = GetInputTarget(verb, inputEventArgs);

        if (foundObject == null)
        {
            return(true);
        }
        if (foundObject == verb.self)
        {
            WaywardManager.instance.DisplayMessage($"You cannot phase into yourself.");
            return(true);
        }

        if (verb.Check(foundObject) == CheckResult.VALID)
        {
            verb.Action(new Dictionary <string, object>()
            {
                { "target", foundObject }
            });
            return(true);
        }
        else
        {
            WaywardManager.instance.DisplayMessage($"Could not phase into {foundObject.GetData("name").text}.");
        }

        return(false);
    }
Example #3
0
    private bool CheckForOutInput(Verb verb, InputEventArgs inputEventArgs)
    {
        if (inputEventArgs.parameters[0].ToLower() != "out")
        {
            return(false);
        }

        if (verb.self.container != null)
        {
            GameObject container = verb.self.container.GetParent();
            if (container.container != null &&
                verb.Check(container.container.GetParent()) == CheckResult.VALID)
            {
                verb.Action(new Dictionary <string, object>()
                {
                    { "target", container.container.GetParent() }
                });
                return(true);
            }
        }

        WaywardManager.instance.DisplayMessage("Could not phase out.");
        return(true);
    }
Example #4
0
    public static void Parse(string input)
    {
        //Split the input on whitespace
        string pattern = @"\s";

        string[]      splitInput = Regex.Split(input, pattern);
        List <string> fInput     = new List <string>(splitInput);

        stripInput(fInput);         // Strip known usless words, we let these be typed in for the players benefit

        //If we have no input left, do invalid input handling and return
        if (fInput.Count < 0)
        {
            //invalid input handling goes here
            sendError("Nothing left after split");
            return;
        }

        // Expression: (verb) ((modifier)*(noun)+)*
        //This is the expression we are trying to break down into.
        //Firt we will assume the first string is always the verb after stripping input.
        //Then we loop through and try to make modifier/noun pairs
        //If there is a modifier, there has to be a noun that follows (look AT TREE)
        //However, we may have a noun that does not have a modifier (grab ROCK)


        //Assume the first string is the verb
        string verbInput = removeFirst(fInput);

        Verb verb = null;

        //Compare verb to verb list
        foreach (Verb v in TextParser.currentParser.verbs)
        {
            foreach (string s in v.getVerbText())
            {
                if (s.Equals(verbInput))
                {
                    //Yay! we found matching verb
                    verb = v;
                }
            }
        }

        //If we didnt find a verb, cause and error and exit
        if (verb == null)
        {
            //Handle invalid input here
            sendError("I'm not sure I know how to do that.");
            return;
        }

        List <string[]> modifierNounPairs = new List <string[]>();

        while (fInput.Count > 0)
        {
            string[] pair = new string[2];             // We use a array of two strings to hold the modifier noun pair
            //Get the first token, there has to be one or else we could never loop here
            string c = removeFirst(fInput);

            bool foundMod = false;
            //Check if that token is a modifier,
            foreach (string s in verb.getModText())
            {
                if (s.Equals(c))
                {
                    //This is a modifier
                    pair[0]  = c;
                    foundMod = true;
                }
            }
            //Debug.Log("foundMod: " + foundMod);
            //based on weather or not we found a modifier, we do different things
            if (foundMod == false)
            {
                //since it was not a mod, we assume it was a noun add it to the pair and move on
                pair[1] = c;
                modifierNounPairs.Add(pair);
                continue;
            }
            else
            {
                //we found a mod, that means there has to be a noun that goes with it
                //check if the list has anything left
                if (fInput.Count < 1)
                {
                    //This input has failed
                    sendError(c + " WHAT?");
                    return;
                }
                //Grab what we think is a noun
                string noun = removeFirst(fInput);

                //Put it in the pair, and add the pair to the list
                pair[1] = noun;
                modifierNounPairs.Add(pair);
            }
        }
        //Call the action now that we have doen all the preprocessing
        verb.Action(GameState.currentState, modifierNounPairs);
    }