Ejemplo n.º 1
0
 private static bool AtMaxFight(GeoLevelController geoLevel, IGeoFactionMissionParticipant attacker)
 {
     try {
         if (geoLevel?.Map == null || IsAlienOrPP(attacker))
         {
             return(false);
         }
         foreach (GeoSite site in geoLevel.Map.AllSites)
         {
             if (!(site.ActiveMission is GeoHavenDefenseMission mission))
             {
                 continue;
             }
             if (Config.No_Attack_When_Sieged_Difficulty >= difficulty && IsAlien(mission.GetEnemyFaction()) && site.Owner == attacker)
             {
                 Verbo("{0} is being sieged by alien at {0}.", site.Name);
                 return(true);
             }
             if (Config.One_Global_Attack_Difficulty >= difficulty)
             {
                 Verbo("Global attack limit: {0} already under siege.", site.Name);
                 return(true); // Rokkie and Veteran limits to 1 faction war on globe
             }
             if (Config.One_Attack_Per_Faction_Difficulty >= difficulty && mission.GetEnemyFaction() == attacker)
             {
                 Verbo("Faction attack limit: {0} already sieging {1}.", attacker.GetPPName(), site.Name);
                 return(true); // Hero and Legend limits to 1 attack per faction
             }
         }
         return(false);
     } catch (Exception ex) { return(!Error(ex)); }
 }
Ejemplo n.º 2
0
 private static void AfterLevelStart_StoreDiff(GeoLevelController __instance)
 {
     try {
         GameDifficultyLevelDef diff = __instance.CurrentDifficultyLevel;
         difficulty   = __instance.DynamicDifficultySystem.DifficultyLevels.ToList().IndexOf(diff);
         lastAttacker = null;
         Info("Attacker reset. Difficulty level is {0}.", difficulty); // 0 = Rookie, 1 = Veteran, 2 = Hero, 3 = Legend
     } catch (Exception ex) { Error(ex); }
 }
Ejemplo n.º 3
0
 private static bool ShouldStopFight(GeoLevelController geoLevel, IGeoFactionMissionParticipant from)
 {
     try {
         if (Config.Stop_OneSided_War && lastAttacker != null && from == lastAttacker)
         {
             Verbo("One sided war; {0} has already attacked.", from.GetPPName());
             return(true);
         }
         return(AtMaxFight(geoLevel, from));
     } catch (Exception ex) { return(!Error(ex)); }
 }
Ejemplo n.º 4
0
        // Do the scrap after user confirmation
        private static void OnScrapConfirmation(UIModuleManufacturing me, MessageBoxCallbackResult answer, IManufacturable item, GeoscapeViewContext context)
        {
            try {
                if (answer.DialogResult != MessageBoxResult.Yes)
                {
                    return;
                }
                GeoFaction         faction  = context.ViewerFaction;
                GeoLevelController geoLevel = context.Level;

                if (item is GeoUnitWrapper)
                {
                    if (item is GeoPlaneWrapper plane)
                    {
                        Info("Scraping airplane {0}", plane.GetName());
                        GeoVehicle vehicle = plane.Vehicle;
                        GeoSite    site    = vehicle.CurrentSite;
                        foreach (GeoCharacter chr in vehicle.Characters.ToList())
                        {
                            Info("Moving {0} to {1}", chr.DisplayName, site.Name);
                            vehicle.RemoveCharacter(chr);
                            site.AddCharacter(chr);
                        }
                        faction.ScrapItem(plane);
                        vehicle.Travelling = true; // Unset vehicle.CurrentSite and triggers site.VehicleLeft
                        vehicle.Destroy();
                    }
                    else if (item is GeoTankWrapper tank)
                    {
                        Info("Scraping tank {0}", tank.GetName());
                        faction.ScrapItem(tank);
                        faction.RemoveCharacter(tank.GroundVehicle);
                        geoLevel.DestroyTacUnit(tank.GroundVehicle);
                    }
                }
                Info("Scrap done, refreshing list");
                typeof(UIModuleManufacturing).GetMethod("DoFilter", NonPublic | Instance).Invoke(me, new object[] { null, null });
            } catch (Exception ex) { Error(ex); }
        }
Ejemplo n.º 5
0
 private static bool Override_Attack(GeoFaction __instance, GeoVehicle vehicle, GeoSite site, GeoLevelController ____level)
 {
     try {
         Verbo("{0} wants to attack {1}.", vehicle.Name, site.Name);
         if (ShouldStopFight(____level, vehicle?.Owner))
         {
             Info("{0} attack prevented at {2}.", __instance.Name.Localize(), vehicle.Name, site.Name);
             return(false);
         }
         lastAttacker = vehicle.Owner;
         return(true);
     } catch (Exception ex) { return(Error(ex)); }
 }
Ejemplo n.º 6
0
 private static void BeforeQueuedEvents_PauseBase(List <IGeoCharacterContainer> ____justRestedContainer, GeoLevelController ____level)
 {
     try {
         if (____justRestedContainer?.OfType <GeoSite>().Any() != true)
         {
             return;
         }
         Info("Crew in a base are rested. Pausing.");
         ____level.View.RequestGamePause();
     } catch (Exception ex) { Error(ex); }
 }
Ejemplo n.º 7
0
 private static void BeforeQueuedEvents_CentreBase(List <IGeoCharacterContainer> ____justRestedContainer, GeoLevelController ____level)
 {
     try {
         var pxbase = ____justRestedContainer?.OfType <GeoSite>().FirstOrDefault();
         if (pxbase == null)
         {
             return;
         }
         Info("Crew in base {0} are rested. Centering.", pxbase.Name);
         ____level.View.ChaseTarget(pxbase, false);
     } catch (Exception ex) { Error(ex); }
 }
Ejemplo n.º 8
0
 private static void BeforeQueuedEvents_CentreVehicle(List <IGeoCharacterContainer> ____justRestedContainer, GeoLevelController ____level)
 {
     try {
         var vehicle = ____justRestedContainer?.OfType <GeoVehicle>().FirstOrDefault();
         if (vehicle == null)
         {
             return;
         }
         GeoscapeViewState state = ____level.View.CurrentViewState;
         Info("Crew on {0} are rested. ViewState is {1}.", vehicle.Name, state);
         if (state is UIStateVehicleSelected)
         {
             typeof(UIStateVehicleSelected).GetMethod("SelectVehicle", NonPublic | Instance).Invoke(state, new object[] { vehicle, true });
         }
     } catch (Exception ex) { Error(ex); }
 }