Esempio n. 1
0
        public void createNewAnimal(ref Mercenary merc, PawnKindDef race)
        {
            Pawn newPawn = PawnGenerator.GeneratePawn(FCPawnGenerator.AnimalRequest(race));

            //merc = (Mercenary)newPawn;

            merc.squad      = this;
            merc.settlement = settlement;
            //Log.Message(newPawn.Name + "   State: Dead - " + newPawn.health.Dead + "    Apparel Count: " + newPawn.apparel.WornApparel.Count());
            merc.pawn = newPawn;
        }
Esempio n. 2
0
        public void createNewPawn(ref Mercenary merc, PawnKindDef race)
        {
            Pawn newPawn = PawnGenerator.GeneratePawn(FCPawnGenerator.WorkerOrMilitaryRequest);

            newPawn.apparel?.DestroyAll();
            newPawn.equipment?.DestroyAllEquipment();
            //merc = (Mercenary)newPawn;
            merc.squad      = this;
            merc.settlement = settlement;
            //Log.Message(newPawn.Name + "   State: Dead - " + newPawn.health.Dead + "    Apparel Count: " + newPawn.apparel.WornApparel.Count());
            merc.pawn = newPawn;
        }
Esempio n. 3
0
        public void EquipPawn(Mercenary merc, MilUnitFC loadout)
        {
            foreach (Apparel clothes in loadout.defaultPawn.apparel.WornApparel)
            {
                if (clothes.def.MadeFromStuff)
                {
                    Thing thing = ThingMaker.MakeThing(clothes.def, clothes.Stuff);
                    thing.SetColor(Color.white);
                    merc.pawn.apparel.Wear(thing as Apparel);
                }
                else
                {
                    Thing thing = ThingMaker.MakeThing(clothes.def, clothes.Stuff);
                    thing.SetColor(Color.white);
                    merc.pawn.apparel.Wear(thing as Apparel);
                }
            }

            foreach (ThingWithComps weapon in loadout.defaultPawn.equipment.AllEquipmentListForReading)
            {
                if (weapon.def.MadeFromStuff)
                {
                    merc.pawn.equipment.AddEquipment(ThingMaker.MakeThing(weapon.def, weapon.Stuff) as ThingWithComps);
                }
                else
                {
                    merc.pawn.equipment.AddEquipment(ThingMaker.MakeThing(weapon.def) as ThingWithComps);
                }

                if (FactionColonies.IsModLoaded("CETeam.CombatExtended"))
                {
                    //Log.Message("mod detected");
                    //CE is loaded
                    foreach (ThingComp comp in merc.pawn.AllComps)
                    {
                        if (comp.GetType().ToString() == "CombatExtended.CompInventory")
                        {
                            Type typ = FactionColonies.returnUnknownTypeFromName(
                                "CombatExtended.LoadoutPropertiesExtension");

                            //Method not static, so create instance of object and define the parameters to the method.
                            var      obj       = Activator.CreateInstance(typ);
                            object[] paramArgu = { merc.pawn.equipment.Primary, comp, 1 };

                            Traverse.Create(obj).Method("TryGenerateAmmoFor", paramArgu).GetValue();
                            Traverse.Create(obj).Method("LoadWeaponWithRandAmmo", merc.pawn.equipment.Primary)
                            .GetValue();
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        static bool Prefix(Pawn __instance)
        {
            if (__instance.IsMercenary())
            {
                if (__instance.Faction != FactionColonies.getPlayerColonyFaction())
                {
                    __instance.SetFaction(FactionColonies.getPlayerColonyFaction());
                }
                MercenarySquadFC squad = Find.World.GetComponent <FactionFC>().militaryCustomizationUtil.returnSquadFromUnit(__instance);
                if (squad != null)
                {
                    Mercenary merc = Find.World.GetComponent <FactionFC>().militaryCustomizationUtil.returnMercenaryFromUnit(__instance, squad);
                    if (merc != null)
                    {
                        if (squad.settlement != null)
                        {
                            if (FactionColonies.Settings().deadPawnsIncreaseMilitaryCooldown)
                            {
                                squad.dead += 1;
                            }

                            squad.settlement.happiness -= 1;
                        }

                        squad.PassPawnToDeadMercenaries(merc);
                    }

                    squad.removeDroppedEquipment();
                }
                else
                {
                    Log.Message("Mercenary Errored out. Did not find squad.");
                }

                __instance.equipment?.DestroyAllEquipment();
                __instance.apparel?.DestroyAll();
                //__instance.Destroy();
                return(true);
            }

            return(true);
        }
Esempio n. 5
0
        public void PassPawnToDeadMercenaries(Mercenary merc)
        {
            //If ever add past dead pawns, use this code

            /*MilitaryCustomizationUtil util = Find.World.GetComponent<FactionFC>().militaryCustomizationUtil;
             * Mercenary pwn = new Mercenary(true);
             * if (merc.animal != null)
             * {
             *  Mercenary animal = new Mercenary(true);
             *  animal = merc.animal;
             *  util.deadPawns.Add(animal);
             * }
             * pwn = merc;*/

            //util.deadPawns.Add(pwn);
            Mercenary pawn2 = new Mercenary(true);

            createNewPawn(ref pawn2, merc.pawn.kindDef);
            mercenaries.Replace(merc, pawn2);
        }
Esempio n. 6
0
        public void createNewPawn(ref Mercenary merc, PawnKindDef race)
        {
            PawnKindDef raceChoice = race;
            FactionFC   factionFc  = Find.World.GetComponent <FactionFC>();

            if (race == null || !factionFc.raceFilter.Allows(raceChoice.race))
            {
                raceChoice = FactionColonies.getPlayerColonyFaction().RandomPawnKind();
            }

            Pawn newPawn = PawnGenerator.GeneratePawn(FCPawnGenerator.WorkerOrMilitaryRequest(raceChoice));

            newPawn.apparel?.DestroyAll();
            newPawn.equipment?.DestroyAllEquipment();
            //merc = (Mercenary)newPawn;
            merc.squad      = this;
            merc.settlement = settlement;
            //Log.Message(newPawn.Name + "   State: Dead - " + newPawn.health.Dead + "    Apparel Count: " + newPawn.apparel.WornApparel.Count());
            merc.pawn = newPawn;
        }
Esempio n. 7
0
        public void initiateSquad()
        {
            mercenaries     = new List <Mercenary>();
            UsedApparelList = new List <Apparel>();
            UsedWeaponList  = new List <ThingWithComps>();

            if (outfit == null)
            {
                for (int k = 0; k < 30; k++)
                {
                    Mercenary pawn = new Mercenary(true);
                    createNewPawn(ref pawn, null);
                    mercenaries.Add(pawn);
                }
            }
            else
            {
                for (int k = 0; k < 30; k++)
                {
                    Mercenary pawn = new Mercenary(true);
                    createNewPawn(ref pawn, outfit.units[k].pawnKind);
                    mercenaries.Add(pawn);
                }
            }

            //Log.Message("count : " + mercenaries.Count().ToString());
            //this.debugMercenarySquad();
            if (loadID == -1)
            {
                loadID = Find.World.GetComponent <FactionFC>().GetNextMercenarySquadID();
            }

            if (outfit != null)
            {
                OutfitSquad(outfit);
            }
        }
Esempio n. 8
0
 public void StripPawn(Mercenary merc)
 {
     merc.pawn.apparel.DestroyAll();
     merc.pawn.equipment.DestroyAllEquipment();
 }
Esempio n. 9
0
        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();
        }
Esempio n. 10
0
 public void HealPawn(Mercenary merc)
 {
     merc.pawn.health.Reset();
 }