ModernUO/Projects/Scripts/Holiday Stuff/Halloween/2006/Engines/TrickOrTreat.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

324 lines
9.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using Server.Events.Halloween;
using Server.Items;
using Server.Mobiles;
using Server.Targeting;
namespace Server.Engines.Events
{
public class TrickOrTreat
{
public static TimeSpan OneSecond = TimeSpan.FromSeconds(1);
public static void Initialize()
{
DateTime now = DateTime.UtcNow;
if (DateTime.UtcNow >= HolidaySettings.StartHalloween && DateTime.UtcNow <= HolidaySettings.FinishHalloween)
EventSink.Speech += EventSink_Speech;
}
private static void EventSink_Speech(SpeechEventArgs e)
{
if (Insensitive.Contains(e.Speech, "trick or treat"))
{
e.Mobile.Target = new TrickOrTreatTarget();
e.Mobile.SendLocalizedMessage(1076764); /* Pick someone to Trick or Treat. */
}
}
public static void Bleeding(Mobile m_From)
{
if (CheckMobile(m_From))
if (m_From.Location != Point3D.Zero)
{
int amount = Utility.RandomMinMax(3, 7);
for (int i = 0; i < amount; i++)
new Blood(Utility.RandomMinMax(0x122C, 0x122F)).MoveToWorld(
RandomPointOneAway(m_From.X, m_From.Y, m_From.Z, m_From.Map), m_From.Map);
}
}
public static void RemoveHueMod(Mobile target)
{
if (target?.Deleted == false)
target.SolidHueOverride = -1;
}
public static void SolidHueMobile(Mobile target)
{
if (CheckMobile(target))
{
target.SolidHueOverride = Utility.RandomMinMax(2501, 2644);
Timer.DelayCall(TimeSpan.FromSeconds(10), RemoveHueMod, target);
}
}
public static void MakeTwin(Mobile m_From)
{
List<Item> m_Items = new List<Item>();
if (CheckMobile(m_From))
{
Mobile twin = new NaughtyTwin(m_From);
if (twin.Deleted)
return;
m_Items.AddRange(m_From.Items.Where(item => item.Layer != Layer.Backpack && item.Layer != Layer.Mount && item.Layer != Layer.Bank));
if (m_Items.Count > 0)
{
for (int i = 0; i < m_Items.Count; i++) /* dupe exploits start out like this ... */
twin.AddItem(Mobile.LiftItemDupe(m_Items[i], 1));
foreach (Item item in twin.Items) /* ... and end like this */
if (item.Layer != Layer.Backpack && item.Layer != Layer.Mount && item.Layer != Layer.Bank)
item.Movable = false;
}
twin.Hue = m_From.Hue;
twin.BodyValue = m_From.BodyValue;
twin.Kills = m_From.Kills;
Point3D point = RandomPointOneAway(m_From.X, m_From.Y, m_From.Z, m_From.Map);
twin.MoveToWorld(m_From.Map.CanSpawnMobile(point) ? point : m_From.Location, m_From.Map);
Timer.DelayCall(TimeSpan.FromSeconds(5), DeleteTwin, twin);
}
}
public static void DeleteTwin(Mobile m_Twin)
{
if (CheckMobile(m_Twin)) m_Twin.Delete();
}
public static Point3D RandomPointOneAway(int x, int y, int z, Map map)
{
Point3D loc = new Point3D(x + Utility.Random(-1, 3), y + Utility.Random(-1, 3), 0);
loc.Z = map.CanFit(loc, 0) ? map.GetAverageZ(loc.X, loc.Y) : z;
return loc;
}
public static bool CheckMobile(Mobile mobile) => mobile?.Map != null && !mobile.Deleted && mobile.Alive && mobile.Map != Map.Internal;
private class TrickOrTreatTarget : Target
{
public TrickOrTreatTarget()
: base(15, false, TargetFlags.None)
{
}
protected override void OnTarget(Mobile from, object targ)
{
if (targ == null || !CheckMobile(from))
return;
if (!(targ is Mobile))
{
from.SendLocalizedMessage(1076781); /* There is little chance of getting candy from that! */
return;
}
BaseVendor begged = targ as BaseVendor;
if (begged?.Deleted != false)
{
from.SendLocalizedMessage(1076765); /* That doesn't look friendly. */
return;
}
DateTime now = DateTime.UtcNow;
if (CheckMobile(begged))
{
if (begged.NextTrickOrTreat > now)
{
from.SendLocalizedMessage(1076767); /* That doesn't appear to have any more candy. */
return;
}
begged.NextTrickOrTreat = now + TimeSpan.FromMinutes(Utility.RandomMinMax(5, 10));
if (from.Backpack?.Deleted != false)
return;
if (Utility.RandomDouble() > .10)
{
switch (Utility.Random(3))
{
case 0:
begged.Say(1076768);
break; /* Oooooh, aren't you cute! */
case 1:
begged.Say(1076779);
break; /* All right...This better not spoil your dinner! */
case 2:
begged.Say(1076778);
break; /* Here you go! Enjoy! */
}
if (Utility.RandomDouble() <= .01 && from.Skills.Begging.Value >= 100)
{
from.AddToBackpack(HolidaySettings.RandomGMBeggerItem);
from.SendLocalizedMessage(1076777); /* You receive a special treat! */
}
else
{
from.AddToBackpack(HolidaySettings.RandomTreat);
from.SendLocalizedMessage(1076769); /* You receive some candy. */
}
}
else
{
begged.Say(1076770); /* TRICK! */
int action = Utility.Random(4);
if (action == 0)
Timer.DelayCall(OneSecond, OneSecond, 10, Bleeding, from);
else if (action == 1)
Timer.DelayCall(TimeSpan.FromSeconds(2), SolidHueMobile, from);
else
Timer.DelayCall(TimeSpan.FromSeconds(2), MakeTwin, from);
}
}
}
}
}
public class NaughtyTwin : BaseCreature
{
private static Point3D[] Felucca_Locations =
{
new Point3D(4467, 1283, 5), // Moonglow
new Point3D(1336, 1997, 5), // Britain
new Point3D(1499, 3771, 5), // Jhelom
new Point3D(771, 752, 5), // Yew
new Point3D(2701, 692, 5), // Minoc
new Point3D(1828, 2948, -20), // Trinsic
new Point3D(643, 2067, 5), // Skara Brae
new Point3D(3563, 2139, Map.Trammel.GetAverageZ(3563, 2139)) // (New) Magincia
};
private static Point3D[] Malas_Locations =
{
new Point3D(1015, 527, -65), // Luna
new Point3D(1997, 1386, -85) // Umbra
};
private static Point3D[] Ilshenar_Locations =
{
new Point3D(1215, 467, -13), // Compassion
new Point3D(722, 1366, -60), // Honesty
new Point3D(744, 724, -28), // Honor
new Point3D(281, 1016, 0), // Humility
new Point3D(987, 1011, -32), // Justice
new Point3D(1174, 1286, -30), // Sacrifice
new Point3D(1532, 1340, -3), // Spirituality
new Point3D(528, 216, -45), // Valor
new Point3D(1721, 218, 96) // Chaos
};
private static Point3D[] Tokuno_Locations =
{
new Point3D(1169, 998, 41), // Isamu-Jima
new Point3D(802, 1204, 25), // Makoto-Jima
new Point3D(270, 628, 15) // Homare-Jima
};
private Mobile m_From;
public NaughtyTwin(Mobile from)
: base(AIType.AI_Melee, FightMode.None, 10, 1, 0.2, 0.4)
{
if (TrickOrTreat.CheckMobile(from))
{
Body = from.Body;
m_From = from;
Name = $"{from.Name}\'s Naughty Twin";
Timer.DelayCall(TrickOrTreat.OneSecond, StealCandyOrGate, m_From);
}
}
public NaughtyTwin(Serial serial)
: base(serial)
{
}
public override void OnThink()
{
if (m_From?.Deleted != false)
Delete();
}
public static Item FindCandyTypes(Mobile target)
{
Type[] types =
{ typeof(WrappedCandy), typeof(Lollipops), typeof(NougatSwirl), typeof(Taffy), typeof(JellyBeans) };
if (TrickOrTreat.CheckMobile(target))
return target.Backpack.FindItemByType(types);
return null;
}
public static void StealCandyOrGate(Mobile target)
{
if (TrickOrTreat.CheckMobile(target))
{
if (Utility.RandomBool())
{
Item item = FindCandyTypes(target);
target.SendLocalizedMessage(1113967); /* Your naughty twin steals some of your candy. */
if (item?.Deleted == false)
item.Delete();
}
else
{
target.SendLocalizedMessage(1113972); /* Your naughty twin teleports you away with a naughty laugh! */
target.MoveToWorld(RandomMoongate(target), target.Map);
}
}
}
public static Point3D RandomMoongate(Mobile target)
{
return target.Map.MapID switch
{
2 => Ilshenar_Locations[Utility.Random(Ilshenar_Locations.Length)],
3 => Malas_Locations[Utility.Random(Malas_Locations.Length)],
4 => Tokuno_Locations[Utility.Random(Tokuno_Locations.Length)],
_ => Felucca_Locations[Utility.Random(Felucca_Locations.Length)]
};
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write(0);
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
}
}
}