Fairy Lantern
Original Author Credit: Ashenfall
This was inspired by an old friend I knew once upon a time. It brought me a lot of joy and laughs and I hope it can do the same for somebody else.
God Bless,
And happy gaming.
FAIRYSHRINKITEM:
FAIRYLANTERN:
SHRINKFAIRY:
Original Author Credit: Ashenfall
This was inspired by an old friend I knew once upon a time. It brought me a lot of joy and laughs and I hope it can do the same for somebody else.
God Bless,
And happy gaming.
FAIRYSHRINKITEM:
Code:
using System;
using Server.Items;
using Server.Mobiles;
namespace Server.Items
{
public class FairyShrinkItem : Item
{
private Mobile m_BondOwner;
public Mobile BondOwner
{
get{ return m_BondOwner; }
set{ m_BondOwner = value; }
}
private BaseCreature m_link;
private bool m_toDeletePet;
public FairyShrinkItem( Serial serial ) : base( serial )
{
Light = LightType.Circle300;
Weight = 2.0;
Layer = Layer.TwoHanded;
}
/*#region Constructors
public FairyShrinkItem( Serial serial ) : base( serial )
{
}
[Constructable]
public FairyShrinkItem() : base( 0xa25 )
{
Weight = 2.0;
Layer = Layer.TwoHanded;
Light = LightType.Circle300;
}
#endregion*/
public FairyShrinkItem(BaseCreature c)
{
m_toDeletePet=true;
m_link=c;
/*if ( !(c.Body==400 || c.Body==401) )
{
Hue=c.Hue;
}*/
Name = c.Name + " [in lantern]";
//ItemID=ShrinkTable.Lookup( c );
ItemID=0xa22;
Weight = 2.0;
Layer = Layer.TwoHanded;
Light = LightType.Circle300;
}
public override void OnDoubleClick( Mobile from )
{
if ( !Movable )
return;
if( from.InRange( this.GetWorldLocation(), 2 ) == false )
{
from.SendLocalizedMessage( 500486 ); //That is too far away.
return;
}
else if ( m_link == null || m_link.Deleted )
{
from.SendMessage( "Your pet is lost forever..." );
return;
//Basically just an "In case something happened" Thing so Server don't crash.
}
else if( !from.CheckAlive() )
{
from.SendLocalizedMessage( 1060190 ); //You cannot do that while dead!
}
else if ( from.Followers + m_link.ControlSlots > from.FollowersMax )
{
from.SendMessage( "You have too many followers to unshrink that creature." );
return;
}
else
{
bool alreadyOwned = m_link.Owners.Contains( from );
if (!alreadyOwned){m_link.Owners.Add( from );}
m_link.SetControlMaster( from );
m_toDeletePet=false;
m_link.Location=from.Location;
m_link.Map=from.Map;
m_link.ControlTarget = from;
m_link.ControlOrder = OrderType.Follow;
if ( m_link.Summoned )
m_link.SummonMaster = from;
//m_link.Loyalty=PetLoyalty.WonderfullyHappy;
if ( ShrinkConfig.RetainSelfBondStatus )
{
if ( m_link.IsBonded &&(( ShrinkConfig.RetainSelfBondStatus && from == BondOwner) || ( ShrinkConfig.TransferBondingStatus )))
m_link.IsBonded = true;
else
m_link.IsBonded = false;
}
this.Delete();
Item NewLantern = new FairyLantern( );
if ( from != null )
{
from.SendMessage( "You release the creature" );
if ( !from.AddToBackpack ( NewLantern ) )
{
NewLantern.MoveToWorld( new Point3D( from.X, from.Y, from.Z ), from.Map );
from.SendMessage( "Your backpack is full so the fairy lantern falls to the ground" );
}
}
else
{
NewLantern.MoveToWorld( new Point3D( from.X, from.Y, from.Z ), from.Map ); // place lantern at current location
}
}
}
public override void OnDelete()
{
//Psuedo Code: IF todeltepet=true Delete the mobile m_link. Then delete this item regardless
try
{
if ( m_toDeletePet )
{
if ( m_link != null )
m_link.Delete();
}
}
catch
{
Console.Write( "Error with Shrunken pet: {0} is being Deleted. ItemID of: {1}.", this.Name, this.ItemID );
//Another "In case Shit hits fan" thing.
}
base.OnDelete();
}
#region Serialization
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 1 ); // version
writer.Write( m_BondOwner );
writer.Write( m_link );
writer.Write( m_toDeletePet );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
switch ( version )
{
case 1:
{
m_BondOwner = reader.ReadMobile();
goto case 0;
}
case 0:
{
m_link = (BaseCreature)reader.ReadMobile();
m_toDeletePet = reader.ReadBool();
break;
}
}
if ( m_link != null )
m_link.IsStabled = true;
}
#endregion
}
}
FAIRYLANTERN:
Code:
using System;
using Server.Items;
using Server.Mobiles;
using Server.Targeting;
namespace Server.Items
{
public class FairyLantern : Item
{
#region Constructors
public FairyLantern( Serial serial ) : base( serial )
{
}
[Constructable]
public FairyLantern() : base( 0xa25 )
{
Name="a Fairy Lantern";
Weight = 2.0;
Layer = Layer.TwoHanded;
}
#endregion
public override void OnDoubleClick( Mobile from )
{
if ( !Movable )
return;
else if( from.InRange( this.GetWorldLocation(), 2 ) == false )
{
from.SendLocalizedMessage( 500486 ); //That is too far away.
return;
}
Container pack = from.Backpack;
if ( !(Parent == from || ( pack != null && Parent == pack )) ) //If not in pack.
{
from.SendLocalizedMessage( 1042001 ); //That must be in your pack to use it.
return;
}
from.Target=new FairyLanternTarget( this );
from.SendMessage( "Target the fairy you wish to shrink" );
}
private class FairyLanternTarget : Target
{
private FairyLantern m_Potion;
public FairyLanternTarget( Item i ) : base( 3, false, TargetFlags.None )
{
m_Potion=(FairyLantern)i;
}
protected override void OnTarget( Mobile from, object targ )
{
if ( !(m_Potion.Deleted) )
{
if ( FairyShrinkFunctions.FairyShrink( from, targ ) )
{
m_Potion.Delete();
}
}
return;
}
}
#region Serialization
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();
}
#endregion
}
}
SHRINKFAIRY:
Code:
using System;
using Server;
using Server.Items;
using Server.Mobiles;
namespace Server
{
public class FairyShrinkFunctions
{
public static bool FairyShrink( Mobile from, object targ, bool restricted )
{
String errorString = null;
int errorLocalizedMessage = 0;
if ( from == targ )
errorString = "You can't shrink yourself!";
else if ( !(targ is BaseCreature) )
errorString = "You can't shrink that!";
else
{
BaseCreature t=(BaseCreature)targ;
#region Shrink Restrictions
if ( ( t is Pixie || t is DarkSprite ) )
{
if( t.IsDeadPet )
{
errorString = "You cannot shrink dead fairies.";
}
else if ( !restricted )
{
//Don't check anything if not a restricted Shrink
}
else if( t.Summoned )
{
errorString = "You cannot shrink summoned creatures.";
}
else if ( t.Combatant != null && t.InRange( t.Combatant, 12 ) && t.Map == t.Combatant.Map )
{
errorString = "You cannot shrink your fairy while it is in combat.";
}
else if (!(t.Controled && t.ControlMaster==from))
{
errorLocalizedMessage = 1042562; //That is not your pet!
errorString = "That is not your pet!";
}
else if ( (t is PackLlama || t is PackHorse || t is Beetle) && (t.Backpack != null && t.Backpack.Items.Count > 0) )
{
errorLocalizedMessage = 1042563; //Unload the pet first
errorString = "Unload the pet first";
}
}
else
{
errorString = "That is not a fairy type!";
}
#endregion
if ( (errorString==null) && ( errorLocalizedMessage == 0 ) )
{
//If no errors, proceed.
FairyShrinkItem shrunkenPet = new FairyShrinkItem( t );
shrunkenPet.Layer = Layer.TwoHanded;
if ( from != null )
{
from.SendMessage( "You shrink the pet" );
if ( !from.AddToBackpack ( shrunkenPet ) )
{
shrunkenPet.MoveToWorld( new Point3D( from.X, from.Y, from.Z ), from.Map );
from.SendMessage( "Your backpack is full so the shrunken pet falls to the ground" );
}
}
else
{
shrunkenPet.MoveToWorld( new Point3D( t.X, t.Y, t.Z ), t.Map ); // place shrunken pet at current location
}
SendAway( t );
if ( ShrinkConfig.RetainSelfBondStatus && from != null )
shrunkenPet.BondOwner = from;
return true;
}
}
if( from != null ) //if From is NOT null, send error Message.
{
if ( errorLocalizedMessage != 0 )
{
from.SendLocalizedMessage( errorLocalizedMessage );
}
else
{
from.SendMessage( errorString );
}
}
return false;
}
public static bool FairyShrink( Mobile from, object targ )
{
return FairyShrink( from, targ, true );
}
public static bool FairyShrink( object targ )
{
return FairyShrink( null, targ, false );
}
private static void SendAway( BaseCreature b )
{
b.Controled = true; //To make it so It won't still be a part of a spawner.
b.SetControlMaster( null );
b.SummonMaster = null;
b.Internalize();
if ( ShrinkConfig.ResetBondingStatus )
b.IsBonded = false;
if( !ShrinkConfig.RetainBondingTimer )
b.BondingBegin = DateTime.MinValue;
b.OwnerAbandonTime = DateTime.MinValue;
b.IsStabled = true;
}
}
}