Terraria 1.4.0.5 Source Code

This commit is contained in:
MikeyIsBaeYT 2021-10-26 12:45:26 -04:00
commit 05205f009e
1059 changed files with 563450 additions and 0 deletions

View file

@ -0,0 +1,153 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.Events.BirthdayParty
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using Terraria.Graphics.Effects;
using Terraria.ID;
using Terraria.Localization;
namespace Terraria.GameContent.Events
{
public class BirthdayParty
{
public static bool ManualParty;
public static bool GenuineParty;
public static int PartyDaysOnCooldown;
public static List<int> CelebratingNPCs = new List<int>();
private static bool _wasCelebrating;
public static bool PartyIsUp => BirthdayParty.GenuineParty || BirthdayParty.ManualParty;
public static void CheckMorning() => BirthdayParty.NaturalAttempt();
public static void CheckNight()
{
bool flag = false;
if (BirthdayParty.GenuineParty)
{
flag = true;
BirthdayParty.GenuineParty = false;
BirthdayParty.CelebratingNPCs.Clear();
}
if (BirthdayParty.ManualParty)
{
flag = true;
BirthdayParty.ManualParty = false;
}
if (!flag)
return;
Color color = new Color((int) byte.MaxValue, 0, 160);
WorldGen.BroadcastText(NetworkText.FromKey(Lang.misc[99].Key), color);
}
private static bool CanNPCParty(NPC n) => n.active && n.townNPC && n.aiStyle != 0 && n.type != 37 && n.type != 453 && n.type != 441 && !NPCID.Sets.IsTownPet[n.type];
private static void NaturalAttempt()
{
if (Main.netMode == 1 || !NPC.AnyNPCs(208))
return;
if (BirthdayParty.PartyDaysOnCooldown > 0)
{
--BirthdayParty.PartyDaysOnCooldown;
}
else
{
if (Main.rand.Next(10) != 0)
return;
List<NPC> source = new List<NPC>();
for (int index = 0; index < 200; ++index)
{
NPC n = Main.npc[index];
if (BirthdayParty.CanNPCParty(n))
source.Add(n);
}
if (source.Count < 5)
return;
BirthdayParty.GenuineParty = true;
BirthdayParty.PartyDaysOnCooldown = Main.rand.Next(5, 11);
NPC.freeCake = true;
BirthdayParty.CelebratingNPCs.Clear();
List<int> intList = new List<int>();
int num = 1;
if (Main.rand.Next(5) == 0 && source.Count > 12)
num = 3;
else if (Main.rand.Next(3) == 0)
num = 2;
List<NPC> list = source.OrderBy<NPC, int>((Func<NPC, int>) (i => Main.rand.Next())).ToList<NPC>();
for (int index = 0; index < num; ++index)
intList.Add(index);
for (int index = 0; index < intList.Count; ++index)
BirthdayParty.CelebratingNPCs.Add(list[intList[index]].whoAmI);
Color color = new Color((int) byte.MaxValue, 0, 160);
if (BirthdayParty.CelebratingNPCs.Count == 3)
WorldGen.BroadcastText(NetworkText.FromKey("Game.BirthdayParty_3", (object) Main.npc[BirthdayParty.CelebratingNPCs[0]].GetGivenOrTypeNetName(), (object) Main.npc[BirthdayParty.CelebratingNPCs[1]].GetGivenOrTypeNetName(), (object) Main.npc[BirthdayParty.CelebratingNPCs[2]].GetGivenOrTypeNetName()), color);
else if (BirthdayParty.CelebratingNPCs.Count == 2)
WorldGen.BroadcastText(NetworkText.FromKey("Game.BirthdayParty_2", (object) Main.npc[BirthdayParty.CelebratingNPCs[0]].GetGivenOrTypeNetName(), (object) Main.npc[BirthdayParty.CelebratingNPCs[1]].GetGivenOrTypeNetName()), color);
else
WorldGen.BroadcastText(NetworkText.FromKey("Game.BirthdayParty_1", (object) Main.npc[BirthdayParty.CelebratingNPCs[0]].GetGivenOrTypeNetName()), color);
NetMessage.SendData(7);
}
}
public static void ToggleManualParty()
{
int num1 = BirthdayParty.PartyIsUp ? 1 : 0;
if (Main.netMode != 1)
BirthdayParty.ManualParty = !BirthdayParty.ManualParty;
else
NetMessage.SendData(111);
int num2 = BirthdayParty.PartyIsUp ? 1 : 0;
if (num1 == num2 || Main.netMode != 2)
return;
NetMessage.SendData(7);
}
public static void WorldClear()
{
BirthdayParty.ManualParty = false;
BirthdayParty.GenuineParty = false;
BirthdayParty.PartyDaysOnCooldown = 0;
BirthdayParty.CelebratingNPCs.Clear();
BirthdayParty._wasCelebrating = false;
}
public static void UpdateTime()
{
if (BirthdayParty._wasCelebrating != BirthdayParty.PartyIsUp)
{
if (Main.netMode != 2)
{
if (BirthdayParty.PartyIsUp)
SkyManager.Instance.Activate("Party", new Vector2());
else
SkyManager.Instance.Deactivate("Party");
}
if (Main.netMode != 1 && BirthdayParty.CelebratingNPCs.Count > 0)
{
for (int index = 0; index < BirthdayParty.CelebratingNPCs.Count; ++index)
{
if (!BirthdayParty.CanNPCParty(Main.npc[BirthdayParty.CelebratingNPCs[index]]))
BirthdayParty.CelebratingNPCs.RemoveAt(index);
}
if (BirthdayParty.CelebratingNPCs.Count == 0)
{
BirthdayParty.GenuineParty = false;
if (!BirthdayParty.ManualParty)
{
Color color = new Color((int) byte.MaxValue, 0, 160);
WorldGen.BroadcastText(NetworkText.FromKey(Lang.misc[99].Key), color);
NetMessage.SendData(7);
}
}
}
}
BirthdayParty._wasCelebrating = BirthdayParty.PartyIsUp;
}
}
}

View file

@ -0,0 +1,91 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.Events.CultistRitual
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using Terraria.ID;
namespace Terraria.GameContent.Events
{
public class CultistRitual
{
public const int delayStart = 86400;
public const int respawnDelay = 43200;
private const int timePerCultist = 3600;
private const int recheckStart = 600;
public static int delay;
public static int recheck;
public static void UpdateTime()
{
if (Main.netMode == 1)
return;
CultistRitual.delay -= Main.dayRate;
if (CultistRitual.delay < 0)
CultistRitual.delay = 0;
CultistRitual.recheck -= Main.dayRate;
if (CultistRitual.recheck < 0)
CultistRitual.recheck = 0;
if (CultistRitual.delay != 0 || CultistRitual.recheck != 0)
return;
CultistRitual.recheck = 600;
if (NPC.AnyDanger())
CultistRitual.recheck *= 6;
else
CultistRitual.TrySpawning(Main.dungeonX, Main.dungeonY);
}
public static void CultistSlain() => CultistRitual.delay -= 3600;
public static void TabletDestroyed() => CultistRitual.delay = 43200;
public static void TrySpawning(int x, int y)
{
if (WorldGen.PlayerLOS(x - 6, y) || WorldGen.PlayerLOS(x + 6, y) || !CultistRitual.CheckRitual(x, y))
return;
NPC.NewNPC(x * 16 + 8, (y - 4) * 16 - 8, 437);
}
private static bool CheckRitual(int x, int y)
{
if (CultistRitual.delay != 0 || !Main.hardMode || !NPC.downedGolemBoss || !NPC.downedBoss3 || y < 7 || WorldGen.SolidTile(Main.tile[x, y - 7]) || NPC.AnyNPCs(437))
return false;
Vector2 Center = new Vector2((float) (x * 16 + 8), (float) (y * 16 - 64 - 8 - 27));
Point[] pointArray = (Point[]) null;
ref Point[] local = ref pointArray;
return CultistRitual.CheckFloor(Center, out local);
}
public static bool CheckFloor(Vector2 Center, out Point[] spawnPoints)
{
Point[] pointArray = new Point[4];
int num1 = 0;
Point tileCoordinates = Center.ToTileCoordinates();
for (int index1 = -5; index1 <= 5; index1 += 2)
{
if (index1 != -1 && index1 != 1)
{
for (int index2 = -5; index2 < 12; ++index2)
{
int num2 = tileCoordinates.X + index1 * 2;
int num3 = tileCoordinates.Y + index2;
if ((WorldGen.SolidTile(num2, num3) || TileID.Sets.Platforms[(int) Framing.GetTileSafely(num2, num3).type]) && (!Collision.SolidTiles(num2 - 1, num2 + 1, num3 - 3, num3 - 1) || !Collision.SolidTiles(num2, num2, num3 - 3, num3 - 1) && !Collision.SolidTiles(num2 + 1, num2 + 1, num3 - 3, num3 - 2) && !Collision.SolidTiles(num2 - 1, num2 - 1, num3 - 3, num3 - 2)))
{
pointArray[num1++] = new Point(num2, num3);
break;
}
}
}
}
if (num1 != 4)
{
spawnPoints = (Point[]) null;
return false;
}
spawnPoints = pointArray;
return true;
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,113 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.Events.LanternNight
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using Terraria.Graphics.Effects;
namespace Terraria.GameContent.Events
{
public class LanternNight
{
public static bool ManualLanterns;
public static bool GenuineLanterns;
public static bool NextNightIsLanternNight;
public static int LanternNightsOnCooldown;
private static bool _wasLanternNight;
public static bool LanternsUp => LanternNight.GenuineLanterns || LanternNight.ManualLanterns;
public static void CheckMorning()
{
bool flag = false;
if (LanternNight.GenuineLanterns)
{
flag = true;
LanternNight.GenuineLanterns = false;
}
if (LanternNight.ManualLanterns)
{
flag = true;
LanternNight.ManualLanterns = false;
}
int num = flag ? 1 : 0;
}
public static void CheckNight() => LanternNight.NaturalAttempt();
public static bool LanternsCanPersist() => !Main.dayTime && LanternNight.LanternsCanStart();
public static bool LanternsCanStart() => !Main.bloodMoon && !Main.pumpkinMoon && !Main.snowMoon && Main.invasionType == 0 && NPC.MoonLordCountdown == 0 && !LanternNight.BossIsActive();
private static bool BossIsActive()
{
for (int index = 0; index < 200; ++index)
{
NPC npc = Main.npc[index];
if (npc.active && (npc.boss || npc.type >= 13 && npc.type <= 15))
return true;
}
return false;
}
private static void NaturalAttempt()
{
if (Main.netMode == 1 || !LanternNight.LanternsCanStart())
return;
bool flag = false;
if (LanternNight.LanternNightsOnCooldown > 0)
--LanternNight.LanternNightsOnCooldown;
if (LanternNight.LanternNightsOnCooldown == 0 && NPC.downedMoonlord && Main.rand.Next(14) == 0)
flag = true;
if (!flag && LanternNight.NextNightIsLanternNight)
{
LanternNight.NextNightIsLanternNight = false;
flag = true;
}
if (!flag)
return;
LanternNight.GenuineLanterns = true;
LanternNight.LanternNightsOnCooldown = Main.rand.Next(5, 11);
}
public static void ToggleManualLanterns()
{
int num1 = LanternNight.LanternsUp ? 1 : 0;
if (Main.netMode != 1)
LanternNight.ManualLanterns = !LanternNight.ManualLanterns;
int num2 = LanternNight.LanternsUp ? 1 : 0;
if (num1 == num2 || Main.netMode != 2)
return;
NetMessage.SendData(7);
}
public static void WorldClear()
{
LanternNight.ManualLanterns = false;
LanternNight.GenuineLanterns = false;
LanternNight.LanternNightsOnCooldown = 0;
LanternNight._wasLanternNight = false;
}
public static void UpdateTime()
{
if (LanternNight.GenuineLanterns && !LanternNight.LanternsCanPersist())
LanternNight.GenuineLanterns = false;
if (LanternNight._wasLanternNight != LanternNight.LanternsUp)
{
if (Main.netMode != 2)
{
if (LanternNight.LanternsUp)
SkyManager.Instance.Activate("Lantern", new Vector2());
else
SkyManager.Instance.Deactivate("Lantern");
}
else
NetMessage.SendData(7);
}
LanternNight._wasLanternNight = LanternNight.LanternsUp;
}
}
}

View file

@ -0,0 +1,220 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.Events.MoonlordDeathDrama
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Content;
using System;
using System.Collections.Generic;
using Terraria.Utilities;
namespace Terraria.GameContent.Events
{
public class MoonlordDeathDrama
{
private static List<MoonlordDeathDrama.MoonlordPiece> _pieces = new List<MoonlordDeathDrama.MoonlordPiece>();
private static List<MoonlordDeathDrama.MoonlordExplosion> _explosions = new List<MoonlordDeathDrama.MoonlordExplosion>();
private static List<Vector2> _lightSources = new List<Vector2>();
private static float whitening;
private static float requestedLight;
public static void Update()
{
for (int index = 0; index < MoonlordDeathDrama._pieces.Count; ++index)
{
MoonlordDeathDrama.MoonlordPiece piece = MoonlordDeathDrama._pieces[index];
piece.Update();
if (piece.Dead)
{
MoonlordDeathDrama._pieces.Remove(piece);
--index;
}
}
for (int index = 0; index < MoonlordDeathDrama._explosions.Count; ++index)
{
MoonlordDeathDrama.MoonlordExplosion explosion = MoonlordDeathDrama._explosions[index];
explosion.Update();
if (explosion.Dead)
{
MoonlordDeathDrama._explosions.Remove(explosion);
--index;
}
}
bool flag = false;
for (int index = 0; index < MoonlordDeathDrama._lightSources.Count; ++index)
{
if ((double) Main.player[Main.myPlayer].Distance(MoonlordDeathDrama._lightSources[index]) < 2000.0)
{
flag = true;
break;
}
}
MoonlordDeathDrama._lightSources.Clear();
if (!flag)
MoonlordDeathDrama.requestedLight = 0.0f;
if ((double) MoonlordDeathDrama.requestedLight != (double) MoonlordDeathDrama.whitening)
{
if ((double) Math.Abs(MoonlordDeathDrama.requestedLight - MoonlordDeathDrama.whitening) < 0.0199999995529652)
MoonlordDeathDrama.whitening = MoonlordDeathDrama.requestedLight;
else
MoonlordDeathDrama.whitening += (float) Math.Sign(MoonlordDeathDrama.requestedLight - MoonlordDeathDrama.whitening) * 0.02f;
}
MoonlordDeathDrama.requestedLight = 0.0f;
}
public static void DrawPieces(SpriteBatch spriteBatch)
{
Rectangle playerScreen = Utils.CenteredRectangle(Main.screenPosition + new Vector2((float) Main.screenWidth, (float) Main.screenHeight) * 0.5f, new Vector2((float) (Main.screenWidth + 1000), (float) (Main.screenHeight + 1000)));
for (int index = 0; index < MoonlordDeathDrama._pieces.Count; ++index)
{
if (MoonlordDeathDrama._pieces[index].InDrawRange(playerScreen))
MoonlordDeathDrama._pieces[index].Draw(spriteBatch);
}
}
public static void DrawExplosions(SpriteBatch spriteBatch)
{
Rectangle playerScreen = Utils.CenteredRectangle(Main.screenPosition + new Vector2((float) Main.screenWidth, (float) Main.screenHeight) * 0.5f, new Vector2((float) (Main.screenWidth + 1000), (float) (Main.screenHeight + 1000)));
for (int index = 0; index < MoonlordDeathDrama._explosions.Count; ++index)
{
if (MoonlordDeathDrama._explosions[index].InDrawRange(playerScreen))
MoonlordDeathDrama._explosions[index].Draw(spriteBatch);
}
}
public static void DrawWhite(SpriteBatch spriteBatch)
{
if ((double) MoonlordDeathDrama.whitening == 0.0)
return;
Color color = Color.White * MoonlordDeathDrama.whitening;
spriteBatch.Draw(TextureAssets.MagicPixel.Value, new Rectangle(-2, -2, Main.screenWidth + 4, Main.screenHeight + 4), new Rectangle?(new Rectangle(0, 0, 1, 1)), color);
}
public static void ThrowPieces(Vector2 MoonlordCoreCenter, int DramaSeed)
{
UnifiedRandom r = new UnifiedRandom(DramaSeed);
Vector2 vector2_1 = Vector2.UnitY.RotatedBy((double) r.NextFloat() * 1.57079637050629 - 0.785398185253143 + 3.14159274101257);
MoonlordDeathDrama._pieces.Add(new MoonlordDeathDrama.MoonlordPiece(Main.Assets.Request<Texture2D>("Images/Misc/MoonExplosion/Spine", (AssetRequestMode) 1).Value, new Vector2(64f, 150f), MoonlordCoreCenter + new Vector2(0.0f, 50f), vector2_1 * 6f, 0.0f, (float) ((double) r.NextFloat() * 0.100000001490116 - 0.0500000007450581)));
Vector2 vector2_2 = Vector2.UnitY.RotatedBy((double) r.NextFloat() * 1.57079637050629 - 0.785398185253143 + 3.14159274101257);
MoonlordDeathDrama._pieces.Add(new MoonlordDeathDrama.MoonlordPiece(Main.Assets.Request<Texture2D>("Images/Misc/MoonExplosion/Shoulder", (AssetRequestMode) 1).Value, new Vector2(40f, 120f), MoonlordCoreCenter + new Vector2(50f, -120f), vector2_2 * 10f, 0.0f, (float) ((double) r.NextFloat() * 0.100000001490116 - 0.0500000007450581)));
Vector2 vector2_3 = Vector2.UnitY.RotatedBy((double) r.NextFloat() * 1.57079637050629 - 0.785398185253143 + 3.14159274101257);
MoonlordDeathDrama._pieces.Add(new MoonlordDeathDrama.MoonlordPiece(Main.Assets.Request<Texture2D>("Images/Misc/MoonExplosion/Torso", (AssetRequestMode) 1).Value, new Vector2(192f, 252f), MoonlordCoreCenter, vector2_3 * 8f, 0.0f, (float) ((double) r.NextFloat() * 0.100000001490116 - 0.0500000007450581)));
Vector2 vector2_4 = Vector2.UnitY.RotatedBy((double) r.NextFloat() * 1.57079637050629 - 0.785398185253143 + 3.14159274101257);
MoonlordDeathDrama._pieces.Add(new MoonlordDeathDrama.MoonlordPiece(Main.Assets.Request<Texture2D>("Images/Misc/MoonExplosion/Head", (AssetRequestMode) 1).Value, new Vector2(138f, 185f), MoonlordCoreCenter - new Vector2(0.0f, 200f), vector2_4 * 12f, 0.0f, (float) ((double) r.NextFloat() * 0.100000001490116 - 0.0500000007450581)));
}
public static void AddExplosion(Vector2 spot) => MoonlordDeathDrama._explosions.Add(new MoonlordDeathDrama.MoonlordExplosion(Main.Assets.Request<Texture2D>("Images/Misc/MoonExplosion/Explosion", (AssetRequestMode) 1).Value, spot, Main.rand.Next(2, 4)));
public static void RequestLight(float light, Vector2 spot)
{
MoonlordDeathDrama._lightSources.Add(spot);
if ((double) light > 1.0)
light = 1f;
if ((double) MoonlordDeathDrama.requestedLight >= (double) light)
return;
MoonlordDeathDrama.requestedLight = light;
}
public class MoonlordPiece
{
private Texture2D _texture;
private Vector2 _position;
private Vector2 _velocity;
private Vector2 _origin;
private float _rotation;
private float _rotationVelocity;
public MoonlordPiece(
Texture2D pieceTexture,
Vector2 textureOrigin,
Vector2 centerPos,
Vector2 velocity,
float rot,
float angularVelocity)
{
this._texture = pieceTexture;
this._origin = textureOrigin;
this._position = centerPos;
this._velocity = velocity;
this._rotation = rot;
this._rotationVelocity = angularVelocity;
}
public void Update()
{
this._velocity.Y += 0.3f;
this._rotation += this._rotationVelocity;
this._rotationVelocity *= 0.99f;
this._position += this._velocity;
}
public void Draw(SpriteBatch sp)
{
Color light = this.GetLight();
sp.Draw(this._texture, this._position - Main.screenPosition, new Rectangle?(), light, this._rotation, this._origin, 1f, SpriteEffects.None, 0.0f);
}
public bool Dead => (double) this._position.Y > (double) (Main.maxTilesY * 16) - 480.0 || (double) this._position.X < 480.0 || (double) this._position.X >= (double) (Main.maxTilesX * 16) - 480.0;
public bool InDrawRange(Rectangle playerScreen) => playerScreen.Contains(this._position.ToPoint());
public Color GetLight()
{
Vector3 zero = Vector3.Zero;
float num1 = 0.0f;
int num2 = 5;
Point tileCoordinates = this._position.ToTileCoordinates();
for (int x = tileCoordinates.X - num2; x <= tileCoordinates.X + num2; ++x)
{
for (int y = tileCoordinates.Y - num2; y <= tileCoordinates.Y + num2; ++y)
{
zero += Lighting.GetColor(x, y).ToVector3();
++num1;
}
}
return (double) num1 == 0.0 ? Color.White : new Color(zero / num1);
}
}
public class MoonlordExplosion
{
private Texture2D _texture;
private Vector2 _position;
private Vector2 _origin;
private Rectangle _frame;
private int _frameCounter;
private int _frameSpeed;
public MoonlordExplosion(Texture2D pieceTexture, Vector2 centerPos, int frameSpeed)
{
this._texture = pieceTexture;
this._position = centerPos;
this._frameSpeed = frameSpeed;
this._frameCounter = 0;
this._frame = this._texture.Frame(verticalFrames: 7);
this._origin = this._frame.Size() / 2f;
}
public void Update()
{
++this._frameCounter;
this._frame = this._texture.Frame(verticalFrames: 7, frameY: (this._frameCounter / this._frameSpeed));
}
public void Draw(SpriteBatch sp)
{
Color light = this.GetLight();
sp.Draw(this._texture, this._position - Main.screenPosition, new Rectangle?(this._frame), light, 0.0f, this._origin, 1f, SpriteEffects.None, 0.0f);
}
public bool Dead => (double) this._position.Y > (double) (Main.maxTilesY * 16) - 480.0 || (double) this._position.X < 480.0 || (double) this._position.X >= (double) (Main.maxTilesX * 16) - 480.0 || this._frameCounter >= this._frameSpeed * 7;
public bool InDrawRange(Rectangle playerScreen) => playerScreen.Contains(this._position.ToPoint());
public Color GetLight() => new Color((int) byte.MaxValue, (int) byte.MaxValue, (int) byte.MaxValue, (int) sbyte.MaxValue);
}
}
}

View file

@ -0,0 +1,150 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.Events.MysticLogFairiesEvent
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using Terraria.Enums;
namespace Terraria.GameContent.Events
{
public class MysticLogFairiesEvent
{
private bool _canSpawnFairies;
private int _delayUntilNextAttempt;
private const int DELAY_BETWEEN_ATTEMPTS = 60;
private List<Point> _stumpCoords = new List<Point>();
public void WorldClear()
{
this._canSpawnFairies = false;
this._delayUntilNextAttempt = 0;
this._stumpCoords.Clear();
}
public void StartWorld()
{
if (Main.netMode == 1)
return;
this.ScanWholeOverworldForLogs();
}
public void StartNight()
{
if (Main.netMode == 1)
return;
this._canSpawnFairies = true;
this._delayUntilNextAttempt = 0;
this.ScanWholeOverworldForLogs();
}
public void UpdateTime()
{
if (Main.netMode == 1 || !this._canSpawnFairies || !this.IsAGoodTime())
return;
this._delayUntilNextAttempt = Math.Max(0, this._delayUntilNextAttempt - Main.dayRate);
if (this._delayUntilNextAttempt != 0)
return;
this._delayUntilNextAttempt = 60;
this.TrySpawningFairies();
}
private bool IsAGoodTime() => !Main.dayTime && Main.time >= 6480.00009655952 && Main.time <= 25920.0003862381;
private void TrySpawningFairies()
{
if ((double) Main.maxRaining > 0.0 || Main.bloodMoon || NPC.MoonLordCountdown > 0 || Main.snowMoon || Main.pumpkinMoon || Main.invasionType > 0 || this._stumpCoords.Count == 0)
return;
int oneOverSpawnChance = this.GetOneOverSpawnChance();
bool flag = false;
for (int index = 0; index < Main.dayRate; ++index)
{
if (Main.rand.Next(oneOverSpawnChance) == 0)
{
flag = true;
break;
}
}
if (!flag)
return;
Point stumpCoord = this._stumpCoords[Main.rand.Next(this._stumpCoords.Count)];
Vector2 worldCoordinates = stumpCoord.ToWorldCoordinates(24f);
worldCoordinates.Y -= 50f;
if (WorldGen.PlayerLOS(stumpCoord.X, stumpCoord.Y))
return;
int num1 = Main.rand.Next(1, 4);
if (Main.rand.Next(7) == 0)
++num1;
int num2 = (int) Utils.SelectRandom<short>(Main.rand, (short) 585, (short) 584, (short) 583);
for (int index = 0; index < num1; ++index)
{
int Type = (int) Utils.SelectRandom<short>(Main.rand, (short) 585, (short) 584, (short) 583);
int number = NPC.NewNPC((int) worldCoordinates.X, (int) worldCoordinates.Y, Type);
if (Main.netMode == 2 && number < 200)
NetMessage.SendData(23, number: number);
}
this._canSpawnFairies = false;
}
public void FallenLogDestroyed()
{
if (Main.netMode == 1)
return;
this.ScanWholeOverworldForLogs();
}
private void ScanWholeOverworldForLogs()
{
this._stumpCoords.Clear();
NPC.fairyLog = false;
int num1 = (int) Main.worldSurface - 10;
int num2 = 100;
int num3 = Main.maxTilesX - 100;
int num4 = 3;
int num5 = 2;
List<Point> pointList = new List<Point>();
for (int x = 100; x < num3; x += num4)
{
for (int y = num1; y >= num2; y -= num5)
{
Tile tile = Main.tile[x, y];
if (tile.active() && tile.type == (ushort) 488 && tile.liquid == (byte) 0)
{
pointList.Add(new Point(x, y));
NPC.fairyLog = true;
}
}
}
foreach (Point stumpRandomPoint in pointList)
this._stumpCoords.Add(this.GetStumpTopLeft(stumpRandomPoint));
}
private Point GetStumpTopLeft(Point stumpRandomPoint)
{
Tile tile = Main.tile[stumpRandomPoint.X, stumpRandomPoint.Y];
Point point = stumpRandomPoint;
point.X -= (int) tile.frameX / 18;
point.Y -= (int) tile.frameY / 18;
return point;
}
private int GetOneOverSpawnChance()
{
int num;
switch (Main.GetMoonPhase())
{
case MoonPhase.Full:
case MoonPhase.Empty:
num = 3600;
break;
default:
num = 10800;
break;
}
return num / 60;
}
}
}

View file

@ -0,0 +1,208 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.Events.Sandstorm
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using System;
using Terraria.Graphics.Effects;
using Terraria.Utilities;
namespace Terraria.GameContent.Events
{
public class Sandstorm
{
private const int SANDSTORM_DURATION_MINIMUM = 28800;
private const int SANDSTORM_DURATION_MAXIMUM = 86400;
public static bool Happening;
public static int TimeLeft;
public static float Severity;
public static float IntendedSeverity;
private static bool _effectsUp;
private static bool HasSufficientWind() => (double) Math.Abs(Main.windSpeedCurrent) >= 0.600000023841858;
public static void WorldClear() => Sandstorm.Happening = false;
public static void UpdateTime()
{
if (Main.netMode != 1)
{
if (Sandstorm.Happening)
{
if (Sandstorm.TimeLeft > 86400)
Sandstorm.TimeLeft = 0;
Sandstorm.TimeLeft -= Main.dayRate;
if (!Sandstorm.HasSufficientWind())
Sandstorm.TimeLeft -= 15 * Main.dayRate;
if ((double) Main.windSpeedCurrent == 0.0)
Sandstorm.TimeLeft = 0;
if (Sandstorm.TimeLeft <= 0)
Sandstorm.StopSandstorm();
}
else if (Sandstorm.HasSufficientWind())
{
for (int index = 0; index < Main.dayRate; ++index)
{
if (Main.rand.Next(86400) == 0)
Sandstorm.StartSandstorm();
}
}
if (Main.rand.Next(18000) == 0)
Sandstorm.ChangeSeverityIntentions();
}
Sandstorm.UpdateSeverity();
}
private static void ChangeSeverityIntentions()
{
Sandstorm.IntendedSeverity = !Sandstorm.Happening ? (Main.rand.Next(3) != 0 ? Main.rand.NextFloat() * 0.3f : 0.0f) : 0.4f + Main.rand.NextFloat();
if (Main.netMode == 1)
return;
NetMessage.SendData(7);
}
private static void UpdateSeverity()
{
if (float.IsNaN(Sandstorm.Severity))
Sandstorm.Severity = 0.0f;
if (float.IsNaN(Sandstorm.IntendedSeverity))
Sandstorm.IntendedSeverity = 0.0f;
int num1 = Math.Sign(Sandstorm.IntendedSeverity - Sandstorm.Severity);
Sandstorm.Severity = MathHelper.Clamp(Sandstorm.Severity + 3f / 1000f * (float) num1, 0.0f, 1f);
int num2 = Math.Sign(Sandstorm.IntendedSeverity - Sandstorm.Severity);
if (num1 == num2)
return;
Sandstorm.Severity = Sandstorm.IntendedSeverity;
}
private static void StartSandstorm()
{
Sandstorm.Happening = true;
Sandstorm.TimeLeft = Main.rand.Next(28800, 86401);
Sandstorm.ChangeSeverityIntentions();
}
private static void StopSandstorm()
{
Sandstorm.Happening = false;
Sandstorm.TimeLeft = 0;
Sandstorm.ChangeSeverityIntentions();
}
public static void HandleEffectAndSky(bool toState)
{
if (toState == Sandstorm._effectsUp)
return;
Sandstorm._effectsUp = toState;
Vector2 center = Main.player[Main.myPlayer].Center;
if (Sandstorm._effectsUp)
{
SkyManager.Instance.Activate(nameof (Sandstorm), center);
Filters.Scene.Activate(nameof (Sandstorm), center);
Overlays.Scene.Activate(nameof (Sandstorm), center);
}
else
{
SkyManager.Instance.Deactivate(nameof (Sandstorm));
Filters.Scene.Deactivate(nameof (Sandstorm));
Overlays.Scene.Deactivate(nameof (Sandstorm));
}
}
public static bool ShouldSandstormDustPersist() => Sandstorm.Happening && Main.player[Main.myPlayer].ZoneSandstorm && (Main.bgStyle == 2 || Main.bgStyle == 5) && Main.bgDelay < 50;
public static void EmitDust()
{
if (Main.gamePaused)
return;
int sandTileCount = Main.SceneMetrics.SandTileCount;
Player player = Main.player[Main.myPlayer];
bool flag = Sandstorm.ShouldSandstormDustPersist();
Sandstorm.HandleEffectAndSky(flag && Main.UseStormEffects);
if (sandTileCount < 100 || (double) player.position.Y > Main.worldSurface * 16.0 || player.ZoneBeach)
return;
int maxValue1 = 1;
if (!flag || Main.rand.Next(maxValue1) != 0)
return;
int num1 = Math.Sign(Main.windSpeedCurrent);
float amount = Math.Abs(Main.windSpeedCurrent);
if ((double) amount < 0.00999999977648258)
return;
float num2 = (float) num1 * MathHelper.Lerp(0.9f, 1f, amount);
float num3 = 2000f / (float) sandTileCount;
float num4 = MathHelper.Clamp(3f / num3, 0.77f, 1f);
int num5 = (int) num3;
int num6 = (int) (1000.0 * (double) ((float) Main.screenWidth / (float) Main.maxScreenW));
float num7 = 20f * Sandstorm.Severity;
float num8 = (float) ((double) num6 * ((double) Main.gfxQuality * 0.5 + 0.5) + (double) num6 * 0.100000001490116) - (float) Dust.SandStormCount;
if ((double) num8 <= 0.0)
return;
float num9 = (float) Main.screenWidth + 1000f;
float screenHeight = (float) Main.screenHeight;
Vector2 vector2 = Main.screenPosition + player.velocity;
WeightedRandom<Color> weightedRandom = new WeightedRandom<Color>();
weightedRandom.Add(new Color(200, 160, 20, 180), (double) (Main.SceneMetrics.GetTileCount((ushort) 53) + Main.SceneMetrics.GetTileCount((ushort) 396) + Main.SceneMetrics.GetTileCount((ushort) 397)));
weightedRandom.Add(new Color(103, 98, 122, 180), (double) (Main.SceneMetrics.GetTileCount((ushort) 112) + Main.SceneMetrics.GetTileCount((ushort) 400) + Main.SceneMetrics.GetTileCount((ushort) 398)));
weightedRandom.Add(new Color(135, 43, 34, 180), (double) (Main.SceneMetrics.GetTileCount((ushort) 234) + Main.SceneMetrics.GetTileCount((ushort) 401) + Main.SceneMetrics.GetTileCount((ushort) 399)));
weightedRandom.Add(new Color(213, 196, 197, 180), (double) (Main.SceneMetrics.GetTileCount((ushort) 116) + Main.SceneMetrics.GetTileCount((ushort) 403) + Main.SceneMetrics.GetTileCount((ushort) 402)));
float num10 = MathHelper.Lerp(0.2f, 0.35f, Sandstorm.Severity);
float num11 = MathHelper.Lerp(0.5f, 0.7f, Sandstorm.Severity);
int maxValue2 = (int) MathHelper.Lerp(1f, 10f, (float) (((double) num4 - 0.769999980926514) / 0.230000019073486));
for (int index1 = 0; (double) index1 < (double) num7; ++index1)
{
if (Main.rand.Next(num5 / 4) == 0)
{
Vector2 Position = new Vector2((float) ((double) Main.rand.NextFloat() * (double) num9 - 500.0), Main.rand.NextFloat() * -50f);
if (Main.rand.Next(3) == 0 && num1 == 1)
Position.X = (float) (Main.rand.Next(500) - 500);
else if (Main.rand.Next(3) == 0 && num1 == -1)
Position.X = (float) (Main.rand.Next(500) + Main.screenWidth);
if ((double) Position.X < 0.0 || (double) Position.X > (double) Main.screenWidth)
Position.Y += (float) ((double) Main.rand.NextFloat() * (double) screenHeight * 0.899999976158142);
Position += vector2;
int x1 = (int) Position.X / 16;
int y1 = (int) Position.Y / 16;
if (WorldGen.InWorld(x1, y1, 10) && Main.tile[x1, y1] != null && Main.tile[x1, y1].wall == (ushort) 0)
{
for (int index2 = 0; index2 < 1; ++index2)
{
Dust dust = Main.dust[Dust.NewDust(Position, 10, 10, 268)];
dust.velocity.Y = (float) (2.0 + (double) Main.rand.NextFloat() * 0.200000002980232);
dust.velocity.Y *= dust.scale;
dust.velocity.Y *= 0.35f;
dust.velocity.X = (float) ((double) num2 * 5.0 + (double) Main.rand.NextFloat() * 1.0);
dust.velocity.X += (float) ((double) num2 * (double) num11 * 20.0);
dust.fadeIn += num11 * 0.2f;
dust.velocity *= (float) (1.0 + (double) num10 * 0.5);
dust.color = (Color) weightedRandom;
dust.velocity *= 1f + num10;
dust.velocity *= num4;
dust.scale = 0.9f;
--num8;
if ((double) num8 > 0.0)
{
if (Main.rand.Next(maxValue2) != 0)
{
--index2;
Position += Utils.RandomVector2(Main.rand, -10f, 10f) + dust.velocity * -1.1f;
int x2 = (int) Position.X / 16;
int y2 = (int) Position.Y / 16;
if (WorldGen.InWorld(x2, y2, 10) && Main.tile[x2, y2] != null)
{
int wall = (int) Main.tile[x2, y2].wall;
}
}
}
else
break;
}
if ((double) num8 <= 0.0)
break;
}
}
}
}
}
}

View file

@ -0,0 +1,48 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.Events.ScreenDarkness
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Terraria.GameContent.Events
{
public class ScreenDarkness
{
public static float screenObstruction;
public static void Update()
{
float num = 0.0f;
float amount = 0.1f;
Vector2 mountedCenter = Main.player[Main.myPlayer].MountedCenter;
for (int index = 0; index < 200; ++index)
{
if (Main.npc[index].active && Main.npc[index].type == 370 && (double) Main.npc[index].Distance(mountedCenter) < 3000.0 && ((double) Main.npc[index].ai[0] >= 10.0 || (double) Main.npc[index].ai[0] == 9.0 && (double) Main.npc[index].ai[2] > 120.0))
{
num = 0.95f;
amount = 0.03f;
}
}
ScreenDarkness.screenObstruction = MathHelper.Lerp(ScreenDarkness.screenObstruction, num, amount);
}
public static void DrawBack(SpriteBatch spriteBatch)
{
if ((double) ScreenDarkness.screenObstruction == 0.0)
return;
Color color = Color.Black * ScreenDarkness.screenObstruction;
spriteBatch.Draw(TextureAssets.MagicPixel.Value, new Rectangle(-2, -2, Main.screenWidth + 4, Main.screenHeight + 4), new Rectangle?(new Rectangle(0, 0, 1, 1)), color);
}
public static void DrawFront(SpriteBatch spriteBatch)
{
if ((double) ScreenDarkness.screenObstruction == 0.0)
return;
Color color = new Color(0, 0, 120) * ScreenDarkness.screenObstruction * 0.3f;
spriteBatch.Draw(TextureAssets.MagicPixel.Value, new Rectangle(-2, -2, Main.screenWidth + 4, Main.screenHeight + 4), new Rectangle?(new Rectangle(0, 0, 1, 1)), color);
}
}
}

View file

@ -0,0 +1,49 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.Events.ScreenObstruction
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Terraria.GameContent.Events
{
public class ScreenObstruction
{
public static float screenObstruction;
public static void Update()
{
float num = 0.0f;
float amount = 0.1f;
if (Main.player[Main.myPlayer].headcovered)
{
num = 0.95f;
amount = 0.3f;
}
ScreenObstruction.screenObstruction = MathHelper.Lerp(ScreenObstruction.screenObstruction, num, amount);
}
public static void Draw(SpriteBatch spriteBatch)
{
if ((double) ScreenObstruction.screenObstruction == 0.0)
return;
Color color = Color.Black * ScreenObstruction.screenObstruction;
int num1 = TextureAssets.Extra[49].Width();
int num2 = 10;
Rectangle rect = Main.player[Main.myPlayer].getRect();
rect.Inflate((num1 - rect.Width) / 2, (num1 - rect.Height) / 2 + num2 / 2);
rect.Offset(-(int) Main.screenPosition.X, -(int) Main.screenPosition.Y + (int) Main.player[Main.myPlayer].gfxOffY - num2);
Rectangle destinationRectangle1 = Rectangle.Union(new Rectangle(0, 0, 1, 1), new Rectangle(rect.Right - 1, rect.Top - 1, 1, 1));
Rectangle destinationRectangle2 = Rectangle.Union(new Rectangle(Main.screenWidth - 1, 0, 1, 1), new Rectangle(rect.Right, rect.Bottom - 1, 1, 1));
Rectangle destinationRectangle3 = Rectangle.Union(new Rectangle(Main.screenWidth - 1, Main.screenHeight - 1, 1, 1), new Rectangle(rect.Left, rect.Bottom, 1, 1));
Rectangle destinationRectangle4 = Rectangle.Union(new Rectangle(0, Main.screenHeight - 1, 1, 1), new Rectangle(rect.Left - 1, rect.Top, 1, 1));
spriteBatch.Draw(TextureAssets.MagicPixel.Value, destinationRectangle1, new Rectangle?(new Rectangle(0, 0, 1, 1)), color);
spriteBatch.Draw(TextureAssets.MagicPixel.Value, destinationRectangle2, new Rectangle?(new Rectangle(0, 0, 1, 1)), color);
spriteBatch.Draw(TextureAssets.MagicPixel.Value, destinationRectangle3, new Rectangle?(new Rectangle(0, 0, 1, 1)), color);
spriteBatch.Draw(TextureAssets.MagicPixel.Value, destinationRectangle4, new Rectangle?(new Rectangle(0, 0, 1, 1)), color);
spriteBatch.Draw(TextureAssets.Extra[49].Value, rect, color);
}
}
}