Skip to content

Instantly share code, notes, and snippets.

@DarkLotus
Last active January 20, 2022 12:50
Show Gist options
  • Save DarkLotus/788881f929bb28490d237b22b1798b23 to your computer and use it in GitHub Desktop.
Save DarkLotus/788881f929bb28490d237b22b1798b23 to your computer and use it in GitHub Desktop.
using Server.ContextMenus;
using Server.Engines.Craft;
using Server.Network;
using System;
using System.Collections.Generic;
using System.Linq;
using Server.Mobiles;
namespace Server.Items
{
public class SummonChest : WoodenChest
{
[CommandProperty(AccessLevel.GameMaster)]
public int ItemsRequired { get; set; } = 10;
[CommandProperty(AccessLevel.GameMaster)]
public Type RequiredItem { get; set; } = typeof(WarHammer);
private int m_CurrentItems { get; set; }
[Constructable]
public SummonChest()
{
}
public SummonChest(Serial serial)
{
}
public override bool OnDragDrop(Mobile @from, Item dropped)
{
if(!base.OnDragDrop(@from, dropped))
return false;
if (dropped.GetType() == RequiredItem)
{
m_CurrentItems++;
dropped.Delete();
if (m_CurrentItems == ItemsRequired)
{
m_CurrentItems = 0;
SpawnMonster(from);
}
return true;
}
return false;
}
public void SpawnMonster(Mobile from)
{
Pixie pixie = new Pixie();
bool validLocation = false;
Point3D loc = from.Location;
for (int j = 0; !validLocation && j < 10; ++j)
{
int x = X + Utility.Random(3) - 1;
int y = Y + Utility.Random(3) - 1;
int z = from.Map.GetAverageZ(x, y);
if (validLocation = from.Map.CanFit(x, y, Z, 16, false, false))
loc = new Point3D(x, y, Z);
else if (validLocation = from.Map.CanFit(x, y, z, 16, false, false))
loc = new Point3D(x, y, z);
}
pixie.MoveToWorld(loc, from.Map);
}
public override void OnDoubleClick(Mobile @from)
{
this.PrivateOverheadMessage(MessageType.Emote,0,true,$"Requires {ItemsRequired - m_CurrentItems} items to summon.", from.NetState);
}
public override void Serialize(GenericWriter writer)
{
writer.Write(0);
writer.Write(m_CurrentItems);
base.Serialize(writer);
}
public override void Deserialize(GenericReader reader)
{
var ver =reader.ReadInt();
m_CurrentItems = reader.ReadInt();
base.Deserialize(reader);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment