Heritage items, talismans
This commit is contained in:
parent
e7db1fd9f7
commit
129cac945b
109 changed files with 11659 additions and 188 deletions
130
Scripts/Items/Misc/FlipableAddonAttribute.cs
Normal file
130
Scripts/Items/Misc/FlipableAddonAttribute.cs
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
using Server.Multis;
|
||||
|
||||
namespace Server.Items
|
||||
{
|
||||
[AttributeUsage( AttributeTargets.Class )]
|
||||
public class FlipableAddonAttribute : Attribute
|
||||
{
|
||||
private static string m_MethodName = "Flip";
|
||||
|
||||
private static Type[] m_Params = new Type[]
|
||||
{
|
||||
typeof( Mobile ), typeof( Direction )
|
||||
};
|
||||
|
||||
private Direction[] m_Directions;
|
||||
|
||||
public Direction[] Directions
|
||||
{
|
||||
get { return m_Directions; }
|
||||
}
|
||||
|
||||
public FlipableAddonAttribute( params Direction[] directions )
|
||||
{
|
||||
m_Directions = directions;
|
||||
}
|
||||
|
||||
public virtual void Flip( Mobile from, Item addon )
|
||||
{
|
||||
if ( m_Directions != null && m_Directions.Length > 1 )
|
||||
{
|
||||
try
|
||||
{
|
||||
MethodInfo flipMethod = addon.GetType().GetMethod( m_MethodName, m_Params );
|
||||
|
||||
if ( flipMethod != null )
|
||||
{
|
||||
int index = 0;
|
||||
|
||||
for ( int i = 0; i < m_Directions.Length; i++ )
|
||||
{
|
||||
if ( addon.Direction == m_Directions[ i ] )
|
||||
{
|
||||
index = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( index >= m_Directions.Length )
|
||||
index = 0;
|
||||
|
||||
ClearComponents( addon );
|
||||
|
||||
flipMethod.Invoke( addon, new object[ 2 ] { from, m_Directions[ index ] } );
|
||||
|
||||
BaseHouse house = null;
|
||||
AddonFitResult result = AddonFitResult.Valid;
|
||||
|
||||
addon.Map = Map.Internal;
|
||||
|
||||
if ( addon is BaseAddon )
|
||||
result = ( (BaseAddon) addon ).CouldFit( addon.Location, from.Map, from, ref house );
|
||||
else if ( addon is BaseAddonContainer )
|
||||
result = ( (BaseAddonContainer) addon ).CouldFit( addon.Location, from.Map, from, ref house );
|
||||
|
||||
addon.Map = from.Map;
|
||||
|
||||
if ( result != AddonFitResult.Valid )
|
||||
{
|
||||
if ( index == 0 )
|
||||
index = m_Directions.Length - 1;
|
||||
else
|
||||
index -= 1;
|
||||
|
||||
ClearComponents( addon );
|
||||
|
||||
flipMethod.Invoke( addon, new object[ 2 ] { from, m_Directions[ index ] } );
|
||||
|
||||
if ( result == AddonFitResult.Blocked )
|
||||
from.SendLocalizedMessage( 500269 ); // You cannot build that there.
|
||||
else if ( result == AddonFitResult.NotInHouse )
|
||||
from.SendLocalizedMessage( 500274 ); // You can only place this in a house that you own!
|
||||
else if ( result == AddonFitResult.DoorsNotClosed )
|
||||
from.SendMessage( "You must close all house doors before placing this." );
|
||||
else if ( result == AddonFitResult.DoorTooClose )
|
||||
from.SendLocalizedMessage( 500271 ); // You cannot build near the door.
|
||||
else if ( result == AddonFitResult.NoWall )
|
||||
from.SendLocalizedMessage( 500268 ); // This object needs to be mounted on something.
|
||||
}
|
||||
|
||||
addon.Direction = m_Directions[ index ];
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearComponents( Item item )
|
||||
{
|
||||
if ( item is BaseAddon )
|
||||
{
|
||||
BaseAddon addon = (BaseAddon) item;
|
||||
|
||||
foreach ( AddonComponent c in addon.Components )
|
||||
{
|
||||
c.Addon = null;
|
||||
c.Delete();
|
||||
}
|
||||
|
||||
addon.Components.Clear();
|
||||
}
|
||||
else if ( item is BaseAddonContainer )
|
||||
{
|
||||
BaseAddonContainer addon = (BaseAddonContainer) item;
|
||||
|
||||
foreach ( AddonContainerComponent c in addon.Components )
|
||||
{
|
||||
c.Addon = null;
|
||||
c.Delete();
|
||||
}
|
||||
|
||||
addon.Components.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -157,10 +157,42 @@ namespace Server.Items
|
|||
|
||||
bool isDecorableComponent = false;
|
||||
|
||||
if ( item is AddonComponent )
|
||||
if ( ((AddonComponent)item).Addon.Components.Count == 1 && Core.SE )
|
||||
if ( item is AddonComponent || item is AddonContainerComponent || item is BaseAddonContainer )
|
||||
{
|
||||
object addon = null;
|
||||
int count = 0;
|
||||
|
||||
if ( item is AddonComponent )
|
||||
{
|
||||
AddonComponent component = (AddonComponent) item;
|
||||
count = component.Addon.Components.Count;
|
||||
addon = component.Addon;
|
||||
}
|
||||
else if ( item is AddonContainerComponent )
|
||||
{
|
||||
AddonContainerComponent component = (AddonContainerComponent) item;
|
||||
count = component.Addon.Components.Count;
|
||||
addon = component.Addon;
|
||||
}
|
||||
else if ( item is BaseAddonContainer )
|
||||
{
|
||||
BaseAddonContainer container = (BaseAddonContainer) item;
|
||||
count = container.Components.Count;
|
||||
addon = container;
|
||||
}
|
||||
|
||||
if ( count == 1 && Core.SE )
|
||||
isDecorableComponent = true;
|
||||
|
||||
if ( m_Decorator.Command == DecorateCommand.Turn )
|
||||
{
|
||||
FlipableAddonAttribute[] attributes = (FlipableAddonAttribute[]) addon.GetType().GetCustomAttributes( typeof( FlipableAddonAttribute ), false );
|
||||
|
||||
if ( attributes.Length > 0 )
|
||||
isDecorableComponent = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( house == null || !house.IsCoOwner( from ) )
|
||||
{
|
||||
from.SendLocalizedMessage( 502092 ); // You must be in your house to do this.
|
||||
|
|
@ -208,10 +240,30 @@ namespace Server.Items
|
|||
|
||||
private static void Turn( Item item, Mobile from )
|
||||
{
|
||||
FlipableAttribute[] attributes = (FlipableAttribute[])item.GetType().GetCustomAttributes( typeof( FlipableAttribute ), false );
|
||||
if ( item is AddonComponent || item is AddonContainerComponent || item is BaseAddonContainer )
|
||||
{
|
||||
object addon = null;
|
||||
|
||||
if( attributes.Length > 0 )
|
||||
attributes[0].Flip( item );
|
||||
if ( item is AddonComponent )
|
||||
addon = ((AddonComponent) item).Addon;
|
||||
else if ( item is AddonContainerComponent )
|
||||
addon = ((AddonContainerComponent) item).Addon;
|
||||
else if ( item is BaseAddonContainer )
|
||||
addon = (BaseAddonContainer) item;
|
||||
|
||||
FlipableAddonAttribute[] aAttributes = (FlipableAddonAttribute[]) addon.GetType().GetCustomAttributes( typeof( FlipableAddonAttribute ), false );
|
||||
|
||||
if ( aAttributes.Length > 0 )
|
||||
{
|
||||
aAttributes[ 0 ].Flip( from, (Item) addon );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
FlipableAttribute[] attributes = (FlipableAttribute[]) item.GetType().GetCustomAttributes( typeof( FlipableAttribute ), false );
|
||||
|
||||
if ( attributes.Length > 0 )
|
||||
attributes[ 0 ].Flip( item );
|
||||
else
|
||||
from.SendLocalizedMessage( 1042273 ); // You cannot turn that.
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue