// If scrap list need to be populated, do it private static void BeforeSetupQueue_AddVehicleToScrap(GeoscapeViewContext ____context, ItemStorage ____scrapStorage) { try { if (!NeedToAddVehicles) { return; } LoadVehicleDefs(); GeoPhoenixFaction faction = ____context.ViewerFaction as GeoPhoenixFaction; foreach (GeoVehicle v in faction.Vehicles) { Verbo("Add {0} to item list", v.Name); ____scrapStorage.AddItem(new GeoPlaneWrapper(v)); } NeedToAddVehicles = false; } catch (Exception ex) { Error(ex); } }
// 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); } }
// Show confirmation popup which callback OnScrapConfirmation private static bool BeforeOnItemAction_ConfirmScrap(UIModuleManufacturing __instance, GeoManufactureItem item, MessageBox ____confirmationBox, GeoscapeViewContext ____context) { try { if (item.Manufacturable is GeoUnitWrapper unit) { Verbo("Confirming scraping of {0}", unit.GetName()); string scrapTxt = TitleCase(__instance.ScrapModeButton.GetComponentInChildren <Text>()?.text ?? "Scrap"); if (scrapTxt == "Scrap Item") { scrapTxt = "Scrap"; } string translation = scrapTxt + " " + unit.GetName() + "?"; ____confirmationBox.ShowSimplePrompt(translation, MessageBoxIcon.Warning, MessageBoxButtons.YesNo, answer => OnScrapConfirmation(__instance, answer, unit, ____context), __instance, MessageBox.DialogMode.DialogBox); return(false); } return(true); } catch (Exception ex) { return(Error(ex)); } }
// Replace scrap list with individual vehicles when applicable private static void BeforeRefreshItemList_FillWithVehicle(UIModuleManufacturing __instance, ref IEnumerable <IManufacturable> availableItemRecipes, PhoenixGeneralButton ____activeFilterButton, GeoscapeViewContext ____context) { try { if (availableItemRecipes == null || availableItemRecipes.GetType() == typeof(List <IManufacturable>)) { return; } if (!IsScrappingVehicles(__instance, ____activeFilterButton)) { return; } List <IManufacturable> vList = new List <IManufacturable>(); GeoPhoenixFaction faction = ____context.ViewerFaction as GeoPhoenixFaction; TankSites = new Dictionary <GeoTacUnit, GeoSite>(); if (faction.Vehicles.Count() > 1) { foreach (GeoVehicle plane in faction.Vehicles) { if (CanScrap(plane, true)) { Verbo("Can scrap airplane {0}", plane.Name); vList.Add(new GeoPlaneWrapper(plane)); foreach (var chr in plane.Characters) { if (chr.ClassDef.IsVehicle || chr.ClassDef.IsMutog) { TankSites.Add(chr, plane.CurrentSite); } } } } } foreach (GeoPhoenixBase pxbase in faction.Bases) { var units = pxbase.Site.TacUnits; if (!units.Any()) { continue; } foreach (var chr in units) { if (chr.ClassDef.IsMutog) { TankSites.Add(chr, pxbase.Site); } } if (CanScrapVehicles(pxbase)) { Verbo("Can scrap tanks at {0}", pxbase.Site.Name); foreach (var chr in units) { if (chr.ClassDef.IsVehicle) { TankSites.Add(chr, pxbase.Site); } } } } foreach (GeoCharacter tank in faction.GroundVehicles) { if (!TankSites.ContainsKey(tank)) { continue; } Verbo("Can scrap tank {0}", tank.DisplayName); vList.Add(new GeoTankWrapper(tank)); } Info("Can scrap {0} vehicles", vList.Count); availableItemRecipes = from t in vList select t; } catch (Exception ex) { Error(ex); } }