Files
tsiva/Weapons/Outbreak.cs

116 lines
5.0 KiB
C#

using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Audio;
using Terraria.ID;
using Terraria.ModLoader;
using Siva.Items;
namespace Siva.Weapons
{
public class Outbreak : ModItem
{
public static readonly int ItemType = ModContent.ItemType<Outbreak>();
public override void SetDefaults()
{
// Modders can use Item.DefaultToRangedWeapon to quickly set many common properties, such as: useTime, useAnimation, useStyle, autoReuse, DamageType, shoot, shootSpeed, useAmmo, and noMelee. These are all shown individually here for teaching purposes.
// Common Properties
Item.width = 22; // Hitbox width of the item.
Item.height = 10; // Hitbox height of the item.
Item.scale = 0.75f;
Item.rare = ItemRarityID.Red; // The color that the item's name will be in-game.
// Use Properties
Item.useTime = 4; // one third of useAnimation for three burst effect I think
Item.useAnimation = 12; // The length of the item's use animation in ticks
Item.reuseDelay = 12; // The delay before you can shoot again, crazy I know
Item.useStyle = ItemUseStyleID.Shoot; // How you use the item (swinging, holding out, etc.)
Item.autoReuse = true; // Whether or not you can hold click to automatically use it again
// Weapon Properties
Item.consumeAmmoOnLastShotOnly = true;
Item.DamageType = DamageClass.Ranged; // Sets the damage type to ranged.
Item.damage = 22; // Sets the item's damage. Note that projectiles shot by this weapon will use its and the used ammunition's damage added together.
Item.knockBack = 3f; // Sets the item's knockback. Note that projectiles shot by this weapon will use its and the used ammunition's knockback added together.
Item.noMelee = true; // So the item's animation doesn't do damage.
Item.crit = 29; // Sets the item's crit chance. Note that the player's base crit chance is 4% and will be added to the item's crit chance.
// Gun Properties
Item.shoot = ProjectileID.PurificationPowder; // For some reason, all the guns in the vanilla source have this.
Item.shootSpeed = 20f; // The speed of the projectile (measured in pixels per frame.)
Item.useAmmo = AmmoID.Bullet; // The "ammo Id" of the ammo item that this weapon uses. Ammo IDs are magic numbers that usually correspond to the item id of one item that most commonly represent the ammo type.
// The sound that this item plays when used.
Item.UseSound = new SoundStyle($"{nameof(Siva)}/Sounds/Pew") {
Volume = 1f,
PitchVariance = 0,
MaxInstances = 3,
};
}
// This method lets you adjust position of the gun in the player's hands. Play with these values until it looks good with your graphics.
public override Vector2? HoldoutOffset() {
return new Vector2(2f, 0f);
}
}
public class CatalystDropChance : GlobalNPC
{
private static readonly Random Random = new Random();
public override void OnHitByProjectile(NPC npc, Projectile projectile, NPC.HitInfo hit, int damageDone)
{
Player player = Main.player[projectile.owner];
if(!player.HasItemInAnyInventory(ModContent.ItemType<OutbreakCatalyst>()) && player.HeldItem.type == Outbreak.ItemType && projectile.aiStyle == 1 && hit.Crit && npc.life <= 0 && !npc.SpawnedFromStatue && npc.lifeMax > 5)
{
int randomNumber = Random.Next(350);
// Main.NewText($"Rolled Catty drop chance, randint is {randomNumber}"); // debug text
if(randomNumber == 77)
{
player.QuickSpawnItem(player.GetSource_FromThis(), ModContent.ItemType<OutbreakCatalyst>());
}
}
}
}
}
// Old nanite creation method.
/*
public class NaniteCreation : GlobalProjectile // Creates 1-3 Nanites on critical hits
{
// Alters the base behavior of what happens when a projectile hits an NPC
public override void OnHitNPC(Projectile projectile, NPC target, NPC.HitInfo hit, int damage)
{
// Accessing the player who shot the projectile
Player player = Main.player[projectile.owner];
// Checks to make sure the player is holding MasterworkedOutbreak and the projectile was not a SIVA Nanite so they don't spawn more nanites.
if (player.HeldItem.type == ModContent.ItemType<MasterworkedOutbreak>() & projectile.type != ModContent.ProjectileType<SIVANanite>())
{
if(hit.Crit) // On critical hits
{
int randomNumber = new Random().Next(101); // Random number 0-10
if (randomNumber <= 60) // 60% chance to make a nanite
{
SIVANanite.Create(1, projectile, target, damage/2);
}
else if (60 < randomNumber & randomNumber <= 90) // 30% chance to make a nanite twice
{
SIVANanite.Create(2, projectile, target, damage/2);
}
else if (90 < randomNumber & randomNumber <= 100) // 10% chance to make a nanite thrice
{
SIVANanite.Create(3, projectile, target, damage/2);
}
}
}
}
}*/