Advertisement
Guest User

Untitled

a guest
Nov 24th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function SyncVisualizer(optional XComGameState GameState = none)
  2. {
  3.     local XGUnit UnitVisualizer;
  4.     local name EffectName;
  5.     local XComGameState_Effect EffectState;
  6.     local int x, y, t;
  7.     local array<XComPerkContent> Perks;
  8.     local XComGameState_Unit TargetState;
  9.     local X2AbilityTemplate AbilityTemplate;
  10.     local WorldInfo WInfo;
  11.     local XComPerkContentInst PerkInstance;
  12.     local XComUnitPawn SourcePawn;
  13.  
  14.     WInfo = class'WorldInfo'.static.GetWorldInfo();
  15.    
  16.     if(GameState == none)
  17.     {
  18.         GameState = GetParentGameState();
  19.     }
  20.  
  21.     UnitVisualizer = XGUnit(FindOrCreateVisualizer(GameState));
  22.     if(UnitVisualizer == none)
  23.     {
  24.         return; // units that have been removed from play will not have a visualizer
  25.     }
  26.  
  27.     UnitVisualizer.m_kPlayer = XGPlayer(`XCOMHISTORY.GetVisualizer(ControllingPlayer.ObjectID));
  28.     UnitVisualizer.m_kPlayerNativeBase = UnitVisualizer.m_kPlayer;
  29.     UnitVisualizer.SetTeamType(GetTeam());
  30.  
  31.     if( UnitVisualizer.m_kPlayer == none )
  32.     {
  33.         `RedScreen("[@gameplay] SyncVisualizer: No unit visualizer for " $ GetFullName());
  34.     }
  35.  
  36.     // Spawning system is meant to do this but since our sync created the visualizer we want it right away
  37.     UnitVisualizer.m_bForceHidden = bRemovedFromPlay;
  38.  
  39.     SourcePawn = UnitVisualizer.GetPawn();
  40.     SourcePawn.GameStateResetVisualizer(self);
  41.  
  42.     //Units also set up visualizers for their items, since the items are dependent on the unit visualizer
  43.     UnitVisualizer.ApplyLoadoutFromGameState(self, GameState);
  44.  
  45.     for (x = 0; x < AppliedEffectNames.Length; ++x)
  46.     {
  47.         EffectName = AppliedEffectNames[x];
  48.         EffectState = XComGameState_Effect( `XCOMHISTORY.GetGameStateForObjectID( AppliedEffects[ x ].ObjectID ) );
  49.  
  50.         AbilityTemplate = class'XComGameState_Ability'.static.GetMyTemplateManager( ).FindAbilityTemplate( EffectState.ApplyEffectParameters.AbilityInputContext.AbilityTemplateName );
  51.         if (AbilityTemplate.bSkipPerkActivationActions && AbilityTemplate.bSkipPerkActivationActionsSync)
  52.         {
  53.             continue;
  54.         }
  55.  
  56.         Perks.Length = 0;
  57.         class'XComPerkContent'.static.GetAssociatedPerkDefinitions( Perks, SourcePawn, EffectState.ApplyEffectParameters.AbilityInputContext.AbilityTemplateName );
  58.         for (y = 0; y < Perks.Length; ++y)
  59.         {
  60.             if (Perks[y].AssociatedEffect == EffectName)
  61.             {
  62.                 PerkInstance = class'XComPerkContent'.static.GetMatchingInstanceForPerk(SourcePawn, Perks[y] );
  63.                 if (PerkInstance == None)
  64.                 {
  65.                     PerkInstance = WInfo.Spawn( class'XComPerkContentInst' );
  66.                     PerkInstance.Init( Perks[y], SourcePawn);
  67.                 }
  68.  
  69.                 if (!PerkInstance.IsInState('DurationActive'))
  70.                 {
  71.                     ReloadPerkContentInst(PerkInstance, EffectState, AbilityTemplate, Perks[y].AssociatedEffect, EffectName);
  72.                 }
  73.                 else
  74.                 {
  75.                     TargetState = XComGameState_Unit( `XCOMHISTORY.GetGameStateForObjectID( EffectState.ApplyEffectParameters.AbilityInputContext.PrimaryTarget.ObjectID ) );
  76.                     if ((TargetState != none) && (TargetState.AffectedByEffectNames.Find(EffectName) != INDEX_NONE))
  77.                     {
  78.                         PerkInstance.AddPerkTarget(XGUnit( TargetState.GetVisualizer( ) ), EffectState, true);
  79.                     }
  80.                     for (t = 0; t < EffectState.ApplyEffectParameters.AbilityInputContext.MultiTargets.Length; ++t)
  81.                     {
  82.                         TargetState = XComGameState_Unit( `XCOMHISTORY.GetGameStateForObjectID( EffectState.ApplyEffectParameters.AbilityInputContext.MultiTargets[t].ObjectID ) );
  83.                         if ((TargetState != none) && (TargetState.AffectedByEffectNames.Find(EffectName) != INDEX_NONE))
  84.                         {
  85.                             PerkInstance.AddPerkTarget(XGUnit( TargetState.GetVisualizer( ) ), EffectState, true);
  86.                         }
  87.                     }
  88.                 }
  89.  
  90.                 if(!Perks[ y ].CasterDurationFXOnly && !Perks[ y ].TargetDurationFXOnly)
  91.                 {
  92.                     // It is possible this perk is for only the target or source.
  93.                     // Only break if that is not the case.
  94.                     break;
  95.                 }
  96.             }
  97.         }
  98.     }
  99.  
  100.     if( bRemovedFromPlay )
  101.     {
  102.         // Force invisible and clear blocking tile.
  103.         RemoveUnitFromPlay();
  104.     }
  105.     else
  106.     {
  107.         if(IsAlive() && !IsIncapacitated())
  108.         {
  109.             SourcePawn.UpdateAnimations();
  110.         }
  111.        
  112.         if( UnitVisualizer.m_kBehavior == None )
  113.         {
  114.             UnitVisualizer.InitBehavior();
  115.         }
  116.     }
  117.  
  118.     if( IsTurret() && IsAlive() )
  119.     {
  120.         UpdateTurretState(true);
  121.     }
  122.  
  123.     // Don't Ragdoll cocoons
  124.     if (m_SpawnedCocoonRef.ObjectID != 0)
  125.     {
  126.         SourcePawn.RagdollFlag = eRagdoll_Never;
  127.     }
  128.  
  129.     UnitVisualizer.VisualizedAlertLevel = UnitVisualizer.GetAlertLevel(self);
  130.  
  131.     UnitVisualizer.IdleStateMachine.bStartedPanick = bPanicked;
  132.  
  133.     if( GetMyTemplate().bLockdownPodIdleUntilReveal && UnitVisualizer.VisualizedAlertLevel != eAL_Green )
  134.     {
  135.         SourcePawn.GetAnimTreeController().SetAllowNewAnimations(true);
  136.     }
  137.  
  138.     if ((RescueRingRadius > 0) && (GetTeam() == eTeam_Neutral))
  139.     {
  140.         SourcePawn.AttachRangeIndicator( RescueRingRadius, SourcePawn.CivilianRescueRing );
  141.     }
  142.  
  143.     if (bGeneratesCover)
  144.     {
  145.         class'X2Effect_GenerateCover'.static.UpdateWorldCoverDataOnSync( self );
  146.     }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement