Ejemplo n.º 1
0
    private bool CheckCondition(string condition)
    {
        if (String.IsNullOrEmpty(condition))
        {
            return(true);
        }

        // Conditions should be in the format ObjectName.Method(Param1, Param2) operand RequiredResult
        var   re    = new Regex(@"\s*(?<object>[^.]+).(?<method>[^\(]+)\((?<parameters>[^\)]*)\)\s(?<operand>[^\s]*)\s(?<value>.*)");
        Match match = re.Match(condition);

        if (!match.Success)
        {
            throw new Exception();
        }

        string objectName    = match.Groups["object"].Value;
        string methodName    = match.Groups["method"].Value;
        string parameters    = match.Groups["parameters"].Value;
        string operand       = match.Groups["operand"].Value;
        string desiredResult = match.Groups["value"].Value;

        // Build Parameters and return value object
        SendMessageCallParams methodCallParams = new SendMessageCallParams()
        {
            Parameters = parameters.Split(','),
            Result     = ""
        };

        // Call the method on the object specified
        if (objectName == "Player")
        {
            Player.SendMessage(methodName, methodCallParams);
        }
        else
        {
            GameObject.Find(objectName).SendMessage(methodName, methodCallParams);
        }

        // Check the result
        switch (operand)
        {
        case "==": return(methodCallParams.Result == desiredResult);

        case "!=": return(methodCallParams.Result != desiredResult);

        case ">=": return(Convert.ToDouble(methodCallParams.Result) >= Convert.ToDouble(desiredResult));

        case "<=": return(Convert.ToDouble(methodCallParams.Result) <= Convert.ToDouble(desiredResult));

        case ">": return(Convert.ToDouble(methodCallParams.Result) > Convert.ToDouble(desiredResult));

        case "<": return(Convert.ToDouble(methodCallParams.Result) < Convert.ToDouble(desiredResult));

        default: return(false);
        }
    }
Ejemplo n.º 2
0
    private void ParseActions(string action)
    {
        if (action == "")
        {
            return;
        }

        // Actions should be in the format ObjectName.Method(Param1, Param2)
        var   re    = new Regex(@"\s*(?<object>[^.]+).(?<method>[^\(]+)\((?<parameters>[^\)]*)\)");
        Match match = re.Match(action);

        if (!match.Success)
        {
            throw new Exception();
        }

        string objectName = match.Groups["object"].Value;
        string methodName = match.Groups["method"].Value;

        string[] parameters = match.Groups["parameters"].Value.Split(',');

        SendMessageCallParams methodCallParams = new SendMessageCallParams()
        {
            Parameters = parameters,
            Result     = ""
        };

        switch (objectName)
        {
        case "Dialogue":
            switch (methodName)
            {
            case "Go":
                CurrentStep   = Convert.ToInt32(parameters[0]) - 1;
                CurrentChoice = 0;
                break;

            case "End":
                EndConversation();
                break;
            }
            break;

        case "Player": Player.SendMessage(methodName, methodCallParams); break;

        default: GameObject.Find(objectName).SendMessage(methodName, methodCallParams); break;
        }
    }
Ejemplo n.º 3
0
 public void ReceiveAsset(SendMessageCallParams parameters)
 {
     Debug.Log("Player Received Asset #" + parameters.Parameters[0]);
 }
Ejemplo n.º 4
0
 public void OnQuest(SendMessageCallParams parameters)
 {
     parameters.Result = "True";
 }
Ejemplo n.º 5
0
 public void QuestCount(SendMessageCallParams parameters)
 {
     parameters.Result = CurrentQuests.Count.ToString();
 }