-
Notifications
You must be signed in to change notification settings - Fork 4
/
Coralite.cs
211 lines (186 loc) · 7.45 KB
/
Coralite.cs
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
//global usings
global using InnoVault;
global using Microsoft.Xna.Framework;
global using Terraria.ModLoader;
global using ATex = ReLogic.Content.Asset<Microsoft.Xna.Framework.Graphics.Texture2D>;
global using Particle = InnoVault.PRT.BasePRT;
using Coralite.Compat.BossCheckList;
using Coralite.Core;
using Coralite.Core.Prefabs.Projectiles;
using Coralite.Core.Systems.BossSystems;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Terraria;
namespace Coralite
{
public class Coralite : Mod
{
public const int YujianHuluContainsMax = 3;
private List<IOrderedLoadable> loadCache;
public NoSmoother NoSmootherInstance;
public HeavySmoother HeavySmootherInstance;
public SqrtSmoother SqrtSmoother;
public X2Smoother X2Smoother;
public X3Smoother X3Smoother;
public SinSmoother SinSmoother;
public BezierEaseSmoother BezierEaseSmoother;
/// <summary>
/// 从0快速接近1,之后快速返回0<br></br>
/// 在0.5的时候到达1
/// </summary>
public ReverseX2Smoother ReverseX2Smoother;
public static Color RedJadeRed => new(221, 50, 50);
/// <summary> ffbeec </summary>
public static Color MagicCrystalPink => new(255, 190, 236);
public static Color GlistentGreen => new(127, 218, 153);
public static Color CrimsonRed => new(231, 48, 54);
public static Color CorruptionPurple => new(107, 66, 208);
public static Color IcicleCyan => new(43, 255, 198);
public static Color ShadowPurple => new(240, 168, 255);
public static Color CrystallineMagikePurple => new(140, 130, 252);
public static Color HallowYellow => new(253, 236, 144);
public static Color ThunderveinYellow => new(255, 202, 101);
public static Color SoulCyan => new(122, 174, 188);
public static Color FeatherLime => new(122, 161, 82);
public static Color SplendorMagicoreLightBlue => new(190, 225, 235);
private static Coralite _instance;
//单例模式!
public static Coralite Instance
{
get
{
_instance ??= (Coralite)ModLoader.GetMod("Coralite");
return _instance;
}
set
{
_instance = value;
}
}
public override void Load()
{
Instance = this;
NoSmootherInstance = new NoSmoother();
HeavySmootherInstance = new HeavySmoother();
SqrtSmoother = new SqrtSmoother();
X2Smoother = new X2Smoother();
X3Smoother = new X3Smoother();
SinSmoother = new SinSmoother();
BezierEaseSmoother = new BezierEaseSmoother();
ReverseX2Smoother = new ReverseX2Smoother();
loadCache = [];
foreach (Type type in Code.GetTypes())
{
if (!type.IsAbstract && type.GetInterfaces().Contains(typeof(IOrderedLoadable)))
{
var instance = Activator.CreateInstance(type);//创建实例
loadCache.Add(instance as IOrderedLoadable);//添加到列表里
}
loadCache.Sort((n, t) => n.Priority.CompareTo(t.Priority));//按照优先度排序
}
for (int k = 0; k < loadCache.Count; k++)
{
loadCache[k].Load();
//SetLoadingText("Loading " + loadCache[k].GetType().Name);
}
}
public override void Unload()
{
if (loadCache is not null)
{
foreach (var loadable in loadCache)
{
loadable.Unload();
}
loadCache = null;
}
Instance = null;
}
/// <summary>
/// 设置加载的时候在屏幕上显示的内容
/// </summary>
public static void SetLoadingText(string text)
{
var Interface_loadMods = typeof(Mod).Assembly.GetType("Terraria.ModLoader.UI.Interface")!.GetField("loadMods", BindingFlags.NonPublic | BindingFlags.Static)!;
var UIProgress_set_SubProgressText = typeof(Mod).Assembly.GetType("Terraria.ModLoader.UI.UIProgress")!.GetProperty("SubProgressText", BindingFlags.Public | BindingFlags.Instance)!.GetSetMethod()!;
UIProgress_set_SubProgressText.Invoke(Interface_loadMods.GetValue(null), new object[] { text });
}
public override void PostSetupContent()
{
BossCheckListCalls.CallBossCheckList();
}
public override object Call(params object[] args)
{
int argsLength = args.Length;
//Array.Resize(ref args, 15);
try
{
string methodName = args[0] as string;
switch (methodName)
{
default: break;
case "GetBossDowned"://获取击败BOSS的bool值
case "BossDowned":
if (argsLength < 2)
return new ArgumentNullException("ERROR: Must specify a boss or event name as a string.");
if (args[1] is not string)
return new ArgumentException("ERROR: The argument to \"Downed\" must be a string.");
return GetBossDowned(args[1].ToString());
}
}
catch (Exception e)
{
Logger.Error($"Call Error: {e.StackTrace} {e.Message}");
}
return new ArgumentException("ERROR: Invalid method name.");
}
/// <summary>
/// 获取击败BOSS的bool
/// </summary>
/// <param name="bossName"></param>
/// <returns></returns>
public static bool GetBossDowned(string bossName)
{
return bossName.ToLower() switch
{
"赤玉灵" or
"Rediancie"
=> DownedBossSystem.downedRediancie,
"冰龙宝宝" or
"BabyIceDragon" or
"Baby Ice Dragon"
=> DownedBossSystem.downedBabyIceDragon,
// "影子球" or "ShadowBalls" => DownedBossSystem.xxxx,
"荒雷龙" or
"ThunderveinDragon" or
"Thundervein Dragon"
=> DownedBossSystem.downedThunderveinDragon,
"史莱姆皇帝" or
"至高帝史莱姆王" or
"至高帝·史莱姆王" or
"至高帝" or
"SlimeEmperor" or
"Slime Emperor"
=> DownedBossSystem.downedSlimeEmperor,
"赤血玉灵" or
"血咒精赤玉灵" or
"血咒精·赤玉灵" or
"血咒精" or
"Bloodiancie"
=> DownedBossSystem.downedBloodiancie,
"梦魇之花" or
"梦界主世纪之花" or
"梦界主·世纪之花" or
"梦界主" or
"NightmarePlantera" or
"Nightmare Plantera"
=> DownedBossSystem.downedNightmarePlantera,
_ => false,
};
}
public override void HandlePacket(BinaryReader reader, int whoAmI) => CoraliteNetWork.NetWorkHander(reader, whoAmI);
}
}