コード例 #1
0
        private void CheckTerrain()
        {
            var selTrait = this.parent.pawn.story.traits.allTraits.FirstOrDefault(trait => trait.def == RSDefOf.RSTraitWinter || trait.def == RSDefOf.RSTraitDesert || trait.def == RSDefOf.RSTraitForest);

            if (selTrait == null)
            {
                return;
            }
            var apply      = false;
            var selTerrain = selTrait.def == RSDefOf.RSTraitWinter ? allowedTerrain : allowedTerrainSand;
            var selBiomes  = selTrait.def == RSDefOf.RSTraitWinter ? allowedBiomes : allowedBiomesSand;

            if (selTrait.def == RSDefOf.RSTraitForest)
            {
                if (this.parent.pawn.Map == null && allowedBiomesForest.Contains(Find.WorldGrid.tiles[this.parent.pawn.Tile].biome) ||
                    (this.parent.pawn.Map != null && allowedBiomesForest.Contains(Find.WorldGrid.tiles[this.parent.pawn.Tile].biome) &&
                     (allowedTerrainForest.Contains(this.parent.pawn.Position.GetTerrain(this.parent.pawn.Map)))))
                {
                    apply = true;
                }
            }
            else if (this.parent.pawn.Map == null && selBiomes.Contains(Find.WorldGrid.tiles[this.parent.pawn.Tile].biome) ||
                     (this.parent.pawn.Map != null && (selTerrain.Contains(this.parent.pawn.Position.GetTerrain(this.parent.pawn.Map)) ||
                                                       (selTrait.def == RSDefOf.RSTraitWinter && parent.pawn.Map.snowGrid.TotalDepth > 100f))))
            {
                apply = true;
            }

            if (apply)
            {
                if (!this.parent.pawn.health.hediffSet.HasHediff(RSDefOf.RSTerrainAdvantage))
                {
                    foreach (var leg in PeacekeeperUtility.GetLegs(parent.pawn))
                    {
                        var hediff = HediffMaker.MakeHediff(RSDefOf.RSTerrainAdvantage, parent.pawn);
                        this.parent.pawn.health.AddHediff(hediff, leg);
                    }
                }
            }
            else
            {
                if (this.parent.pawn.health.hediffSet.HasHediff(RSDefOf.RSTerrainAdvantage))
                {
                    this.parent.pawn.health.hediffSet.hediffs.RemoveAll(hediff => hediff.def == RSDefOf.RSTerrainAdvantage);
                }
            }
        }