Guest User

Grub Controller

a guest
Feb 14th, 2016
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 27.23 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using Vexe.Runtime.Types;
  4. using System.Collections.Generic;
  5.  
  6. public partial class ExplodingGrubController : PossessableUnit
  7. {
  8.     [DontSerialize][Show]
  9.     public StanceManager StanceMgr;
  10.  
  11.     void LoadStanceManager()
  12.     {
  13.         StanceMgr = gameObject.AddComponent<StanceManager>();
  14.         StanceMgr.Unit = this;
  15.         StanceMgr.skeleton = GetComponentInChildren<SkeletonAnimation>();
  16.  
  17.         List<Stance> StanceList = new List<Stance>()
  18.         {
  19.             // Movement
  20.             new Stance { Name = "Idle",             Animation = "Idle",             Looping = true,     BundleNames = {"Common", "Ground"}, },
  21.             new Stance { Name = "Move Forward",     Animation = "Walk",             Looping = true,     BundleNames = {"Common", "Ground"}, },
  22.             new Stance { Name = "Move Backward",    Animation = "Walk",             Looping = true,     BundleNames = {"Common", "Ground"}, },
  23.  
  24.             // Burrow
  25.             new Stance { Name = "Burrow Start",     Animation = "Burrow Start",     Looping = false,     BundleNames = {"Burrow"}, },
  26.             new Stance { Name = "Burrow Loop",      Animation = "Burrow Loop",      Looping = true,      BundleNames = {"Burrow"}, },
  27.             new Stance { Name = "Burrow End",       Animation = "Burrow End",       Looping = false,     BundleNames = {}, },
  28.  
  29.             new Stance { Name = "Burrow Leap Start",    Animation = "Burrow Leap Start",    Looping = false,     BundleNames = {}, },
  30.             new Stance { Name = "Burrow Leap Start Delayed",    Animation = "Burrow Leap Start Delayed",    Looping = false,     BundleNames = {}, },
  31.             new Stance { Name = "Burrow Leap Start Reaction",    Animation = "Burrow Leap Start Reaction",  Looping = false,     BundleNames = {}, },
  32.             new Stance { Name = "Burrow Leap Arc",      Animation = "Burrow Leap Arc",      Looping = false,     BundleNames = {"Common"}, },
  33.             new Stance { Name = "Burrow Leap Down",     Animation = "Burrow Leap Straight Down", Looping = true,      BundleNames = {"Common"}, },
  34.             new Stance { Name = "Burrow Leap Up",       Animation = "Burrow Leap Straight Up", Looping = true,      BundleNames = {"Common"}, },
  35.             new Stance { Name = "Burrow Leap End",      Animation = "Burrow Leap End",      Looping = false,     BundleNames = {}, },
  36.  
  37.             // Air
  38.             new Stance { Name = "Jump Start",       Animation = "Jump Start",       Looping = false,     BundleNames = {}, },
  39.             new Stance { Name = "Jump Upward",      Animation = "Jump Loop",        Looping = true,      BundleNames = {"Air Common"}, },
  40.             new Stance { Name = "Jump Falling",     Animation = "Jump Loop",        Looping = true,      BundleNames = {"Air Common"}, },
  41.             new Stance { Name = "Jump Landing",     Animation = "Jump Landing",     Looping = false,     BundleNames = {}, },
  42.             new Stance { Name = "Spin Start",       Animation = "Spin Start",       Looping = false,     BundleNames = {"Spin"}, },
  43.             new Stance { Name = "Spin Loop",        Animation = "Spin Loop",        Looping = true,      BundleNames = {"Spin", "Common"}, },
  44.             new Stance { Name = "Spin Explode",     Animation = "Spin Explode",     Looping = false,     BundleNames = {}, },
  45.             new Stance { Name = "Spin End",         Animation = "Spin End",         Looping = false,     BundleNames = {}, },
  46.  
  47.             // One-Offs
  48.             new Stance { Name = "Hit Reaction",     Animation = "Hit Reaction",     Looping = false,    CanResume = false,  StandardReactionRules = true },
  49.             new Stance { Name = "Death",            Animation = "Death",            Looping = false,    CanResume = false },
  50.             new Stance { Name = "Dead",             Animation = "Dead",             Looping = true,     },
  51.             new Stance { Name = "Revive",           Animation = "Revive",           Looping = false,    CanResume = false },
  52.  
  53.             // Attacks
  54.             new Stance { Name = "Attack",           Animation = "Attack",           Looping = false,    CanResume = false },
  55.             new Stance { Name = "Explode",          Animation = "Explode",          Looping = false,    CanResume = false },
  56.             new Stance { Name = "Explode Death",    Animation = "Explode Death",    Looping = false,    CanResume = false },
  57.             new Stance { Name = "Explode Dead",     Animation = "Explode Dead",     Looping = true,     CanResume = false },
  58.  
  59.         };
  60.  
  61.         Dictionary< string, BranchBundle > BranchBundles = new Dictionary< string, BranchBundle > ()
  62.         {
  63.             {
  64.                 "Common",
  65.                 new BranchBundle()
  66.                 {
  67.                     Name = "Common",
  68.                     Branches = new List<Branch>()  
  69.                     {
  70.                         new Branch {
  71.                             Condition = context => { return this[PS.Health] <= 0; },
  72.                             NextStance = "Death",
  73.                         },
  74.                         new Branch {
  75.                             Signal = Signal.DoReaction,
  76.                             Action = DoReaction,
  77.                             NextStance = "Hit Reaction",
  78.                         },
  79.                     }
  80.                 }
  81.             },
  82.             {
  83.                 "Spin",
  84.                 new BranchBundle()
  85.                 {
  86.                     Name = "Spin",
  87.                     Branches = new List<Branch>()  
  88.                     {
  89.                         new Branch {
  90.                             Condition = context => { return this[PS.HeldSpecial] && !this[PS.Grounded]; },
  91.                             NextStance = "Spin Explode",
  92.                         },
  93.                         new Branch {
  94.                             Condition = context => { return this[PS.Health] <= 0; },
  95.                             NextStance = "Death",
  96.                         },
  97.                         new Branch {
  98.                             Signal = Signal.DoReaction,
  99.                             Action = DoReaction,
  100.                             NextStance = "Hit Reaction",
  101.                         },
  102.                         new Branch
  103.                         {
  104.                             Label = "Cling to Ceiling",
  105.                             Condition = context => { return this["SpinWallDetection_N"] > -1f && this["SpinWallDetection_N"] < this["SpinSensorDistance"]; },
  106.                             Action = StickNorth,
  107.                             NextStance = "Spin End",
  108.                             NextStanceBlendTime = 0f,
  109.                         },
  110.                         new Branch
  111.                         {
  112.                             Label = "Cling to Floor",
  113.                             Condition = context => { return this["SpinWallDetection_S"] > -1f && this["SpinWallDetection_S"] < this["SpinSensorDistance"] && !ShouldFall(context); },
  114.                             Action = StickSouth,
  115.                             NextStance = "Spin End",
  116.                             NextStanceBlendTime = 0f,
  117.                         },
  118.                         new Branch
  119.                         {
  120.                             Label = "Cling to Front",
  121.                             Condition = context => { return this["SpinWallDetection_E"] > -1f && this["SpinWallDetection_E"] < this["SpinSensorDistance"]; },
  122.                             Action = StickEast,
  123.                             NextStance = "Spin End",
  124.                             NextStanceBlendTime = 0f,
  125.                         },
  126.                         new Branch
  127.                         {
  128.                             Label = "Cling to West",
  129.                             Condition = context => { return this["SpinWallDetection_W"] > -1f && this["SpinWallDetection_W"] < this["SpinSensorDistance"]; },
  130.                             Action = StickWest,
  131.                             NextStance = "Spin End",
  132.                             NextStanceBlendTime = 0f,
  133.                         },
  134.                     }
  135.                 }
  136.             },
  137.             {
  138.                 "Ground",
  139.                 new BranchBundle()
  140.                 {
  141.                     Name = "Ground",
  142.                     Branches = new List<Branch>()  
  143.                     {
  144.                         new Branch {
  145.                             Condition = context => { return this[PS.HeldAttack]; },
  146.                             NextStance = "Attack",
  147.                         },
  148.                         new Branch {
  149.                             Condition = context => { return this[PS.HeldSpecial] && this[PS.Grounded]; },
  150.                             NextStance = "Explode",
  151.                         },
  152.                         new Branch {
  153.                             Condition = context => { return this[PS.InputForward] > 0.1f && this[PS.WallInFront] == false; },
  154.                             ResetBones = true,
  155.                             NextStance = "Move Forward",
  156.                         },
  157.                         new Branch {
  158.                             Condition = context => { return this[PS.InputForward] <-0.1f && this[PS.BackToTheWall] == false; },
  159.                             ResetBones = true,
  160.                             NextStance = "Move Forward",
  161.                             Action = FlipDirection,
  162.                         },
  163.                         new Branch {
  164.                             Label = "Wall In Front",
  165.                             Priority = 0,
  166.                             Condition = context => { return this[PS.WallInFront] && this[PS.InputForward] > 0.1f; },
  167.                             NextStance = "Idle",
  168.                         },
  169.                         new Branch {
  170.                             Label = "Wall Behind",
  171.                             Priority = 0,
  172.                             Condition = context => { return (this[PS.BackToTheWall] && this[PS.InputForward] < -0.1f); },
  173.                             NextStance = "Idle",
  174.                         },
  175.                         new Branch {
  176.                             Signal = Signal.DoJump,
  177.                             Condition = context => { return this[PS.Grounded]; },
  178.                             NextStance = "Jump Start",
  179.                         },
  180.                         new Branch {
  181.                             Condition = ShouldFall,
  182.                             NextStance = "Jump Falling",
  183.                         },
  184.                         new Branch {
  185.                             Condition = context => { return this[PS.Grounded] && this[PS.InputUpward] < -0.1f; },
  186.                             NextStance = "Burrow Start",
  187.                         },                        
  188.                     }
  189.                 }
  190.             },
  191.             {
  192.                 "Air Common",
  193.                 new BranchBundle()
  194.                 {
  195.                     Name = "Air Common",
  196.                     Branches = new List<Branch>()  
  197.                     {
  198.                         new Branch {
  199.                             Condition = context => { return !ShouldFall(context); },
  200.                             NextStance = "Jump Landing",
  201.                         },
  202.                         new Branch {
  203.                             Priority  = 2,
  204.                             Condition = context => { return this[PS.HeldSwitch] && this[PS.Grounded] == false; },
  205.                             NextStance = "Spin Start",
  206.                         },
  207.                     },
  208.                 }
  209.             },   
  210.         };
  211.        
  212.         // Stance:Branch Map
  213.         Dictionary<string, List<Branch> > StanceBranches = new Dictionary<string, List<Branch> > ()
  214.         {
  215.             {
  216.                 "Attack",
  217.                 new List<Branch>()
  218.                 {
  219.                     new Branch
  220.                     {
  221.                         Signal = Signal.StanceEnter,
  222.                         Action = Attack,
  223.                     },
  224.                     new Branch
  225.                     {
  226.                         On = 1.0f,
  227.                         NextStance = StanceManager.PreviousStance,
  228.                     },
  229.                     new Branch
  230.                     {
  231.                         On = 0.8f,
  232.                         Condition = context => { return this[PS.HeldAttack]; },
  233.                         NextStance = StanceManager.ResetStance,
  234.                     },
  235.                 }
  236.             },   
  237.             {
  238.                 "Hit Reaction",
  239.                 new List<Branch>()
  240.                 {
  241.                     new Branch
  242.                     {
  243.                         On = 1.0f,
  244.                         NextStance = StanceManager.PreviousStance,
  245.                     },
  246.                 }
  247.             },   
  248.             {
  249.                 "Move Forward",
  250.                 new List<Branch>()
  251.                 {
  252.                     new Branch {
  253.                         Signal = Signal.StanceEnter,
  254.                         Action = MoveForward,
  255.                     },
  256.                     new Branch {
  257.                         Condition = context => { return this[PS.InputForward] < 0.1f; },
  258.                         NextStance = "Idle",
  259.                     },
  260.                 }
  261.             },
  262.             {
  263.                 "Move Backward",
  264.                 new List<Branch>()
  265.                 {
  266.                     new Branch {
  267.                         Signal = Signal.StanceEnter,
  268.                         Action = MoveBackward,
  269.                     },
  270.                     new Branch {
  271.                         Condition = context => { return this[PS.InputForward] > -0.1f; },
  272.                         NextStance = "Idle",
  273.                     },
  274.                 }
  275.             },
  276.             {
  277.                 "Idle",
  278.                 new List<Branch>()
  279.                 {
  280.                     new Branch {
  281.                         Signal = Signal.StanceEnter,
  282.                         Action = Idle,
  283.                     }
  284.                 }
  285.             },
  286.             // Spin
  287.             {
  288.                 "Spin Start",
  289.                 new List<Branch>()
  290.                 {
  291.                     new Branch {
  292.                         Signal = Signal.StanceEnter,
  293.                         Action = context => { Properties["Spin"] = true; return SignalDispatcher.BlockParent; },
  294.                     },
  295.                     new Branch {
  296.                         On = 1.0f,
  297.                         NextStance = "Spin Loop",
  298.                     },
  299.                 }
  300.             },
  301.             {
  302.                 "Spin Loop",
  303.                 new List<Branch>()
  304.                 {
  305.                     new Branch {
  306.                         Condition = context => { return this[PS.HeldSwitch] == false; },
  307.                         NextStance = "Spin End",
  308.                     },
  309.                 }
  310.             },
  311.            
  312.             {
  313.                 "Spin Explode",
  314.                 new List<Branch>()
  315.                 {
  316.                     new Branch
  317.                     {
  318.                         On = 0.9f,
  319.                         Action = context =>
  320.                         {
  321.                             var t = StaticVisualHelpers.CreateUnitVFX ( this, Explosion, Vector3.zero );                            
  322.                             // 5.0 seconds is arbitrary to ensure cleanup
  323.                             Object.Destroy ( t, 1.0f );
  324.  
  325.                             return SignalDispatcher.BlockParent;
  326.                         },
  327.                     },
  328.                     new Branch
  329.                     {
  330.                         On = 1.0f,
  331.                         NextStance = "Explode Death",
  332.                     },
  333.                 }
  334.             },
  335.             {
  336.                 "Spin End",
  337.                 new List<Branch>()
  338.                 {
  339.                     new Branch {
  340.                         On = 1.0f,
  341.                         NextStance = "Idle",
  342.                         Action = context => {
  343.                             StaticMovementHelper.ResetVelocity(this);
  344.                             StaticMovementHelper.RemoveAllMoversExceptGravity(this);
  345.                             Properties["Spin"] = false;
  346.                             return SignalDispatcher.BlockParent;
  347.                         },
  348.                     },
  349.                 }
  350.             },
  351.             // Burrower
  352.             {
  353.                 "Burrow Start",
  354.                 new List<Branch>()
  355.                 {
  356.                     new Branch {
  357.                         Signal = Signal.StanceEnter,
  358.                         Action = BurrowStart,
  359.                     },
  360.                     new Branch {
  361.                         On = 1.0f,
  362.                         NextStance = "Burrow Loop",
  363.                     },
  364.                 }
  365.             },
  366.             {
  367.                 "Burrow Loop",
  368.                 new List<Branch>()
  369.                 {
  370.                     new Branch {
  371.                         Condition = context => { return this[PS.InputUpward] > 0.1f; },
  372.                         NextStance = "Burrow End",
  373.                     },
  374.                     new Branch {
  375.                         ActionRunsPerStance = 3,
  376.                         Signal = Signal.DoDash,
  377.                         Action = context => { this.transform.position = this.transform.position + GetForwardVector() * BurrowTeleportDistance * context["AxisValue"]*GetForwardDirection(); return SignalDispatcher.BlockParent;}
  378.                     },
  379.                     new Branch {
  380.                         Signal = Signal.DoJump,
  381.                         Condition = context => { return this[PS.PlayerControlled];},
  382.                         CooldownAmount = 1.5f,
  383.                         NextStance = "Burrow Leap Start",
  384.                     },
  385.                     new Branch {
  386.                         Signal = Signal.DoJump,
  387.                         Condition = context => { return !this[PS.PlayerControlled];},
  388.                         CooldownAmount = 1.5f,
  389.                         NextStance = "Burrow Leap Start Delayed",
  390.                     },
  391.                 }
  392.             },
  393.             {
  394.                 "Burrow End",
  395.                 new List<Branch>()
  396.                 {
  397.                     new Branch {
  398.                         On = 1.0f,
  399.                         NextStance = "Idle",
  400.                         Action = BurrowEnd,
  401.                     },
  402.                 }
  403.             },
  404.             {
  405.                 "Burrow Leap Start",
  406.                 new List<Branch>()
  407.                 {
  408.                     new Branch {
  409.                         Signal = Signal.StanceEnter,
  410.                         Action = LeapStart,
  411.                     },
  412.                     new Branch {
  413.                         On = 1.0f,
  414.                         Condition = context => { return this[PS.InputUpward] < 0.5f; },
  415.                         NextStance = "Burrow Leap Arc",
  416.                     },
  417.                     new Branch {
  418.                         On = 1.0f,
  419.                         Condition = context => { return this[PS.InputUpward] >= 0.5f; },
  420.                         NextStance = "Burrow Leap Up",
  421.                     },
  422.                 }
  423.             },
  424.             {
  425.                 "Burrow Leap Start Delayed",
  426.                 new List<Branch>()
  427.                 {
  428.                     new Branch {
  429.                         Signal = Signal.StanceEnter,
  430.                         Action = LeapStart,
  431.                     },
  432.                     new Branch {
  433.                         Signal = Signal.TakeHit,
  434.                         NextStance = "Burrow Leap Start Reaction",
  435.                     },
  436.                     new Branch {
  437.                         On = 1.0f,
  438.                         Condition = context => { return this[PS.InputUpward] < 0.5f; },
  439.                         NextStance = "Burrow Leap Arc",
  440.                     },
  441.                     new Branch {
  442.                         On = 1.0f,
  443.                         Condition = context => { return this[PS.InputUpward] >= 0.5f; },
  444.                         NextStance = "Burrow Leap Up",
  445.                     },
  446.                 }
  447.             },
  448.             {
  449.                 "Burrow Leap Start Reaction",
  450.                 new List<Branch>()
  451.                 {
  452.                     new Branch {
  453.                         On = 1.0f,
  454.                         Actions = {
  455.                             BurrowEnd,
  456.                             KnockLoose,
  457.                             context =>
  458.                             {
  459.  
  460.                                 Properties[PS.AIState] = (Properties[PS.AIState] == ExplodingGrubBehaviours.BurrowAndArc) ?  (int) ExplodingGrubBehaviours.ApproachAndExplode : (int) Properties[PS.AIState];
  461.                                 return true;
  462.                             },
  463.                         },
  464.                         NextStance = "Spin Loop",
  465.                     }
  466.                 }
  467.             },
  468.  
  469.             {
  470.                 "Burrow Leap Arc",
  471.                 new List<Branch>()
  472.                 {
  473.                     new Branch {
  474.                         Signal = Signal.StanceEnter,
  475.                         Actions = {BurrowEnd, DoArcJump},
  476.                     },
  477.                     new Branch {
  478.                         On = 1.0f,
  479.                         NextStance = "Burrow Leap End",
  480.                     },
  481.                     new Branch {
  482.                         Signal = Signal.TakeHit,
  483.                         Actions =
  484.                         {
  485.                             KnockLoose,
  486.                             context =>
  487.                             {
  488.  
  489.                                 Properties[PS.AIState] = (Properties[PS.AIState] == ExplodingGrubBehaviours.BurrowAndArc) ?  (int) ExplodingGrubBehaviours.ApproachAndExplode : (int) Properties[PS.AIState];
  490.                                 return true;
  491.                             },
  492.                         },
  493.                         ResetBones = true,
  494.                         ApplyPose = "Idle",
  495.                         NextStance = "Spin Loop",
  496.                     },
  497.                     new Branch {
  498.                         Signal = Signal.DealBlock,
  499.                         Actions = { KnockLoose, context =>
  500.                             {
  501.  
  502.                                 Properties[PS.AIState] = (Properties[PS.AIState] == ExplodingGrubBehaviours.BurrowAndArc) ?  (int) ExplodingGrubBehaviours.ApproachAndExplode : (int) Properties[PS.AIState];
  503.                                 return true;
  504.                             },
  505.                         },
  506.                         ResetBones = true,
  507.                         ApplyPose = "Idle",
  508.                         NextStance = "Spin Loop",
  509.                     },
  510.                     new Branch
  511.                     {
  512.                         On = 0.25f,
  513.                         Label = "Cling to Ceiling",
  514.                         Condition = context => { return this["SpinWallDetection_N"] > -1f && this["SpinWallDetection_N"] < this["SpinSensorDistance"]; },
  515.                         Action = StickNorth,
  516.                         NextStance = "Burrow Leap End",
  517.                         NextStanceBlendTime = 0f,
  518.                     },
  519.                     new Branch
  520.                     {
  521.                         On = 0.25f,
  522.                         Label = "Cling to Floor",
  523.                         Condition = context => { return this["SpinWallDetection_S"] > -1f && this["SpinWallDetection_S"] < this["SpinSensorDistance"]; },
  524.                         Action = StickSouth,
  525.                         NextStance = "Burrow Leap End",
  526.                         NextStanceBlendTime = 0f,
  527.                     },
  528.                     new Branch
  529.                     {
  530.                         On = 0.25f,
  531.                         Label = "Cling to Front",
  532.                         Condition = context => { return this["SpinWallDetection_E"] > -1f && this["SpinWallDetection_E"] < this["SpinSensorDistance"]; },
  533.                         Action = StickEast,
  534.                         NextStance = "Burrow Leap End",
  535.                         NextStanceBlendTime = 0f,
  536.                     },
  537.                     new Branch
  538.                     {
  539.                         On = 0.25f,
  540.                         Label = "Cling to West",
  541.                         Condition = context => { return this["SpinWallDetection_W"] > -1f && this["SpinWallDetection_W"] < this["SpinSensorDistance"]; },
  542.                         Action = StickWest,
  543.                         NextStance = "Burrow Leap End",
  544.                         NextStanceBlendTime = 0f,
  545.                     },
  546.                 }
  547.             },
  548.             {
  549.                 "Burrow Leap End",
  550.                 new List<Branch>()
  551.                 {
  552.                     new Branch {
  553.                         Signal = Signal.StanceExit,
  554.                         Action = LeapEnd,
  555.                     },
  556.                     new Branch {
  557.                         On = 1.0f,
  558.                         NextStance = "Burrow Loop",
  559.                         Action = BurrowStart,
  560.                     },
  561.                 }
  562.             },
  563.             // Air Stuff
  564.             {
  565.                 "Jump Start",
  566.                 new List<Branch>()
  567.                 {
  568.                     new Branch {
  569.                         Signal = Signal.StanceEnter,
  570.                         Action = JumpPause,
  571.                     },
  572.                     new Branch {
  573.                         On = 3f / 7f,  // 10 of 20 frames
  574.                         Action = DoStandardJump,
  575.                     },
  576.                     new Branch {
  577.                         On = 1.0f,
  578.                         NextStance = "Jump Upward",
  579.                     },
  580.                 }
  581.             },
  582.             {
  583.                 "Jump Upward",
  584.                 new List<Branch>()
  585.                 {
  586.                     new Branch {
  587.                         Condition = context => { return IsFalling(); },
  588.                         NextStance = "Jump Falling",
  589.                         KeepProgress  = true,
  590.                     },
  591.  
  592.                 }
  593.             },
  594.             {
  595.                 "Jump Falling",
  596.                 new List<Branch>()
  597.                 {
  598.                     new Branch {
  599.                         Condition = context => { return !IsFalling() && !this[PS.Stopped] && this["GroundDistance_C"] > 0.25f; },
  600.                         NextStance = "Jump Upward",
  601.                         KeepProgress  = true,
  602.                     },
  603.                 }
  604.             },      
  605.             {
  606.                 "Jump Landing",
  607.                 new List<Branch>()
  608.                 {
  609.                     new Branch {
  610.                         On = 0.4f,
  611.                         Action = JumpPause,
  612.                     },
  613.                     new Branch {
  614.                         On = 1.0f,
  615.                         NextStance = "Idle",
  616.                     },
  617.                     new Branch {
  618.                         On = 0.5f,
  619.                         Condition = context => { return this[PS.InputForward] > 0.1f; },
  620.                         NextStance = "Move Forward",
  621.                     },
  622.                     new Branch {
  623.                         On = 0.5f,
  624.                         Condition = context => { return this[PS.InputForward] < -0.1f; },
  625.                         NextStance = "Move Backward",
  626.                     },
  627.                     new Branch {
  628.                         Signal = Signal.DoJump,
  629.                         // TODO : Re-evaluate
  630.                         Condition = context => { return this[PS.Grounded]; },
  631.                         NextStance = "Jump Start",
  632.                     },
  633.                 }
  634.             },
  635.             // Death Standard
  636.             {
  637.                 "Death",
  638.                 new List<Branch>()
  639.                 {
  640.                     // Return to the previous stance after this animation completes
  641.                     new Branch
  642.                     {
  643.                         On = 1f,  // Frames
  644.                         Action = MakeDead,
  645.                         NextStance = "Dead",
  646.                     },
  647.                 }
  648.             },
  649.             {
  650.                 "Dead",
  651.                 new List<Branch>()
  652.                 {
  653.                     // Return to the previous stance after this animation completes
  654.                     new Branch
  655.                     {
  656.                         Condition = context => { return this[PS.Possessed]; },
  657.                         On = 0f,  // Frames
  658.                         NextStance = "Revive",
  659.                     },
  660.                 }
  661.             },
  662.             {
  663.                 "Revive",
  664.                 new List<Branch>()
  665.                 {
  666.                     // Return to the previous stance after this animation completes
  667.                     new Branch
  668.                     {
  669.                         On = 1.0f,
  670.                         Action = Revive,
  671.                         NextStance = "Idle",
  672.                     },
  673.                 }
  674.             },
  675.  
  676.             {
  677.                 "Explode",
  678.                 new List<Branch>()
  679.                 {
  680.                     new Branch
  681.                     {
  682.                         Signal = Signal.StanceEnter,
  683.                         Action = ExplodeStart,
  684.                     },
  685.                     new Branch {
  686.                         Condition = context => { return this[PS.Health] <= 0; },
  687.                         NextStance = "Death",
  688.                     },
  689.                     new Branch
  690.                     {
  691.                         On = 0.9f,
  692.                         Action = context =>
  693.                         {
  694.                             var t = StaticVisualHelpers.CreateUnitVFX ( this, Explosion, Vector3.zero );                            
  695.                             // 5.0 seconds is arbitrary to ensure cleanup
  696.                             Object.Destroy ( t, 1.0f );
  697.  
  698.                             return SignalDispatcher.BlockParent;
  699.                         },
  700.                     },
  701.                     new Branch
  702.                     {
  703.                         On = 1.0f,
  704.                         NextStance = "Explode Death",
  705.                     },
  706.                 }
  707.             },   
  708.             {
  709.                 "Explode Death",
  710.                 new List<Branch>()
  711.                 {
  712.                     new Branch
  713.                     {
  714.                         Signal = Signal.StanceEnter,
  715.                         Action = MakeDead,
  716.                     },
  717.                     new Branch
  718.                     {
  719.                         On = 1.0f,
  720.                         NextStance = "Explode Dead",
  721.                     },
  722.                 }
  723.             },   
  724.         };
  725.  
  726.         // Now load the data into the stances
  727.         StanceManager.BuildStances(StanceMgr, StanceList, BranchBundles, StanceBranches);
  728.  
  729.         // Validate Data
  730.         StanceMgr.CurrentStance = "Spin Loop";
  731.         StanceMgr.ValidateStances();
  732.     }
  733. }
Advertisement
Add Comment
Please, Sign In to add comment