tModLoader  0.12 Alpha
A mod to make and play Terraria mods
Terraria.NPC Class Reference

Inherits Terraria.Entity, and Terraria.ModLoader.IEntityWithGlobals< GlobalNPC >.

Public Member Functions

void AddBuff (int type, int time, bool quiet=false)
 
void AI ()
 
void AI_000_TransformBoundNPC (int playerID, int npcType)
 
void AI_001_SetRainbowSlimeColor ()
 
NPC AI_113_WindyBalloon_GetSlaveNPC ()
 
bool AI_120_HallowBoss_IsGenuinelyEnraged ()
 
bool AI_120_HallowBoss_IsInPhase2 ()
 
void AI_122_PirateGhost ()
 
bool AnyInteractions ()
 
void ApplyInteraction (int player)
 
int BannerID ()
 
void BigMimicSpawnSmoke ()
 
void BloodNautilus_GetMouthPositionAndRotation (out Vector2 mouthPosition, out Vector2 mouthDirection)
 
bool CanBeChasedBy (object attacker=null, bool ignoreDontTakeDamage=false)
 
bool CanReflectProjectile (Projectile proj)
 
void CheckActive ()
 
int checkArmorPenetration (int armorPenetration)
 
void checkDead ()
 
void CheckDrowning ()
 
object Clone ()
 
void CloneDefaults (int Type)
 
void CopyInteractions (NPC npc)
 
void DelBuff (int buffIndex)
 
void DiscourageDespawn (int despawnTime)
 
bool DoesntDespawnToInactivity ()
 
void DropBossBags ()
 
void DropItemInstanced (Vector2 Position, Vector2 HitboxSize, int itemType, int itemStack=1, bool interactionRequired=true)
 
void DropTombstoneTownNPC (NetworkText deathText)
 
void EncourageDespawn (int despawnTime)
 
bool ExcludedFromDeathTally ()
 
void FaceTarget ()
 
int FindBuffIndex (int type)
 
int FindClosestPlayer ()
 
int FindClosestPlayer (out float distanceToPlayer)
 
void FindFrame ()
 
Color GetAlpha (Color newColor)
 
int GetAttackDamage_ForProjectiles (float normalDamage, float expertDamage)
 
int GetAttackDamage_ForProjectiles_MultiLerp (float normalDamage, float expertDamage, float masterDamage)
 
int GetAttackDamage_LerpBetweenFinalValues (float normalDamage, float expertDamage)
 
float GetAttackDamage_LerpBetweenFinalValuesFloat (float normalDamage, float expertDamage)
 
int GetAttackDamage_ScaledByStrength (float normalDamage)
 
string GetBestiaryCreditId ()
 
Color GetBestiaryEntryColor ()
 
float GetBossHeadRotation ()
 
SpriteEffects GetBossHeadSpriteEffects ()
 
int GetBossHeadTextureIndex ()
 
string GetChat ()
 
Color GetColor (Color newColor)
 
NetworkText GetFullNetName ()
 
NetworkText GetGivenNetName ()
 
NetworkText GetGivenOrTypeNetName ()
 
GetGlobalNPC< T > (bool exactType=true)
 Gets the instance of the specified GlobalNPC type. This will throw exceptions on failure. More...
 
GetGlobalNPC< T > (T baseInstance)
 Gets the local instance of the type of the specified GlobalNPC instance. This will throw exceptions on failure. More...
 
void GetImmuneTime (int fromWho, int time)
 
float GetLifePercent ()
 
void GetLifeStats (out int statLife, out int statLifeMax)
 
NPCSpawnParams GetMatchingSpawnParams ()
 
float GetMyBalance ()
 
Color GetNPCColorTintedByBuffs (Color npcColor)
 
PartyHatColor GetPartyHatColor ()
 
IProjectileSource GetProjectileSpawnSource ()
 
Rectangle getRect ()
 
int GetShootingFrame (float circleY)
 
bool GetSpecialEventTextIfNotEmpty (string specialTextKey, object substitutes, ref string specialEventText)
 
Tuple< Vector2, float > GetSwingStats (int swingMax, int swingCurrent, int aimDir, int itemWidth, int itemHeight)
 
NPCAimedTarget GetTargetData (bool ignorePlayerTankPets=true)
 
void GetTileCollisionParameters (out Vector2 cPosition, out int cWidth, out int cHeight)
 
NetworkText GetTypeNetName ()
 
bool GetWereThereAnyInteractions ()
 
bool HasBuff (int type)
 Returns whether or not this NPC currently has a (de)buff of the provided type. More...
 
bool HasBuff< T > ()
 
bool HasLuckTextForWizard (out string specialEventText)
 
bool HasSpecialEventText (string specialTextCategoryKey, out string specialEventText)
 
void HealEffect (int healAmount, bool broadcast=true)
 
void HitEffect (int hitDirection=0, double dmg=10.0)
 
void IdleSounds ()
 
void moneyPing (Vector2 pos)
 
bool NPCCanStickToWalls ()
 
void NPCLoot ()
 
void NPCLootOld ()
 
void PlayerInteraction (int player)
 
void PopAllAttachedProjectilesAndTakeDamageForThem ()
 
void ReflectProjectile (Projectile proj)
 
void ReflectProjectiles (Rectangle myRect)
 
void RequestBuffRemoval (int buffTypeToRemove)
 
void ScaleStats (int? activePlayersCount, GameModeData gameModeData, float? strengthOverride)
 
void ScaleStats_Old (int? activePlayersCount, GameModeData gameModeData)
 
void ScaleStats_UseStrengthMultiplier (float strength)
 
void SetDefaults (int Type, NPCSpawnParams spawnparams=default(NPCSpawnParams))
 
void SetDefaults_ForNetId (int Type, float scaleOverride)
 
void SetDefaults_ForNetId (int Type, NPCSpawnParams spawnparams, float scaleOverride)
 
void SetDefaultsKeepPlayerInteraction (int Type)
 
void SetFrameSize ()
 
bool ShouldBestiaryGirlBeLycantrope ()
 
bool ShouldFaceTarget (ref NPCUtils.TargetSearchResults searchResults, NPCUtils.TargetType? overrideTargetType=null)
 
void SimpleFlyMovement (Vector2 desiredVelocity, float moveSpeed)
 
void SpawnWithHigherTime (int timeMult)
 
double StrikeNPC (int Damage, float knockBack, int hitDirection, bool crit=false, bool noEffect=false, bool fromNet=false)
 
double StrikeNPCNoInteraction (int Damage, float knockBack, int hitDirection, bool crit=false, bool noEffect=false, bool fromNet=false)
 
void TargetClosest (bool faceTarget=true)
 
void TargetClosest_WOF (bool faceTarget=true)
 
void TargetClosestUpgraded (bool faceTarget=true, Vector2? checkPosition=null)
 
void Teleport (Vector2 newPos, int Style=0, int extraInfo=0)
 
override string ToString ()
 
void Transform (int newType)
 
void TransformVisuals (int oldType, int newType)
 
bool TryGetGlobalNPC< T > (out T result, bool exactType=true)
 Gets the instance of the specified GlobalNPC type. More...
 
bool TryGetGlobalNPC< T > (T baseInstance, out T result)
 Safely attempts to get the local instance of the type of the specified GlobalNPC instance. More...
 
void TryPortalJumping ()
 
void TweakSwingStats (int swingMax, int swingCurrent, int aimDir, ref Rectangle itemRectangle)
 
void UpdateAltTexture ()
 
void UpdateNPC (int i)
 
void UpdateNPC_BuffSetFlags (bool lowerBuffTime=true)
 
bool UsesPartyHat ()
 
void VanillaAI ()
 
void VanillaFindFrame (int num)
 
void VanillaHitEffect (int hitDirection=0, double dmg=10.0)
 
- Public Member Functions inherited from Terraria.Entity
float AngleFrom (Vector2 Source)
 
float AngleTo (Vector2 Destination)
 
Vector2 DirectionFrom (Vector2 Source)
 
Vector2 DirectionTo (Vector2 Destination)
 
float Distance (Vector2 Other)
 
float DistanceSQ (Vector2 Other)
 
bool WithinRange (Vector2 Target, float MaxRange)
 

Static Public Member Functions

static Color AI_121_QueenSlime_GetDustColor ()
 
static bool AnyDanger (bool quickBossNPCCheck=false, bool ignorePillars=false)
 
static bool AnyHelpfulFairies ()
 
static bool AnyNPCs (int Type)
 
static bool AnyoneNearCultists ()
 
static bool BigMimicSummonCheck (int x, int y)
 
static Color buffColor (Color newColor, float R, float G, float B, float A)
 
static bool BusyWithAnyInvasionOfSorts ()
 
static bool CanReleaseNPCs (int who)
 
static void CatchNPC (int i, int who=-1)
 
static void ClearFoundActiveNPCs ()
 
static void ClearFoundNPCTypesForBestiary ()
 
static int CountNPCS (int Type)
 
static int DefaultHeadIndexToType (int headIndex)
 
static bool DespawnEncouragement_AIStyle2_FloatingEye_IsDiscouraged (int npcID, Vector2 npcPosition, int target=255)
 
static bool DespawnEncouragement_AIStyle3_Fighters_CanBeBusyWithAction (int npcID)
 
static bool DespawnEncouragement_AIStyle3_Fighters_NotDiscouraged (int npcID, Vector2 position, NPC npcInstance)
 
static void FairyEffects (Vector2 Position, int type)
 
static bool FindCattailTop (int landX, int landY, out int cattailX, out int cattailY)
 
static int FindFirstNPC (int Type)
 
static bool FindTreeBranch (int landX, int landY, out int treeBranchX, out int treeBranchY)
 
static string firstNPCName (int npcType)
 
static int GetActivePlayerCount ()
 
static int GetAvailableAmountOfNPCsToSpawnFromTraps (int amountWeWant)
 
static float GetBalance ()
 
static int GetBrainOfCthuluCreepersCount ()
 
static int GetEaterOfWorldsSegmentsCount ()
 
static int GetEaterOfWorldsSegmentsCountByGamemode (int gamemode)
 
static string GetFirstNPCNameOrNull (int npcType)
 
static string GetFullnameByID (int npcID)
 
static void GetMeleeCollisionData (Rectangle victimHitbox, int enemyIndex, ref int specialHitSetter, ref float damageMultiplier, ref Rectangle npcRect)
 
static string getNewNPCName (int npcType)
 
static int GetNPCInvasionGroup (int npcID)
 
static bool GetNPCLocation (int i, bool seekHead, bool averageDirection, out int index, out Vector2 pos)
 
static int GetStackForSlimeItemDrop (int item)
 
static void HealEffect (Rectangle r, int healAmount, bool broadcast=true)
 
static int[,,,] InitializeMoonLordAttacks ()
 
static int[,] InitializeMoonLordAttacks2 ()
 
static bool IsValidSpawningGroundTile (int x, int y)
 
static void LadyBugKilled (Vector2 Position, bool GoldLadyBug=false)
 
static bool MechSpawn (float x, float y, int type)
 
static bool NearSpikeBall (int x, int y)
 
static int NewNPC (int X, int Y, int Type, int Start=0, float ai0=0f, float ai1=0f, float ai2=0f, float ai3=0f, int Target=255)
 
static void OnGameEventClearedForTheFirstTime (int gameEventId)
 
static void ReleaseNPC (int x, int y, int Type, int Style, int who)
 
static void ResetBadgerHatTime ()
 
static void ResetKillCount ()
 
static void ResetNetOffsets ()
 
static void SetEventFlagCleared (ref bool eventFlag, int gameEventId)
 
static void setFireFlyChance ()
 
static void setNPCName (string newName, int npcType, bool resetExtras=false)
 
static void SetWorldSpecificMonstersByWorldID ()
 
static bool ShouldEmpressBeEnraged ()
 
static void SlimeRainSpawns (int plr)
 
static void SpawnBoss (int spawnPositionX, int spawnPositionY, int Type, int targetPlayerIndex)
 
static bool Spawning_FlyingAntlionCheck (int x, int y)
 
static bool Spawning_SandstoneCheck (int x, int y)
 
static void SpawnNPC ()
 
static void SpawnOnPlayer (int plr, int Type)
 
static void SpawnSkeletron ()
 
static void SpawnWOF (Vector2 pos)
 
static int TypeToDefaultHeadIndex (int type)
 
static void UpdateFoundActiveNPCs ()
 
static void UpdateRGBPeriheralProbe ()
 
static bool WouldBeEncouragedToDespawn (int aistyle, int type)
 

Public Attributes

float[] ai = new float[maxAI]
 
int aiAction
 
int aiStyle
 
int alpha
 
int altTexture
 
bool behindTiles
 
bool betsysCurse
 
bool boss
 
int breath
 
int breathCounter
 
bool[] buffImmune = new bool[BuffLoader.BuffCount]
 
int[] buffTime = new int[5]
 
int[] buffType = new int[5]
 
bool canGhostHeal = true
 
short catchItem
 
bool celled
 
bool chaseable = true
 
bool closeDoor
 
bool coldDamage
 
bool collideX
 
bool collideY
 
Color color
 
bool confused
 
int damage
 
bool daybreak
 
LegacySoundStyle DeathSound
 
int defDamage
 
int defDefense
 
int defense
 
bool despawnEncouraged
 
int directionY = 1
 
bool dontCountMe
 
bool dontTakeDamage
 
bool dontTakeDamageFromHostiles
 
int doorX
 
int doorY
 
bool dripping
 
bool drippingSlime
 
bool drippingSparkleSlime
 
bool dryadBane
 
bool dryadWard
 
int extraValue
 
bool ForcePartyHatOn
 
Rectangle frame
 
double frameCounter
 
bool friendly
 
int friendlyRegen
 
float gfxOffY
 
bool hide
 
LegacySoundStyle HitSound
 
bool homeless
 
int homeTileX = -1
 
int homeTileY = -1
 
int housingCategory
 
bool ichor
 
bool immortal
 
int[] immune = new int[256]
 
bool IsABestiaryIconDummy
 
bool javelined
 
bool justHit
 
float knockBackResist = 1f
 
int lastInteraction = 255
 
int lastPortalColorIndex
 
bool lavaImmune
 
int life
 
int lifeMax
 
int lifeRegen
 
int lifeRegenCount
 
int lifeRegenExpectedLossPerSecond = -1
 
float[] localAI = new float[maxAI]
 
bool loveStruck
 
bool markedByScytheWhip
 
bool midas
 
float nameOver
 
bool netAlways
 
int netID
 
Vector2 netOffset = Vector2.Zero
 
int netSkip
 
int netSpam
 
bool netUpdate
 
bool netUpdate2
 
bool noGravity
 
bool noTileCollide
 
float npcSlots = 1f
 
bool oiled
 
int oldDirectionY
 
bool oldHomeless
 
int oldHomeTileX = -1
 
int oldHomeTileY = -1
 
Vector2[] oldPos = new Vector2[10]
 
float[] oldRot = new float[10]
 
int oldTarget
 
bool onFire
 
bool onFire2
 
bool onFire3
 
bool onFrostBurn
 
bool onFrostBurn2
 
bool[] playerInteraction = new bool[256]
 
bool poisoned
 
int rarity
 
int realLife = -1
 
bool reflectsProjectiles
 
short releaseOwner = 255
 
float rotation
 
float scale = 1f
 
bool setFrameSize
 
bool shadowFlame
 
bool soulDrain
 
int soundDelay
 
bool SpawnedFromStatue
 
int spriteDirection = -1
 
bool stairFall
 
int statsAreScaledForThisManyPlayers
 
float stepSpeed
 
bool stinky
 
float strengthMultiplier = 1f
 
float takenDamageMultiplier = 1f
 
int target = -1
 
Rectangle targetRect
 
bool teleporting
 
int teleportStyle
 
float teleportTime
 
int timeLeft
 
bool townNPC
 
int townNpcVariationIndex
 
bool trapImmune
 
int type
 
float value
 
bool venom
 
- Public Attributes inherited from Terraria.Entity
bool active
 
int direction = 1
 
int height
 
bool honeyWet
 
bool lavaWet
 
int oldDirection
 
Vector2 oldPosition
 
Vector2 oldVelocity
 
Vector2 position
 
Vector2 velocity
 
bool wet
 
byte wetCount
 
int whoAmI
 
int width
 

Static Public Attributes

static int activeTime = 750
 
static readonly int AFKTimeNeededForNoWorms = 300
 
static bool boughtBunny = false
 
static bool boughtCat = false
 
static bool boughtDog = false
 
const int breathMax = 200
 
static int butterflyChance = 0
 
static int[,] cavernMonsterType = new int[2, 3]
 
static bool combatBookWasUsed = false
 
static int crimsonBoss = -1
 
static bool downedAncientCultist = false
 
static bool downedBoss1 = false
 
static bool downedBoss2 = false
 
static bool downedBoss3 = false
 
static bool downedChristmasIceQueen = false
 
static bool downedChristmasSantank = false
 
static bool downedChristmasTree = false
 
static bool downedClown = false
 
static bool downedEmpressOfLight = false
 
static bool downedFishron = false
 
static bool downedFrost = false
 
static bool downedGoblins = false
 
static bool downedGolemBoss = false
 
static bool downedHalloweenKing = false
 
static bool downedHalloweenTree = false
 
static bool downedMartians = false
 
static bool downedMechBoss1 = false
 
static bool downedMechBoss2 = false
 
static bool downedMechBoss3 = false
 
static bool downedMechBossAny = false
 
static bool downedMoonlord = false
 
static bool downedPirates = false
 
static bool downedPlantBoss = false
 
static bool downedQueenBee = false
 
static bool downedQueenSlime = false
 
static bool downedSlimeKing = false
 
static bool downedTowerNebula = false
 
static bool downedTowerSolar = false
 
static bool downedTowerStardust = false
 
static bool downedTowerVortex = false
 
static bool fairyLog = false
 
static int fireFlyChance = 0
 
static int fireFlyFriendly = 0
 
static int fireFlyMultiple = 0
 
static bool freeCake = false
 
static int goldCritterChance = 400
 
static int golemBoss = -1
 
static int immuneTime = 20
 
static int[] killCount = new int[668]
 
static int ladyBugBadLuckTime = -10800
 
static int ladyBugGoodLuckTime = 43200
 
static int[] lazyNPCOwnedProjectileSearchArray = new int[200]
 
static bool LunarApocalypseIsUp = false
 
static int LunarShieldPowerExpert = 150
 
static int LunarShieldPowerNormal = 100
 
static int maxAI = 4
 
const int maxBuffs = 5
 
const int MaxMoonLordCountdown = 3600
 
static readonly int[,,,] MoonLordAttacksArray = InitializeMoonLordAttacks()
 
static readonly int[,] MoonLordAttacksArray2 = InitializeMoonLordAttacks2()
 
static int MoonLordCountdown = 0
 
static int MoonLordFightingDistance = 4500
 
const float nameOverDistance = 350f
 
const float nameOverIncrement = 0.025f
 
static bool[] npcsFoundForCheckActive = new bool[668]
 
static int offSetDelayTime = 60
 
static int plantBoss = -1
 
static CoinLossRevengeSystem RevengeManager = new CoinLossRevengeSystem()
 
static int safeRangeX = (int)((double)(sWidth / 16) * 0.52)
 
static int safeRangeY = (int)((double)(sHeight / 16) * 0.52)
 
static bool savedAngler = false
 
static bool savedBartender = false
 
static bool savedGoblin = false
 
static bool savedGolfer = false
 
static bool savedMech = false
 
static bool savedStylist = false
 
static bool savedTaxCollector = false
 
static bool savedWizard = false
 
static int sHeight = 1080
 
static int ShieldStrengthTowerNebula = 0
 
static int ShieldStrengthTowerSolar = 0
 
static int ShieldStrengthTowerStardust = 0
 
static int ShieldStrengthTowerVortex = 0
 
static int sWidth = 1920
 
static bool taxCollector = false
 
static bool TowerActiveNebula = false
 
static bool TowerActiveSolar = false
 
static bool TowerActiveStardust = false
 
static bool TowerActiveVortex = false
 
static bool travelNPC = false
 
static float waveKills = 0f
 
static int waveNumber = 0
 

Properties

IBigProgressBar BossBar [get, set]
 Assign a special boss bar, vanilla or modded. Not used by vanilla. More...
 
bool CanBeTalkedTo [get]
 
bool CanTalk [get]
 
bool CountsAsACritter [get]
 
static bool downedTowers [get]
 
string FullName [get]
 
string?? GivenName [get, set]
 
string GivenOrTypeName [get]
 
RefReadOnlyArray< Instanced< GlobalNPC > > Globals [get]
 
bool HasGivenName [get]
 
bool HasNPCTarget [get]
 
bool HasPlayerTarget [get]
 
bool HasValidTarget [get]
 
bool isLikeATownNPC [get]
 
ModNPC ModNPC [get, set]
 
float Opacity [get, set]
 
static int ShieldStrengthTowerMax [get]
 
bool SupportsNPCTargets [get]
 
static bool TooWindyForButterflies [get]
 
static bool TowersDefeated [get]
 
int TranslatedTargetIndex [get]
 
string TypeName [get]
 
int WhoAmIToTargettingIndex [get]
 
- Properties inherited from Terraria.Entity
Vector2 Bottom [get, set]
 
Vector2 BottomLeft [get, set]
 
Vector2 BottomRight [get, set]
 
Vector2 Center [get, set]
 
Rectangle Hitbox [get, set]
 
Vector2 Left [get, set]
 
Vector2 Right [get, set]
 
Vector2 Size [get, set]
 
Vector2 Top [get, set]
 
Vector2 TopLeft [get, set]
 
Vector2 TopRight [get, set]
 
virtual Vector2 VisualPosition [get]
 
- Properties inherited from Terraria.ModLoader.IEntityWithGlobals< GlobalNPC >
RefReadOnlyArray< Instanced< T > > Globals [get]
 

Member Function Documentation

◆ GetGlobalNPC< T >() [1/2]

T Terraria.NPC.GetGlobalNPC< T > ( bool  exactType = true)

Gets the instance of the specified GlobalNPC type. This will throw exceptions on failure.

Exceptions
KeyNotFoundException
Exceptions
IndexOutOfRangeException
Type Constraints
T :GlobalNPC 
T :GlobalType.GetGlobal 
T :NPC 
T :GlobalNPC 
T :T 
T :globalNPCs 
T :exactType 

◆ GetGlobalNPC< T >() [2/2]

T Terraria.NPC.GetGlobalNPC< T > ( baseInstance)

Gets the local instance of the type of the specified GlobalNPC instance. This will throw exceptions on failure.

Exceptions
KeyNotFoundException
Exceptions
NullReferenceException
Type Constraints
T :GlobalNPC 
T :GlobalType.GetGlobal 
T :NPC 
T :GlobalNPC 
T :T 
T :globalNPCs 
T :baseInstance 

◆ HasBuff()

bool Terraria.NPC.HasBuff ( int  type)

Returns whether or not this NPC currently has a (de)buff of the provided type.

◆ TryGetGlobalNPC< T >() [1/2]

bool Terraria.NPC.TryGetGlobalNPC< T > ( out T  result,
bool  exactType = true 
)

Gets the instance of the specified GlobalNPC type.

Type Constraints
T :GlobalNPC 
T :GlobalType.TryGetGlobal 
T :GlobalNPC 
T :T 
T :globalNPCs 
T :exactType 
T :out 
T :result 

◆ TryGetGlobalNPC< T >() [2/2]

bool Terraria.NPC.TryGetGlobalNPC< T > ( baseInstance,
out T  result 
)

Safely attempts to get the local instance of the type of the specified GlobalNPC instance.

Returns
Whether or not the requested instance has been found.
Type Constraints
T :GlobalNPC 
T :GlobalType.TryGetGlobal 
T :GlobalNPC 
T :T 
T :globalNPCs 
T :baseInstance 
T :out 
T :result 

Property Documentation

◆ BossBar

IBigProgressBar Terraria.NPC.BossBar
getset

Assign a special boss bar, vanilla or modded. Not used by vanilla.

To assign a modded boss bar, use NPC.BossBar = ModContent.GetInstance<ExampleBossBar>(); where ExampleBossBar is a ModBossBar

To assign a vanilla boss bar for whatever reason, fetch it first through the NPC type using Main.BigBossProgressBar.TryGetSpecialVanillaBossBar