View Full Version: Interior Decorateur avancée

RunUO.FR Support > Le vivier > Interior Decorateur avancée


Title: Interior Decorateur avancée
Description: besoin de revision


jamid - June 29, 2004 11:15 PM (GMT)
:huh: j'ai trouver se script mais il ne marche pas.... j'aimerais bien en avoir un qui marche pour bouger les objets dans une maison nord, sud, est, ouest.

voila le code.

using System;
using System.Collections;
using Server;
using Server.Network;
using Server.Regions;
using Server.Multis;
using Server.Gumps;
using Server.Targeting;
using Server.ContextMenus;
using Server.Misc;
using Server.Engines.Help;

namespace Server.Items
{
public enum DecorateCommandX
{
None,
Turn,
Up,
Down,
North,
South,
East,
West
}

public class InteriorDecorator : Item
{
private DecorateCommandX m_Command;

[CommandProperty( AccessLevel.GameMaster )]
public DecorateCommandX Command{ get{ return m_Command; } set{ m_Command = value; InvalidateProperties(); } }

[Constructable]
public InteriorDecorator() : base( 0xFC1 )
{
Weight = 1.0;
LootType = LootType.Blessed;
}

public override int LabelNumber{ get{ return 1041280; } } // an interior decorator

public InteriorDecorator( Serial serial ) : base( serial )
{
}

public override void GetProperties( ObjectPropertyList list )
{
base.GetProperties( list );

if ( m_Command != DecorateCommandX.None )
list.Add( 1018322 + (int)m_Command ); // Turn/Up/Down
}

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 override void OnDoubleClick( Mobile from )
{
if ( !CheckUse( this, from ) )
return;

if ( m_Command == DecorateCommandX.None )
from.SendGump( new InternalGump( this ) );
else
from.Target = new InternalTarget( this );
}

public static bool InHouse( Mobile from )
{
BaseHouse house = BaseHouse.FindHouseAt( from );

return ( house != null && house.IsCoOwner( from ) );
}

public static bool CheckUse( InteriorDecorator tool, Mobile from )
{
/*if ( tool.Deleted || !tool.IsChildOf( from.Backpack ) )
from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it.
else*/
if ( !InHouse( from ) )
from.SendLocalizedMessage( 502092 ); // You must be in your house to do this.
else
return true;

return false;
}

private class InternalGump : Gump
{
private InteriorDecorator m_Decorator;

public InternalGump( InteriorDecorator decorator ) : base( 150, 50 )
{
m_Decorator = decorator;

AddBackground( 0, 0, 200, 400, 2600 );

AddButton( 50, 45, 2152, 2154, 1, GumpButtonType.Reply, 0 );
AddHtmlLocalized( 90, 50, 70, 40, 1018323, false, false ); // Turn

AddButton( 50, 95, 2152, 2154, 2, GumpButtonType.Reply, 0 );
AddHtmlLocalized( 90, 100, 70, 40, 1018324, false, false ); // Up

AddButton( 50, 145, 2152, 2154, 3, GumpButtonType.Reply, 0 );
AddHtmlLocalized( 90, 150, 70, 40, 1018325, false, false ); // Down

AddButton( 50, 195, 2152, 2154, 4, GumpButtonType.Reply, 0 );
AddHtml( 90, 200, 70, 40, "North", false, false ); // north

AddButton( 50, 245, 2152, 2154, 5, GumpButtonType.Reply, 0 );
AddHtml( 90, 250, 70, 40, "South", false, false ); // south

AddButton( 50, 295, 2152, 2154, 6, GumpButtonType.Reply, 0 );
AddHtml( 90, 300, 70, 40, "East", false, false ); // east

AddButton( 50, 345, 2152, 2154, 7, GumpButtonType.Reply, 0 );
AddHtml( 90, 350, 70, 40, "West", false, false ); // west

}

public override void OnResponse( NetState sender, RelayInfo info )
{
DecorateCommandX command = DecorateCommandX.None;

switch ( info.ButtonID )
{
case 1: command = DecorateCommandX.Turn; break;
case 2: command = DecorateCommandX.Up; break;
case 3: command = DecorateCommandX.Down; break;
case 4: command = DecorateCommandX.North; break;
case 5: command = DecorateCommandX.South; break;
case 6: command = DecorateCommandX.East; break;
case 7: command = DecorateCommandX.West; break;
}

if ( command != DecorateCommandX.None )
{
m_Decorator.Command = command;
sender.Mobile.Target = new InternalTarget( m_Decorator );
}
}
}

private class InternalTarget : Target
{

private InteriorDecorator m_Decorator;

public InternalTarget( InteriorDecorator decorator ) : base( -1, false, TargetFlags.None )
{
CheckLOS = false;

m_Decorator = decorator;
}

protected override void OnTargetNotAccessible( Mobile from, object targeted )
{
OnTarget( from, targeted );
}

protected override void OnTarget( Mobile from, object targeted )
{
if ( targeted == m_Decorator )
{
m_Decorator.Command = DecorateCommandX.None;
from.SendGump( new InternalGump( m_Decorator ) );
}
else if ( targeted is Item && InteriorDecorator.CheckUse( m_Decorator, from ) )
{
BaseHouse house = BaseHouse.FindHouseAt( from );
Item item = (Item)targeted;

if ( house == null || !house.IsCoOwner( from ) )
{
from.SendLocalizedMessage( 502092 ); // You must be in your house to do this.
}
else if ( item.Parent != null || !house.IsInside( item ) )
{
from.SendLocalizedMessage( 1042270 ); // That is not in your house.
}
else if ( !house.IsLockedDown( item ) && !house.IsSecure( item ) )
{
from.SendLocalizedMessage( 1042271 ); // That is not locked down.
}
else if ( item.TotalWeight + item.PileWeight > 100000 )
{
from.SendLocalizedMessage( 1042272 ); // That is too heavy.
}
else
{
switch ( m_Decorator.Command )
{
case DecorateCommandX.Up: Up( item, from ); break;
case DecorateCommandX.Down: Down( item, from ); break;
case DecorateCommandX.Turn: Turn( item, from ); break;
case DecorateCommandX.North: North( item, from ); break;
case DecorateCommandX.South: South( item, from ); break;
case DecorateCommandX.East: East( item, from ); break;
case DecorateCommandX.West: West( item, from ); break;
}
}
}
}

private static void Turn( Item item, Mobile from )
{
FlipableAttribute[] attributes = (FlipableAttribute[])item.GetType().GetCustomAttributes( typeof( FlipableAttribute ), false );

attributes[0].Flip( item );
}

private static void Up( Item item, Mobile from )
{
int floorZ = GetFloorZ( item );

if ( floorZ > int.MinValue && item.Z < (floorZ + 15) ) // Confirmed : no height checks here
item.Location = new Point3D( item.Location, item.Z + 1 );
else
from.SendLocalizedMessage( 1042274 ); // You cannot raise it up any higher.
}

private static void Down( Item item, Mobile from )
{
int floorZ = GetFloorZ( item );

if ( floorZ > int.MinValue && item.Z > GetFloorZ( item ) )

item.Location = new Point3D( item.Location, item.Z - 1 );


else
from.SendLocalizedMessage( 1042275 ); // You cannot lower it down any further.
}

private static void North( Item item, Mobile from )
{
string notice;

int floorY = GetFloorY( item );

if ( floorY > int.MinValue && item.Y > GetFloorY( item ))
item.Location = new Point3D(item.X + 0, item.Y + 1, item.Z + 0 );
}

private static void South( Item item, Mobile from )
{

int floorY = GetFloorZ( item );

if ( floorY > int.MinValue && item.Y > GetFloorZ( item ) )
item.Location = new Point3D( item.Location, item.Y + 1 );
}

private static void East( Item item, Mobile from )
{

int floorX = GetFloorZ( item );

if ( floorX > int.MinValue && item.X > GetFloorZ( item ) )
item.Location = new Point3D( item.Location, item.X + 1 );
}

private static void West( Item item, Mobile from )
{

int floorX = GetFloorZ( item );

if ( floorX > int.MinValue && item.X > GetFloorZ( item ) )
item.Location = new Point3D( item.Location, item.X - 1 );
}

private static int GetFloorZ( Item item )
{
Map map = item.Map;

if ( map == null )
return int.MinValue;

Tile[] tiles = map.Tiles.GetStaticTiles( item.X, item.Y, true );

int z = int.MinValue;

/*for ( int i = 0; i < tiles.Length; ++i )
{
Tile tile = tiles[i];
ItemData id = TileData.ItemTable[tile.ID & 0x3FFF];

int top = tile.Z; // Confirmed : no height checks here

if ( id.Surface && !id.Impassable && top > z && top <= item.Z )
z = top;
}*/
return z;
}

private static int GetFloorX( Item item )
{
Map map = item.Map;

if ( map == null )
return int.MinValue;

Tile[] tiles = map.Tiles.GetStaticTiles( item.X, item.Y, true );

int x = int.MinValue;

/*for ( int i = 0; i < tiles.Length; ++i )
{
Tile tile = tiles[i];
ItemData id = TileData.ItemTable[tile.ID & 0x3FFF];

int top = tile.X; // Confirmed : no height checks here

if ( id.Surface && !id.Impassable > item.Y )
g = top;
}*/
return x;
}

private static int GetFloorY( Item item )
{
Map map = item.Map;

if ( map == null )
return int.MinValue;

Tile[] tiles = map.Tiles.GetStaticTiles( item.X, item.Y, true );

int y = int.MinValue;

/*for ( int i = 0; i < tiles.Length; ++i )
{
Tile tile = tiles[i];
ItemData id = TileData.ItemTable[tile.ID & 0x3FFF];

int top = tile.Y; // Confirmed : no height checks here

if ( id.Surface && !id.Impassable > item.Z )
y = top;
}*/
return y;
}
}
}

}


SVP aider moi a le faire marcher

Injall - June 29, 2004 11:42 PM (GMT)
L'erreur c'est quoi?

Ah un conseil, pour les scripts
CODE
utilise [CODE] c'est plus lisible :)

jamid - June 30, 2004 09:52 PM (GMT)
CODE
using System;
using System.Collections;
using Server;
using Server.Network;
using Server.Regions;
using Server.Multis;
using Server.Gumps;
using Server.Targeting;
using Server.ContextMenus;
using Server.Misc;
using Server.Engines.Help;

namespace Server.Items
{
public enum DecorateCommandX
{
 None,
 Turn,
 Up,
 Down,
 North,
 South,
 East,
 West
}

public class InteriorDecorator : Item
{
 private DecorateCommandX m_Command;

 [CommandProperty( AccessLevel.GameMaster )]
 public DecorateCommandX Command{ get{ return m_Command; } set{ m_Command = value; InvalidateProperties(); } }

 [Constructable]
 public InteriorDecorator() : base( 0xFC1 )
 {
  Weight = 1.0;
  LootType = LootType.Blessed;
 }

 public override int LabelNumber{ get{ return 1041280; } } // an interior decorator

 public InteriorDecorator( Serial serial ) : base( serial )
 {
 }

 public override void GetProperties( ObjectPropertyList list )
 {
  base.GetProperties( list );

  if ( m_Command != DecorateCommandX.None )
   list.Add( 1018322 + (int)m_Command ); // Turn/Up/Down
 }

 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 override void OnDoubleClick( Mobile from )
 {
  if ( !CheckUse( this, from ) )
   return;

  if ( m_Command == DecorateCommandX.None )
   from.SendGump( new InternalGump( this ) );
  else
   from.Target = new InternalTarget( this );
 }

 public static bool InHouse( Mobile from )
 {
  BaseHouse house = BaseHouse.FindHouseAt( from );

  return ( house != null && house.IsCoOwner( from ) );
 }

 public static bool CheckUse( InteriorDecorator tool, Mobile from )
 {
  /*if ( tool.Deleted || !tool.IsChildOf( from.Backpack ) )
   from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it.
  else*/
  if ( !InHouse( from ) )
   from.SendLocalizedMessage( 502092 ); // You must be in your house to do this.
  else
   return true;

  return false;
 }

 private class InternalGump : Gump
 {
  private InteriorDecorator m_Decorator;

  public InternalGump( InteriorDecorator decorator ) : base( 150, 50 )
  {
   m_Decorator = decorator;

   AddBackground( 0, 0, 200, 400, 2600 );

   AddButton( 50, 45, 2152, 2154, 1, GumpButtonType.Reply, 0 );
   AddHtmlLocalized( 90, 50, 70, 40, 1018323, false, false ); // Turn

   AddButton( 50, 95, 2152, 2154, 2, GumpButtonType.Reply, 0 );
   AddHtmlLocalized( 90, 100, 70, 40, 1018324, false, false ); // Up

   AddButton( 50, 145, 2152, 2154, 3, GumpButtonType.Reply, 0 );
   AddHtmlLocalized( 90, 150, 70, 40, 1018325, false, false ); // Down

   AddButton( 50, 195, 2152, 2154, 4, GumpButtonType.Reply, 0 );
   AddHtml( 90, 200, 70, 40, "North", false, false ); // north

   AddButton( 50, 245, 2152, 2154, 5, GumpButtonType.Reply, 0 );
   AddHtml( 90, 250, 70, 40, "South", false, false ); // south

   AddButton( 50, 295, 2152, 2154, 6, GumpButtonType.Reply, 0 );
   AddHtml( 90, 300, 70, 40, "East", false, false ); // east

   AddButton( 50, 345, 2152, 2154, 7, GumpButtonType.Reply, 0 );
   AddHtml( 90, 350, 70, 40, "West", false, false ); // west

  }

  public override void OnResponse( NetState sender, RelayInfo info )
  {
   DecorateCommandX command = DecorateCommandX.None;

   switch ( info.ButtonID )
   {
    case 1: command = DecorateCommandX.Turn; break;
    case 2: command = DecorateCommandX.Up; break;
    case 3: command = DecorateCommandX.Down; break;
    case 4: command = DecorateCommandX.North; break;
    case 5: command = DecorateCommandX.South; break;
    case 6: command = DecorateCommandX.East; break;
    case 7: command = DecorateCommandX.West; break;
   }

   if ( command != DecorateCommandX.None )
   {
    m_Decorator.Command = command;
    sender.Mobile.Target = new InternalTarget( m_Decorator );
   }
  }
 }

 private class InternalTarget : Target
 {

  private InteriorDecorator m_Decorator;

  public InternalTarget( InteriorDecorator decorator ) : base( -1, false, TargetFlags.None )
  {
   CheckLOS = false;

   m_Decorator = decorator;
  }

  protected override void OnTargetNotAccessible( Mobile from, object targeted )
  {
   OnTarget( from, targeted );
  }

  protected override void OnTarget( Mobile from, object targeted )
  {
   if ( targeted == m_Decorator )
   {
    m_Decorator.Command = DecorateCommandX.None;
    from.SendGump( new InternalGump( m_Decorator ) );
   }
   else if ( targeted is Item && InteriorDecorator.CheckUse( m_Decorator, from ) )
   {
    BaseHouse house = BaseHouse.FindHouseAt( from );
    Item item = (Item)targeted;

    if ( house == null || !house.IsCoOwner( from ) )
    {
     from.SendLocalizedMessage( 502092 ); // You must be in your house to do this.
    }
    else if ( item.Parent != null || !house.IsInside( item ) )
    {
     from.SendLocalizedMessage( 1042270 ); // That is not in your house.
    }
    else if ( !house.IsLockedDown( item ) && !house.IsSecure( item ) )
    {
     from.SendLocalizedMessage( 1042271 ); // That is not locked down.
    }
    else if ( item.TotalWeight + item.PileWeight > 100000 )
    {
     from.SendLocalizedMessage( 1042272 ); // That is too heavy.
    }
    else
    {
     switch ( m_Decorator.Command )
     {
      case DecorateCommandX.Up: Up( item, from ); break;
      case DecorateCommandX.Down: Down( item, from ); break;
      case DecorateCommandX.Turn: Turn( item, from ); break;
      case DecorateCommandX.North: North( item, from ); break;
      case DecorateCommandX.South: South( item, from ); break;
      case DecorateCommandX.East: East( item, from ); break;
      case DecorateCommandX.West: West( item, from ); break;
     }
    }
   }
  }

  private static void Turn( Item item, Mobile from )
  {
   FlipableAttribute[] attributes = (FlipableAttribute[])item.GetType().GetCustomAttributes( typeof( FlipableAttribute ), false );

    attributes[0].Flip( item );
  }

  private static void Up( Item item, Mobile from )
  {
   int floorZ = GetFloorZ( item );

   if ( floorZ > int.MinValue && item.Z < (floorZ + 15) ) // Confirmed : no height checks here
    item.Location = new Point3D( item.Location, item.Z + 1 );
   else
    from.SendLocalizedMessage( 1042274 ); // You cannot raise it up any higher.
  }

  private static void Down( Item item, Mobile from )
  {
   int floorZ = GetFloorZ( item );

   if ( floorZ > int.MinValue && item.Z > GetFloorZ( item ) )
   
                                 item.Location = new Point3D( item.Location, item.Z - 1 );
                                       
                               
   else
    from.SendLocalizedMessage( 1042275 ); // You cannot lower it down any further.
  }

  private static void North( Item item, Mobile from )
  {
                               string notice;

   int floorY = GetFloorY( item );

   if ( floorY > int.MinValue && item.Y > GetFloorY( item ))
                                   item.Location = new Point3D(item.X + 0, item.Y + 1, item.Z + 0 );
  }

  private static void South( Item item, Mobile from )
  {

   int floorY = GetFloorZ( item );

   if ( floorY > int.MinValue && item.Y > GetFloorZ( item ) )
    item.Location = new Point3D(  item.Location, item.Y + 1 );
  }

  private static void East( Item item, Mobile from )
  {

   int floorX = GetFloorZ( item );

   if ( floorX > int.MinValue && item.X > GetFloorZ( item ) )
    item.Location = new Point3D( item.Location, item.X + 1 );
  }

  private static void West( Item item, Mobile from )
  {

   int floorX = GetFloorZ( item );

   if ( floorX > int.MinValue && item.X > GetFloorZ( item ) )
    item.Location = new Point3D(  item.Location, item.X - 1 );
  }

  private static int GetFloorZ( Item item )
  {
   Map map = item.Map;

   if ( map == null )
    return int.MinValue;

   Tile[] tiles = map.Tiles.GetStaticTiles( item.X, item.Y, true );

   int z = int.MinValue;

   /*for ( int i = 0; i < tiles.Length; ++i )
   {
    Tile tile = tiles[i];
    ItemData id = TileData.ItemTable[tile.ID & 0x3FFF];

    int top = tile.Z; // Confirmed : no height checks here

    if ( id.Surface && !id.Impassable && top > z && top <= item.Z )
     z = top;
   }*/
   return z;
                       }

  private static int GetFloorX( Item item )
  {
   Map map = item.Map;

   if ( map == null )
    return int.MinValue;

   Tile[] tiles = map.Tiles.GetStaticTiles( item.X, item.Y, true );

   int x = int.MinValue;

   /*for ( int i = 0; i < tiles.Length; ++i )
   {
    Tile tile = tiles[i];
    ItemData id = TileData.ItemTable[tile.ID & 0x3FFF];

    int top = tile.X; // Confirmed : no height checks here

    if ( id.Surface && !id.Impassable  > item.Y )
     g = top;
   }*/
   return x;
  }

  private static int GetFloorY( Item item )
  {
   Map map = item.Map;

   if ( map == null )
    return int.MinValue;

   Tile[] tiles = map.Tiles.GetStaticTiles( item.X, item.Y, true );

   int y = int.MinValue;

   /*for ( int i = 0; i < tiles.Length; ++i )
   {
    Tile tile = tiles[i];
    ItemData id = TileData.ItemTable[tile.ID & 0x3FFF];

    int top = tile.Y; // Confirmed : no height checks here

    if ( id.Surface && !id.Impassable  > item.Z )
     y = top;
   }*/
   return y;
   }
              }
}

}



l'erreur c'est que les bouton north sud est west marche pas sa bouge rien... et je sais pas trop quoi faire avec sa......

Didi - July 1, 2004 08:04 PM (GMT)
essai sa

CODE
using System;
using System.Collections;
using Server;
using Server.Network;
using Server.Regions;
using Server.Multis;
using Server.Gumps;
using Server.Targeting;
using Server.ContextMenus;
using Server.Misc;
using Server.Engines.Help;

namespace Server.Items
{
public enum DecorateCommandX
{
 None,
 Turn,
 Up,
 Down,
 North,
 South,
 East,
 West
}

public class InteriorDecorator : Item
{
 private DecorateCommandX m_Command;

 [CommandProperty( AccessLevel.GameMaster )]
 public DecorateCommandX Command{ get{ return m_Command; } set{ m_Command = value; InvalidateProperties(); } }

 [Constructable]
 public InteriorDecorator() : base( 0xFC1 )
 {
  Weight = 1.0;
  LootType = LootType.Blessed;
 }

 public override int LabelNumber{ get{ return 1041280; } } // an interior decorator

 public InteriorDecorator( Serial serial ) : base( serial )
 {
 }

 public override void GetProperties( ObjectPropertyList list )
 {
  base.GetProperties( list );

  if ( m_Command != DecorateCommandX.None )
   list.Add( 1018322 + (int)m_Command ); // Turn/Up/Down
 }

 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 override void OnDoubleClick( Mobile from )
 {
  if ( !CheckUse( this, from ) )
   return;

  if ( m_Command == DecorateCommandX.None )
   from.SendGump( new InternalGump( this ) );
  else
   from.Target = new InternalTarget( this );
 }

 public static bool InHouse( Mobile from )
 {
  BaseHouse house = BaseHouse.FindHouseAt( from );

  return ( house != null && house.IsCoOwner( from ) );
 }

 public static bool CheckUse( InteriorDecorator tool, Mobile from )
 {
  /*if ( tool.Deleted || !tool.IsChildOf( from.Backpack ) )
   from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it.
  else*/
  if ( !InHouse( from ) )
   from.SendLocalizedMessage( 502092 ); // You must be in your house to do this.
  else
   return true;

  return false;
 }

 private class InternalGump : Gump
 {
  private InteriorDecorator m_Decorator;

  public InternalGump( InteriorDecorator decorator ) : base( 150, 50 )
  {
   m_Decorator = decorator;

   AddBackground( 0, 0, 200, 400, 2600 );

   AddButton( 50, 45, 2152, 2154, 1, GumpButtonType.Reply, 0 );
   AddHtmlLocalized( 90, 50, 70, 40, 1018323, false, false ); // Turn

   AddButton( 50, 95, 2152, 2154, 2, GumpButtonType.Reply, 0 );
   AddHtmlLocalized( 90, 100, 70, 40, 1018324, false, false ); // Up

   AddButton( 50, 145, 2152, 2154, 3, GumpButtonType.Reply, 0 );
   AddHtmlLocalized( 90, 150, 70, 40, 1018325, false, false ); // Down

   AddButton( 50, 195, 2152, 2154, 4, GumpButtonType.Reply, 0 );
   AddHtml( 90, 200, 70, 40, "North", false, false ); // north

   AddButton( 50, 245, 2152, 2154, 5, GumpButtonType.Reply, 0 );
   AddHtml( 90, 250, 70, 40, "South", false, false ); // south

   AddButton( 50, 295, 2152, 2154, 6, GumpButtonType.Reply, 0 );
   AddHtml( 90, 300, 70, 40, "East", false, false ); // east

   AddButton( 50, 345, 2152, 2154, 7, GumpButtonType.Reply, 0 );
   AddHtml( 90, 350, 70, 40, "West", false, false ); // west

  }

  public override void OnResponse( NetState sender, RelayInfo info )
  {
   DecorateCommandX command = DecorateCommandX.None;

   switch ( info.ButtonID )
   {
    case 1: command = DecorateCommandX.Turn; break;
    case 2: command = DecorateCommandX.Up; break;
    case 3: command = DecorateCommandX.Down; break;
    case 4: command = DecorateCommandX.North; break;
    case 5: command = DecorateCommandX.South; break;
    case 6: command = DecorateCommandX.East; break;
    case 7: command = DecorateCommandX.West; break;
   }

   if ( command != DecorateCommandX.None )
   {
    m_Decorator.Command = command;
    sender.Mobile.Target = new InternalTarget( m_Decorator );
   }
  }
 }

 private class InternalTarget : Target
 {

  private InteriorDecorator m_Decorator;

  public InternalTarget( InteriorDecorator decorator ) : base( -1, false, TargetFlags.None )
  {
   CheckLOS = false;

   m_Decorator = decorator;
  }

  protected override void OnTargetNotAccessible( Mobile from, object targeted )
  {
   OnTarget( from, targeted );
  }

  protected override void OnTarget( Mobile from, object targeted )
  {
   if ( targeted == m_Decorator )
   {
    m_Decorator.Command = DecorateCommandX.None;
    from.SendGump( new InternalGump( m_Decorator ) );
   }
   else if ( targeted is Item && InteriorDecorator.CheckUse( m_Decorator, from ) )
   {
    BaseHouse house = BaseHouse.FindHouseAt( from );
    Item item = (Item)targeted;

    if ( house == null || !house.IsCoOwner( from ) )
    {
     from.SendLocalizedMessage( 502092 ); // You must be in your house to do this.
    }
    else if ( item.Parent != null || !house.IsInside( item ) )
    {
     from.SendLocalizedMessage( 1042270 ); // That is not in your house.
    }
    else if ( !house.IsLockedDown( item ) && !house.IsSecure( item ) )
    {
     from.SendLocalizedMessage( 1042271 ); // That is not locked down.
    }
    else if ( item.TotalWeight + item.PileWeight > 100000 )
    {
     from.SendLocalizedMessage( 1042272 ); // That is too heavy.
    }
    else
    {
     switch ( m_Decorator.Command )
     {
      case DecorateCommandX.Up: Up( item, from ); break;
      case DecorateCommandX.Down: Down( item, from ); break;
      case DecorateCommandX.Turn: Turn( item, from ); break;
      case DecorateCommandX.North: North( item, from ); break;
      case DecorateCommandX.South: South( item, from ); break;
      case DecorateCommandX.East: East( item, from ); break;
      case DecorateCommandX.West: West( item, from ); break;
     }
    }
   }
  }

  private static void Turn( Item item, Mobile from )
  {
   FlipableAttribute[] attributes = (FlipableAttribute[])item.GetType().GetCustomAttributes( typeof( FlipableAttribute ), false );

    attributes[0].Flip( item );
  }

  private static void Up( Item item, Mobile from )
  {
   int floorZ = GetFloorZ( item );

   if ( floorZ > int.MinValue && item.Z < (floorZ + 15) ) // Confirmed : no height checks here
    item.Location = new Point3D( item.Location, item.Z + 1 );
   else
    from.SendLocalizedMessage( 1042274 ); // You cannot raise it up any higher.
  }

  private static void Down( Item item, Mobile from )
  {
   int floorZ = GetFloorZ( item );

   if ( floorZ > int.MinValue && item.Z > GetFloorZ( item ) )
   
                                 item.Location = new Point3D( item.Location, item.Z - 1 );
                                       
                               
   else
    from.SendLocalizedMessage( 1042275 ); // You cannot lower it down any further.
  }

  private static void North( Item item, Mobile from )
  {
                               string notice;

   int floorY = GetFloorY( item );

   if ( floorY > int.MinValue && item.Y > GetFloorY( item ))
                                   item.Location = new Point3D(item.X + 0, item.Y - 1, item.Z + 0 );
  }

  private static void South( Item item, Mobile from )
  {

   int floorY = GetFloorY( item );

   if ( floorY > int.MinValue && item.Y > GetFloorY( item ) )
    item.Location = new Point3D(  item.Location, item.Y + 1 );
  }

  private static void East( Item item, Mobile from )
  {

   int floorX = GetFloorX( item );

   if ( floorX > int.MinValue && item.X > GetFloorX( item ) )
    item.Location = new Point3D( item.Location, item.X +1 );
  }

  private static void West( Item item, Mobile from )
  {

   int floorX = GetFloorX( item );

   if ( floorX > int.MinValue && item.X > GetFloorX( item ) )
    item.Location = new Point3D(  item.Location, item.X - 1 );
  }

  private static int GetFloorZ( Item item )
  {
   Map map = item.Map;

   if ( map == null )
    return int.MinValue;

   Tile[] tiles = map.Tiles.GetStaticTiles( item.X, item.Y, true );

   int z = int.MinValue;

   /*for ( int i = 0; i < tiles.Length; ++i )
   {
    Tile tile = tiles[i];
    ItemData id = TileData.ItemTable[tile.ID & 0x3FFF];

    int top = tile.Z; // Confirmed : no height checks here

    if ( id.Surface && !id.Impassable && top > z && top <= item.Z )
     z = top;
   }*/
   return z;
                       }

  private static int GetFloorX( Item item )
  {
   Map map = item.Map;

   if ( map == null )
    return int.MinValue;

   Tile[] tiles = map.Tiles.GetStaticTiles( item.X, item.Y, true );

   int x = int.MinValue;

   /*for ( int i = 0; i < tiles.Length; ++i )
   {
    Tile tile = tiles[i];
    ItemData id = TileData.ItemTable[tile.ID & 0x3FFF];

    int top = tile.X; // Confirmed : no height checks here

    if ( id.Surface && !id.Impassable  > item.Y )
     g = top;
   }*/
   return x;
  }

  private static int GetFloorY( Item item )
  {
   Map map = item.Map;

   if ( map == null )
    return int.MinValue;

   Tile[] tiles = map.Tiles.GetStaticTiles( item.X, item.Y, true );

   int y = int.MinValue;

   /*for ( int i = 0; i < tiles.Length; ++i )
   {
    Tile tile = tiles[i];
    ItemData id = TileData.ItemTable[tile.ID & 0x3FFF];

    int top = tile.Y; // Confirmed : no height checks here

    if ( id.Surface && !id.Impassable  > item.Z )
     y = top;
   }*/
   return y;
   }
              }
}

}

jamid - July 2, 2004 02:12 AM (GMT)
Sa marche toujours pas tu tout pour Nort, sud , est west.....

Didi - July 2, 2004 06:51 PM (GMT)
hum, cé pas le meilleur, mais sa fonctionne.

CODE
using System;
using Server;
using Server.Network;
using Server.Regions;
using Server.Multis;
using Server.Gumps;
using Server.Targeting;

namespace Server.Items
{
public enum DecorateCommand
{
 None,
 Rotation,
 Haut,
 Bas,
 Nord,
 Sud,
 Est,
 Ouest
}

public class InteriorDecorator : Item
{
 private DecorateCommand m_Command;
 private string[] FeKwa = new string[]
 {
  "None",
  "Rotation",
  "Haut",
  "Bas",
  "Nord",
  "Sud",
  "Est",
  "Ouest"
 };

 [CommandProperty( AccessLevel.GameMaster )]
 public DecorateCommand Command{ get{ return m_Command; } set{ m_Command = value; InvalidateProperties(); } }

 [Constructable]
 public InteriorDecorator() : base( 0xFC1 )
 {
  Weight = 1.0;
  LootType = LootType.Blessed;
 }

 public override int LabelNumber{ get{ return 1041280; } } // an interior decorator

 public InteriorDecorator( Serial serial ) : base( serial )
 {
 }

 public override void GetProperties( ObjectPropertyList list )
 {
  base.GetProperties( list );
  int c = (int)m_Command;
  if (c > 0)
   list.Add(FeKwa[c]);
 }

 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 override void OnDoubleClick( Mobile from )
 {
  if ( !CheckUse( this, from ) )
   return;

  if ( m_Command == DecorateCommand.None )
   from.SendGump( new InternalGump( this ) );
  else
   from.Target = new InternalTarget( this );
 }

 public static bool InHouse( Mobile from )
 {
  BaseHouse house = BaseHouse.FindHouseAt( from );

  return ( house != null && house.IsCoOwner( from ) );
 }

 public static bool CheckUse( InteriorDecorator tool, Mobile from )
 {
  /*if ( tool.Deleted || !tool.IsChildOf( from.Backpack ) )
   from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it.
  else*/
  if ( !InHouse( from ) )
   from.SendLocalizedMessage( 502092 ); // You must be in your house to do this.
  else
   return true;

  return false;
 }

 private class InternalGump : Gump
 {
  private InteriorDecorator m_Decorator;

  private string[] FeKwa = new string[]
  {
  "None",
  "Rotation",
  "Haut",
  "Bas",
  "Nord",
  "Sud",
  "Est",
  "Ouest"
  };

  public InternalGump( InteriorDecorator decorator ) : base( 150, 50 )
  {
   m_Decorator = decorator;

   AddBackground( 0, 0, 200, 260, 2600 );

   for( int i = 1; i <= 7; ++i )
   {
    AddButton( 50, (30*i)-5, 2152, 2154, i, GumpButtonType.Reply, 0 );
    AddLabel( 90, 30*i, 0, m_Decorator.FeKwa[i] );    
   }
  }

  public override void OnResponse( NetState sender, RelayInfo info )
  {
   DecorateCommand command = DecorateCommand.None;

   switch ( info.ButtonID )
   {
    case 1: command = DecorateCommand.Rotation; break;
    case 2: command = DecorateCommand.Haut; break;
    case 3: command = DecorateCommand.Bas; break;
    case 4: command = DecorateCommand.Nord; break;
    case 5: command = DecorateCommand.Sud; break;
    case 6: command = DecorateCommand.Est; break;
    case 7: command = DecorateCommand.Ouest; break;
   }

   if ( command != DecorateCommand.None )
   {
    m_Decorator.Command = command;
    sender.Mobile.Target = new InternalTarget( m_Decorator );
   }
  }
 }

 private class InternalTarget : Target
 {
  private InteriorDecorator m_Decorator;

  public InternalTarget( InteriorDecorator decorator ) : base( -1, false, TargetFlags.None )
  {
   CheckLOS = false;

   m_Decorator = decorator;
  }

  protected override void OnTargetNotAccessible( Mobile from, object targeted )
  {
   OnTarget( from, targeted );
  }

  protected override void OnTarget( Mobile from, object targeted )
  {
   if ( targeted == m_Decorator )
   {
    m_Decorator.Command = DecorateCommand.None;
    from.SendGump( new InternalGump( m_Decorator ) );
   }
   else if ( targeted is Item && InteriorDecorator.CheckUse( m_Decorator, from ) )
   {
    BaseHouse house = BaseHouse.FindHouseAt( from );
    Item item = (Item)targeted;

    if ( house == null || !house.IsCoOwner( from ) )
    {
     from.SendLocalizedMessage( 502092 ); // You must be in your house to do this.
    }
    else if ( item.Parent != null || !house.IsInside( item ) )
    {
     from.SendLocalizedMessage( 1042270 ); // That is not in your house.
    }
    else if ( !house.IsLockedDown( item ) && !house.IsSecure( item ) )
    {
     from.SendLocalizedMessage( 1042271 ); // That is not locked down.
    }
    else if ( item.TotalWeight + item.PileWeight > 100 )
    {
     from.SendLocalizedMessage( 1042272 ); // That is too heavy.
    }
    else
    {
     switch ( m_Decorator.Command )
     {
      case DecorateCommand.Haut:  UpDown( item, from, true );  break;
      case DecorateCommand.Bas:  UpDown( item, from, false ); break;
      case DecorateCommand.Rotation: Turn( item, from );    break;
      case DecorateCommand.Nord:  NordSud( item, from, true ); break;
      case DecorateCommand.Sud:  NordSud( item, from, false ); break;
      case DecorateCommand.Est:  EstOuest( item, from, false ); break;
      case DecorateCommand.Ouest:  EstOuest( item, from, true ); break;

     }
    }
   }
  }

  private static void Turn( Item item, Mobile from )
  {
   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.
  }

  private static void UpDown( Item item, Mobile from, bool Up )
  {
   int floorZ = GetFloorZ( item );

   if ( floorZ > int.MinValue && item.Z < (floorZ + 15) && Up ) // Confirmed : no height checks here
    item.Location = new Point3D( item.Location, item.Z + 1 );
   else if ( floorZ > int.MinValue && item.Z > GetFloorZ( item ) && !Up ) // Confirmed : no height checks here
    item.Location = new Point3D( item.Location, item.Z - 1 );
   else
    from.SendLocalizedMessage( (Up ? 1042274 : 1042275) ); // You cannot raise it up any higher.
  }
 
  private static void NordSud( Item item, Mobile from, bool Nord )
  {
 
   Point3D newloc = new Point3D( item.X, item.Y+(Nord?-1:1), item.Z );
   BaseHouse lasthouse = BaseHouse.FindHouseAt( item );
   BaseHouse newhouse = BaseHouse.FindHouseAt( newloc, item.Map, 16 );
   if (lasthouse != newhouse)
   {
    from.SendMessage("Action Impossible");
   }
   else
   {
    item.Location = newloc;
   }
  }

  private static void EstOuest( Item item, Mobile from, bool Ouest )
  {
   
   Point3D newloc = new Point3D( item.X+(Ouest?-1:1), item.Y, item.Z );
   BaseHouse lasthouse = BaseHouse.FindHouseAt( item );
   BaseHouse newhouse = BaseHouse.FindHouseAt( newloc, item.Map, 16 );
   if (lasthouse != newhouse)
   {
    from.SendMessage("Action Impossible");
   }
   else
   {
    item.Location = newloc;
   }
  }
 
  private static int GetFloorZ( Item item )
  {
   Map map = item.Map;

   if ( map == null )
    return int.MinValue;

   Tile[] tiles = map.Tiles.GetStaticTiles( item.X, item.Y, true );

   int z = int.MinValue;

   for ( int i = 0; i < tiles.Length; ++i )
   {
    Tile tile = tiles[i];
    ItemData id = TileData.ItemTable[tile.ID & 0x3FFF];

    int top = tile.Z; // Confirmed : no height checks here

    if ( id.Surface && !id.Impassable && top > z && top <= item.Z )
     z = top;
   }

   return z;
  }
 }
}
}

Didi - July 3, 2004 02:24 PM (GMT)
Oups, je corrige, jai mis +1 au lieu de -1 :D




Hosted for free by InvisionFree