Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
LucyAxeMessage.cs
Go to the documentation of this file.
4using Terraria.ID;
6using Terraria.UI;
7
9
10public static class LucyAxeMessage
11{
12 public enum MessageSource
13 {
14 Idle,
15 Storage,
21 Count
22 }
23
24 private static byte _variation;
25
26 private static int[] _messageCooldownsByType = new int[7];
27
28 private static string GetCategoryName(MessageSource source)
29 {
30 return source switch
31 {
32 MessageSource.Storage => "LucyTheAxe_Storage",
33 MessageSource.ThrownAway => "LucyTheAxe_ThrownAway",
34 MessageSource.PickedUp => "LucyTheAxe_PickedUp",
35 MessageSource.ChoppedTree => "LucyTheAxe_ChoppedTree",
36 MessageSource.ChoppedGemTree => "LucyTheAxe_GemTree",
37 MessageSource.ChoppedCactus => "LucyTheAxe_ChoppedCactus",
38 _ => "LucyTheAxe_Idle",
39 };
40 }
41
42 public static void Initialize()
43 {
44 ItemSlot.OnItemTransferred += ItemSlot_OnItemTransferred;
45 Player.Hooks.OnEnterWorld += Hooks_OnEnterWorld;
46 }
47
48 private static void Hooks_OnEnterWorld(Player player)
49 {
50 if (player == Main.LocalPlayer)
51 {
53 }
54 }
55
56 public static void UpdateMessageCooldowns()
57 {
58 for (int i = 0; i < _messageCooldownsByType.Length; i++)
59 {
60 if (_messageCooldownsByType[i] > 0)
61 {
63 }
64 }
65 }
66
67 public static void TryPlayingIdleMessage()
68 {
69 MessageSource messageSource = MessageSource.Idle;
70 if (_messageCooldownsByType[(int)messageSource] <= 0)
71 {
72 Player localPlayer = Main.LocalPlayer;
73 Create(messageSource, localPlayer.Top, new Vector2(Main.rand.NextFloatDirection() * 7f, -2f + Main.rand.NextFloat() * -2f));
74 }
75 }
76
78 {
79 if (info.ItemType != 5095)
80 {
81 return;
82 }
83 bool flag = CountsAsStorage(info.FromContenxt);
84 bool flag2 = CountsAsStorage(info.ToContext);
85 if (flag != flag2)
86 {
87 MessageSource messageSource = ((!flag) ? MessageSource.Storage : MessageSource.PickedUp);
88 if (_messageCooldownsByType[(int)messageSource] <= 0)
89 {
90 PutMessageTypeOnCooldown(messageSource, 420);
91 Player localPlayer = Main.LocalPlayer;
92 Create(messageSource, localPlayer.Top, new Vector2(localPlayer.direction * 7, -2f));
93 }
94 }
95 }
96
97 private static void GiveIdleMessageCooldown()
98 {
99 PutMessageTypeOnCooldown(MessageSource.Idle, Main.rand.Next(7200, 14400));
100 }
101
102 public static void PutMessageTypeOnCooldown(MessageSource source, int timeInFrames)
103 {
104 _messageCooldownsByType[(int)source] = timeInFrames;
105 }
106
107 private static bool CountsAsStorage(int itemSlotContext)
108 {
109 if (itemSlotContext == 3 || itemSlotContext == 6 || itemSlotContext == 15)
110 {
111 return true;
112 }
113 return false;
114 }
115
116 public static void TryCreatingMessageWithCooldown(MessageSource messageSource, Vector2 position, Vector2 velocity, int cooldownTimeInTicks)
117 {
118 if (Main.netMode != 2 && _messageCooldownsByType[(int)messageSource] <= 0)
119 {
120 PutMessageTypeOnCooldown(messageSource, cooldownTimeInTicks);
121 Create(messageSource, position, velocity);
122 }
123 }
124
125 public static void Create(MessageSource source, Vector2 position, Vector2 velocity)
126 {
127 if (Main.netMode != 2)
128 {
130 SpawnPopupText(source, _variation, position, velocity);
131 PlaySound(source, position);
133 if (Main.netMode == 1)
134 {
135 NetMessage.SendData(141, -1, -1, null, (int)source, (int)_variation, velocity.X, velocity.Y, (int)position.X, (int)position.Y);
136 }
137 _variation++;
138 }
139 }
140
141 private static void SpawnEmoteBubble()
142 {
144 }
145
146 public static void CreateFromNet(MessageSource source, byte variation, Vector2 position, Vector2 velocity)
147 {
148 SpawnPopupText(source, variation, position, velocity);
149 PlaySound(source, position);
150 }
151
152 private static void PlaySound(MessageSource source, Vector2 position)
153 {
155 }
156
157 private static void SpawnPopupText(MessageSource source, int variationUnwrapped, Vector2 position, Vector2 velocity)
158 {
159 string textForVariation = GetTextForVariation(source, variationUnwrapped);
161 request.Text = textForVariation;
162 request.DurationInFrames = 420;
163 request.Velocity = velocity;
164 request.Color = new Color(184, 96, 98) * 1.15f;
165 PopupText.NewText(request, position);
166 }
167
168 private static string GetTextForVariation(MessageSource source, int variationUnwrapped)
169 {
170 string categoryName = GetCategoryName(source);
171 return LanguageManager.Instance.IndexedFromCategory(categoryName, variationUnwrapped).Value;
172 }
173}
static void PlaySound(int type, Vector2 position, int style=1)
Vector2 Top
Definition Entity.cs:79
static void PutMessageTypeOnCooldown(MessageSource source, int timeInFrames)
static string GetCategoryName(MessageSource source)
static string GetTextForVariation(MessageSource source, int variationUnwrapped)
static void PlaySound(MessageSource source, Vector2 position)
static void ItemSlot_OnItemTransferred(ItemSlot.ItemTransferInfo info)
static bool CountsAsStorage(int itemSlotContext)
static void CreateFromNet(MessageSource source, byte variation, Vector2 position, Vector2 velocity)
static void Hooks_OnEnterWorld(Player player)
static void TryCreatingMessageWithCooldown(MessageSource messageSource, Vector2 position, Vector2 velocity, int cooldownTimeInTicks)
static void SpawnPopupText(MessageSource source, int variationUnwrapped, Vector2 position, Vector2 velocity)
static void Create(MessageSource source, Vector2 position, Vector2 velocity)
static void MakeLocalPlayerEmote(int emoteId)
static readonly LegacySoundStyle LucyTheAxeTalk
Definition SoundID.cs:958
static int netMode
Definition Main.cs:2095
static UnifiedRandom rand
Definition Main.cs:1387
static Player LocalPlayer
Definition Main.cs:2829
static void SendData(int msgType, int remoteClient=-1, int ignoreClient=-1, NetworkText text=null, int number=0, float number2=0f, float number3=0f, float number4=0f, int number5=0, int number6=0, int number7=0)
Definition NetMessage.cs:88
static int NewText(AdvancedPopupRequest request, Vector2 position)
Definition PopupText.cs:95