Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
BirthdayParty.cs
Go to the documentation of this file.
2using System.Linq;
6using Terraria.ID;
8
10
11public class BirthdayParty
12{
13 public static bool ManualParty;
14
15 public static bool GenuineParty;
16
17 public static int PartyDaysOnCooldown;
18
19 public static List<int> CelebratingNPCs = new List<int>();
20
21 private static bool _wasCelebrating;
22
23 public static bool PartyIsUp
24 {
25 get
26 {
27 if (!GenuineParty)
28 {
29 return ManualParty;
30 }
31 return true;
32 }
33 }
34
35 public static void CheckMorning()
36 {
38 }
39
40 public static void CheckNight()
41 {
42 bool flag = false;
43 if (GenuineParty)
44 {
45 flag = true;
46 GenuineParty = false;
47 CelebratingNPCs.Clear();
48 }
49 if (ManualParty)
50 {
51 flag = true;
52 ManualParty = false;
53 }
54 if (flag)
55 {
56 WorldGen.BroadcastText(color: new Color(255, 0, 160), text: NetworkText.FromKey(Lang.misc[99].Key));
57 }
58 }
59
60 private static bool CanNPCParty(NPC n)
61 {
62 if (!n.active || !n.townNPC || n.aiStyle == 0 || n.type == 37 || n.type == 453 || n.type == 441)
63 {
64 return false;
65 }
66 if (NPCID.Sets.IsTownPet[n.type])
67 {
68 return false;
69 }
70 return true;
71 }
72
73 private static void NaturalAttempt()
74 {
75 if (Main.netMode == 1 || !NPC.AnyNPCs(208))
76 {
77 return;
78 }
79 if (PartyDaysOnCooldown > 0)
80 {
82 return;
83 }
84 int maxValue = 10;
86 {
87 maxValue = 7;
88 }
89 if (Main.rand.Next(maxValue) != 0)
90 {
91 return;
92 }
93 List<NPC> list = new List<NPC>();
94 for (int j = 0; j < 200; j++)
95 {
96 NPC nPC = Main.npc[j];
97 if (CanNPCParty(nPC))
98 {
99 list.Add(nPC);
100 }
101 }
102 if (list.Count >= 5)
103 {
104 GenuineParty = true;
105 PartyDaysOnCooldown = Main.rand.Next(5, 11);
106 NPC.freeCake = true;
107 CelebratingNPCs.Clear();
108 List<int> list2 = new List<int>();
109 int num = 1;
110 if (Main.rand.Next(5) == 0 && list.Count > 12)
111 {
112 num = 3;
113 }
114 else if (Main.rand.Next(3) == 0)
115 {
116 num = 2;
117 }
118 list = list.OrderBy((NPC i) => Main.rand.Next()).ToList();
119 for (int k = 0; k < num; k++)
120 {
121 list2.Add(k);
122 }
123 for (int l = 0; l < list2.Count; l++)
124 {
125 CelebratingNPCs.Add(list[list2[l]].whoAmI);
126 }
127 Color color = new Color(255, 0, 160);
128 if (CelebratingNPCs.Count == 3)
129 {
130 WorldGen.BroadcastText(NetworkText.FromKey("Game.BirthdayParty_3", Main.npc[CelebratingNPCs[0]].GetGivenOrTypeNetName(), Main.npc[CelebratingNPCs[1]].GetGivenOrTypeNetName(), Main.npc[CelebratingNPCs[2]].GetGivenOrTypeNetName()), color);
131 }
132 else if (CelebratingNPCs.Count == 2)
133 {
134 WorldGen.BroadcastText(NetworkText.FromKey("Game.BirthdayParty_2", Main.npc[CelebratingNPCs[0]].GetGivenOrTypeNetName(), Main.npc[CelebratingNPCs[1]].GetGivenOrTypeNetName()), color);
135 }
136 else
137 {
138 WorldGen.BroadcastText(NetworkText.FromKey("Game.BirthdayParty_1", Main.npc[CelebratingNPCs[0]].GetGivenOrTypeNetName()), color);
139 }
142 }
143 }
144
145 public static void ToggleManualParty()
146 {
147 bool partyIsUp = PartyIsUp;
148 if (Main.netMode != 1)
149 {
151 }
152 else
153 {
154 NetMessage.SendData(111);
155 }
156 if (partyIsUp != PartyIsUp)
157 {
158 if (Main.netMode == 2)
159 {
161 }
163 }
164 }
165
166 private static void CheckForAchievement()
167 {
168 if (PartyIsUp)
169 {
171 }
172 }
173
174 public static void WorldClear()
175 {
176 ManualParty = false;
177 GenuineParty = false;
179 CelebratingNPCs.Clear();
180 _wasCelebrating = false;
181 }
182
183 public static void UpdateTime()
184 {
186 {
187 if (Main.netMode != 2)
188 {
189 if (PartyIsUp)
190 {
191 SkyManager.Instance.Activate("Party", default(Vector2));
192 }
193 else
194 {
195 SkyManager.Instance.Deactivate("Party");
196 }
197 }
198 if (Main.netMode != 1 && CelebratingNPCs.Count > 0)
199 {
200 for (int i = 0; i < CelebratingNPCs.Count; i++)
201 {
203 {
204 CelebratingNPCs.RemoveAt(i);
205 }
206 }
207 if (CelebratingNPCs.Count == 0)
208 {
209 GenuineParty = false;
210 if (!ManualParty)
211 {
212 WorldGen.BroadcastText(color: new Color(255, 0, 160), text: NetworkText.FromKey(Lang.misc[99].Key));
214 }
215 }
216 }
217 }
219 }
220}
void Add(TKey key, TValue value)
static bool[] IsTownPet
Definition NPCID.cs:4099
static LocalizedText[] misc
Definition Lang.cs:25
static NetworkText FromKey(string key, params object[] substitutions)
static int netMode
Definition Main.cs:2095
static UnifiedRandom rand
Definition Main.cs:1387
static NPC[] npc
Definition Main.cs:1685
static bool tenthAnniversaryWorld
Definition Main.cs:343
static bool AnyNPCs(int Type)
Definition NPC.cs:86689
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 void BroadcastText(NetworkText text, Vector4 color)