Ejemplo n.º 1
0
        public Pawn GetNearbyTarget(float radius)
        {
            List <Pawn> allPawns = this.Pawn.Map.mapPawns.AllPawnsSpawned;

            for (int i = 0; i < allPawns.Count(); i++)
            {
                if (!allPawns[i].DestroyedOrNull() && allPawns[i] != this.Pawn)
                {
                    if (!allPawns[i].Dead && !allPawns[i].Downed)
                    {
                        if ((allPawns[i].Position - this.Pawn.Position).LengthHorizontal <= radius)
                        {
                            if (allPawns[i].Faction != null && allPawns[i].Faction != this.Pawn.Faction)
                            {
                                // Log.Message("checking " + allPawns[i].LabelShort + " for hostility: " + FactionUtility.HostileTo(this.Pawn.Faction, allPawns[i].Faction));
                                //Log.Message(this.Pawn.Faction.RelationWith(allPawns[i].Faction, false).ToString());
                                if (FactionUtility.HostileTo(this.Pawn.Faction, allPawns[i].Faction))
                                {
                                    return(allPawns[i]);
                                }
                            }
                        }
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
        public Pawn SearchForTargets()
        {
            Pawn threat = null;

            List <Pawn> allPawns = this.Map.mapPawns.AllPawnsSpawned;

            for (int i = 0; i < allPawns.Count(); i++)
            {
                if (!allPawns[i].DestroyedOrNull())
                {
                    if (!allPawns[i].Dead && !allPawns[i].Downed && !allPawns[i].IsPrisonerInPrisonCell())
                    {
                        if ((allPawns[i].Position - this.Position).LengthHorizontal <= this.threatRange)
                        {
                            if ((allPawns[i].Faction != null || (allPawns[i].RaceProps.Animal && allPawns[i].InAggroMentalState)) && allPawns[i].Faction != this.sustainerPawn.Faction)
                            {
                                if (FactionUtility.HostileTo(this.sustainerPawn.Faction, allPawns[i].Faction) || (allPawns[i].RaceProps.Animal && allPawns[i].InAggroMentalState))
                                {
                                    if (!allPawns[i].IsPrisoner || (allPawns[i].IsPrisoner && allPawns[i].IsFighting()))
                                    {
                                        threat = allPawns[i];
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(threat);
        }
Ejemplo n.º 3
0
        // prefix
        // - wants instance, result and count
        // - wants to change count
        // - returns a boolean that controls if original is executed (true) or not (false)
        public static Boolean CheckSpringPrefix(Pawn p)
        {
            if (p == null)
            {
                return(true);
            }

            if (p.Faction == null)
            {
                return(true);
            }

            //Retuen False so the origional method is not executed.

            // if (p.Faction.IsPlayer)

            //This looks to include the Player Faction as Bring Friendly to Itself.
            if (!FactionUtility.HostileTo(p.Faction, Faction.OfPlayer))
            {
                //Log.Message("Friendly");
                return(false);
            }
            //Log.Message("Hostile");
            return(true);
        }
Ejemplo n.º 4
0
            public override bool Allows(Pawn pawn)
            {
                if (!enabled)
                {
                    return(false);
                }
                if (pawn.IsColonist)
                {
                    return(false);
                }
                Lord lord = LordUtility.GetLord(pawn);

                if (lord != null && lord.LordJob != null && lord.LordJob.CanOpenAnyDoor(pawn))
                {
                    return(true);
                }
                if (pawn.Faction != null && FactionUtility.HostileTo(pawn.Faction, Faction.OfPlayer))
                {
                    return(false);
                }
                if (pawn.Faction == null && WildManUtility.NonHumanlikeOrWildMan(pawn) && (pawn.HostFaction != Faction.OfPlayer || pawn.IsPrisoner))
                {
                    return(false);
                }
                if (pawn.IsPrisoner && pawn.HostFaction == Faction.OfPlayer)
                {
                    return(false);
                }
                return(true);
            }
Ejemplo n.º 5
0
        public IEnumerable <Thing> Filter(AbilityDef ability, Saveable_Caster pawn)
        {
            foreach (Thing thing in this.optionalSource.Targets(ability, pawn))
            {
                Pawn thingPawn = thing as Pawn;
                if (thingPawn != null)
                {
                    if (FactionUtility.HostileTo(pawn.pawn.Faction, thingPawn.Faction))
                    {
                        yield return(thing);
                    }
                    continue;
                }

                Corpse corpsePawn = thing as Corpse;
                if (corpsePawn != null)
                {
                    if (FactionUtility.HostileTo(pawn.pawn.Faction, corpsePawn.innerPawn.Faction))
                    {
                        yield return(thing);
                    }
                    continue;
                }
            }
        }
Ejemplo n.º 6
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map     map      = (Map)parms.target;
            Faction faction  = Find.FactionManager.RandomNonHostileFaction(true, true, true, TechLevel.Neolithic);
            Faction faction2 = Find.FactionManager.FirstFactionOfDef(FactionDefOf.PlayerColony);
            int     freeColonistsSpawnedCount = map.mapPawns.FreeColonistsSpawnedCount;
            bool    flag = !FactionUtility.HostileTo(faction, faction2) && map.resourceCounter.TotalHumanEdibleNutrition < 4f * (float)freeColonistsSpawnedCount;
            bool    result;

            if (flag)
            {
                Thing        thing  = ThingMaker.MakeThing(ThingDef.Named("MealSimple"), null);
                Thing        thing2 = ThingMaker.MakeThing(ThingDef.Named("MealFine"), null);
                Thing        thing3 = ThingMaker.MakeThing(ThingDef.Named("MealSimple"), null);
                Thing        thing4 = ThingMaker.MakeThing(ThingDef.Named("MealFine"), null);
                List <Thing> list   = new List <Thing>();
                int          num    = Rand.Range(20, 40);
                bool         flag2  = num > thing.def.stackLimit;
                if (flag2)
                {
                    num = thing.def.stackLimit;
                }
                bool flag3 = num == 0;
                if (flag3)
                {
                    num = 1;
                }
                int  num2  = Rand.Range(20, 40);
                bool flag4 = num2 > thing2.def.stackLimit;
                if (flag4)
                {
                    num2 = thing2.def.stackLimit;
                }
                bool flag5 = num2 == 0;
                if (flag5)
                {
                    num2 = 1;
                }
                thing.stackCount  = num;
                thing2.stackCount = num2;
                thing3.stackCount = num;
                thing4.stackCount = num2;
                list.Add(thing);
                list.Add(thing2);
                list.Add(thing3);
                list.Add(thing4);
                IntVec3 intVec = DropCellFinder.RandomDropSpot(map);
                DropPodUtility.DropThingsNear(intVec, map, list, 110, false, false, true);
                Find.LetterStack.ReceiveLetter("MO_Thanksgiving".Translate(), "MO_ThanksgivingDesc".Translate(), LetterDefOf.PositiveEvent, new TargetInfo(intVec, map, false), null);                  //"One of the tribes has noticed your food stores are low. They have provided you with some food, no strings attached.\n\nThey thank you for being such good friends and they hope your friendship will be further cemented by this act."
                result = true;
            }
            else
            {
                result = false;
            }
            return(result);
        }
Ejemplo n.º 7
0
        private void DetermineThreats()
        {
            this.target = null;
            try
            {
                List <Pawn> allPawns = this.Pawn.Map.mapPawns.AllPawnsSpawned;
                for (int i = 0; i < allPawns.Count(); i++)
                {
                    if (!allPawns[i].DestroyedOrNull() && allPawns[i] != this.Pawn)
                    {
                        if (!allPawns[i].Dead && !allPawns[i].Downed && !allPawns[i].IsPrisonerInPrisonCell())
                        {
                            if ((allPawns[i].Position - this.Pawn.Position).LengthHorizontal <= this.threatRange)
                            {
                                if (allPawns[i].Faction != null && allPawns[i].Faction != this.Pawn.Faction)
                                {
                                    if (FactionUtility.HostileTo(this.Pawn.Faction, allPawns[i].Faction))
                                    {
                                        if (ModCheck.Validate.PrisonLabor.IsInitialized())
                                        {
                                            if (!allPawns[i].IsPrisoner)
                                            {
                                                this.target = allPawns[i];
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            this.target = allPawns[i];
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (this.target != null && this.Pawn.meleeVerbs.TryGetMeleeVerb(this.target.Thing) != null)
                {
                    Thing currentTargetThing = this.Pawn.CurJob.targetA.Thing;
                    if (currentTargetThing == null)
                    {
                        this.Pawn.TryStartAttack(this.target);
                    }
                }
                else
                {
                    this.shouldDespawn = true;
                }
            }
            catch (NullReferenceException)
            {
                //Log.Message("Error processing threats" + ex);
            }
        }
Ejemplo n.º 8
0
        public override void PostMapGenerate(Map map)
        {
            IncidentParms incidentParms = StorytellerUtility.DefaultParmsNow(Find.Storyteller.def, (IncidentCategory)3, map);

            incidentParms.forced = true;
            IntVec3 spawnCenter;

            if (RCellFinder.TryFindRandomPawnEntryCell(out spawnCenter, map, 0f, (IntVec3 v) => GenGrid.Standable(v, map)))
            {
                incidentParms.spawnCenter = spawnCenter;
            }
            Faction faction;

            if (GenCollection.TryRandomElement <Faction>(from f in Find.FactionManager.AllFactions
                                                         where !f.def.hidden && FactionUtility.HostileTo(f, Faction.OfPlayer)
                                                         select f, out faction))
            {
                IntVec3 spawnCenter2;
                if (CellFinder.TryFindRandomEdgeCellWith((IntVec3 c) => map.reachability.CanReachColony(c), map, 0f, out spawnCenter2))
                {
                    incidentParms.faction                 = Faction.OfMechanoids;
                    incidentParms.raidStrategy            = RaidStrategyDefOf.ImmediateAttack;
                    incidentParms.generateFightersOnly    = true;
                    incidentParms.raidNeverFleeIndividual = true;
                    incidentParms.raidArrivalMode         = PawnsArriveMode.CenterDrop;
                    incidentParms.spawnCenter             = spawnCenter2;
                    incidentParms.points *= 20f;
                    incidentParms.points  = Math.Max(incidentParms.points, 250f);
                    QueuedIncident queuedIncident = new QueuedIncident(new FiringIncident(TorannMagicDefOf.ArcaneEnemyRaid, null, incidentParms), Find.TickManager.TicksGame + Rand.RangeInclusive(500, 5000));
                    Find.Storyteller.incidentQueue.Add(queuedIncident);
                    System.Random random = new System.Random();
                    int           rnd    = GenMath.RoundRandom(random.Next(0, 10));
                    if (rnd < 5)
                    {
                        incidentParms.points = Math.Max(incidentParms.points * 2, 500f);
                        queuedIncident       = new QueuedIncident(new FiringIncident(TorannMagicDefOf.ArcaneEnemyRaid, null, incidentParms), Find.TickManager.TicksGame + Rand.RangeInclusive(2000, 3000));
                        Find.Storyteller.incidentQueue.Add(queuedIncident);
                    }
                    if (rnd < 3)
                    {
                        if (GenCollection.TryRandomElement <Faction>(from f in Find.FactionManager.AllFactions
                                                                     where !f.def.hidden && FactionUtility.HostileTo(f, Faction.OfPlayer)
                                                                     select f, out faction))
                        {
                            incidentParms.faction = faction;
                            incidentParms.points  = Math.Max(250f, 500f);
                            queuedIncident        = new QueuedIncident(new FiringIncident(TorannMagicDefOf.ArcaneEnemyRaid, null, incidentParms), Find.TickManager.TicksGame + Rand.RangeInclusive(5000, 10000));
                            Find.Storyteller.incidentQueue.Add(queuedIncident);
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        // Token: 0x06000018 RID: 24 RVA: 0x0000264C File Offset: 0x0000084C
        public bool KnowsOfTrap(Pawn p)
        {
            if (p.Faction != null && !FactionUtility.HostileTo(p.Faction, base.Faction))
            {
                return(true);
            }
            if (p.guest != null && p.guest.Released)
            {
                return(true);
            }
            Lord lord = LordUtility.GetLord(p);

            return(p.RaceProps.Humanlike && lord != null && lord.LordJob is LordJob_FormAndSendCaravan);
        }
Ejemplo n.º 10
0
        // Token: 0x06000043 RID: 67 RVA: 0x00004CA0 File Offset: 0x00002EA0
        private static bool GenAdminOption(Pawn patient, RecipeDef recipe, BodyPartRecord part = null)
        {
            bool result = false;

            if (patient != null)
            {
                Bill_Medical bill_Medical = new Bill_Medical(recipe);
                patient.BillStack.AddBill(bill_Medical);
                result            = true;
                bill_Medical.Part = part;
                if (recipe.conceptLearned != null)
                {
                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(recipe.conceptLearned, KnowledgeAmount.Total);
                }
                Pawn patient2 = patient;
                Map  map      = patient2?.Map;
                if (map != null)
                {
                    if (!map.mapPawns.FreeColonists.Any((Pawn col) => recipe.PawnSatisfiesSkillRequirements(col)))
                    {
                        Bill.CreateNoPawnsWithSkillDialog(recipe);
                    }
                    if (!RestUtility.InBed(patient) && patient.RaceProps.IsFlesh)
                    {
                        if (patient.RaceProps.Humanlike)
                        {
                            if (!GenCollection.Any(map.listerBuildings.allBuildingsColonist, (Building x) => x is Building_Bed bed && RestUtility.CanUseBedEver(patient, x.def) && bed.Medical))
                            {
                                Messages.Message(Translator.Translate("MessageNoMedicalBeds"), patient, MessageTypeDefOf.CautionInput, false);
                            }
                        }
                        else if (!GenCollection.Any <Building>(map.listerBuildings.allBuildingsColonist, (Building x) => x is Building_Bed && RestUtility.CanUseBedEver(patient, x.def)))
                        {
                            Messages.Message(Translator.Translate("MessageNoAnimalBeds"), patient, MessageTypeDefOf.CautionInput, false);
                        }
                    }
                    if (patient.Faction != null && !patient.Faction.def.hidden && !FactionUtility.HostileTo(patient.Faction, Faction.OfPlayer) && recipe.Worker.IsViolationOnPawn(patient, part, Faction.OfPlayer))
                    {
                        Messages.Message(TranslatorFormattedStringExtensions.Translate("MessageMedicalOperationWillAngerFaction", patient.Faction), patient, MessageTypeDefOf.CautionInput, false);
                    }
                    ThingDef minRequiredMedicine = MSAddDrugBill.GetMinRequiredMedicine(recipe);
                    if (minRequiredMedicine != null && patient.playerSettings != null && !MedicalCareUtility.AllowsMedicine(patient.playerSettings.medCare, minRequiredMedicine))
                    {
                        Messages.Message(TranslatorFormattedStringExtensions.Translate("MessageTooLowMedCare", minRequiredMedicine.label, patient.LabelShort, MedicalCareUtility.GetLabel(patient.playerSettings.medCare), NamedArgumentUtility.Named(patient, "PAWN")), patient, MessageTypeDefOf.CautionInput, false);
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 11
0
 private static IEnumerable <Pawn> DangerInPosRadius(Pawn pawn, IntVec3 position, Map map, float distance)
 {
     return(Enumerable.Where <Pawn>(map.mapPawns.AllPawns, (p => p.Position.InHorDistOf(position, distance) && !p.RaceProps.Animal && !p.Downed && !p.Dead && FactionUtility.HostileTo(p.Faction, pawn.Faction))));
 }
Ejemplo n.º 12
0
        private void ImpactSomething()
        {
            if (this.def.projectile.flyOverhead)
            {
                RoofDef roofDef = base.Map.roofGrid.RoofAt(base.Position);
                if (roofDef != null)
                {
                    if (roofDef.isThickRoof)
                    {
                        SoundStarter.PlayOneShot(this.def.projectile.soundHitThickRoof, new TargetInfo(base.Position, base.Map, false));
                        this.Destroy(0);
                        return;
                    }
                    if (GridsUtility.GetEdifice(base.Position, base.Map) == null || GridsUtility.GetEdifice(base.Position, base.Map).def.Fillage != FillCategory.Full)
                    {
                        RoofCollapserImmediate.DropRoofInCells(base.Position, base.Map, null);
                    }
                }
            }
            if (!this.usedTarget.HasThing || !base.CanHit(this.usedTarget.Thing))
            {
                List <Thing> list = new List <Thing>();
                list.Clear();
                List <Thing> thingList = GridsUtility.GetThingList(base.Position, base.Map);
                for (int i = 0; i < thingList.Count; i++)
                {
                    Thing thing = thingList[i];
                    if ((thing.def.category == ThingCategory.Building || thing.def.category == ThingCategory.Pawn || thing.def.category == ThingCategory.Item || thing.def.category == ThingCategory.Plant) && base.CanHit(thing))
                    {
                        list.Add(thing);
                    }
                }
                GenList.Shuffle <Thing>(list);
                for (int j = 0; j < list.Count; j++)
                {
                    Thing thing2 = list[j];
                    Pawn  pawn   = thing2 as Pawn;
                    float num;
                    if (pawn != null)
                    {
                        num = 0.5f * Mathf.Clamp(pawn.BodySize, 0.1f, 2f);
                        if (PawnUtility.GetPosture(pawn) != null && GenGeo.MagnitudeHorizontalSquared(this.origin - this.destination) >= 20.25f)
                        {
                            num *= 0.2f;
                        }
                        if (this.launcher != null && pawn.Faction != null && this.launcher.Faction != null && !FactionUtility.HostileTo(pawn.Faction, this.launcher.Faction))
                        {
                            num *= VerbUtility.InterceptChanceFactorFromDistance(this.origin, base.Position);
                        }
                    }
                    else
                    {
                        num = 1.5f * thing2.def.fillPercent;
                    }
                    if (Rand.Chance(num))
                    {
                        this.Impact(GenCollection.RandomElement <Thing>(list));
                        return;
                    }
                }
                this.Impact(null);
                return;
            }
            Pawn pawn2 = this.usedTarget.Thing as Pawn;

            if (pawn2 != null && PawnUtility.GetPosture(pawn2) != null && GenGeo.MagnitudeHorizontalSquared(this.origin - this.destination) >= 20.25f && !Rand.Chance(0.2f))
            {
                this.Impact(null);
                return;
            }
            this.Impact(this.usedTarget.Thing);
        }
Ejemplo n.º 13
0
        private static bool isFriendly(Pawn hunter, Pawn prey)
        {
            bool flag  = hunter.Faction == Faction.OfPlayer;
            bool flag2 = flag;
            bool result;

            if (flag2)
            {
                bool flag3 = prey == null;
                bool flag4 = flag3;
                if (flag4)
                {
                    result = (prey.Faction == Faction.OfPlayer || prey.def == hunter.def || prey.IsPrisonerOfColony || FactionUtility.HostileTo(prey.Faction, Faction.OfPlayer));
                }
                else
                {
                    result = (prey.Faction == Faction.OfPlayer || prey.Faction == Faction.OfPlayer || prey.IsPrisonerOfColony || FactionUtility.HostileTo(prey.Faction, Faction.OfPlayer));
                }
            }
            else
            {
                result = (prey.def == hunter.def);
            }
            return(result);
        }