Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
FinalFractalHelper.cs
Go to the documentation of this file.
2using System.Linq;
6
7namespace Terraria.Graphics;
8
9[StructLayout(LayoutKind.Sequential, Size = 1)]
10public struct FinalFractalHelper
11{
12 public delegate void SpawnDustMethod(Vector2 centerPosition, float rotation, Vector2 velocity);
13
14 public struct FinalFractalProfile
15 {
16 public float trailWidth;
17
19
20 public SpawnDustMethod dustMethod;
21
22 public VertexStrip.StripColorFunction colorMethod;
23
24 public VertexStrip.StripHalfWidthFunction widthMethod;
25
27 {
29 trailColor = color;
30 widthMethod = null;
31 colorMethod = null;
32 dustMethod = null;
36 }
37
38 private void StripDust(Vector2 centerPosition, float rotation, Vector2 velocity)
39 {
40 if (Main.rand.Next(9) == 0)
41 {
42 int num = Main.rand.Next(1, 4);
43 for (int i = 0; i < num; i++)
44 {
45 Dust dust = Dust.NewDustPerfect(centerPosition, 278, null, 100, Color.Lerp(trailColor, Color.White, Main.rand.NextFloat() * 0.3f));
46 dust.scale = 0.4f;
47 dust.fadeIn = 0.4f + Main.rand.NextFloat() * 0.3f;
48 dust.noGravity = true;
49 dust.velocity += rotation.ToRotationVector2() * (3f + Main.rand.NextFloat() * 4f);
50 }
51 }
52 }
53
55 {
56 Color result = trailColor * (1f - Utils.GetLerpValue(0f, 0.98f, progressOnStrip));
57 result.A /= 2;
58 return result;
59 }
60
61 private float StripWidth(float progressOnStrip)
62 {
63 return trailWidth;
64 }
65 }
66
67 public const int TotalIllusions = 4;
68
69 public const int FramesPerImportantTrail = 15;
70
71 private static VertexStrip _vertexStrip = new VertexStrip();
72
74 {
75 {
76 65,
77 new FinalFractalProfile(48f, new Color(236, 62, 192))
78 },
79 {
80 1123,
82 },
83 {
84 46,
85 new FinalFractalProfile(48f, new Color(122, 66, 191))
86 },
87 {
88 121,
89 new FinalFractalProfile(76f, new Color(254, 158, 35))
90 },
91 {
92 190,
93 new FinalFractalProfile(70f, new Color(107, 203, 0))
94 },
95 {
96 368,
97 new FinalFractalProfile(70f, new Color(236, 200, 19))
98 },
99 {
100 674,
101 new FinalFractalProfile(70f, new Color(236, 200, 19))
102 },
103 {
104 273,
105 new FinalFractalProfile(70f, new Color(179, 54, 201))
106 },
107 {
108 675,
109 new FinalFractalProfile(70f, new Color(179, 54, 201))
110 },
111 {
112 2880,
113 new FinalFractalProfile(70f, new Color(84, 234, 245))
114 },
115 {
116 989,
117 new FinalFractalProfile(48f, new Color(91, 158, 232))
118 },
119 {
120 1826,
121 new FinalFractalProfile(76f, new Color(252, 95, 4))
122 },
123 {
124 3063,
125 new FinalFractalProfile(76f, new Color(254, 194, 250))
126 },
127 {
128 3065,
129 new FinalFractalProfile(70f, new Color(237, 63, 133))
130 },
131 {
132 757,
133 new FinalFractalProfile(70f, new Color(80, 222, 122))
134 },
135 {
136 155,
137 new FinalFractalProfile(70f, new Color(56, 78, 210))
138 },
139 {
140 795,
141 new FinalFractalProfile(70f, new Color(237, 28, 36))
142 },
143 {
144 3018,
145 new FinalFractalProfile(80f, new Color(143, 215, 29))
146 },
147 {
148 4144,
149 new FinalFractalProfile(45f, new Color(178, 255, 180))
150 },
151 {
152 3507,
153 new FinalFractalProfile(45f, new Color(235, 166, 135))
154 },
155 {
156 4956,
157 new FinalFractalProfile(86f, new Color(178, 255, 180))
158 }
159 };
160
162
163 public static int GetRandomProfileIndex()
164 {
165 List<int> list = _fractalProfiles.Keys.ToList();
166 int index = Main.rand.Next(list.Count);
167 if (list[index] == 4956)
168 {
169 list.RemoveAt(index);
170 index = Main.rand.Next(list.Count);
171 }
172 return list[index];
173 }
174
175 public void Draw(Projectile proj)
176 {
179 int num = 4;
180 int num2 = 0;
181 int num3 = 0;
182 int num4 = 4;
183 miscShaderData.UseShaderSpecificData(new Vector4(num, num2, num3, num4));
184 miscShaderData.UseImage0("Images/Extra_" + (short)201);
185 miscShaderData.UseImage1("Images/Extra_" + (short)193);
186 miscShaderData.Apply();
187 _vertexStrip.PrepareStrip(proj.oldPos, proj.oldRot, finalFractalProfile.colorMethod, finalFractalProfile.widthMethod, -Main.screenPosition + proj.Size / 2f, proj.oldPos.Length, includeBacksides: true);
188 _vertexStrip.DrawTrail();
189 Main.pixelShader.CurrentTechnique.Passes[0].Apply();
190 }
191
193 {
194 if (!_fractalProfiles.TryGetValue(usedSwordId, out var value))
195 {
196 return _defaultProfile;
197 }
198 return value;
199 }
200
202 {
204 result.A /= 2;
205 return result;
206 }
207
208 private float StripWidth(float progressOnStrip)
209 {
210 return 50f;
211 }
212}
static Dust NewDustPerfect(Vector2 Position, int Type, Vector2? Velocity=null, int Alpha=0, Color newColor=default(Color), float Scale=1f)
Definition Dust.cs:52
static Dictionary< string, MiscShaderData > Misc
static Effect pixelShader
Definition Main.cs:2764
static Vector2 screenPosition
Definition Main.cs:1715
static Microsoft.Xna.Framework.Color OurFavoriteColor
Definition Main.cs:902
static UnifiedRandom rand
Definition Main.cs:1387
static float GetLerpValue(float from, float to, float t, bool clamped=false)
Definition Utils.cs:203
static Color Lerp(Color value1, Color value2, float amount)
Definition Color.cs:491
void StripDust(Vector2 centerPosition, float rotation, Vector2 velocity)
static Dictionary< int, FinalFractalProfile > _fractalProfiles
delegate void SpawnDustMethod(Vector2 centerPosition, float rotation, Vector2 velocity)
Color StripColors(float progressOnStrip)
float StripWidth(float progressOnStrip)
static FinalFractalProfile _defaultProfile
static FinalFractalProfile GetFinalFractalProfile(int usedSwordId)