コード例 #1
0
        public void RandomizeTraits(CustomPawn customPawn)
        {
            Pawn         pawn   = GenerateSameKindOfColonist(customPawn);
            List <Trait> traits = pawn.story.traits.allTraits;

            if (traits.Count > 0)
            {
                customPawn.SetTrait(0, traits[0]);
            }
            else
            {
                customPawn.SetTrait(0, null);
            }
            if (traits.Count > 1 && customPawn.GetTrait(0) != traits[1])
            {
                customPawn.SetTrait(1, traits[1]);
            }
            else
            {
                customPawn.SetTrait(1, null);
            }
            if (traits.Count > 2 && customPawn.GetTrait(0) != traits[2] && customPawn.GetTrait(1) != traits[2])
            {
                customPawn.SetTrait(2, traits[2]);
            }
            else
            {
                customPawn.SetTrait(2, null);
            }
        }
コード例 #2
0
        protected void SelectPreviousTrait(CustomPawn customPawn, int traitIndex)
        {
            Trait currentTrait = customPawn.GetTrait(traitIndex);

            ComputeDisallowedTraits(customPawn, currentTrait);
            int index = -1;

            if (currentTrait != null)
            {
                index = providerTraits.Traits.FindIndex((Trait t) => {
                    return(t.Label.Equals(currentTrait.Label));
                });
            }
            int count = 0;

            do
            {
                index--;
                if (index < 0)
                {
                    index = providerTraits.Traits.Count - 1;
                }
                if (++count > providerTraits.Traits.Count + 1)
                {
                    index = -1;
                    break;
                }
            }while (index != -1 && (customPawn.HasTrait(providerTraits.Traits[index]) || disallowedTraitDefs.Contains(providerTraits.Traits[index].def)));

            Trait newTrait = null;

            if (index > -1)
            {
                newTrait = providerTraits.Traits[index];
            }
            TraitUpdated(traitIndex, newTrait);
        }