Reorganizes Project (#41)

This commit is contained in:
Kamron Batman 2019-08-02 18:13:40 -07:00 committed by GitHub
parent 08bf44af9a
commit 3614a66aee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3499 changed files with 79 additions and 55 deletions

View file

@ -0,0 +1,650 @@
using System;
using System.Collections.Generic;
using Server.Commands;
using Server.Items;
using Server.Mobiles;
using Server.Regions;
namespace Server.Engines.Doom
{
public enum GauntletSpawnerState
{
InSequence,
InProgress,
Completed
}
public class GauntletSpawner : Item
{
public const int PlayersPerSpawn = 5;
public const int InSequenceItemHue = 0x000;
public const int InProgressItemHue = 0x676;
public const int CompletedItemHue = 0x455;
private GauntletSpawnerState m_State;
private Timer m_Timer;
[Constructible]
public GauntletSpawner(string typeName = null) : base(0x36FE)
{
Visible = false;
Movable = false;
TypeName = typeName;
Creatures = new List<Mobile>();
Traps = new List<BaseTrap>();
}
public GauntletSpawner(Serial serial) : base(serial)
{
}
[CommandProperty(AccessLevel.GameMaster)]
public string TypeName{ get; set; }
[CommandProperty(AccessLevel.GameMaster)]
public BaseDoor Door{ get; set; }
[CommandProperty(AccessLevel.GameMaster)]
public BaseAddon Addon{ get; set; }
[CommandProperty(AccessLevel.GameMaster)]
public GauntletSpawner Sequence{ get; set; }
[CommandProperty(AccessLevel.GameMaster)]
public bool HasCompleted
{
get
{
if (Creatures.Count == 0)
return false;
for (int i = 0; i < Creatures.Count; ++i)
{
Mobile mob = Creatures[i];
if (!mob.Deleted)
return false;
}
return true;
}
}
[CommandProperty(AccessLevel.GameMaster)]
public Rectangle2D RegionBounds{ get; set; }
[CommandProperty(AccessLevel.GameMaster)]
public GauntletSpawnerState State
{
get => m_State;
set
{
if (m_State == value)
return;
m_State = value;
int hue = 0;
bool lockDoors = m_State == GauntletSpawnerState.InProgress;
switch (m_State)
{
case GauntletSpawnerState.InSequence:
hue = InSequenceItemHue;
break;
case GauntletSpawnerState.InProgress:
hue = InProgressItemHue;
break;
case GauntletSpawnerState.Completed:
hue = CompletedItemHue;
break;
}
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();
m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0), Slice);
}
else
{
ClearCreatures();
ClearTraps();
DestroyRegion();
m_Timer?.Stop();
m_Timer = null;
}
}
}
public List<Mobile> Creatures{ get; set; }
public List<BaseTrap> Traps{ get; set; }
public Region Region{ get; set; }
public override string DefaultName => "doom spawner";
public virtual void CreateRegion()
{
if (Region != null)
return;
Map map = Map;
if (map == null || map == Map.Internal)
return;
Region = new GauntletRegion(this, map);
}
public virtual void DestroyRegion()
{
Region?.Unregister();
Region = null;
}
public virtual int ComputeTrapCount()
{
int area = RegionBounds.Width * RegionBounds.Height;
return area / 100;
}
public virtual void ClearTraps()
{
for (int i = 0; i < Traps.Count; ++i)
Traps[i].Delete();
Traps.Clear();
}
public virtual void SpawnTrap()
{
Map map = Map;
if (map == null)
return;
BaseTrap trap;
int random = Utility.Random(100);
if (22 > random)
trap = new SawTrap(Utility.RandomBool() ? SawTrapType.WestFloor : SawTrapType.NorthFloor);
else if (44 > random)
trap = new SpikeTrap(Utility.RandomBool() ? SpikeTrapType.WestFloor : SpikeTrapType.NorthFloor);
else if (66 > random)
trap = new GasTrap(Utility.RandomBool() ? GasTrapType.NorthWall : GasTrapType.WestWall);
else if (88 > random)
trap = new FireColumnTrap();
else
trap = new MushroomTrap();
if (trap is FireColumnTrap || trap is MushroomTrap)
trap.Hue = 0x451;
// try 10 times to find a valid location
for (int i = 0; i < 10; ++i)
{
int x = Utility.Random(RegionBounds.X, RegionBounds.Width);
int y = Utility.Random(RegionBounds.Y, RegionBounds.Height);
int z = Z;
if (!map.CanFit(x, y, z, 16, false, false))
z = map.GetAverageZ(x, y);
if (!map.CanFit(x, y, z, 16, false, false))
continue;
trap.MoveToWorld(new Point3D(x, y, z), map);
Traps.Add(trap);
return;
}
trap.Delete();
}
public virtual int ComputeSpawnCount()
{
int playerCount = 0;
Map map = Map;
if (map != null)
{
Point3D loc = GetWorldLocation();
Region reg = Region.Find(loc, map).GetRegion("Doom Gauntlet");
if (reg != null)
playerCount = reg.GetPlayerCount();
}
if (playerCount == 0 && Region != null)
playerCount = Region.GetPlayerCount();
int count = (playerCount + PlayersPerSpawn - 1) / PlayersPerSpawn;
if (count < 1)
count = 1;
return count;
}
public virtual void ClearCreatures()
{
for (int i = 0; i < Creatures.Count; ++i)
Creatures[i].Delete();
Creatures.Clear();
}
public virtual void FullSpawn()
{
ClearCreatures();
int count = ComputeSpawnCount();
for (int i = 0; i < count; ++i)
Spawn();
ClearTraps();
count = ComputeTrapCount();
for (int i = 0; i < count; ++i)
SpawnTrap();
}
public virtual void Spawn()
{
try
{
if (TypeName == null)
return;
Type type = ScriptCompiler.FindTypeByName(TypeName, true);
if (type == null)
return;
object obj = Activator.CreateInstance(type);
if (obj is Item item)
{
item.Delete();
}
else if (obj is Mobile mob)
{
mob.MoveToWorld(GetWorldLocation(), Map);
Creatures.Add(mob);
}
}
catch
{
// ignored
}
}
public virtual void RecurseReset()
{
if (m_State != GauntletSpawnerState.InSequence)
{
State = GauntletSpawnerState.InSequence;
if (Sequence?.Deleted == false)
Sequence.RecurseReset();
}
}
public virtual void Slice()
{
if (m_State != GauntletSpawnerState.InProgress)
return;
int count = ComputeSpawnCount();
for (int i = Creatures.Count; i < count; ++i)
Spawn();
if (HasCompleted)
{
State = GauntletSpawnerState.Completed;
if (Sequence?.Deleted == false)
{
if (Sequence.State == GauntletSpawnerState.Completed)
RecurseReset();
Sequence.State = GauntletSpawnerState.InProgress;
}
}
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write(1); // version
writer.Write(RegionBounds);
writer.WriteItemList(Traps, false);
writer.Write(Creatures, false);
writer.Write(TypeName);
writer.WriteItem(Door);
writer.WriteItem(Addon);
writer.WriteItem(Sequence);
writer.Write((int)m_State);
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
switch (version)
{
case 1:
{
RegionBounds = reader.ReadRect2D();
Traps = reader.ReadStrongItemList<BaseTrap>();
goto case 0;
}
case 0:
{
if (version < 1)
{
Traps = new List<BaseTrap>();
RegionBounds = new Rectangle2D(X - 40, Y - 40, 80, 80);
}
Creatures = reader.ReadStrongMobileList();
TypeName = reader.ReadString();
Door = reader.ReadItem<BaseDoor>();
Addon = reader.ReadItem<BaseAddon>();
Sequence = reader.ReadItem<GauntletSpawner>();
State = (GauntletSpawnerState)reader.ReadInt();
break;
}
}
}
public static void Initialize()
{
CommandSystem.Register("GenGauntlet", AccessLevel.Administrator, GenGauntlet_OnCommand);
}
public static void CreateTeleporter(int xFrom, int yFrom, int xTo, int yTo)
{
Static telePad = new Static(0x1822);
Teleporter teleItem = new Teleporter(new Point3D(xTo, yTo, -1), Map.Malas);
telePad.Hue = 0x482;
telePad.MoveToWorld(new Point3D(xFrom, yFrom, -1), Map.Malas);
teleItem.MoveToWorld(new Point3D(xFrom, yFrom, -1), Map.Malas);
teleItem.SourceEffect = true;
teleItem.DestEffect = true;
teleItem.SoundID = 0x1FE;
}
public static BaseDoor CreateDoorSet(int xDoor, int yDoor, bool doorEastToWest, int hue)
{
BaseDoor hiDoor = new MetalDoor(doorEastToWest ? DoorFacing.NorthCCW : DoorFacing.WestCW);
BaseDoor loDoor = new MetalDoor(doorEastToWest ? DoorFacing.SouthCW : DoorFacing.EastCCW);
hiDoor.MoveToWorld(new Point3D(xDoor, yDoor, -1), Map.Malas);
loDoor.MoveToWorld(new Point3D(xDoor + (doorEastToWest ? 0 : 1), yDoor + (doorEastToWest ? 1 : 0), -1),
Map.Malas);
hiDoor.Link = loDoor;
loDoor.Link = hiDoor;
hiDoor.Hue = hue;
loDoor.Hue = hue;
return hiDoor;
}
public static GauntletSpawner CreateSpawner(string typeName, int xSpawner, int ySpawner, int xDoor, int yDoor,
int xPentagram, int yPentagram, bool doorEastToWest, int xStart, int yStart, int xWidth, int yHeight)
{
GauntletSpawner spawner = new GauntletSpawner(typeName);
spawner.MoveToWorld(new Point3D(xSpawner, ySpawner, -1), Map.Malas);
if (xDoor > 0 && yDoor > 0)
spawner.Door = CreateDoorSet(xDoor, yDoor, doorEastToWest, 0);
spawner.RegionBounds = new Rectangle2D(xStart, yStart, xWidth, yHeight);
if (xPentagram > 0 && yPentagram > 0)
{
PentagramAddon pentagram = new PentagramAddon();
pentagram.MoveToWorld(new Point3D(xPentagram, yPentagram, -1), Map.Malas);
spawner.Addon = pentagram;
}
return spawner;
}
public static void CreatePricedHealer(int price, int x, int y)
{
PricedHealer healer = new PricedHealer(price);
healer.MoveToWorld(new Point3D(x, y, -1), Map.Malas);
healer.Home = healer.Location;
healer.RangeHome = 5;
}
public static void CreateMorphItem(int x, int y, int inactiveItemID, int activeItemID, int range, int hue)
{
MorphItem item = new MorphItem(inactiveItemID, activeItemID, range);
item.Hue = hue;
item.MoveToWorld(new Point3D(x, y, -1), Map.Malas);
}
public static void CreateVarietyDealer(int x, int y)
{
VarietyDealer dealer = new VarietyDealer();
/* Begin outfit */
dealer.Name = "Nix";
dealer.Title = "the Variety Dealer";
dealer.Body = 400;
dealer.Female = false;
dealer.Hue = 0x8835;
List<Item> items = new List<Item>(dealer.Items);
for (int i = 0; i < items.Count; ++i)
{
Item item = items[i];
if (item.Layer != Layer.ShopBuy && item.Layer != Layer.ShopResale && item.Layer != Layer.ShopSell)
item.Delete();
}
dealer.HairItemID = 0x2049; // Pig Tails
dealer.HairHue = 0x482;
dealer.FacialHairItemID = 0x203E;
dealer.FacialHairHue = 0x482;
dealer.AddItem(new FloppyHat(1));
dealer.AddItem(new Robe(1));
dealer.AddItem(new LanternOfSouls());
dealer.AddItem(new Sandals(0x482));
/* End outfit */
dealer.MoveToWorld(new Point3D(x, y, -1), Map.Malas);
dealer.Home = dealer.Location;
dealer.RangeHome = 2;
}
public static void GenGauntlet_OnCommand(CommandEventArgs e)
{
/* Begin healer room */
CreatePricedHealer(5000, 387, 400);
CreateTeleporter(390, 407, 394, 405);
BaseDoor healerDoor = CreateDoorSet(393, 404, true, 0x44E);
healerDoor.Locked = true;
healerDoor.KeyValue = Key.RandomValue();
if (healerDoor.Link != null)
{
healerDoor.Link.Locked = true;
healerDoor.Link.KeyValue = Key.RandomValue();
}
/* End healer room */
/* Begin supply room */
CreateMorphItem(433, 371, 0x29F, 0x116, 3, 0x44E);
CreateMorphItem(433, 372, 0x29F, 0x115, 3, 0x44E);
CreateVarietyDealer(492, 369);
for (int x = 434; x <= 478; ++x)
for (int y = 371; y <= 372; ++y)
{
Static item = new Static(0x524);
item.Hue = 1;
item.MoveToWorld(new Point3D(x, y, -1), Map.Malas);
}
/* End supply room */
/* Begin gauntlet cycle */
CreateTeleporter(471, 428, 474, 428);
CreateTeleporter(462, 494, 462, 498);
CreateTeleporter(403, 502, 399, 506);
CreateTeleporter(357, 476, 356, 480);
CreateTeleporter(361, 433, 357, 434);
GauntletSpawner sp1 = CreateSpawner("DarknightCreeper", 491, 456, 473, 432, 417, 426, true, 473, 412, 39, 60);
GauntletSpawner sp2 = CreateSpawner("FleshRenderer", 482, 520, 468, 496, 426, 422, false, 448, 496, 56, 48);
GauntletSpawner sp3 = CreateSpawner("Impaler", 406, 538, 408, 504, 432, 430, false, 376, 504, 64, 48);
GauntletSpawner sp4 = CreateSpawner("ShadowKnight", 335, 512, 360, 478, 424, 439, false, 300, 478, 72, 64);
GauntletSpawner sp5 = CreateSpawner("AbysmalHorror", 326, 433, 360, 429, 416, 435, true, 300, 408, 60, 56);
GauntletSpawner sp6 = CreateSpawner("DemonKnight", 423, 430, 0, 0, 423, 430, true, 392, 392, 72, 96);
sp1.Sequence = sp2;
sp2.Sequence = sp3;
sp3.Sequence = sp4;
sp4.Sequence = sp5;
sp5.Sequence = sp6;
sp6.Sequence = sp1;
sp1.State = GauntletSpawnerState.InProgress;
/* End gauntlet cycle */
/* Begin exit gate */
ConfirmationMoongate gate = new ConfirmationMoongate();
gate.Dispellable = false;
gate.Target = new Point3D(2350, 1270, -85);
gate.TargetMap = Map.Malas;
gate.GumpWidth = 420;
gate.GumpHeight = 280;
gate.MessageColor = 0x7F00;
gate.MessageNumber = 1062109; // You are about to exit Dungeon Doom. Do you wish to continue?
gate.TitleColor = 0x7800;
gate.TitleNumber = 1062108; // Please verify...
gate.Hue = 0x44E;
gate.MoveToWorld(new Point3D(433, 326, 4), Map.Malas);
/* End exit gate */
}
}
public class GauntletRegion : BaseRegion
{
private GauntletSpawner m_Spawner;
public GauntletRegion(GauntletSpawner spawner, Map map)
: base(null, map, Find(spawner.Location, spawner.Map), spawner.RegionBounds)
{
m_Spawner = spawner;
GoLocation = spawner.Location;
Register();
}
public override void AlterLightLevel(Mobile m, ref int global, ref int personal)
{
global = 12;
}
public override void OnEnter(Mobile m)
{
}
public override void OnExit(Mobile m)
{
}
}
}

View file

@ -0,0 +1,641 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Server.Commands;
using Server.Mobiles;
using Server.Network;
using Server.Spells;
/*
this is From me to you, Under no terms, Conditions... K? to apply you
just simply Unpatch/delete, Stick these in, Same location.. Restart
*/
namespace Server.Engines.Doom
{
public class LeverPuzzleController : Item
{
private static bool installed;
public static string[] Msgs =
{
"You are pinned down by the weight of the boulder!!!", // 0
"A speeding rock hits you in the head!", // 1
"OUCH!" // 2
};
/* font&hue for above msgs. index matches */
public static int[][] MsgParams =
{
new[] { 0x66d, 3 },
new[] { 0x66d, 3 },
new[] { 0x34, 3 }
};
/* World data for items */
public static int[][] TA =
{
new[] { 316, 64, 5 }, /* 3D Coords for levers */
new[] { 323, 58, 5 },
new[] { 332, 63, 5 },
new[] { 323, 71, 5 },
new[] { 324, 64 }, /* 2D Coords for standing regions */
new[] { 316, 65 },
new[] { 324, 58 },
new[] { 332, 64 },
new[] { 323, 72 },
new[] { 468, 92, -1 }, new[] { 0x181D, 0x482 }, /* 3D coord, itemid+hue for L.R. teles */
new[] { 469, 92, -1 }, new[] { 0x1821, 0x3fd },
new[] { 470, 92, -1 }, new[] { 0x1825, 0x66d },
new[] { 319, 70, 18 }, new[] { 0x12d8 }, /* 3D coord, itemid for statues */
new[] { 329, 60, 18 }, new[] { 0x12d9 },
new[] { 469, 96, 6 } /* 3D Coords for Fake Box */
};
/* CLILOC data for statue "correct souls" messages */
public static int[] Statue_Msg = { 1050009, 1050007, 1050008, 1050008 };
/* Exit & Enter locations for the lamp room */
public static Point3D lr_Exit = new Point3D(353, 172, -1);
public static Point3D lr_Enter = new Point3D(467, 96, -1);
/* "Center" location in puzzle */
public static Point3D lp_Center = new Point3D(324, 64, -1);
/* Lamp Room Area */
public static Rectangle2D lr_Rect = new Rectangle2D(465, 92, 10, 10);
/* Lamp Room area Poison message data */
public static int[][] PA =
{
new[] { 0, 0, 0xA6 },
new[] { 1050001, 0x485, 0xAA },
new[] { 1050003, 0x485, 0xAC },
new[] { 1050056, 0x485, 0xA8 },
new[] { 1050057, 0x485, 0xA4 },
new[] { 1062091, 0x23F3, 0xAC }
};
public static Poison[] PA2 =
{
Poison.Lesser,
Poison.Regular,
Poison.Greater,
Poison.Deadly,
Poison.Lethal,
Poison.Lethal
};
/* SOUNDS */
private static int[] fs = { 0x144, 0x154 };
private static int[] ms = { 0x144, 0x14B };
private static int[] fs2 = { 0x13F, 0x154 };
private static int[] ms2 = { 0x13F, 0x14B };
private static int[] cs1 = { 0x244 };
private static int[] exp = { 0x307 };
private Timer l_Timer;
private LampRoomBox m_Box;
private Region m_LampRoom;
private List<Item> m_Levers;
private List<Item> m_Statues;
private List<Item> m_Teles;
private List<LeverPuzzleRegion> m_Tiles;
private Timer m_Timer;
public LeverPuzzleController() : base(0x1822)
{
Movable = false;
Hue = 0x4c;
installed = true;
int i = 0;
m_Levers = new List<Item>(); /* codes are 0x1 shifted left x # of bits, easily handled here */
for (; i < 4; i++)
m_Levers.Add(AddLeverPuzzlePart(TA[i], new LeverPuzzleLever((ushort)(1 << i), this)));
m_Tiles = new List<LeverPuzzleRegion>();
for (; i < 9; i++)
m_Tiles.Add(new LeverPuzzleRegion(this, TA[i]));
m_Teles = new List<Item>();
for (; i < 15; i++)
m_Teles.Add(AddLeverPuzzlePart(TA[i], new LampRoomTeleporter(TA[++i])));
m_Statues = new List<Item>();
for (; i < 19; i++)
m_Statues.Add(AddLeverPuzzlePart(TA[i], new LeverPuzzleStatue(TA[++i], this)));
if (!installed)
Delete();
else
Enabled = true;
m_Box = (LampRoomBox)AddLeverPuzzlePart(TA[i], new LampRoomBox(this));
m_LampRoom = new LampRoomRegion(this);
GenKey();
}
public LeverPuzzleController(Serial serial) : base(serial)
{
}
[CommandProperty(AccessLevel.GameMaster)]
public ushort MyKey{ get; set; }
[CommandProperty(AccessLevel.GameMaster)]
public ushort TheirKey{ get; set; }
[CommandProperty(AccessLevel.GameMaster)]
public bool Enabled{ get; set; }
public Mobile Successful{ get; private set; }
public bool CircleComplete
{
get /* OSI: all 5 must be occupied */
{
for (int i = 0; i < 5; i++)
if (GetOccupant(i) == null)
return false;
return true;
}
}
public static void Initialize()
{
CommandSystem.Register("GenLeverPuzzle", AccessLevel.Administrator, GenLampPuzzle_OnCommand);
}
[Usage("GenLeverPuzzle")]
[Description("Generates lamp room and lever puzzle in doom.")]
public static void GenLampPuzzle_OnCommand(CommandEventArgs e)
{
if (Map.Malas.GetItemsInRange(lp_Center, 0).OfType<LeverPuzzleController>().Any())
{
e.Mobile.SendMessage("Lamp room puzzle already exists: please delete the existing controller first ...");
return;
}
e.Mobile.SendMessage("Generating Lamp Room puzzle...");
new LeverPuzzleController().MoveToWorld(lp_Center, Map.Malas);
if (!installed)
e.Mobile.SendMessage("There was a problem generating the puzzle.");
else
e.Mobile.SendMessage("Lamp room puzzle successfully generated.");
}
public static Item AddLeverPuzzlePart(int[] Loc, Item newitem)
{
if (newitem?.Deleted != false)
installed = false;
else
newitem.MoveToWorld(new Point3D(Loc[0], Loc[1], Loc[2]), Map.Malas);
return newitem;
}
public override void OnDelete()
{
KillTimers();
base.OnDelete();
}
public override void OnAfterDelete()
{
NukeItemList(m_Teles);
NukeItemList(m_Statues);
NukeItemList(m_Levers);
m_LampRoom?.Unregister();
if (m_Tiles != null)
foreach (LeverPuzzleRegion region in m_Tiles)
region.Unregister();
if (m_Box?.Deleted == false)
m_Box.Delete();
}
public static void NukeItemList(List<Item> list)
{
if (list?.Count > 0)
foreach (Item item in list)
if (item?.Deleted == false)
item.Delete();
}
public virtual PlayerMobile GetOccupant(int index)
{
LeverPuzzleRegion region = m_Tiles[index];
if (region?.Occupant != null && region.Occupant.Alive) return (PlayerMobile)region.Occupant;
return null;
}
public virtual LeverPuzzleStatue GetStatue(int index)
{
LeverPuzzleStatue statue = (LeverPuzzleStatue)m_Statues[index];
return statue?.Deleted == false ? statue : null;
}
public virtual LeverPuzzleLever GetLever(int index)
{
LeverPuzzleLever lever = (LeverPuzzleLever)m_Levers[index];
return lever?.Deleted == false ? lever : null;
}
public virtual void PuzzleStatus(int message, string fstring = null)
{
for (int i = 0; i < 2; i++)
{
Item s;
if ((s = GetStatue(i)) != null)
s.PublicOverheadMessage(MessageType.Regular, 0x3B2, message, fstring);
}
}
public virtual void ResetPuzzle()
{
PuzzleStatus(1062053);
ResetLevers();
}
public virtual void ResetLevers()
{
for (int i = 0; i < 4; i++)
{
Item l;
if ((l = GetLever(i)) != null)
{
l.ItemID = 0x108E;
Effects.PlaySound(l.Location, Map, 0x3E8);
}
}
TheirKey ^= TheirKey;
}
public virtual void KillTimers()
{
if (l_Timer?.Running == true) l_Timer.Stop();
if (m_Timer?.Running == true) m_Timer.Stop();
}
public virtual void RemoveSuccessful()
{
Successful = null;
}
public virtual void LeverPulled(ushort code)
{
int correct = 0;
KillTimers();
/* if one bit in each of the four nibbles is set, this is false */
if ((TheirKey = (ushort)(code | (TheirKey <<= 4))) < 0x0FFF)
{
l_Timer = Timer.DelayCall(TimeSpan.FromSeconds(30.0), ResetPuzzle);
return;
}
if (!CircleComplete)
{
PuzzleStatus(1050004); // The circle is the key...
}
else
{
Mobile player;
if (TheirKey == MyKey)
{
GenKey();
if ((Successful = player = GetOccupant(0)) != null)
{
SendLocationEffect(lp_Center, 0x1153, 0, 60, 1);
PlaySounds(lp_Center, cs1);
Effects.SendBoltEffect(player, true);
player.MoveToWorld(lr_Enter, Map.Malas);
m_Timer = new LampRoomTimer(this);
m_Timer.Start();
Enabled = false;
}
}
else
{
for (int i = 0; i < 16; i++) /* Count matching SET bits, ie correct codes */
if (((MyKey >> i) & 1) == 1 && ((TheirKey >> i) & 1) == 1)
correct++;
PuzzleStatus(Statue_Msg[correct], correct > 0 ? correct.ToString() : null);
for (int i = 0; i < 5; i++)
if ((player = GetOccupant(i)) != null)
new RockTimer(player, this).Start();
}
}
ResetLevers();
}
public virtual void GenKey() /* Shuffle & build key */
{
ushort[] CA = { 1, 2, 4, 8 };
for (int i = 0; i < 4; i++)
{
int n = (n = Utility.Random(0, 3)) == i ? n & ~i : n;
ushort tmp = CA[i];
CA[i] = CA[n];
CA[n] = tmp;
}
for (int i = 0; i < 4; MyKey = (ushort)(CA[i++] | (MyKey <<= 4)))
{
}
}
private static bool IsValidDamagable(Mobile m)
{
return m?.Deleted == false &&
(m.Player && m.Alive ||
m is BaseCreature bc && (bc.Controlled || bc.Summoned) && !bc.IsDeadBondedPet);
}
public static void MoveMobileOut(Mobile m)
{
if (m != null)
{
if (m is PlayerMobile && !m.Alive)
if (m.Corpse?.Deleted == false)
m.Corpse.MoveToWorld(lr_Exit, Map.Malas);
BaseCreature.TeleportPets(m, lr_Exit, Map.Malas);
m.Location = lr_Exit;
m.ProcessDelta();
}
}
public static bool AniSafe(Mobile m)
{
return m?.BodyMod == 0 && m.Alive && !TransformationSpellHelper.UnderTransformation(m);
}
public static IEntity ZAdjustedIEFromMobile(Mobile m, int ZDelta)
{
return new Entity(Serial.Zero, new Point3D(m.X, m.Y, m.Z + ZDelta), m.Map);
}
public static void DoDamage(Mobile m, int min, int max, bool poison)
{
if (m?.Deleted == false && m.Alive)
{
int damage = Utility.Random(min, max);
AOS.Damage(m, damage, poison ? 0 : 100, 0, 0, poison ? 100 : 0, 0);
}
}
public static Point3D RandomPointIn(Point3D point, int range)
{
return RandomPointIn(point.X - range, point.Y - range, range * 2, range * 2, point.Z);
}
public static Point3D RandomPointIn(Rectangle2D rect, int z)
{
return RandomPointIn(rect.X, rect.Y, rect.Height, rect.Width, z);
}
public static Point3D RandomPointIn(int x, int y, int x2, int y2, int z)
{
return new Point3D(Utility.Random(x, x2), Utility.Random(y, y2), z);
}
public static void PlaySounds(Point3D location, int[] sounds)
{
foreach (int soundid in sounds)
Effects.PlaySound(location, Map.Malas, soundid);
}
public static void PlayEffect(IEntity from, IEntity to, int itemid, int speed, bool explodes)
{
Effects.SendMovingParticles(from, to, itemid, speed, 0, true, explodes, 2, 0, 0);
}
public static void SendLocationEffect(IPoint3D p, int itemID, int speed, int duration, int hue)
{
Effects.SendPacket(p, Map.Malas, new LocationEffect(p, itemID, speed, duration, hue, 0));
}
public static void PlayerSendASCII(Mobile player, int index)
{
player.Send(new AsciiMessage(Serial.MinusOne, 0xFFFF, MessageType.Label, MsgParams[index][0],
MsgParams[index][1], null, Msgs[index]));
}
/* I cant find any better way to send "speech" using fonts other than default */
public static void POHMessage(Mobile from, int index)
{
Packet p = new AsciiMessage(from.Serial, from.Body, MessageType.Regular, MsgParams[index][0],
MsgParams[index][1], from.Name, Msgs[index]);
p.Acquire();
foreach (NetState state in from.Map.GetClientsInRange(from.Location))
state.Send(p);
Packet.Release(p);
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write(0); // version
writer.WriteItemList(m_Levers, true);
writer.WriteItemList(m_Statues, true);
writer.WriteItemList(m_Teles, true);
writer.Write(m_Box);
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
m_Levers = reader.ReadStrongItemList();
m_Statues = reader.ReadStrongItemList();
m_Teles = reader.ReadStrongItemList();
m_Box = reader.ReadItem() as LampRoomBox;
m_Tiles = new List<LeverPuzzleRegion>();
for (int i = 4; i < 9; i++)
m_Tiles.Add(new LeverPuzzleRegion(this, TA[i]));
m_LampRoom = new LampRoomRegion(this);
Enabled = true;
TheirKey = 0;
MyKey = 0;
GenKey();
}
public class RockTimer : Timer
{
private int Count;
private LeverPuzzleController m_Controller;
private Mobile m_Player;
public RockTimer(Mobile player, LeverPuzzleController Controller)
: base(TimeSpan.Zero, TimeSpan.FromSeconds(.25))
{
Count = 0;
m_Player = player;
m_Controller = Controller;
}
private int Rock()
{
return 0x1363 + Utility.Random(0, 11);
}
protected override void OnTick()
{
if (m_Player == null || m_Player.Map != Map.Malas)
{
Stop();
}
else
{
Count++;
if (Count == 1) /* TODO consolidate */
{
m_Player.Paralyze(TimeSpan.FromSeconds(2));
Effects.SendTargetEffect(m_Player, 0x11B7, 20, 10);
PlayerSendASCII(m_Player, 0); // You are pinned down ...
PlaySounds(m_Player.Location, !m_Player.Female ? fs : ms);
PlayEffect(ZAdjustedIEFromMobile(m_Player, 50), m_Player, 0x11B7, 20, false);
}
else if (Count == 2)
{
DoDamage(m_Player, 80, 90, false);
Effects.SendTargetEffect(m_Player, 0x36BD, 20, 10);
PlaySounds(m_Player.Location, exp);
PlayerSendASCII(m_Player, 1); // A speeding rock ...
if (AniSafe(m_Player)) m_Player.Animate(21, 10, 1, true, true, 0);
}
else if (Count == 3)
{
Stop();
Effects.SendTargetEffect(m_Player, 0x36B0, 20, 10);
PlayerSendASCII(m_Player, 1); // A speeding rock ...
PlaySounds(m_Player.Location, !m_Player.Female ? fs2 : ms2);
int j = Utility.Random(6, 10);
for (int i = 0; i < j; i++)
{
IEntity m_IEntity = new Entity(Serial.Zero, RandomPointIn(m_Player.Location, 10), m_Player.Map);
List<Mobile> mobiles = m_IEntity.Map.GetMobilesInRange(m_IEntity.Location, 2).ToList();
for (int k = 0; k < mobiles.Count; k++)
if (IsValidDamagable(mobiles[k]) && mobiles[k] != m_Player)
{
PlayEffect(m_Player, mobiles[k], Rock(), 8, true);
DoDamage(mobiles[k], 25, 30, false);
if (mobiles[k].Player) POHMessage(mobiles[k], 2); // OUCH!
}
PlayEffect(m_Player, m_IEntity, Rock(), 8, false);
}
}
}
}
}
public class LampRoomKickTimer : Timer
{
private Mobile m;
public LampRoomKickTimer(Mobile player)
: base(TimeSpan.FromSeconds(.25))
{
m = player;
}
protected override void OnTick()
{
MoveMobileOut(m);
}
}
public class LampRoomTimer : Timer
{
public int level;
public LeverPuzzleController m_Controller;
public int ticks;
public LampRoomTimer(LeverPuzzleController controller)
: base(TimeSpan.FromSeconds(5.0), TimeSpan.FromSeconds(5.0))
{
level = 0;
ticks = 0;
m_Controller = controller;
}
protected override void OnTick()
{
ticks++;
List<Mobile> mobiles = m_Controller.m_LampRoom.GetMobiles();
if (ticks >= 71 || m_Controller.m_LampRoom.GetPlayerCount() == 0)
{
foreach (Mobile mobile in mobiles)
if (mobile?.Deleted == false && !mobile.IsDeadBondedPet)
mobile.Kill();
m_Controller.Enabled = true;
Stop();
}
else
{
if (ticks % 12 == 0) level++;
foreach (Mobile mobile in mobiles)
if (IsValidDamagable(mobile))
{
if (ticks % 2 == 0 && level == 5)
{
if (mobile.Player)
{
mobile.Say(1062092);
if (AniSafe(mobile)) mobile.Animate(32, 5, 1, true, false, 0);
}
DoDamage(mobile, 15, 20, true);
}
if (Utility.Random((int)(level & ~0xfffffffc), 3) == 3)
mobile.ApplyPoison(mobile, PA2[level]);
if (ticks % 12 == 0 && level > 0 && mobile.Player)
mobile.SendLocalizedMessage(PA[level][0], null, PA[level][1]);
}
for (int i = 0; i <= level; i++)
SendLocationEffect(RandomPointIn(lr_Rect, -1), 0x36B0, Utility.Random(150, 200), 0, PA[level][2]);
}
}
}
}
}

View file

@ -0,0 +1,205 @@
using System;
using Server.Mobiles;
using Server.Network;
using Server.Spells;
namespace Server.Engines.Doom
{
public class LampRoomBox : Item
{
private LeverPuzzleController m_Controller;
private Mobile m_Wanderer;
public LampRoomBox(LeverPuzzleController controller) : base(0xe80)
{
m_Controller = controller;
ItemID = 0xe80;
Movable = false;
}
public LampRoomBox(Serial serial) : base(serial)
{
}
public override void OnDoubleClick(Mobile m)
{
if (!m.InRange(GetWorldLocation(), 3))
return;
if (m_Controller.Enabled)
return;
if (m_Wanderer == null || !m_Wanderer.Alive)
{
m_Wanderer = new WandererOfTheVoid();
m_Wanderer.MoveToWorld(LeverPuzzleController.lr_Enter, Map.Malas);
m_Wanderer.PublicOverheadMessage(MessageType.Regular, 0x3B2, 1060002); // I am the guardian of...
Timer.DelayCall(TimeSpan.FromSeconds(5.0), CallBackMessage);
}
}
public void CallBackMessage()
{
PublicOverheadMessage(MessageType.Regular, 0x3B2, 1060003, ""); // You try to pry the box open...
}
public override void OnAfterDelete()
{
if (m_Controller?.Deleted == false)
m_Controller.Delete();
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write(0); // version
writer.Write(m_Controller);
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
m_Controller = reader.ReadItem() as LeverPuzzleController;
}
}
public class LeverPuzzleStatue : Item
{
private LeverPuzzleController m_Controller;
public LeverPuzzleStatue(int[] dat, LeverPuzzleController controller) : base(dat[0])
{
m_Controller = controller;
Hue = 0x44E;
Movable = false;
}
public LeverPuzzleStatue(Serial serial) : base(serial)
{
}
public override void OnAfterDelete()
{
if (m_Controller?.Deleted == false)
m_Controller.Delete();
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write(0); // version
writer.Write(m_Controller);
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
m_Controller = reader.ReadItem() as LeverPuzzleController;
}
}
public class LeverPuzzleLever : Item
{
private LeverPuzzleController m_Controller;
public LeverPuzzleLever(ushort code, LeverPuzzleController controller) : base(0x108E)
{
m_Controller = controller;
Code = code;
Hue = 0x66D;
Movable = false;
}
public LeverPuzzleLever(Serial serial) : base(serial)
{
}
[CommandProperty(AccessLevel.GameMaster)]
public ushort Code{ get; private set; }
public override void OnDoubleClick(Mobile m)
{
if (m != null && m_Controller.Enabled)
{
ItemID ^= 2;
Effects.PlaySound(Location, Map, 0x3E8);
m_Controller.LeverPulled(Code);
}
else
{
m?.SendLocalizedMessage(1060001); // You throw the switch, but the mechanism cannot be engaged again so soon.
}
}
public override void OnAfterDelete()
{
if (m_Controller?.Deleted == false)
m_Controller.Delete();
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write(0); // version
writer.Write(Code);
writer.Write(m_Controller);
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
Code = reader.ReadUShort();
m_Controller = reader.ReadItem() as LeverPuzzleController;
}
}
[TypeAlias("Server.Engines.Doom.LampRoomTelePorter")]
public class LampRoomTeleporter : Item
{
public LampRoomTeleporter(int[] dat)
{
Hue = dat[1];
ItemID = dat[0];
Movable = false;
}
public LampRoomTeleporter(Serial serial) : base(serial)
{
}
public override bool HandlesOnMovement => true;
public override bool OnMoveOver(Mobile m)
{
if (m is PlayerMobile)
{
if (SpellHelper.CheckCombat(m))
{
m.SendLocalizedMessage(1005564, "", 0x22); // Wouldst thou flee during the heat of battle??
}
else
{
BaseCreature.TeleportPets(m, LeverPuzzleController.lr_Exit, Map.Malas);
m.MoveToWorld(LeverPuzzleController.lr_Exit, Map.Malas);
return false;
}
}
return true;
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write(0); // version
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
}
}
}

View file

@ -0,0 +1,103 @@
using Server.Mobiles;
using Server.Regions;
namespace Server.Engines.Doom
{
public class LampRoomRegion : BaseRegion
{
private LeverPuzzleController m_Controller;
public LampRoomRegion(LeverPuzzleController controller)
: base(null, Map.Malas, Find(LeverPuzzleController.lr_Enter, Map.Malas), LeverPuzzleController.lr_Rect)
{
m_Controller = controller;
Register();
}
public static void Initialize()
{
EventSink.Login += OnLogin;
}
public static void OnLogin(LoginEventArgs e)
{
Mobile m = e.Mobile;
Rectangle2D rect = LeverPuzzleController.lr_Rect;
if (m.X >= rect.X && m.X <= rect.X + 10 && m.Y >= rect.Y && m.Y <= rect.Y + 10 && m.Map == Map.Internal)
{
Timer kick = new LeverPuzzleController.LampRoomKickTimer(m);
kick.Start();
}
}
public override void OnEnter(Mobile m)
{
if (m == null || m is WandererOfTheVoid)
return;
if (m.AccessLevel > AccessLevel.Player)
return;
if (m_Controller.Successful != null)
{
if (m is PlayerMobile)
{
if (m == m_Controller.Successful) return;
}
else if (m is BaseCreature bc && (bc.Controlled && bc.ControlMaster == m_Controller.Successful ||
bc.Summoned))
{
return;
}
}
Timer kick = new LeverPuzzleController.LampRoomKickTimer(m);
kick.Start();
}
public override void OnExit(Mobile m)
{
if (m != null && m == m_Controller.Successful)
m_Controller.RemoveSuccessful();
}
public override void OnDeath(Mobile m)
{
if (m?.Deleted != false || m is WandererOfTheVoid)
return;
Timer kick = new LeverPuzzleController.LampRoomKickTimer(m);
kick.Start();
}
public override bool OnSkillUse(Mobile m, int Skill) /* just in case */
{
return m_Controller.Successful != null && (m.AccessLevel != AccessLevel.Player || m == m_Controller.Successful);
}
}
public class LeverPuzzleRegion : BaseRegion
{
public Mobile m_Occupant;
public LeverPuzzleRegion(LeverPuzzleController controller, int[] loc)
: base(null, Map.Malas, Find(LeverPuzzleController.lr_Enter, Map.Malas), new Rectangle2D(loc[0], loc[1], 1, 1))
{
Register();
}
[CommandProperty(AccessLevel.GameMaster)]
public Mobile Occupant => m_Occupant?.Alive == true ? m_Occupant : null;
public override void OnEnter(Mobile m)
{
if (m != null && m_Occupant == null && m is PlayerMobile && m.Alive)
m_Occupant = m;
}
public override void OnExit(Mobile m)
{
if (m != null && m == m_Occupant)
m_Occupant = null;
}
}
}