Beispiel #1
0
    /// <summary>
    /// Check the WorldEvent's trigger conditions with the current game state.
    /// If every one of them evaluates to True, trigger the actions.
    /// </summary>
    /// <returns>True if the WorldEvent cannot be triggered anymore, False otherwise.</returns>
    public bool CheckEvent(IScriptContext context, out bool triggered)
    {
        Assert.IsTrue(active);
        triggered = false;
        // trigger limits check
        int limit;

        if (!triggersLimit.Compute(context, out limit))
        {
            Debug.Log($"WorldEvent - Event \"{info.Id}\" : evaluation error in limit \"{info.TriggerLimit}\".");
            active = false;
            return(true);
        }
        if (limit >= 0 && triggersCount >= limit)
        {
            Debug.Log($"WorldEvent - Event \"{info.Id}\" reached its triggers limit ({limit}).");
            active = false;
            return(true);
        }

        // condition check : all conditions must evaluate to True
        bool validated;

        if (!condition.Compute(context, out validated))
        {
            Debug.Log($"WorldEvent - Event \"{info.Id}\" : error while " +
                      $"evaluating condition \"{info.TriggerCondition}\".");
        }
        if (!validated)
        {
            return(false);
        }

        // action when triggered
        Debug.Log($"WorldEvent - Event \"{info.Id}\" triggered ! " +
                  $"Triggers count = {++triggersCount}, limit = {limit}.");
        if (action.Execute(context) == null)
        {
            Debug.LogError($"WorldEvent - Event \"{info.Id}\" activation : error " +
                           $"while evaluating Action script \"{info.TriggerAction}\".");
            computedTitle = computedDescription = "$ SCRIPT EXECUTION ERROR $";
            return(true);
        }
        computedTitle       = ComputeTitle(context);
        computedDescription = ComputeDescription(context);
        triggered           = true;
        return(false);
    }
Beispiel #2
0
        public bool CheckFeature(IScriptContext context)
        {
            // requirement check
            bool validated;

            if (!requirement.Compute(context, out validated))
            {
                Debug.LogError($"EngineFeature \"{info.Id}\" : error while evaluating requirement \"{info.Requirement}\".");
                return(true);
            }
            if (!validated)
            {
                return(false);
            }

            // action when triggered
            allowed = true;
            Debug.Log($"WorldEngineFeature - Engine feature {info.Id} is now allowed.");
            return(true);
        }