Skip to content

Commit

Permalink
Update the mod again so that big core lasers will have sounds in mult…
Browse files Browse the repository at this point in the history
…iplayer
  • Loading branch information
cheeeeeeeeeen committed Sep 26, 2021
1 parent 460730e commit 8282c7d
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 7 deletions.
57 changes: 55 additions & 2 deletions ChensGradiusMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,50 @@ public override void HandlePacket(BinaryReader reader, int whoAmI)
break;
}

case PacketMessageType.BroadcastSound:
SoundPacketType soundPacketType = (SoundPacketType)reader.ReadByte();
switch (soundPacketType)
{
case SoundPacketType.Vanilla:
{
ushort soundType = reader.ReadUInt16();
Vector2 soundPosition = reader.ReadVector2();
byte soundStyle = reader.ReadByte();

if (IsServer())
{
ModPacket packet = GetPacket();
packet.Write((byte)PacketMessageType.BroadcastSound);
packet.Write((byte)SoundPacketType.Vanilla);
packet.Write(soundType);
packet.WriteVector2(soundPosition);
packet.Write(soundStyle);
packet.Send();
}
else Main.PlaySound(soundType, soundPosition, soundStyle);
break;
}

case SoundPacketType.Legacy:
{
string customSound = reader.ReadString();
Vector2 soundPosition = reader.ReadVector2();

if (IsServer())
{
ModPacket packet = GetPacket();
packet.Write((byte)PacketMessageType.BroadcastSound);
packet.Write((byte)SoundPacketType.Legacy);
packet.Write(customSound);
packet.WriteVector2(soundPosition);
packet.Send();
}
else Main.PlaySound(GetLegacySoundSlot(SoundType.Custom, customSound), soundPosition);
break;
}
}
break;

case PacketMessageType.SpawnBoss:
Vector2 initialPosition = reader.ReadVector2();
if (IsServer())
Expand All @@ -460,11 +504,13 @@ public override void HandlePacket(BinaryReader reader, int whoAmI)
NPC npc = Main.npc[npcIndex];
NetMessage.BroadcastChatMessage(NetworkText.FromKey(Language.GetTextValue("Announcement.HasAwoken", npc.GivenOrTypeName)), new Color(175, 75, 255));
ModPacket packet = GetPacket();
packet.Write((byte)PacketMessageType.SpawnBoss);
packet.Write((byte)PacketMessageType.BroadcastSound);
packet.Write((byte)SoundPacketType.Vanilla);
packet.Write((ushort)SoundID.Roar);
packet.WriteVector2(initialPosition);
packet.Write((byte)0);
packet.Send();
}
else Main.PlaySound(SoundID.Roar, initialPosition, 0);
break;

case PacketMessageType.RecurveUpdatePositions:
Expand Down Expand Up @@ -533,9 +579,16 @@ internal enum PacketMessageType : byte
ClientChangesChargeMultiple,
SpawnRetaliationBullet,
ClientChangesSearchOption,
BroadcastSound,
SpawnBoss,
RecurveUpdatePositions,
ClientChangesTurretOption
};

internal enum SoundPacketType : byte
{
Vanilla,
Legacy
}
}
}
2 changes: 1 addition & 1 deletion ChensGradiusMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<TargetFramework>net45</TargetFramework>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<Version>1.2.2</Version>
<Version>1.2.3</Version>
</PropertyGroup>
<Target Name="BuildMod" AfterTargets="Build">
<Exec Command="&quot;$(tMLBuildServerPath)&quot; -build $(ProjectDir) -eac $(TargetPath) -define &quot;$(DefineConstants)&quot; -unsafe $(AllowUnsafeBlocks)" />
Expand Down
17 changes: 15 additions & 2 deletions NPCs/BigCoreCustom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using static ChensGradiusMod.ChensGradiusMod;
using static ChensGradiusMod.GradiusHelper;

namespace ChensGradiusMod.NPCs
Expand Down Expand Up @@ -255,8 +256,20 @@ private void PerformAttack()
Main.myPlayer);
}

Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/Enemies/BigCoreShoot"),
npc.Center);
if (IsServer())
{
ModPacket packet = mod.GetPacket();
packet.Write((byte)PacketMessageType.BroadcastSound);
packet.Write((byte)SoundPacketType.Legacy);
packet.Write("Sounds/Enemies/BigCoreShoot");
packet.WriteVector2(npc.Center);
packet.Send();
}
else
{
Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/Enemies/BigCoreShoot"),
npc.Center);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
displayName = Chen's Gradius Mod
author = blancfaye7
version = 1.2.2
version = 1.2.3
homepage = https://forums.terraria.org/index.php?threads/chens-gradius-mod.83289/
hideCode = true
hideResources = true
Expand Down
5 changes: 4 additions & 1 deletion forum.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Hello. I decided to share my mod here in the forums. I'm not very good at documenting, but it will improve as time passes. Without further ado...

[IMG]https://i.imgur.com/FKqzjlB.png[/IMG]
[B][U][SIZE=6]Mod Version: 1.2.2
[B][U][SIZE=6]Mod Version: 1.2.3
tModLoader: 0.11.8.5
The mod will be ported to tModLoader 1.4! Stay tuned![/SIZE][/U][/B]

Expand Down Expand Up @@ -251,6 +251,9 @@ For more information, visit this [URL=https://github.com/cheeeeeeeeeen/Chens-Gra
The content is moved because it's hard to maintain a Wiki and a main post! However, the latest version change will still be here.
Click [URL=https://github.com/cheeeeeeeeeen/Chens-Gradius-Mod/wiki/Changelog]here[/URL] for the full changelog.

1.2.3
- Fix Big Core's Laser sounds not being heard by clients on a dedicated server setup.

1.2.2
- Fix Big Core Custom spawning on dedicated servers as it does not work when clients use the spawner.
[/SPOILER]
Expand Down

0 comments on commit 8282c7d

Please sign in to comment.