using System;
using System.Collections;
using System.Collections.Generic;
using Server;
using Server.Commands;
using Server.Gumps;
using Server.Mobiles;
using Server.Network;
using Server.Spells;
using Server.Targeting;
using Server.ContextMenus;
// UnrealUO - Returned to pre-UO:R behavior
namespace Server.Items
{
public class PublicMoongate : Item
{
[Constructable]
public PublicMoongate() : base( 0xF6C )
{
Movable = false;
Light = LightType.Circle300;
}
public PublicMoongate( Serial serial ) : base( serial )
{
}
[COLOR="Red"]
public override void OnSingleClick( Mobile from )
{
base.OnSingleClick( from );
int mgate = 0, steptime, steps, number;
int hours, minutes, totalMinutes;
PMList moongates = PMList.Felucca;
foreach ( PMEntry entry in moongates.Entries )
{
if ( this.Location == entry.Location )
break;
else
mgate++;
}
if ( mgate > 7 ) // Invalid
return;
Clock.GetTime( from.Map, from.X, from.Y, out hours, out minutes, out totalMinutes );
steptime = ((hours % 2) * 6) + (int)(minutes / 10);
switch ( steptime )
{
case 0: steps = 0; break;
case 1:
case 2: steps = 1; break;
case 3: steps = 2; break;
case 4:
case 5: steps = 3; break;
case 6: steps = 4; break;
case 7:
case 8: steps = 5; break;
case 9: steps = 6; break;
case 10:
case 11: steps = 7; break;
default: return;
}
mgate += steps;
if ( mgate > 7 )
mgate -= 8;
switch ( mgate )
{
case 0: number = 1005390; break; // Britain ...see a road to the east and mountains in the distance to the west.
case 1: number = 1005389; break; // Moonglow ...see a small escarpment to the south and a large city to the North.
case 2: number = 1005396; break; // Magincia ...see what appears to be a small peninsula covered in lush foliage.
case 3: number = 1005395; break; // Skara Brae ...see a small city to the south, while a vast ocean lies in all other directions.
case 4: number = 1005394; break; // Trinsic ...see a large sandstone city standing on a far bank of the river to the north.
case 5: number = 1005393; break; // Minoc ...can just make out a road to the southwest and a river to the north.
case 6: number = 1005392; break; // Yew ...see deep forest on all sides.
case 7: number = 1005391; break; // Jhelom ...see a vast body of water to the east while to the west a city can be seen nearby.
default: number = 1005397; break; // The moongate is cloudy, and nothing can be made out.
}
LabelTo( from, number );
}
[/COLOR]
public override void OnDoubleClick( Mobile from )
{
if ( !from.Player )
return;
if ( from.InRange( GetWorldLocation(), 1 ) )
UseGate( from );
else
from.SendLocalizedMessage( 500446 ); // That is too far away.
}
public override bool OnMoveOver( Mobile m )
{
if ( !m.Player )
return true;
return !UseGate( m );
}
public bool UseGate( Mobile m )
{
if ( m.Criminal )
{
m.SendLocalizedMessage( 1005561, "", 0x22 ); // Thou'rt a criminal and cannot escape so easily.
return false;
}
else if ( Server.Spells.SpellHelper.CheckCombat( m ) )
{
m.SendLocalizedMessage( 1005564, "", 0x22 ); // Wouldst thou flee during the heat of battle??
return false;
}
else if ( m.Spell != null )
{
m.SendLocalizedMessage( 1049616 ); // You are too busy to do that at the moment.
return false;
}
else
{
int mgate = 0, steptime, steps;
int hours, minutes, totalMinutes;
PMList moongates = PMList.Felucca;
foreach ( PMEntry entry in moongates.Entries )
{
if ( this.Location == entry.Location )
break;
else
mgate++;
}
if ( mgate > 7 ) // Invalid
return false;
Clock.GetTime( m.Map, m.X, m.Y, out hours, out minutes, out totalMinutes );
steptime = ((hours % 2) * 6) + (int)(minutes / 10);
switch ( steptime )
{
case 0: steps = 0; break;
case 1:
case 2: steps = 1; break;
case 3: steps = 2; break;
case 4:
case 5: steps = 3; break;
case 6: steps = 4; break;
case 7:
case 8: steps = 5; break;
case 9: steps = 6; break;
case 10:
case 11: steps = 7; break;
default: return false;
}
mgate += steps;
if ( mgate > 7 )
mgate -= 8;
BaseCreature.TeleportPets( m, moongates.Entries[mgate].Location, m.Map );
m.Combatant = null;
m.Warmode = false;
m.Hidden = false;
m.MoveToWorld( moongates.Entries[mgate].Location, m.Map );
Effects.PlaySound( moongates.Entries[mgate].Location, m.Map, 0x1FE );
return true;
}
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 ); // version
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
public static void Initialize()
{
CommandSystem.Register( "MoonGen", AccessLevel.Administrator, new CommandEventHandler( MoonGen_OnCommand ) );
}
[Usage( "MoonGen" )]
[Description( "Generates public moongates. Removes all old moongates." )]
public static void MoonGen_OnCommand( CommandEventArgs e )
{
DeleteAll();
int count = 0;
count += MoonGen( PMList.Felucca );
World.Broadcast( 0x35, true, "{0} moongates generated.", count );
}
//-------------------------------------------------------------------------------------------------
private static void DeleteAll()
{
List<Item> list = new List<Item>();
foreach ( Item item in World.Items.Values )
{
if ( item is PublicMoongate )
list.Add( item );
}
foreach ( Item item in list )
item.Delete();
if ( list.Count > 0 )
World.Broadcast( 0x35, true, "{0} moongates removed.", list.Count );
}
//-------------------------------------------------------------------------------------------------
private static int MoonGen( PMList list )
{
foreach ( PMEntry entry in list.Entries )
{
Item item = new PublicMoongate();
item.MoveToWorld( entry.Location, list.Map );
}
return list.Entries.Length;
}
}
public class PMEntry
{
private Point3D m_Location;
private int m_Number;
public Point3D Location
{
get
{
return m_Location;
}
}
public int Number
{
get
{
return m_Number;
}
}
public PMEntry( Point3D loc, int number )
{
m_Location = loc;
m_Number = number;
}
}
public class PMList
{
private int m_Number, m_SelNumber;
private Map m_Map;
private PMEntry[] m_Entries;
public int Number
{
get
{
return m_Number;
}
}
public int SelNumber
{
get
{
return m_SelNumber;
}
}
public Map Map
{
get
{
return m_Map;
}
}
public PMEntry[] Entries
{
get
{
return m_Entries;
}
}
public PMList( int number, int selNumber, Map map, PMEntry[] entries )
{
m_Number = number;
m_SelNumber = selNumber;
m_Map = map;
m_Entries = entries;
}
public static readonly PMList Felucca =
new PMList( 1012001, 1012013, Map.Felucca, new PMEntry[]
{
new PMEntry( new Point3D( 1336, 1997, 5 ), 1012004 ), // Britain
new PMEntry( new Point3D( 4467, 1283, 5 ), 1012003 ), // Moonglow
new PMEntry( new Point3D( 3563, 2139, 34), 1012010 ), // Magincia
new PMEntry( new Point3D( 643, 2067, 5 ), 1012009 ), // Skara Brae
new PMEntry( new Point3D( 1828, 2948,-20), 1012008 ), // Trinsic
new PMEntry( new Point3D( 2701, 692, 5 ), 1012007 ), // Minoc
new PMEntry( new Point3D( 771, 752, 5 ), 1012006 ), // Yew
new PMEntry( new Point3D( 1499, 3771, 5 ), 1012005 ), // Jhelom
} );
}
}