106 lines
3.0 KiB
C#
106 lines
3.0 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using Terraria;
|
|
using Terraria.ModLoader;
|
|
using Terraria.ModLoader.IO;
|
|
using Microsoft.Xna.Framework;
|
|
|
|
namespace ForgottenWawiTech
|
|
{
|
|
public class WorldDefeatedBosses : ModSystem
|
|
{
|
|
public static bool Niko;
|
|
public static bool Lyyka;
|
|
public static bool Neptune;
|
|
public static bool Lexy;
|
|
public static bool Terra;
|
|
public static bool Clara;
|
|
public static bool Raccoon;
|
|
|
|
public override void OnWorldUnload()
|
|
{
|
|
Niko = Lyyka = Neptune = Lexy = Terra = Clara = Raccoon = false;
|
|
}
|
|
|
|
public override void SaveWorldData(TagCompound tag)
|
|
{
|
|
var list = new List<string>();
|
|
if (Niko) list.Add("Niko");
|
|
if (Lyyka) list.Add("Lyyka");
|
|
if (Neptune) list.Add("Neptune");
|
|
if (Lexy) list.Add("Lexy");
|
|
if (Terra) list.Add("Terra");
|
|
if (Clara) list.Add("Clara");
|
|
if (Raccoon) list.Add("Raccoon");
|
|
|
|
tag["ForgottenWawiTech_DefeatedBosses"] = list;
|
|
}
|
|
|
|
public override void LoadWorldData(TagCompound tag)
|
|
{
|
|
if (tag.TryGet<List<string>>("ForgottenWawiTech_DefeatedBosses", out var list))
|
|
{
|
|
Niko = list.Contains("Niko");
|
|
Lyyka = list.Contains("Lyyka");
|
|
Neptune = list.Contains("Neptune");
|
|
Lexy = list.Contains("Lexy");
|
|
Terra = list.Contains("Terra");
|
|
Clara = list.Contains("Clara");
|
|
Raccoon = list.Contains("Raccoon");
|
|
}
|
|
else
|
|
{
|
|
Niko = Lyyka = Neptune = Lexy = Terra = Clara = Raccoon = false;
|
|
}
|
|
}
|
|
|
|
public override void NetSend(BinaryWriter writer)
|
|
{
|
|
var flags = new BitsByte(
|
|
Niko,
|
|
Lyyka,
|
|
Neptune,
|
|
Lexy,
|
|
Terra,
|
|
Clara,
|
|
Raccoon
|
|
);
|
|
writer.Write((byte)flags);
|
|
}
|
|
|
|
public override void NetReceive(BinaryReader reader)
|
|
{
|
|
BitsByte flags = reader.ReadByte();
|
|
Niko = flags[0];
|
|
Lyyka = flags[1];
|
|
Neptune = flags[2];
|
|
Lexy = flags[3];
|
|
Terra = flags[4];
|
|
Clara = flags[5];
|
|
Raccoon = flags[6];
|
|
}
|
|
|
|
// Immediate network sync helper to broadcast current flags to clients.
|
|
public static void Sync(Mod mod)
|
|
{
|
|
if (mod == null)
|
|
return;
|
|
|
|
var flags = new BitsByte(
|
|
Niko,
|
|
Lyyka,
|
|
Neptune,
|
|
Lexy,
|
|
Terra,
|
|
Clara,
|
|
Raccoon
|
|
);
|
|
|
|
ModPacket packet = mod.GetPacket();
|
|
packet.Write((byte)0); // message type 0 = sync world defeated bosses
|
|
packet.Write((byte)flags);
|
|
packet.Send();
|
|
}
|
|
}
|
|
}
|