/
ExampleSword.cs
97 lines (90 loc) · 4.17 KB
/
ExampleSword.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using ExampleMod.Dusts;
using ExampleMod.Tiles;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace ExampleMod.Items.Weapons
{
public class ExampleSword : ModItem
{
public override void SetStaticDefaults() {
Tooltip.SetDefault("This is a modded sword."); //The (English) text shown below your weapon's name
}
public override void SetDefaults() {
item.damage = 50; // The damage your item deals
item.melee = true; // Whether your item is part of the melee class
item.width = 40; // The item texture's width
item.height = 40; // The item texture's height
item.useTime = 20; // The time span of using the weapon. Remember in terraria, 60 frames is a second.
item.useAnimation = 20; // The time span of the using animation of the weapon, suggest setting it the same as useTime.
item.knockBack = 6; // The force of knockback of the weapon. Maximum is 20
item.value = Item.buyPrice(gold: 1); // The value of the weapon in copper coins
item.rare = ItemRarityID.Green; // The rarity of the weapon, from -1 to 13. You can also use ItemRarityID.TheColorRarity
item.UseSound = SoundID.Item1; // The sound when the weapon is being used
item.autoReuse = true; // Whether the weapon can be used more than once automatically by holding the use button
item.crit = 6; // The critical strike chance the weapon has. The player, by default, has 4 critical strike chance
//The useStyle of the item.
//Use useStyle 1 for normal swinging or for throwing
//use useStyle 2 for an item that drinks such as a potion,
//use useStyle 3 to make the sword act like a shortsword
//use useStyle 4 for use like a life crystal,
//and use useStyle 5 for staffs or guns
item.useStyle = ItemUseStyleID.SwingThrow; // 1 is the useStyle
}
public override void AddRecipes() {
ModRecipe recipe = new ModRecipe(mod);
// ItemType<ExampleItem>() is how to get the ExampleItem item, 10 is the amount of that item you need to craft the recipe
recipe.AddIngredient(ModContent.ItemType<ExampleItem>(), 10);
// You can use recipe.AddIngredient(ItemID.TheItemYouWantToUse, the amount of items needed); for a vanilla item.
recipe.AddTile(ModContent.TileType<ExampleWorkbench>()); // Set the crafting tile to ExampleWorkbench
recipe.SetResult(this); // Set the result to this item (ExampleSword)
recipe.AddRecipe(); // When your done, add the recipe
}
public override void MeleeEffects(Player player, Rectangle hitbox) {
if (Main.rand.NextBool(3)) {
//Emit dusts when the sword is swung
Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, ModContent.DustType<Sparkle>());
}
}
public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit) {
// Add the Onfire buff to the NPC for 1 second when the weapon hits an NPC
// 60 frames = 1 second
target.AddBuff(BuffID.OnFire, 60);
}
// Star Wrath/Starfury style weapon. Spawn projectiles from sky that aim towards mouse.
// See Source code for Star Wrath projectile to see how it passes through tiles.
/* The following changes to SetDefaults
item.shoot = 503;
item.shootSpeed = 8f;
public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
Vector2 target = Main.screenPosition + new Vector2((float)Main.mouseX, (float)Main.mouseY);
float ceilingLimit = target.Y;
if (ceilingLimit > player.Center.Y - 200f)
{
ceilingLimit = player.Center.Y - 200f;
}
for (int i = 0; i < 3; i++)
{
position = player.Center + new Vector2((-(float)Main.rand.Next(0, 401) * player.direction), -600f);
position.Y -= (100 * i);
Vector2 heading = target - position;
if (heading.Y < 0f)
{
heading.Y *= -1f;
}
if (heading.Y < 20f)
{
heading.Y = 20f;
}
heading.Normalize();
heading *= new Vector2(speedX, speedY).Length();
speedX = heading.X;
speedY = heading.Y + Main.rand.Next(-40, 41) * 0.02f;
Projectile.NewProjectile(position.X, position.Y, speedX, speedY, type, damage * 2, knockBack, player.whoAmI, 0f, ceilingLimit);
}
return false;
}*/
}
}