-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCalTestHelpersWorld.cs
More file actions
144 lines (131 loc) · 6.3 KB
/
CalTestHelpersWorld.cs
File metadata and controls
144 lines (131 loc) · 6.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
using CalamityMod.CalPlayer;
using CalamityMod.Projectiles.Boss;
using CalamityMod.World;
using CalTestHelpers.UI;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Terraria;
using Terraria.Chat;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;
using Terraria.UI;
using static Terraria.ModLoader.ModContent;
namespace CalTestHelpers
{
public class CalTestHelpersWorld : ModSystem
{
public static int OriginalTime;
public static int BossKillTimeFrames;
public static bool NoSpawns = false;
public static bool FrozenTime = false;
public static List<int> BossKillDPS = new List<int>();
public string LocalisationKey = "Mods.CalTestHelpers.BossDeathStats.";
public override void SaveWorldData(TagCompound tag)
{
tag["NoSpawns"] = NoSpawns;
tag["FrozenTime"] = FrozenTime;
}
public override void LoadWorldData(TagCompound tag)
{
NoSpawns = tag.GetBool("NoSpawns");
}
public override void NetSend(BinaryWriter writer)
{
writer.Write(NoSpawns);
}
public override void NetReceive(BinaryReader reader)
{
NoSpawns = reader.ReadBoolean();
}
public override void PostUpdateWorld()
{
if (CalamityPlayer.areThereAnyDamnBosses && !Main.LocalPlayer.dead)
{
BossKillTimeFrames++;
// Incorporate any new DPS values as they come.
if (Main.LocalPlayer.dpsDamage != BossKillDPS.LastOrDefault())
{
BossKillDPS.Add(Main.LocalPlayer.dpsDamage);
}
}
else if (BossKillTimeFrames >= 2)
{
double averageDPS = BossKillDPS.Count == 0 ? 0f : BossKillDPS.Average();
double maxDPS = BossKillDPS.Count == 0 ? 0f : BossKillDPS.Max();
string timeString = TimeSpan.FromSeconds(BossKillTimeFrames / 60f).ToString(@"hh\:mm\:ss");
if (CalTestHelperConfig.Instance.BossDeathStatMessages)
{
//string textToDisplay = Language.GetTextValue(, timeString, maxDPS, (maxDPS+1f)/(averageDPS+1f));
ChatHelper.BroadcastChatMessage(NetworkText.FromKey(LocalisationKey + "Time", timeString), Color.Crimson);
ChatHelper.BroadcastChatMessage(NetworkText.FromKey(LocalisationKey + "AverageDPS", averageDPS), Color.Crimson);
ChatHelper.BroadcastChatMessage(NetworkText.FromKey(LocalisationKey + "MaxDPS", maxDPS), Color.Crimson);
ChatHelper.BroadcastChatMessage(NetworkText.FromKey(LocalisationKey + "Instability", Math.Round((maxDPS + 1f) / (averageDPS + 1f), 2)), Color.Crimson);
/*string textToDisplay = $"Time Elapsed: {timeString}\n" +
$"Average DPS: {averageDPS}\n" +
$"Maximum DPS: {maxDPS}\n" +
$"DPS Instability Factor: {(maxDPS + 1f) / (averageDPS + 1f)}";
// Newlines fuck text displays up.
foreach (var snippet in textToDisplay.Split('\n'))
{
if (Main.netMode == NetmodeID.SinglePlayer)
Main.NewText(snippet, Color.Crimson);
else if (Main.netMode == NetmodeID.Server)
ChatHelper.BroadcastChatMessage(NetworkText.FromLiteral(snippet), Color.Crimson);
}
*/
}
if (CalTestHelperConfig.Instance.StoreFightInformation)
FightInformationPrintManager.SaveFightInformation();
BossKillDPS.Clear();
BossKillTimeFrames = 0;
}
if (CalTestHelperConfig.Instance.InstantBossSummoning)
if (CalamityWorld.DraedonSummonCountdown > 0)
CalamityWorld.DraedonSummonCountdown = 1;
// Scal goes on Global Projectile since Xyk made the value of the ritual a constant
}
public override void PostUpdateEverything()
{
CalTestHelpers.GlobalTickTimer++;
if (CalTestHelpers.HasDonePostLoading)
return;
ItemOverrideCache.Load();
EntityOverrideCache.Load();
CalTestHelpers.HasDonePostLoading = true;
}
public override void ModifyInterfaceLayers(List<GameInterfaceLayer> layers)
{
int mouseIndex = layers.FindIndex(layer => layer.Name == "Vanilla: Mouse Text");
if (mouseIndex != -1)
{
layers.Insert(mouseIndex, new LegacyGameInterfaceLayer("Special UIs", () =>
{
if (!Main.inFancyUI && Main.playerInventory)
{
CalTestHelpers.UltimateUI.Draw(Main.spriteBatch);
if (CalTestHelpers.SecondaryUIToDisplay != null)
CalTestHelpers.SecondaryUIToDisplay.Draw(Main.spriteBatch);
}
// Draw a gear at the bottom of the screen if any stat manipulations have been done
// This is done to prevent cheating by nohitters (who use this mod).
// If you attempt to remove this behavior and do something like this, I am not responsible.
// - Lucille
if (CalTestHelpers.HaveAnyStatManipulationsBeenDone)
{
Texture2D gearTexture = ModContent.Request<Texture2D>("CalTestHelpers/UI/Gear").Value;
Vector2 gearDrawPosition = new Vector2(Main.screenWidth - 400f, Main.screenHeight - 60f);
Main.spriteBatch.Draw(gearTexture, gearDrawPosition, null, Color.Cyan, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
}
return true;
}, InterfaceScaleType.UI));
}
}
public override void PostDrawFullscreenMap(ref string mouseText) => MapServices.TryToTeleportPlayerOnMap();
}
}