// Script Package: Sleepable Beds
// Version: 1.0
// Author: Oak
// Servers: RunUO 2.0
// Date: 7/7/2006
// History:
// Written for RunUO 1.0 shard, Sylvan Dreams, in February 2005. Based largely on work by David on his Sleepable NPCs scripts.
// Modified for RunUO 2.0, removed shard specific customizations (wing layers, etc.)
// Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
using System;
using System.Collections;
using Server;
using Server.Engines.PartySystem;
using Server.Misc;
using Server.Guilds;
using Server.Mobiles;
using Server.Network;
using Server.ContextMenus;
namespace Server.Items
{
public class SleeperBedBody : Container
{
private Mobile m_Owner;
private string m_SleeperBedBodyName;
private bool m_Blessed;
private Timer m_Timer;
//Start Edited by Vano 31.08.07. Âðåìÿ èçìåíåíèÿ 11:32
private Timer m_TimerSleep;
//End Edited by Vano
private ArrayList m_EquipItems;
private bool m_spell;
// Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
private bool m_Pl_wake; // Ñàì ïðîñíóëñÿ ( true ) èëè ïî òàéìåðó ( false )
// private DateTime m_SleepBegin; // Êîãäà óñíóë
private SleepableBedsAddon m_Bed; // Êðîâàòü
[CommandProperty( AccessLevel.GameMaster )]
public SleepableBedsAddon Bed{ get{ return m_Bed; } set{ m_Bed = value; InvalidateProperties(); } }
// end Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
[CommandProperty( AccessLevel.GameMaster )]
public Mobile Owner // Âëàäåëåö êðîâàòè
{
get{ return m_Owner; }
set{ m_Owner = value; InvalidateProperties(); }
}
public ArrayList EquipItems
{
get{ return m_EquipItems; }
}
[CommandProperty( AccessLevel.GameMaster )]
public bool Invuln
{
get{ return m_Blessed; }
}
// Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
// [Constructable]
// end Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
public SleeperBedBody( Mobile owner, bool blessed ) : this( owner, blessed, true )
{
}
// Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
// [Constructable]
/*
public SleeperBedBody( Mobile owner, bool blessed, bool isSpell ) // Ñòàðûé âûçîâ.
{
return SleeperBedBody( owner, blessed, isSpell, null );
}
*/
// public SleeperBedBody( Mobile owner, bool blessed, bool isSpell ) : this( owner, blessed, isSpell, null ) {}
public SleeperBedBody( Mobile owner, bool blessed, bool isSpell ) : this( owner, isSpell, null ) {} // Ñòàðûé âûçîâ. Îñòàâëåí, ÷òîáû ñòàðûå êðîâàòè çàãðóçèëèñü
// public SleeperBedBody( Mobile owner, bool blessed, bool isSpell, SleepableBedsAddon bed ) : base( 0x2006 )
// Mod KOCTa 05.12.2008 - 08.12.2008
// public SleeperBedBody( Mobile owner, bool isSpell, SleepableBedsAddon bed ) : base( 0x2006 )
public SleeperBedBody( Mobile owner, bool isSpell, SleepableBedsAddon bed ) : this( owner, isSpell, bed, 0x2006 ) {}
public SleeperBedBody( Mobile owner, bool isSpell, SleepableBedsAddon bed, int itemid ) : base( itemid )
// end Mod KOCTa 05.12.2008 - 08.12.2008
{
Stackable = true; // To supress console warnings, stackable must be true
Amount = owner.Body; // protocol defines that for itemid 0x2006, amount=body
Stackable = false;
m_Blessed = owner.Blessed;
owner.Blessed = true;
Movable = false;
// Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
m_Owner = owner;
// Name = m_Owner.Name;
Name = m_Owner.Name;
m_SleeperBedBodyName = "a sleeping " + Name;
Hue = m_Owner.Hue;
// Direction = m_Owner.Direction;
m_spell = isSpell;
m_Bed = bed;
// end Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
m_EquipItems = new ArrayList();
AddFromLayer( m_Owner, Layer.FirstValid, ref m_EquipItems );
AddFromLayer( m_Owner, Layer.TwoHanded, ref m_EquipItems );
AddFromLayer( m_Owner, Layer.Shoes, ref m_EquipItems );
AddFromLayer( m_Owner, Layer.Pants, ref m_EquipItems );
AddFromLayer( m_Owner, Layer.Shirt, ref m_EquipItems );
AddFromLayer( m_Owner, Layer.Helm, ref m_EquipItems );
AddFromLayer( m_Owner, Layer.Gloves, ref m_EquipItems );
AddFromLayer( m_Owner, Layer.Ring, ref m_EquipItems );
AddFromLayer( m_Owner, Layer.Neck, ref m_EquipItems );
AddFromLayer( m_Owner, Layer.Hair, ref m_EquipItems );
AddFromLayer( m_Owner, Layer.Waist, ref m_EquipItems );
AddFromLayer( m_Owner, Layer.InnerTorso, ref m_EquipItems );
AddFromLayer( m_Owner, Layer.Bracelet, ref m_EquipItems );
AddFromLayer( m_Owner, Layer.FacialHair, ref m_EquipItems );
AddFromLayer( m_Owner, Layer.MiddleTorso, ref m_EquipItems );
AddFromLayer( m_Owner, Layer.Earrings, ref m_EquipItems );
AddFromLayer( m_Owner, Layer.Arms, ref m_EquipItems );
AddFromLayer( m_Owner, Layer.Cloak, ref m_EquipItems );
AddFromLayer( m_Owner, Layer.OuterTorso, ref m_EquipItems );
AddFromLayer( m_Owner, Layer.OuterLegs, ref m_EquipItems );
AddFromLayer( m_Owner, Layer.LastUserValid, ref m_EquipItems );
// Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
// m_SleepBegin = DateTime.Now;
// m_Timer = new InternalTimer( m_Owner, this );
m_Timer = new InternalTimer( this );
m_Timer.Start();
//Start Edited by Vano 31.08.07. Âðåìÿ èçìåíåíèÿ 11:33
// m_TimerSleep = new InternalTimerSleep( this, 60 );
// m_TimerSleep.Start();
//End Edited by Vano
// end Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
}
private void AddFromLayer( Mobile from, Layer layer, ref ArrayList list )
{
if( list == null )
list = new ArrayList();
Item worn = from.FindItemOnLayer( layer );
if ( worn != null )
{
Item item = new Item();
item.ItemID = worn.ItemID;
item.Hue = worn.Hue;
item.Layer = layer;
DropItem( item );
list.Add( item );
}
}
// Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
public override void OnDoubleClick( Mobile from )
{
if ( from == m_Owner )
from.SendMessage(" Sta riposando profondamente.");
/* else if ( from.AccessLevel >= AccessLevel.GameMaster )
from.SendMessage("Âû íå ìîæåòå åãî ðàçáóäèòü.");
else
from.SendMessage("Âû íå ìîæåòå åãî ðàçáóäèòü.");*/
}
public override bool OnDragDrop( Mobile from, Item dropped )
{
from.SendLocalizedMessage( 1005468 ); // Me Sleepy.
return false;
}
public override bool OnDragDropInto( Mobile from, Item item, Point3D p )
{
from.SendLocalizedMessage( 1005468 ); // Me Sleepy.
return false;
}
public override bool CheckContentDisplay( Mobile from )
{
return false;
}
public override bool DisplaysContent{ get{ return false; } }
public override void OnAfterDelete()
{
if ( m_Timer != null )
m_Timer.Stop();
m_Timer = null;
//Start Edited by Vano 31.08.07. Âðåìÿ èçìåíåíèÿ 11:33
if ( m_TimerSleep != null )
m_TimerSleep.Stop();
m_TimerSleep = null;
//End Edited by Vano
// Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
if ( m_Bed != null )
m_Bed.ClearBad();
if( m_Owner != null )
{
//m_Owner.Z = this.Z;
Wake();
m_Owner.Blessed = this.m_Blessed;
}
// end Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
for( int i = 0; i < m_EquipItems.Count; i++ )
{
object o = m_EquipItems[i];
if( o != null && o is Item )
{
Item item = (Item)o;
item.Delete();
}
}
base.OnAfterDelete();
}
public SleeperBedBody( Serial serial ) : base( serial )
{
}
//Modificato per FIx
public void SendInfoTo(NetState state)
{
base.SendInfoTo(state);
if (ItemID == 0x2006)
{
state.Send(new SleeperBedBodyContent(state.Mobile, this));
state.Send(new SleeperBedBodyEquip(state.Mobile, this));
}
}
/*public override void SendInfoTo( NetState state )
{
base.SendInfoTo( state );
if ( ItemID == 0x2006 )
{
state.Send( new SleeperBedBodyContent( state.Mobile, this ) );
state.Send( new SleeperBedBodyEquip( state.Mobile, this ) );
}
}*/
// Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
/*
public override void AddNameProperty( ObjectPropertyList list )
{
if ( m_SleeperBedBodyName != null )
list.Add( m_SleeperBedBodyName );
else
list.Add( 1049644, String.Format( "Ñïÿùèé {0}", Name ) );
}
public override void OnSingleClick( Mobile from )
{
LabelTo( from, m_SleeperBedBodyName == null ? String.Format( "Ñïÿùèé {0}", Name ) : m_SleeperBedBodyName );
}
*/
public override void AddNameProperty( ObjectPropertyList list )
{
if ( m_Owner != null )
list.Add( "{0} {1}", Name, m_Owner.Name );
else
list.Add( 1049644, String.Format( "{0}", Name ) );
}
public override void OnSingleClick( Mobile from )
{
LabelTo( from, m_Owner != null ? String.Format( "{0} {1}", Name, m_Owner.Name ) : Name );
}
/*
public static string GetBodyName( Mobile m )
{
Type t = m.GetType();
object[] attrs = t.GetCustomAttributes( typeof( SleeperBedNameAttribute ), true );
if ( attrs != null && attrs.Length > 0 )
{
SleeperBedNameAttribute attr = attrs[0] as SleeperBedNameAttribute;
if ( attr != null )
return attr.Name;
}
return m.Name;
}
*/
public void Wake( bool plwake )
{
m_Pl_wake = plwake;
Delete();
}
public void Wake( )
{
try{
if(m_Owner==null) return;
// m_Owner.Hidden = false;
m_Owner.CantWalk = false;
//Edited by Vano 09.11.07. Version 1.3
m_Owner.Squelched = false;
if (m_Owner is PlayerMobile)
{
PlayerMobile pl = m_Owner as PlayerMobile;
pl.Sleeping = false;
}
//End Edited by Vano. Version 1.3
if( m_Pl_wake )
{
switch( Utility.RandomMinMax( 1, 3 ) )
{
case 1:
// m_Player.LocalOverheadMessage( MessageType.Regular, 0x33, true, "Åõõõ.. Êàê íå õî÷åòñÿ âñòàâàòü, íî ïîäâèãè íå æäóò!");
m_Owner.LocalOverheadMessage( MessageType.Regular, 0x33, false, "*Ti alzi dal letto e ti senti pieno di energie!!*");
break;
case 2:
// m_Player.LocalOverheadMessage( MessageType.Regular, 0x33, true, "Íåìíîãî ïîñïàâ ó âàñ ïîÿâèëîñü æåëàíèå ïîéòè íàäðàòü êîìó-íèáóäü çàä." );
m_Owner.LocalOverheadMessage( MessageType.Regular, 0x33, false, "*Ti alzi dal letto ,Sei pronto per un altra giornata!*" );
break;
case 3:
// m_Player.LocalOverheadMessage( MessageType.Regular, 0x33, true, "Äëÿ ïîëíîé ðàçðÿäêè âàì íå õâàòàåò êîôåéêó..." );
m_Owner.LocalOverheadMessage( MessageType.Regular, 0x33, false, "* Yawn *" );
break;
}
}
// m_Owner = null;
} catch {
Console.WriteLine( "SleeperBedBody.Wake: Ben Svegliato!" );
}
}
// end Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
// Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
// writer.Write( (int) 1 );
writer.Write( (int) 2 );
writer.Write(m_Bed);
// writer.Write( m_SleepBegin );
writer.Write(m_spell); // version 1
writer.Write(m_Owner); // version 0
// writer.Write(m_SleeperBedBodyName);
// end Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
writer.Write(m_Blessed);
writer.WriteItemList( m_EquipItems, true );
}
public override void Deserialize( GenericReader reader )
{
// m_spell = true; // Ñìûñë? Íèæå m_spell ñ÷èòûâàåòñÿ
base.Deserialize( reader );
int version = reader.ReadInt();
// Console.WriteLine( "SleeperBedBody.Deserialize: version = {0}", version );
switch( version )
{
// Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
case 2:
{
m_Bed = reader.ReadItem() as SleepableBedsAddon;
// m_SleepBegin = reader.ReadDateTime();
goto case 1;
}
/* case 2:
{
m_SleepBegin = reader.ReadDateTime();
goto case 1;
}
*/
// end Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
case 1:
{
m_spell = reader.ReadBool();
goto case 0;
}
case 0:
{
m_Owner = reader.ReadMobile();
// Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
if ( version < 2 )
m_SleeperBedBodyName = reader.ReadString();
// end Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
m_Blessed = reader.ReadBool();
m_EquipItems = reader.ReadItemList();
break;
}
}
// Delete on Server restart if spell action
// Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
// if( m_spell )
// if( !m_spell ) // Ïîñëå ðåñòàðòà òåëî óäàëÿåòñÿ, à ñïÿùèé áóäèòñÿ
// this.Delete();
PlayerMobile pm = m_Owner as PlayerMobile;
if ( pm != null && pm.Sleep >= 30)
// Wake(false);
this.Delete();
// Sleep( 60 );
else
Sleep( 60 );
// end Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
}
private void Sleep( int delay )
{
m_TimerSleep = new InternalTimerSleep( this, delay );
m_TimerSleep.Start();
}
private class InternalTimer : Timer
{
private Mobile m_Owner;
private SleeperBedBody m_Body;
private DateTime shutitoff = DateTime.Now + TimeSpan.FromSeconds(300);
public InternalTimer( SleeperBedBody body ) : base( TimeSpan.FromSeconds(20),TimeSpan.FromSeconds(20) ) //aggiunto Int delay
{
m_Owner = body.Owner;
m_Body = body;
}
protected override void OnTick() //Modificato per rigenerare le forze mentre si dorme
{
if (DateTime.Now < shutitoff)
{
if (m_Body != null)
m_Body.PublicOverheadMessage(0, m_Owner.SpeechHue, false, "*ZzZzZz*");
if (m_Owner != null)
{
m_Owner.PlaySound(m_Owner.Female ? 819 : 1093);
if (m_Owner.Hits < m_Owner.HitsMax)
{
m_Owner.Hits += (m_Owner.HitsMax / 10);
if (m_Owner.Hits > m_Owner.HitsMax)
m_Owner.Hits = m_Owner.HitsMax;
}
/* if (m_Owner.Sleep < 30)
{
m_Owner.Sleep += (m_Owner.Sleep + 1 );
}*/
if (m_Owner.Stam < m_Owner.StamMax)
{
m_Owner.Stam += (m_Owner.StamMax / 10);
if (m_Owner.Stam > m_Owner.StamMax)
m_Owner.Stam = m_Owner.StamMax;
}
if (m_Owner.Mana < m_Owner.ManaMax)
{
m_Owner.Mana += (m_Owner.ManaMax / 10);
if (m_Owner.Mana > m_Owner.ManaMax)
m_Owner.Mana = m_Owner.ManaMax;
}
}
}
else
{
Stop();
// Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
// m_Body.PublicOverheadMessage(0,m_Owner.SpeechHue, false,"Ïîãðóçèëñÿ â ãëóáîêèé ñîí.");
m_Body.PublicOverheadMessage(0, 44, false, m_Owner.Name + " si sente riposato." );
m_Body.Sleep( 60 );
// end Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
}
}
}
//Start Edited by Vano 31.08.07. Âðåìÿ èçìåíåíèÿ 11:34
private class InternalTimerSleep : Timer
{
// Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
// private Mobile m_Owner;
private SleeperBedBody m_Body;
// private DateTime shutitoff2 = DateTime.Now + TimeSpan.FromSeconds(300);//aggiunto per fixare sleep
public InternalTimerSleep( SleeperBedBody body, int delay ) : base( TimeSpan.FromSeconds(delay),TimeSpan.FromSeconds(20) )
{
// m_Owner = body.Owner;
m_Body = body;
// PlayerMobile pm = m_Body.Owner as PlayerMobile;
// Console.WriteLine( "SleeperBedBody.InternalTimerSleep: Âðåìÿ âêëþ÷åíèÿ: {1}, Sleep = {0}", pm.Sleep, DateTime.Now );
}
protected override void OnTick()
{
// if (DateTime.Now < shutitoff2) //aggiunto per fixare Sleep
{
PlayerMobile pm = null;
if(m_Body != null)
pm = m_Body.Owner as PlayerMobile;
if ( pm == null )
{
m_Body.Delete();
Stop();
}
else
{
if ( pm.Sleep < 29 )
{
pm.Sleep += 1;
// Console.WriteLine( "SleeperBedBody.InternalTimerSleep.Âðåìÿ: {1}, OnTick: Sleep = {0}", pm.Sleep, DateTime.Now );
}
else
{
if ( pm.Sleep < 30 )
pm.Sleep += 1;
// Console.WriteLine( "SleeperBedBody.InternalTimerSleep.OnTick: Ïîäú¸ì Âðåìÿ: {1}, Sleep = {0}", pm.Sleep, DateTime.Now );
// m_Body.Wake(false);
m_Body.Delete();
Stop();
}
}
}
}
// end Mod KOCTa SleepableBeds v.1.0 04.10.2008 - 07.10.2008
}
//End Edited by Vano
}
}