Example #1
0
 /// <summary>
 /// This function is called whenever a combatant takes damage. We perform a check to see if this combatant is the target. If so, we push a flinch action to the front of
 /// the queue.
 /// </summary>
 public void Flinch(Combatant combatant)
 {
     if (combatant == this)
     {
         Flinch flinchAction = this.gameObject.AddComponent <Flinch>();
         this.Actions.AddToFront(flinchAction);
     }
 }
    protected void Awake()
    {
        anim         = GetComponent <Animator>();
        Shaker       = GameObject.FindGameObjectWithTag("Shake");
        maxGrip      = fighter.weight;
        HP           = fighter.HitPoints;
        jumpHeight   = fighter.jumpHeight;
        moveSpeed    = fighter.speed;
        maxJumpCount = fighter.jumpCount;
        rigidBody    = GetComponent <Rigidbody2D>();
        Target       = GameObject.FindGameObjectWithTag("Floor").GetComponent <GravAttractor>();
        Shield       = GetComponentInChildren <Barrier>(true).gameObject;
        if (isPlayer)
        {
            player = ReInput.players.GetPlayer(playerID); //The player controlling this fighter
        }
        gameObject.name = fighter.name.ToString() + playerID;
        statemachine    = new StateMachine();
        var flinch       = new Flinch(this);
        var walk         = new Walk(this);
        var run          = new Run(this);
        var idle         = new Idle(this);
        var jump         = new Jump(this);
        var groundattack = new GroundAttack(this, attack);
        var airattack    = new AirAttack(this, attack);
        var stun         = new Stun(this);
        var leapprep     = new LeapPrep(this);
        var blocking     = new Blocking(this);
        var dodge        = new AirDodge(this);
        var leap         = new Leaping(this);
        var prone        = new Prone(this);

        At(dodge, idle, landed());
        At(flinch, idle, stunless());
        At(run, idle, stop());
        At(walk, idle, stop());
        At(idle, jump, jumping());
        At(idle, jump, unground());
        At(jump, jump, jumping());
        At(walk, jump, unground());
        At(run, jump, unground());
        At(walk, jump, jumping());
        At(run, jump, jumping());
        At(walk, run, running());
        At(run, walk, walking());
        At(idle, walk, walking());
        At(idle, run, running());
        At(idle, groundattack, offensive());
        At(walk, groundattack, offensive());
        At(run, groundattack, offensive());
        At(jump, airattack, offensive());
        At(groundattack, idle, unoffensive());
        At(airattack, jump, unoffensive());
        At(airattack, idle, landed());
        At(jump, airattack, offensive());
        At(jump, idle, landed());
        At(jump, dodge, guard());
        At(blocking, stun, pierce());
        At(idle, blocking, guard());
        At(walk, blocking, guard());
        At(run, blocking, guard());
        At(leapprep, idle, cancelleap());
        At(leapprep, leap, gravityChange());
        At(blocking, idle, unguard());
        At(leap, idle, landed());
        At(prone, idle, stunless());
        statemachine.AddAnyTransition(leapprep, () => LeapPrep && leapCooldown <= 0);
        statemachine.AddAnyTransition(stun, () => stunned);
        statemachine.AddAnyTransition(flinch, () => isDamaged);
        statemachine.AddAnyTransition(prone, () => slam);
        Func <bool> stunless() => () => doneStun == true;
        Func <bool> walking() => () => speed > 0.3 && speed < 0.7;
        Func <bool> running() => () => speed > 0.7;
        Func <bool> stop() => () => speed < 0.3;
        Func <bool> jumping() => () => (jumpTimer > Time.time) && (maxJumpCount > jumpCount) && !action && actionCooldown > 0;
        Func <bool> offensive() => () => attack != null && actionCooldown > 0;
        Func <bool> unoffensive() => () => attack == null;
        Func <bool> landed() => () => grounded;
        Func <bool> pierce() => () => Guard <= 0;
        Func <bool> guard() => () => isBlocking && actionCooldown > 0;
        Func <bool> unguard() => () => !isBlocking;
        Func <bool> gravityChange() => () => LeapRelease;
        Func <bool> cancelleap() => () => cancelled;
        Func <bool> unground() => () => !grounded;

        statemachine.SetState(idle);
    }