Пример #1
0
    // Update is called once per frame
    public virtual void Update()
    {
        /*
         * if (sprite_rate != 0) // if it's zero, no need to animate
         * {
         *  int sprite_number = Mathf.FloorToInt(current_frame / sprite_rate);
         *  if (sprite_rate < 0)
         *      sprite_number = Mathf.FloorToInt(current_frame / sprite_rate) - 1;
         *  if (loop)
         *      actor.SendMessage("ChangeSubimageWithLoop", sprite_number,SendMessageOptions.RequireReceiver);
         *  else
         *      actor.SendMessage("ChangeSubimage", sprite_number,SendMessageOptions.RequireReceiver);
         * }
         */
        executeSubGroup(SubactionGroup.BEFORE);
        actor.SendMessage("ChangeSubimage", current_frame);
        executeSubGroup(SubactionGroup.ONFRAME(current_frame));
        executeSubGroup(SubactionGroup.AFTER);

        //Sometimes, we might end up AFTER the last frame. For all intents and purposes, every frame after the last frame is also the last frame
        if (current_frame >= last_frame)
        {
            executeSubGroup(SubactionGroup.LAST);
            if (!isInBuilder)
            {
                if (exit_action != null && exit_action != "")
                {
                    actor.SendMessage("DoAction", exit_action);
                }
            }
        }
    }
    public override void Execute(BattleObject actor, GameAction action)
    {
        base.Execute(actor, action);
        bool  relative = (bool)GetArgument("relative", actor, action, false);
        float x        = (float)GetArgument("x", actor, action);

        if (relative)
        {
            actor.SendMessage("ChangeXPreferredBy", x);
        }
        else
        {
            actor.SendMessage("ChangeXPreferred", x);
        }
    }
Пример #3
0
    public override void Execute(BattleObject actor, GameAction action)
    {
        base.Execute(actor, action);
        float degrees = (float)GetArgument("degrees", actor, action);

        actor.SendMessage("RotateSprite", degrees);
    }
    public override void Execute(BattleObject actor, GameAction action)
    {
        base.Execute(actor, action);
        bool relative = (bool)GetArgument("relative", actor, action, false);

        if (arg_dict.ContainsKey("xspeed"))
        {
            if (relative)
            {
                actor.SendMessage("ChangeXSpeedBy", GetArgument("xspeed", actor, action));
            }
            else
            {
                actor.SendMessage("ChangeXSpeed", GetArgument("xspeed", actor, action));
            }
        }
        if (arg_dict.ContainsKey("yspeed"))
        {
            if (relative)
            {
                actor.SendMessage("ChangeYSpeedBy", GetArgument("yspeed", actor, action));
            }
            else
            {
                actor.SendMessage("ChangeYSpeed", GetArgument("yspeed", actor, action));
            }
        }
        if (arg_dict.ContainsKey("xpref"))
        {
            if (relative)
            {
                actor.SendMessage("ChangeXPreferredBy", GetArgument("xpref", actor, action));
            }
            else
            {
                actor.SendMessage("ChangeXPreferred", GetArgument("xpref", actor, action));
            }
        }
        if (arg_dict.ContainsKey("ypref"))
        {
            if (relative)
            {
                actor.SendMessage("ChangeYPreferredBy", GetArgument("ypref", actor, action));
            }
            else
            {
                actor.SendMessage("ChangeYPreferred", GetArgument("ypref", actor, action));
            }
        }
    }
Пример #5
0
    public override void Execute(BattleObject obj, GameAction action)
    {
        //Arguments
        float xFactor = (float)GetArgument("xFactor", obj, action, 0);

        //Variables from fighter
        float change_x = obj.GetFloatVar(TussleConstants.MotionVariableNames.XSPEED);
        float xPref    = obj.GetFloatVar(TussleConstants.MotionVariableNames.XPREF);

        //Values from settings
        float friction    = Settings.current_settings.friction_ratio;
        float air_control = Settings.current_settings.aircontrol_ratio;

        if (obj.GetBoolVar(TussleConstants.FighterVariableNames.IS_GROUNDED))
        {
            xFactor = xFactor * friction;
        }
        else
        {
            xFactor = xFactor * air_control;
        }

        if (change_x > xPref)
        {
            float diff = change_x - xPref;
            change_x -= Mathf.Min(diff, xFactor);
        }
        else if (change_x < xPref)
        {
            float diff = xPref - change_x;
            change_x += Mathf.Min(diff, xFactor);
        }

        //Finally, update our actual speed
        obj.SendMessage("ChangeXSpeed", change_x);
    }
Пример #6
0
    public override void Execute(BattleObject obj, GameAction action)
    {
        string sprite = (string)GetArgument("sprite", obj, action);

        obj.SendMessage("ChangeSprite", sprite);
    }
 public override void Execute(BattleObject actor, GameAction action)
 {
     base.Execute(actor, action);
     actor.SendMessage("UnRotate");
 }
Пример #8
0
    public override void Execute(BattleObject obj, GameAction action)
    {
        int subimage = (int)GetArgument("subimage", obj, action);

        obj.SendMessage("ChangeSubimage", subimage);
    }
Пример #9
0
    public static void executeSubaction(string subact, BattleObject actor, GameAction action)
    {
        string[] args = subact.Split(' ');

        switch (args[0])
        {
        // ====== CONTROL SUBACTIONS ======\\
        case "DoAction":
            /* doAction actionName:string
             *      Switches the fighter's action to actionName
             */
            actor.BroadcastMessage("DoAction", args[1]);
            break;

        case "DoTransition":
            /* doTransition transitionState:string
             *      Executes the named helper StateTransition
             */
            StateTransitions.LoadTransitionState(args[1], actor.GetAbstractFighter());
            break;

        case "SetFrame":
            /* setFrame frameNumber:int
             *      Sets the current frame to the given number
             */
            action.current_frame = int.Parse(args[1]);
            break;

        case "ChangeFrame":
            /* changeFrame frameNumber:int|1
             *      Changes the action frame by the specified amount.
             */
            action.current_frame += int.Parse(args[1]);
            break;

        case "SetVar":
            /* setVar source:string name:string type:string value:dynamic relative:bool|false
             *      Sets the variable from GameAction, Fighter, Global with the given name to the given value and type.
             *      If relative is set and type is something that can be relative, such as integer, it will increment
             *      the variable instead of changing it
             */
            //TODO
            break;

        case "IfVar":
            /* ifVar source:string name:string compare:string|== value:dynamic|true
             *      Sets the action condition to the result of the logical equation compare(source|name, value)
             */
            //TODO
            break;

        case "Else":
            /* else
             *      inverts the current action condition
             */
            //TODO
            break;

        case "Endif":
            /* endif
             *      unsets the current action condition
             */
            //TODO
            break;

        // ====== CONTROL SUBACTIONS ======\\
        case "ChangeSpeed":
            /* changeSpeed x:float|_ y:float|_ xpref:float|_ ypref:float|_ relative:bool|false
             *      changes the xSpeed, ySpeed, xPreferred, yPreferred speeds. If set to null, value will remain the same
             */
            if (args[1] != "_")
            {
                actor.SendMessage("ChangeXSpeed", float.Parse(args[1]));
            }
            if (args[2] != "_")
            {
                actor.SendMessage("ChangeYSpeed", float.Parse(args[2]));
            }
            if (args[3] != "_")
            {
                actor.SendMessage("ChangeXPreferred", float.Parse(args[3]));
            }
            if (args[4] != "_")
            {
                actor.SendMessage("ChangeYPreferred", float.Parse(args[4]));
            }
            break;

        case "ChangeXSpeed":
            /* changeXSpeed x:float rel:bool
             *      changes the xSpeed of the fighter
             */
            if (args.Length > 2)
            {
                actor.SendMessage("ChangeXSpeedBy", float.Parse(args[1]) * actor.GetIntVar(TussleConstants.FighterVariableNames.FACING_DIRECTION));
            }
            else
            {
                actor.SendMessage("ChangeXSpeed", float.Parse(args[1]) * actor.GetIntVar(TussleConstants.FighterVariableNames.FACING_DIRECTION));
            }
            break;

        case "ChangeYSpeed":
            /* changeYSpeed y:float rel:bool
             *      changes the ySpeed of the fighter
             */
            if (args.Length > 2)
            {
                actor.SendMessage("ChangeYSpeedBy", float.Parse(args[1]));
            }
            else
            {
                actor.SendMessage("ChangeYSpeed", float.Parse(args[1]));
            }
            break;

        case "ChangeXPreferred":
            /* changeXPreferred x:float rel:bool
             *      changes the preferred xSpeed of the fighter
             */
            if (args.Length > 2)
            {
                actor.SendMessage("ChangeXPreferredBy", float.Parse(args[1]) * actor.GetIntVar(TussleConstants.FighterVariableNames.FACING_DIRECTION));
            }
            else
            {
                actor.SendMessage("ChangeXPreferred", float.Parse(args[1]) * actor.GetIntVar(TussleConstants.FighterVariableNames.FACING_DIRECTION));
            }
            break;

        case "ChangeYPreferred":
            /* changeXPreferred y:float rel:bool
             *      changes the yPreferred of the fighter
             */
            if (args.Length > 2)
            {
                actor.SendMessage("ChangeYPreferredBy", float.Parse(args[1]));
            }
            else
            {
                actor.SendMessage("ChangeYPreferred", float.Parse(args[1]));
            }
            break;

        case "ShiftPosition":
            /* shiftPosition x:float|0 y:float|0 relative:bool|true
             *      Displaces the fighter by a certain amount in either direction
             */
            //TODO
            break;

        // ====== CONTROL SUBACTIONS ======\\
        case "ChangeAnim":
            /* changeAnim animName:string
             *      Changes to the specified animation.
             *      ALIAS: ChangeSprite
             */
            actor.BroadcastMessage("ChangeSprite", args[1]);
            break;

        case "ChangeSprite":
            /* changeSprite animName:string
             *      Changes to the specified animation.
             *      ALIAS: ChangeAnim
             */
            actor.BroadcastMessage("ChangeSprite", args[1]);
            break;

        case "ChangeSubimage":
            /* changeSpriteSubimage index:int
             *      SPRITE MODE ONLY
             *      Changes to the sprite subimage of the current animation with the given index
             */
            actor.BroadcastMessage("ChangeSubimage", int.Parse(args[1]));
            break;

        case "Flip":
            /* flipFighter
             *      Flips the fighter horizontally, so they are facing the other direction
             */
            actor.BroadcastMessage("flip");
            break;

        case "RotateSprite":
            /* rotateFighter deg:int
             *      Rotates the fighter by the given degrees
             */
            //TODO
            break;

        case "Unrotate":
            /* unrotateFighter
             *      Sets the fighter back to upright, no matter how many times it has been rotated
             */
            //TODO
            break;

        case "ShiftSprite":
            /* shiftSprite x:float y:float
             *      Shifts the sprite by the given X and Y without moving the fighter
             */
            //TODO
            break;

        case "PlaySound":
            /* Playsound sound:string
             *      Plays the sound with the given name from the fighter's sound library
             */
            actor.BroadcastMessage("PlaySound", args[1]);
            break;

        // ====== HITBOX SUBACTIONS ======\\
        case "CreateHitbox":
            /* createHitbox name:string [argumentName:string value:dynamic]
             *      Creates a hitbox with the given name. Every pair of arguments from then after is the name of a value, and what to set it to.
             *      Hitboxes will be able to parse the property name and extract the right value out.
             */
            string name = args[1];
            Dictionary <string, string> hbox_dict = new Dictionary <string, string>();
            for (int i = 2; i < args.Length; i = i + 2)
            {
                hbox_dict[args[i]] = args[i + 1];
            }
            Hitbox hbox = FindObjectOfType <HitboxLoader>().LoadHitbox(actor.GetAbstractFighter(), action, hbox_dict);
            action.hitboxes.Add(name, hbox);
            break;

        case "ActivateHitbox":
            /* activateHitbox name:string life:int
             *      Activates the named hitbox, if it exists, for the given number of frames.
             *      If life is -1, hitbox will persist until manually deactivated.
             */
            name = args[1];
            if (action.hitboxes.ContainsKey(args[1]))
            {
                action.hitboxes[args[1]].Activate(int.Parse(args[2]));
            }
            else
            {
                Debug.LogWarning("Current action has no hitbox named " + name);
            }
            break;

        case "DeactivateHitbox":
            /* activateHitbox name:string life:int
             *      Activates the named hitbox, if it exists, for the given number of frames.
             */
            name = args[1];
            if (action.hitboxes.ContainsKey(args[1]))
            {
                action.hitboxes[args[1]].Deactivate();
            }
            else
            {
                Debug.LogWarning("Current action has no hitbox names " + name);
            }
            break;

        case "ModifyHitbox":
            /* createHitbox name:string [argumentName:string value:dynamic]
             *      Creates a hitbox with the given name. Every pair of arguments from then after is the name of a value, and what to set it to.
             *      Hitboxes will be able to parse the property name and extract the right value out.
             */
            name      = args[1];
            hbox_dict = new Dictionary <string, string>();
            for (int i = 2; i < args.Length; i = i + 2)
            {
                hbox_dict[args[i]] = args[i + 1];
            }
            if (action.hitboxes.ContainsKey(name))
            {
                action.hitboxes[name].LoadValuesFromDict(hbox_dict);
            }
            break;

        default:
            //Debug.LogWarning("Could not load subaction " + args[0]);
            break;
        }
    }
Пример #10
0
 void onHit(Hitbox hitbox)
 {
     //Debug.Log("Hurtbox has been hit");
     owner.SendMessage("GetHit", hitbox);
 }