Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class X2Actor_VisionCone extends X2Actor_ConeTarget implements(X2VisualizationMgrObserverInterface);
- var int ObjectID;
- function InitVisionCone(float Length, float Width, XComGameState_Unit UnitState)
- {
- local StaticMesh ConeMesh;
- local MaterialInstanceConstant MIC;
- ConeMesh = StaticMesh(`CONTENT.RequestGameArchetype(MeshLocation));
- `assert(ConeMesh != none);
- MeshComp.SetStaticMesh(ConeMesh);
- MIC = GetChildMaterial();
- MIC.SetScalarParameterValue('RangeLengthScale', Length);
- MIC.SetScalarParameterValue('RangeWidthScale', Width);
- XGUnit(UnitState.GetVisualizer()).GetPawn().AttachComponent(MeshComp);
- ObjectID = UnitState.ObjectID;
- RegisterEvents();
- }
- function RegisterEvents()
- {
- local X2EventManager EventManager;
- local Object ThisObj;
- EventManager = `XEVENTMGR;
- ThisObj = self;
- `LOG(default.class @ GetFuncName(),, 'TrueStealth');
- //EventManager.RegisterForEvent(ThisObj, 'AbilityActivated', OnReEvaluationEvent, ELD_OnVisualizationBlockStarted);
- //EventManager.RegisterForEvent(ThisObj, 'PlayerTurnEnded', OnPlayerTurnEnded, ELD_OnStateSubmitted);
- //EventManager.RegisterForEvent(ThisObj, 'OnTacticalBeginPlay', OnTacticalBeginPlay, ELD_OnStateSubmitted);
- EventManager.RegisterForEvent(ThisObj, 'UnitDied', KillCheck, ELD_OnStateSubmitted);
- EventManager.RegisterForEvent(ThisObj, 'AlertDataTriggerAlertAbility', OnAlertDataTriggerAlertAbility, ELD_OnStateSubmitted);
- }
- event Destroyed()
- {
- UnregisterEvents();
- super.Destroyed();
- }
- function UnregisterEvents()
- {
- local X2EventManager EventManager;
- local Object ThisObj;
- EventManager = `XEVENTMGR;
- ThisObj = self;
- EventManager.UnRegisterFromAllEvents(ThisObj);
- }
- function EventListenerReturn KillCheck(Object EventData, Object EventSource, XComGameState GameState, Name EventID, Object CallbackData)
- {
- if (XComGameState_Unit(EventSource).ObjectID == ObjectID)
- {
- self.Destroy();
- }
- return ELR_NoInterrupt;
- }
- function EventListenerReturn OnAlertDataTriggerAlertAbility(Object EventData, Object EventSource, XComGameState GameState, Name Event, Object CallbackData)
- {
- local XComGameState_Unit AlertedUnit;
- local XComGameState_AIUnitData AIGameState;
- local int AIUnitDataID;
- local EAlertCause AlertCause;
- local XComGameState NewGameState;
- local X2Actor_VisionCone VisionCone;
- AlertedUnit = XComGameState_Unit(EventSource);
- if (ObjectID == AlertedUnit.ObjectID)
- {
- UpdateAlertLevel(AlertedUnit);
- `LOG(default.class @ GetFuncName() @ AlertedUnit.GetFullName() @ AlertedUnit.ObjectID @ AlertedUnit.GetCurrentStat(eStat_AlertLevel),, 'TrueStealth');
- }
- return ELR_NoInterrupt;
- }
- event OnVisualizationBlockComplete(XComGameState AssociatedGameState)
- {
- }
- event OnVisualizationIdle()
- {
- }
- event OnActiveUnitChanged(XComGameState_Unit NewActiveUnit)
- {
- self.SetVisible(NewActiveUnit.IsConcealed());
- }
- function UpdateAlertLevel(XComGameState_Unit UnitState)
- {
- local float AlertLevel;
- local MaterialInstanceConstant MIC;
- local LinearColor Color;
- MIC = GetChildMaterial();
- AlertLevel = UnitState.GetCurrentStat(eStat_AlertLevel);
- switch (AlertLevel)
- {
- case `ALERT_LEVEL_GREEN:
- Color.R = 0;
- Color.G = 1;
- Color.B = 0.06;
- Color.A = 0.5;
- break;
- case `ALERT_LEVEL_YELLOW:
- Color.R = 1;
- Color.G = 0.76;
- Color.B = 0;
- Color.A = 0.5;
- break;
- case `ALERT_LEVEL_RED:
- Color.R = 1;
- Color.G = 0;
- Color.B = 0;
- Color.A = 0.5;
- break;
- default:
- Color.R = 0.44;
- Color.G = 0.44;
- Color.B = 0.44;
- Color.A = 0.5;
- break;
- }
- `LOG(default.class @ GetFuncName() @ UnitState.GetFullName() @ UnitState.ObjectID @ AlertLevel @ PathName(MIC) @ Color.R @ Color.G @ Color.B,, 'TrueStealth');
- MIC.SetVectorParameterValue('IconColor', Color);
- }
- simulated private function MaterialInstanceConstant GetChildMaterial()
- {
- local MaterialInterface Mat, ParentMat;
- local MaterialInstanceConstant MIC, ParentMIC, NewMIC;
- if (MeshComp != none)
- {
- MIC = MaterialInstanceConstant(MeshComp.GetMaterial(0));
- // It is possible for there to be MITVs in these slots, so check
- if (MIC != none)
- {
- // If this is not a child MIC, make it one. This is done so that the material updates below don't stomp
- // on each other between units.
- if (InStr(MIC.Name, "MaterialInstanceConstant") == INDEX_NONE)
- {
- NewMIC = new (self) class'MaterialInstanceConstant';
- NewMIC.SetParent(MIC);
- MeshComp.SetMaterial(0, NewMIC);
- MIC = NewMIC;
- }
- ParentMat = MIC.Parent;
- while (!ParentMat.IsA('Material'))
- {
- ParentMIC = MaterialInstanceConstant(ParentMat);
- if (ParentMIC != none)
- ParentMat = ParentMIC.Parent;
- else
- break;
- }
- return MIC;
- }
- }
- return none;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement