<?xml version="1.0" encoding="utf-8"?>
<Randomevents>
  <EventPrefabs>
    <!--commsrelay EVENTS-->
    <!-- UNUSED. 
    TODO: Rework by adding a custom logbook item that rarely spawns in wrecks, upon reading trigger an unknown monster mission
          Change tags of randomencounter missions  to match logbook description -->
    <!-- <ScriptedEvent identifier="commsrelay_randomencounter" commonness="100">
      <TagAction criteria="player" tag="player" ContinueIfNoTargetsFound="true" />
      <TagAction criteria="itemtag:navterminal" tag="commsrelay" submarinetype="player" ContinueIfNoTargetsFound="true" />
      <TagAction criteria="itemtag:sonarmonitor" tag="commsrelay" Submarinetype="player" ContinueIfNoTargetsFound="true" />
      <TagAction criteria="itemtag:sonarmonitor" tag="commsrelay" SubmarineType="BeaconStation" ContinueIfNoTargetsFound="true"  />
      <TriggerAction target1tag="commsrelay" target2tag="player" applytotarget2="cre_trig_player" radius="100" waitforinteraction="true" />
      <ConversationAction text="eventtext.commsrelay.monster" dialogtype="Small" targettag="cre_trig_player" eventsprite="sonar">
        <Option text="eventtext.option.listen" endconversation="true">
          <StatusEffectAction targettag="cre_trig_player">
            <StatusEffect target="NearbyItems" tags="commsrelay" duration="10.5">
              <Sound file="%ModDir:2532991202%/Sounds/Events/MonsterBroadcast.ogg" volume="1" loop="true" />
            </StatusEffect>
          </StatusEffectAction>
          <ConversationAction text="eventtext.commsrelay.monster.answer" dialogtype="Small" targettag="cre_trig_player" />
          <MissionAction missiontag="randomencounter" locationtype="None" minlocationdistance="1" />
          <ClearTagAction tag="cre_trig_player" />
        </Option>
        <Option text="eventtext.option.ignore" endconversation="true">
          <ClearTagAction tag="cre_trig_player" />
        </Option>
      </ConversationAction>
    </ScriptedEvent> -->
    <!--TRIGGERED AT A WRECK TO ALERT YOU-->
    <ScriptedEvent identifier="commsrelay_wreck">
      <TagAction criteria="hull" tag="wreck" submarinetype="wreck" ContinueIfNoTargetsFound="false" />
      <TagAction criteria="player" tag="player" ContinueIfNoTargetsFound="true" />
      <WaitAction time="30" />
      <TriggerAction target1tag="wreck" target2tag="player" radius="500000" waitforinteraction="false" />
      <TagAction criteria="itemtag:navterminal" tag="commsrelay" submarinetype="player" ContinueIfNoTargetsFound="true" />
      <TagAction criteria="itemtag:sonarmonitor" tag="commsrelay" Submarinetype="player" ContinueIfNoTargetsFound="true" />
      <TagAction criteria="itemtag:sonarmonitor" tag="commsrelay" SubmarineType="BeaconStation" ContinueIfNoTargetsFound="true" />
      <TriggerAction target1tag="commsrelay" target2tag="player" applytotarget2="crw_trig_player" radius="100" waitforinteraction="true" />
      <ConversationAction text="eventtext.commsrelay.wreck" dialogtype="Small" targettag="crw_trig_player" eventsprite="sonar">
        <Option text="eventtext.option.investigate">
          <StatusEffectAction targettag="crw_trig_player">
            <StatusEffect target="NearbyItems" tags="commsrelay" duration="10.5">
              <Sound file="%ModDir:2532991202%/Sounds/Events/SOSBroadcast.ogg" volume="1" loop="true" />
            </StatusEffect>
          </StatusEffectAction>
          <ConversationAction text="eventtext.commsrelay.wreck.answer" dialogtype="Small" targettag="crw_trig_player" />
          <SpawnAction itemidentifier="broadcasterwreck" spawnlocation="wreck" />
          <ClearTagAction tag="crw_trig_player" />
          <SetDataAction identifier="commsrelay_multiwreck_triggered" operation="Set" value="0" />
        </Option>
        <Option text="eventtext.option.ignore">
          <ConversationAction text="eventtext.general.decline" dialogtype="Small" targettag="crw_trig_player" />
          <ClearTagAction tag="crw_trig_player" />
          <SetDataAction identifier="commsrelay_multiwreck_triggered" operation="Set" value="0" />
        </Option>
      </ConversationAction>
    </ScriptedEvent>
    <!--TRIGGERED AT A RUIN TO ALERT YOU-->
    <ScriptedEvent identifier="commsrelay_ruin" commonness="100">
      <TagAction criteria="hull" tag="ruin" submarinetype="ruin" ContinueIfNoTargetsFound="false" />
      <TagAction criteria="player" tag="player" ContinueIfNoTargetsFound="true" />
      <WaitAction time="30" />
      <TriggerAction target1tag="ruin" target2tag="player" radius="500000" waitforinteraction="false" />
      <TagAction criteria="itemtag:navterminal" tag="commsrelay" submarinetype="player" ContinueIfNoTargetsFound="true" />
      <TagAction criteria="itemtag:sonarmonitor" tag="commsrelay" Submarinetype="player" ContinueIfNoTargetsFound="true" />
      <TagAction criteria="itemtag:sonarmonitor" tag="commsrelay" SubmarineType="BeaconStation" ContinueIfNoTargetsFound="true" />
      <TriggerAction target1tag="commsrelay" target2tag="player" applytotarget2="crr_trig_player" radius="100" waitforinteraction="true" />
      <ConversationAction text="eventtext.commsrelay.ruin" dialogtype="Small" targettag="crr_trig_player" eventsprite="sonar">
        <Option text="eventtext.option.investigate">
          <StatusEffectAction targettag="commsrelay">
            <StatusEffect target="This" duration="10.5">
              <Sound file="%ModDir:2532991202%/Sounds/Events/AlienBroadcast.ogg" volume="1" loop="true" />
            </StatusEffect>
          </StatusEffectAction>
          <ConversationAction text="eventtext.commsrelay.ruin.answer" dialogtype="Small" targettag="crr_trig_player" eventsprite="sonar" />
          <SpawnAction itemidentifier="broadcasterruin" spawnlocation="ruin" />
          <ClearTagAction tag="crr_trig_player" />
        </Option>
        <Option text="eventtext.option.ignore">
          <ConversationAction text="eventtext.general.decline" dialogtype="Small" targettag="crr_trig_player" eventsprite="sonar" />
          <ClearTagAction tag="crr_trig_player" />
        </Option>
      </ConversationAction>
    </ScriptedEvent>
    <!-- TODO: rework this, including stealingintel -->
    <!--     <ScriptedEvent identifier="factionseparatist" commonness="100">
      <TagAction criteria="itemtag:hidden" tag="deaddrop" ContinueIfNoTargetsFound="true" />
      <Label name="deaddropreturn" />
      <TriggerAction target1tag="deaddrop" target2tag="player" applytotarget1="selecteddeaddrop" applytotarget2="fs_trig_player" radius="50" waitforinteraction="true" />
      <ConversationAction text="eventtext.factionseparatist.hiddenstash" dialogtype="Small" targettag="fs_trig_player" eventsprite="vent">
        <Option text="eventtext.option.investigate">
          <ConversationAction text="eventtext.factionseparatist.hiddenstash.take" targettag="fs_trig_player" />
          <SpawnAction itemidentifier="detonator" targetinventory="fs_trig_player" />
          <MissionAction missionidentifier="stealingintel" locationtype="City,Colony,Military,Base" requiredfaction="coalition" minlocationdistance="2" />
          <ClearTagAction tag="fs_trig_player" />
        </Option>
      </ConversationAction>
    </ScriptedEvent> -->
    <!--Stowaway 2, reworked version of the unused vanilla event-->
    <ScriptedEvent identifier="stowaway22" commonness="50">
      <!-- requires a cargo mission. note: not all cargo missions are tagged "cargo" -->
      <CheckMissionAction missiontag="cargo" Type="Current">
        <Success>
          <WaitAction time="50" />
          <CheckDataAction identifier="stowaway2_complete" condition="eq true">
            <Success>
              <!--Don't repeat event-->
            </Success>
            <Failure>
              <TagAction criteria="player" tag="player" />
              <TagAction criteria="itemidentifier:steelcabinet" tag="potentialcabinet" submarinetype="player" />
              <TagAction criteria="itemidentifier:mediumwindowedsteelcabinet" tag="potentialcabinet" submarinetype="player" />
              <TagAction criteria="itemidentifier:mediumsteelcabinet" tag="potentialcabinet" submarinetype="player" />
              <!-- use a trigger to tag a single cabinet -->
              <TriggerAction target1tag="potentialcabinet" target2tag="player" applytotarget1="triggered_cabinet" radius="150" waitforinteraction="false" />
              <StatusEffectAction targettag="triggered_cabinet">
                <StatusEffect target="this">
                  <Sound file="Content/Items/Door/Duct2.ogg" range="800" volume="3" frequencymultiplier="0.25" />
                  <ParticleEmitter particle="shockwavesmall" particleamount="3" />
                </StatusEffect>
              </StatusEffectAction>
              <Label name="stowawayreturn" />
              <TriggerAction target1tag="triggered_cabinet" target2tag="player" applytotarget2="triggerer_player" radius="150" waitforinteraction="true" />
              <ConversationAction text="EventText.stowaway2.c1" dialogtype="Regular" targettag="triggerer_player" eventsprite="Stowaway2">
                <Option text="EventText.stowaway2.o1">
                  <CheckReputationAction targettype="faction" identifier="clowns" condition="gte 20">
                    <Success>
                      <SpawnAction npcsetidentifier="customnpcs1" npcidentifier="clownmessenger" targettag="messenger" spawnpointtag="triggerer_player" />
                      <SetDataAction identifier="stowaway2_complete" value="true" />
                      <StatusEffectAction targettag="triggered_cabinet">
                        <StatusEffect target="this">
                          <Sound file="Content/Items/Jobgear/Clown/ITEM_bananaSlip1.ogg" range="800" volume="2" frequencymultiplier="1" />
                          <ParticleEmitter particle="impactfirearm" particleamount="30" velocitymin="50" velocitymax="100" anglemin="45" anglemax="135" scalemin="0.5" scalemax="1" Spread="75" distancemin="-75" distancemax="75" colormultiplier="255,255,255,255" lifetimemultiplier="5" />
                        </StatusEffect>
                      </StatusEffectAction>
                      <ConversationAction text="EventText.stowaway2.o1.c1" dialogtype="Regular" targettag="triggerer_player">
                        <Option text="EventText.stowaway2.o1.o1">
                          <ConversationAction text="EventText.stowaway2.o1.o1.c1" dialogtype="Regular" targettag="triggerer_player" />
                          <TriggerEventAction identifier="stowaway2clownmission" nextround="true" />
                        </Option>
                      </ConversationAction>
                    </Success>
                    <!-- regular stowaway -->
                    <Failure>
                      <ConversationAction text="EventText.stowaway2.o1.c2" dialogtype="Regular" targettag="triggerer_player">
                        <Option text="EventText.stowaway2.o1.o2">
                          <ConversationAction text="EventText.stowaway2.o1.o2.c1" dialogtype="Regular" targettag="triggerer_player">
                            <Option text="EventText.stowaway2.o1.o2.o1">
                              <Label name="whatamIgoingtodo" />
                              <ConversationAction text="EventText.stowaway2.o1.o2.o1.c1" dialogtype="Regular" targettag="triggerer_player">
                                <Option text="EventText.stowaway2.o1.o2.o1.o1">
                                  <ConversationAction text="EventText.stowaway2.o1.o2.o1.o1.c1" dialogtype="Regular" targettag="triggerer_player">
                                    <Option text="EventText.stowaway2.o1.o2.o1.o1.o2">
                                      <SpawnAction npcsetidentifier="customnpcs1" npcidentifier="stowaway" spawnpointtag="triggerer_player" targettag="stowaway" />
                                      <SetDataAction identifier="stowaway2_complete" value="true" />
                                      <ConversationAction text="EventText.stowaway2.o1.o2.o1.o1.o1.c1" dialogtype="Regular" targettag="triggerer_player" />
                                      <!-- currently triggers immediately, bug?  -->
                                      <OnRoundEndAction>
                                        <CheckConditionalAction targettag="Stowaway" IsDead="False">
                                          <Success>
                                            <ReputationAction targettype="Location" increase="3" />
                                          </Success>
                                          <Failure></Failure>
                                        </CheckConditionalAction>
                                      </OnRoundEndAction>
                                    </Option>
                                    <Option text="EventText.stowaway2.o1.o2.o1.o1.o3">
                                      <SpawnAction npcsetidentifier="customnpcs1" npcidentifier="stowaway" spawnpointtag="triggerer_player" targettag="stowaway" />
                                      <SetDataAction identifier="stowaway2_complete" value="true" />
                                      <ConversationAction text="EventText.stowaway2.o1.o2.o1.o1.o3.c1" dialogtype="Regular" targettag="triggerer_player" />
                                      <NPCChangeTeamAction npctag="stowaway" teamid="Team1" addtocrew="true" />
                                    </Option>
                                  </ConversationAction>
                                </Option>
                              </ConversationAction>
                            </Option>
                            <Option text="EventText.stowaway2.o1.o2.o2" endconversation="true">
                              <GoTo name="stowawayreturn" />
                            </Option>
                          </ConversationAction>
                        </Option>
                        <Option text="EventText.stowaway2.o1.o2.o1">
                          <Goto name="whatamIgoingtodo" />
                        </Option>
                        <Option text="EventText.stowaway2.o1.o2.o2" endconversation="true">
                          <GoTo name="stowawayreturn" />
                        </Option>
                      </ConversationAction>
                    </Failure>
                  </CheckReputationAction>
                </Option>
                <Option text="EventText.generic.walkaway" endconversation="true">
                  <GoTo name="stowawayreturn" />
                </Option>
              </ConversationAction>
            </Failure>
          </CheckDataAction>
        </Success>
        <Failure>
          <!-- End -->
        </Failure>
      </CheckMissionAction>
    </ScriptedEvent>
    <ScriptedEvent identifier="stowaway2clownmission">
      <MissionAction missiontag="salvageclown" />
    </ScriptedEvent>
    <ScriptedEvent identifier="huskinfectiontest">
      <TagAction criteria="player" tag="player" />
      <AfflictionAction affliction="husktransformimmunity" strength="100" targettag="player" />
      <AfflictionAction affliction="huskinfection" strength="90" targettag="player" />
    </ScriptedEvent>
    <!-- Husk Encounter -->
    <!-- Unused. TODO: enable huskbeaconmission if devs allow spawning specific beacons. also move to missionevents /> -->
    <ScriptedEvent identifier="huskencounter">
      <TagAction criteria="player" tag="player" />
      <TagAction criteria="itemtag:oxygengenerator" tag="oxygengenerator" submarinetype="BeaconStation" />
      <SpawnAction npcsetidentifier="husknpcsmission" npcidentifier="beaconhuskresearcher" targettag="dormanthusk" spawnpointtag="huskencounter1" spawnlocation="BeaconStation" TeamID="FriendlyNPC" />
      <SpawnAction npcsetidentifier="husknpcsmission" npcidentifier="beaconhusk" targettag="dormanthusk" spawnpointtag="huskencounter2" spawnlocation="BeaconStation" TeamID="FriendlyNPC" />
      <SpawnAction npcsetidentifier="husknpcsmission" npcidentifier="beaconhusk" targettag="dormanthusk" spawnpointtag="huskencounter3" spawnlocation="BeaconStation" TeamID="FriendlyNPC" />
      <AfflictionAction affliction="husktransformimmunity" strength="100" targettag="dormanthusk" />
      <AfflictionAction affliction="huskinfection" strength="90" targettag="dormanthusk" />
      <Label name="oxygencheck" />
      <CheckConditionalAction targettag="oxygengenerator" targetitemcomponent="OxygenGenerator" LogicalOperator="And">
        <Conditional targetitemcomponent="OxygenGenerator" voltage="gt 0.5" />
        <Conditional condition="gt 0" />
        <Failure>
          <WaitAction time="1" />
          <AfflictionAction affliction="stun" strength="100" targettag="dormanthusk" />
          <Goto name="oxygencheck" />
        </Failure>
        <Success>
          <Waitaction time="3" />
          <ConversationAction text="EventText.beaconhusk.smell" dialogtype="Small" targettag="player" eventsprite="brokenmachinery" endconversation="true" continueautomatically="true" />
          <StatusEffectAction targettag="oxygengenerator">
            <StatusEffect target="This" duration="5">
              <ParticleEmitter particle="fixfoam" particlespersecond="3" velocitymin="20" velocitymax="50" anglemin="50" anglemax="130" scalemin="0.2" scalemax="0.4" Spread="50" distancemin="0" distancemax="50" colormultiplier="150,255,150,40" lifetimemultiplier="3" />
              <Sound file="Content/Items/Diving/ITEMS_divingSuitOxygenLeakLoop.ogg" range="800" loop="true" frequencymultiplier="0.5" volume="1" />
            </StatusEffect>
          </StatusEffectAction>
        </Success>
      </CheckConditionalAction>
      <!-- Remove and readd husk infection. Hacky way of putting husk affliction at 100, game is hardcoded to make affliction not go over 80 via SEs... -->
      <AfflictionAction affliction="huskinfection" strength="-100" targettag="dormanthusk" />
      <AfflictionAction affliction="husktransformimmunity" strength="-100" targettag="dormanthusk" />
      <WaitAction time="1" />
      <AfflictionAction affliction="huskinfection" strength="100" targettag="dormanthusk" />
      <TagAction criteria="humanprefabidentifier:beaconhusk" tag="turninghusk" />
      <StatusEffectAction targettag="turninghusk">
        <StatusEffect target="This" duration="20">
          <Affliction identifier="internaldamage" amount="5" />
        </StatusEffect>
      </StatusEffectAction>
      <TagAction criteria="humanprefabidentifier:beaconhuskresearcher" tag="dormanthuskresearcher" />
      <AfflictionAction affliction="husktransformimmunity" strength="100" targettag="dormanthuskresearcher" />
      <!-- check if any NPC is still human after being unstunned -->
      <Waitaction time="20" />
      <Label name="unstunned" />
      <CheckConditionalAction targettag="dormanthuskresearcher" IsHuman="true" LogicalOperator="And">
        <Conditional stun="lte 0" />
        <Success>
          <ConversationAction text="EventText.beaconhusk.savedresearcher" speakertag="dormanthuskresearcher" invokertag="talker_player" endeventifinterrupted="false" dialogtype="Small">
            <Option text="EventText.beaconhusk.whathappened">
              <ConversationAction text="EventText.beaconhusk.taintedgenes" targettag="talker_player">
                <Option text="EventText.beaconhusk.whynotransform">
                  <ConversationAction text="EventText.beaconhusk.explanation" targettag="talker_player">
                    <Option text="EventText.beaconhusk.sabotaged">
                      <ConversationAction text="EventText.beaconhusk.reward" endconversation="true" targettag="talker_player" />
                      <ReputationAction targettype="Faction" identifier="huskcult" increase="5" />
                    </Option>
                  </ConversationAction>
                </Option>
              </ConversationAction>
            </Option>
          </ConversationAction>
        </Success>
        <Failure>
          <!-- check if dead, if not loop -->
          <CheckConditionalAction targettag="dormanthuskresearcher" isdead="false">
            <Success>
              <Waitaction time="1" />
              <Goto name="unstunned" />
            </Success>
            <Failure>
              <!-- end event if dead -->
            </Failure>
          </CheckConditionalAction>
        </Failure>
      </CheckConditionalAction>
    </ScriptedEvent>
    <!-- Troubled Engine -->
    <ScriptedEvent identifier="troubledengine">
      <Label name="delay" />
      <WaitAction time="30" />
      <RNGAction chance="0.2">
        <Success>
          <GoTo name="start" />
        </Success>
        <Failure>
          <GoTo name="delay" />
        </Failure>
      </RNGAction>
      <Label name="start" />
      <TagAction criteria="itemtag:engine" tag="activeengine" submarinetype="player" />
      <TagAction criteria="itemidentifier:statusmonitor" tag="monitor" submarinetype="player" />
      <TagAction criteria="player" tag="player" />
      <TriggerAction target1tag="monitor" target2tag="player" applytotarget1="activemonitor" radius="2200" waitforinteraction="false" />
      <!-- drop engine condition, for 60 seconds -->
      <StatusEffectAction targettag="activeengine">
        <StatusEffect target="This" condition="-30" disabledeltatime="true">
          <Sound file="Content/Items/Door/DoorBreak1.ogg" range="500" volume="2" frequencymultiplier="0.5" />
        </StatusEffect>
        <StatusEffect target="This" condition="-2" duration="60" stackable="false">
          <ParticleEmitter particle="weldspark" particlespersecond="10" velocitymin="100" velocitymax="300" anglemin="-90" anglemax="90" scalemin="0.5" scalemax="1" Spread="50" distancemin="0" distancemax="100" colormultiplier="255,255,255,255" highqualitycollisiondetection="true" lifetimemultiplier="3" />
        </StatusEffect>
      </StatusEffectAction>
      <!-- monitor effects -->
      <StatusEffectAction targettag="activemonitor">
        <StatusEffect target="this" duration="20" noninteractable="false">
          <Sound file="Content/Items/WarningBeepSlow.ogg" range="500" volume="0.5" loop="true" />
          <ParticleEmitter particle="impactfirearm" particlespersecond="1" velocitymin="0" velocitymax="0" anglemin="0" anglemax="0" scalemin="0.5" scalemax="0.5" distancemin="0" distancemax="0" colormultiplier="255,0,0,255" lifetimemultiplier="2" />
        </StatusEffect>
      </StatusEffectAction>
      <TriggerAction target1tag="activemonitor" target2tag="player" applytotarget2="monitorchecker" radius="200" waitforinteraction="true" />
      <ConversationAction targettag="monitorchecker" text="eventtext.troubledengine.monitor" dialogtype="Small" eventsprite="malfunction" endconversation="true" />
      <Label name="restart" />
      <ClearTagAction tag="te_player" />
      <TriggerAction target1tag="activeengine" target2tag="player" applytotarget2="te_player" radius="300" waitforinteraction="true" />
      <ConversationAction targettag="te_player" text="eventtext.troubledengine.engine" eventsprite="officeinside">
        <Option text="eventtext.option.smack">
          <!-- if success, cancel out the engine decay, if failure either try again or drop a scrap and wait -->
          <SkillCheckAction requiredskill="Mechanical" requiredlevel="55" targettag="te_player">
            <Success>
              <StatusEffectAction targettag="activeengine">
                <StatusEffect target="This" condition="2" duration="60" stackable="false">
                  <Sound file="Content/Sounds/Impact/MetalImpactHeavy2.ogg" range="500" />
                </StatusEffect>
              </StatusEffectAction>
              <GiveSkillEXPAction skill="mechanical" amount="2" targettag="triggerer_player" />
              <ConversationAction targettag="te_player" text="eventtext.troubledengine.engine.success" eventsprite="officeinside" endconversation="true" />
            </Success>
            <Failure>
              <RNGAction chance="0.5">
                <Success>
                  <ConversationAction targettag="te_player" text="eventtext.troubledengine.engine.failure" endconversation="true" eventsprite="officeinside" />
                  <WaitAction time="1" />
                  <GoTo name="restart" />
                </Success>
                <Failure>
                  <AfflictionAction affliction="lacerations" strength="5" limbtype="LeftHand" targettag="te_player" />
                  <AfflictionAction affliction="stun" strength="0.5" targettag="te_player" />
                  <SpawnAction itemidentifier="scrap" spawnpointtag="activeengine" />
                  <StatusEffectAction targettag="activeengine">
                    <StatusEffect target="this" condition="-25" disabledeltatime="true">
                      <Sound file="Content/Sounds/Impact/MetalImpactHeavy2.ogg" range="500" />
                      <Sound file="Content/Items/MechanicalRepairFail.ogg" range="500" />
                    </StatusEffect>
                  </StatusEffectAction>
                  <ConversationAction targettag="te_player" text="eventtext.troubledengine.engine.smack.failure" endconversation="true" eventsprite="officeinside" />
                </Failure>
              </RNGAction>
            </Failure>
          </SkillCheckAction>
        </Option>
        <Option text="eventtext.option.dontbother" endconversation="true">
          <GoTo name="restart" />
        </Option>
      </ConversationAction>
    </ScriptedEvent>
    <!-- Reactor Malfunction -->
    <ScriptedEvent identifier="reactormalfunction">
      <Label name="delay" />
      <WaitAction time="30" />
      <RNGAction chance="0.2">
        <Success>
          <GoTo name="start" />
        </Success>
        <Failure>
          <GoTo name="delay" />
        </Failure>
      </RNGAction>
      <Label name="start" />
      <TagAction criteria="itemtag:reactor" tag="activereactor" submarinetype="player" />
      <TagAction criteria="itemidentifier:statusmonitor" tag="monitor" submarinetype="player" />
      <TagAction criteria="player" tag="player" ContinueIfNoTargetsFound="true" />
      <TriggerAction target1tag="monitor" target2tag="player" applytotarget1="activemonitor" radius="2200" waitforinteraction="false" />
      <!-- first trigger of effects, just a taste -->
      <StatusEffectAction targettag="activereactor">
        <StatusEffect target="This" AutoTemp="false">
          <ParticleEmitter particle="weldspark" particlespersecond="2" velocitymin="150" velocitymax="300" anglemin="0" anglemax="180" scalemin="0.5" scalemax="1" Spread="50" distancemin="0" distancemax="100" colormultiplier="255,255,255,255" highqualitycollisiondetection="true" lifetimemultiplier="3" />
          <Sound file="Content/Items/Electricity/zap3.ogg" range="500" loop="false" />
        </StatusEffect>
      </StatusEffectAction>
      <!-- monitor effects -->
      <StatusEffectAction targettag="activemonitor">
        <StatusEffect target="this" duration="20" noninteractable="false">
          <Sound file="Content/Items/WarningBeepSlow.ogg" range="500" volume="0.5" loop="true" />
          <ParticleEmitter particle="impactfirearm" particlespersecond="1" velocitymin="0" velocitymax="0" anglemin="0" anglemax="0" scalemin="0.5" scalemax="0.5" distancemin="0" distancemax="0" colormultiplier="255,0,0,255" lifetimemultiplier="2" />
        </StatusEffect>
      </StatusEffectAction>
      <TriggerAction target1tag="activemonitor" target2tag="player" applytotarget2="monitorchecker" waitforinteraction="true" />
      <ConversationAction targettag="monitorchecker" text="eventtext.reactormalfunction.monitor" endconversation="true" eventsprite="malfunction" dialogtype="Small" />
      <TriggerAction target1tag="activereactor" target2tag="player" applytotarget2="rm_player" radius="300" waitforinteraction="true" />
      <StatusEffectAction targettag="activereactor">
        <StatusEffect target="This" AutoTemp="false" duration="120" stackable="false">
          <ParticleEmitter particle="weldspark" particlespersecond="2" velocitymin="150" velocitymax="300" anglemin="0" anglemax="180" scalemin="0.5" scalemax="1" Spread="50" distancemin="0" distancemax="100" colormultiplier="255,255,255,255" highqualitycollisiondetection="true" lifetimemultiplier="3" />
          <Sound file="Content/Items/Electricity/zap3.ogg" range="500" loop="false" />
        </StatusEffect>
      </StatusEffectAction>
      <ConversationAction targettag="rm_player" text="eventtext.reactormalfunction.reactor" endconversation="true" continueautomatically="true" eventsprite="officeinside" dialogtype="Small" />
      <WaitAction time="120" />
      <ClearTagAction tag="rm_player" />
      <StatusEffectAction targettag="activereactor">
        <StatusEffect target="This">
          <ParticleEmitter particle="heavysmoke" particleamount="3" velocitymin="0" velocitymax="0" anglemin="70" anglemax="110" scalemin="2" scalemax="3" Spread="50" distancemin="0" distancemax="100" colormultiplier="255,255,255,255" highqualitycollisiondetection="true" lifetimemultiplier="3" />
          <Sound file="Content/Items/Door/duct2.ogg" range="500" volume="2" frequencymultiplier="0.5" loop="false" />
        </StatusEffect>
      </StatusEffectAction>
      <TriggerAction target1tag="activereactor" target2tag="player" applytotarget2="rm_player" radius="300" waitforinteraction="true" />
      <ConversationAction targettag="rm_player" text="eventtext.reactormalfunction.backtonormal" continueautomatically="true" endconversation="true" eventsprite="officeinside" dialogtype="Small" />
    </ScriptedEvent>
    <!-- Oxygen generator leak -->
    <ScriptedEvent identifier="oxygenfluidleak">
      <Label name="delay" />
      <WaitAction time="30" />
      <RNGAction chance="0.2">
        <Success>
          <GoTo name="start" />
        </Success>
        <Failure>
          <GoTo name="delay" />
        </Failure>
      </RNGAction>
      <Label name="start" />
      <TagAction criteria="itemtag:oxygengenerator" tag="activeoxygengenerator" submarinetype="player" />
      <TagAction criteria="itemidentifier:statusmonitor" tag="monitor" submarinetype="player" />
      <TagAction criteria="player" tag="player" ContinueIfNoTargetsFound="true" />
      <TriggerAction target1tag="monitor" target2tag="player" applytotarget1="activemonitor" radius="2200" waitforinteraction="false" />
      <!-- first trigger of effects, just a taste -->
      <StatusEffectAction targettag="activeoxygengenerator">
        <StatusEffect target="This" duration="10">
          <ParticleEmitter particle="weldspark" particlespersecond="2" velocitymin="150" velocitymax="300" anglemin="0" anglemax="180" scalemin="0.5" scalemax="1" Spread="50" distancemin="0" distancemax="100" colormultiplier="255,255,255,255" highqualitycollisiondetection="true" lifetimemultiplier="3" />
          <ParticleEmitter particle="heavysmoke" particlespersecond="2" velocitymin="20" velocitymax="50" anglemin="50" anglemax="130" scalemin="2" scalemax="3" Spread="50" distancemin="0" distancemax="50" colormultiplier="150,255,150,255" lifetimemultiplier="3" />
          <Sound file="Content/Items/MechanicalRepairFail.ogg" range="800" loop="false" frequencymultiplier="0.5" />
        </StatusEffect>
      </StatusEffectAction>
      <WaitAction time="10" />
      <!-- gas loop -->
      <TriggerEventAction identifier="oxygenfluidleakloopevent" />
      <!-- monitor effects -->
      <StatusEffectAction targettag="activemonitor">
        <StatusEffect target="this" duration="20" noninteractable="false">
          <Sound file="Content/Items/WarningBeepSlow.ogg" range="500" volume="0.5" loop="true" />
          <ParticleEmitter particle="impactfirearm" particlespersecond="1" velocitymin="0" velocitymax="0" anglemin="0" anglemax="0" scalemin="0.5" scalemax="0.5" distancemin="-2" distancemax="2" colormultiplier="255,0,0,255" lifetimemultiplier="2" Spread="50" />
        </StatusEffect>
      </StatusEffectAction>
      <StatusEffectAction targettag="activeoxygengenerator">
        <StatusEffect target="This" duration="150" stackable="false">
          <ParticleEmitter particle="weldspark" particlespersecond="2" velocitymin="150" velocitymax="300" anglemin="0" anglemax="180" scalemin="0.5" scalemax="1" Spread="50" distancemin="0" distancemax="100" colormultiplier="255,255,255,255" highqualitycollisiondetection="true" lifetimemultiplier="3" />
          <ParticleEmitter particle="heavysmoke" particlespersecond="2" velocitymin="20" velocitymax="50" anglemin="70" anglemax="110" scalemin="2" scalemax="3" Spread="50" distancemin="0" distancemax="30" colormultiplier="255,255,255,255" lifetimemultiplier="3" />
          <Sound file="Content/Items/Electricity/zap3.ogg" range="500" loop="false" />
        </StatusEffect>
      </StatusEffectAction>
      <TriggerAction target1tag="activemonitor" target2tag="player" applytotarget2="monitorchecker" waitforinteraction="true" />
      <ConversationAction targettag="monitorchecker" text="eventtext.oxygenfluidleak.monitor" endconversation="true" eventsprite="malfunction" />
      <Label name="repairgenerator" />
      <ClearTagAction tag="ofl_player" />
      <TriggerAction target1tag="activeoxygengenerator" target2tag="player" applytotarget2="ofl_player" radius="300" waitforinteraction="true" />
      <CheckDataAction identifier="oxygenfluidleakloopcount" condition="gte 30">
        <Success>
          <!-- do nothing if too much time passed -->
          <ConversationAction targettag="ofl_player" text="eventtext.oxygenfluidleak.toolate" eventsprite="officeinside" endconversation="true" />
        </Success>
        <Failure>
          <ConversationAction targettag="ofl_player" text="eventtext.oxygenfluidleak.leakyscrubber" eventsprite="officeinside">
            <Option text="EventText.generic.continue">
              <ConversationAction targettag="ofl_player" text="eventtext.oxygenfluidleak.waitorpurge" eventsprite="officeinside">
                <Option text="eventtext.oxygenfluidleak.purgeoption">
                  <SkillCheckAction requiredskill="Mechanic" requiredlevel="55" targettag="ofl_player">
                    <Success>
                      <ConversationAction targettag="ofl_player" text="eventtext.oxygenfluidleak.goodpurge" eventsprite="officeinside" endconversation="true" />
                      <SetDataAction identifier="oxygenfluidleakloopcount" operation="set" value="31" />
                      <TagAction criteria="itemtag:vent" tag="allvents" submarinetype="player" />
                      <StatusEffectAction targettag="allvents">
                        <StatusEffect target="This">
                          <ParticleEmitter particle="heavysmoke" particleamount="5" velocitymin="20" velocitymax="50" anglemin="50" anglemax="130" scalemin="0.5" scalemax="1" Spread="50" distancemin="0" distancemax="50" colormultiplier="255,255,255,255" lifetimemultiplier="3" />
                          <SpawnItem identifiers="ventleakcloud" spawnposition="This" />
                        </StatusEffect>
                      </StatusEffectAction>
                      <StatusEffectAction targettag="activeoxygengenerator" condition="-20" disabledeltatime="true" forceplaysounds="true">
                        <StatusEffect target="This">
                          <Sound file="Content/Items/Warningbeep.ogg" range="800.0" />
                          <Sound file="Content/Items/Reactor/ReactorTemperatureBoostUp.ogg" range="800.0" frequencymultiplier="0.5" />
                        </StatusEffect>
                      </StatusEffectAction>
                      <GiveSkillEXPAction skill="mechanical" amount="2" targettag="ofl_player" />
                    </Success>
                    <Failure>
                      <ConversationAction targettag="ofl_player" text="eventtext.oxygenfluidleak.badpurge" eventsprite="officeinside" endconversation="true" />
                      <SetDataAction identifier="oxygenfluidleakloopcount" operation="set" value="31" />
                      <TagAction criteria="itemtag:vent" tag="allvents" submarinetype="player" />
                      <StatusEffectAction targettag="allvents">
                        <StatusEffect target="This">
                          <ParticleEmitter particle="heavysmoke" particleamount="5" velocitymin="20" velocitymax="50" anglemin="50" anglemax="130" scalemin="0.5" scalemax="1" Spread="50" distancemin="0" distancemax="50" colormultiplier="255,255,255,255" lifetimemultiplier="3" />
                          <SpawnItem identifiers="ventleakcloud" spawnposition="This" />
                        </StatusEffect>
                      </StatusEffectAction>
                      <StatusEffectAction targettag="activeoxygengenerator">
                        <StatusEffect target="This" condition="-80" disabledeltatime="true" forceplaysounds="true">
                          <ParticleEmitter particle="spark" particleamount="20" velocitymin="150" velocitymax="300" anglemin="0" anglemax="180" scalemin="0.5" scalemax="1" Spread="50" distancemin="0" distancemax="100" colormultiplier="255,255,255,255" highqualitycollisiondetection="true" lifetimemultiplier="3" />
                          <Sound file="Content/Items/Warningbeep.ogg" range="800.0" />
                          <Sound file="Content/Items/Reactor/ReactorTemperatureBoostUp.ogg" range="800.0" frequencymultiplier="0.5" />
                        </StatusEffect>
                      </StatusEffectAction>
                      <SpawnAction itemidentifier="ventleakcloud" spawnpointtag="activeoxygengenerator" />
                      <GiveSkillEXPAction skill="mechanical" amount="2" targettag="ofl_player" />
                    </Failure>
                  </SkillCheckAction>
                </Option>
                <Option text="EventText.oxygenfluidleak.waititout" endconversation="true"></Option>
                <Option text="eventtext.option.dontbother">
                  <WaitAction time="1" />
                  <GoTo name="repairgenerator" />
                </Option>
              </ConversationAction>
            </Option>
            <Option text="EventText.option.ignore">
              <WaitAction time="1" />
              <GoTo name="repairgenerator" />
            </Option>
          </ConversationAction>
        </Failure>
      </CheckDataAction>
    </ScriptedEvent>
    <ScriptedEvent identifier="oxygenfluidleakloopevent">
      <SetDataAction identifier="oxygenfluidleakloopcount" operation="set" value="0" />
      <Label name="pickavent" />
      <ClearTagAction tag="selectedvent" />
      <TagAction criteria="itemtag:vent" tag="selectedvent" submarinetype="player" chooserandom="true" choosepercentage="1" />
      <CheckConditionalAction targettag="selectedvent">
        <Conditional OxygenFlow="gt 10" targetitemcomponent="Vent" />
        <Success>
          <StatusEffectAction targettag="selectedvent">
            <StatusEffect target="This">
              <ParticleEmitter particle="heavysmoke" particleamount="5" velocitymin="20" velocitymax="50" anglemin="50" anglemax="130" scalemin="0.5" scalemax="1" Spread="50" distancemin="0" distancemax="50" colormultiplier="255,255,255,255" lifetimemultiplier="3" />
              <Sound file="Content/Items/Electricity/zap3.ogg" range="500" loop="false" />
              <SpawnItem identifiers="ventleakcloud" spawnposition="This" />
            </StatusEffect>
          </StatusEffectAction>
          <SetDataAction identifier="oxygenfluidleakloopcount" operation="add" value="1" />
        </Success>
        <Failure></Failure>
      </CheckConditionalAction>
      <WaitAction time="5" />
      <CheckDataAction identifier="oxygenfluidleakloopcount" condition="gte 30">
        <Success>
          <!-- end -->
        </Success>
        <Failure>
          <Goto name="pickavent" />
        </Failure>
      </CheckDataAction>
      <Label name="end" />
    </ScriptedEvent>
    <!-- jams your headsets if you activate the beacon -->
    <ScriptedEvent identifier="beaconcommsjam">
      <TagAction criteria="player" tag="player" />
      <TagAction criteria="itemtag:sonarmonitor" tag="beaconmonitor" submarinetype="BeaconStation" />
      <TagAction criteria="itemtag:mobileradio" tag="mobileradio" />
      <Label name="beaconactivecheck1" />
      <CheckConditionalAction targettag="beaconmonitor" targetitemcomponent="Sonar" LogicalOperator="And">
        <Conditional targetitemcomponent="Sonar" voltage="gt 0.5" />
        <Conditional targetitemcomponent="Sonar" CurrentMode="Active" />
        <Success>
          <ConversationAction text="EventText.beaconcommsjam.jammed" dialogtype="Small" targettag="player" eventsprite="brokenmachinery" endconversation="true" continueautomatically="true" />
          <Goto name="beaconactivecheck2" />
        </Success>
        <Failure>
          <WaitAction time="1" />
          <Goto name="beaconactivecheck1" />
        </Failure>
      </CheckConditionalAction>
      <Label name="beaconactivecheck2" />
      <CheckConditionalAction targettag="beaconmonitor" targetitemcomponent="Sonar" LogicalOperator="And">
        <Conditional targetitemcomponent="Sonar" voltage="gt 0.5" />
        <Conditional targetitemcomponent="Sonar" CurrentMode="Active" />
        <Success>
          <StatusEffectAction targettag="mobileradio">
            <StatusEffect target="This" JamTimer="1.5" setvalue="true" forceplaysounds="true" />
          </StatusEffectAction>
          <WaitAction time="1" />
          <Goto name="beaconactivecheck2" />
        </Success>
        <Failure>
          <WaitAction time="1" />
          <Goto name="beaconactivecheck2" />
        </Failure>
      </CheckConditionalAction>
    </ScriptedEvent>
    <!-- UNUSED prototype would spawn a mission when getting in range of the "patrol spawner" item -->
    <!-- <ScriptedEvent identifier="militarypatrol">
      <MissionAction missiontag="militarypatrol" />
    </ScriptedEvent> -->
  </EventPrefabs>
  <!-- SPAWNS WASTEYARD ENEMIES WITH BIG COMMONNESS -->
  <EventSet identifier="Wasteyard" biome="hydrothermalwastes" chooserandom="false" allowatstart="true" campaign="true">
    <Commonness commonness="0">
      <Override leveltype="wastesgraveyard" commonness="100000" />
    </Commonness>
    <!--10% or 2 min-->
    <EventSet identifier="first" chooserandom="true" mindistancetraveled="0.10" minmissiontime="120" minintensity="0.0" maxintensity="0.8">
      <EventSet identifier="wastecrawlers" chooserandom="false">
        <MonsterEvent characterfile="De-wastecrawler" minamount="7" maxamount="9" spawntype="mainpath,sidepath" />
      </EventSet>
      <EventSet identifier="wastehammerheads" chooserandom="false">
        <MonsterEvent characterfile="De-wastehammerhead" minamount="2" maxamount="3" spawntype="mainpath,sidepath" />
      </EventSet>
    </EventSet>
    <!--30% or 5 min-->
    <EventSet identifier="second" chooserandom="true" mindistancetraveled="0.30" minmissiontime="300" minintensity="0.0" maxintensity="0.8">
      <EventSet identifier="wastecrawlers" chooserandom="false">
        <MonsterEvent characterfile="De-wastecrawler" minamount="8" maxamount="10" spawntype="mainpath,sidepath" />
      </EventSet>
      <EventSet identifier="wastehammerheads" chooserandom="false">
        <MonsterEvent characterfile="De-wastehammerhead" minamount="3" maxamount="4" spawntype="mainpath,sidepath" />
      </EventSet>
    </EventSet>
    <!--50% or 20 min-->
    <EventSet identifier="third" chooserandom="true" mindistancetraveled="0.50" minmissiontime="1200" minintensity="0.0" maxintensity="0.8">
      <EventSet identifier="wastecrawlers" chooserandom="false">
        <MonsterEvent characterfile="De-wastecrawler" minamount="9" maxamount="11" spawntype="mainpath,sidepath" />
      </EventSet>
      <EventSet identifier="wastehammerheads" chooserandom="false">
        <MonsterEvent characterfile="De-wastehammerhead" minamount="4" maxamount="5" spawntype="mainpath,sidepath" />
      </EventSet>
    </EventSet>
    <!--80%-->
    <EventSet identifier="fourth" chooserandom="true" mindistancetraveled="0.80" minmissiontime="100000" minintensity="0.0" maxintensity="0.8">
      <EventSet identifier="wastecrawlers" chooserandom="false">
        <MonsterEvent characterfile="De-wastecrawler" minamount="10" maxamount="12" spawntype="mainpath,sidepath" />
      </EventSet>
      <EventSet identifier="wastehammerheads" chooserandom="false">
        <MonsterEvent characterfile="De-wastehammerhead" minamount="5" maxamount="6" spawntype="mainpath,sidepath" />
      </EventSet>
    </EventSet>
  </EventSet>
  <!--   UNUSED - can't match an eventset to a specific mission (to spawn the right creatures) unless we have different locations for each lair
  also mainpath/nearmainsub/abyss spawns arent great -->
  <!--   <EventSet identifier="laircrawlersoutside" leveltype="outpost" locationtype="lair" allowatstart="true" minleveldifficulty="0" maxleveldifficulty="100" ignorecooldown="true"  campaign="true" chooserandom="false" commonness="100" >
    <EventSet identifier="first" minmissiontime="10" >
      <MonsterEvent characterfile="mudraptor" minamount="1" maxamount="2" spawntype="mainpath" /> 
    </EventSet>
    <EventSet identifier="second" minmissiontime="20" >
      <MonsterEvent characterfile="crawler" minamount="1" maxamount="2" spawntype="mainpath" /> 
    </EventSet>
    <EventSet identifier="third" minmissiontime="30" >
      <MonsterEvent characterfile="crawler" minamount="1" maxamount="2" spawntype="mainpath" /> 
    </EventSet>
  </EventSet> -->
</Randomevents>