Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ UpdateLifeRegen()

void Terraria.Player.UpdateLifeRegen ( )
inline

Definition at line 18481 of file Player.cs.

18482 {
18483 bool flag = false;
18485 {
18486 flag = true;
18487 }
18488 if (poisoned)
18489 {
18490 if (lifeRegen > 0)
18491 {
18492 lifeRegen = 0;
18493 }
18494 lifeRegenTime = 0f;
18495 lifeRegen -= 4;
18496 }
18497 if (venom)
18498 {
18499 if (lifeRegen > 0)
18500 {
18501 lifeRegen = 0;
18502 }
18503 lifeRegenTime = 0f;
18504 lifeRegen -= 30;
18505 }
18506 if (onFire)
18507 {
18508 if (lifeRegen > 0)
18509 {
18510 lifeRegen = 0;
18511 }
18512 lifeRegenTime = 0f;
18513 lifeRegen -= 8;
18514 }
18515 if (onFire3)
18516 {
18517 if (lifeRegen > 0)
18518 {
18519 lifeRegen = 0;
18520 }
18521 lifeRegenTime = 0f;
18522 lifeRegen -= 8;
18523 }
18524 if (onFrostBurn)
18525 {
18526 if (lifeRegen > 0)
18527 {
18528 lifeRegen = 0;
18529 }
18530 lifeRegenTime = 0f;
18531 lifeRegen -= 16;
18532 }
18533 if (onFrostBurn2)
18534 {
18535 if (lifeRegen > 0)
18536 {
18537 lifeRegen = 0;
18538 }
18539 lifeRegenTime = 0f;
18540 lifeRegen -= 16;
18541 }
18542 if (onFire2)
18543 {
18544 if (lifeRegen > 0)
18545 {
18546 lifeRegen = 0;
18547 }
18548 lifeRegenTime = 0f;
18549 lifeRegen -= 24;
18550 }
18551 if (burned)
18552 {
18553 if (lifeRegen > 0)
18554 {
18555 lifeRegen = 0;
18556 }
18557 lifeRegenTime = 0f;
18558 lifeRegen -= 60;
18559 moveSpeed *= 0.5f;
18560 }
18561 if (suffocating)
18562 {
18563 if (lifeRegen > 0)
18564 {
18565 lifeRegen = 0;
18566 }
18567 lifeRegenTime = 0f;
18568 lifeRegen -= 40;
18569 }
18570 if (electrified)
18571 {
18572 if (lifeRegen > 0)
18573 {
18574 lifeRegen = 0;
18575 }
18576 lifeRegenTime = 0f;
18577 lifeRegen -= 8;
18579 {
18580 lifeRegen -= 32;
18581 }
18582 }
18583 if (tongued && Main.expertMode)
18584 {
18585 if (lifeRegen > 0)
18586 {
18587 lifeRegen = 0;
18588 }
18589 lifeRegenTime = 0f;
18590 lifeRegen -= 100;
18591 }
18592 if (honey && lifeRegen < 0)
18593 {
18594 lifeRegen += 4;
18595 if (lifeRegen > 0)
18596 {
18597 lifeRegen = 0;
18598 }
18599 }
18601 {
18602 lifeRegen = 0;
18603 }
18604 if (flag && lifeRegen < 0)
18605 {
18606 lifeRegen /= 2;
18607 }
18608 lifeRegenTime += 1f;
18609 if (usedAegisCrystal)
18610 {
18611 lifeRegenTime += 0.2f;
18612 }
18613 if (crimsonRegen)
18614 {
18615 lifeRegenTime += 1f;
18616 }
18617 if (soulDrain > 0)
18618 {
18619 lifeRegenTime += 2f;
18620 }
18621 if (flag)
18622 {
18623 if (lifeRegenTime > 90f && lifeRegenTime < 1800f)
18624 {
18625 lifeRegenTime = 1800f;
18626 }
18627 lifeRegenTime += 4f;
18628 lifeRegen += 4;
18629 }
18630 if (honey)
18631 {
18632 lifeRegenTime += 2f;
18633 lifeRegen += 2;
18634 }
18635 if (starving)
18636 {
18637 if (lifeRegen > 0)
18638 {
18639 lifeRegen = 0;
18640 }
18641 if (lifeRegenCount > 0)
18642 {
18643 lifeRegenCount = 0;
18644 }
18645 if (lifeRegenTime > 0f)
18646 {
18647 lifeRegenTime = 0f;
18648 }
18649 int num = 3000;
18650 int num2 = 120 * statLifeMax2 / num;
18651 if (num2 < 4)
18652 {
18653 num2 = 4;
18654 }
18655 lifeRegen = -num2;
18656 }
18657 if (soulDrain > 0)
18658 {
18659 int num3 = (5 + soulDrain) / 2;
18661 lifeRegen += num3;
18662 }
18663 if (heartyMeal)
18664 {
18665 int num4 = 3 * 120 / 60;
18666 lifeRegen += num4;
18667 }
18668 if (whoAmI == Main.myPlayer && Main.SceneMetrics.HasCampfire)
18669 {
18670 lifeRegen++;
18671 }
18672 if (whoAmI == Main.myPlayer && Main.SceneMetrics.HasHeartLantern)
18673 {
18674 lifeRegen += 2;
18675 }
18676 if (bleed)
18677 {
18678 lifeRegenTime = 0f;
18679 }
18680 float num5 = 0f;
18681 if (lifeRegenTime >= 300f)
18682 {
18683 num5 += 1f;
18684 }
18685 if (lifeRegenTime >= 600f)
18686 {
18687 num5 += 1f;
18688 }
18689 if (lifeRegenTime >= 900f)
18690 {
18691 num5 += 1f;
18692 }
18693 if (lifeRegenTime >= 1200f)
18694 {
18695 num5 += 1f;
18696 }
18697 if (lifeRegenTime >= 1500f)
18698 {
18699 num5 += 1f;
18700 }
18701 if (lifeRegenTime >= 1800f)
18702 {
18703 num5 += 1f;
18704 }
18705 if (lifeRegenTime >= 2400f)
18706 {
18707 num5 += 1f;
18708 }
18709 if (lifeRegenTime >= 3000f)
18710 {
18711 num5 += 1f;
18712 }
18713 if (flag)
18714 {
18715 float num6 = lifeRegenTime - 3000f;
18716 num6 /= 300f;
18717 if (num6 > 0f)
18718 {
18719 if (num6 > 30f)
18720 {
18721 num6 = 30f;
18722 }
18723 num5 += num6;
18724 }
18725 }
18726 else if (lifeRegenTime >= 3600f)
18727 {
18728 num5 += 1f;
18729 lifeRegenTime = 3600f;
18730 }
18732 {
18733 lifeRegenTime += 3f;
18734 num5 *= 1.3f;
18735 }
18737 {
18738 TryToPoop();
18739 }
18740 num5 = ((velocity.X != 0f && grappling[0] <= 0) ? (num5 * 0.5f) : (num5 * 1.25f));
18741 if (crimsonRegen)
18742 {
18743 num5 *= 1.5f;
18744 }
18745 if (shinyStone)
18746 {
18747 num5 *= 1.1f;
18748 }
18749 if (whoAmI == Main.myPlayer && Main.SceneMetrics.HasCampfire)
18750 {
18751 num5 *= 1.1f;
18752 }
18753 if (Main.expertMode && !wellFed)
18754 {
18755 num5 = ((!shinyStone) ? (num5 / 2f) : (num5 * 0.75f));
18756 }
18757 if (rabid)
18758 {
18759 num5 = ((!shinyStone) ? (num5 / 2f) : (num5 * 0.75f));
18760 }
18761 float num7 = (float)statLifeMax2 / 400f * 0.85f + 0.15f;
18762 num5 *= num7;
18763 lifeRegen += (int)Math.Round(num5);
18765 if (palladiumRegen)
18766 {
18767 lifeRegenCount += 4;
18768 }
18769 if (flag && lifeRegen > 0 && statLife < statLifeMax2)
18770 {
18772 if (flag && ((float)Main.rand.Next(30000) < lifeRegenTime || Main.rand.Next(30) == 0))
18773 {
18774 int num8 = Dust.NewDust(position, width, height, 55, 0f, 0f, 200, default(Color), 0.5f);
18775 Main.dust[num8].noGravity = true;
18776 Main.dust[num8].velocity *= 0.75f;
18777 Main.dust[num8].fadeIn = 1.3f;
18778 Vector2 vector = new Vector2(Main.rand.Next(-100, 101), Main.rand.Next(-100, 101));
18779 vector.Normalize();
18780 vector *= (float)Main.rand.Next(50, 100) * 0.04f;
18781 Main.dust[num8].velocity = vector;
18782 vector.Normalize();
18783 vector *= 34f;
18784 Main.dust[num8].position = base.Center - vector;
18785 }
18786 }
18787 while (lifeRegenCount >= 120)
18788 {
18789 lifeRegenCount -= 120;
18790 if (statLife < statLifeMax2)
18791 {
18792 statLife++;
18793 if (crimsonRegen)
18794 {
18795 for (int i = 0; i < 10; i++)
18796 {
18797 int num9 = Dust.NewDust(position, width, height, 5, 0f, 0f, 175, default(Color), 1.75f);
18798 Main.dust[num9].noGravity = true;
18799 Main.dust[num9].velocity *= 0.75f;
18800 int num10 = Main.rand.Next(-40, 41);
18801 int num11 = Main.rand.Next(-40, 41);
18802 Main.dust[num9].position.X += num10;
18803 Main.dust[num9].position.Y += num11;
18804 Main.dust[num9].velocity.X = (float)(-num10) * 0.075f;
18805 Main.dust[num9].velocity.Y = (float)(-num11) * 0.075f;
18806 }
18807 }
18808 }
18809 if (statLife > statLifeMax2)
18810 {
18812 }
18813 }
18814 if (burned || suffocating || (tongued && Main.expertMode))
18815 {
18816 while (lifeRegenCount <= -600)
18817 {
18818 lifeRegenCount += 600;
18819 statLife -= 5;
18820 CombatText.NewText(new Rectangle((int)position.X, (int)position.Y, width, height), CombatText.LifeRegen, 5, dramatic: false, dot: true);
18821 if (statLife <= 0 && whoAmI == Main.myPlayer)
18822 {
18823 if (suffocating)
18824 {
18825 KillMe(PlayerDeathReason.ByOther(7), 10.0, 0);
18826 }
18827 else if (tongued)
18828 {
18829 KillMe(PlayerDeathReason.ByOther(12), 10.0, 0);
18830 }
18831 else
18832 {
18833 KillMe(PlayerDeathReason.ByOther(8), 10.0, 0);
18834 }
18835 }
18836 }
18837 return;
18838 }
18839 if (starving)
18840 {
18841 int num12 = statLifeMax2 / 50;
18842 if (num12 < 2)
18843 {
18844 num12 = 2;
18845 }
18846 int num13 = ((ZoneDesert || ZoneSnow) ? (num12 * 2) : num12);
18847 int num14 = 120 * num12;
18848 while (lifeRegenCount <= -num14)
18849 {
18851 statLife -= num13;
18852 CombatText.NewText(new Rectangle((int)position.X, (int)position.Y, width, height), CombatText.LifeRegen, num13, dramatic: false, dot: true);
18853 if (statLife <= 0 && whoAmI == Main.myPlayer)
18854 {
18855 KillMe(PlayerDeathReason.ByOther(18), 10.0, 0);
18856 }
18857 }
18858 return;
18859 }
18860 while (lifeRegenCount <= -120)
18861 {
18862 if (lifeRegenCount <= -480)
18863 {
18864 lifeRegenCount += 480;
18865 statLife -= 4;
18866 CombatText.NewText(new Rectangle((int)position.X, (int)position.Y, width, height), CombatText.LifeRegen, 4, dramatic: false, dot: true);
18867 }
18868 else if (lifeRegenCount <= -360)
18869 {
18870 lifeRegenCount += 360;
18871 statLife -= 3;
18872 CombatText.NewText(new Rectangle((int)position.X, (int)position.Y, width, height), CombatText.LifeRegen, 3, dramatic: false, dot: true);
18873 }
18874 else if (lifeRegenCount <= -240)
18875 {
18876 lifeRegenCount += 240;
18877 statLife -= 2;
18878 CombatText.NewText(new Rectangle((int)position.X, (int)position.Y, width, height), CombatText.LifeRegen, 2, dramatic: false, dot: true);
18879 }
18880 else
18881 {
18882 lifeRegenCount += 120;
18883 statLife--;
18884 CombatText.NewText(new Rectangle((int)position.X, (int)position.Y, width, height), CombatText.LifeRegen, 1, dramatic: false, dot: true);
18885 }
18886 if (statLife <= 0 && whoAmI == Main.myPlayer)
18887 {
18888 if (poisoned || venom)
18889 {
18890 KillMe(PlayerDeathReason.ByOther(9), 10.0, 0);
18891 }
18892 else if (electrified)
18893 {
18894 KillMe(PlayerDeathReason.ByOther(10), 10.0, 0);
18895 }
18896 else
18897 {
18898 KillMe(PlayerDeathReason.ByOther(8), 10.0, 0);
18899 }
18900 }
18901 }
18902 }
static decimal Round(decimal d)
Definition Math.cs:1096
static PlayerDeathReason ByOther(int type)
Vector2 position
Definition Entity.cs:14
float moveSpeed
Definition Player.cs:2047
bool controlRight
Definition Player.cs:1383
float lifeRegenTime
Definition Player.cs:1571
bool electrified
Definition Player.cs:911
bool IsStandingStillForSpecialEffects
Definition Player.cs:2841
PlayerSleepingHelper sleeping
Definition Player.cs:2465
bool palladiumRegen
Definition Player.cs:929
bool crimsonRegen
Definition Player.cs:873
bool onFrostBurn2
Definition Player.cs:1897
PlayerSittingHelper sitting
Definition Player.cs:2463
void TryToPoop()
Definition Player.cs:18435
void KillMe(PlayerDeathReason damageSource, double dmg, int hitDirection, bool pvp=false)
Definition Player.cs:36665
int[] grappling
Definition Player.cs:2305
bool usedAegisCrystal
Definition Player.cs:645

References Terraria.DataStructures.PlayerDeathReason.ByOther(), Terraria.Main.dust, Terraria.Main.expertMode, Terraria.CombatText.LifeRegen, Terraria.Main.myPlayer, Terraria.Dust.NewDust(), Terraria.CombatText.NewText(), Terraria.Main.rand, System.Math.Round(), and Terraria.Main.SceneMetrics.