Example #1
0
    public override void Execute(BattleObject actor, GameAction action)
    {
        base.Execute(actor, action);
        SubactionVarData variable = arg_dict["variable"];
        SubactionVarData data     = arg_dict["value"];

        if (variable.source == SubactionSource.OWNER)
        {
            //Only set the variable if there isn't already one present
            if (!actor.HasVar(variable.data))
            {
                variable.SetVariableInTarget(actor, action, data.GetData(actor, action));
            }
        }
        else if (variable.source == SubactionSource.ACTION)
        {
            //Only set the variable if there isn't already one present
            if (!action.HasVar(variable.data))
            {
                variable.SetVariableInTarget(actor, action, data.GetData(actor, action));
            }
        }
    }
    public override void Execute(BattleObject obj, GameAction action)
    {
        SubactionVarData var1 = arg_dict["var1"];
        SubactionVarData var2 = arg_dict["var2"];
        string           cond = (string)GetArgument("cond", obj, action, "==");

        bool value = false; //If the cond isn't set right, this subaction will always return false

        if (cond == "==")
        {
            value = (var1.GetData(obj, action) == var2.GetData(obj, action));
        }
        if (cond == "!=")
        {
            value = (var1.GetData(obj, action) != var2.GetData(obj, action));
        }

        if (var1.IsNumeric() && var2.IsNumeric()) //If they're both numeric, we can compare them
        {
            float var1data = (float)var1.GetData(obj, action);
            float var2data = (float)var2.GetData(obj, action);

            if (cond == "<")
            {
                value = (var1data < var2data);
            }
            if (cond == ">")
            {
                value = (var1data > var2data);
            }
            if (cond == "<=")
            {
                value = (var1data <= var2data);
            }
            if (cond == ">=")
            {
                value = (var1data >= var2data);
            }
        }

        if (var1.type == SubactionVarType.BOOL && var2.type == SubactionVarType.BOOL)
        {
            bool var1data = (bool)var1.GetData(obj, action);
            bool var2data = (bool)var2.GetData(obj, action);

            if (cond == "&&")
            {
                value = var1data && var2data;
            }
            if (cond == "||")
            {
                value = var1data || var2data;
            }
            if (cond == "^")
            {
                value = var1data ^ var2data;
            }
            if (cond == "!&")
            {
                value = !(var1data && var2data);
            }
            if (cond == "!|")
            {
                value = !(var1data || var2data);
            }
            if (cond == "!^")
            {
                value = !(var1data ^ var2data);
            }
        }

        action.cond_list.Add(value);
        action.cond_depth++;
    }