fix: Fixes gauntlet spawner and map item deserialization (#1170)

This commit is contained in:
Kamron Batman 2022-09-13 18:20:10 -07:00 committed by GitHub
parent 4499c8397d
commit fe94aa050a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 71 additions and 65 deletions

View file

@ -84,63 +84,10 @@ namespace Server.Engines.Doom
get => m_State;
set
{
if (m_State == value)
if (m_State != value)
{
return;
}
m_State = value;
var hue = 0;
var lockDoors = m_State == GauntletSpawnerState.InProgress;
hue = m_State switch
{
GauntletSpawnerState.InSequence => InSequenceItemHue,
GauntletSpawnerState.InProgress => InProgressItemHue,
GauntletSpawnerState.Completed => CompletedItemHue,
_ => hue
};
if (Door != null)
{
Door.Hue = hue;
Door.Locked = lockDoors;
if (lockDoors)
{
Door.KeyValue = Key.RandomValue();
Door.Open = false;
}
if (Door.Link != null)
{
Door.Link.Hue = hue;
Door.Link.Locked = lockDoors;
if (lockDoors)
{
Door.Link.KeyValue = Key.RandomValue();
Door.Open = false;
}
}
}
if (Addon != null)
{
Addon.Hue = hue;
}
if (m_State == GauntletSpawnerState.InProgress)
{
CreateRegion();
FullSpawn();
Timer.StartTimer(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0), Slice, out _timerToken);
}
else
{
Stop();
m_State = value;
Update();
}
}
}
@ -151,6 +98,64 @@ namespace Server.Engines.Doom
public Region Region { get; set; }
private void Update(bool shouldSpawn = true)
{
var lockDoors = m_State == GauntletSpawnerState.InProgress;
var hue = m_State switch
{
GauntletSpawnerState.InSequence => InSequenceItemHue,
GauntletSpawnerState.InProgress => InProgressItemHue,
GauntletSpawnerState.Completed => CompletedItemHue,
_ => 0
};
if (Door != null)
{
Door.Hue = hue;
Door.Locked = lockDoors;
if (lockDoors)
{
Door.KeyValue = Key.RandomValue();
Door.Open = false;
}
if (Door.Link != null)
{
Door.Link.Hue = hue;
Door.Link.Locked = lockDoors;
if (lockDoors)
{
Door.Link.KeyValue = Key.RandomValue();
Door.Open = false;
}
}
}
if (Addon != null)
{
Addon.Hue = hue;
}
if (m_State == GauntletSpawnerState.InProgress)
{
CreateRegion();
if (shouldSpawn)
{
FullSpawn();
}
Timer.StartTimer(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0), Slice, out _timerToken);
}
else
{
Stop();
}
}
public override string DefaultName => "doom spawner";
public virtual void CreateRegion()
@ -222,11 +227,9 @@ namespace Server.Engines.Doom
return;
}
BaseTrap trap;
var random = Utility.Random(100);
trap = random switch
BaseTrap trap = random switch
{
< 22 => new SawTrap(Utility.RandomBool() ? SawTrapType.WestFloor : SawTrapType.NorthFloor),
< 44 => new SpikeTrap(Utility.RandomBool() ? SpikeTrapType.WestFloor : SpikeTrapType.NorthFloor),
@ -446,11 +449,13 @@ namespace Server.Engines.Doom
Addon = reader.ReadEntity<BaseAddon>();
Sequence = reader.ReadEntity<GauntletSpawner>();
State = (GauntletSpawnerState)reader.ReadInt();
m_State = (GauntletSpawnerState)reader.ReadInt();
break;
}
}
Timer.DelayCall(() => Update(false));
}
}
}

View file

@ -284,17 +284,18 @@ public partial class MapItem : Item, ICraftable
{
// Version 0 doesn't serialize Facet/Editable, and count is not encoded
Bounds = reader.ReadRect2D();
_bounds = reader.ReadRect2D();
Width = reader.ReadInt();
Height = reader.ReadInt();
_width = reader.ReadInt();
_height = reader.ReadInt();
Protected = reader.ReadBool();
_protected = reader.ReadBool();
var count = reader.ReadInt();
_pins = new List<Point2D>(count);
for (var i = 0; i < count; i++)
{
Pins.Add(reader.ReadPoint2D());
_pins.Add(reader.ReadPoint2D());
}
}
}