EntitySpecific Done, Replaced OldDuke packet to SpawnBossOnPosition
This commit is contained in:
1 parent
b59688ff50
commit
fd6674a52d
11 files changed
+365
-96
No files matched your search
+33
-61
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@@ -68,6 +69,9 @@ namespace CalamityMod
|
||||
{
|
||||
foreach (var packetHandler in _PacketRegistry ?? Enumerable.Empty<CalamityPacket>())
|
||||
{
|
||||
if (packetHandler is null)
|
||||
continue;
|
||||
|
||||
packetHandler.OnUnloaded();
|
||||
packetHandler._Prop_Static_Instance?.SetValue(null, null);
|
||||
packetHandler._Prop_Static_Instance = null;
|
||||
@@ -107,66 +111,6 @@ namespace CalamityMod
|
||||
Main.player[reader.ReadInt32()].Calamity().HandleCooldownDictionary(reader);
|
||||
break;
|
||||
|
||||
//
|
||||
// Syncs for specific bosses or entities
|
||||
//
|
||||
case CalamityModMessageType.SyncAndroombaSolution:
|
||||
int index = reader.ReadInt32();
|
||||
int solType = reader.ReadInt32();
|
||||
if (Main.netMode != NetmodeID.MultiplayerClient)
|
||||
AndroombaFriendly.SwapSolution(index, solType);
|
||||
break;
|
||||
|
||||
case CalamityModMessageType.SyncAndroombaAI:
|
||||
{
|
||||
int idx = reader.ReadInt32();
|
||||
int phase = reader.ReadInt32();
|
||||
if (Main.netMode != NetmodeID.MultiplayerClient)
|
||||
AndroombaFriendly.ChangeAI(idx, phase);
|
||||
}
|
||||
break;
|
||||
|
||||
case CalamityModMessageType.SyncSlabCrabAI:
|
||||
{
|
||||
int idx = reader.ReadInt32();
|
||||
int phase = reader.ReadInt32();
|
||||
if (Main.netMode != NetmodeID.MultiplayerClient)
|
||||
AndroombaFriendly.ChangeAI(idx, phase);
|
||||
}
|
||||
break;
|
||||
|
||||
case CalamityModMessageType.PlaceAltCritter:
|
||||
{
|
||||
int placerplayer = reader.ReadInt32();
|
||||
int posX = reader.ReadInt32();
|
||||
int posY = reader.ReadInt32();
|
||||
int type = reader.ReadInt32();
|
||||
int itemType = reader.ReadInt32();
|
||||
float color = reader.ReadInt32();
|
||||
if (Main.netMode != NetmodeID.MultiplayerClient)
|
||||
{
|
||||
int n = NPC.NewNPC(Main.player[placerplayer].GetSource_ReleaseEntity(), posX, posY, type, ai1: color);
|
||||
Main.npc[n].catchItem = itemType;
|
||||
Main.npc[n].releaseOwner = (short)placerplayer;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CalamityModMessageType.ServersideSpawnOldDuke:
|
||||
byte playerIndex2 = reader.ReadByte();
|
||||
CalamityUtils.SpawnOldDuke(playerIndex2);
|
||||
break;
|
||||
|
||||
case CalamityModMessageType.ProvidenceDyeConditionSync:
|
||||
byte npcIndex3 = reader.ReadByte();
|
||||
(Main.npc[npcIndex3].ModNPC as Providence).hasTakenDaytimeDamage = reader.ReadBoolean();
|
||||
break;
|
||||
|
||||
case CalamityModMessageType.PSCChallengeSync:
|
||||
byte npcIndex4 = reader.ReadByte();
|
||||
(Main.npc[npcIndex4].ModNPC as Providence).challenge = reader.ReadBoolean();
|
||||
break;
|
||||
|
||||
//
|
||||
// Tile Entities
|
||||
//
|
||||
@@ -355,6 +299,34 @@ namespace CalamityMod
|
||||
NetMessage.SendData(MessageID.WorldData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shorthand for NetMessage.SendData(MessageID.SyncNPC)
|
||||
/// </summary>
|
||||
public static void SyncNPC(NPC npcToSync, int toClient = -1, int ignoreClient = -1)
|
||||
{
|
||||
if (Main.netMode == NetmodeID.SinglePlayer)
|
||||
return;
|
||||
|
||||
if (npcToSync is null)
|
||||
return;
|
||||
|
||||
NetMessage.SendData(MessageID.SyncNPC, toClient, ignoreClient, null, npcToSync.whoAmI);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shorthand for NetMessage.SendData(MessageID.SyncNPC)
|
||||
/// </summary>
|
||||
public static void SyncNPC(int npcWhoAmI, int toClient = -1, int ignoreClient = -1)
|
||||
{
|
||||
if (Main.netMode == NetmodeID.SinglePlayer)
|
||||
return;
|
||||
|
||||
if (npcWhoAmI < 0 || npcWhoAmI >= Main.maxNPCs)
|
||||
return;
|
||||
|
||||
NetMessage.SendData(MessageID.SyncNPC, toClient, ignoreClient, null, npcWhoAmI);
|
||||
}
|
||||
|
||||
public static void SyncCalamityWorldDifficulties(int sender)
|
||||
{
|
||||
if (Main.netMode == NetmodeID.SinglePlayer)
|
||||
@@ -408,12 +380,12 @@ namespace CalamityMod
|
||||
SyncAndroombaAI,
|
||||
SyncSlabCrabAI,
|
||||
PlaceAltCritter,
|
||||
ServersideSpawnOldDuke,
|
||||
ProvidenceDyeConditionSync, // TODO -- this packetstorms if you hit Provi with spam weapons. It should ONLY send a packet if the status changes.
|
||||
PSCChallengeSync, // TODO -- once you've failed the PSC challenge this packetstorms
|
||||
|
||||
// General things for entities
|
||||
SpawnNPCOnPlayer,
|
||||
SpawnBossOnPosition,
|
||||
SyncNPCMotionDataToServer,
|
||||
SyncNPCPosAndRotOnly,
|
||||
|
||||
|
||||
+22
-22
@@ -82,6 +82,7 @@ using Terraria.UI.Chat;
|
||||
using Terraria.Utilities;
|
||||
using static Terraria.ModLoader.ModContent;
|
||||
using CalamityMod.NPCs.SunkenSea;
|
||||
using CalamityMod.Packets;
|
||||
|
||||
namespace CalamityMod.NPCs
|
||||
{
|
||||
@@ -8326,33 +8327,32 @@ namespace CalamityMod.NPCs
|
||||
// has an owner, hence the MyPlayer check.
|
||||
if (Main.myPlayer == projectile.owner)
|
||||
{
|
||||
if (!player.active || player.dead)
|
||||
return;
|
||||
|
||||
Projectile proj = null;
|
||||
foreach (Projectile p in Main.ActiveProjectiles)
|
||||
{
|
||||
proj = p;
|
||||
if (p.bobber && p.owner == player.whoAmI)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (proj is null)
|
||||
return;
|
||||
|
||||
var spawnPosX = (int)proj.Center.X;
|
||||
var spawnPosY = (int)proj.Center.Y + 100;
|
||||
if (Main.netMode == NetmodeID.SinglePlayer)
|
||||
{
|
||||
if (!player.active || player.dead)
|
||||
return;
|
||||
|
||||
Projectile proj = null;
|
||||
foreach (Projectile p in Main.ActiveProjectiles)
|
||||
{
|
||||
proj = p;
|
||||
if (p.bobber && p.owner == player.whoAmI)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (proj is null)
|
||||
return;
|
||||
|
||||
int oldDuke = NPC.NewNPC(NPC.GetBossSpawnSource(player.whoAmI), (int)proj.Center.X, (int)proj.Center.Y + 100, NPCType<OldDuke.OldDuke>());
|
||||
int oldDuke = NPC.NewNPC(NPC.GetBossSpawnSource(player.whoAmI), spawnPosX, spawnPosY, NPCType<OldDuke.OldDuke>());
|
||||
CalamityUtils.BossAwakenMessage(oldDuke);
|
||||
}
|
||||
else
|
||||
else if (Main.netMode == NetmodeID.MultiplayerClient)
|
||||
{
|
||||
var netMessage = CalamityMod.Instance.GetPacket();
|
||||
netMessage.Write((byte)CalamityModMessageType.ServersideSpawnOldDuke);
|
||||
netMessage.Write((byte)player.whoAmI);
|
||||
netMessage.Send();
|
||||
SpawnBossOnPositionPacket.Send(spawnPosX, spawnPosY, NPCType<OldDuke.OldDuke>(), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Terraria;
|
||||
using Terraria.DataStructures;
|
||||
using Terraria.ID;
|
||||
|
||||
namespace CalamityMod.Packets
|
||||
{
|
||||
public sealed class SpawnBossOnPositionPacket : CalamityPacket
|
||||
{
|
||||
public static SpawnBossOnPositionPacket Instance { get; private set; }
|
||||
|
||||
public override byte MessageType => (byte)CalamityModMessageType.SpawnBossOnPosition;
|
||||
|
||||
public static void Send(int x, int y, int npcType, Player target = null, int toClient = -1, int ignoreClient = -1)
|
||||
{
|
||||
var packet = Instance.CreateBasePacket();
|
||||
packet.Write(x);
|
||||
packet.Write(y);
|
||||
packet.Write(npcType);
|
||||
packet.Write((byte)(target?.whoAmI ?? byte.MaxValue));
|
||||
packet.Send(toClient, ignoreClient);
|
||||
}
|
||||
|
||||
public override void HandlePacket(in BinaryReader packet, int sender)
|
||||
{
|
||||
var x = packet.ReadInt32();
|
||||
var y = packet.ReadInt32();
|
||||
var npcType = packet.ReadInt32();
|
||||
var target = packet.ReadPlayer();
|
||||
var targetIndex = target?.whoAmI ?? 255;
|
||||
|
||||
if (!Main.dedServ)
|
||||
return;
|
||||
|
||||
int spawnedNPCIdx = NPC.NewNPC(NPC.GetBossSpawnSource(targetIndex), x, y, npcType, Start: 1);
|
||||
if (spawnedNPCIdx >= Main.maxNPCs)
|
||||
return;
|
||||
|
||||
NPC npc = Main.npc[spawnedNPCIdx];
|
||||
npc.timeLeft *= 20;
|
||||
npc.target = targetIndex;
|
||||
|
||||
CalamityUtils.BossAwakenMessage(spawnedNPCIdx);
|
||||
CalamityNetcode.SyncNPC(npc);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,10 @@ namespace CalamityMod.Packets
|
||||
if (Main.dedServ)
|
||||
{
|
||||
int spawnedNPC = NPC.NewNPC(new EntitySource_WorldEvent(), x, y, npcType, Target: player.whoAmI);
|
||||
NetMessage.SendData(MessageID.SyncNPC, -1, player.whoAmI, null, spawnedNPC);
|
||||
if (spawnedNPC >= Main.maxNPCs)
|
||||
return;
|
||||
|
||||
CalamityNetcode.SyncNPC(spawnedNPC);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CalamityMod.Packets
|
||||
{
|
||||
public sealed class CooldownAdditionPacket : CalamityPacket
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CalamityMod.NPCs.Providence;
|
||||
|
||||
namespace CalamityMod.Packets
|
||||
{
|
||||
public sealed class PSCChallengeSyncPacket : CalamityPacket
|
||||
{
|
||||
public static PSCChallengeSyncPacket Instance { get; private set; }
|
||||
|
||||
public override byte MessageType => (byte)CalamityModMessageType.PSCChallengeSync;
|
||||
|
||||
public static void Send(Providence providence, int toClient = -1, int ignoreClient = -1)
|
||||
{
|
||||
if (providence is null)
|
||||
return;
|
||||
|
||||
var packet = Instance.CreateBasePacket();
|
||||
packet.WriteWhoAmI(providence.NPC);
|
||||
packet.Write(providence.challenge);
|
||||
packet.Send(toClient, ignoreClient);
|
||||
}
|
||||
|
||||
public override void HandlePacket(in BinaryReader packet, int sender)
|
||||
{
|
||||
var providence = packet.ReadModNPC<Providence>();
|
||||
var challenge = packet.ReadBoolean();
|
||||
|
||||
if (providence is null)
|
||||
return;
|
||||
|
||||
providence.challenge = challenge;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Terraria.ID;
|
||||
using Terraria;
|
||||
|
||||
namespace CalamityMod.Packets
|
||||
{
|
||||
public sealed class PlaceAltCritterPacket : CalamityPacket
|
||||
{
|
||||
public static PlaceAltCritterPacket Instance { get; private set; }
|
||||
|
||||
public override byte MessageType => (byte)CalamityModMessageType.PlaceAltCritter;
|
||||
|
||||
/// <summary>
|
||||
/// Same Method, but uses critterItem.makeNPC and critterItem.type for shorthanded call
|
||||
/// </summary>
|
||||
public static void Send(Player placer, int x, int y, Item critterItem, int colorType, int toClient = -1, int ignoreClient = -1)
|
||||
{
|
||||
Send(placer, x, y, critterItem.makeNPC, critterItem.type, colorType, toClient, ignoreClient);
|
||||
}
|
||||
|
||||
public static void Send(Player placer, int x, int y, int critterNPCType, int itemType, int colorType, int toClient = -1, int ignoreClient = -1)
|
||||
{
|
||||
var packet = Instance.CreateBasePacket();
|
||||
packet.WriteWhoAmI(placer);
|
||||
packet.Write(x);
|
||||
packet.Write(y);
|
||||
packet.Write(critterNPCType);
|
||||
packet.Write(itemType);
|
||||
packet.Write(colorType);
|
||||
packet.Send(toClient, ignoreClient);
|
||||
}
|
||||
|
||||
public override void HandlePacket(in BinaryReader packet, int sender)
|
||||
{
|
||||
var placerplayer = packet.ReadPlayer();
|
||||
int posX = packet.ReadInt32();
|
||||
int posY = packet.ReadInt32();
|
||||
int type = packet.ReadInt32();
|
||||
int itemType = packet.ReadInt32();
|
||||
float color = packet.ReadInt32();
|
||||
if (Main.dedServ && placerplayer is not null)
|
||||
{
|
||||
int newNPCIndex = NPC.NewNPC(placerplayer.GetSource_ReleaseEntity(), posX, posY, type, ai1: color);
|
||||
if (newNPCIndex >= Main.maxNPCs)
|
||||
return;
|
||||
|
||||
var npc = Main.npc[newNPCIndex];
|
||||
npc.catchItem = itemType;
|
||||
npc.releaseOwner = (short)placerplayer.whoAmI;
|
||||
CalamityNetcode.SyncNPC(npc); // releaseOwner should be synced in here
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CalamityMod.NPCs.Providence;
|
||||
|
||||
namespace CalamityMod.Packets
|
||||
{
|
||||
public sealed class ProvidenceDyeConditionSyncPacket : CalamityPacket
|
||||
{
|
||||
public static ProvidenceDyeConditionSyncPacket Instance { get; private set; }
|
||||
|
||||
public override byte MessageType => (byte)CalamityModMessageType.ProvidenceDyeConditionSync;
|
||||
|
||||
public static void Send(Providence providence, int toClient = -1, int ignoreClient = -1)
|
||||
{
|
||||
if (providence is null)
|
||||
return;
|
||||
|
||||
var packet = Instance.CreateBasePacket();
|
||||
packet.WriteWhoAmI(providence.NPC);
|
||||
packet.Write(providence.hasTakenDaytimeDamage);
|
||||
packet.Send(toClient, ignoreClient);
|
||||
}
|
||||
|
||||
public override void HandlePacket(in BinaryReader packet, int sender)
|
||||
{
|
||||
var providence = packet.ReadModNPC<Providence>();
|
||||
var hasTakenDaytimeDmg = packet.ReadBoolean();
|
||||
|
||||
if (providence is null)
|
||||
return;
|
||||
|
||||
providence.hasTakenDaytimeDamage = hasTakenDaytimeDmg;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CalamityMod.NPCs.DraedonLabThings;
|
||||
using CalamityMod.NPCs.TownNPCs;
|
||||
using Microsoft.Build.Execution;
|
||||
using Terraria;
|
||||
|
||||
namespace CalamityMod.Packets
|
||||
{
|
||||
public sealed class SyncAndroombaAIPacket : CalamityPacket
|
||||
{
|
||||
public static SyncAndroombaAIPacket Instance { get; private set; }
|
||||
|
||||
public override byte MessageType => (byte)CalamityModMessageType.SyncAndroombaAI;
|
||||
|
||||
public static void Send(AndroombaFriendly roomba, int toClient = -1, int ignoreClient = -1)
|
||||
{
|
||||
var packet = Instance.CreateBasePacket();
|
||||
packet.WriteWhoAmI(roomba.NPC);
|
||||
packet.Write((int)roomba.NPC.ai[0]); // Phase
|
||||
packet.Send(toClient, ignoreClient);
|
||||
}
|
||||
|
||||
public override void HandlePacket(in BinaryReader packet, int sender)
|
||||
{
|
||||
var roomba = packet.ReadModNPC<AndroombaFriendly>();
|
||||
var phase = packet.ReadInt32();
|
||||
|
||||
if (roomba is null)
|
||||
return;
|
||||
|
||||
if (Main.dedServ)
|
||||
AndroombaFriendly.ChangeAI(roomba.NPC.whoAmI, phase);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CalamityMod.NPCs.TownNPCs;
|
||||
using Terraria;
|
||||
|
||||
namespace CalamityMod.Packets
|
||||
{
|
||||
public sealed class SyncAndroombaSolutionPacket : CalamityPacket
|
||||
{
|
||||
public static SyncAndroombaSolutionPacket Instance { get; private set; }
|
||||
|
||||
public override byte MessageType => (byte)CalamityModMessageType.SyncAndroombaSolution;
|
||||
|
||||
public static void Send(AndroombaFriendly roomba, int toClient = -1, int ignoreClient = -1)
|
||||
{
|
||||
var packet = Instance.CreateBasePacket();
|
||||
packet.WriteWhoAmI(roomba.NPC);
|
||||
packet.Write((int)roomba.NPC.ai[3]); // Solution
|
||||
}
|
||||
|
||||
public override void HandlePacket(in BinaryReader packet, int sender)
|
||||
{
|
||||
var roomba = packet.ReadModNPC<AndroombaFriendly>();
|
||||
var solution = packet.ReadInt32();
|
||||
|
||||
if (roomba is null)
|
||||
return;
|
||||
|
||||
if (Main.dedServ)
|
||||
AndroombaFriendly.SwapSolution(roomba.NPC.whoAmI, solution);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CalamityMod.NPCs.Abyss;
|
||||
using CalamityMod.NPCs.TownNPCs;
|
||||
using Terraria;
|
||||
|
||||
namespace CalamityMod.Packets
|
||||
{
|
||||
public sealed class SyncSlabCrabAIPacket : CalamityPacket
|
||||
{
|
||||
public static SyncSlabCrabAIPacket Instance { get; private set; }
|
||||
|
||||
public override byte MessageType => (byte)CalamityModMessageType.SyncSlabCrabAI;
|
||||
|
||||
public static void Send(SlabCrab crab, int toClient = -1, int ignoreClient = -1)
|
||||
{
|
||||
var packet = Instance.CreateBasePacket();
|
||||
packet.WriteWhoAmI(crab.NPC);
|
||||
packet.Write((int)crab.NPC.ai[0]); // Phase
|
||||
packet.Send(toClient, ignoreClient);
|
||||
}
|
||||
|
||||
public override void HandlePacket(in BinaryReader packet, int sender)
|
||||
{
|
||||
var crab = packet.ReadModNPC<SlabCrab>();
|
||||
var phase = packet.ReadInt32();
|
||||
|
||||
if (crab is null)
|
||||
return;
|
||||
|
||||
if (Main.dedServ)
|
||||
crab.ChangePhase(phase);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user