Esempio n. 1
0
        public static Region MakeNewUnfilled(IntVec3 root, Map map)
        {
            Region obj = new Region
            {
                debug_makeTick = Find.TickManager.TicksGame,
                id             = nextId
            };

            nextId++;
            obj.mapIndex = (sbyte)map.Index;
            obj.precalculatedHashCode = Gen.HashCombineInt(obj.id, 1295813358);
            obj.extentsClose.minX     = root.x;
            obj.extentsClose.maxX     = root.x;
            obj.extentsClose.minZ     = root.z;
            obj.extentsClose.maxZ     = root.z;
            obj.extentsLimit.minX     = root.x - root.x % 12;
            obj.extentsLimit.maxX     = root.x + 12 - (root.x + 12) % 12 - 1;
            obj.extentsLimit.minZ     = root.z - root.z % 12;
            obj.extentsLimit.maxZ     = root.z + 12 - (root.z + 12) % 12 - 1;
            obj.extentsLimit.ClipInsideMap(map);
            return(obj);
        }
Esempio n. 2
0
        public float ImmunityChangePerTick(Pawn pawn, bool sick, Hediff diseaseInstance)
        {
            if (!pawn.RaceProps.IsFlesh)
            {
                return(0f);
            }
            HediffCompProperties_Immunizable hediffCompProperties_Immunizable = this.hediffDef.CompProps <HediffCompProperties_Immunizable>();

            if (sick)
            {
                float num = hediffCompProperties_Immunizable.immunityPerDaySick;
                num *= pawn.GetStatValue(StatDefOf.ImmunityGainSpeed, true);
                if (diseaseInstance != null)
                {
                    Rand.PushState();
                    Rand.Seed = Gen.HashCombineInt(diseaseInstance.loadID ^ Find.World.info.persistentRandomValue, 156482735);
                    num      *= Mathf.Lerp(0.8f, 1.2f, Rand.Value);
                    Rand.PopState();
                }
                return(num / 60000f);
            }
            return(hediffCompProperties_Immunizable.immunityPerDayNotSick / 60000f);
        }
Esempio n. 3
0
        public float ImmunityChangePerTick(Pawn pawn, bool sick, Hediff diseaseInstance)
        {
            if (!pawn.RaceProps.IsFlesh)
            {
                return(0f);
            }
            HediffCompProperties_Immunizable hediffCompProperties_Immunizable = this.hediffDef.CompProps <HediffCompProperties_Immunizable>();
            float num = (!sick) ? hediffCompProperties_Immunizable.immunityPerDayNotSick : hediffCompProperties_Immunizable.immunityPerDaySick;

            num /= 60000f;
            float num2 = pawn.GetStatValue(StatDefOf.ImmunityGainSpeed, true);

            if (diseaseInstance != null)
            {
                int value = Gen.HashCombineInt(diseaseInstance.GetHashCode(), 156482735);
                num2 *= Mathf.Lerp(0.8f, 1.2f, (float)Mathf.Abs(value) / 2.14748365E+09f);
            }
            if (num > 0f)
            {
                return(num * num2);
            }
            return(num / num2);
        }
Esempio n. 4
0
 public static void GenerateContentsIntoMap(IEnumerable <GenStepWithParams> genStepDefs, Map map, int seed)
 {
     data.Clear();
     Rand.PushState();
     try
     {
         Rand.Seed = seed;
         RockNoises.Init(map);
         tmpGenSteps.Clear();
         tmpGenSteps.AddRange(from x in genStepDefs
                              orderby x.def.order, x.def.index
                              select x);
         for (int i = 0; i < tmpGenSteps.Count; i++)
         {
             DeepProfiler.Start("GenStep - " + tmpGenSteps[i].def);
             try
             {
                 Rand.Seed = Gen.HashCombineInt(seed, GetSeedPart(tmpGenSteps, i));
                 tmpGenSteps[i].def.genStep.Generate(map, tmpGenSteps[i].parms);
             }
             catch (Exception arg)
             {
                 Log.Error("Error in GenStep: " + arg);
             }
             finally
             {
                 DeepProfiler.End();
             }
         }
     }
     finally
     {
         Rand.PopState();
         RockNoises.Reset();
         data.Clear();
     }
 }
Esempio n. 5
0
		public static string Translate(this string key, params object[] args)
		{
			if (key.NullOrEmpty())
			{
				return key;
			}
			if (LanguageDatabase.activeLanguage == null)
			{
				Log.Error("No active language! Cannot translate from key " + key + ".", false);
				return key;
			}
			string text;
			if (!LanguageDatabase.activeLanguage.TryGetTextFromKey(key, out text))
			{
				LanguageDatabase.defaultLanguage.TryGetTextFromKey(key, out text);
				if (Prefs.DevMode)
				{
					text = Translator.PseudoTranslated(text);
				}
			}
			string result = text;
			try
			{
				result = string.Format(text, args);
			}
			catch (Exception ex)
			{
				Log.ErrorOnce(string.Concat(new object[]
				{
					"Exception translating '",
					text,
					"': ",
					ex
				}), Gen.HashCombineInt(key.GetHashCode(), 394878901), false);
			}
			return result;
		}
Esempio n. 6
0
        public void Draw(int xOffset, int yOffset)
        {
            Rect rect = this.CalculateRect((float)xOffset, (float)yOffset);

            Find.WindowStack.ImmediateWindow(Gen.HashCombineInt(this.ID, 45574281), rect, WindowLayer.Super, delegate
            {
                Text.Font   = GameFont.Small;
                Text.Anchor = TextAnchor.MiddleLeft;
                Rect rect   = rect.AtZero();
                float alpha = this.Alpha;
                GUI.color   = new Color(1f, 1f, 1f, alpha);
                if (Message.ShouldDrawBackground)
                {
                    GUI.color = new Color(0.15f, 0.15f, 0.15f, 0.8f * alpha);
                    GUI.DrawTexture(rect, BaseContent.WhiteTex);
                    GUI.color = new Color(1f, 1f, 1f, alpha);
                }
                if (CameraJumper.CanJump(this.lookTargets.TryGetPrimaryTarget()))
                {
                    UIHighlighter.HighlightOpportunity(rect, "Messages");
                    Widgets.DrawHighlightIfMouseover(rect);
                }
                Rect rect2 = new Rect(2f, 0f, rect.width - 2f, rect.height);
                Widgets.Label(rect2, this.text);
                if (Current.ProgramState == ProgramState.Playing && CameraJumper.CanJump(this.lookTargets.TryGetPrimaryTarget()) && Widgets.ButtonInvisible(rect, false))
                {
                    CameraJumper.TryJumpAndSelect(this.lookTargets.TryGetPrimaryTarget());
                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.ClickingMessages, KnowledgeAmount.Total);
                }
                Text.Anchor = TextAnchor.UpperLeft;
                GUI.color   = Color.white;
                if (Mouse.IsOver(rect))
                {
                    Messages.Notify_Mouseover(this);
                }
            }, false, false, 0f);
        }
Esempio n. 7
0
 public void Launch(Thing launcher, Vector3 origin, LocalTargetInfo usedTarget, LocalTargetInfo intendedTarget, ProjectileHitFlags hitFlags, Thing equipment = null, ThingDef targetCoverDef = null)
 {
     this.launcher       = launcher;
     this.origin         = origin;
     this.usedTarget     = usedTarget;
     this.intendedTarget = intendedTarget;
     this.targetCoverDef = targetCoverDef;
     this.HitFlags       = hitFlags;
     if (equipment != null)
     {
         this.equipmentDef = equipment.def;
     }
     else
     {
         this.equipmentDef = null;
     }
     this.destination   = usedTarget.Cell.ToVector3Shifted() + Gen.RandomHorizontalVector(0.3f);
     this.ticksToImpact = this.StartingTicksToImpact;
     if (!this.def.projectile.soundAmbient.NullOrUndefined())
     {
         SoundInfo info = SoundInfo.InMap(this, MaintenanceType.PerTick);
         this.ambientSustainer = this.def.projectile.soundAmbient.TrySpawnSustainer(info);
     }
 }
        public static Graphic GhostGraphicFor(Graphic baseGraphic, ThingDef thingDef, Color ghostCol)
        {
            if (thingDef.useSameGraphicForGhost)
            {
                return(baseGraphic);
            }
            int seed = 0;

            seed = Gen.HashCombine(seed, baseGraphic);
            seed = Gen.HashCombine(seed, thingDef);
            seed = Gen.HashCombineStruct(seed, ghostCol);
            if (!ghostGraphics.TryGetValue(seed, out var value))
            {
                if (thingDef.graphicData.Linked || thingDef.IsDoor)
                {
                    value = GraphicDatabase.Get <Graphic_Single>(thingDef.uiIconPath, ShaderTypeDefOf.EdgeDetect.Shader, thingDef.graphicData.drawSize, ghostCol);
                }
                else
                {
                    if (baseGraphic == null)
                    {
                        baseGraphic = thingDef.graphic;
                    }
                    GraphicData graphicData = null;
                    if (baseGraphic.data != null)
                    {
                        graphicData = new GraphicData();
                        graphicData.CopyFrom(baseGraphic.data);
                        graphicData.shadowData = null;
                    }
                    value = GraphicDatabase.Get(baseGraphic.GetType(), baseGraphic.path, ShaderTypeDefOf.EdgeDetect.Shader, baseGraphic.drawSize, ghostCol, Color.white, graphicData, null);
                }
                ghostGraphics.Add(seed, value);
            }
            return(value);
        }
Esempio n. 9
0
 public override int GetHashCode()
 {
     return(Gen.HashCombineStruct(min.GetHashCode(), max));
 }
Esempio n. 10
0
 public override int GetHashCode()
 {
     return(Gen.HashCombineInt(this.ID, 1538478890));
 }
 public override int GetHashCode()
 {
     return(Gen.HashCombineStruct(Gen.HashCombineStruct(Gen.HashCombine(0, path), color), colorTwo));
 }
 public override int GetHashCode()
 {
     return(Gen.HashCombineInt(this.mat.GetHashCode(), this.alphaIndex));
 }
Esempio n. 13
0
 public override int GetHashCode()
 {
     return(Gen.HashCombineInt(min, max));
 }
Esempio n. 14
0
 public override int GetHashCode()
 {
     return(Gen.HashCombineInt(Gen.HashCombineInt(Gen.HashCombineInt(Gen.HashCombineInt(0, minX), maxX), minZ), maxZ));
 }
Esempio n. 15
0
 public override int GetHashCode()
 {
     return(Gen.HashCombineInt(this.nameInt.GetHashCode(), 1384661390));
 }
Esempio n. 16
0
        public override bool TryAdd(Thing item, bool canMergeWithExistingStacks = true)
        {
            if (item == null)
            {
                Log.Warning("Tried to add null item to ThingOwner.");
                return(false);
            }
            T val = (T)(item as T);

            if (val == null)
            {
                return(false);
            }
            if (base.Contains(item))
            {
                Log.Warning("Tried to add " + Gen.ToStringSafe <Thing>(item) + " to ThingOwner but this item is already here.");
                return(false);
            }
            if (item.holdingOwner != null)
            {
                Log.Warning("Tried to add " + Gen.ToStringSafe <Thing>(item) + " to ThingOwner but this thing is already in another container. owner=" + Gen.ToStringSafe <IThingHolder>(base.owner) + ", current container owner=" + Gen.ToStringSafe <IThingHolder>(item.holdingOwner.Owner) + ". Use TryAddOrTransfer, TryTransferToContainer, or remove the item before adding it.");
                return(false);
            }
            if (!this.CanAcceptAnyOf(item, canMergeWithExistingStacks))
            {
                return(false);
            }
            if (canMergeWithExistingStacks)
            {
                for (int i = 0; i < this.innerList.Count; i++)
                {
                    T val2 = this.innerList[i];
                    if (val2.CanStackWith(item))
                    {
                        int num = Mathf.Min(item.stackCount, ((Thing)(object)val2).def.stackLimit - ((Thing)(object)val2).stackCount);
                        if (num > 0)
                        {
                            Thing other      = item.SplitOff(num);
                            int   stackCount = ((Thing)(object)val2).stackCount;
                            val2.TryAbsorbStack(other, true);
                            if (((Thing)(object)val2).stackCount > stackCount)
                            {
                                base.NotifyAddedAndMergedWith((Thing)(object)val2, ((Thing)(object)val2).stackCount - stackCount);
                            }
                            if (!item.Destroyed && item.stackCount != 0)
                            {
                                continue;
                            }
                            return(true);
                        }
                    }
                }
            }
            if (this.Count >= base.maxStacks)
            {
                return(false);
            }
            item.holdingOwner = this;
            this.innerList.Add(val);
            base.NotifyAdded((Thing)(object)val);
            return(true);
        }
Esempio n. 17
0
        public override int TryAdd(Thing item, int count, bool canMergeWithExistingStacks = true)
        {
            if (count <= 0)
            {
                return(0);
            }
            if (item == null)
            {
                Log.Warning("Tried to add null item to ThingOwner.");
                return(0);
            }
            if (base.Contains(item))
            {
                Log.Warning("Tried to add " + item + " to ThingOwner but this item is already here.");
                return(0);
            }
            if (item.holdingOwner != null)
            {
                Log.Warning("Tried to add " + count + " of " + Gen.ToStringSafe <Thing>(item) + " to ThingOwner but this thing is already in another container. owner=" + Gen.ToStringSafe <IThingHolder>(base.owner) + ", current container owner=" + Gen.ToStringSafe <IThingHolder>(item.holdingOwner.Owner) + ". Use TryAddOrTransfer, TryTransferToContainer, or remove the item before adding it.");
                return(0);
            }
            if (!this.CanAcceptAnyOf(item, canMergeWithExistingStacks))
            {
                return(0);
            }
            int   stackCount = item.stackCount;
            int   num        = Mathf.Min(stackCount, count);
            Thing thing      = item.SplitOff(num);

            if (!this.TryAdd((Thing)(object)(T)thing, canMergeWithExistingStacks))
            {
                if (thing != item)
                {
                    int result = stackCount - item.stackCount - thing.stackCount;
                    item.TryAbsorbStack(thing, false);
                    return(result);
                }
                return(stackCount - item.stackCount);
            }
            return(num);
        }
Esempio n. 18
0
 public static int RandSeedForHour(this Thing t, int salt)
 {
     return(Gen.HashCombineInt(Gen.HashCombineInt(t.HashOffset(), Find.TickManager.TicksAbs / 2500), salt));
 }
Esempio n. 19
0
 public override int GetHashCode()
 {
     return(Gen.HashCombineStruct(Gen.HashCombineInt(FirstRoomID, SecondRoomID), TraverseParms));
 }
Esempio n. 20
0
 public static int HashOffset(this int baseInt)
 {
     return(Gen.HashCombineInt(baseInt, 169495093));
 }
Esempio n. 21
0
 protected virtual void ExplosionVisualEffectCenter(Explosion explosion)
 {
     for (int i = 0; i < 4; i++)
     {
         MoteMaker.ThrowSmoke(explosion.Position.ToVector3Shifted() + Gen.RandomHorizontalVector(explosion.radius * 0.7f), explosion.Map, explosion.radius * 0.6f);
     }
     if (this.def.explosionInteriorMote != null)
     {
         int num = Mathf.RoundToInt(3.14159274f * explosion.radius * explosion.radius / 6f);
         for (int j = 0; j < num; j++)
         {
             MoteMaker.ThrowExplosionInteriorMote(explosion.Position.ToVector3Shifted() + Gen.RandomHorizontalVector(explosion.radius * 0.7f), explosion.Map, this.def.explosionInteriorMote);
         }
     }
 }
Esempio n. 22
0
 public override int GetHashCode()
 {
     return(Gen.HashCombineStruct <float>(this.min.GetHashCode(), this.max));
 }
Esempio n. 23
0
        private static void DropRoofInCellPhaseOne(IntVec3 c, Map map, List <Thing> outCrushedThings)
        {
            RoofDef roofDef = map.roofGrid.RoofAt(c);

            if (roofDef != null)
            {
                if (roofDef.collapseLeavingThingDef != null && roofDef.collapseLeavingThingDef.passability == Traversability.Impassable)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        List <Thing> thingList = c.GetThingList(map);
                        for (int num = thingList.Count - 1; num >= 0; num--)
                        {
                            Thing thing = thingList[num];
                            TryAddToCrushedThingsList(thing, outCrushedThings);
                            Pawn       pawn  = thing as Pawn;
                            DamageInfo dinfo = default(DamageInfo);
                            if (pawn != null)
                            {
                                DamageDef      crush            = DamageDefOf.Crush;
                                float          amount           = 99999f;
                                float          armorPenetration = 999f;
                                BodyPartRecord brain            = pawn.health.hediffSet.GetBrain();
                                dinfo = new DamageInfo(crush, amount, armorPenetration, -1f, null, brain, null, DamageInfo.SourceCategory.Collapse);
                            }
                            else
                            {
                                dinfo = new DamageInfo(DamageDefOf.Crush, 99999f, 999f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse);
                                dinfo.SetBodyRegion(BodyPartHeight.Top, BodyPartDepth.Outside);
                            }
                            BattleLogEntry_DamageTaken battleLogEntry_DamageTaken = null;
                            if (i == 0 && pawn != null)
                            {
                                battleLogEntry_DamageTaken = new BattleLogEntry_DamageTaken(pawn, RulePackDefOf.DamageEvent_Ceiling);
                                Find.BattleLog.Add(battleLogEntry_DamageTaken);
                            }
                            thing.TakeDamage(dinfo).AssociateWithLog(battleLogEntry_DamageTaken);
                            if (!thing.Destroyed && thing.def.destroyable)
                            {
                                thing.Kill(new DamageInfo(DamageDefOf.Crush, 99999f, 999f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse));
                            }
                        }
                    }
                }
                else
                {
                    List <Thing> thingList2 = c.GetThingList(map);
                    for (int num2 = thingList2.Count - 1; num2 >= 0; num2--)
                    {
                        Thing thing2 = thingList2[num2];
                        if (thing2.def.category == ThingCategory.Item || thing2.def.category == ThingCategory.Plant || thing2.def.category == ThingCategory.Building || thing2.def.category == ThingCategory.Pawn)
                        {
                            TryAddToCrushedThingsList(thing2, outCrushedThings);
                            float num3 = (float)ThinRoofCrushDamageRange.RandomInRange;
                            if (thing2.def.building != null)
                            {
                                num3 *= thing2.def.building.roofCollapseDamageMultiplier;
                            }
                            BattleLogEntry_DamageTaken battleLogEntry_DamageTaken2 = null;
                            if (thing2 is Pawn)
                            {
                                battleLogEntry_DamageTaken2 = new BattleLogEntry_DamageTaken((Pawn)thing2, RulePackDefOf.DamageEvent_Ceiling);
                                Find.BattleLog.Add(battleLogEntry_DamageTaken2);
                            }
                            DamageInfo dinfo2 = new DamageInfo(DamageDefOf.Crush, (float)GenMath.RoundRandom(num3), 0f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse);
                            dinfo2.SetBodyRegion(BodyPartHeight.Top, BodyPartDepth.Outside);
                            thing2.TakeDamage(dinfo2).AssociateWithLog(battleLogEntry_DamageTaken2);
                        }
                    }
                }
                if (roofDef.collapseLeavingThingDef != null)
                {
                    Thing thing3 = GenSpawn.Spawn(roofDef.collapseLeavingThingDef, c, map);
                    if (thing3.def.rotatable)
                    {
                        thing3.Rotation = Rot4.Random;
                    }
                }
                for (int j = 0; j < 1; j++)
                {
                    Vector3 a = c.ToVector3Shifted();
                    a += Gen.RandomHorizontalVector(0.6f);
                    MoteMaker.ThrowDustPuff(a, map, 2f);
                }
            }
        }
Esempio n. 24
0
 public override int GetHashCode()
 {
     return(Gen.HashCombineInt(this.x, this.z));
 }
Esempio n. 25
0
            public override int GetHashCode()
            {
                int seed = Gen.HashCombineInt(this.FirstRoomID, this.SecondRoomID);

                return(Gen.HashCombineStruct <TraverseParms>(seed, this.TraverseParms));
            }
Esempio n. 26
0
        public void Update()
        {
            if (LongEventHandler.ShouldWaitForEvent)
            {
                if (Current.SubcameraDriver != null)
                {
                    Current.SubcameraDriver.UpdatePositions(this.MyCamera);
                }
                return;
            }
            if (Find.CurrentMap == null)
            {
                return;
            }
            Vector2 lhs = this.CalculateCurInputDollyVect();

            if (lhs != Vector2.zero)
            {
                float d = (this.rootSize - 11f) / 49f * 0.7f + 0.3f;
                this.velocity = new Vector3(lhs.x, 0f, lhs.y) * d;
                PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.CameraDolly, KnowledgeAmount.FrameInteraction);
            }
            if (!this.AnythingPreventsCameraMotion)
            {
                float d2 = Time.deltaTime * CameraDriver.HitchReduceFactor;
                this.rootPos  += this.velocity * d2 * this.config.moveSpeedScale;
                this.rootPos.x = Mathf.Clamp(this.rootPos.x, 2f, (float)Find.CurrentMap.Size.x + -2f);
                this.rootPos.z = Mathf.Clamp(this.rootPos.z, 2f, (float)Find.CurrentMap.Size.z + -2f);
            }
            int num = Gen.FixedTimeStepUpdate(ref this.fixedTimeStepBuffer, 60f);

            for (int i = 0; i < num; i++)
            {
                if (this.velocity != Vector3.zero)
                {
                    this.velocity *= this.config.camSpeedDecayFactor;
                    if (this.velocity.magnitude < 0.1f)
                    {
                        this.velocity = Vector3.zero;
                    }
                }
                if (this.config.smoothZoom)
                {
                    float num2 = Mathf.Lerp(this.rootSize, this.desiredSize, 0.05f);
                    this.desiredSize += (num2 - this.rootSize) * this.config.zoomPreserveFactor;
                    this.rootSize     = num2;
                }
                else
                {
                    float num3 = this.desiredSize - this.rootSize;
                    float num4 = num3 * 0.4f;
                    this.desiredSize += this.config.zoomPreserveFactor * num4;
                    this.rootSize    += num4;
                }
                this.config.ConfigFixedUpdate_60(ref this.velocity);
            }
            this.shaker.Update();
            this.ApplyPositionToGameObject();
            Current.SubcameraDriver.UpdatePositions(this.MyCamera);
            if (Find.CurrentMap != null)
            {
                RememberedCameraPos rememberedCameraPos = Find.CurrentMap.rememberedCameraPos;
                rememberedCameraPos.rootPos  = this.rootPos;
                rememberedCameraPos.rootSize = this.rootSize;
            }
        }
 public void HealthTick()
 {
     if (!this.Dead)
     {
         for (int i = this.hediffSet.hediffs.Count - 1; i >= 0; i--)
         {
             Hediff hediff = this.hediffSet.hediffs[i];
             try
             {
                 hediff.Tick();
                 hediff.PostTick();
             }
             catch (Exception ex)
             {
                 Log.Error(string.Concat(new object[]
                 {
                     "Exception ticking hediff ",
                     hediff.ToStringSafe <Hediff>(),
                     " for pawn ",
                     this.pawn.ToStringSafe <Pawn>(),
                     ". Removing hediff... Exception: ",
                     ex
                 }), false);
                 try
                 {
                     this.RemoveHediff(hediff);
                 }
                 catch (Exception arg)
                 {
                     Log.Error("Error while removing hediff: " + arg, false);
                 }
             }
         }
         bool flag = false;
         for (int j = this.hediffSet.hediffs.Count - 1; j >= 0; j--)
         {
             Hediff hediff2 = this.hediffSet.hediffs[j];
             if (hediff2.ShouldRemove)
             {
                 this.hediffSet.hediffs.RemoveAt(j);
                 hediff2.PostRemoved();
                 flag = true;
             }
         }
         if (flag)
         {
             this.Notify_HediffChanged(null);
         }
         if (!this.Dead)
         {
             this.immunity.ImmunityHandlerTick();
             if (this.pawn.RaceProps.IsFlesh && this.pawn.IsHashIntervalTick(600) && (this.pawn.needs.food == null || !this.pawn.needs.food.Starving))
             {
                 bool flag2 = false;
                 if (this.hediffSet.HasNaturallyHealingInjury())
                 {
                     float num = 8f;
                     if (this.pawn.GetPosture() != PawnPosture.Standing)
                     {
                         num += 4f;
                         Building_Bed building_Bed = this.pawn.CurrentBed();
                         if (building_Bed != null)
                         {
                             num += building_Bed.def.building.bed_healPerDay;
                         }
                     }
                     Hediff_Injury hediff_Injury = (from x in this.hediffSet.GetHediffs <Hediff_Injury>()
                                                    where x.CanHealNaturally()
                                                    select x).RandomElement <Hediff_Injury>();
                     hediff_Injury.Heal(num * this.pawn.HealthScale * 0.01f);
                     flag2 = true;
                 }
                 if (this.hediffSet.HasTendedAndHealingInjury() && (this.pawn.needs.food == null || !this.pawn.needs.food.Starving))
                 {
                     Hediff_Injury hediff_Injury2 = (from x in this.hediffSet.GetHediffs <Hediff_Injury>()
                                                     where x.CanHealFromTending()
                                                     select x).RandomElement <Hediff_Injury>();
                     float tendQuality = hediff_Injury2.TryGetComp <HediffComp_TendDuration>().tendQuality;
                     float num2        = GenMath.LerpDouble(0f, 1f, 0.5f, 1.5f, Mathf.Clamp01(tendQuality));
                     hediff_Injury2.Heal(22f * num2 * this.pawn.HealthScale * 0.01f);
                     flag2 = true;
                 }
                 if (flag2 && !this.HasHediffsNeedingTendByPlayer(false) && !HealthAIUtility.ShouldSeekMedicalRest(this.pawn) && !this.hediffSet.HasTendedAndHealingInjury() && PawnUtility.ShouldSendNotificationAbout(this.pawn))
                 {
                     Messages.Message("MessageFullyHealed".Translate(new object[]
                     {
                         this.pawn.LabelCap
                     }), this.pawn, MessageTypeDefOf.PositiveEvent, true);
                 }
             }
             if (this.pawn.RaceProps.IsFlesh && this.hediffSet.BleedRateTotal >= 0.1f)
             {
                 float num3 = this.hediffSet.BleedRateTotal * this.pawn.BodySize;
                 if (this.pawn.GetPosture() == PawnPosture.Standing)
                 {
                     num3 *= 0.004f;
                 }
                 else
                 {
                     num3 *= 0.0004f;
                 }
                 if (Rand.Value < num3)
                 {
                     this.DropBloodFilth();
                 }
             }
             if (this.pawn.IsHashIntervalTick(60))
             {
                 List <HediffGiverSetDef> hediffGiverSets = this.pawn.RaceProps.hediffGiverSets;
                 if (hediffGiverSets != null)
                 {
                     for (int k = 0; k < hediffGiverSets.Count; k++)
                     {
                         List <HediffGiver> hediffGivers = hediffGiverSets[k].hediffGivers;
                         for (int l = 0; l < hediffGivers.Count; l++)
                         {
                             hediffGivers[l].OnIntervalPassed(this.pawn, null);
                             if (this.pawn.Dead)
                             {
                                 return;
                             }
                         }
                     }
                 }
                 if (this.pawn.story != null)
                 {
                     List <Trait> allTraits = this.pawn.story.traits.allTraits;
                     for (int m = 0; m < allTraits.Count; m++)
                     {
                         TraitDegreeData currentData = allTraits[m].CurrentData;
                         if (currentData.randomDiseaseMtbDays > 0f && Rand.MTBEventOccurs(currentData.randomDiseaseMtbDays, 60000f, 60f))
                         {
                             BiomeDef biome;
                             if (this.pawn.Tile != -1)
                             {
                                 biome = Find.WorldGrid[this.pawn.Tile].biome;
                             }
                             else
                             {
                                 biome = DefDatabase <BiomeDef> .GetRandom();
                             }
                             IncidentDef incidentDef = (from d in DefDatabase <IncidentDef> .AllDefs
                                                        where d.category == IncidentCategoryDefOf.DiseaseHuman
                                                        select d).RandomElementByWeightWithFallback((IncidentDef d) => biome.CommonalityOfDisease(d), null);
                             if (incidentDef != null)
                             {
                                 ((IncidentWorker_Disease)incidentDef.Worker).ApplyToPawns(Gen.YieldSingle <Pawn>(this.pawn));
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 public override int GetHashCode()
 {
     return(Gen.HashCombine(Gen.HashCombineInt(Gen.HashCombine(Gen.HashCombine(Gen.HashCombineStruct(Gen.HashCombineStruct(Gen.HashCombine(0, shader), color), colorTwo), mainTex), maskTex), renderQueue), shaderParameters));
 }
Esempio n. 29
0
 public override int GetHashCode()
 {
     return(Gen.HashCombine <ThingDef>(this.count, this.thingDef));
 }
Esempio n. 30
0
 public void HealthTick()
 {
     if (!Dead)
     {
         for (int num = hediffSet.hediffs.Count - 1; num >= 0; num--)
         {
             Hediff hediff = hediffSet.hediffs[num];
             try
             {
                 hediff.Tick();
                 hediff.PostTick();
             }
             catch (Exception ex)
             {
                 Log.Error("Exception ticking hediff " + hediff.ToStringSafe() + " for pawn " + pawn.ToStringSafe() + ". Removing hediff... Exception: " + ex);
                 try
                 {
                     RemoveHediff(hediff);
                 }
                 catch (Exception arg)
                 {
                     Log.Error("Error while removing hediff: " + arg);
                 }
             }
         }
         bool flag = false;
         for (int num2 = hediffSet.hediffs.Count - 1; num2 >= 0; num2--)
         {
             Hediff hediff2 = hediffSet.hediffs[num2];
             if (hediff2.ShouldRemove)
             {
                 hediffSet.hediffs.RemoveAt(num2);
                 hediff2.PostRemoved();
                 flag = true;
             }
         }
         if (flag)
         {
             Notify_HediffChanged(null);
         }
         if (!Dead)
         {
             immunity.ImmunityHandlerTick();
             if (pawn.RaceProps.IsFlesh && pawn.IsHashIntervalTick(600) && (pawn.needs.food == null || !pawn.needs.food.Starving))
             {
                 bool flag2 = false;
                 if (hediffSet.HasNaturallyHealingInjury())
                 {
                     float num3 = 8f;
                     if (pawn.GetPosture() != 0)
                     {
                         num3 += 4f;
                         Building_Bed building_Bed = pawn.CurrentBed();
                         if (building_Bed != null)
                         {
                             num3 += building_Bed.def.building.bed_healPerDay;
                         }
                     }
                     Hediff_Injury hediff_Injury = hediffSet.GetHediffs <Hediff_Injury>().Where(HediffUtility.CanHealNaturally).RandomElement();
                     hediff_Injury.Heal(num3 * pawn.HealthScale * 0.01f);
                     flag2 = true;
                 }
                 if (hediffSet.HasTendedAndHealingInjury() && (pawn.needs.food == null || !pawn.needs.food.Starving))
                 {
                     Hediff_Injury hediff_Injury2 = hediffSet.GetHediffs <Hediff_Injury>().Where(HediffUtility.CanHealFromTending).RandomElement();
                     float         tendQuality    = hediff_Injury2.TryGetComp <HediffComp_TendDuration>().tendQuality;
                     float         num4           = GenMath.LerpDouble(0f, 1f, 0.5f, 1.5f, Mathf.Clamp01(tendQuality));
                     hediff_Injury2.Heal(8f * num4 * pawn.HealthScale * 0.01f);
                     flag2 = true;
                 }
                 if (flag2 && !HasHediffsNeedingTendByPlayer() && !HealthAIUtility.ShouldSeekMedicalRest(pawn) && !hediffSet.HasTendedAndHealingInjury() && PawnUtility.ShouldSendNotificationAbout(pawn))
                 {
                     Messages.Message("MessageFullyHealed".Translate(pawn.LabelCap, pawn), pawn, MessageTypeDefOf.PositiveEvent);
                 }
             }
             if (pawn.RaceProps.IsFlesh && hediffSet.BleedRateTotal >= 0.1f)
             {
                 float num5 = hediffSet.BleedRateTotal * pawn.BodySize;
                 num5 = ((pawn.GetPosture() != 0) ? (num5 * 0.0004f) : (num5 * 0.004f));
                 if (Rand.Value < num5)
                 {
                     DropBloodFilth();
                 }
             }
             if (pawn.IsHashIntervalTick(60))
             {
                 List <HediffGiverSetDef> hediffGiverSets = pawn.RaceProps.hediffGiverSets;
                 if (hediffGiverSets != null)
                 {
                     for (int i = 0; i < hediffGiverSets.Count; i++)
                     {
                         List <HediffGiver> hediffGivers = hediffGiverSets[i].hediffGivers;
                         for (int j = 0; j < hediffGivers.Count; j++)
                         {
                             hediffGivers[j].OnIntervalPassed(pawn, null);
                             if (pawn.Dead)
                             {
                                 return;
                             }
                         }
                     }
                 }
                 if (pawn.story != null)
                 {
                     List <Trait> allTraits = pawn.story.traits.allTraits;
                     for (int k = 0; k < allTraits.Count; k++)
                     {
                         TraitDegreeData currentData = allTraits[k].CurrentData;
                         if (currentData.randomDiseaseMtbDays > 0f && Rand.MTBEventOccurs(currentData.randomDiseaseMtbDays, 60000f, 60f))
                         {
                             BiomeDef biome;
                             if (pawn.Tile != -1)
                             {
                                 biome = Find.WorldGrid[pawn.Tile].biome;
                             }
                             else
                             {
                                 biome = DefDatabase <BiomeDef> .GetRandom();
                             }
                             IncidentDef incidentDef = (from d in DefDatabase <IncidentDef> .AllDefs
                                                        where d.category == IncidentCategoryDefOf.DiseaseHuman
                                                        select d).RandomElementByWeightWithFallback((IncidentDef d) => biome.CommonalityOfDisease(d));
                             if (incidentDef != null)
                             {
                                 string      blockedInfo;
                                 List <Pawn> list = ((IncidentWorker_Disease)incidentDef.Worker).ApplyToPawns(Gen.YieldSingle(pawn), out blockedInfo);
                                 if (PawnUtility.ShouldSendNotificationAbout(pawn))
                                 {
                                     if (list.Contains(pawn))
                                     {
                                         Find.LetterStack.ReceiveLetter("LetterLabelTraitDisease".Translate(incidentDef.diseaseIncident.label), "LetterTraitDisease".Translate(pawn.LabelCap, incidentDef.diseaseIncident.label, pawn.Named("PAWN")).AdjustedFor(pawn), LetterDefOf.NegativeEvent, pawn);
                                     }
                                     else if (!blockedInfo.NullOrEmpty())
                                     {
                                         Messages.Message(blockedInfo, pawn, MessageTypeDefOf.NeutralEvent);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }