ModernUO/Projects/Scripts/Items/Skill Items/Fishing/Misc/SOS.cs
Kamron Batman 179cb50557 Updates Packets & Randomizer (#43)
* Fixes a bug with the main loop. Removes unnecessary optimizations for RDRand.

* WIP - Rewriting packets.

* Cleanup and updates README

* Converts more packets

* Fixes header

* Converts Effects packets.

* Forgot the send command

* Adds the start of containers packets.

* Adds message packets with caching

* Extends the send methods

* Starts to add Acquire methods

* Converted the packets

* Cleanup

* Cleanup

* Adds more packets

* Adds more packets

* Fixes clearing arrays from pool. Adds Mobile Incoming

* Converts more packets.

* Moves more packets

* Moves more packets

* Test compression

* Merges

* Migrating to an idiomatic syntax that also supports compression, and proxying.

* Optimize the stack alloc. Changes attributes

* Converted container packets

* Visual Studio doesn't auto save files. I am still getting used to subpar IDEs.

* Adds static packet caching. Will profile later. Converts more packets

* Fixes packets and changes how compression is configured

* WIP - Adds basics for Gumps. Not finished though.

* Fix file

* Fixes formatting

* Changed SpanWriter to be more idiomatic.

* Fixes Span vs RawSpan and missing stackallocs

* Converts over some more gumps

* WIP - Deletes 32bit support.

* Drops RDRand32 support.

* Fixes gump compilation

* Converting gump components

* Removes old huffman compression function

* Revert signature for backwards compatibility

* WIP - Converting more gump components

* Creates ArraySet for the strings. Updates AppendTo to reference that.

* Converts the maining gump components

* Cleans up gump components

* Cleans up directives

* Cleans up ArraySet and moves it. Adds null-coalescing-assignment

* Cleanup, Target Packets, and C# 8 changes.

* Removed OPL Packet

* World packets

* Fixing packet uses

* Cleans up code. Fixes packet uses in various places.

* More cleanup for packets

* Code cleanup

* Converts more packet uses and cleans up more code

* More code cleanup

* Finishes fixing the packets in Item

* Updates secure trade packets

* Updates core and gets it to compile.

* Moved packets to scripts. Fixed account handler use of packets

* Code cleanup

* Updates chat packets

* Code cleanuo

* Adds party packets, but need to implement them.

* Party packets WIP

* Finishes party packets

* Rearrange movement namespaces and classes

* Finishes plant packets

* Code Formatting

* Fixes moving effects

* Code cleanup, eliminates equipinfo

* Adds more packets. Fixes bugs with various packets.

* Finishes mahjon packets

* Fixes mahjong packet

* Code cleanup

* Finishes mahjong packets

* Adds Map packets

* Add multifacet maps and charts

* Cleans up some packets with UTF8

* Optimizes packets

* Cleans up more packets. Moves the MessageHelper

* Removes assistant support. Removes extended protocol. Incorporates MapUO packets as normal packets.

* Updates protocol extensions packet receiver

* Fixes a few bugs. Fixes a few more packets.

* Code cleanup and fixing more packets

* Fixes packet effects

* Cleaned up more code

* Buff Icon cleanup

* Removed unused constructors

* Code Cleanup. Adds BoatHS Packets

* Moves house files. Updates house foundation packets.

* Deployment cleanup

* Fixes:

* Code cleanup

* More code cleanup

* More code cleanup

* Cleaned up BaseHouse

* Enforces styling

* Converts foreach to linq where possible.

* Dont need that

* Goals/Readme updates

* Removes 32bit support at the highest level. Turns on HRT by default.

* Code cleanup. Fixes extended features packet.

* Fixes various bugs

* Code cleanup

* Code cleanup

* Code cleanup. Fixes gump X/Y assignment.

* Code cleanup using |= operator

* More code cleanup

* Cleanup

* Fixes spacing issues. Thanks Visual Studio. You suck.

* Compiler error

* Fixes NPE from RunUO 2.7

* Renames ScriptCompiler to AssemblyHandler. Fixes packets. Updates README

* Fixes more packets. Stupid trailing nulls.

* Fixes various bugs.

* Fixes for gumps

* Fixes more gump stuff. Going to split it out later since it is getting insane

* Recoded the gump writing

* WIP

* *Added output path of scripts project to dev branch
*Activated debugging in code
2019-11-11 12:40:16 +01:00

301 lines
10 KiB
C#

using System;
using Server.Gumps;
namespace Server.Items
{
[Flippable(0x14ED, 0x14EE)]
public class SOS : Item
{
public override int LabelNumber
{
get
{
if (IsAncient)
return 1063450; // an ancient SOS
return 1041081; // a waterstained SOS
}
}
private int m_Level;
[CommandProperty(AccessLevel.GameMaster)]
public bool IsAncient => m_Level >= 4;
[CommandProperty(AccessLevel.GameMaster)]
public int Level
{
get => m_Level;
set
{
m_Level = Math.Max(1, Math.Min(value, 4));
UpdateHue();
InvalidateProperties();
}
}
[CommandProperty(AccessLevel.GameMaster)]
public Map TargetMap{ get; set; }
[CommandProperty(AccessLevel.GameMaster)]
public Point3D TargetLocation{ get; set; }
[CommandProperty(AccessLevel.GameMaster)]
public int MessageIndex{ get; set; }
public void UpdateHue()
{
if (IsAncient)
Hue = 0x481;
else
Hue = 0;
}
[Constructible]
public SOS(Map map = null) : this(map, MessageInABottle.GetRandomLevel())
{
}
[Constructible]
public SOS(Map map, int level) : base(0x14EE)
{
Weight = 1.0;
m_Level = level;
MessageIndex = Utility.Random(MessageEntry.Entries.Length);
TargetMap = map ?? Map.Trammel;
TargetLocation = FindLocation(TargetMap);
UpdateHue();
}
public SOS(Serial serial) : base(serial)
{
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write(4); // version
writer.Write(m_Level);
writer.Write(TargetMap);
writer.Write(TargetLocation);
writer.Write(MessageIndex);
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
switch (version)
{
case 4:
case 3:
case 2:
{
m_Level = reader.ReadInt();
goto case 1;
}
case 1:
{
TargetMap = reader.ReadMap();
TargetLocation = reader.ReadPoint3D();
MessageIndex = reader.ReadInt();
break;
}
case 0:
{
TargetMap = Map;
if (TargetMap == null || TargetMap == Map.Internal)
TargetMap = Map.Trammel;
TargetLocation = FindLocation(TargetMap);
MessageIndex = Utility.Random(MessageEntry.Entries.Length);
break;
}
}
if (version < 2)
m_Level = MessageInABottle.GetRandomLevel();
if (version < 3)
UpdateHue();
if (version < 4 && TargetMap == Map.Tokuno)
TargetMap = Map.Trammel;
}
public override void OnDoubleClick(Mobile from)
{
if (IsChildOf(from.Backpack))
{
MessageEntry entry;
if (MessageIndex >= 0 && MessageIndex < MessageEntry.Entries.Length)
entry = MessageEntry.Entries[MessageIndex];
else
entry = MessageEntry.Entries[MessageIndex = Utility.Random(MessageEntry.Entries.Length)];
//from.CloseGump( typeof( MessageGump ) );
from.SendGump(new MessageGump(entry, TargetMap, TargetLocation));
}
else
{
from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it.
}
}
private static int[] m_WaterTiles =
{
0x00A8, 0x00AB,
0x0136, 0x0137
};
private static Rectangle2D[] m_BritRegions = { new Rectangle2D(0, 0, 5120, 4096) };
private static Rectangle2D[] m_IlshRegions =
{ new Rectangle2D(1472, 272, 304, 240), new Rectangle2D(1240, 1000, 312, 160) };
private static Rectangle2D[] m_MalasRegions = { new Rectangle2D(1376, 1520, 464, 280) };
public static Point3D FindLocation(Map map)
{
if (map == null || map == Map.Internal)
return Point3D.Zero;
Rectangle2D[] regions;
if (map == Map.Felucca || map == Map.Trammel)
regions = m_BritRegions;
else if (map == Map.Ilshenar)
regions = m_IlshRegions;
else if (map == Map.Malas)
regions = m_MalasRegions;
else
regions = new[] { new Rectangle2D(0, 0, map.Width, map.Height) };
if (regions.Length == 0)
return Point3D.Zero;
for (int i = 0; i < 50; ++i)
{
Rectangle2D reg = regions[Utility.Random(regions.Length)];
int x = Utility.Random(reg.X, reg.Width);
int y = Utility.Random(reg.Y, reg.Height);
if (!ValidateDeepWater(map, x, y))
continue;
bool valid = true;
for (int j = 1, offset = 5; valid && j <= 5; ++j, offset += 5)
if (!ValidateDeepWater(map, x + offset, y + offset))
valid = false;
else if (!ValidateDeepWater(map, x + offset, y - offset))
valid = false;
else if (!ValidateDeepWater(map, x - offset, y + offset))
valid = false;
else if (!ValidateDeepWater(map, x - offset, y - offset))
valid = false;
if (valid)
return new Point3D(x, y, 0);
}
return Point3D.Zero;
}
private static bool ValidateDeepWater(Map map, int x, int y)
{
int tileID = map.Tiles.GetLandTile(x, y).ID;
bool water = false;
for (int i = 0; !water && i < m_WaterTiles.Length; i += 2)
water = tileID >= m_WaterTiles[i] && tileID <= m_WaterTiles[i + 1];
return water;
}
private class MessageGump : Gump
{
public MessageGump(MessageEntry entry, Map map, Point3D loc) : base(150, 50)
{
int xLong = 0, yLat = 0;
int xMins = 0, yMins = 0;
bool xEast = false, ySouth = false;
string fmt;
fmt = Sextant.Format(loc, map, ref xLong, ref yLat, ref xMins, ref yMins, ref xEast, ref ySouth) ?
$"{yLat}°{yMins}'{(ySouth ? "S" : "N")},{xLong}°{xMins}'{(xEast ? "E" : "W")}" : "?????";
AddPage(0);
AddBackground(0, 40, 350, 300, 2520);
AddHtmlLocalized(30, 80, 285, 160, 1018326, true, true);
/* This is a message hastily scribbled by a passenger aboard a sinking ship.
* While it is probably too late to save the passengers and crew,
* perhaps some treasure went down with the ship!
* The message gives the ship's last known sextant co-ordinates.=
*/
AddHtml(35, 240, 230, 20, fmt);
AddButton(35, 265, 4005, 4007, 0);
AddHtmlLocalized(70, 265, 100, 20, 1011036); // OKAY
}
}
private class MessageEntry
{
public MessageEntry(int width, int height, string message)
{
Width = width;
Height = height;
Message = message;
}
public int Width{ get; }
public int Height{ get; }
public string Message{ get; }
public static MessageEntry[] Entries{ get; } =
{
new MessageEntry(280, 180,
"...Ar! {0} and a fair wind! No chance... storms, though--ar! Is that a sea serp...<br><br>uh oh."),
new MessageEntry(280, 215,
"...been inside this whale for three days now. I've run out of food I can pick out of his teeth. I took a sextant reading through the blowhole: {0}. I'll never see my treasure again..."),
new MessageEntry(280, 285,
"...grand adventure! Captain Quacklebush had me swab down the decks daily...<br> ...pirates came, I was in the rigging practicing with my sextant. {0} if I am not mistaken...<br> ....scuttled the ship, and our precious cargo went with her and the screaming pirates, down to the bottom of the sea..."),
new MessageEntry(280, 180,
"Help! Ship going dow...n heavy storms...precious cargo...st reach dest...current coordinates {0}...ve any survivors... ease!"),
new MessageEntry(280, 215,
"...know that the wreck is near {0} but have not found it. Could the message passed down in my family for generations be wrong? No... I swear on the soul of my grandfather, I will find..."),
new MessageEntry(280, 195,
"...never expected an iceberg...silly woman on bow crushed instantly...send help to {0}...ey'll never forget the tragedy of the sinking of the Miniscule..."),
new MessageEntry(280, 265,
"...nobody knew I was a girl. They just assumed I was another sailor...then we met the undine. {0}. It was demanded sacrifice...I was youngset, they figured...<br> ...grabbed the captain's treasure, screamed, 'It'll go down with me!'<br> ...they took me up on it."),
new MessageEntry(280, 230,
"...so I threw the treasure overboard, before the curse could get me too. But I was too late. Now I am doomed to wander these seas, a ghost forever. Join me: seek ye at {0} if thou wishest my company..."),
new MessageEntry(280, 285,
"...then the ship exploded. A dragon swooped by. The slime swallowed Bertie whole--he screamed, it was amazing. The sky glowed orange. A sextant reading put us at {0}. Norma was chattering about sailing over the edge of the world. I looked at my hands and saw through them..."),
new MessageEntry(280, 285,
"...trapped on a deserted island, with a magic fountain supplying wood, fresh water springs, gorgeous scenery, and my lovely young wife. I know the ship with all our life's earnings sank at {0} but I don't know what our coordinates are... someone has GOT to rescue me before Sunday's finals game or I'll go mad..."),
new MessageEntry(280, 160,
"WANTED: divers exp...d in shipwre...overy. Must have own vess...pply at {0}<br>...good benefits, flexible hours..."),
new MessageEntry(280, 250,
"...was a cad and a boor, no matter what momma s...rew him overboard! Oh, Anna, 'twas so exciting!<br> Unfort...y he grabbe...est, and all his riches went with him!<br> ...sked the captain, and he says we're at {0}<br>...so maybe...")
};
}
}
}