Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ShopHelper.cs
Go to the documentation of this file.
1using System;
5using Terraria.ID;
7
9
10public class ShopHelper
11{
12 public const float LowestPossiblePriceMultiplier = 0.75f;
13
14 public const float MaxHappinessAchievementPriceMultiplier = 0.82f;
15
16 public const float HighestPossiblePriceMultiplier = 1.5f;
17
18 private string _currentHappiness;
19
21
23
25
27
29 {
30 new CorruptionBiome(),
31 new CrimsonBiome(),
32 new DungeonBiome()
33 };
34
35 private const float likeValue = 0.94f;
36
37 private const float dislikeValue = 1.06f;
38
39 private const float loveValue = 0.88f;
40
41 private const float hateValue = 1.12f;
42
48
50 {
52 shoppingSettings.PriceAdjustment = 1.0;
53 shoppingSettings.HappinessReport = "";
56 _currentPlayerTalking = player;
57 ProcessMood(player, npc);
58 result.PriceAdjustment = _currentPriceAdjustment;
59 result.HappinessReport = _currentHappiness;
60 return result;
61 }
62
63 private float GetSkeletonMerchantPrices(NPC npc)
64 {
65 float num = 1f;
66 if (Main.moonPhase == 1 || Main.moonPhase == 7)
67 {
68 num = 1.1f;
69 }
70 if (Main.moonPhase == 2 || Main.moonPhase == 6)
71 {
72 num = 1.2f;
73 }
74 if (Main.moonPhase == 3 || Main.moonPhase == 5)
75 {
76 num = 1.3f;
77 }
78 if (Main.moonPhase == 4)
79 {
80 num = 1.4f;
81 }
82 if (Main.dayTime)
83 {
84 num += 0.1f;
85 }
86 return num;
87 }
88
90 {
91 Vector2 value = npc.Center / 16f;
93 float num = Vector2.Distance(value, value2) / (float)(Main.maxTilesX / 2);
94 num = 1.5f - num;
95 return (2f + num) / 3f;
96 }
97
98 private void ProcessMood(Player player, NPC npc)
99 {
102 if (Main.remixWorld)
103 {
104 return;
105 }
106 if (npc.type == 368)
107 {
109 }
110 else if (npc.type == 453)
111 {
113 }
114 else
115 {
116 if (NPCID.Sets.IsTownPet[npc.type])
117 {
118 return;
119 }
120 if (IsNotReallyTownNPC(npc))
121 {
123 return;
124 }
125 if (RuinMoodIfHomeless(npc))
126 {
128 }
129 else if (IsFarFromHome(npc))
130 {
132 }
133 if (IsPlayerInEvilBiomes(player))
134 {
136 }
137 int npcsWithinHouse;
140 bool flag = true;
141 float num = 1.05f;
142 if (npc.type == 663)
143 {
144 flag = false;
145 num = 1f;
146 if (npcsWithinHouse < 2 && npcsWithinVillage < 2)
147 {
148 AddHappinessReportText("HateLonely");
150 }
151 }
152 if (true && npcsWithinHouse > 3)
153 {
154 for (int i = 3; i < npcsWithinHouse; i++)
155 {
157 }
158 if (npcsWithinHouse > 6)
159 {
160 AddHappinessReportText("HateCrowded");
161 }
162 else
163 {
164 AddHappinessReportText("DislikeCrowded");
165 }
166 }
167 if (flag && npcsWithinHouse <= 2 && npcsWithinVillage < 4)
168 {
169 AddHappinessReportText("LoveSpace");
171 }
172 bool[] array = new bool[NPCID.Count];
173 foreach (NPC item in nearbyResidentNPCs)
174 {
175 array[item.type] = true;
176 }
178 helperInfo.player = player;
179 helperInfo.npc = npc;
180 helperInfo.NearbyNPCs = nearbyResidentNPCs;
181 helperInfo.nearbyNPCsByType = array;
184 {
185 shopModifier.ModifyShopPrice(info, this);
186 }
188 if (_currentHappiness == "")
189 {
190 AddHappinessReportText("Content");
191 }
193 }
194 }
195
197 {
199 priceAdjustment = (float)Math.Round(priceAdjustment * 100f) / 100f;
200 return priceAdjustment;
201 }
202
203 private static string BiomeNameByKey(string biomeNameKey)
204 {
205 return Language.GetTextValue("TownNPCMoodBiomes." + biomeNameKey);
206 }
207
208 private void AddHappinessReportText(string textKeyInCategory, object substitutes = null)
209 {
210 string text = "TownNPCMood_" + NPCID.Search.GetName(_currentNPCBeingTalkedTo.netID);
212 {
213 text += "Transformed";
214 }
217 }
218
219 public void LikeBiome(string nameKey)
220 {
221 AddHappinessReportText("LikeBiome", new
222 {
224 });
226 }
227
228 public void LoveBiome(string nameKey)
229 {
230 AddHappinessReportText("LoveBiome", new
231 {
233 });
235 }
236
237 public void DislikeBiome(string nameKey)
238 {
239 AddHappinessReportText("DislikeBiome", new
240 {
242 });
244 }
245
246 public void HateBiome(string nameKey)
247 {
248 AddHappinessReportText("HateBiome", new
249 {
251 });
253 }
254
255 public void LikeNPC(int npcType)
256 {
257 AddHappinessReportText("LikeNPC", new
258 {
260 });
262 }
263
264 public void LoveNPCByTypeName(int npcType)
265 {
266 AddHappinessReportText("LoveNPC_" + NPCID.Search.GetName(npcType), new
267 {
268 NPCName = NPC.GetFullnameByID(npcType)
269 });
271 }
272
273 public void LikePrincess()
274 {
275 AddHappinessReportText("LikeNPC_Princess", new
276 {
278 });
280 }
281
282 public void LoveNPC(int npcType)
283 {
284 AddHappinessReportText("LoveNPC", new
285 {
287 });
289 }
290
291 public void DislikeNPC(int npcType)
292 {
293 AddHappinessReportText("DislikeNPC", new
294 {
296 });
298 }
299
300 public void HateNPC(int npcType)
301 {
302 AddHappinessReportText("HateNPC", new
303 {
305 });
307 }
308
310 {
311 List<NPC> list = new List<NPC>();
312 npcsWithinHouse = 0;
314 Vector2 value = new Vector2(npc.homeTileX, npc.homeTileY);
315 if (npc.homeless)
316 {
317 value = new Vector2(npc.Center.X / 16f, npc.Center.Y / 16f);
318 }
319 for (int i = 0; i < 200; i++)
320 {
321 if (i == npc.whoAmI)
322 {
323 continue;
324 }
325 NPC nPC = Main.npc[i];
326 if (nPC.active && nPC.townNPC && !IsNotReallyTownNPC(nPC) && !WorldGen.TownManager.CanNPCsLiveWithEachOther_ShopHelper(npc, nPC))
327 {
328 Vector2 value2 = new Vector2(nPC.homeTileX, nPC.homeTileY);
329 if (nPC.homeless)
330 {
331 value2 = nPC.Center / 16f;
332 }
333 float num = Vector2.Distance(value, value2);
334 if (num < 25f)
335 {
336 list.Add(nPC);
338 }
339 else if (num < 120f)
340 {
342 }
343 }
344 }
345 return list;
346 }
347
348 private bool RuinMoodIfHomeless(NPC npc)
349 {
350 if (npc.homeless)
351 {
352 AddHappinessReportText("NoHome");
353 }
354 return npc.homeless;
355 }
356
357 private bool IsFarFromHome(NPC npc)
358 {
359 Vector2 value = new Vector2(npc.homeTileX, npc.homeTileY);
360 Vector2 value2 = new Vector2(npc.Center.X / 16f, npc.Center.Y / 16f);
361 if (Vector2.Distance(value, value2) > 120f)
362 {
363 AddHappinessReportText("FarFromHome");
364 return true;
365 }
366 return false;
367 }
368
369 private bool IsPlayerInEvilBiomes(Player player)
370 {
371 for (int i = 0; i < _dangerousBiomes.Length; i++)
372 {
374 if (aShoppingBiome.IsInBiome(player))
375 {
376 AddHappinessReportText("HateBiome", new
377 {
379 });
380 return true;
381 }
382 }
383 return false;
384 }
385
386 private bool IsNotReallyTownNPC(NPC npc)
387 {
388 int type = npc.type;
389 if (type == 37 || type == 368 || type == 453)
390 {
391 return true;
392 }
393 return false;
394 }
395}
static float Clamp(float value, float min, float max)
Definition MathHelper.cs:46
static decimal Round(decimal d)
Definition Math.cs:1096
Vector2 Center
Definition Entity.cs:43
void ModifyShopPrice(HelperInfo info, ShopHelper shopHelperInstance)
bool IsPlayerInEvilBiomes(Player player)
PersonalityDatabase _database
Definition ShopHelper.cs:26
ShoppingSettings GetShoppingSettings(Player player, NPC npc)
Definition ShopHelper.cs:49
static string BiomeNameByKey(string biomeNameKey)
void HateBiome(string nameKey)
const float HighestPossiblePriceMultiplier
Definition ShopHelper.cs:16
void LoveNPCByTypeName(int npcType)
void LoveBiome(string nameKey)
void ProcessMood(Player player, NPC npc)
Definition ShopHelper.cs:98
void AddHappinessReportText(string textKeyInCategory, object substitutes=null)
void DislikeBiome(string nameKey)
float LimitAndRoundMultiplier(float priceAdjustment)
float GetTravelingMerchantPrices(NPC npc)
Definition ShopHelper.cs:89
List< NPC > GetNearbyResidentNPCs(NPC npc, out int npcsWithinHouse, out int npcsWithinVillage)
AShoppingBiome[] _dangerousBiomes
Definition ShopHelper.cs:28
float GetSkeletonMerchantPrices(NPC npc)
Definition ShopHelper.cs:63
const float MaxHappinessAchievementPriceMultiplier
Definition ShopHelper.cs:14
void LikeBiome(string nameKey)
const float LowestPossiblePriceMultiplier
Definition ShopHelper.cs:12
static bool[] IsTownPet
Definition NPCID.cs:4099
static readonly short Count
Definition NPCID.cs:11744
static readonly IdDictionary Search
Definition NPCID.cs:11746
static string GetTextValue(string key)
Definition Language.cs:15
static string GetTextValueWith(string key, object obj)
Definition Language.cs:40
static int spawnTileY
Definition Main.cs:1811
static bool dayTime
Definition Main.cs:1282
static int moonPhase
Definition Main.cs:1288
static int maxTilesX
Definition Main.cs:1114
static int spawnTileX
Definition Main.cs:1809
static NPC[] npc
Definition Main.cs:1685
static bool remixWorld
Definition Main.cs:349
static string GetFullnameByID(int npcID)
Definition NPC.cs:1036
int homeTileX
Definition NPC.cs:543
int type
Definition NPC.cs:445
int altTexture
Definition NPC.cs:99
int netID
Definition NPC.cs:531
bool homeless
Definition NPC.cs:541
int homeTileY
Definition NPC.cs:545
static TownRoomManager TownManager
Definition WorldGen.cs:892
static float Distance(Vector2 value1, Vector2 value2)
Definition Vector2.cs:91