Advertisement
Guest User

Untitled

a guest
Apr 30th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class X2Actor_VisionCone extends X2Actor_ConeTarget implements(X2VisualizationMgrObserverInterface);
  2.  
  3. var int ObjectID;
  4.  
  5. function InitVisionCone(float Length, float Width, XComGameState_Unit UnitState)
  6. {
  7.     local StaticMesh ConeMesh;
  8.     local MaterialInstanceConstant MIC;
  9.  
  10.     ConeMesh = StaticMesh(`CONTENT.RequestGameArchetype(MeshLocation));
  11.     `assert(ConeMesh != none);
  12.     MeshComp.SetStaticMesh(ConeMesh);
  13.  
  14.     MIC = GetChildMaterial();
  15.     MIC.SetScalarParameterValue('RangeLengthScale', Length);
  16.     MIC.SetScalarParameterValue('RangeWidthScale', Width);
  17.    
  18.     XGUnit(UnitState.GetVisualizer()).GetPawn().AttachComponent(MeshComp);
  19.     ObjectID = UnitState.ObjectID;
  20.     RegisterEvents();
  21. }
  22.  
  23.  
  24. function RegisterEvents()
  25. {
  26.     local X2EventManager EventManager;
  27.     local Object ThisObj;
  28.  
  29.     EventManager = `XEVENTMGR;
  30.     ThisObj = self;
  31.  
  32.     `LOG(default.class @ GetFuncName(),, 'TrueStealth');
  33.  
  34.     //EventManager.RegisterForEvent(ThisObj, 'AbilityActivated', OnReEvaluationEvent, ELD_OnVisualizationBlockStarted);
  35.     //EventManager.RegisterForEvent(ThisObj, 'PlayerTurnEnded', OnPlayerTurnEnded, ELD_OnStateSubmitted);
  36.     //EventManager.RegisterForEvent(ThisObj, 'OnTacticalBeginPlay', OnTacticalBeginPlay, ELD_OnStateSubmitted);
  37.  
  38.     EventManager.RegisterForEvent(ThisObj, 'UnitDied', KillCheck, ELD_OnStateSubmitted);
  39.     EventManager.RegisterForEvent(ThisObj, 'AlertDataTriggerAlertAbility', OnAlertDataTriggerAlertAbility, ELD_OnStateSubmitted);
  40. }
  41.  
  42. event Destroyed()
  43. {
  44.     UnregisterEvents();
  45.     super.Destroyed();
  46. }
  47.  
  48. function UnregisterEvents()
  49. {
  50.     local X2EventManager EventManager;
  51.     local Object ThisObj;
  52.  
  53.     EventManager = `XEVENTMGR;
  54.     ThisObj = self;
  55.  
  56.     EventManager.UnRegisterFromAllEvents(ThisObj);
  57. }
  58.  
  59. function EventListenerReturn KillCheck(Object EventData, Object EventSource, XComGameState GameState, Name EventID, Object CallbackData)
  60. {
  61.     if (XComGameState_Unit(EventSource).ObjectID == ObjectID)
  62.     {
  63.         self.Destroy();
  64.     }
  65.     return ELR_NoInterrupt;
  66. }
  67.  
  68. function EventListenerReturn OnAlertDataTriggerAlertAbility(Object EventData, Object EventSource, XComGameState GameState, Name Event, Object CallbackData)
  69. {
  70.     local XComGameState_Unit AlertedUnit;
  71.     local XComGameState_AIUnitData AIGameState;
  72.     local int AIUnitDataID;
  73.     local EAlertCause AlertCause;
  74.     local XComGameState NewGameState;
  75.     local X2Actor_VisionCone VisionCone;
  76.  
  77.     AlertedUnit = XComGameState_Unit(EventSource);
  78.  
  79.     if (ObjectID == AlertedUnit.ObjectID)
  80.     {
  81.         UpdateAlertLevel(AlertedUnit);
  82.         `LOG(default.class @ GetFuncName() @ AlertedUnit.GetFullName() @ AlertedUnit.ObjectID @ AlertedUnit.GetCurrentStat(eStat_AlertLevel),, 'TrueStealth');
  83.     }
  84.  
  85.     return ELR_NoInterrupt;
  86. }
  87.  
  88. event OnVisualizationBlockComplete(XComGameState AssociatedGameState)
  89. {
  90.  
  91. }
  92.  
  93. event OnVisualizationIdle()
  94. {
  95.  
  96. }
  97.  
  98. event OnActiveUnitChanged(XComGameState_Unit NewActiveUnit)
  99. {
  100.     self.SetVisible(NewActiveUnit.IsConcealed());
  101. }
  102.  
  103. function UpdateAlertLevel(XComGameState_Unit UnitState)
  104. {
  105.     local float AlertLevel;
  106.     local MaterialInstanceConstant MIC;
  107.     local LinearColor Color;
  108.  
  109.     MIC = GetChildMaterial();
  110.  
  111.     AlertLevel = UnitState.GetCurrentStat(eStat_AlertLevel);
  112.  
  113.     switch (AlertLevel)
  114.     {
  115.         case `ALERT_LEVEL_GREEN:
  116.             Color.R = 0;
  117.             Color.G = 1;
  118.             Color.B = 0.06;
  119.             Color.A = 0.5;
  120.             break;
  121.         case `ALERT_LEVEL_YELLOW:
  122.             Color.R = 1;
  123.             Color.G = 0.76;
  124.             Color.B = 0;
  125.             Color.A = 0.5;
  126.             break;
  127.         case `ALERT_LEVEL_RED:
  128.             Color.R = 1;
  129.             Color.G = 0;
  130.             Color.B = 0;
  131.             Color.A = 0.5;
  132.             break;
  133.         default:
  134.             Color.R = 0.44;
  135.             Color.G = 0.44;
  136.             Color.B = 0.44;
  137.             Color.A = 0.5;
  138.             break;
  139.     }
  140.     `LOG(default.class @ GetFuncName() @ UnitState.GetFullName() @ UnitState.ObjectID @ AlertLevel @ PathName(MIC) @ Color.R @ Color.G @ Color.B,, 'TrueStealth');
  141.     MIC.SetVectorParameterValue('IconColor', Color);
  142. }
  143.  
  144. simulated private function MaterialInstanceConstant GetChildMaterial()
  145. {
  146.     local MaterialInterface Mat, ParentMat;
  147.     local MaterialInstanceConstant MIC, ParentMIC, NewMIC;
  148.  
  149.     if (MeshComp != none)
  150.     {
  151.  
  152.         MIC = MaterialInstanceConstant(MeshComp.GetMaterial(0));
  153.  
  154.         // It is possible for there to be MITVs in these slots, so check
  155.         if (MIC != none)
  156.         {
  157.             // If this is not a child MIC, make it one. This is done so that the material updates below don't stomp
  158.             // on each other between units.
  159.             if (InStr(MIC.Name, "MaterialInstanceConstant") == INDEX_NONE)
  160.             {
  161.                 NewMIC = new (self) class'MaterialInstanceConstant';
  162.                 NewMIC.SetParent(MIC);
  163.                 MeshComp.SetMaterial(0, NewMIC);
  164.                 MIC = NewMIC;
  165.             }
  166.  
  167.             ParentMat = MIC.Parent;
  168.             while (!ParentMat.IsA('Material'))
  169.             {
  170.                 ParentMIC = MaterialInstanceConstant(ParentMat);
  171.                 if (ParentMIC != none)
  172.                     ParentMat = ParentMIC.Parent;
  173.                 else
  174.                     break;
  175.             }
  176.  
  177.             return MIC;
  178.         }
  179.     }
  180.     return none;
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement