This commit is contained in:
GinYuH committed 2024-01-08 19:27:03 -08:00
1 parent 8287b0a5d2
commit 4366fbc0ee
6 files changed
+430

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
using CalamityMod.Projectiles.Pets;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.Buffs.Pets
{
public class StarSwallowerPetBuff : ModBuff
{
public override void SetStaticDefaults()
{
Main.buffNoTimeDisplay[Type] = true;
Main.vanityPet[Type] = true;
}
public override void Update(Player player, ref int buffIndex)
{
player.buffTime[buffIndex] = 18000;
player.Calamity().starSwallowerPetFroge = true;
bool petProjectileNotSpawned = player.ownedProjectileCounts[ModContent.ProjectileType<StarSwallowerPet>()] <= 0;
if (petProjectileNotSpawned && player.whoAmI == Main.myPlayer)
{
Projectile.NewProjectile(player.GetSource_Buff(buffIndex), player.Center, Vector2.Zero, ModContent.ProjectileType<StarSwallowerPet>(), 0, 0f, player.whoAmI, 0f, 0f);
}
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 617 B

+40
View File
@@ -0,0 +1,40 @@
using CalamityMod.Buffs.Pets;
using CalamityMod.Projectiles.Pets;
using CalamityMod.Rarities;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Items.Pets
{
public class StarSwallowerUnit : ModItem, ILocalizedModType
{
public new string LocalizationCategory => "Items.Pets";
public override void SetDefaults()
{
Item.width = 42;
Item.height = 30;
Item.damage = 0;
Item.useAnimation = 20;
Item.useTime = 20;
Item.useStyle = ItemUseStyleID.Swing;
Item.noMelee = true;
Item.value = Item.sellPrice(gold: 1);
Item.rare = ModContent.RarityType<DarkOrange>();
Item.shoot = ModContent.ProjectileType<StarSwallowerPet>();
Item.buffType = ModContent.BuffType<StarSwallowerPetBuff>();
Item.UseSound = SoundID.Item10;
}
public override void UseStyle(Player player, Rectangle heldItemFrame)
{
if (player.whoAmI == Main.myPlayer && player.itemTime == 0)
{
player.AddBuff(Item.buffType, 15, true);
}
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 796 B

+363
View File
@@ -0,0 +1,363 @@
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using CalamityMod.CalPlayer;
namespace CalamityMod.Projectiles.Pets
{
public class StarSwallowerPet : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Pets";
private int playerStill = 0;
private bool idleAnimation = false;
private bool fly = false;
public override void SetStaticDefaults()
{
Main.projFrames[Projectile.type] = 8;
Main.projPet[Projectile.type] = true;
ProjectileID.Sets.CharacterPreviewAnimations[Projectile.type] = ProjectileID.Sets.SimpleLoop(1, 8, 6)
.WithOffset(-18f, 0f).WithSpriteDirection(1).WhenNotSelected(0, 0);
}
public override void SetDefaults()
{
Projectile.netImportant = true;
Projectile.width = 54;
Projectile.height = 48;
Projectile.friendly = true;
Projectile.penetrate = -1;
Projectile.timeLeft *= 5;
Projectile.tileCollide = true;
Projectile.ignoreWater = true;
}
public override bool PreDraw(ref Color lightColor)
{
/* Texture2D texture = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Pets/EidolonSnail").Value;
int height = texture.Height / Main.projFrames[Projectile.type];
int frameHeight = height * Projectile.frame;
SpriteEffects spriteEffects = Projectile.spriteDirection == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
Main.EntitySpriteDraw(texture, Projectile.Center - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY + 2),
new Microsoft.Xna.Framework.Rectangle?(new Rectangle(0, frameHeight, texture.Width, height)), lightColor,
Projectile.rotation, new Vector2(texture.Width / 2f, height / 2f), Projectile.scale, spriteEffects, 0);*/
return true;
}
public override void PostDraw(Color lightColor)
{
/* Texture2D texture = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Pets/EidolonSnailGlow").Value;
int height = texture.Height / Main.projFrames[Projectile.type];
int frameHeight = height * Projectile.frame;
SpriteEffects spriteEffects = Projectile.spriteDirection == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
Main.EntitySpriteDraw(texture, Projectile.Center - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY + 2),
new Microsoft.Xna.Framework.Rectangle?(new Rectangle(0, frameHeight, texture.Width, height)), Color.White,
Projectile.rotation, new Vector2(texture.Width / 2f, height / 2f), Projectile.scale, spriteEffects, 0);*/
}
public override bool TileCollideStyle(ref int width, ref int height, ref bool fallThrough, ref Vector2 hitboxCenterFrac)
{
Player player = Main.player[Projectile.owner];
Vector2 projCenter = Projectile.Center;
Vector2 playerDirection = player.Center - projCenter;
float playerDistance = playerDirection.Length();
fallThrough = playerDistance > 200f;
return true;
}
public override void AI()
{
Player player = Main.player[Projectile.owner];
if (!player.active)
{
Projectile.active = false;
return;
}
CalamityPlayer modPlayer = player.Calamity();
if (player.dead)
{
modPlayer.starSwallowerPetFroge = false;
}
if (modPlayer.starSwallowerPetFroge)
{
Projectile.timeLeft = 2;
}
Vector2 projPos = Projectile.position;
if (!fly)
{
Projectile.rotation = 0;
Vector2 projCenter = Projectile.Center;
Vector2 playerDirection = player.Center - projCenter;
float playerDistance = playerDirection.Length();
if (Projectile.velocity.Y == 0 && ((HoleBelow() && playerDistance > 150f) || (playerDistance > 150f && Projectile.position.X == Projectile.oldPosition.X)))
{
Projectile.velocity.Y = -8f;
}
Projectile.velocity.Y += 0.35f;
if (Projectile.velocity.Y > 15f)
{
Projectile.velocity.Y = 15f;
}
if (playerDistance > 520f)
{
fly = true;
Projectile.velocity.X = 0f;
Projectile.velocity.Y = 0f;
}
if (playerDistance > 100f)
{
if (player.position.X - Projectile.position.X > 0f)
{
Projectile.velocity.X += 0.12f;
if (Projectile.velocity.X > 6f)
{
Projectile.velocity.X = 6f;
}
}
else
{
Projectile.velocity.X -= 0.12f;
if (Projectile.velocity.X < -6f)
{
Projectile.velocity.X = -6f;
}
}
}
if (playerDistance < 100f)
{
if (Projectile.velocity.X != 0f)
{
if (Projectile.velocity.X > 0.8f)
{
Projectile.velocity.X -= 0.25f;
}
else if (Projectile.velocity.X < -0.8f)
{
Projectile.velocity.X += 0.25f;
}
else if (Projectile.velocity.X < 0.8f && Projectile.velocity.X > -0.8f)
{
Projectile.velocity.X = 0f;
}
}
}
if (playerDistance < 70f)
{
Projectile.velocity.X *= 0.5f;
}
//set frames when idle
if (Projectile.position.X == Projectile.oldPosition.X && Projectile.position.Y == Projectile.oldPosition.Y && Projectile.velocity.X == 0)
{
/*if (Main.rand.NextBool(200) && !idleAnimation)
{
idleAnimation = true;
}
if (idleAnimation)
{
Projectile.frameCounter++;
if (Projectile.frameCounter > 8)
{
Projectile.frame++;
Projectile.frameCounter = 0;
}
if (Projectile.frame > 4)
{
Projectile.frame = 0;
idleAnimation = false;
}
}
else
{
Projectile.frame = 0;
Projectile.frameCounter = 0;
}*/
Projectile.frame = 0;
}
//falling frame
else if (Projectile.velocity.Y > 0.3f && Projectile.position.Y != Projectile.oldPosition.Y)
{
Projectile.frame = 7;
Projectile.frameCounter = 0;
}
else if (Projectile.velocity.X != 0)
{
if (Projectile.frame < 4)
{
//Projectile.frame = 4;
}
//moving animation
Projectile.frameCounter++;
if (Projectile.frameCounter >= 6)
{
Projectile.frame++;
Projectile.frameCounter = 0;
}
if (Projectile.frame > 7)
{
Projectile.frame = 0;
}
}
if (Projectile.velocity.X > 0.8f)
{
Projectile.spriteDirection = -1;
}
else if (Projectile.velocity.X < -0.8f)
{
Projectile.spriteDirection = 1;
}
}
else if (fly)
{
float flySpeed = 0.5f;
Projectile.tileCollide = false;
Vector2 flyDirection = new Vector2(Projectile.position.X + (float)Projectile.width * 0.5f, Projectile.position.Y + (float)Projectile.height * 0.5f);
float horiPos = Main.player[Projectile.owner].position.X + (float)(Main.player[Projectile.owner].width / 2) - flyDirection.X;
float vertiPos = Main.player[Projectile.owner].position.Y + (float)(Main.player[Projectile.owner].height / 2) - flyDirection.Y;
vertiPos += (float)Main.rand.Next(-10, 21);
horiPos += (float)Main.rand.Next(-10, 21);
horiPos += (float)(60 * -(float)player.direction);
vertiPos -= 60f;
float playerDistance = (float)Math.Sqrt((double)(horiPos * horiPos + vertiPos * vertiPos));
if (playerDistance > 1200f)
{
Projectile.position.X = player.Center.X - (float)(Projectile.width / 2);
Projectile.position.Y = player.Center.Y - (float)(Projectile.height / 2);
Projectile.netUpdate = true;
}
if (playerDistance < 100f)
{
flySpeed = 0.5f;
if (player.velocity.Y == 0f)
{
++playerStill;
}
else
{
playerStill = 0;
}
if (playerStill > 10 && !Collision.SolidCollision(Projectile.position, Projectile.width, Projectile.height))
{
fly = false;
Projectile.velocity *= 0.2f;
Projectile.tileCollide = true;
}
}
if (playerDistance < 50f)
{
if (Math.Abs(Projectile.velocity.X) > 2f || Math.Abs(Projectile.velocity.Y) > 2f)
{
Projectile.velocity *= 0.90f;
}
flySpeed = 0.02f;
}
else
{
if (playerDistance < 100f)
{
flySpeed = 0.35f;
}
if (playerDistance > 300f)
{
flySpeed = 1f;
}
playerDistance = 18f / playerDistance;
horiPos *= playerDistance;
vertiPos *= playerDistance;
}
if (Projectile.velocity.X <= horiPos)
{
Projectile.velocity.X = Projectile.velocity.X + flySpeed;
if (flySpeed > 0.05f && Projectile.velocity.X < 0f)
{
Projectile.velocity.X = Projectile.velocity.X + flySpeed;
}
}
if (Projectile.velocity.X > horiPos)
{
Projectile.velocity.X = Projectile.velocity.X - flySpeed;
if (flySpeed > 0.05f && Projectile.velocity.X > 0f)
{
Projectile.velocity.X = Projectile.velocity.X - flySpeed;
}
}
if (Projectile.velocity.Y <= vertiPos)
{
Projectile.velocity.Y = Projectile.velocity.Y + flySpeed;
if (flySpeed > 0.05f && Projectile.velocity.Y < 0f)
{
Projectile.velocity.Y = Projectile.velocity.Y + flySpeed * 2f;
}
}
if (Projectile.velocity.Y > vertiPos)
{
Projectile.velocity.Y = Projectile.velocity.Y - flySpeed;
if (flySpeed > 0.05f && Projectile.velocity.Y > 0f)
{
Projectile.velocity.Y = Projectile.velocity.Y - flySpeed * 2f;
}
}
Projectile.rotation += (Math.Abs(Projectile.velocity.X) + Math.Abs(Projectile.velocity.Y)) * 0.01f * (float)Projectile.direction;
if (Projectile.Center.X < Main.player[Projectile.owner].Center.X)
{
Projectile.spriteDirection = -1;
}
else if (Projectile.Center.X > Main.player[Projectile.owner].Center.X)
{
Projectile.spriteDirection = 1;
}
//funny flying animation
Projectile.frame = 7;
/*Projectile.frameCounter++;
if (Projectile.frameCounter > 4)
{
Projectile.frame++;
Projectile.frameCounter = 0;
}
if (Projectile.frame > 11)
{
Projectile.frame = 9;
}*/
}
}
private bool HoleBelow()
{
int tileWidth = 4;
int tileX = (int)(Projectile.Center.X / 16f) - tileWidth;
if (Projectile.velocity.X > 0)
{
tileX += tileWidth;
}
int tileY = (int)((Projectile.position.Y + Projectile.height) / 16f);
for (int y = tileY; y < tileY + 2; y++)
{
for (int x = tileX; x < tileX + tileWidth; x++)
{
if (Main.tile[x, y].HasTile && (Main.tile[x - 1, y].HasTile || Main.tile[x + 1, y].HasTile))
{
return false;
}
}
}
return true;
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB