Example #1
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map         map         = (Map)parms.target;
            PawnKindDef elderDragon = WyvernUtility.GetRandomElderDragonForEvent(map);

            if (elderDragon == null)
            {
                return(false);
            }
            IntVec3 intVec;

            if (!RCellFinder.TryFindRandomPawnEntryCell(out intVec, map, CellFinder.EdgeRoadChance_Animal, false, null))
            {
                return(false);
            }
            IntVec3 loc            = CellFinder.RandomClosewalkCellNear(intVec, map, 10, null);
            Pawn    newThing       = PawnGenerator.GeneratePawn(elderDragon, null);
            Pawn    newElderDragon = (Pawn)GenSpawn.Spawn(newThing, loc, map, WipeMode.Vanish);

            newElderDragon.needs.food.CurLevelPercentage = 1f;
            List <Pawn> wildlifeAnimals = map.mapPawns.AllPawnsSpawned.FindAll(p => p != newElderDragon && p.Faction == null && p.RaceProps.Animal && !p.health.Dead);

            foreach (Pawn wildlifeAnimal in wildlifeAnimals)
            {
                if (WyvernUtility.IsElderDragon(wildlifeAnimal))
                {
                    if (!WyvernUtility.IsSameSpecies(newElderDragon, wildlifeAnimal))
                    {
                        if (wildlifeAnimal.IsFighting())
                        {
                            continue;
                        }
                        if (newElderDragon.jobs.TryTakeOrderedJob(new Job(JobDefOf.AttackMelee, wildlifeAnimal)))
                        {
                            Messages.Message("TurfWarLabel".Translate().CapitalizeFirst(), newElderDragon, MessageTypeDefOf.NeutralEvent);
                        }
                        if (wildlifeAnimal.jobs.TryTakeOrderedJob(new Job(JobDefOf.AttackMelee, newElderDragon)))
                        {
                            Messages.Message("TurfWarLabel".Translate().CapitalizeFirst(), wildlifeAnimal, MessageTypeDefOf.NeutralEvent);
                        }
                    }
                    continue;
                }
                if (Rand.Chance(0.2f) || LoadedModManager.GetMod <MonsterHunterRimworldMod>().GetSettings <MonsterHunterRimworldModSettings>().elderDragonScareAnimals)
                {
                    continue;                                                                                                                                                   // animals will flee with a 80% chance
                }
                JobGiver_ExitMapPanic jobFlee     = new JobGiver_ExitMapPanic();
                ThinkResult           thinkResult = jobFlee.TryIssueJobPackage(wildlifeAnimal, new JobIssueParams()
                {
                    maxDistToSquadFlag = 500
                });
                wildlifeAnimal.jobs.TryTakeOrderedJob(thinkResult.Job);
            }
            Find.LetterStack.ReceiveLetter("LetterLabelElderDragonAppear".Translate(), "LetterTextElderDragonAppear".Translate(newElderDragon.Label.CapitalizeFirst()), LetterDefOf.ThreatSmall, new TargetInfo(intVec, map, false), null, null);
            return(true);
        }
Example #2
0
        public override void CompTickRare()
        {
            base.CompTickRare();


            if (!(parent is Pawn largeMonster))
            {
                return;
            }
            if (largeMonster.Faction != null)
            {
                return;
            }
            Map map = largeMonster.Map;

            if (map == null)
            {
                return;
            }
            if (largeMonster.IsFighting() || largeMonster.Downed || largeMonster.Dead)
            {
                return;
            }

            List <Pawn> possibleTargetsToFight = map.mapPawns.AllPawnsSpawned.FindAll(p => p.RaceProps.Animal && p.Faction == null && !p.IsFighting() && !p.Downed && !p.Dead && !WyvernUtility.IsSameSpecies(p, largeMonster) && p.Position.DistanceTo(largeMonster.Position) < Props.maxFightRange && p.TryGetComp <CompTurfWar>() != null);

            if (possibleTargetsToFight.Count == 0)
            {
                return;
            }
            Pawn targetToFight = possibleTargetsToFight.RandomElement();

            if (largeMonster.jobs.TryTakeOrderedJob(new Job(JobDefOf.AttackMelee, targetToFight)))
            {
                Messages.Message("TurfWarLabel".Translate().CapitalizeFirst(), largeMonster, MessageTypeDefOf.NeutralEvent);
            }
            if (targetToFight.jobs.TryTakeOrderedJob(new Job(JobDefOf.AttackMelee, largeMonster)))
            {
                Messages.Message("TurfWarLabel".Translate().CapitalizeFirst(), targetToFight, MessageTypeDefOf.NeutralEvent);
            }
        }