Added old Puff Shroom code of mine

This commit is contained in:
Dominic committed 2022-06-19 00:34:10 -05:00
1 parent d1a220f926
commit ea1f4d4fbc
9 files changed
+310

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
using CalamityMod.CalPlayer;
using CalamityMod.Projectiles.Summon;
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.Buffs.Summon
{
public class PuffWarriorBuff : ModBuff
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Puff Warrior");
Description.SetDefault("It confidently and excitedly protects you");
Main.buffNoTimeDisplay[Type] = true;
Main.buffNoSave[Type] = true;
}
public override void Update(Player player, ref int buffIndex)
{
CalamityPlayer modPlayer = player.Calamity();
if (player.ownedProjectileCounts[ModContent.ProjectileType<PuffWarrior>()] > 0)
modPlayer.puffWarrior = true;
if (modPlayer.puffWarrior)
player.buffTime[buffIndex] = 18000;
else
{
player.DelBuff(buffIndex);
buffIndex--;
}
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 576 B

+2
View File
@@ -989,6 +989,7 @@ namespace CalamityMod.CalPlayer
public bool eyeOfNight = false;
public bool soulSeeker = false;
public bool perditionBeacon = false;
public bool puffWarrior = false;
public List<DeadMinionProperties> PendingProjectilesToRespawn = new List<DeadMinionProperties>();
@@ -2076,6 +2077,7 @@ namespace CalamityMod.CalPlayer
eyeOfNight = false;
soulSeeker = false;
perditionBeacon = false;
puffWarrior = false;
disableVoodooSpawns = false;
disablePerfCystSpawns = false;
+48
View File
@@ -0,0 +1,48 @@
using CalamityMod.Projectiles.Summon;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Items.Weapons.Summon
{
public class PuffShroom : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Puff Shroom");
Tooltip.SetDefault("Summons a cute mushroom warrior to fight for you");
}
public override void SetDefaults()
{
Item.damage = 14;
Item.mana = 10;
Item.width = 32;
Item.height = 32;
Item.useTime = Item.useAnimation = 35;
Item.useStyle = ItemUseStyleID.Swing;
Item.noMelee = true;
Item.knockBack = 2f;
Item.value = CalamityGlobalItem.Rarity2BuyPrice;
Item.rare = ItemRarityID.Green;
Item.UseSound = SoundID.Item42;
Item.autoReuse = true;
Item.shoot = ModContent.ProjectileType<PuffWarrior>();
Item.shootSpeed = 10f;
Item.DamageType = DamageClass.Summon;
}
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
{
if (player.altFunctionUse != 2)
{
int puffGuy = Projectile.NewProjectile(source, Main.MouseWorld, Vector2.Zero, type, damage, knockback, player.whoAmI);
if (Main.projectile.IndexInRange(puffGuy))
Main.projectile[puffGuy].originalDamage = Item.damage;
}
return false;
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 576 B

+43
View File
@@ -0,0 +1,43 @@
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Summon
{
public class PuffCloud : ModProjectile
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Cloud");
Main.projFrames[Projectile.type] = 7;
ProjectileID.Sets.MinionShot[Projectile.type] = true;
}
public override void SetDefaults()
{
Projectile.width = Projectile.height = 16;
Projectile.friendly = true;
Projectile.minion = true;
Projectile.minionSlots = 0f;
Projectile.ignoreWater = true;
Projectile.penetrate = 1;
Projectile.tileCollide = false;
}
public override void AI()
{
Lighting.AddLight(Projectile.Center, Color.Cyan.ToVector3());
Projectile.velocity *= 0.97f;
Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2;
Projectile.frameCounter++;
if (Projectile.frameCounter % 4 == 3)
{
Projectile.frame++;
if (Projectile.frame >= Main.projFrames[Projectile.type])
Projectile.Kill();
}
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 945 B

+184
View File
@@ -0,0 +1,184 @@
using CalamityMod.Buffs.Summon;
using Microsoft.Xna.Framework;
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.WorldBuilding;
namespace CalamityMod.Projectiles.Summon
{
public class PuffWarrior : ModProjectile
{
public Player Owner => Main.player[Projectile.owner];
public Tile GroundTile => CalamityUtils.ParanoidTileRetrieval((int)(Projectile.Bottom.X / 16), (int)(Projectile.Bottom.Y / 16) + 1);
public bool Jumping => !GroundTile.IsTileSolidGround() || Math.Abs(Projectile.velocity.Y) > 5f;
public ref float JumpCountdown => ref Projectile.localAI[1];
public const float Gravity = 0.425f;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Puff Warrior");
Main.projFrames[Projectile.type] = 10;
ProjectileID.Sets.MinionSacrificable[Projectile.type] = true;
ProjectileID.Sets.MinionTargettingFeature[Projectile.type] = true;
}
public override void SetDefaults()
{
Projectile.width = Projectile.height = 36;
Projectile.netImportant = true;
Projectile.friendly = true;
Projectile.ignoreWater = true;
Projectile.minionSlots = 1f;
Projectile.timeLeft = 90000;
Projectile.penetrate = -1;
Projectile.minion = true;
Projectile.usesLocalNPCImmunity = true;
Projectile.localNPCHitCooldown = 18;
Projectile.tileCollide = true;
}
public override void AI()
{
ProvidePlayerMinionBuffs();
DetermineFrames();
NPC potentialTarget = Projectile.Center.MinionHoming(660f, Owner);
if (potentialTarget is null)
{
HopToOwner(out Vector2 guardSpot);
TeleportToFarOffDestination(guardSpot);
}
else
HopToTarget(potentialTarget);
Projectile.spriteDirection = (Projectile.velocity.X > 0).ToDirectionInt();
Projectile.rotation = Jumping ? Projectile.rotation + MathHelper.Pi / 10f * Projectile.spriteDirection : 0f;
while (Collision.SolidCollision(Projectile.position, Projectile.width, Projectile.height))
Projectile.position.Y -= 10f;
// Enforce gravity.
if (Projectile.velocity.Y < 16f)
Projectile.velocity.Y += Gravity;
}
internal void ProvidePlayerMinionBuffs()
{
Owner.AddBuff(ModContent.BuffType<PuffWarriorBuff>(), 3600);
// Verify player/minion state integrity. The minion cannot stay alive if the
// owner is dead or if the caller of the AI is invalid.
if (Projectile.type != ModContent.ProjectileType<PuffWarrior>())
return;
if (Owner.dead)
Owner.Calamity().puffWarrior = false;
if (Owner.Calamity().puffWarrior)
Projectile.timeLeft = 2;
}
internal void DetermineFrames()
{
int startingFrame = Jumping ? Main.projFrames[Projectile.type] - 3 : 0;
int endingFrame = Jumping ? Main.projFrames[Projectile.type] - 4 : Main.projFrames[Projectile.type] - 4;
if (Jumping)
JumpCountdown = 12f;
else if (Math.Abs(Projectile.velocity.Y) <= Gravity && JumpCountdown > 0)
{
startingFrame = Main.projFrames[Projectile.type] - 1;
endingFrame = Main.projFrames[Projectile.type] - 1;
JumpCountdown--;
}
if (Projectile.frame < startingFrame)
Projectile.frame = startingFrame;
Projectile.frameCounter++;
if (Projectile.frameCounter % 6 == 5)
Projectile.frame++;
if (Projectile.frame >= endingFrame)
Projectile.frame = startingFrame;
}
internal void TeleportToFarOffDestination(Vector2 guardSpot)
{
bool obstructionBetweenSpot = Collision.CanHitLine(Projectile.position, Projectile.width, Projectile.height, guardSpot, 4, 4);
bool outOfRangeOfSpot = !Projectile.WithinRange(guardSpot, obstructionBetweenSpot ? 700f : 1900f);
if (Main.myPlayer == Projectile.owner && outOfRangeOfSpot)
{
Projectile.Center = guardSpot;
Projectile.netUpdate = true;
}
}
internal void HopToOwner(out Vector2 guardSpot)
{
guardSpot = Owner.Center;
guardSpot.X += Owner.direction * 40f * (Projectile.identity % 14f + Projectile.identity / 14 * 0.2f);
Vector2 searchPoint = guardSpot - Vector2.UnitY * 420f;
// Ensure that the search point is not outside of the world (which would result in index problems in the search).
searchPoint.Y = MathHelper.Clamp(searchPoint.Y, 32f, Main.maxTilesY * 16f - 32f);
// Adjust the destination to be at the lowest point.
WorldUtils.Find(searchPoint.ToTileCoordinates(), Searches.Chain(new Searches.Down(Main.maxTilesY + 2), new Conditions.IsSolid()), out Point guardPoint);
guardSpot = guardPoint.ToWorldCoordinates(8f, 16f);
if (!Jumping && MathHelper.Distance(guardSpot.X, Projectile.Center.X) > 10f)
{
Projectile.velocity = CalamityUtils.GetProjectilePhysicsFiringVelocity(Projectile.Center, guardSpot, Gravity, 12f);
Projectile.netUpdate = true;
}
}
internal void HopToTarget(NPC target)
{
Vector2 attackPosition = target.Center;
float attackPositionOffsetDirection = (target.velocity.X > 0).ToDirectionInt() * Math.Sign(Projectile.Center.X - target.Center.X);
attackPosition.X += attackPositionOffsetDirection * 22f * (Projectile.identity % 14f + Projectile.identity / 14 * 0.2f);
Vector2 searchPoint = attackPosition - Vector2.UnitY * 360f;
// Ensure that the search point is not outside of the world (which would result in index problems in the search).
searchPoint.Y = MathHelper.Clamp(searchPoint.Y, 32f, Main.maxTilesY * 16f - 32f);
// Adjust the destination to be at the lowest point.
WorldUtils.Find(searchPoint.ToTileCoordinates(), Searches.Chain(new Searches.Down(Main.maxTilesY + 2), new Conditions.IsSolid()), out Point guardPoint);
attackPosition = guardPoint.ToWorldCoordinates();
if (!Jumping)
{
Projectile.position += new Vector2(Projectile.spriteDirection * 4f, -4f);
Projectile.velocity = CalamityUtils.GetProjectilePhysicsFiringVelocity(Projectile.Center, attackPosition, Gravity, 17f);
if (Main.myPlayer == Projectile.owner && Projectile.WithinRange(attackPosition, 360f))
{
for (int i = 0; i < 3; i++)
{
Vector2 shootPosition = Projectile.Top + Vector2.UnitY * (8f + i * 3f);
Vector2 shootVelocity = (target.Center - shootPosition).SafeNormalize(Vector2.UnitY) * 14f;
Projectile.NewProjectile(Projectile.GetSource_FromThis(), shootPosition, shootVelocity, ModContent.ProjectileType<PuffCloud>(), Projectile.damage, Projectile.knockBack, Projectile.owner);
}
}
Projectile.netUpdate = true;
}
}
public override bool OnTileCollide(Vector2 oldVelocity)
{
if (Projectile.oldVelocity.Length() > 6f)
Projectile.velocity = oldVelocity * 0.5f;
else
Projectile.velocity.X = 0f;
return false;
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB