Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UnlockableNPCEntryIcon.cs
Go to the documentation of this file.
4using Terraria.ID;
6
8
10{
11 private int _npcNetId;
12
13 private NPC _npcCache;
14
15 private bool _firstUpdateDone;
16
18
20
21 private string _overrideNameKey;
22
23 public UnlockableNPCEntryIcon(int npcNetId, float ai0 = 0f, float ai1 = 0f, float ai2 = 0f, float ai3 = 0f, string overrideNameKey = null)
24 {
25 _npcNetId = npcNetId;
26 _npcCache = new NPC();
27 _npcCache.IsABestiaryIconDummy = true;
29 _firstUpdateDone = false;
30 _npcCache.ai[0] = ai0;
31 _npcCache.ai[1] = ai1;
32 _npcCache.ai[2] = ai2;
33 _npcCache.ai[3] = ai3;
34 _customTexture = null;
35 _overrideNameKey = overrideNameKey;
36 }
37
39 {
40 return new UnlockableNPCEntryIcon(_npcNetId, 0f, 0f, 0f, 0f, _overrideNameKey);
41 }
42
43 public void Update(BestiaryUICollectionInfo providedInfo, Rectangle hitbox, EntryIconDrawSettings settings)
44 {
45 Vector2 positionOffsetCache = default(Vector2);
46 int? num = null;
47 int? num2 = null;
48 int? num3 = null;
49 bool wet = false;
50 float num4 = 0f;
51 Asset<Texture2D> val = null;
52 if (NPCID.Sets.NPCBestiaryDrawOffset.TryGetValue(_npcNetId, out var value))
53 {
54 _npcCache.rotation = value.Rotation;
55 _npcCache.scale = value.Scale;
56 if (value.PortraitScale.HasValue && settings.IsPortrait)
57 {
58 _npcCache.scale = value.PortraitScale.Value;
59 }
60 positionOffsetCache = value.Position;
61 num = value.Frame;
62 num2 = value.Direction;
63 num3 = value.SpriteDirection;
64 num4 = value.Velocity;
65 wet = value.IsWet;
66 if (value.PortraitPositionXOverride.HasValue && settings.IsPortrait)
67 {
68 positionOffsetCache.X = value.PortraitPositionXOverride.Value;
69 }
70 if (value.PortraitPositionYOverride.HasValue && settings.IsPortrait)
71 {
72 positionOffsetCache.Y = value.PortraitPositionYOverride.Value;
73 }
74 if (value.CustomTexturePath != null)
75 {
76 val = Main.Assets.Request<Texture2D>(value.CustomTexturePath, (AssetRequestMode)1);
77 }
78 if (val != null && val.IsLoaded)
79 {
80 _customTexture = val;
81 }
82 }
83 _positionOffsetCache = positionOffsetCache;
84 UpdatePosition(settings);
86 {
87 for (int i = 0; i < _npcCache.oldPos.Length; i++)
88 {
90 }
91 }
92 _npcCache.direction = (_npcCache.spriteDirection = (num2.HasValue ? num2.Value : (-1)));
93 if (num3.HasValue)
94 {
95 _npcCache.spriteDirection = num3.Value;
96 }
97 _npcCache.wet = wet;
100 if (!num.HasValue && (settings.IsPortrait || settings.IsHovered))
101 {
102 _npcCache.velocity.X = (float)_npcCache.direction * num4;
104 }
105 else if (num.HasValue)
106 {
108 _npcCache.frame.Y = _npcCache.frame.Height * num.Value;
109 }
110 }
111
113 {
115 {
116 _npcCache.Center = settings.iconbox.Center.ToVector2() + _positionOffsetCache;
117 }
118 else
119 {
120 _npcCache.Bottom = settings.iconbox.TopLeft() + settings.iconbox.Size() * new Vector2(0.5f, 1f) + new Vector2(0f, -8f) + _positionOffsetCache;
121 }
122 _npcCache.position = _npcCache.position.Floor();
123 }
124
126 {
127 if (NPCID.Sets.SpecialSpawningRules.TryGetValue(_npcNetId, out var value) && value == 0)
128 {
129 Point point = (_npcCache.position - _npcCache.rotation.ToRotationVector2() * -1600f).ToTileCoordinates();
130 _npcCache.ai[0] = point.X;
131 _npcCache.ai[1] = point.Y;
132 }
133 switch (_npcNetId)
134 {
135 case 244:
137 break;
138 case 356:
139 _npcCache.ai[2] = 1f;
140 break;
141 case 330:
142 case 372:
143 case 586:
144 case 587:
145 case 619:
146 case 620:
147 _npcCache.alpha = 0;
148 break;
149 case 299:
150 case 538:
151 case 539:
152 case 639:
153 case 640:
154 case 641:
155 case 642:
156 case 643:
157 case 644:
158 case 645:
159 if (settings.IsPortrait && _npcCache.frame.Y == 0)
160 {
161 _npcCache.frame.Y = _npcCache.frame.Height;
162 }
163 break;
164 case 636:
165 _npcCache.Opacity = 1f;
166 if ((_npcCache.localAI[0] += 1f) >= 44f)
167 {
168 _npcCache.localAI[0] = 0f;
169 }
170 break;
171 case 656:
172 _npcCache.townNpcVariationIndex = 1;
173 break;
174 case 670:
175 _npcCache.townNpcVariationIndex = 0;
176 break;
177 }
178 }
179
180 private void SimulateFirstHover(float velocity)
181 {
182 if (!_firstUpdateDone)
183 {
184 _firstUpdateDone = true;
186 _npcCache.velocity.X = (float)_npcCache.direction * velocity;
187 for (int i = 0; i < 1; i++)
188 {
190 }
191 }
192 }
193
194 public void Draw(BestiaryUICollectionInfo providedInfo, SpriteBatch spriteBatch, EntryIconDrawSettings settings)
195 {
196 UpdatePosition(settings);
197 if (_customTexture != null)
198 {
199 spriteBatch.Draw(_customTexture.Value, _npcCache.Center, null, Color.White, 0f, _customTexture.Size() / 2f, _npcCache.scale, SpriteEffects.None, 0f);
200 return;
201 }
202 if (_npcCache.townNPC && TownNPCProfiles.Instance.GetProfile(_npcCache.type, out var profile))
203 {
204 TextureAssets.Npc[_npcCache.type] = profile.GetTextureNPCShouldUse(_npcCache);
205 }
206 Main.instance.DrawNPCDirect(spriteBatch, _npcCache, _npcCache.behindTiles, Vector2.Zero);
207 }
208
209 public string GetHoverText(BestiaryUICollectionInfo providedInfo)
210 {
211 string result = Lang.GetNPCNameValue(_npcCache.netID);
212 if (!string.IsNullOrWhiteSpace(_overrideNameKey))
213 {
215 }
216 if (GetUnlockState(providedInfo))
217 {
218 return result;
219 }
220 return "???";
221 }
222
223 public bool GetUnlockState(BestiaryUICollectionInfo providedInfo)
224 {
225 return providedInfo.UnlockState > BestiaryEntryUnlockState.NotKnownAtAll_0;
226 }
227}
void Draw(Texture2D texture, Vector2 position, Color color)
Vector2 Center
Definition Entity.cs:43
Vector2 position
Definition Entity.cs:14
string GetHoverText(BestiaryUICollectionInfo providedInfo)
void AdjustSpecialSpawnRulesForVisuals(EntryIconDrawSettings settings)
void Draw(BestiaryUICollectionInfo providedInfo, SpriteBatch spriteBatch, EntryIconDrawSettings settings)
void Update(BestiaryUICollectionInfo providedInfo, Rectangle hitbox, EntryIconDrawSettings settings)
UnlockableNPCEntryIcon(int npcNetId, float ai0=0f, float ai1=0f, float ai2=0f, float ai3=0f, string overrideNameKey=null)
bool GetUnlockState(BestiaryUICollectionInfo providedInfo)
static Asset< Texture2D >[] Npc
static Dictionary< int, NPCBestiaryDrawModifiers > NPCBestiaryDrawOffset
Definition NPCID.cs:106
static Dictionary< int, int > SpecialSpawningRules
Definition NPCID.cs:96
static int[] TrailingMode
Definition NPCID.cs:4162
static string GetNPCNameValue(int netID)
Definition Lang.cs:143
static string GetTextValue(string key)
Definition Language.cs:15
static Main instance
Definition Main.cs:283
static IAssetRepository Assets
Definition Main.cs:209
void SetDefaults(int Type, NPCSpawnParams spawnparams=default(NPCSpawnParams))
Definition NPC.cs:2523
void FindFrame()
Definition NPC.cs:59052
float[] localAI
Definition NPC.cs:449
void AI_001_SetRainbowSlimeColor()
Definition NPC.cs:54011
bool noGravity
Definition NPC.cs:503
float[] ai
Definition NPC.cs:447
void SetFrameSize()
Definition NPC.cs:59042
float scale
Definition NPC.cs:493
int type
Definition NPC.cs:445
float rotation
Definition NPC.cs:501
bool behindTiles
Definition NPC.cs:519
int netID
Definition NPC.cs:531
Rectangle frame
Definition NPC.cs:485
Vector2[] oldPos
Definition NPC.cs:155
bool townNPC
Definition NPC.cs:537