TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches

◆ Prefix()

bool Terraria.Item.Prefix ( int prefixWeWant)
inline

Attempts to apply a prefix to this T:Terraria.Item.

Parameters
prefixWeWant
If prefixWeWant == 0, do nothing.
If prefixWeWant == -1, then a random prefix is rolled, with a 25% chance to not roll a prefix and an additional 66% chance to void any prefixes in the F:Terraria.ID.PrefixID.Sets.ReducedNaturalChance set. This is used for chest loot, starting equipment, etc.
If prefixWeWant == -2, then a random prefix is rolled, with no chance to not roll a prefix. This is used for the Goblin Tinkerer.
If prefixWeWant == -3, then this method simple checks if this item can receive prefixes.
Otherwise, attempt to apply the given T:Terraria.ID.PrefixID to this item.
Returns
false if:
  • prefixWeWant is 0
  • M:Terraria.Item.CanHavePrefixes returns false
  • M:Terraria.Item.CanApplyPrefix(System.Int32) returns false
  • prefixWeWant == -1 and F:Terraria.Item.maxStack > 1
  • M:Terraria.ModLoader.ItemLoader.PrefixChance(Terraria.Item,System.Int32,Terraria.Utilities.UnifiedRandom) returns false
  • prefixWeWant == -1 or -2 or -3 and M:Terraria.ModLoader.PrefixLoader.Roll(Terraria.Item,Terraria.Utilities.UnifiedRandom,System.Int32@,System.Boolean) returns false.
Otherwise, return true.

Definition at line 1279 of file Item.cs.

1280 {
1281 if (!WorldGen.gen && Main.rand == null)
1282 {
1283 Main.rand = new UnifiedRandom();
1284 }
1285 if (prefixWeWant == 0)
1286 {
1287 return false;
1288 }
1289 if (!CanHavePrefixes())
1290 {
1291 return false;
1292 }
1294 {
1295 return false;
1296 }
1297 if (prefixWeWant == -1 && maxStack > 1)
1298 {
1299 return false;
1300 }
1301 UnifiedRandom unifiedRandom = (WorldGen.gen ? WorldGen.genRand : Main.rand);
1303 if ((!applyPrefixOverride) ?? false)
1304 {
1305 return false;
1306 }
1308 float dmg = 1f;
1309 float kb = 1f;
1310 float spd = 1f;
1311 float size = 1f;
1312 float shtspd = 1f;
1313 float mcst = 1f;
1314 int crt = 0;
1315 bool flag = true;
1316 while (flag)
1317 {
1318 flag = false;
1319 if (((!applyPrefixOverride) ?? true) && rolledPrefix == -1 && unifiedRandom.Next(4) == 0)
1320 {
1321 return true;
1322 }
1323 if (prefixWeWant < -1)
1324 {
1325 rolledPrefix = -1;
1326 }
1327 int num2;
1328 if (prefixWeWant == -3)
1329 {
1331 }
1333 {
1334 return false;
1335 }
1336 switch (prefixWeWant)
1337 {
1338 case -3:
1339 return true;
1340 case -1:
1342 {
1343 return true;
1344 }
1345 break;
1346 }
1348 {
1349 flag = true;
1350 rolledPrefix = -1;
1351 }
1352 if (prefixWeWant == -2 && rolledPrefix == 0)
1353 {
1354 rolledPrefix = -1;
1355 flag = true;
1356 }
1357 }
1359 damage = (int)Math.Round((float)damage * dmg);
1360 useAnimation = (int)Math.Round((float)useAnimation * spd);
1361 useTime = (int)Math.Round((float)useTime * spd);
1362 reuseDelay = (int)Math.Round((float)reuseDelay * spd);
1363 mana = (int)Math.Round((float)mana * mcst);
1364 knockBack *= kb;
1365 scale *= size;
1366 shootSpeed *= shtspd;
1367 crit += crt;
1369 {
1370 PrefixLoader.GetPrefix(rolledPrefix)?.Apply(this);
1371 }
1373 float num = 1f * dmg * (2f - spd) * (2f - mcst) * size * kb * shtspd * (1f + (float)crt * 0.02f);
1374 if (rolledPrefix == 62 || rolledPrefix == 69 || rolledPrefix == 73 || rolledPrefix == 77)
1375 {
1376 num *= 1.05f;
1377 }
1378 if (rolledPrefix == 63 || rolledPrefix == 70 || rolledPrefix == 74 || rolledPrefix == 78 || rolledPrefix == 67)
1379 {
1380 num *= 1.1f;
1381 }
1382 if (rolledPrefix == 64 || rolledPrefix == 71 || rolledPrefix == 75 || rolledPrefix == 79 || rolledPrefix == 66)
1383 {
1384 num *= 1.15f;
1385 }
1386 if (rolledPrefix == 65 || rolledPrefix == 72 || rolledPrefix == 76 || rolledPrefix == 80 || rolledPrefix == 68)
1387 {
1388 num *= 1.2f;
1389 }
1391 {
1392 PrefixLoader.GetPrefix(rolledPrefix)?.ModifyValue(ref num);
1393 }
1394 int baseRarity = rare;
1395 if ((double)num >= 1.2)
1396 {
1397 rare += 2;
1398 }
1399 else if ((double)num >= 1.05)
1400 {
1401 rare++;
1402 }
1403 else if ((double)num <= 0.8)
1404 {
1405 rare -= 2;
1406 }
1407 else if ((double)num <= 0.95)
1408 {
1409 rare--;
1410 }
1411 if (baseRarity >= 12)
1412 {
1413 rare = RarityLoader.GetRarity(baseRarity).GetPrefixedRarity(rare - baseRarity, num);
1414 }
1415 else if (rare > 11)
1416 {
1417 rare = 11;
1418 }
1419 if (rare > -11)
1420 {
1421 if (rare < -1)
1422 {
1423 rare = -1;
1424 }
1425 if (rare > RarityLoader.RarityCount - 1)
1426 {
1427 rare = RarityLoader.RarityCount - 1;
1428 }
1429 }
1430 num *= num;
1431 value = (int)((float)value * num);
1433 return true;
1434 }
static bool[] ReducedNaturalChance
If true for a given prefix type (F:Terraria.Item.prefix), then that prefix has a 66% to not be applie...
Definition PrefixID.cs:16
static readonly int Count
Definition PrefixID.cs:187
float knockBack
The force of the knock back. Max value is 20. The Knockback wiki pagehas info on existing values....
Definition Item.cs:462
int useAnimation
The time span of the using animation for the item in ticks. This is independent of the time it takes ...
Definition Item.cs:384
int crit
The base critical chance for this item. Remember that the player has a base crit chance of 4....
Definition Item.cs:746
int value
The number of copper coins this item is worth (aka, cost to buy from a merchant). Setting it to 10462...
Definition Item.cs:655
bool TryGetPrefixStatMultipliersForItem(int rolledPrefix, out float dmg, out float kb, out float spd, out float size, out float shtspd, out float mcst, out int crt)
Definition Item.cs:1472
int reuseDelay
A delay in frames added at the end of the using animation for the item, during which the player wont ...
Definition Item.cs:760
int rare
Indicates the rarity of an item. Assign to a T:Terraria.ID.ItemRarityID value. Vanilla values range f...
Definition Item.cs:587
int maxStack
The maximum number of items that can be contained within a single stack. F:Terraria....
Definition Item.cs:402
float scale
The size multiplier of the item's sprite while the item is being used. Also increases range for melee...
Definition Item.cs:526
int damage
The base damage inflicted by this item. The List of weapons wiki pagecan be a useful guide for decidi...
Definition Item.cs:455
void UndoItemAnimationCompensations()
Definition Item.cs:52077
float shootSpeed
The velocity in pixels the projectile fired by this item will have. Actual velocity depends on the pr...
Definition Item.cs:600
int mana
The amount of mana this item consumes on use. Use M:Terraria.ModLoader.ModItem.ModifyManaCost(Terra...
Definition Item.cs:635
bool CanHavePrefixes()
Determines if this T:Terraria.Item can receive prefixes.
Definition Item.cs:1245
int useTime
The time span of using the item in ticks. This is independent of the time it takes for the item anima...
Definition Item.cs:391
void ApplyItemAnimationCompensationsToVanillaItems()
Definition Item.cs:52063
int prefix
The current prefix applied to this item. Either a T:Terraria.ID.PrefixID entry or M:Terraria....
Definition Item.cs:752
bool RollAPrefix(UnifiedRandom random, ref int rolledPrefix)
Definition Item.cs:1869
bool CanApplyPrefix(int prefix)
Determines if this T:Terraria.Item can receive the given prefix.
Definition Item.cs:1456
static ? bool PrefixChance(Item item, int pre, UnifiedRandom rand)
Allows for blocking, forcing and altering chance of prefix rolling. False (block) takes precedence ov...
This serves as the central class from which item-related functions are carried out....
Definition ItemLoader.cs:26
static ModPrefix GetPrefix(int type)
Returns the ModPrefix associated with specified type If not a ModPrefix, returns null.
static bool Roll(Item item, UnifiedRandom unifiedRandom, out int prefix, bool justCheck)
static ModRarity GetRarity(int type)

References Terraria.Item.ApplyItemAnimationCompensationsToVanillaItems(), Terraria.Item.CanApplyPrefix(), Terraria.Item.CanHavePrefixes(), Terraria.ID.PrefixID.Count, Terraria.Item.crit, Terraria.Item.damage, Terraria.WorldGen.gen, Terraria.ModLoader.PrefixLoader.GetPrefix(), Terraria.ModLoader.RarityLoader.GetRarity(), Terraria.Item.knockBack, Terraria.Item.mana, Terraria.Item.maxStack, Terraria.Item.prefix, Terraria.ModLoader.ItemLoader.PrefixChance(), Terraria.Main.rand, Terraria.Item.rare, Terraria.ModLoader.RarityLoader.RarityCount, Terraria.ID.PrefixID.Sets.ReducedNaturalChance, Terraria.Item.reuseDelay, Terraria.ModLoader.PrefixLoader.Roll(), Terraria.Item.RollAPrefix(), Terraria.Item.scale, Terraria.Item.shootSpeed, Terraria.Item.TryGetPrefixStatMultipliersForItem(), Terraria.Item.UndoItemAnimationCompensations(), Terraria.Item.useAnimation, Terraria.Item.useTime, and Terraria.Item.value.

Referenced by Terraria.Item.Item(), Terraria.WorldGen.AddBuriedChest(), Terraria.Item.DeserializeFrom(), Terraria.GameContent.Drawing.TileDrawing.DrawSpecialTilesLegacy(), Terraria.Player.DropItems_GetDefaults(), Terraria.ModLoader.TileLoader.GetItemDrops(), Terraria.WorldGen.KillTile(), Terraria.ModLoader.IO.ItemIO.Load(), Terraria.IO.WorldFile.LoadChests(), Terraria.Item.NewItem_Inner(), Terraria.UI.ItemSlot.OverrideHover(), Terraria.GameContent.UI.Chat.ItemTagHandler.Parse(), Terraria.WorldGen.PrefixItemFromOptions(), Terraria.GameContent.Tile_Entities.TEDisplayDoll.ReadExtraData(), Terraria.GameContent.Tile_Entities.TEFoodPlatter.ReadExtraData(), Terraria.GameContent.Tile_Entities.TEHatRack.ReadExtraData(), Terraria.GameContent.Tile_Entities.TEItemFrame.ReadExtraData(), Terraria.GameContent.Tile_Entities.TEWeaponsRack.ReadExtraData(), Terraria.GameContent.Tile_Entities.TEDisplayDoll.ReadItem(), Terraria.GameContent.Tile_Entities.TEHatRack.ReadItem(), and Terraria.ModLoader.IO.ItemIO.Receive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: