Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ItemTransferParticle.cs
Go to the documentation of this file.
3using Terraria.UI;
4
6
8{
10
12
14
16
18
19 private int _lifeTimeCounted;
20
21 private int _lifeTimeTotal;
22
23 public bool ShouldBeRemovedFromRenderer { get; private set; }
24
25 public bool IsRestingInPool { get; private set; }
26
28 {
29 _itemInstance = new Item();
30 }
31
32 public void Update(ref ParticleRendererSettings settings)
33 {
35 {
37 }
38 }
39
40 public void Prepare(int itemType, int lifeTimeTotal, Vector2 playerPosition, Vector2 chestPosition)
41 {
42 _itemInstance.SetDefaults(itemType);
43 _lifeTimeTotal = lifeTimeTotal;
44 StartPosition = playerPosition;
45 EndPosition = chestPosition;
46 Vector2 vector = (EndPosition - StartPosition).SafeNormalize(Vector2.UnitY).RotatedBy(1.5707963705062866);
47 bool num = vector.Y < 0f;
48 bool flag = vector.Y == 0f;
49 if (!num || (flag && Main.rand.Next(2) == 0))
50 {
51 vector *= -1f;
52 }
53 vector = new Vector2(0f, -1f);
55 BezierHelper1 = vector * num2 + Main.rand.NextVector2Circular(32f, 32f);
56 BezierHelper2 = -vector * num2 + Main.rand.NextVector2Circular(32f, 32f);
57 }
58
59 public void Draw(ref ParticleRendererSettings settings, SpriteBatch spritebatch)
60 {
61 float fromValue = (float)_lifeTimeCounted / (float)_lifeTimeTotal;
62 float toMin = Utils.Remap(fromValue, 0.1f, 0.5f, 0f, 0.85f);
63 toMin = Utils.Remap(fromValue, 0.5f, 0.9f, toMin, 1f);
64 Vector2.Hermite(ref StartPosition, ref BezierHelper1, ref EndPosition, ref BezierHelper2, toMin, out var result);
65 float toMin2 = Utils.Remap(fromValue, 0f, 0.1f, 0f, 1f);
66 toMin2 = Utils.Remap(fromValue, 0.85f, 0.95f, toMin2, 0f);
67 float num = Utils.Remap(fromValue, 0f, 0.25f, 0f, 1f) * Utils.Remap(fromValue, 0.85f, 0.95f, 1f, 0f);
68 ItemSlot.DrawItemIcon(_itemInstance, 31, Main.spriteBatch, settings.AnchorPosition + result, _itemInstance.scale * toMin2, 100f, Color.White * num);
69 }
70
71 public void RestInPool()
72 {
73 IsRestingInPool = true;
74 }
75
76 public virtual void FetchFromPool()
77 {
80 IsRestingInPool = false;
83 }
84}
void Prepare(int itemType, int lifeTimeTotal, Vector2 playerPosition, Vector2 chestPosition)
void Draw(ref ParticleRendererSettings settings, SpriteBatch spritebatch)
void Update(ref ParticleRendererSettings settings)
float scale
Definition Item.cs:189
void SetDefaults(int Type=0)
Definition Item.cs:47332
static SpriteBatch spriteBatch
Definition Main.cs:974
static UnifiedRandom rand
Definition Main.cs:1387
static float DrawItemIcon(Item item, int context, SpriteBatch spriteBatch, Vector2 screenPositionForItemCenter, float scale, float sizeLimit, Color environmentColor)
Definition ItemSlot.cs:2273
static float Remap(float fromValue, float fromMin, float fromMax, float toMin, float toMax, bool clamped=true)
Definition Utils.cs:233
static float Distance(Vector2 value1, Vector2 value2)
Definition Vector2.cs:91
static Vector2 Hermite(Vector2 value1, Vector2 tangent1, Vector2 value2, Vector2 tangent2, float amount)
Definition Vector2.cs:291