Ejemplo n.º 1
0
 // Token: 0x06002241 RID: 8769 RVA: 0x00101EB8 File Offset: 0x001002B8
 public override IEnumerable <Thing> PlayerStartingThings()
 {
     for (int i = 0; i < this.count; i++)
     {
         PawnKindDef kind;
         if (this.animalKind != null)
         {
             kind = this.animalKind;
         }
         else
         {
             kind = this.RandomPets().RandomElementByWeight((PawnKindDef td) => td.RaceProps.petness);
         }
         Pawn animal = PawnGenerator.GeneratePawn(kind, Faction.OfPlayer);
         if (animal.Name == null || animal.Name.Numerical)
         {
             animal.Name = PawnBioAndNameGenerator.GeneratePawnName(animal, NameStyle.Full, null);
         }
         Rand.PushState();
         if (Rand.Value < this.bondToRandomPlayerPawnChance && animal.training.CanAssignToTrain(TrainableDefOf.Obedience).Accepted)
         {
             Pawn pawn = (from p in Find.GameInitData.startingAndOptionalPawns.Take(Find.GameInitData.startingPawnCount)
                          where TrainableUtility.CanBeMaster(p, animal, false) && !p.story.traits.HasTrait(TraitDefOf.Psychopath)
                          select p).RandomElementWithFallback(null);
             if (pawn != null)
             {
                 animal.training.Train(TrainableDefOf.Obedience, null, true);
                 animal.training.SetWantedRecursive(TrainableDefOf.Obedience, true);
                 pawn.relations.AddDirectRelation(PawnRelationDefOf.Bond, animal);
                 animal.playerSettings.Master = pawn;
             }
         }
         Rand.PopState();
         if (gender != Gender.None)
         {
             animal.gender = gender;
         }
         yield return(animal);
     }
     yield break;
 }
Ejemplo n.º 2
0
        public Pawn GetMaster(Pawn animal, MasterMode mode)
        {
            var master  = animal.playerSettings.Master;
            var options = animal.kindDef.GetMasterOptions(manager, mode);

            // if the animal is bonded, and we care about bonds, there's no discussion
            if (RespectBonds)
            {
                var bondee = animal.relations.GetFirstDirectRelationPawn(PawnRelationDefOf.Bond, p => !p.Dead);
                if (bondee != null && TrainableUtility.CanBeMaster(bondee, animal))
                {
                    return(bondee);
                }
            }

            Logger.Follow(
                $"Getting master for {animal.LabelShort}:\n\tcurrent: {master?.LabelShort ?? "None"}\n\toptions:\n");
#if DEBUG_FOLLOW
            foreach (var option in options)
            {
                Logger.Follow($"\t\t{option.LabelShort}\n");
            }
#endif

            // cop out if no options
            if (options.NullOrEmpty())
            {
                return(null);
            }

            // if we currently have a master, our current master is a valid option,
            // and all the options have roughly equal amounts of pets following them, we don't need to take action
            if (master != null && options.Contains(master) && RoughlyEquallyDistributed(options))
            {
                return(master);
            }

            // otherwise, assign a master that has the least amount of current followers.
            return(options.MinBy(p => p.GetFollowers().Count));
        }