tModLoader v0.11.8.9
A mod to make and play Terraria mods
GlobalProjectile.cs
Go to the documentation of this file.
1using Microsoft.Xna.Framework;
2using Microsoft.Xna.Framework.Graphics;
3using System;
4using System.Collections.Generic;
5
6namespace Terraria.ModLoader
7{
11 public class GlobalProjectile
12 {
16 public Mod mod {
17 get;
18 internal set;
19 }
20
24 public string Name {
25 get;
26 internal set;
27 }
28
29 internal int index;
30 internal int instanceIndex;
31
37 public virtual bool Autoload(ref string name) {
38 return mod.Properties.Autoload;
39 }
40
46 public virtual bool InstancePerEntity => false;
47
48 public GlobalProjectile Instance(Projectile projectile) => InstancePerEntity ? projectile.globalProjectiles[instanceIndex] : this;
49
54 public virtual bool CloneNewInstances => false;
55
61 public virtual GlobalProjectile Clone() => (GlobalProjectile)MemberwiseClone();
62
69 public virtual GlobalProjectile NewInstance(Projectile projectile) {
71 return Clone();
72 }
73 GlobalProjectile copy = (GlobalProjectile)Activator.CreateInstance(GetType());
74 copy.mod = mod;
75 copy.Name = Name;
76 copy.index = index;
77 copy.instanceIndex = instanceIndex;
78 return copy;
79 }
80
85 public virtual void SetDefaults(Projectile projectile) {
86 }
87
93 public virtual bool PreAI(Projectile projectile) {
94 return true;
95 }
96
101 public virtual void AI(Projectile projectile) {
102 }
103
108 public virtual void PostAI(Projectile projectile) {
109 }
110
116 public virtual bool ShouldUpdatePosition(Projectile projectile) {
117 return true;
118 }
119
128 public virtual bool TileCollideStyle(Projectile projectile, ref int width, ref int height, ref bool fallThrough) {
129 return true;
130 }
131
138 public virtual bool OnTileCollide(Projectile projectile, Vector2 oldVelocity) {
139 return true;
140 }
141
148 public virtual bool PreKill(Projectile projectile, int timeLeft) {
149 return true;
150 }
151
157 public virtual void Kill(Projectile projectile, int timeLeft) {
158 }
159
165 public virtual bool? CanCutTiles(Projectile projectile) {
166 return null;
167 }
168
173 public virtual void CutTiles(Projectile projectile) {
174 }
175
181 public virtual bool CanDamage(Projectile projectile) {
182 return true;
183 }
184
190 public virtual bool MinionContactDamage(Projectile projectile) {
191 return false;
192 }
193
199 public virtual void ModifyDamageHitbox(Projectile projectile, ref Rectangle hitbox) {
200 }
201
208 public virtual bool? CanHitNPC(Projectile projectile, NPC target) {
209 return null;
210 }
211
221 public virtual void ModifyHitNPC(Projectile projectile, NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) {
222 }
223
232 public virtual void OnHitNPC(Projectile projectile, NPC target, int damage, float knockback, bool crit) {
233 }
234
241 public virtual bool CanHitPvp(Projectile projectile, Player target) {
242 return true;
243 }
244
252 public virtual void ModifyHitPvp(Projectile projectile, Player target, ref int damage, ref bool crit) {
253 }
254
262 public virtual void OnHitPvp(Projectile projectile, Player target, int damage, bool crit) {
263 }
264
271 public virtual bool CanHitPlayer(Projectile projectile, Player target) {
272 return true;
273 }
274
282 public virtual void ModifyHitPlayer(Projectile projectile, Player target, ref int damage, ref bool crit) {
283 }
284
292 public virtual void OnHitPlayer(Projectile projectile, Player target, int damage, bool crit) {
293 }
294
302 public virtual bool? Colliding(Projectile projectile, Rectangle projHitbox, Rectangle targetHitbox) {
303 return null;
304 }
305
312 public virtual Color? GetAlpha(Projectile projectile, Color lightColor) {
313 return null;
314 }
315
322 public virtual bool PreDrawExtras(Projectile projectile, SpriteBatch spriteBatch) {
323 return true;
324 }
325
333 public virtual bool PreDraw(Projectile projectile, SpriteBatch spriteBatch, Color lightColor) {
334 return true;
335 }
336
343 public virtual void PostDraw(Projectile projectile, SpriteBatch spriteBatch, Color lightColor) {
344 }
345
355 public virtual void DrawBehind(Projectile projectile, int index, List<int> drawCacheProjsBehindNPCsAndTiles, List<int> drawCacheProjsBehindNPCs, List<int> drawCacheProjsBehindProjectiles, List<int> drawCacheProjsOverWiresUI) {
356 }
357
361 public virtual bool? CanUseGrapple(int type, Player player) {
362 return null;
363 }
364
368 public virtual bool? SingleGrappleHook(int type, Player player) {
369 return null;
370 }
371
375 public virtual void UseGrapple(Player player, ref int type) {
376 }
377
381 public virtual void NumGrappleHooks(Projectile projectile, Player player, ref int numHooks) {
382 }
383
387 public virtual void GrappleRetreatSpeed(Projectile projectile, Player player, ref float speed) {
388 }
389
393 public virtual void GrapplePullSpeed(Projectile projectile, Player player, ref float speed) {
394 }
395
399 public virtual void GrappleTargetPoint(Projectile projectile, Player player, ref float grappleX, ref float grappleY) {
400 }
401 }
402}
This class allows you to modify and use hooks for all projectiles, including vanilla projectiles....
virtual void OnHitPvp(Projectile projectile, Player target, int damage, bool crit)
Allows you to create special effects when a projectile hits an opponent player.
virtual ? bool CanUseGrapple(int type, Player player)
Whether or not a grappling hook that shoots this type of projectile can be used by the given player....
virtual bool InstancePerEntity
Whether to create a new GlobalProjectile instance for every Projectile that exists....
virtual bool Autoload(ref string name)
Allows you to automatically load a GlobalProjectile instead of using Mod.AddGlobalProjectile....
virtual void GrapplePullSpeed(Projectile projectile, Player player, ref float speed)
The speed at which the grapple pulls the player after hitting something. Defaults to 11,...
virtual void Kill(Projectile projectile, int timeLeft)
Allows you to control what happens when a projectile is killed (for example, creating dust or making ...
virtual bool CloneNewInstances
Whether instances of this GlobalProjectile are created through Clone or constructor (by default imple...
virtual bool PreDraw(Projectile projectile, SpriteBatch spriteBatch, Color lightColor)
Allows you to draw things behind a projectile, or to modify the way the projectile is drawn....
virtual void ModifyHitPlayer(Projectile projectile, Player target, ref int damage, ref bool crit)
Allows you to modify the damage, etc., that a hostile projectile does to a player.
virtual bool PreAI(Projectile projectile)
Allows you to determine how any projectile behaves. Return false to stop the vanilla AI and the AI ho...
virtual void OnHitPlayer(Projectile projectile, Player target, int damage, bool crit)
Allows you to create special effects when a hostile projectile hits a player.
virtual ? bool CanCutTiles(Projectile projectile)
Return true or false to specify if the projectile can cut tiles, like vines. Return null for vanilla ...
virtual void PostDraw(Projectile projectile, SpriteBatch spriteBatch, Color lightColor)
Allows you to draw things in front of a projectile. This method is called even if PreDraw returns fal...
virtual bool CanHitPlayer(Projectile projectile, Player target)
Allows you to determine whether a hostile projectile can hit the given player. Return false to block ...
virtual bool OnTileCollide(Projectile projectile, Vector2 oldVelocity)
Allows you to determine what happens when a projectile collides with a tile. OldVelocity is the veloc...
virtual void PostAI(Projectile projectile)
Allows you to determine how any projectile behaves. This will be called regardless of what PreAI retu...
Mod mod
The mod to which this GlobalProjectile belongs.
virtual void OnHitNPC(Projectile projectile, NPC target, int damage, float knockback, bool crit)
Allows you to create special effects when a projectile hits an NPC (for example, inflicting debuffs)....
virtual void CutTiles(Projectile projectile)
Code ran when the projectile cuts tiles. Only runs if CanCutTiles() returns true. Useful when program...
virtual void ModifyHitNPC(Projectile projectile, NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection)
Allows you to modify the damage, knockback, etc., that a projectile does to an NPC....
virtual ? bool CanHitNPC(Projectile projectile, NPC target)
Allows you to determine whether a projectile can hit the given NPC. Return true to allow hitting the ...
virtual ? Color GetAlpha(Projectile projectile, Color lightColor)
Allows you to determine the color and transparency in which a projectile is drawn....
virtual void ModifyDamageHitbox(Projectile projectile, ref Rectangle hitbox)
Allows you to change the hitbox used by a projectile for damaging players and NPCs.
virtual bool ShouldUpdatePosition(Projectile projectile)
Whether or not the given projectile should update its position based on factors such as its velocity,...
virtual bool CanHitPvp(Projectile projectile, Player target)
Allows you to determine whether a projectile can hit the given opponent player. Return false to block...
virtual GlobalProjectile Clone()
Returns a clone of this GlobalProjectile. By default this will return a memberwise clone; you will wa...
virtual void UseGrapple(Player player, ref int type)
This code is called whenever the player uses a grappling hook that shoots this type of projectile....
virtual bool CanDamage(Projectile projectile)
Whether or not the given projectile is capable of killing tiles (such as grass) and damaging NPCs/pla...
virtual void NumGrappleHooks(Projectile projectile, Player player, ref int numHooks)
How many of this type of grappling hook the given player can latch onto blocks before the hooks start...
virtual bool MinionContactDamage(Projectile projectile)
Whether or not a minion can damage NPCs by touching them. Returns false by default....
virtual ? bool Colliding(Projectile projectile, Rectangle projHitbox, Rectangle targetHitbox)
Allows you to use custom collision detection between a projectile and a player or NPC that the projec...
virtual void ModifyHitPvp(Projectile projectile, Player target, ref int damage, ref bool crit)
Allows you to modify the damage, etc., that a projectile does to an opponent player.
GlobalProjectile Instance(Projectile projectile)
virtual void GrappleTargetPoint(Projectile projectile, Player player, ref float grappleX, ref float grappleY)
The location that the grappling hook pulls the player to. Defaults to the center of the hook projecti...
virtual GlobalProjectile NewInstance(Projectile projectile)
Create a new instance of this GlobalProjectile for a Projectile instance. Called at the end of Projec...
virtual bool PreKill(Projectile projectile, int timeLeft)
Allows you to determine whether the vanilla code for Kill and the Kill hook will be called....
virtual void DrawBehind(Projectile projectile, int index, List< int > drawCacheProjsBehindNPCsAndTiles, List< int > drawCacheProjsBehindNPCs, List< int > drawCacheProjsBehindProjectiles, List< int > drawCacheProjsOverWiresUI)
When used in conjunction with "projectile.hide = true", allows you to specify that this projectile sh...
string Name
The name of this GlobalProjectile instance.
virtual ? bool SingleGrappleHook(int type, Player player)
Whether or not a grappling hook can only have one hook per player in the world at a time....
virtual void AI(Projectile projectile)
Allows you to determine how any projectile behaves. This will only be called if PreAI returns true.
virtual bool TileCollideStyle(Projectile projectile, ref int width, ref int height, ref bool fallThrough)
Allows you to determine how a projectile interacts with tiles. Width and height determine the project...
virtual void GrappleRetreatSpeed(Projectile projectile, Player player, ref float speed)
The speed at which the grapple retreats back to the player after not hitting anything....
virtual bool PreDrawExtras(Projectile projectile, SpriteBatch spriteBatch)
Allows you to draw things behind a projectile. Returns false to stop the game from drawing extras tex...
virtual void SetDefaults(Projectile projectile)
Allows you to set the properties of any and every projectile that gets created.
Mod is an abstract class that you will override. It serves as a central place from which the mod's co...
Definition: Mod.cs:25
ModProperties Properties
Definition: Mod.cs:52
bool Autoload
Whether or not this mod will autoload content by default. Autoloading content means you do not need t...