public void ProcessTrigger(TriggerProfile trigger, long attackerEntityId = 0, bool skipOnComplete = false) { if (this.RemoteControl?.SlimBlock?.CubeGrid == null) { return; } if (trigger.Triggered == false || trigger.Actions == null) { return; } long detectedEntity = attackerEntityId; if (trigger.DetectedEntityId != 0 && detectedEntity == 0) { detectedEntity = trigger.DetectedEntityId; } trigger.DetectedEntityId = 0; trigger.Triggered = false; trigger.CooldownTime = trigger.Rnd.Next((int)trigger.MinCooldownMs, (int)trigger.MaxCooldownMs); trigger.LastTriggerTime = MyAPIGateway.Session.GameDateTime; trigger.TriggerCount++; Logger.MsgDebug(trigger.Actions.ProfileSubtypeId + ": Performing Eligible Actions", DebugTypeEnum.Action); //ChatBroadcast if (trigger.Actions.UseChatBroadcast == true) { Logger.MsgDebug(trigger.Actions.ProfileSubtypeId + ": Attempting Chat Broadcast", DebugTypeEnum.Action); _broadcast.BroadcastRequest(trigger.Actions.ChatData); } //BarrellRoll - Implement Post Release if (trigger.Actions.BarrelRoll == true) { //_autopilot.ChangeAutoPilotMode(AutoPilotMode.BarrelRoll); } //Strafe - Implement Post Release if (trigger.Actions.Strafe == true) { //_autopilot.ChangeAutoPilotMode(AutoPilotMode.Strafe); } //ChangeAutopilotSpeed if (trigger.Actions.ChangeAutopilotSpeed == true) { Logger.MsgDebug(trigger.Actions.ProfileSubtypeId + ": Changing AutoPilot Speed To: " + trigger.Actions.NewAutopilotSpeed.ToString(), DebugTypeEnum.Action); _autopilot.IdealMaxSpeed = trigger.Actions.NewAutopilotSpeed; var blockList = TargetHelper.GetAllBlocks(RemoteControl.SlimBlock.CubeGrid); foreach (var block in blockList.Where(x => x.FatBlock != null)) { var tBlock = block.FatBlock as IMyRemoteControl; if (tBlock != null) { tBlock.SpeedLimit = trigger.Actions.NewAutopilotSpeed; } } } //SpawnReinforcements if (trigger.Actions.SpawnEncounter == true && trigger.Actions.Spawner.UseSpawn) { Logger.MsgDebug(trigger.Actions.ProfileSubtypeId + ": Attempting Spawn", DebugTypeEnum.Spawn); if (trigger.Actions.Spawner.IsReadyToSpawn()) { //Logger.AddMsg("Do Spawn", true); trigger.Actions.Spawner.CurrentPositionMatrix = this.RemoteControl.WorldMatrix; trigger.Actions.Spawner.CurrentFactionTag = (trigger.Actions.Spawner.ForceSameFactionOwnership && !string.IsNullOrWhiteSpace(_owner.Faction?.Tag)) ? _owner.Faction.Tag : ""; SpawnHelper.SpawnRequest(trigger.Actions.Spawner); } } else { } //SelfDestruct if (trigger.Actions.SelfDestruct == true) { Logger.MsgDebug(trigger.Actions.ProfileSubtypeId + ": Attempting SelfDestruct", DebugTypeEnum.Action); var blockList = TargetHelper.GetAllBlocks(RemoteControl.SlimBlock.CubeGrid); int totalWarheads = 0; foreach (var block in blockList.Where(x => x.FatBlock != null)) { var tBlock = block.FatBlock as IMyWarhead; if (tBlock != null) { if (!trigger.Actions.StaggerWarheadDetonation) { tBlock.IsArmed = true; tBlock.DetonationTime = 0; tBlock.Detonate(); totalWarheads++; } else { tBlock.DetonationTime = totalWarheads + 1; tBlock.StartCountdown(); totalWarheads++; } } } //Logger.AddMsg("TotalBlocks: " + blockList.Count.ToString(), true); //Logger.AddMsg("TotalWarheads: " + totalWarheads.ToString(), true); //TODO: Shield EMP } //Retreat if (trigger.Actions.Retreat) { Logger.MsgDebug(trigger.Actions.ProfileSubtypeId + ": Attempting Retreat", DebugTypeEnum.Action); _despawn.Retreat(); } //ForceDespawn if (trigger.Actions.ForceDespawn) { _despawn.DespawnGrid(); } //TerminateBehavior if (trigger.Actions.TerminateBehavior) { Logger.MsgDebug(trigger.Actions.ProfileSubtypeId + ": Attempting Termination Of Behavior", DebugTypeEnum.Action); _autopilot.ActivateAutoPilot(AutoPilotType.None, NewAutoPilotMode.None, Vector3D.Zero); _behavior.BehaviorTerminated = true; } //BroadcastGenericCommand if (trigger.Actions.BroadcastGenericCommand == true) { Logger.MsgDebug(trigger.Actions.ProfileSubtypeId + ": Attempting Broadcast of Generic Command", DebugTypeEnum.Action); var antenna = BlockHelper.GetAntennaWithHighestRange(this.AntennaList); if (antenna != null) { CommandHelper.CommandTrigger?.Invoke(trigger.Actions.BroadcastSendCode, this.RemoteControl, (double)antenna.Radius, 0); } } //BroadcastCurrentTarget if (trigger.Actions.BroadcastCurrentTarget == true && detectedEntity != 0) { Logger.MsgDebug(trigger.Actions.ProfileSubtypeId + ": Attempting Broadcast of Current Target", DebugTypeEnum.Action); var antenna = BlockHelper.GetAntennaWithHighestRange(this.AntennaList); if (antenna != null) { CommandHelper.CommandTrigger?.Invoke(trigger.Actions.BroadcastSendCode, this.RemoteControl, (double)antenna.Radius, detectedEntity); } } //SwitchToReceivedTarget if (trigger.Actions.SwitchToReceivedTarget == true && detectedEntity != 0) { Logger.MsgDebug(trigger.Actions.ProfileSubtypeId + ": Attempting Switch to Received Target Data", DebugTypeEnum.Action); _autopilot.Targeting.ForceTargetEntity = detectedEntity; _autopilot.Targeting.ForceRefresh = true; } //SwitchToBehavior if (trigger.Actions.SwitchToBehavior == true) { _behavior.ChangeBehavior(trigger.Actions.NewBehavior, trigger.Actions.PreserveSettingsOnBehaviorSwitch, trigger.Actions.PreserveTriggersOnBehaviorSwitch, trigger.Actions.PreserveTargetDataOnBehaviorSwitch); } //RefreshTarget if (trigger.Actions.RefreshTarget == true) { Logger.MsgDebug(trigger.Actions.ProfileSubtypeId + ": Attempting Target Refresh", DebugTypeEnum.Action); _autopilot.Targeting.ForceRefresh = true; } //ChangeTargetProfile if (trigger.Actions.ChangeTargetProfile == true) { Logger.MsgDebug(trigger.Actions.ProfileSubtypeId + ": Attempting Target Change", DebugTypeEnum.Action); _autopilot.Targeting.UseNewTargetProfile = true; _autopilot.Targeting.NewTargetProfileName = trigger.Actions.NewTargetProfileId; } //ChangeReputationWithPlayers if (trigger.Actions.ChangeReputationWithPlayers == true) { Logger.MsgDebug(trigger.Actions.ProfileSubtypeId + ": Attempting Reputation Change With Players In Radius", DebugTypeEnum.Action); OwnershipHelper.ChangeReputationWithPlayersInRadius(this.RemoteControl, trigger.Actions.ReputationChangeRadius, trigger.Actions.ReputationChangeAmount, trigger.Actions.ReputationChangeFactions, trigger.Actions.ReputationChangesForAllRadiusPlayerFactionMembers); } //ChangeAttackerReputation if (trigger.Actions.ChangeAttackerReputation == true && detectedEntity != 0) { Logger.MsgDebug(trigger.Actions.ProfileSubtypeId + ": Attempting Reputation Change for Attacker", DebugTypeEnum.Action); OwnershipHelper.ChangeDamageOwnerReputation(trigger.Actions.ChangeAttackerReputationFaction, detectedEntity, trigger.Actions.ChangeAttackerReputationAmount, trigger.Actions.ReputationChangesForAllAttackPlayerFactionMembers); } //TriggerTimerBlock if (trigger.Actions.TriggerTimerBlocks == true) { Logger.MsgDebug(trigger.Actions.ProfileSubtypeId + ": Attempting Trigger of Timer Blocks", DebugTypeEnum.Action); var blockList = BlockHelper.GetBlocksWithNames(RemoteControl.SlimBlock.CubeGrid, trigger.Actions.TimerBlockNames); foreach (var block in blockList) { var tBlock = block as IMyTimerBlock; if (tBlock != null) { tBlock.Trigger(); } } } //ChangeBlockNames if (trigger.Actions.ChangeBlockNames) { BlockHelper.RenameBlocks(RemoteControl.CubeGrid, trigger.Actions.ChangeBlockNamesFrom, trigger.Actions.ChangeBlockNamesTo, trigger.Actions.ProfileSubtypeId); } //ChangeAntennaRanges if (trigger.Actions.ChangeAntennaRanges) { BlockHelper.SetGridAntennaRanges(AntennaList, trigger.Actions.AntennaNamesForRangeChange, trigger.Actions.AntennaRangeChangeType, trigger.Actions.AntennaRangeChangeAmount); } //ChangeAntennaOwnership if (trigger.Actions.ChangeAntennaOwnership == true) { Logger.MsgDebug(trigger.Actions.ProfileSubtypeId + ": Attempting Antenna Ownership Change", DebugTypeEnum.Action); OwnershipHelper.ChangeAntennaBlockOwnership(AntennaList, trigger.Actions.AntennaFactionOwner); } //CreateKnownPlayerArea if (trigger.Actions.CreateKnownPlayerArea == true) { Logger.MsgDebug(trigger.Actions.ProfileSubtypeId + ": Attempting Creation of Known Player Area in MES", DebugTypeEnum.Action); MESApi.AddKnownPlayerLocation(this.RemoteControl.GetPosition(), _owner.Faction?.Tag, trigger.Actions.KnownPlayerAreaRadius, trigger.Actions.KnownPlayerAreaTimer, trigger.Actions.KnownPlayerAreaMaxSpawns); } //DamageAttacker if (trigger.Actions.DamageToolAttacker == true && detectedEntity != 0) { Logger.MsgDebug(trigger.Actions.ProfileSubtypeId + ": Attempting Damage to Tool User", DebugTypeEnum.Action); DamageHelper.ApplyDamageToTarget(attackerEntityId, trigger.Actions.DamageToolAttackerAmount, trigger.Actions.DamageToolAttackerParticle, trigger.Actions.DamageToolAttackerSound); } //PlayParticleEffectAtRemote if (trigger.Actions.PlayParticleEffectAtRemote == true) { EffectManager.SendParticleEffectRequest(trigger.Actions.ParticleEffectId, this.RemoteControl.WorldMatrix, trigger.Actions.ParticleEffectOffset, trigger.Actions.ParticleEffectScale, trigger.Actions.ParticleEffectMaxTime, trigger.Actions.ParticleEffectColor); } //ResetCooldownTimeOfTriggers if (trigger.Actions.ResetCooldownTimeOfTriggers) { foreach (var resetTrigger in Triggers) { if (trigger.Actions.ResetTriggerCooldownNames.Contains(resetTrigger.ProfileSubtypeId)) { resetTrigger.LastTriggerTime = MyAPIGateway.Session.GameDateTime; } } foreach (var resetTrigger in DamageTriggers) { if (trigger.Actions.ResetTriggerCooldownNames.Contains(resetTrigger.ProfileSubtypeId)) { resetTrigger.LastTriggerTime = MyAPIGateway.Session.GameDateTime; } } foreach (var resetTrigger in CommandTriggers) { if (trigger.Actions.ResetTriggerCooldownNames.Contains(resetTrigger.ProfileSubtypeId)) { resetTrigger.LastTriggerTime = MyAPIGateway.Session.GameDateTime; } } } if (trigger.Actions.EnableTriggers) { foreach (var resetTrigger in Triggers) { if (trigger.Actions.EnableTriggerNames.Contains(resetTrigger.ProfileSubtypeId)) { resetTrigger.UseTrigger = true; } } foreach (var resetTrigger in DamageTriggers) { if (trigger.Actions.EnableTriggerNames.Contains(resetTrigger.ProfileSubtypeId)) { resetTrigger.UseTrigger = true; } } foreach (var resetTrigger in CommandTriggers) { if (trigger.Actions.EnableTriggerNames.Contains(resetTrigger.ProfileSubtypeId)) { resetTrigger.UseTrigger = true; } } } if (trigger.Actions.DisableTriggers) { foreach (var resetTrigger in Triggers) { if (trigger.Actions.DisableTriggerNames.Contains(resetTrigger.ProfileSubtypeId)) { resetTrigger.UseTrigger = false; } } foreach (var resetTrigger in DamageTriggers) { if (trigger.Actions.DisableTriggerNames.Contains(resetTrigger.ProfileSubtypeId)) { resetTrigger.UseTrigger = false; } } foreach (var resetTrigger in CommandTriggers) { if (trigger.Actions.DisableTriggerNames.Contains(resetTrigger.ProfileSubtypeId)) { resetTrigger.UseTrigger = false; } } } //ChangeInertiaDampeners if (trigger.Actions.ChangeInertiaDampeners) { RemoteControl.DampenersOverride = trigger.Actions.InertiaDampenersEnable; } //ChangeRotationDirection if (trigger.Actions.ChangeRotationDirection) { _behavior.Settings.SetRotation(trigger.Actions.RotationDirection); } //GenerateExplosion if (trigger.Actions.GenerateExplosion) { var coords = Vector3D.Transform(trigger.Actions.ExplosionOffsetFromRemote, RemoteControl.WorldMatrix); MyVisualScriptLogicProvider.CreateExplosion(coords, trigger.Actions.ExplosionRange, trigger.Actions.ExplosionDamage); } //SetBooleansTrue foreach (var variable in trigger.Actions.SetBooleansTrue) { _settings.SetCustomBool(variable, true); } //SetBooleansFalse foreach (var variable in trigger.Actions.SetBooleansFalse) { _settings.SetCustomBool(variable, false); } //IncreaseCounters foreach (var variable in trigger.Actions.IncreaseCounters) { _settings.SetCustomCounter(variable, 1); } //DecreaseCounters foreach (var variable in trigger.Actions.DecreaseCounters) { _settings.SetCustomCounter(variable, -1); } //ResetCounters foreach (var variable in trigger.Actions.ResetCounters) { _settings.SetCustomCounter(variable, 0, true); } //SetSandboxBooleansTrue foreach (var variable in trigger.Actions.SetSandboxBooleansTrue) { SetSandboxBool(variable, true); } //SetSandboxBooleansFalse foreach (var variable in trigger.Actions.SetSandboxBooleansFalse) { SetSandboxBool(variable, false); } //IncreaseSandboxCounters foreach (var variable in trigger.Actions.IncreaseSandboxCounters) { SetSandboxCounter(variable, 1); } //DecreaseSandboxCounters foreach (var variable in trigger.Actions.DecreaseSandboxCounters) { SetSandboxCounter(variable, -1); } //ResetSandboxCounters foreach (var variable in trigger.Actions.ResetSandboxCounters) { SetSandboxCounter(variable, 0); } //BehaviorSpecificEventA if (trigger.Actions.BehaviorSpecificEventA) { BehaviorEventA?.Invoke(); } //BehaviorSpecificEventB if (trigger.Actions.BehaviorSpecificEventB) { BehaviorEventB?.Invoke(); } //BehaviorSpecificEventC if (trigger.Actions.BehaviorSpecificEventC) { BehaviorEventC?.Invoke(); } //BehaviorSpecificEventD if (trigger.Actions.BehaviorSpecificEventD) { BehaviorEventD?.Invoke(); } //BehaviorSpecificEventE if (trigger.Actions.BehaviorSpecificEventE) { BehaviorEventE?.Invoke(); } //BehaviorSpecificEventF if (trigger.Actions.BehaviorSpecificEventF) { BehaviorEventF?.Invoke(); } //BehaviorSpecificEventG if (trigger.Actions.BehaviorSpecificEventG) { BehaviorEventG?.Invoke(); } //BehaviorSpecificEventH if (trigger.Actions.BehaviorSpecificEventH) { BehaviorEventH?.Invoke(); } }