<?xml version="1.0" encoding="utf-8"?>
<Override>
  <Randomevents>
    <EventPrefabs>
      <!-- added Base as potential location -->
      <ScriptedEvent identifier="missionevent_jailbreak_coalition" commonness="80">
        <CheckReputationAction targettype="faction" identifier="coalition" condition="gte 30">
          <Failure>
            <!-- Do nothing -->
          </Failure>
          <Success>
            <ConversationAction text="EventText.missionevent_jailbreak_coalition.c1" speakertag="outpostmanager" invokertag="triggerer_player" endeventifinterrupted="false" eventsprite="Coalition">
              <Option text="EventText.missionevent.pleasecontinue">
                <!-- "please continue" -->
                <ConversationAction text="EventText.missionevent_jailbreak_coalition.o1.c1" targettag="triggerer_player" endeventifinterrupted="false" eventsprite="Coalition" endconversation="true" />
                <MissionAction missionidentifier="jailbreak_coalition" locationtype="Colony,City,Base,Military" requiredfaction="separatists" minlocationdistance="1" />
              </Option>
            </ConversationAction>
          </Success>
        </CheckReputationAction>
      </ScriptedEvent>
      <!-- added Base as potential location -->
      <ScriptedEvent identifier="missionevent_jailbreak_separatists" commonness="80">
        <CheckReputationAction targettype="faction" identifier="separatists" condition="gte 30">
          <Failure>
            <!-- Do nothing -->
          </Failure>
          <Success>
            <ConversationAction text="EventText.missionevent_jailbreak_separatists.c1" speakertag="outpostmanager" invokertag="triggerer_player" endeventifinterrupted="false" eventsprite="Stuckinthemiddle1">
              <Option text="EventText.missionevent.pleasecontinue">
                <!-- "please continue" -->
                <ConversationAction text="EventText.missionevent_jailbreak_separatists.o1.c1" targettag="triggerer_player" endeventifinterrupted="false" eventsprite="Separatists" endconversation="true" />
                <MissionAction missionidentifier="jailbreak_separatists" locationtype="Colony,City,Base,Military" requiredfaction="coalition" minlocationdistance="1" />
              </Option>
            </ConversationAction>
          </Success>
        </CheckReputationAction>
      </ScriptedEvent>
      <ScriptedEvent identifier="missionevent_jailbreak_sootman" commonness="80">
        <CheckReputationAction targettype="faction" identifier="separatists" condition="gte 50">
          <Failure>
            <!-- Do nothing -->
          </Failure>
          <Success>
            <CheckDataAction identifier="jailbreak_sootman_unlocked" condition="eq true">
              <Success>
                <!-- do nothing -->
              </Success>
              <Failure>
                <ConversationAction text="EventText.missionevent_jailbreak_sootman.c1" speakertag="outpostmanager" invokertag="triggerer_player" endeventifinterrupted="false" eventsprite="Stuckinthemiddle1">
                  <Option text="EventText.missionevent_tormsdalereport.whosthat">
                    <!-- who's that? -->
                    <ConversationAction text="EventText.missionevent_tormsdalereport.whospetran" targettag="triggerer_player" endeventifinterrupted="false" eventsprite="Separatists">
                      <Option text="EventText.missionevent_tormsdalereport.o1.o1">
                        <!-- ok, what's the mission -->
                        <Goto name="givemission" />
                      </Option>
                    </ConversationAction>
                  </Option>
                  <Option text="EventText.missionevent.pleasecontinue">
                    <!-- we're interested -->
                    <Goto name="givemission" />
                  </Option>
                </ConversationAction>
                <Label name="givemission" />
                <ConversationAction text="EventText.missionevent_jailbreak_sootman.c1.c1" targettag="triggerer_player" endeventifinterrupted="false" eventsprite="Stuckinthemiddle1">
                  <Option text="EventText.missionevent_jailbreak_sootman.c1.o1">
                    <ConversationAction text="EventText.missionevent_jailbreak_sootman.c1.o1.c1" targettag="triggerer_player" endeventifinterrupted="false" eventsprite="Stuckinthemiddle1" />
                    <MissionAction missionidentifier="jailbreak_sootman" locationtype="Colony,City,Base,Military" requiredfaction="coalition" minlocationdistance="1" CreateLocationIfNotFound="true" />
                    <SetDataAction identifier="jailbreak_sootman_unlocked" value="true" />
                  </Option>
                </ConversationAction>
              </Failure>
            </CheckDataAction>
          </Success>
        </CheckReputationAction>
      </ScriptedEvent>
      <!-- changed viable locations for the mission -->
      <ScriptedEvent identifier="missionevent_tormsdalereport" commonness="80">
        <CheckReputationAction targettype="faction" identifier="separatists" condition="gte 30">
          <Failure>
            <!-- Do nothing -->
          </Failure>
          <Success>
            <CheckDataAction identifier="tormsdalereport" condition="eq 0">
              <Failure>
                <!-- do nothing -->
              </Failure>
              <Success>
                <ConversationAction text="EventText.missionevent_tormsdalereport.c1" speakertag="outpostmanager" invokertag="triggerer_player" endeventifinterrupted="false" eventsprite="Stuckinthemiddle1">
                  <Option text="EventText.missionevent_tormsdalereport.whosthat">
                    <ConversationAction text="EventText.missionevent_tormsdalereport.whospetran" targettag="triggerer_player" endeventifinterrupted="false" eventsprite="Stuckinthemiddle1">
                      <Option text="EventText.missionevent_tormsdalereport.o1.o1">
                        <Goto name="givemission" />
                      </Option>
                    </ConversationAction>
                  </Option>
                  <Option text="EventText.missionevent.pleasecontinue">
                    <Goto name="givemission" />
                  </Option>
                </ConversationAction>
                <Label name="givemission" />
                <ConversationAction text="EventText.missionevent_tormsdalereport.c1.c1" targettag="triggerer_player" endeventifinterrupted="false" eventsprite="Stuckinthemiddle1">
                  <Option text="EventText.missionevent_tormsdalereport.c1.o1">
                    <ConversationAction text="EventText.missionevent_tormsdalereport.c1.o1.c1" targettag="triggerer_player" endeventifinterrupted="false" eventsprite="Separatists">
                      <Option text="EventText.missionevent_tormsdalereport.c1.o1.o1">
                        <ConversationAction text="EventText.missionevent_tormsdalereport.c1.o1.o1.c1" targettag="triggerer_player" endeventifinterrupted="false" eventsprite="Separatists">
                          <Option text="EventText.missionevent_tormsdalereport.c1.o1.o1.o1">
                            <ConversationAction text="EventText.missionevent_tormsdalereport.c1.o1.o1.o1.c1" targettag="triggerer_player" endeventifinterrupted="false" eventsprite="Separatists">
                              <Option text="EventText.missionevent_tormsdalereport.c1.o1.o1.o1.o1">
                                <ConversationAction text="EventText.missionevent_tormsdalereport.c1.o1.o1.o1.o1.c1" targettag="triggerer_player" endeventifinterrupted="false" eventsprite="Separatists">
                                  <Option text="EventText.missionevent_tormsdalereport.c1.o1.o1.o1.o1.o1">
                                    <ConversationAction text="EventText.missionevent_tormsdalereport.c1.o1.o1.o1.o1.o1.c1" targettag="triggerer_player" endeventifinterrupted="false" eventsprite="Separatists" endconversation="true" />
                                    <MissionAction missionidentifier="tormsdalereport" locationtype="outpost,settlement,colony,city,camp,base,military,blockade,study,research,clinic,hospital,hydroponics,factory,shipyard" requiredfaction="coalition" minlocationdistance="2" CreateLocationIfNotFound="true" />
                                    <SetDataAction identifier="tormsdalereport" value="1" />
                                  </Option>
                                </ConversationAction>
                              </Option>
                            </ConversationAction>
                          </Option>
                        </ConversationAction>
                      </Option>
                    </ConversationAction>
                  </Option>
                </ConversationAction>
              </Success>
            </CheckDataAction>
          </Success>
        </CheckReputationAction>
      </ScriptedEvent>
      <ScriptedEvent identifier="waytoascension3">
        <CheckDataAction identifier="subraevent_state" condition="lt 3">
          <Failure>
            <!-- cannot continue the way to ascension if Subra has been assassinated (see assassinationofjacovsubra4) -->
          </Failure>
          <Success>
            <CheckDataAction identifier="waytoascension" condition="eq 4">
              <Failure>
                <!-- do nothing -->
              </Failure>
              <Success>
                <TagAction criteria="player" tag="player" />
                <SpawnAction npcsetidentifier="outpostnpcs1" npcidentifier="huskcultecclesiast" targettag="ecclesiast" spawnlocation="Outpost" targetmoduletags="huskmodule" />
                <TriggerAction target1tag="player" target2tag="ecclesiast" applytotarget1="triggerer_player" waitforinteraction="true" />
                <NPCFollowAction npctag="ecclesiast" targettag="triggerer_player" follow="true" />
                <ConversationAction targettag="triggerer_player" text="EventText.waytoascension3.c1" eventsprite="Ecclesiast">
                  <Option text="EventText.waytoascension3.o1">
                    <ConversationAction targettag="triggerer_player" text="EventText.waytoascension3.o1.c1" eventsprite="Ecclesiast">
                      <Option text="EventText.waytoascension3.o1.o1">
                        <GoTo name="givemission" />
                      </Option>
                      <Option text="EventText.waytoascension3.o1.o2">
                        <ConversationAction targettag="triggerer_player" text="EventText.waytoascension3.o1.o2.c1" eventsprite="Ecclesiast">
                          <Option text="EventText.waytoascension3.o1.o2.o1">
                            <Label name="givemission" />
                            <ConversationAction targettag="triggerer_player" text="EventText.waytoascension3.o1.o2.o1.c1" eventsprite="Ecclesiast" endconversation="true" />
                            <MissionAction missionidentifier="huskcultspecialassassinate" minlocationdistance="2" requiredfaction="coalition" locationtype="outpost,settlement,colony,city,camp,base,military,blockade,study,research,clinic,hospital,hydroponics,factory,shipyard" CreateLocationIfNotFound="true" />
                            <SetDataAction identifier="waytoascension" value="5" />
                          </Option>
                        </ConversationAction>
                      </Option>
                    </ConversationAction>
                  </Option>
                </ConversationAction>
              </Success>
            </CheckDataAction>
            <NPCFollowAction npctag="ecclesiast" targettag="triggerer_player" follow="false" />
          </Success>
        </CheckDataAction>
      </ScriptedEvent>
      <!-- overriding to make the spawning in our custom modules easier + no repeat -->
      <ScriptedEvent identifier="malfunctioningdefensebot" commonness="100">
        <CheckDataAction identifier="malfunctioningdefensebotnorepeat" condition="eq 0">
          <Failure>
            <Goto name="end" />
          </Failure>
        </CheckDataAction>
        <TagAction criteria="player" tag="player" />
        <SpawnAction speciesname="Defensebot" targettag="scrapbot" spawnlocation="Outpost" targetmoduletags="ProductionFactory,ProductionShipyard" />
        <SpawnAction itemidentifier="defensebotammobox" amount="1" targetinventory="scrapbot" SpawnIfInventoryFull="false" ContinueIfFailedToSpawn="true" />
        <StatusEffectAction targettag="scrapbot">
          <StatusEffect target="This" IsDead="true" setvalue="true" />
        </StatusEffectAction>
        <Label name="restart" />
        <ClearTagAction tag="triggerer_player" />
        <TriggerAction target1tag="scrapbot" target2tag="player" applytotarget2="triggerer_player" radius="100" waitforinteraction="true" DisableIfTargetIncapacitated="false" />
        <SetDataAction identifier="malfunctioningdefensebotnorepeat" operation="set" value="1" />
        <ConversationAction text="EventText.malfunctioningdefensebot.c1" targettag="triggerer_player" eventsprite="brokenmachinery">
          <Option text="EventText.malfunctioningdefensebot.o1">
            <SkillCheckAction requiredskill="Mechanical" requiredlevel="60" targettag="triggerer_player">
              <Success>
                <ConversationAction text="EventText.malfunctioningdefensebot.o1.c1" targettag="triggerer_player" eventsprite="brokenmachinery">
                  <Option text="EventText.malfunctioningdefensebot.o1.c1.o1">
                    <SkillCheckAction requiredskill="Electrical" requiredlevel="40" targettag="triggerer_player">
                      <Success>
                        <ConversationAction text="EventText.malfunctioningdefensebot.o1.c1.o1.c1" targettag="triggerer_player" eventsprite="brokenmachinery" endconversation="true"></ConversationAction>
                        <!-- Revive it -->
                        <StatusEffectAction targettag="scrapbot">
                          <StatusEffect target="This" IsDead="false" setvalue="true">
                            <Sound file="Content/Characters/Defensebot/DEFENCEBOT_interact1.ogg" range="100" />
                          </StatusEffect>
                        </StatusEffectAction>
                        <!-- 'Petting' (playing with) them makes them join the crew automatically -->
                      </Success>
                      <Failure>
                        <ConversationAction text="EventText.malfunctioningdefensebot.o1.c1.o1.c2" targettag="triggerer_player" eventsprite="brokenmachinery" endconversation="true"></ConversationAction>
                        <!-- Revive it-->
                        <StatusEffectAction targettag="scrapbot">
                          <StatusEffect target="This" IsDead="false" setvalue="true">
                            <Sound file="Content/Characters/Defensebot/DEFENCEBOT_interact3.ogg" range="100" />
                          </StatusEffect>
                        </StatusEffectAction>
                        <!-- Turn hostile -->
                        <NPCChangeTeamAction npctag="scrapbot" teamid="Team2" />
                      </Failure>
                    </SkillCheckAction>
                  </Option>
                  <Option text="EventText.malfunctioningdefensebot.o1.c1.o2" endconversation="true">
                    <!-- Revive it -->
                    <StatusEffectAction targettag="scrapbot">
                      <StatusEffect target="This" IsDead="false" setvalue="true">
                        <Sound file="Content/Characters/Defensebot/DEFENCEBOT_interact3.ogg" range="100" />
                      </StatusEffect>
                    </StatusEffectAction>
                    <!-- Turn hostile -->
                    <NPCChangeTeamAction npctag="scrapbot" teamid="Team2" />
                  </Option>
                </ConversationAction>
              </Success>
              <Failure>
                <ConversationAction text="EventText.malfunctioningdefensebot.o1.c2" targettag="triggerer_player" eventsprite="brokenmachinery">
                  <Option text="EventText.malfunctioningdefensebot.o1.c2.o1" endconversation="true">
                    <!-- Player broke it, but learns some mechanical skill in the process -->
                    <GiveSkillEXPAction skill="mechanical" amount="2" targettag="triggerer_player" />
                  </Option>
                </ConversationAction>
              </Failure>
            </SkillCheckAction>
          </Option>
          <Option text="EventText.malfunctioningdefensebot.o2" endconversation="true">
            <!-- Leave -->
            <Goto name="restart" />
          </Option>
        </ConversationAction>
        <Label name="end" />
      </ScriptedEvent>
    </EventPrefabs>
  </Randomevents>
</Override>