Advertisement
musashi1584

Untitled

Jul 17th, 2017
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class X2Ability_Silacoid_AbilitySet extends X2Ability;
  2.  
  3. static function array<X2DataTemplate> CreateTemplates()
  4. {
  5.     local array<X2DataTemplate> Templates;
  6.  
  7.     Templates.AddItem(FireTrail());
  8.     Templates.AddItem(PurePassive('FireTrail_Passive', "img:///UILibrary_PerkIcons.UIPerk_andromedon_poisoncloud"));
  9.  
  10.     return Templates;
  11. }
  12.  
  13. static function X2AbilityTemplate FireTrail()
  14. {
  15.     local X2AbilityTemplate Template;
  16.     local X2AbilityTrigger_EventListener EventListener;
  17.  
  18.     `CREATE_X2ABILITY_TEMPLATE(Template, 'FireTrail');
  19.     Template.IconImage = "img:///UILibrary_PerkIcons.UIPerk_andromedon_poisoncloud"; // TODO: This needs to be changed
  20.  
  21.     Template.AdditionalAbilities.AddItem('FireTrail_Passive');
  22.  
  23.     Template.AbilitySourceName = 'eAbilitySource_Standard';
  24.     Template.eAbilityIconBehaviorHUD = EAbilityIconBehavior_NeverShow;
  25.     Template.Hostility = eHostility_Neutral;
  26.  
  27.     //This ability fires as part of game states where the Andromedon robot moves
  28.     EventListener = new class'X2AbilityTrigger_EventListener';
  29.     EventListener.ListenerData.Deferral = ELD_OnStateSubmitted;
  30.     EventListener.ListenerData.EventID = 'UnitMoveFinished';
  31.     EventListener.ListenerData.Filter = eFilter_Unit;
  32.     EventListener.ListenerData.EventFn = BuildFireTrail_Self;
  33.     Template.AbilityTriggers.AddItem(EventListener);
  34.  
  35.     // Targets the Andromedon unit so it can be replaced by the andromedon robot;
  36.     Template.AbilityTargetStyle = default.SelfTarget;
  37.  
  38.     //NOTE: This ability does not require a build game state or visualization function because this is handled
  39.     //      by the event listener and associated functionality when creating world tile effects
  40.     Template.BuildNewGameStateFn = Empty_BuildGameState;
  41.  
  42.     return Template;
  43. }
  44.  
  45. function XComGameState Empty_BuildGameState( XComGameStateContext Context )
  46. {
  47.     return none;
  48. }
  49.  
  50. static function EventListenerReturn BuildFireTrail_Self(Object EventData, Object EventSource, XComGameState GameState, Name EventID)
  51. {
  52.     local XComGameStateContext_Ability MoveContext;
  53.     local int TileIndex;   
  54.     local XComGameState NewGameState;
  55.     local float AbilityRadius;
  56.     local XComWorldData WorldData;
  57.     local vector TargetLocation;
  58.     local array<TilePosPair> OutTiles;
  59.     local TTile MovementTile;
  60.     local XComGameState_Unit UnitStateObject;
  61.     local XComGameStateHistory History;
  62.     local int FireNumTurns;
  63.  
  64.     MoveContext = XComGameStateContext_Ability(GameState.GetContext());
  65.  
  66.     History = `XCOMHISTORY;
  67.     WorldData = `XWORLD;
  68.  
  69.     //Define how wide the trail will spread
  70.     AbilityRadius = class'XComWorldData'.const.WORLD_StepSize * 0.5f;
  71.     //Define how long the trail will last
  72.     FireNumTurns = 2;
  73.  
  74.     //These branches define different situations for which we should generate tile effects. Our first step is to
  75.     //see what tiles we will be affecting
  76.     if( MoveContext.InputContext.MovementPaths[0].MovementTiles.Length > 0 )
  77.     {      
  78.         //If this move was uninterrupted, or we do not have a resume
  79.         if( MoveContext.InterruptionStatus == eInterruptionStatus_None || MoveContext.ResumeHistoryIndex < 0 )
  80.         {
  81.             //Build the list of tiles that will be affected by the fire and set it into our tile update game state object          
  82.             for(TileIndex = 0; TileIndex < MoveContext.InputContext.MovementPaths[0].MovementTiles.Length; ++TileIndex)
  83.             {
  84.                 MovementTile = MoveContext.InputContext.MovementPaths[0].MovementTiles[TileIndex];
  85.                 TargetLocation = WorldData.GetPositionFromTileCoordinates(MovementTile);               
  86.                 WorldData.CollectTilesInSphere( OutTiles, TargetLocation, AbilityRadius );
  87.             }
  88.         }
  89.     }
  90.     else
  91.     {
  92.         //This may occur during teleports, spawning, or other instaneous modes of travel
  93.         UnitStateObject = XComGameState_Unit(History.GetGameStateForObjectID(MoveContext.InputContext.SourceObject.ObjectID));
  94.        
  95.         UnitStateObject.GetKeystoneVisibilityLocation(MovementTile);
  96.         TargetLocation = WorldData.GetPositionFromTileCoordinates(MovementTile);       
  97.        
  98.         WorldData.CollectTilesInSphere( OutTiles, TargetLocation, AbilityRadius );
  99.     }
  100.        
  101.     //If we will be adding fire to any tiles, do the rest of the set up
  102.     if( OutTiles.Length > 0 )
  103.     {
  104.         //Build the game state for the fire trail update
  105.         NewGameState = History.CreateNewGameState(true, class'XComGameStateContext_AreaDamage'.static.CreateXComGameStateContext());
  106.  
  107.         if( UnitStateObject == none )
  108.         {
  109.             //This may occur during teleports, spawning, or other instaneous modes of travel
  110.             UnitStateObject = XComGameState_Unit(History.GetGameStateForObjectID(MoveContext.InputContext.SourceObject.ObjectID));
  111.         }
  112.         class'X2Effect_ApplyFireToWorld'.static.SharedApplyFireToTiles('X2Effect_ApplyFireToWorld', X2Effect_ApplyFireToWorld(class'Engine'.static.FindClassDefaultObject("X2Effect_ApplyFireToWorld")), NewGameState, OutTiles, UnitStateObject, FireNumTurns);
  113.    
  114.         //Submit the new game state to the rules engine
  115.         `GAMERULES.SubmitGameState(NewGameState);
  116.     }
  117.  
  118.     return ELR_NoInterrupt;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement