Advertisement
Guest User

Untitled

a guest
May 17th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function SharedAnimation_MergeVisualization(X2Action BuildTree, out X2Action VisualizationTree)
  2. {
  3.     local XComGameStateVisualizationMgr VisMgr;
  4.     local X2Action_MarkerNamed MarkerNamed, JoinMarker, SecondJoin, FireReplace;
  5.     local array<X2Action> arrActions;
  6.     local X2Action Action, FirstFireAction, SecondFireAction, SpacerAction;
  7.     local int i;
  8.     local VisualizationActionMetadata ActionMetadata;
  9.     local XComGameStateContext_Ability FirstAbilityContext, SecondAbilityContext;//, ProxyAbilityContext;
  10.     local StateObjectReference Target;
  11.  
  12.     VisMgr = `XCOMVISUALIZATIONMGR;
  13.  
  14.     SecondFireAction = VisMgr.GetNodeOfType(BuildTree, class'X2Action_Fire');
  15.     SecondAbilityContext=XComGameStateContext_Ability(BuildTree.StateChangeContext);
  16.     Target=SecondAbilityContext.InputContext.PrimaryTarget;
  17.     //Mr. Nice Much simpler this time! Due to how the second shot is triggered, we know what index we want already!
  18.     VisMgr.GetNodesOfType(VisualizationTree, class'X2Action_Fire', arrActions, , , true);
  19.  
  20.     foreach arrActions(Action)
  21.     {
  22.         if (Action.StateChangeContext.AssociatedState.HistoryIndex == SecondAbilityContext.DesiredVisualizationBlockIndex)
  23.         {
  24.             FirstFireAction=Action;
  25.             FirstAbilityContext=XComGameStateContext_Ability(Action.StateChangeContext);
  26.         }
  27.     }
  28.  
  29.     if (FirstFireAction == none || SecondFireAction==none)
  30.     {
  31.         //Mr. Nice: If this happens who knows what's going on? Just keep VisMgr happy with the most generic merge...
  32.         `log("Dual Shot Merge Failed?!?!");
  33.         XComGameStateContext_Ability(BuildTree.StateChangeContext).SuperMergeIntoVisualizationTree(BuildTree, VisualizationTree);
  34.         return;
  35.     }
  36.    
  37.     VisMgr.GetNodesOfType(VisualizationTree, class'X2Action_MarkerNamed', arrActions, , , true);
  38.     for (i = 0; i < arrActions.Length; ++i)
  39.     {
  40.         MarkerNamed = X2Action_MarkerNamed(arrActions[i]);
  41.         if (MarkerNamed.MarkerName == 'Join' && MarkerNamed.StateChangeContext.AssociatedState.HistoryIndex == SecondAbilityContext.DesiredVisualizationBlockIndex)
  42.         {
  43.             JoinMarker = MarkerNamed;
  44.             break;
  45.         }
  46.     }
  47.  
  48.     `assert(JoinMarker != none);
  49.    
  50.     VisMgr.GetNodesOfType(BuildTree, class'X2Action_MarkerNamed', arrActions, , , true);
  51.     for (i = 0; i < arrActions.Length; ++i)
  52.     {
  53.         MarkerNamed = X2Action_MarkerNamed(arrActions[i]);
  54.         if (MarkerNamed.MarkerName == 'Join')
  55.         {
  56.             SecondJoin = MarkerNamed;
  57.         }
  58.     }
  59.  
  60.     //Mr. Nice: If Second hit misses animate first hit, otherwise animate second hit
  61.     //Means that if we kill on the second shot, we correctly get the death anim
  62.     //Well, that was the theory, but hiding hits is hard, and if you hide the first one, you don't get the projectile blood
  63.     if(IsContextMiss(SecondAbilityContext))
  64.     {
  65.         VisMgr.GetNodesOfType(BuildTree, class'X2Action_ApplyWeaponDamageToUnit', arrActions,, Target.ObjectID);
  66.         foreach arrActions(Action)
  67.         {
  68.             if(Action.ParentActions[0]==SecondFireAction)
  69.             {
  70.                 X2Action_ApplyWeaponDamageToUnit(Action).bPlayDamageAnim=false;
  71.             }
  72.         }
  73.     }
  74.     else
  75.     {
  76.         VisMgr.GetNodesOfType(VisualizationTree, class'X2Action_ApplyWeaponDamageToUnit', arrActions,, Target.ObjectID);
  77.         if (IsContextMiss(FirstAbilityContext))
  78.         {
  79.             foreach arrActions(Action)
  80.             {
  81.                 if(Action.ParentActions[0]==FirstFireAction)
  82.                 {
  83.                     X2Action_ApplyWeaponDamageToUnit(Action).bPlayDamageAnim=false;
  84.                 }
  85.             }
  86.         }
  87.        
  88.         //Mr. Nice: This makes sure you can see the counter, whether the second shot kills them or not
  89.         else if(FirstAbilityContext.ResultContext.HitResult==eHit_CounterAttack)
  90.         {
  91.             foreach arrActions(Action)
  92.             {
  93.                 if (Action.ParentActions[0]==FirstFireAction)
  94.                 {
  95.                     if(default.ENABLE_LOGGING) `Log("Found miss/counter action...");
  96.                     if(XComGameState_Unit(`XCOMHISTORY.GetGameStateForObjectID(Target.ObjectID,, SecondAbilityContext.AssociatedState.HistoryIndex)).IsDead())
  97.                     {
  98.                         //Mr. Nice: If the second hit kills, stil want to show the counter animation before the unit animates its death
  99.                         SpacerAction=Action;
  100.                     }
  101.                     else
  102.                     {
  103.                        
  104.                         //Mr. Nice: If the second hit does not kill, want the counter animation, not the flinch animation, to get priority
  105.                         //Spacer both keeps the sets of damageotunit's from being siblings if both miss,
  106.                         //and helpfully makes sure you see the counter anim, not the flinch anim when you have a counter & hit result
  107.                         ActionMetaData=FirstFireAction.Metadata;
  108.                         SpacerAction=class'X2Action_ApplyDamageSpacer'.static.AddToVisualizationTree(ActionMetadata, FirstAbilityContext,, FirstFireAction);
  109.                         VisMgr.DisconnectAction(Action);
  110.                         VisMgr.ConnectAction(Action, VisualizationTree,, SpacerAction);
  111.                         SpacerAction=FirstFireAction;
  112.                     }
  113.                     break;
  114.                 }
  115.             }
  116.         }
  117.     }
  118.  
  119.     //If the second shot has a join created, then just slot it in above the first shots join
  120.     if (SecondJoin!=none)
  121.     {
  122.         VisMgr.ConnectAction(SecondJoin, VisualizationTree,,, JoinMarker.ParentActions);
  123.         VisMgr.ConnectAction(JoinMarker, BuildTree,, SecondJoin);
  124.     }
  125.     //If the second shot does not have a join, then connect the leaf nodes to the first shots join
  126.     else
  127.     {
  128.         VisMgr.GetAllLeafNodes(BuildTree, arrActions);
  129.         VisMgr.ConnectAction(JoinMarker,BuildTree,,, arrActions);
  130.     }
  131.     //Mr. Nice, ok, want to connect children of secondfireaction, to firstfireaction
  132.     arrActions=SecondFireAction.ChildActions;
  133.     //If first hit was countered, then the attachment point for second hit applydamagetounit will have been set
  134.     //Otherwise, create a new SpacerAction for them
  135.     if (SpacerAction==none)
  136.     {
  137.         ActionMetaData=SecondFireAction.Metadata;
  138.         SpacerAction=class'X2Action_ApplyDamageSpacer'.static.AddToVisualizationTree(ActionMetadata, SecondAbilityContext,, FirstFireAction);
  139.     }
  140.     //if(default.ENABLE_LOGGING) `Log(`showvar(arrActions.Length));
  141.     foreach arrActions(Action)
  142.     {
  143.         VisMgr.ConnectAction(Action, VisualizationTree,, X2Action_ApplyWeaponDamageToUnit(Action)!=none ? SpacerAction : FirstFireAction);
  144.     }
  145.     //For correct counter attack animations, need to be able to trace from BuildTree down to the second shots apply damages, without
  146.     //encountering the first shot's applydamages. So swap out the SecondFireAction for a marker, just to keep BuildTree traceable.
  147.     FireReplace = X2Action_MarkerNamed(class'X2Action'.static.CreateVisualizationActionClass(class'X2Action_MarkerNamed', SecondAbilityContext));
  148.     FireReplace.SetName("FireActionSharedAnimStub");
  149.     VisMgr.ReplaceNode(FireReplace, SecondFireAction)
  150.     //Mr. Nice we have swapped out the SecondFireAction,
  151.     //So can destroy it now without "stranding" any other actions
  152.     VisMgr.DestroyAction(SecondFireAction);
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement