public void unequipWeapon() { changeTick(); defaultPawn.equipment.DestroyAllEquipment(); MilSquadFC.UpdateEquipmentTotalCostOfSquadsContaining(this); }
public void wearEquipment(Apparel Equipment, bool wear) { changeTick(); Reset: foreach (ApparelLayerDef layer in Equipment.def.apparel.layers) { foreach (BodyPartGroupDef part in Equipment.def.apparel.bodyPartGroups) { foreach (Apparel apparel in defaultPawn.apparel.WornApparel) { if ((apparel.def.apparel.layers.Contains(layer) && apparel.def.apparel.bodyPartGroups.Contains(part)) || (Equipment.def.apparel.layers.Contains(ApparelLayerDefOf.Overhead) && apparel.def.apparel.layers.Contains(ApparelLayerDefOf.Overhead))) { defaultPawn.apparel.Remove(apparel); goto Reset; } } } } if (wear == false) { //NOTHING } else { defaultPawn.apparel.Wear(Equipment); } MilSquadFC.UpdateEquipmentTotalCostOfSquadsContaining(this); }
public MilSquadFC CreateMilSquad() { MilSquadFC squad = new MilSquadFC(true); squad.name = name; squad.isCivilian = isCivilian; squad.isTraderCaravan = isTraderCaravan; FactionFC fc = Find.World.GetComponent <FactionFC>(); var milUnits = unitTemplates.Select(unit => unit.CreateMilUnit()).ToList(); foreach (int i in units) { if (i == -1) { squad.units.Add(fc.militaryCustomizationUtil.blankUnit); } else { squad.units.Add(milUnits[i]); } } return(squad); }
public override void Select(IExposable selecting) { MilSquadFC squad = (MilSquadFC)selecting; selectedSquad = squad; selectedText = squad.name; }
public MilSquadFC Import() { FactionFC fc = Find.World.GetComponent <FactionFC>(); MilSquadFC squad = this.CreateMilSquad(); foreach (MilUnitFC unit in squad.units.Distinct().Where(unit => !unit.isBlank)) { fc.militaryCustomizationUtil.units.Add(unit); } fc.militaryCustomizationUtil.squads.Add(squad); return(squad); }
public SavedSquadFC(MilSquadFC squad) { name = squad.name; isTraderCaravan = squad.isTraderCaravan; isCivilian = squad.isCivilian; // Dont store blank units var squadTemplates = squad.units.Distinct().Where(u => !u.isBlank).ToList(); unitTemplates = squadTemplates.Select(unit => new SavedUnitFC(unit)).ToList(); units = squad.units.Select(unit => squadTemplates.IndexOf(unit)).ToList(); }
protected override void OnImport(string name) { FactionFC fc = Find.World.GetComponent <FactionFC>(); MilSquadFC squad = FactionColoniesMilitary.GetSquad(name).Import(); militaryCustomizationWindowFC mil = (militaryCustomizationWindowFC)Find.WindowStack.Windows.FirstOrFallback( window => window.GetType() == typeof(militaryCustomizationWindowFC)); mil.SetActive(squad); MessageTypeDefOf.PositiveEvent.sound.PlayOneShotOnCamera(); Messages.Message("FCImported".Translate((NamedArgument)name), MessageTypeDefOf.PositiveEvent); this.Close(); }
public void equipWeapon(ThingWithComps weapon) { changeTick(); if (isCivilian == false) { unequipWeapon(); defaultPawn.equipment.AddEquipment(weapon); } else { Messages.Message("You cannot put a weapon on a civilian!", MessageTypeDefOf.RejectInput); } MilSquadFC.UpdateEquipmentTotalCostOfSquadsContaining(this); }
public void attemptToAssignSquad(SettlementFC settlement, MilSquadFC squad) { if (FactionColonies.calculateMilitaryLevelPoints(settlement.settlementMilitaryLevel) >= squad.equipmentTotalCost) { if (squadExists(settlement)) { settlement.militarySquad.OutfitSquad(squad); } else { //create new squad createMercenarySquad(settlement); settlement.militarySquad.OutfitSquad(squad); } Messages.Message(squad.name + "'s loadout has been assigned to " + settlement.name, MessageTypeDefOf.TaskCompletion); } else { Messages.Message("That squad exceeds the settlement's max allotted cost", MessageTypeDefOf.RejectInput); } }
public void OutfitSquad(MilSquadFC outfit) { FactionFC faction = Find.World.GetComponent <FactionFC>(); int count = 0; this.outfit = outfit; UsedWeaponList = new List <ThingWithComps>(); UsedApparelList = new List <Apparel>(); animals = new List <Mercenary>(); foreach (MilUnitFC loadout in outfit.units) { try { if (mercenaries[count]?.pawn?.kindDef != loadout.pawnKind || mercenaries[count].pawn.Dead) { Mercenary pawn = new Mercenary(true); createNewPawn(ref pawn, loadout.pawnKind); mercenaries.Replace(mercenaries[count], pawn); } StripPawn(mercenaries[count]); HealPawn(mercenaries[count]); if (loadout != null) { //mercenaries[count]; //StripPawn(mercenaries[count]); EquipPawn(mercenaries[count], loadout); if (loadout.animal != null) { Mercenary animal = new Mercenary(true); createNewAnimal(ref animal, loadout.animal); animal.handler = mercenaries[count]; mercenaries[count].animal = animal; animals.Add(animal); } mercenaries[count].loadout = loadout; mercenaries[count].deployable = mercenaries[count].loadout != faction.militaryCustomizationUtil.blankUnit; } if (mercenaries[count].pawn.equipment.AllEquipmentListForReading != null) { UsedWeaponList.AddRange(mercenaries[count].pawn.equipment.AllEquipmentListForReading); //add single check at start of load and mark variable } if (mercenaries[count].pawn.apparel.WornApparel != null) { UsedApparelList.AddRange(mercenaries[count].pawn.apparel.WornApparel); } } catch (Exception e) { Log.Error("Something went wrong when outfitting a squad: " + e.Message); bool isNullOrEmpty = mercenaries.NullOrEmpty(); Log.Error("Mercanaries NullOrEmpty: " + isNullOrEmpty); if (isNullOrEmpty) { Log.Error("Number of Mercs: " + mercenaries.Count); Log.Error("Any mercenary or pawn is null: " + mercenaries.Any(mercenary => mercenary?.pawn == null)); } } count++; } //debugMercenarySquad(); }
public override void DrawTab(Rect rect) { //set text anchor and font GameFont fontBefore = Text.Font; TextAnchor anchorBefore = Text.Anchor; Rect SelectionBar = new Rect(5, 45, 200, 30); Rect importButton = new Rect(5, SelectionBar.y + SelectionBar.height + 10, 200, 30); Rect nameTextField = new Rect(5, importButton.y + importButton.height + 10, 250, 30); Rect isTrader = new Rect(5, nameTextField.y + nameTextField.height + 10, 130, 30); Rect UnitStandBase = new Rect(170, 220, 50, 30); Rect EquipmentTotalCost = new Rect(350, 50, 450, 40); Rect ResetButton = new Rect(700, 100, 100, 30); Rect DeleteButton = new Rect(ResetButton.x, ResetButton.y + ResetButton.height + 5, ResetButton.width, ResetButton.height); Rect PointRefButton = new Rect(DeleteButton.x, DeleteButton.y + DeleteButton.height + 5, DeleteButton.width, DeleteButton.height); Rect SaveSquadButton = new Rect(DeleteButton.x, PointRefButton.y + DeleteButton.height + 5, DeleteButton.width, DeleteButton.height); //If squad is not selected if (Widgets.CustomButtonText(ref SelectionBar, selectedText, Color.gray, Color.white, Color.black)) { //check null if (util.squads == null) { util.resetSquads(); } List <FloatMenuOption> squads = new List <FloatMenuOption> { new FloatMenuOption("Create New Squad", delegate { MilSquadFC newSquad = new MilSquadFC(true) { name = $"New Squad {(util.squads.Count + 1).ToString()}" }; selectedText = newSquad.name; selectedSquad = newSquad; selectedSquad.newSquad(); util.squads.Add(newSquad); }) }; //Create list of selectable units squads.AddRange(util.squads.Select(squad => new FloatMenuOption(squad.name, delegate { //Unit is selected selectedText = squad.name; selectedSquad = squad; selectedSquad.updateEquipmentTotalCost(); }))); FloatMenu selection = new Searchable_FloatMenu(squads); Find.WindowStack.Add(selection); } if (Widgets.ButtonText(importButton, "Import Squad")) { Find.WindowStack.Add(new Dialog_ManageSquadExportsFC( FactionColoniesMilitary.SavedSquads.ToList())); } //if squad is selected if (selectedSquad != null) { Text.Anchor = TextAnchor.MiddleLeft; Text.Font = GameFont.Small; if (settlementPointReference != null) { Widgets.Label(EquipmentTotalCost, "Total Squad Equipment Cost: " + selectedSquad.equipmentTotalCost + " / " + FactionColonies .calculateMilitaryLevelPoints(settlementPointReference .settlementMilitaryLevel) + " (Max Cost)"); } else { Widgets.Label(EquipmentTotalCost, "Total Squad Equipment Cost: " + selectedSquad.equipmentTotalCost + " / " + "No Reference"); } Text.Font = GameFont.Tiny; Text.Anchor = TextAnchor.UpperCenter; Widgets.CheckboxLabeled(isTrader, "is Trader Caravan", ref selectedSquad.isTraderCaravan); selectedSquad.setTraderCaravan(selectedSquad.isTraderCaravan); //Unit Name selectedSquad.name = Widgets.TextField(nameTextField, selectedSquad.name); if (Widgets.ButtonText(ResetButton, "Reset to Default")) { selectedSquad.newSquad(); } if (Widgets.ButtonText(DeleteButton, "Delete Squad")) { selectedSquad.deleteSquad(); util.checkMilitaryUtilForErrors(); selectedSquad = null; selectedText = "Select A Squad"; //Reset Text anchor and font Text.Font = fontBefore; Text.Anchor = anchorBefore; return; } if (Widgets.ButtonText(PointRefButton, "Set Point Ref")) { List <FloatMenuOption> settlementList = Find.World.GetComponent <FactionFC>() .settlements.Select(settlement => new FloatMenuOption(settlement.name + " - Military Level : " + settlement.settlementMilitaryLevel, delegate { //set points settlementPointReference = settlement; })) .ToList(); if (!settlementList.Any()) { settlementList.Add(new FloatMenuOption("No Valid Settlements", null)); } FloatMenu floatMenu = new FloatMenu(settlementList) { vanishIfMouseDistant = true }; Find.WindowStack.Add(floatMenu); } if (Widgets.ButtonText(SaveSquadButton, "Export Squad")) { // TODO: Confirm if squad with name already exists FactionColoniesMilitary.SaveSquad(new SavedSquadFC(selectedSquad)); Messages.Message("ExportSquad".Translate(), MessageTypeDefOf.TaskCompletion); } //for (int k = 0; k < 30; k++) //{ // Widgets.ButtonImage(new Rect(UnitStandBase.x + (k * 15), UnitStandBase.y + ((k % 5) * 70), 50, 20), texLoad.unitCircle); //} for (int k = 0; k < 30; k++) { if (Widgets.ButtonImage(new Rect(UnitStandBase.x + k % 6 * 80, UnitStandBase.y + (k - k % 6) / 5 * 70, 50, 20), TexLoad.unitCircle)) { int click = k; //Option to clear unit slot List <FloatMenuOption> units = new List <FloatMenuOption> { new FloatMenuOption("clearUnitSlot".Translate(), delegate { //Log.Message(selectedSquad.units.Count().ToString()); //Log.Message(click.ToString()); selectedSquad.units[click] = new MilUnitFC(true); selectedSquad.updateEquipmentTotalCost(); selectedSquad.ChangeTick(); }) }; //Create list of selectable units units.AddRange(util.units.Select(unit => new FloatMenuOption(unit.name + " - Cost: " + unit.equipmentTotalCost, delegate { //Unit is selected selectedSquad.units[click] = unit; selectedSquad.updateEquipmentTotalCost(); selectedSquad.ChangeTick(); }))); FloatMenu selection = new Searchable_FloatMenu(units); Find.WindowStack.Add(selection); } if (selectedSquad.units[k].isBlank) { continue; } if (selectedSquad.units.ElementAt(k).animal != null) { Widgets.ButtonImage( new Rect(UnitStandBase.x + 15 + ((k % 6) * 80), UnitStandBase.y - 45 + (k - k % 6) / 5 * 70, 60, 60), selectedSquad.units.ElementAt(k).animal.race.uiIcon); } Widgets.ThingIcon( new Rect(UnitStandBase.x - 5 + ((k % 6) * 80), UnitStandBase.y - 45 + (k - k % 6) / 5 * 70, 60, 60), selectedSquad.units.ElementAt(k).defaultPawn); if (selectedSquad.units.ElementAt(k).defaultPawn.equipment.AllEquipmentListForReading.Count > 0) { Widgets.ThingIcon( new Rect(UnitStandBase.x - 5 + ((k % 6) * 80), UnitStandBase.y - 15 + (k - k % 6) / 5 * 70, 40, 40), selectedSquad.units.ElementAt(k).defaultPawn.equipment.AllEquipmentListForReading[0]); } Widgets.Label( new Rect(UnitStandBase.x - 15 + ((k % 6) * 80), UnitStandBase.y - 65 + (k - k % 6) / 5 * 70, 80, 60), selectedSquad.units.ElementAt(k).name); } //Reset Text anchor and font Text.Font = fontBefore; Text.Anchor = anchorBefore; } //Reset Text anchor and font Text.Font = fontBefore; Text.Anchor = anchorBefore; }