Networking stuff for the Dune Wyrm.

Changed Crystal Skull and Red Hot Shackle's sprites
This commit is contained in:
FyloZ 2020-06-05 16:06:36 -04:00
parent 16b387b796
commit 15d2947c33
11 changed files with 153 additions and 81 deletions

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using Decimation.Content.NPCs.Arachnus;
using Decimation.Content.NPCs.DuneWyrm;
using Decimation.Content.NPCs.DuneWyrm.AncientTombCrawler;
using Decimation.Content.UI;
using Decimation.Lib.Util;
using Microsoft.Xna.Framework;
@ -15,8 +16,6 @@ namespace Decimation.Content
{
public class Decimation : Mod
{
public static Decimation Instance { set; get; }
public static AmuletSlotState amuletSlotState;
private UserInterface amuletSlotInterface;
@ -26,7 +25,7 @@ namespace Decimation.Content
{
Instance = this;
Properties = new ModProperties()
Properties = new ModProperties
{
Autoload = true,
AutoloadGores = true,
@ -36,6 +35,8 @@ namespace Decimation.Content
References.mod = this;
}
public static Decimation Instance { set; get; }
public override void Load()
{
if (!Main.dedServ)
@ -104,22 +105,11 @@ namespace Decimation.Content
public override void AddRecipeGroups()
{
RecipeGroup gems = new RecipeGroup(() => Lang.misc[37] + " Gem", new int[]
{
ItemID.Amethyst,
ItemID.Topaz,
ItemID.Emerald,
ItemID.Sapphire,
ItemID.Ruby,
ItemID.Diamond,
});
RecipeGroup gems = new RecipeGroup(() => Lang.misc[37] + " Gem", ItemID.Amethyst, ItemID.Topaz,
ItemID.Emerald, ItemID.Sapphire, ItemID.Ruby, ItemID.Diamond);
RecipeGroup threads = new RecipeGroup(() => Lang.misc[37] + " Thread", new int[]
{
ItemID.BlackThread,
ItemID.GreenThread,
ItemID.PinkThread
});
RecipeGroup threads = new RecipeGroup(() => Lang.misc[37] + " Thread", ItemID.BlackThread,
ItemID.GreenThread, ItemID.PinkThread);
RecipeGroup.RegisterGroup("AnyGem", gems);
RecipeGroup.RegisterGroup("AnyThread", threads);
@ -133,20 +123,15 @@ namespace Decimation.Content
{
case DecimationModMessageType.Arachnus:
Arachnus arachnus = (Arachnus) Main.npc[reader.ReadInt32()].modNPC;
if (arachnus != null && arachnus.npc.active)
{
arachnus.HandlePacket(reader);
}
if (arachnus != null && arachnus.npc.active) arachnus.HandlePacket(reader);
break;
case DecimationModMessageType.DuneWorm:
case DecimationModMessageType.DuneWyrm:
DuneWyrmHead duneWyrm = (DuneWyrmHead) Main.npc[reader.ReadInt32()].modNPC;
if (duneWyrm != null && duneWyrm.npc.active)
{
// TODO multiplayer
// duneWyrm.HandlePacket(reader);
}
if (duneWyrm != null && duneWyrm.npc.active) duneWyrm.HandlePacket(reader);
break;
case DecimationModMessageType.AncientTombCrawler:
AncientTombCrawler tombCrawler = (AncientTombCrawler) Main.npc[reader.ReadInt32()].modNPC;
if (tombCrawler != null && tombCrawler.npc.active) tombCrawler.HandlePacket(reader);
break;
case DecimationModMessageType.SpawnBoss:
int type = reader.ReadInt32();
@ -155,17 +140,15 @@ namespace Decimation.Content
if (Main.netMode != 1)
NPC.SpawnOnPlayer(player, type);
break;
default:
ErrorLogger.Log("DecimationMod: Unknown Message type: " + msgType);
break;
}
}
}
enum DecimationModMessageType : byte
internal enum DecimationModMessageType : byte
{
Arachnus,
DuneWorm,
DuneWyrm,
AncientTombCrawler,
SpawnBoss
}
}

View File

@ -15,11 +15,11 @@ namespace Decimation.Content.Items.Accessories
protected override void InitAccessory()
{
item.width = 24;
item.height = 24;
item.width = 35;
item.height = 22;
item.rare = Rarity.Green.GetRarityValue();
this.item.value = Item.buyPrice(0, 0, 0, 10);
this.item.defense = 2;
item.value = Item.buyPrice(0, 0, 0, 10);
item.defense = 2;
}
protected override List<ModRecipe> GetAdditionalRecipes()
@ -39,7 +39,5 @@ namespace Decimation.Content.Items.Accessories
player.AddBuff(BuffID.Thorns, 1);
Lighting.AddLight(player.Center, new Vector3(0.9f * 0.6f, 0.9f * 0.1f, 0.9f));
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 524 B

After

Width:  |  Height:  |  Size: 549 B

View File

@ -23,6 +23,7 @@ namespace Decimation.Content.Items.Accessories
item.value = Item.buyPrice(0, 0, 2);
item.defense = 1;
}
protected override List<ModRecipe> GetAdditionalRecipes()
{
ModRecipe recipe = GetNewModRecipe(this, 1, new List<int>() { TileID.Furnaces }, true);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 315 B

After

Width:  |  Height:  |  Size: 381 B

View File

@ -54,9 +54,9 @@ namespace Decimation.Content.NPCs.Arachnus
public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
{
npc.lifeMax = (int)(npc.lifeMax * 0.625f * bossLifeScale);
npc.damage = (int)(npc.damage * 0.6f);
npc.defense = (int)(npc.defense + numPlayers * 2);
npc.lifeMax = (int) (npc.lifeMax * 0.625f * bossLifeScale);
npc.damage = (int) (npc.damage * 0.6f);
npc.defense = (int) (npc.defense + numPlayers * 2);
}
private bool CheckDispawn()
@ -77,19 +77,20 @@ namespace Decimation.Content.NPCs.Arachnus
{
// Rotate to player
Vector2 moveTo = Main.player[npc.target].Center - npc.Center;
float angle = (float)Math.Atan2(moveTo.Y, moveTo.X);
npc.rotation = (float)(angle + Math.PI * 0.5f);
float angle = (float) Math.Atan2(moveTo.Y, moveTo.X);
npc.rotation = (float) (angle + Math.PI * 0.5f);
// Move
Vector2 move = moveTo;
float magnitude = (float)Math.Sqrt(move.X * move.X + move.Y * move.Y);
float magnitude = (float) Math.Sqrt(move.X * move.X + move.Y * move.Y);
if (magnitude > speed)
{
move *= speed / magnitude;
}
float turnResistance = 50f;
move = (npc.velocity * turnResistance + move) / (turnResistance + 1f);
magnitude = (float)Math.Sqrt(move.X * move.X + move.Y * move.Y);
magnitude = (float) Math.Sqrt(move.X * move.X + move.Y * move.Y);
if (magnitude > speed)
{
move *= speed / magnitude;
@ -104,17 +105,23 @@ namespace Decimation.Content.NPCs.Arachnus
if (counter % 60 == 0)
{
int validBlockCount = 0;
for (int i = (int)(-50 + npc.Center.X / 16f); i <= (int)(50 + npc.Center.X / 16f); i++)
for (int i = (int) (-50 + npc.Center.X / 16f); i <= (int) (50 + npc.Center.X / 16f); i++)
{
for (int j = (int)(-50 + npc.Center.Y / 16f); j <= (int)(50 + npc.Center.Y / 16f); j++)
for (int j = (int) (-50 + npc.Center.Y / 16f); j <= (int) (50 + npc.Center.Y / 16f); j++)
{
if (i >= 0 && i <= Main.maxTilesX && j >= 0 && j <= Main.maxTilesY)
{
if (Main.tile[i, j].type == ModContent.TileType<ShrineBrick>() || (Main.tile[i, j].type == ModContent.TileType<LockedShrineDoor>() || Main.tile[i, j].type == ModContent.TileType<ShrineDoorClosed>() || Main.tile[i, j].type == ModContent.TileType<ShrineDoorOpened>()) || Main.tile[i, j].type == ModContent.TileType<RedHotSpike>() || Main.tile[i, j].type == ModContent.TileType<ShrineAltar>())
if (Main.tile[i, j].type == ModContent.TileType<ShrineBrick>() ||
(Main.tile[i, j].type == ModContent.TileType<LockedShrineDoor>() ||
Main.tile[i, j].type == ModContent.TileType<ShrineDoorClosed>() ||
Main.tile[i, j].type == ModContent.TileType<ShrineDoorOpened>()) ||
Main.tile[i, j].type == ModContent.TileType<RedHotSpike>() ||
Main.tile[i, j].type == ModContent.TileType<ShrineAltar>())
validBlockCount++;
}
}
}
if (validBlockCount < 15)
tooFarFromShrine = true;
else
@ -130,7 +137,10 @@ namespace Decimation.Content.NPCs.Arachnus
private void CheckEnraged()
{
npc.ai[2] = !Main.player[npc.target].ZoneUnderworldHeight || !Collision.CanHit(npc.Center, 0, 0, Main.player[npc.target].Center, 0, 0) || CheckForShrine() ? 1 : 0;
npc.ai[2] = !Main.player[npc.target].ZoneUnderworldHeight ||
!Collision.CanHit(npc.Center, 0, 0, Main.player[npc.target].Center, 0, 0) || CheckForShrine()
? 1
: 0;
}
public override void AI()
@ -152,8 +162,8 @@ namespace Decimation.Content.NPCs.Arachnus
// Normal ai
if (npc.ai[0] == 0)
{
float mouthX = (float)(((npc.height) / 2) * Math.Cos(npc.rotation - Math.PI * 0.5f)) + npc.Center.X;
float mouthY = (float)(((npc.height) / 2) * Math.Sin(npc.rotation - Math.PI * 0.5f)) + npc.Center.Y;
float mouthX = (float) (((npc.height) / 2) * Math.Cos(npc.rotation - Math.PI * 0.5f)) + npc.Center.X;
float mouthY = (float) (((npc.height) / 2) * Math.Sin(npc.rotation - Math.PI * 0.5f)) + npc.Center.Y;
//Counter
if (npc.life <= npc.lifeMax / 2) counterMax = 1500;
@ -172,32 +182,39 @@ namespace Decimation.Content.NPCs.Arachnus
npc.ai[1] = 1;
}
// Increase speed
else if (counter > 1320 && counter <= 1500 || (Main.expertMode && counter > 600 && counter < 800 && npc.life <= npc.lifeMax / 4))
else if (counter > 1320 && counter <= 1500 ||
(Main.expertMode && counter > 600 && counter < 800 && npc.life <= npc.lifeMax / 4))
{
if (counter == 1321)
{
Main.PlaySound(SoundID.Roar, (int)npc.position.X, (int)npc.position.Y, 0);
if (Main.netMode == 2)
GetPacket(ArachnusMessageType.RoarSound).Send();
if (Main.netMode == NetmodeID.SinglePlayer)
Main.PlaySound(SoundID.Roar, (int) npc.position.X, (int) npc.position.Y, 0);
if (Main.netMode == NetmodeID.Server) GetPacket(ArachnusMessageType.RoarSound).Send();
}
npc.ai[1] = 2;
}
else npc.ai[1] = 99;
if (counter % 40 == 0 && npc.ai[1] == 0 && Main.netMode != 1)
{
float speedX = (float)(6 * Math.Cos(npc.rotation - Math.PI * 0.5f)) * 2;
float speedY = (float)(6 * Math.Sin(npc.rotation - Math.PI * 0.5f)) * 2;
Projectile.NewProjectile(new Vector2(mouthX, mouthY), new Vector2(speedX, speedY), ModContent.ProjectileType<ArachnusFireball>(), 30, 0f);
float speedX = (float) (6 * Math.Cos(npc.rotation - Math.PI * 0.5f)) * 2;
float speedY = (float) (6 * Math.Sin(npc.rotation - Math.PI * 0.5f)) * 2;
Projectile.NewProjectile(new Vector2(mouthX, mouthY), new Vector2(speedX, speedY),
ModContent.ProjectileType<ArachnusFireball>(), 30, 0f);
}
else if (counter % 5 == 0 && npc.ai[1] == 1)
{
if (Main.netMode != 1)
{
float speedX = (float)(7 * Math.Cos(npc.rotation - Math.PI * 0.5f));
float speedY = (float)(7 * Math.Sin(npc.rotation - Math.PI * 0.5f));
Projectile.NewProjectile(new Vector2(mouthX, mouthY), new Vector2(speedX, speedY), npc.ai[2] == 1 ? ModContent.ProjectileType<BlastofShadowFlame>() : ModContent.ProjectileType<BlastofHeat>(), 30, 0f, 255);
float speedX = (float) (7 * Math.Cos(npc.rotation - Math.PI * 0.5f));
float speedY = (float) (7 * Math.Sin(npc.rotation - Math.PI * 0.5f));
Projectile.NewProjectile(new Vector2(mouthX, mouthY), new Vector2(speedX, speedY),
npc.ai[2] == 1
? ModContent.ProjectileType<BlastofShadowFlame>()
: ModContent.ProjectileType<BlastofHeat>(), 30, 0f, 255);
}
Main.PlaySound(SoundID.Item34, npc.position);
if (Main.netMode == 2)
GetPacket(ArachnusMessageType.FlamesSound).Send();
@ -245,6 +262,7 @@ namespace Decimation.Content.NPCs.Arachnus
writer.Write(counterMax);
writer.Write(speed);
}
public override void ReceiveExtraAI(BinaryReader reader)
{
counter = reader.ReadInt32();
@ -255,18 +273,19 @@ namespace Decimation.Content.NPCs.Arachnus
private ModPacket GetPacket(ArachnusMessageType type)
{
ModPacket packet = mod.GetPacket();
packet.Write((byte)DecimationModMessageType.Arachnus);
packet.Write((byte) DecimationModMessageType.Arachnus);
packet.Write(npc.whoAmI);
packet.Write((byte)type);
packet.Write((byte) type);
return packet;
}
public void HandlePacket(BinaryReader reader)
{
ArachnusMessageType type = (ArachnusMessageType)reader.ReadByte();
ArachnusMessageType type = (ArachnusMessageType) reader.ReadByte();
switch (type)
{
case ArachnusMessageType.RoarSound:
Main.PlaySound(SoundID.Roar, (int)npc.position.X, (int)npc.position.Y, 0);
Main.PlaySound(SoundID.Roar, (int) npc.position.X, (int) npc.position.Y, 0);
break;
case ArachnusMessageType.FlamesSound:
Main.PlaySound(SoundID.Item34, npc.position);
@ -280,6 +299,7 @@ namespace Decimation.Content.NPCs.Arachnus
{
target.AddBuff(ModContent.BuffType<Hyperthermic>(), 900);
}
base.OnHitPlayer(target, damage, crit);
}
@ -288,7 +308,7 @@ namespace Decimation.Content.NPCs.Arachnus
npc.frameCounter += 3f;
if (npc.frameCounter >= 40)
npc.frameCounter = 0;
npc.frame.Y = ((int)npc.frameCounter / 10) * frameHeight;
npc.frame.Y = ((int) npc.frameCounter / 10) * frameHeight;
}
public override void NPCLoot()
@ -356,4 +376,4 @@ namespace Decimation.Content.NPCs.Arachnus
FlamesSound
}
}
}
}

View File

@ -1,3 +1,4 @@
using System.IO;
using Decimation.Content.Items.Misc.Souls;
using Decimation.Lib.NPCs;
using Microsoft.Xna.Framework;
@ -142,5 +143,35 @@ namespace Decimation.Content.NPCs.DuneWyrm.AncientTombCrawler
npc.HitSound = SoundID.NPCHit1;
undergroundSound = mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/Custom/Earthquake");
}
protected override void SendSoundPacket()
{
GetPacket(AncientTombCrawlerMessageType.UndergroundSound).Send();
}
private ModPacket GetPacket(AncientTombCrawlerMessageType type)
{
ModPacket packet = mod.GetPacket();
packet.Write((byte) DecimationModMessageType.AncientTombCrawler);
packet.Write(npc.whoAmI);
packet.Write((byte) type);
return packet;
}
public void HandlePacket(BinaryReader reader)
{
AncientTombCrawlerMessageType type = (AncientTombCrawlerMessageType) reader.ReadByte();
switch (type)
{
case AncientTombCrawlerMessageType.UndergroundSound:
Main.PlaySound(undergroundSound, npc.Center);
break;
}
}
}
public enum AncientTombCrawlerMessageType
{
UndergroundSound
}
}

View File

@ -15,7 +15,6 @@ namespace Decimation.Content.NPCs.DuneWyrm
[AutoloadBossHead]
internal class DuneWyrmHead : DuneWyrm
{
private int _attackCounter;
private int _previousTile = -1;
private bool _spawnedAncientTombCrawler;
@ -65,12 +64,14 @@ namespace Decimation.Content.NPCs.DuneWyrm
public override void SendExtraAI(BinaryWriter writer)
{
writer.Write(_attackCounter);
writer.Write(_previousTile);
writer.Write(_spawnedAncientTombCrawler);
}
public override void ReceiveExtraAI(BinaryReader reader)
{
_attackCounter = reader.ReadInt32();
_previousTile = reader.ReadInt32();
_spawnedAncientTombCrawler = reader.ReadBoolean();
}
public override void CustomBehavior()
@ -289,5 +290,35 @@ namespace Decimation.Content.NPCs.DuneWyrm
npc.HitSound = SoundID.NPCHit1;
undergroundSound = mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/Custom/Earthquake");
}
protected override void SendSoundPacket()
{
GetPacket(DuneWyrmMessageType.UndergroundSound).Send();
}
private ModPacket GetPacket(DuneWyrmMessageType type)
{
ModPacket packet = mod.GetPacket();
packet.Write((byte) DecimationModMessageType.DuneWyrm);
packet.Write(npc.whoAmI);
packet.Write((byte) type);
return packet;
}
public void HandlePacket(BinaryReader reader)
{
DuneWyrmMessageType type = (DuneWyrmMessageType) reader.ReadByte();
switch (type)
{
case DuneWyrmMessageType.UndergroundSound:
Main.PlaySound(undergroundSound, npc.Center);
break;
}
}
}
public enum DuneWyrmMessageType
{
UndergroundSound
}
}

View File

@ -6,12 +6,12 @@ namespace Decimation.Content.Projectiles
{
protected override void Init()
{
this.projectile.CloneDefaults(ProjectileID.SpikyBall);
this.projectile.damage = 30;
this.projectile.width = 10;
this.projectile.height = 16;
this.projectile.friendly = false;
this.projectile.hostile = true;
projectile.CloneDefaults(ProjectileID.SpikyBall);
projectile.damage = 30;
projectile.width = 36;
projectile.height = 32;
projectile.friendly = false;
projectile.hostile = true;
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 375 B

After

Width:  |  Height:  |  Size: 534 B

View File

@ -3,6 +3,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.Audio;
using Terraria.ID;
using Terraria.ModLoader;
namespace Decimation.Lib.NPCs
@ -233,8 +234,13 @@ namespace Decimation.Lib.NPCs
{
if (!flies && npc.behindTiles && npc.soundDelay == 0)
{
npc.soundDelay = 120;
Main.PlaySound(undergroundSound, npc.position);
if (Main.netMode != NetmodeID.MultiplayerClient)
{
npc.soundDelay = 120;
Main.PlaySound(undergroundSound, npc.position);
if(Main.netMode == NetmodeID.Server) SendSoundPacket();
}
}
num193 = (float) Math.Sqrt(num191 * num191 + num192 * num192);
@ -440,5 +446,7 @@ namespace Decimation.Lib.NPCs
0f
);
}
protected abstract void SendSoundPacket();
}
}