Overwrite
Complete Overwrite of the Folder with the free shard. ServUO 57.3 has been added.
This commit is contained in:
11
Scripts/Scripts-master/Games/Battle Chess/Changelog.txt
Normal file
11
Scripts/Scripts-master/Games/Battle Chess/Changelog.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
Version 1.3
|
||||
|
||||
- RunUO 2.0 RC1 compatible
|
||||
|
||||
Version 1.2.5
|
||||
|
||||
- Refactored the Chessboard class to BChessboard. This will prevent the crash occuring when using the [Decorate command.
|
||||
- NPCs will be now ejected from the chessboard
|
||||
- Fixed crash occuring when staff would delete a pawn in the middle of its promotion
|
||||
- If the winner has no backpack they will not receive their winning certificate
|
||||
- You can no longer check mate your enemy and win the game, while being checked yourself.
|
||||
40
Scripts/Scripts-master/Games/Battle Chess/ChessConfig.cs
Normal file
40
Scripts/Scripts-master/Games/Battle Chess/ChessConfig.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
public class ChessConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// The time out for the game to start. If a second player hasn't accepted the game within this time
|
||||
/// the game will be reset.
|
||||
/// </summary>
|
||||
public static TimeSpan GameStartTimeOut = TimeSpan.FromMinutes( 2 );
|
||||
/// <summary>
|
||||
/// The maximum time allowed for a player to make a move. If no move is made within this amount of time
|
||||
/// the game will be reset.
|
||||
/// </summary>
|
||||
public static TimeSpan MoveTimeOut = TimeSpan.FromMinutes( 10 );
|
||||
/// <summary>
|
||||
/// When a player disconnects, the game will give them time to get back to their game (to handle
|
||||
/// player system crashes, connections faults and so on). If one of the player doesn't log back in within
|
||||
/// this time frame, the game is reset.
|
||||
/// </summary>
|
||||
public static TimeSpan DisconnectTimeOut = TimeSpan.FromMinutes( 10 );
|
||||
/// <summary>
|
||||
/// This is the amount of time given to players before the game ends after they have been notified of the
|
||||
/// move time out. Also when the game ends regularly, both players get a gump asking to confirm the end
|
||||
/// of the game. If they don't close it within this time frame, the game will reset.
|
||||
/// </summary>
|
||||
public static TimeSpan EndGameTimerOut = TimeSpan.FromMinutes( 3 );
|
||||
/// <summary>
|
||||
/// Specifies whether the winner should receive a reward scroll or not after the game is over.
|
||||
/// No scroll is given for stalemate, or canceled games. This item has no function in the real world,
|
||||
/// its properties only show the results of the game.
|
||||
/// </summary>
|
||||
public static bool GiveRewardScroll = true;
|
||||
/// <summary>
|
||||
/// This is the keyword that can be used to restore the gumps if anything goes wrong and the gump disappears
|
||||
/// </summary>
|
||||
public static string ResetKeyword = "game";
|
||||
}
|
||||
}
|
||||
937
Scripts/Scripts-master/Games/Battle Chess/ChessGame.cs
Normal file
937
Scripts/Scripts-master/Games/Battle Chess/ChessGame.cs
Normal file
@@ -0,0 +1,937 @@
|
||||
using System;
|
||||
|
||||
using Server;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
/// <summary>
|
||||
/// Describes the status of the current game
|
||||
/// </summary>
|
||||
public enum GameStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// The game is being setup
|
||||
/// </summary>
|
||||
Setup,
|
||||
/// <summary>
|
||||
/// White should make the next move
|
||||
/// </summary>
|
||||
WhiteToMove,
|
||||
/// <summary>
|
||||
/// Black should make the next move
|
||||
/// </summary>
|
||||
BlackToMove,
|
||||
/// <summary>
|
||||
/// A white piece is moving
|
||||
/// </summary>
|
||||
WhiteMoving,
|
||||
/// <summary>
|
||||
/// A black piece is moving
|
||||
/// </summary>
|
||||
BlackMoving,
|
||||
/// <summary>
|
||||
/// A white pawn has been promoted and the system is waiting for the user to make the decision
|
||||
/// </summary>
|
||||
WhitePromotion,
|
||||
/// <summary>
|
||||
/// A black pawn has been promoted and the system is waiting for the user to make the decision
|
||||
/// </summary>
|
||||
BlackPromotion,
|
||||
/// <summary>
|
||||
/// Game over
|
||||
/// </summary>
|
||||
Over
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Describes the logic for dealing with players, from creation to game end
|
||||
/// </summary>
|
||||
public class ChessGame
|
||||
{
|
||||
#region Variables
|
||||
|
||||
/// <summary>
|
||||
/// The mobile playing black
|
||||
/// </summary>
|
||||
private Mobile m_Black;
|
||||
/// <summary>
|
||||
/// The mobile playing white
|
||||
/// </summary>
|
||||
private Mobile m_White;
|
||||
/// <summary>
|
||||
/// Flag stating that the black player is the game owner
|
||||
/// </summary>
|
||||
private bool m_BlackOwner;
|
||||
/// <summary>
|
||||
/// Moment when the game started
|
||||
/// </summary>
|
||||
private DateTime m_GameStart;
|
||||
/// <summary>
|
||||
/// The time used by black to make its moves
|
||||
/// </summary>
|
||||
private TimeSpan m_WhiteTime = TimeSpan.Zero;
|
||||
/// <summary>
|
||||
/// Time used by white to make its moves
|
||||
/// </summary>
|
||||
private TimeSpan m_BlackTime = TimeSpan.Zero;
|
||||
/// <summary>
|
||||
/// The BChessboard object providing game logic
|
||||
/// </summary>
|
||||
private BChessboard m_Board;
|
||||
/// <summary>
|
||||
/// The piece that is performing a move
|
||||
/// </summary>
|
||||
private BaseChessPiece m_MovingPiece;
|
||||
/// <summary>
|
||||
/// The status of the game
|
||||
/// </summary>
|
||||
private GameStatus m_Status = GameStatus.Setup;
|
||||
/// <summary>
|
||||
/// The moment when the last move was made
|
||||
/// </summary>
|
||||
private DateTime m_MoveTime;
|
||||
/// <summary>
|
||||
/// The bounds of the BChessboard
|
||||
/// </summary>
|
||||
private Rectangle2D m_Bounds;
|
||||
/// <summary>
|
||||
/// The height of the BChessboard
|
||||
/// </summary>
|
||||
private int m_Z;
|
||||
/// <summary>
|
||||
/// The pawn that is being promoted
|
||||
/// </summary>
|
||||
private Pawn m_PromotedPawn;
|
||||
/// <summary>
|
||||
/// The timer object providing time out support
|
||||
/// </summary>
|
||||
private ChessTimer m_Timer;
|
||||
/// <summary>
|
||||
/// States whether the game is idle because a player has been disconnected
|
||||
/// </summary>
|
||||
private bool m_Pending;
|
||||
/// <summary>
|
||||
/// The ChessControl object owner of this game
|
||||
/// </summary>
|
||||
private ChessControl m_Parent;
|
||||
/// <summary>
|
||||
/// The region for the BChessboard
|
||||
/// </summary>
|
||||
private ChessRegion m_Region;
|
||||
/// <summary>
|
||||
/// Specifies if other players can get on the board or not
|
||||
/// </summary>
|
||||
private bool m_AllowSpectators;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mobile who started this game
|
||||
/// </summary>
|
||||
public Mobile Owner
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_BlackOwner ? m_Black : m_White;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the player who has been invited to join the game
|
||||
/// </summary>
|
||||
public Mobile Guest
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_BlackOwner ? m_White : m_Black;
|
||||
}
|
||||
set
|
||||
{
|
||||
if ( m_BlackOwner )
|
||||
m_White = value;
|
||||
else
|
||||
m_Black = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// States whether the game is able to accept targets
|
||||
/// </summary>
|
||||
public bool AllowTarget
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Pending ) // Pending status
|
||||
return false;
|
||||
|
||||
if ( m_Status == GameStatus.Setup && Owner == null ) // Ownerless setup - is this even needed?
|
||||
return false;
|
||||
|
||||
if ( m_Status != GameStatus.Setup )
|
||||
{
|
||||
if ( m_White == null || m_Black == null || m_White.NetState == null || m_Black.NetState == null )
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( m_Status == GameStatus.Over )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies if the game is in a consistent state and can send the game gumps to players
|
||||
/// </summary>
|
||||
public bool AllowGame
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Pending )
|
||||
return false;
|
||||
|
||||
if ( m_Status == GameStatus.Setup || m_Status == GameStatus.Over )
|
||||
return false;
|
||||
|
||||
if ( m_White == null || m_Black == null || m_White.NetState == null || m_Black.NetState == null )
|
||||
return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the attack effect on the BChessboard
|
||||
/// </summary>
|
||||
public int AttackEffect
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Parent != null )
|
||||
return m_Parent.AttackEffect;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the capture effect on the BChessboard
|
||||
/// </summary>
|
||||
public int CaptureEffect
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Parent != null )
|
||||
return m_Parent.CaptureEffect;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the BoltOnDeath property on the BChessboard
|
||||
/// </summary>
|
||||
public bool BoltOnDeath
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Parent != null )
|
||||
return m_Parent.BoltOnDeath;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the orientation of the BChessboard
|
||||
/// </summary>
|
||||
public BoardOrientation Orientation
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Parent != null )
|
||||
return m_Parent.Orientation;
|
||||
else
|
||||
return BoardOrientation.NorthSouth;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// States whether other players can get on the board
|
||||
/// </summary>
|
||||
public bool AllowSpectators
|
||||
{
|
||||
get { return m_AllowSpectators; }
|
||||
set { m_AllowSpectators = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the BChessboard region
|
||||
/// </summary>
|
||||
public ChessRegion Region
|
||||
{
|
||||
get { return m_Region; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public ChessGame( ChessControl parent, Mobile owner, Rectangle2D bounds, int z )
|
||||
{
|
||||
m_Parent = parent;
|
||||
m_Bounds = bounds;
|
||||
m_Z = z;
|
||||
|
||||
m_BlackOwner = Utility.RandomBool();
|
||||
|
||||
if ( m_BlackOwner )
|
||||
m_Black = owner;
|
||||
else
|
||||
m_White = owner;
|
||||
|
||||
m_AllowSpectators = m_Parent.AllowSpectators;
|
||||
|
||||
// Owner.SendGump( new StartGameGump( Owner, this, true, m_AllowSpectators ) );
|
||||
Owner.SendGump( new ChessSetGump( Owner, this, true, m_AllowSpectators ) );
|
||||
|
||||
// Owner.Target = new ChessTarget( this, Owner, "Please select your partner...",
|
||||
// new ChessTargetCallback( ChooseOpponent ) );
|
||||
|
||||
EventSink.Login += new LoginEventHandler(OnPlayerLogin);
|
||||
EventSink.Disconnected += new DisconnectedEventHandler(OnPlayerDisconnected);
|
||||
|
||||
m_Timer = new ChessTimer( this );
|
||||
}
|
||||
|
||||
#region Game Startup
|
||||
|
||||
/// <summary>
|
||||
/// This function is called when one of the two players initializing the game decides to cancel
|
||||
/// </summary>
|
||||
/// <param name="from">The player refusing</param>
|
||||
public void CancelGameStart( Mobile from )
|
||||
{
|
||||
if ( from == Owner )
|
||||
{
|
||||
// End this game
|
||||
if ( Guest != null )
|
||||
{
|
||||
Guest.SendMessage( 0x40, "The owner of this game decided to cancel." );
|
||||
Guest.CloseGump( typeof( StartGameGump ) );
|
||||
}
|
||||
|
||||
if ( from.Target != null && from.Target is ChessTarget )
|
||||
(from.Target as ChessTarget).Remove( from );
|
||||
|
||||
Cleanup();
|
||||
}
|
||||
else if ( from == Guest )
|
||||
{
|
||||
Guest = null;
|
||||
|
||||
Owner.SendGump( new StartGameGump( Owner, this, true, m_AllowSpectators ) );
|
||||
Owner.Target = new ChessTarget( this, Owner, "The selected partner refused the game. Please select another partner...",
|
||||
new ChessTargetCallback( ChooseOpponent ) );
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The guest accepted the game
|
||||
/// </summary>
|
||||
/// <param name="guest">The player accepting the game</param>
|
||||
public void AcceptGame( Mobile guest )
|
||||
{
|
||||
if ( Owner == null )
|
||||
{
|
||||
guest.SendMessage( 0x40, "Your partner canceled the game" );
|
||||
return;
|
||||
}
|
||||
|
||||
m_GameStart = DateTime.Now;
|
||||
m_Timer.OnGameStart();
|
||||
|
||||
m_Status = GameStatus.WhiteToMove;
|
||||
|
||||
Guest = guest;
|
||||
|
||||
Owner.CloseGump( typeof( Arya.Chess.StartGameGump ) );
|
||||
|
||||
m_Board = new BChessboard( m_Black, m_White, m_Z, m_Bounds, this, m_Parent.ChessSet, m_Parent.WhiteHue, m_Parent.BlackHue, m_Parent.WhiteMinorHue, m_Parent.BlackMinorHue, m_Parent.OverrideMinorHue );
|
||||
|
||||
m_MoveTime = DateTime.Now;
|
||||
|
||||
// Create the region
|
||||
m_Region = new ChessRegion( m_Parent.Map, this, m_AllowSpectators, m_Bounds, m_Z );
|
||||
m_Region.Register();
|
||||
|
||||
SendAllGumps( null, null );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Callback for choosing a partner for the game
|
||||
/// </summary>
|
||||
public void ChooseOpponent( Mobile from, object targeted )
|
||||
{
|
||||
Mobile m = targeted as Mobile;
|
||||
|
||||
if ( m == null || ! m.Player || m.NetState == null )
|
||||
{
|
||||
Owner.SendGump( new StartGameGump( Owner, this, true, m_AllowSpectators ) );
|
||||
Owner.Target = new ChessTarget( this, Owner, "You must select a player. Please select another partner...",
|
||||
new ChessTargetCallback( ChooseOpponent ) );
|
||||
}
|
||||
else if ( m == from )
|
||||
{
|
||||
from.SendMessage( 0x40, "You can't play against yourself" );
|
||||
|
||||
Owner.SendGump( new StartGameGump( Owner, this, true, m_AllowSpectators ) );
|
||||
Owner.Target = new ChessTarget( this, Owner, "You must select a player. Please select another partner...",
|
||||
new ChessTargetCallback( ChooseOpponent ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
Guest = m;
|
||||
|
||||
Owner.SendGump( new StartGameGump( Owner, this, true, m_AllowSpectators ) );
|
||||
|
||||
Guest.SendGump( new StartGameGump( Guest, this, false, m_AllowSpectators ) );
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event Handlers
|
||||
|
||||
/// <summary>
|
||||
/// Verify if a player is logging back in after disconnecting
|
||||
/// </summary>
|
||||
private void OnPlayerLogin(LoginEventArgs e)
|
||||
{
|
||||
if ( ! m_Pending )
|
||||
return;
|
||||
|
||||
if ( m_White == null || m_Black == null )
|
||||
return;
|
||||
|
||||
if ( e.Mobile == m_White || e.Mobile == m_Black )
|
||||
{
|
||||
if ( m_White.NetState != null && m_Black.NetState != null )
|
||||
{
|
||||
m_Pending = false;
|
||||
|
||||
// Both players are back and playing
|
||||
m_Timer.OnPlayerConnected();
|
||||
|
||||
m_White.CloseGump( typeof( EndGameGump ) );
|
||||
m_Black.CloseGump( typeof( EndGameGump ) );
|
||||
|
||||
if ( m_Status == GameStatus.BlackPromotion )
|
||||
{
|
||||
// Black
|
||||
SendAllGumps( "Waiting for black to promote their pawn", "Please promote your pawn" );
|
||||
|
||||
m_Black.SendGump( new PawnPromotionGump( m_Black, this ) );
|
||||
}
|
||||
else if ( m_Status == GameStatus.WhitePromotion )
|
||||
{
|
||||
// White
|
||||
SendAllGumps( "Please promote your pawn", "Waiting for white to promote their pawn" );
|
||||
|
||||
m_White.SendGump( new PawnPromotionGump( m_White, this ) );
|
||||
}
|
||||
else
|
||||
SendAllGumps( null, null );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify if one of the players disconnects
|
||||
/// </summary>
|
||||
private void OnPlayerDisconnected(DisconnectedEventArgs e)
|
||||
{
|
||||
if ( e.Mobile != m_Black && e.Mobile != m_White )
|
||||
return;
|
||||
|
||||
if ( m_Status == GameStatus.Setup )
|
||||
{
|
||||
Cleanup(); // No game to loose, just end.
|
||||
return;
|
||||
}
|
||||
|
||||
if ( m_Status == GameStatus.Over )
|
||||
{
|
||||
// If game is over, logging out = confirming game over through the gump
|
||||
NotifyGameOver( e.Mobile );
|
||||
return;
|
||||
}
|
||||
|
||||
// Game in progress
|
||||
|
||||
m_Pending = true;
|
||||
|
||||
if ( m_Black != null && m_Black.NetState != null )
|
||||
{
|
||||
m_Black.CloseGump( typeof( GameGump ) );
|
||||
m_Black.SendGump( new EndGameGump( m_Black, this, false,
|
||||
"Your partner has been disconnected", ChessConfig.DisconnectTimeOut.Minutes ) );
|
||||
}
|
||||
|
||||
if ( m_White != null && m_White.NetState != null )
|
||||
{
|
||||
m_White.CloseGump( typeof( GameGump ) );
|
||||
m_White.SendGump( new EndGameGump( m_White, this, false,
|
||||
"Your partner has been disconnected", ChessConfig.DisconnectTimeOut.Minutes ) );
|
||||
}
|
||||
|
||||
if ( m_Timer != null )
|
||||
m_Timer.OnPlayerDisconnected();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Gets the color of a mobile
|
||||
/// </summary>
|
||||
/// <param name="m">The mobile examined</param>
|
||||
/// <returns>The color of the player</returns>
|
||||
public ChessColor GetColor( Mobile m )
|
||||
{
|
||||
if ( m == m_Black )
|
||||
return ChessColor.Black;
|
||||
else
|
||||
return ChessColor.White;
|
||||
}
|
||||
|
||||
#region Moving Pieces
|
||||
|
||||
/// <summary>
|
||||
/// Sends the move request target
|
||||
/// </summary>
|
||||
/// <param name="m">The player that must make the move</param>
|
||||
public void SendMoveTarget( Mobile m )
|
||||
{
|
||||
if ( GetColor( m ) == ChessColor.White )
|
||||
m_Status = GameStatus.WhiteToMove;
|
||||
else
|
||||
m_Status = GameStatus.BlackToMove;
|
||||
|
||||
m.Target = new ChessTarget( this, m, "Select the piece you wish to move...",
|
||||
new ChessTargetCallback( OnPickPieceTarget ) );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Callback for selecting the piece to move
|
||||
/// </summary>
|
||||
public void OnPickPieceTarget( Mobile from, object targeted )
|
||||
{
|
||||
m_Black.CloseGump( typeof( EndGameGump ) );
|
||||
m_White.CloseGump( typeof( EndGameGump ) );
|
||||
|
||||
if ( ! ( targeted is IPoint2D ) )
|
||||
{
|
||||
from.SendMessage( 0x40, "Invalid selection" );
|
||||
SendMoveTarget( from );
|
||||
return;
|
||||
}
|
||||
|
||||
BaseChessPiece piece = m_Board[ m_Board.WorldToBoard( new Point2D( targeted as IPoint2D ) ) ];
|
||||
|
||||
if ( piece == null || piece.Color != GetColor( from ) )
|
||||
{
|
||||
from.SendMessage( 0x40, "Invalid selection" );
|
||||
SendMoveTarget( from );
|
||||
return;
|
||||
}
|
||||
|
||||
m_MovingPiece = piece;
|
||||
from.Target = new ChessTarget( this, from, "Where do you wish to move?",
|
||||
new ChessTargetCallback( OnPieceMove ) );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Callback for the move finalization
|
||||
/// </summary>
|
||||
public void OnPieceMove( Mobile from, object targeted )
|
||||
{
|
||||
string err = null;
|
||||
|
||||
if ( ! ( targeted is IPoint2D ) )
|
||||
{
|
||||
err = "Invalid Move";
|
||||
m_MovingPiece = null;
|
||||
|
||||
if ( GetColor( from ) == ChessColor.Black )
|
||||
SendAllGumps( null, err );
|
||||
else
|
||||
SendAllGumps( err, null );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! m_Board.TryMove( ref err, m_MovingPiece, new Point2D( targeted as IPoint2D ) ) )
|
||||
{
|
||||
m_MovingPiece = null;
|
||||
|
||||
if ( GetColor( from ) == ChessColor.Black )
|
||||
SendAllGumps( null, err );
|
||||
else
|
||||
SendAllGumps( err, null );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Move has been made. Wait until it's over
|
||||
if ( m_Status == GameStatus.WhiteToMove )
|
||||
{
|
||||
m_Status = GameStatus.WhiteMoving;
|
||||
SendAllGumps( "Making your move", null );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Status = GameStatus.BlackMoving;
|
||||
SendAllGumps( null, "Making your move" );
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function is called when a move is completed, and the next step in game should be performed
|
||||
/// </summary>
|
||||
public void OnMoveOver( Move move, string whiteMsg, string blackMsg )
|
||||
{
|
||||
m_Timer.OnMoveMade();
|
||||
|
||||
if ( move != null && move.Piece is Pawn && ( move.Piece as Pawn ).ShouldBePromoted )
|
||||
{
|
||||
// A pawn should be promoted
|
||||
m_PromotedPawn = move.Piece as Pawn;
|
||||
|
||||
if ( m_Status == GameStatus.BlackMoving )
|
||||
{
|
||||
// Black
|
||||
m_Status = GameStatus.BlackPromotion;
|
||||
SendAllGumps( "Waiting for black to promote their pawn", "Please promote your pawn" );
|
||||
|
||||
m_Black.SendGump( new PawnPromotionGump( m_Black, this ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
// White
|
||||
m_Status = GameStatus.WhitePromotion;
|
||||
SendAllGumps( "Please promote your pawn", "Waiting for white to promote their pawn" );
|
||||
|
||||
m_White.SendGump( new PawnPromotionGump( m_White, this ) );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( m_Status == GameStatus.BlackMoving || m_Status == GameStatus.BlackPromotion )
|
||||
{
|
||||
m_BlackTime += ( DateTime.Now.Subtract( m_MoveTime ) );
|
||||
m_Status = GameStatus.WhiteToMove;
|
||||
}
|
||||
else if ( m_Status == GameStatus.WhiteMoving || m_Status == GameStatus.WhitePromotion )
|
||||
{
|
||||
m_WhiteTime += ( DateTime.Now.Subtract( m_MoveTime ) );
|
||||
m_Status = GameStatus.BlackToMove;
|
||||
}
|
||||
|
||||
m_MoveTime = DateTime.Now;
|
||||
|
||||
SendAllGumps( null, null );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The user decided to promote a pawn
|
||||
/// </summary>
|
||||
/// <param name="type">The piece the pawn should promote to</param>
|
||||
public void OnPawnPromoted( PawnPromotion type )
|
||||
{
|
||||
m_Board.OnPawnPromoted( m_PromotedPawn, type );
|
||||
|
||||
m_PromotedPawn = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function sends pending gumps to players notifying them to hurry to make a move
|
||||
/// </summary>
|
||||
public void OnMoveTimeout()
|
||||
{
|
||||
if ( m_Black.NetState != null )
|
||||
{
|
||||
m_Black.SendGump( new EndGameGump( m_Black, this, false, string.Format( "No move made in {0} minutes", ChessConfig.MoveTimeOut.Minutes ), ChessConfig.EndGameTimerOut.Minutes ) );
|
||||
}
|
||||
|
||||
if ( m_White.NetState != null )
|
||||
{
|
||||
m_White.SendGump( new EndGameGump( m_White, this, false, string.Format( "No move made in {0} minutes", ChessConfig.MoveTimeOut.Minutes ), ChessConfig.EndGameTimerOut.Minutes ) );
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Sends the game and score gumps to both player
|
||||
/// </summary>
|
||||
/// <param name="whiteMsg">The message displayed to white</param>
|
||||
/// <param name="blackMsg">The message displayed to black</param>
|
||||
public void SendAllGumps( string whiteMsg, string blackMsg )
|
||||
{
|
||||
if ( m_White == null || m_Black == null )
|
||||
return;
|
||||
|
||||
if ( m_Pending )
|
||||
{
|
||||
whiteMsg = "This game is temporarily stopped";
|
||||
blackMsg = whiteMsg;
|
||||
}
|
||||
|
||||
m_Black.SendGump( new GameGump(
|
||||
m_Black, this, ChessColor.Black, blackMsg,
|
||||
! m_Pending && m_Status == GameStatus.BlackToMove,
|
||||
m_Status == GameStatus.BlackMoving ) );
|
||||
|
||||
m_White.SendGump( new GameGump(
|
||||
m_White, this, ChessColor.White, whiteMsg,
|
||||
! m_Pending && m_Status == GameStatus.WhiteToMove,
|
||||
m_Status == GameStatus.WhiteMoving ) );
|
||||
|
||||
int[] white = m_Board.GetCaptured( ChessColor.White );
|
||||
int[] black = m_Board.GetCaptured( ChessColor.Black );
|
||||
int ws = m_Board.GetScore( ChessColor.White );
|
||||
int bs = m_Board.GetScore( ChessColor.Black );
|
||||
|
||||
m_White.SendGump( new ScoreGump( m_White, this, white, black, ws, bs ) );
|
||||
m_Black.SendGump( new ScoreGump( m_Black, this, white, black, ws, bs ) );
|
||||
}
|
||||
|
||||
#region End Game
|
||||
|
||||
/// <summary>
|
||||
/// Notifies the parent object to clean up this game
|
||||
/// </summary>
|
||||
private void ParentCleanup()
|
||||
{
|
||||
m_Parent.OnGameOver();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cleans up the resources used by this game
|
||||
/// </summary>
|
||||
public void Cleanup()
|
||||
{
|
||||
EventSink.Disconnected -= new DisconnectedEventHandler( OnPlayerDisconnected );
|
||||
EventSink.Login -= new LoginEventHandler( OnPlayerLogin );
|
||||
|
||||
if ( m_Board != null )
|
||||
{
|
||||
m_Board.Delete();
|
||||
}
|
||||
|
||||
if ( m_Timer != null )
|
||||
{
|
||||
m_Timer.Stop();
|
||||
m_Timer = null;
|
||||
}
|
||||
|
||||
if ( m_Black != null && m_Black.Target != null && m_Black.Target is ChessTarget )
|
||||
( m_Black.Target as ChessTarget ).Remove( m_Black );
|
||||
|
||||
if ( m_White != null && m_White.Target != null && m_White.Target is ChessTarget )
|
||||
( m_White.Target as ChessTarget ).Remove( m_White );
|
||||
|
||||
if ( m_Black != null && m_Black.NetState != null )
|
||||
{
|
||||
m_Black.CloseGump( typeof( StartGameGump ) );
|
||||
m_Black.CloseGump( typeof( GameGump ) );
|
||||
m_Black.CloseGump( typeof( EndGameGump ) );
|
||||
m_Black.CloseGump( typeof( PawnPromotionGump ) );
|
||||
m_Black.CloseGump( typeof( ScoreGump ) );
|
||||
}
|
||||
|
||||
if ( m_White != null && m_White.NetState != null )
|
||||
{
|
||||
m_White.CloseGump( typeof( StartGameGump ) );
|
||||
m_White.CloseGump( typeof( GameGump ) );
|
||||
m_White.CloseGump( typeof( EndGameGump ) );
|
||||
m_White.CloseGump( typeof( PawnPromotionGump ) );
|
||||
m_White.CloseGump( typeof( ScoreGump ) );
|
||||
}
|
||||
|
||||
if ( m_Region != null )
|
||||
{
|
||||
m_Region.Unregister();
|
||||
m_Region = null;
|
||||
}
|
||||
|
||||
ParentCleanup();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Notifies that the game has ended
|
||||
/// </summary>
|
||||
/// <param name="winner">The winner of the game, null for a stall</param>
|
||||
public void EndGame( Mobile winner )
|
||||
{
|
||||
m_Status = GameStatus.Over;
|
||||
|
||||
m_Timer.OnGameOver();
|
||||
|
||||
if ( winner != null )
|
||||
{
|
||||
GiveWinnerBook( winner );
|
||||
}
|
||||
|
||||
string msg = null;
|
||||
|
||||
if ( winner != null )
|
||||
msg = string.Format( "Winner: {0}", winner.Name );
|
||||
else
|
||||
msg = "Game Stalled";
|
||||
|
||||
m_Black.SendGump( new EndGameGump( m_Black, this, true, msg, -1 ) );
|
||||
m_White.SendGump( new EndGameGump( m_White, this, true, msg, -1 ) );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function is called by the gumps when players acknowledge the end of the game
|
||||
/// </summary>
|
||||
/// <param name="m">The mobile acknowledging the end of the game</param>
|
||||
public void NotifyGameOver( Mobile m )
|
||||
{
|
||||
if ( m_Black == m )
|
||||
{
|
||||
m_Black.CloseGump( typeof( StartGameGump ) );
|
||||
m_Black.CloseGump( typeof( GameGump ) );
|
||||
m_Black.CloseGump( typeof( EndGameGump ) );
|
||||
m_Black.CloseGump( typeof( PawnPromotionGump ) );
|
||||
m_Black.CloseGump( typeof( ScoreGump ) );
|
||||
|
||||
m_Black = null;
|
||||
}
|
||||
|
||||
if ( m_White == m )
|
||||
{
|
||||
m_White.CloseGump( typeof( StartGameGump ) );
|
||||
m_White.CloseGump( typeof( GameGump ) );
|
||||
m_White.CloseGump( typeof( EndGameGump ) );
|
||||
m_White.CloseGump( typeof( PawnPromotionGump ) );
|
||||
m_White.CloseGump( typeof( ScoreGump ) );
|
||||
|
||||
m_White = null;
|
||||
}
|
||||
|
||||
if ( m_Black == null && m_White == null )
|
||||
{
|
||||
Cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gives the winner the book with the sum up of the game
|
||||
/// </summary>
|
||||
/// <param name="to">The winner of the game</param>
|
||||
public void GiveWinnerBook( Mobile to )
|
||||
{
|
||||
Mobile winner = to;
|
||||
Mobile looser = null;
|
||||
TimeSpan winTime = TimeSpan.Zero;
|
||||
TimeSpan looseTime = TimeSpan.Zero;
|
||||
int winnerScore = 0;
|
||||
int looserScore = 0;
|
||||
|
||||
if ( winner == m_Black )
|
||||
{
|
||||
looser = m_White;
|
||||
looseTime = m_WhiteTime;
|
||||
winTime = m_BlackTime;
|
||||
winnerScore = m_Board.GetScore( ChessColor.Black );
|
||||
looserScore = m_Board.GetScore( ChessColor.White );
|
||||
}
|
||||
else
|
||||
{
|
||||
looser = m_Black;
|
||||
looseTime = m_BlackTime;
|
||||
winTime = m_WhiteTime;
|
||||
winnerScore = m_Board.GetScore( ChessColor.White );
|
||||
looserScore = m_Board.GetScore( ChessColor.Black );
|
||||
}
|
||||
|
||||
if ( winner == null || looser == null )
|
||||
return;
|
||||
|
||||
WinnerPaper paper = new WinnerPaper( winner, looser, DateTime.Now - m_GameStart, winTime, looseTime, winnerScore, looserScore );
|
||||
|
||||
if ( to.Backpack != null )
|
||||
to.Backpack.AddItem( paper );
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Appearance
|
||||
|
||||
/// <summary>
|
||||
/// Changes the board's chess set
|
||||
/// </summary>
|
||||
public void SetChessSet( ChessSet chessset )
|
||||
{
|
||||
if ( m_Board != null )
|
||||
m_Board.ChessSet = chessset;
|
||||
else
|
||||
m_Parent.SetChessSet( chessset ); // This allows players to choose their own set
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the pieces hues
|
||||
/// </summary>
|
||||
/// <param name="white"></param>
|
||||
/// <param name="black"></param>
|
||||
public void SetHues( int white, int black, int whiteMinor, int blackMinor )
|
||||
{
|
||||
if ( m_Board != null )
|
||||
{
|
||||
m_Board.WhiteHue = white;
|
||||
m_Board.BlackHue = black;
|
||||
m_Board.WhiteMinorHue = whiteMinor;
|
||||
m_Board.BlackMinorHue = blackMinor;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the orientation of the board
|
||||
/// </summary>
|
||||
/// <param name="orientation"></param>
|
||||
public void SetOrientation( BoardOrientation orientation )
|
||||
{
|
||||
if ( m_Board != null )
|
||||
m_Board.Orientation = orientation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the flag that makes pieces ignore their minor hue
|
||||
/// </summary>
|
||||
/// <param name="doOverride"></param>
|
||||
public void SetMinorHueOverride( bool doOverride )
|
||||
{
|
||||
if ( m_Board != null )
|
||||
m_Board.OverrideMinorHue = doOverride;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Misc
|
||||
|
||||
/// <summary>
|
||||
/// Verifies if a specified mobile is a player in the game
|
||||
/// </summary>
|
||||
/// <param name="m"></param>
|
||||
public bool IsPlayer( Mobile m )
|
||||
{
|
||||
return m == m_Black || m == m_White;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
188
Scripts/Scripts-master/Games/Battle Chess/ChessMobile.cs
Normal file
188
Scripts/Scripts-master/Games/Battle Chess/ChessMobile.cs
Normal file
@@ -0,0 +1,188 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
using Server;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
/// <summary>
|
||||
/// The basic mobile that will be used as the actual chess piece
|
||||
/// </summary>
|
||||
public class ChessMobile : BaseCreature
|
||||
{
|
||||
/// <summary>
|
||||
/// The chess piece that owns this NPC
|
||||
/// </summary>
|
||||
private BaseChessPiece m_Piece;
|
||||
/// <summary>
|
||||
/// Specifies the location of the next position of this piece
|
||||
/// </summary>
|
||||
private Point3D m_NextMove = Point3D.Zero;
|
||||
/// <summary>
|
||||
/// The list of waypoints used by this NPC
|
||||
/// </summary>
|
||||
private ArrayList m_WayPoints;
|
||||
|
||||
public ChessMobile( BaseChessPiece piece ) : base( AIType.AI_Use_Default, FightMode.None, 1, 1, 0.2, 0.2 )
|
||||
{
|
||||
m_WayPoints = new ArrayList();
|
||||
|
||||
InitStats( 25, 100, 100 );
|
||||
m_Piece = piece;
|
||||
|
||||
Blessed = true;
|
||||
Paralyzed = true;
|
||||
Direction = m_Piece.Facing;
|
||||
}
|
||||
|
||||
#region Serialization
|
||||
|
||||
public ChessMobile( Serial serial ) : base( serial )
|
||||
{
|
||||
}
|
||||
|
||||
public override void Serialize(GenericWriter writer)
|
||||
{
|
||||
base.Serialize( writer );
|
||||
}
|
||||
|
||||
public override void Deserialize(GenericReader reader)
|
||||
{
|
||||
base.Deserialize( reader );
|
||||
Delete();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Movement on the BChessboard
|
||||
|
||||
/// <summary>
|
||||
/// Places the piece on the board for the first time
|
||||
/// </summary>
|
||||
/// <param name="location">The location where the piece should be placed</param>
|
||||
/// <param name="map">The map where the game takes place</param>
|
||||
public void Place( Point3D location, Map map )
|
||||
{
|
||||
MoveToWorld( location, map );
|
||||
FixedParticles( 0x373A, 1, 15, 5012, Hue, 2, EffectLayer.Waist );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the NPC to the specified location
|
||||
/// </summary>
|
||||
/// <param name="to">The location the NPC should move to</param>
|
||||
public void GoTo( Point2D to )
|
||||
{
|
||||
AI = AIType.AI_Melee;
|
||||
|
||||
m_NextMove = new Point3D( to, Z );
|
||||
|
||||
if ( m_Piece is Knight )
|
||||
{
|
||||
WayPoint end = new WayPoint();
|
||||
WayPoint start = new WayPoint();
|
||||
|
||||
end.MoveToWorld( m_NextMove, Map );
|
||||
|
||||
// This is a knight, so do L shaped move
|
||||
int dx = to.X - X;
|
||||
int dy = to.Y - Y;
|
||||
|
||||
Point3D p = Location; // Point3D is a value type
|
||||
|
||||
if ( Math.Abs( dx ) == 1 )
|
||||
p.X += dx;
|
||||
else
|
||||
p.Y += dy;
|
||||
|
||||
start.MoveToWorld( p, Map );
|
||||
start.NextPoint = end;
|
||||
|
||||
CurrentWayPoint = start;
|
||||
|
||||
m_WayPoints.Add( start );
|
||||
m_WayPoints.Add( end );
|
||||
}
|
||||
else
|
||||
{
|
||||
WayPoint wp = new WayPoint();
|
||||
wp.MoveToWorld( m_NextMove, Map );
|
||||
CurrentWayPoint = wp;
|
||||
|
||||
m_WayPoints.Add( wp );
|
||||
}
|
||||
|
||||
Paralyzed = false;
|
||||
}
|
||||
|
||||
protected override void OnLocationChange(Point3D oldLocation)
|
||||
{
|
||||
if ( m_NextMove == Point3D.Zero || m_NextMove != Location )
|
||||
return;
|
||||
|
||||
// The NPC is at the waypoint
|
||||
AI = AIType.AI_Use_Default;
|
||||
|
||||
CurrentWayPoint = null;
|
||||
Paralyzed = true;
|
||||
|
||||
foreach( WayPoint wp in m_WayPoints )
|
||||
wp.Delete();
|
||||
|
||||
m_WayPoints.Clear();
|
||||
|
||||
m_NextMove = Point3D.Zero;
|
||||
|
||||
Direction = m_Piece.Facing;
|
||||
|
||||
m_Piece.OnMoveOver();
|
||||
|
||||
Server.Timer.DelayCall( TimeSpan.FromMilliseconds( 500 ), TimeSpan.FromMilliseconds( 500 ), 1, new TimerStateCallback ( OnFacingTimer ), null );
|
||||
}
|
||||
|
||||
private void OnFacingTimer( object state )
|
||||
{
|
||||
if ( ! Deleted && m_Piece != null )
|
||||
{
|
||||
Direction = m_Piece.Facing;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override bool HandlesOnSpeech(Mobile from)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void OnDelete()
|
||||
{
|
||||
if ( m_Piece != null )
|
||||
m_Piece.OnPieceDeleted();
|
||||
|
||||
CurrentWayPoint = null;
|
||||
|
||||
if ( m_WayPoints != null && m_WayPoints.Count > 0 )
|
||||
{
|
||||
foreach( WayPoint wp in m_WayPoints )
|
||||
wp.Delete();
|
||||
|
||||
m_WayPoints.Clear();
|
||||
}
|
||||
|
||||
base.OnDelete ();
|
||||
}
|
||||
|
||||
public override bool OnMoveOver(Mobile m)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool CanPaperdollBeOpenedBy(Mobile from)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
155
Scripts/Scripts-master/Games/Battle Chess/ChessRegion.cs
Normal file
155
Scripts/Scripts-master/Games/Battle Chess/ChessRegion.cs
Normal file
@@ -0,0 +1,155 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
using Server;
|
||||
using Server.Regions;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
public class ChessRegion : Region
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies whether spectators should be allowed on the BChessboard or not
|
||||
/// </summary>
|
||||
private bool m_AllowSpectators = false;
|
||||
/// <summary>
|
||||
/// The game that's being held on the BChessboard
|
||||
/// </summary>
|
||||
private ChessGame m_Game;
|
||||
/// <summary>
|
||||
/// The bounds of the region
|
||||
/// </summary>
|
||||
private Rectangle2D m_Bounds;
|
||||
/// <summary>
|
||||
/// The bounds of the BChessboard
|
||||
/// </summary>
|
||||
private Rectangle2D m_BoardBounds;
|
||||
/// <summary>
|
||||
/// The height of the BChessboard
|
||||
/// </summary>
|
||||
private int m_Height;
|
||||
|
||||
public bool AllowSpectators
|
||||
{
|
||||
get { return m_AllowSpectators; }
|
||||
set
|
||||
{
|
||||
if ( value != m_AllowSpectators )
|
||||
{
|
||||
m_AllowSpectators = value;
|
||||
|
||||
ForceExpel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ChessRegion( Map map, ChessGame game, bool allowSpectators, Rectangle2D bounds, int height ) : base( "Chessboard", map, 100, bounds )
|
||||
{
|
||||
m_Game = game;
|
||||
m_AllowSpectators = allowSpectators;
|
||||
|
||||
// Make the region larger so that people can't cast invisibility outside
|
||||
// m_Bounds = new Rectangle2D( bounds.X - 12, bounds.Y - 12, bounds.Width + 24, bounds.Height + 24 );
|
||||
// m_BoardBounds = bounds;
|
||||
|
||||
m_Height = height;
|
||||
|
||||
// Coords = new ArrayList();
|
||||
// Coords.Add( m_Bounds );
|
||||
}
|
||||
|
||||
public override void OnLocationChanged(Mobile m, Point3D oldLocation)
|
||||
{
|
||||
if ( m_Game == null || m is ChessMobile || m_AllowSpectators || m_Game.IsPlayer( m ) )
|
||||
base.OnLocationChanged (m, oldLocation);
|
||||
else if ( m_BoardBounds.Contains( m.Location ) && m.AccessLevel < AccessLevel.GameMaster )
|
||||
{
|
||||
m.SendMessage( 0x40, "Spectators aren't allowed on the chessboard" );
|
||||
|
||||
// Expel
|
||||
if ( ! m_BoardBounds.Contains( oldLocation as IPoint2D ) )
|
||||
m.Location = oldLocation;
|
||||
else
|
||||
m.Location = new Point3D( m_BoardBounds.X - 1, m_BoardBounds.Y - 1, m_Height );
|
||||
}
|
||||
else
|
||||
base.OnLocationChanged( m, oldLocation );
|
||||
}
|
||||
|
||||
public override bool OnBeginSpellCast(Mobile m, ISpell s)
|
||||
{
|
||||
if ( s is Server.Spells.Sixth.InvisibilitySpell )
|
||||
{
|
||||
m.SendMessage( 0x40, "You can't cast that spell when you're close to a chessboard" );
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return base.OnBeginSpellCast (m, s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Don't announce
|
||||
public override void OnEnter(Mobile m)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnExit(Mobile m)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool AllowSpawn()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void OnSpeech(SpeechEventArgs args)
|
||||
{
|
||||
if ( m_Game != null && m_Game.IsPlayer( args.Mobile ) && m_Game.AllowTarget )
|
||||
{
|
||||
if ( args.Speech.ToLower().IndexOf( ChessConfig.ResetKeyword.ToLower() ) > -1 )
|
||||
m_Game.SendAllGumps( null, null );
|
||||
}
|
||||
|
||||
base.OnSpeech( args );
|
||||
}
|
||||
|
||||
private void ForceExpel()
|
||||
{
|
||||
if ( m_Game != null && ! m_AllowSpectators )
|
||||
{
|
||||
IPooledEnumerable en = Map.GetMobilesInBounds( m_BoardBounds );
|
||||
ArrayList expel = new ArrayList();
|
||||
|
||||
try
|
||||
{
|
||||
foreach( Mobile m in en )
|
||||
{
|
||||
if ( m.Player && ! m_Game.IsPlayer( m ) )
|
||||
{
|
||||
expel.Add( m );
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
en.Free();
|
||||
}
|
||||
|
||||
foreach( Mobile m in expel )
|
||||
{
|
||||
m.SendMessage( 0x40, "Spectators aren't allowed on the chessboard" );
|
||||
m.Location = new Point3D( m_BoardBounds.X - 1, m_BoardBounds.Y - 1, m_Height );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// public override void Register()
|
||||
// {
|
||||
// base.Register();
|
||||
|
||||
// ForceExpel();
|
||||
// }
|
||||
}
|
||||
}
|
||||
75
Scripts/Scripts-master/Games/Battle Chess/ChessTarget.cs
Normal file
75
Scripts/Scripts-master/Games/Battle Chess/ChessTarget.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
|
||||
using Server;
|
||||
using Server.Targeting;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
public delegate void ChessTargetCallback( Mobile from, object targeted );
|
||||
|
||||
/// <summary>
|
||||
/// General purpose target for the chess system
|
||||
/// </summary>
|
||||
public class ChessTarget : Target
|
||||
{
|
||||
/// <summary>
|
||||
/// The message for the target request
|
||||
/// </summary>
|
||||
private string m_Message;
|
||||
/// <summary>
|
||||
/// The callback for this target
|
||||
/// </summary>
|
||||
private ChessTargetCallback m_Callback;
|
||||
/// <summary>
|
||||
/// The chess game managing this target
|
||||
/// </summary>
|
||||
private ChessGame m_Game;
|
||||
/// <summary>
|
||||
/// Flag for a target used outside a game
|
||||
/// </summary>
|
||||
private bool m_IgnoreGame = false;
|
||||
|
||||
public ChessTarget( ChessGame game, Mobile m, string message, ChessTargetCallback callback ) : base( -1, true, TargetFlags.None )
|
||||
{
|
||||
m_Message = message;
|
||||
m_Callback = callback;
|
||||
m_Game = game;
|
||||
|
||||
if ( message != null )
|
||||
m.SendMessage( 0x40, message );
|
||||
}
|
||||
|
||||
public ChessTarget( Mobile m, string message, ChessTargetCallback callback ) : base( -1, true, TargetFlags.None )
|
||||
{
|
||||
m_IgnoreGame = true;
|
||||
m_Message = message;
|
||||
m_Callback = callback;
|
||||
|
||||
if ( message != null )
|
||||
m.SendMessage( 0x40, message );
|
||||
}
|
||||
|
||||
protected override void OnTarget(Mobile from, object targeted)
|
||||
{
|
||||
if ( !m_IgnoreGame && ( m_Game == null || !m_Game.AllowTarget ) )
|
||||
return;
|
||||
|
||||
if ( m_Callback != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
m_Callback.DynamicInvoke( new object[] { from, targeted } );
|
||||
}
|
||||
catch ( Exception err )
|
||||
{
|
||||
Console.WriteLine( err.ToString() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove( Mobile m )
|
||||
{
|
||||
Invoke( m, new Point3D( 0, 0, 0 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
131
Scripts/Scripts-master/Games/Battle Chess/ChessTimer.cs
Normal file
131
Scripts/Scripts-master/Games/Battle Chess/ChessTimer.cs
Normal file
@@ -0,0 +1,131 @@
|
||||
using System;
|
||||
|
||||
using Server;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
public class ChessTimer
|
||||
{
|
||||
private InternalTimer m_Timer;
|
||||
|
||||
private DateTime m_LastMove = DateTime.MaxValue;
|
||||
private DateTime m_Disconnect = DateTime.MaxValue;
|
||||
private DateTime m_GameStart;
|
||||
private DateTime m_EndGame = DateTime.MaxValue;
|
||||
|
||||
private ChessGame m_Game;
|
||||
|
||||
public ChessTimer( ChessGame game )
|
||||
{
|
||||
m_Game = game;
|
||||
m_Timer = new InternalTimer( this );
|
||||
m_Timer.Start();
|
||||
|
||||
m_GameStart = DateTime.Now;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if ( m_Timer != null && m_Timer.Running )
|
||||
{
|
||||
m_Timer.Stop();
|
||||
m_Timer = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnTick()
|
||||
{
|
||||
if ( m_Game == null )
|
||||
{
|
||||
m_Timer.Stop();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( m_GameStart != DateTime.MaxValue )
|
||||
{
|
||||
// Still starting the game
|
||||
if ( ( DateTime.Now - m_GameStart ) >= ChessConfig.GameStartTimeOut )
|
||||
{
|
||||
m_Game.Cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
if ( m_EndGame != DateTime.MaxValue )
|
||||
{
|
||||
if ( ( DateTime.Now - m_EndGame ) >= ChessConfig.EndGameTimerOut )
|
||||
{
|
||||
m_Game.Cleanup();
|
||||
}
|
||||
|
||||
return; // Waiting for end game, don't bother with other checks
|
||||
}
|
||||
|
||||
if ( m_LastMove != DateTime.MaxValue )
|
||||
{
|
||||
// Now playing
|
||||
if ( ( DateTime.Now - m_LastMove ) >= ChessConfig.MoveTimeOut )
|
||||
{
|
||||
m_EndGame = DateTime.Now;
|
||||
m_Game.OnMoveTimeout();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( m_Disconnect != DateTime.MaxValue )
|
||||
{
|
||||
// A player has been disconnected
|
||||
if ( ( DateTime.Now - m_Disconnect ) >= ChessConfig.DisconnectTimeOut )
|
||||
{
|
||||
m_Game.Cleanup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnGameStart()
|
||||
{
|
||||
m_GameStart = DateTime.MaxValue;
|
||||
m_LastMove = DateTime.Now;
|
||||
}
|
||||
|
||||
public void OnMoveMade()
|
||||
{
|
||||
m_LastMove = DateTime.Now;
|
||||
m_EndGame = DateTime.MaxValue;
|
||||
}
|
||||
|
||||
public void OnPlayerDisconnected()
|
||||
{
|
||||
if ( m_Disconnect == DateTime.MaxValue )
|
||||
m_Disconnect = DateTime.Now;
|
||||
}
|
||||
|
||||
public void OnPlayerConnected()
|
||||
{
|
||||
m_Disconnect = DateTime.MaxValue;
|
||||
}
|
||||
|
||||
public void OnGameOver()
|
||||
{
|
||||
m_EndGame = DateTime.Now;
|
||||
}
|
||||
|
||||
private class InternalTimer : Timer
|
||||
{
|
||||
private ChessTimer m_Parent;
|
||||
|
||||
public InternalTimer( ChessTimer parent ) : base( TimeSpan.FromSeconds( 15 ), TimeSpan.FromSeconds( 15 ) )
|
||||
{
|
||||
Priority = TimerPriority.FiveSeconds;
|
||||
m_Parent = parent;
|
||||
}
|
||||
|
||||
protected override void OnTick()
|
||||
{
|
||||
if ( m_Parent != null )
|
||||
m_Parent.OnTick();
|
||||
else
|
||||
Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1087
Scripts/Scripts-master/Games/Battle Chess/Chessboard.cs
Normal file
1087
Scripts/Scripts-master/Games/Battle Chess/Chessboard.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
public class ChessHelpGump : Gump
|
||||
{
|
||||
private const int LabelHue = 0x480;
|
||||
private const int GreenHue = 0x40;
|
||||
|
||||
public ChessHelpGump( Mobile m ) : base( 150, 150 )
|
||||
{
|
||||
m.CloseGump( typeof( ChessHelpGump ) );
|
||||
MakeGump();
|
||||
}
|
||||
|
||||
private void MakeGump()
|
||||
{
|
||||
this.Closable=true;
|
||||
this.Disposable=true;
|
||||
this.Dragable=true;
|
||||
this.Resizable=false;
|
||||
this.AddPage(0);
|
||||
this.AddBackground(0, 0, 420, 271, 9300);
|
||||
this.AddAlphaRegion( 0, 0, 420, 271 );
|
||||
|
||||
this.AddLabel(134, 5, GreenHue, @"Chess Game Information");
|
||||
|
||||
this.AddButton(20, 32, 5601, 5605, 1, GumpButtonType.Reply, 0);
|
||||
this.AddLabel(45, 30, LabelHue, @"Basic rules and pieces moves");
|
||||
this.AddButton(20, 57, 5601, 5605, 2, GumpButtonType.Reply, 0);
|
||||
this.AddLabel(45, 55, LabelHue, @"General Chess FAQ");
|
||||
this.AddButton(20, 82, 5601, 5605, 3, GumpButtonType.Reply, 0);
|
||||
this.AddLabel(45, 80, LabelHue, @"Check, Checkmate and Stalemate FAQ");
|
||||
this.AddButton(20, 107, 5601, 5605, 4, GumpButtonType.Reply, 0);
|
||||
this.AddLabel(45, 105, LabelHue, @"Castle FAQ");
|
||||
this.AddLabel(45, 120, LabelHue, @"Note: To castle in Battle Chess, select the King and move it");
|
||||
this.AddLabel(45, 135, LabelHue, @"on the Rook (or do exactly the opposite)");
|
||||
this.AddButton(20, 162, 5601, 5605, 5, GumpButtonType.Reply, 0);
|
||||
this.AddLabel(45, 160, LabelHue, @"The En Passant Move");
|
||||
this.AddButton(20, 207, 5601, 5605, 6, GumpButtonType.Reply, 0);
|
||||
this.AddLabel(20, 185, GreenHue, @"Pieces FAQs");
|
||||
this.AddLabel(40, 205, LabelHue, @"Pawn");
|
||||
this.AddButton(85, 207, 5601, 5605, 7, GumpButtonType.Reply, 0);
|
||||
this.AddLabel(105, 205, LabelHue, @"Knight");
|
||||
this.AddButton(155, 207, 5601, 5605, 8, GumpButtonType.Reply, 0);
|
||||
this.AddLabel(175, 205, LabelHue, @"Queen");
|
||||
this.AddButton(220, 207, 5601, 5605, 9, GumpButtonType.Reply, 0);
|
||||
this.AddLabel(240, 205, LabelHue, @"King");
|
||||
this.AddButton(20, 242, 5601, 5605, 0, GumpButtonType.Reply, 0);
|
||||
this.AddLabel(40, 240, LabelHue, @"Exit");
|
||||
}
|
||||
|
||||
public override void OnResponse(Server.Network.NetState sender, RelayInfo info)
|
||||
{
|
||||
string web = null;
|
||||
|
||||
switch ( info.ButtonID )
|
||||
{
|
||||
case 1 : web = "http://www.chessvariants.com/d.chess/chess.html";
|
||||
break;
|
||||
|
||||
case 2 : web = "http://www.chessvariants.com/d.chess/faq.html";
|
||||
break;
|
||||
|
||||
case 3 : web = "http://www.chessvariants.com/d.chess/matefaq.html";
|
||||
break;
|
||||
|
||||
case 4 : web = "http://www.chessvariants.com/d.chess/castlefaq.html";
|
||||
break;
|
||||
|
||||
case 5 : web = "http://www.chessvariants.com/d.chess/enpassant.html";
|
||||
break;
|
||||
|
||||
case 6 : web = "http://www.chessvariants.com/d.chess/pawnfaq.html";
|
||||
break;
|
||||
|
||||
case 7 : web = "http://www.chessvariants.com/d.chess/knightfaq.html";
|
||||
break;
|
||||
|
||||
case 8 : web = "http://www.chessvariants.com/d.chess/queenfaq.html";
|
||||
break;
|
||||
|
||||
case 9 : web = "http://www.chessvariants.com/d.chess/kingfaq.html";
|
||||
break;
|
||||
}
|
||||
|
||||
if ( web != null )
|
||||
{
|
||||
sender.Mobile.LaunchBrowser( web );
|
||||
sender.Mobile.SendGump( this );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
132
Scripts/Scripts-master/Games/Battle Chess/Gumps/ChessSetGump.cs
Normal file
132
Scripts/Scripts-master/Games/Battle Chess/Gumps/ChessSetGump.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for ChessSetGump.
|
||||
/// </summary>
|
||||
public class ChessSetGump : Gump
|
||||
{
|
||||
private const int LabelHue = 0x480;
|
||||
private const int GreenHue = 0x40;
|
||||
private static string[] m_Sets;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of chess sets available
|
||||
/// </summary>
|
||||
private static string[] Sets
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Sets == null )
|
||||
m_Sets = Enum.GetNames( typeof( Arya.Chess.ChessSet ) );
|
||||
|
||||
return m_Sets;
|
||||
}
|
||||
}
|
||||
|
||||
private ChessGame m_Game;
|
||||
private Mobile m_User;
|
||||
private bool m_IsOwner;
|
||||
private bool m_AllowSpectators;
|
||||
private int m_Page = 0;
|
||||
|
||||
public ChessSetGump( Mobile m, ChessGame game, bool isOwner, bool allowSpectators, int page ) : base( 200, 200 )
|
||||
{
|
||||
m_Game = game;
|
||||
m_User = m;
|
||||
m_IsOwner = isOwner;
|
||||
m_AllowSpectators = allowSpectators;
|
||||
m_Page = page;
|
||||
|
||||
m_User.CloseGump( typeof( ChessSetGump ) );
|
||||
|
||||
MakeGump();
|
||||
}
|
||||
|
||||
public ChessSetGump( Mobile m, ChessGame game, bool isOwner, bool allowSpectators ) : this( m, game, isOwner, allowSpectators, 0 )
|
||||
{
|
||||
}
|
||||
|
||||
private void MakeGump()
|
||||
{
|
||||
this.Closable=false;
|
||||
this.Disposable=true;
|
||||
this.Dragable=true;
|
||||
this.Resizable=false;
|
||||
|
||||
this.AddPage(0);
|
||||
this.AddBackground(0, 0, 320, 170, 9250);
|
||||
this.AddAlphaRegion(0, 0, 320, 170);
|
||||
|
||||
for ( int i = 0; i < 4 && 4 * m_Page + i < Sets.Length; i++ )
|
||||
{
|
||||
AddButton( 35, 45 + i * 20, 5601, 5605, 10 + 4 * m_Page + i, GumpButtonType.Reply, 0 );
|
||||
AddLabel( 60, 43 + i * 20, LabelHue, Sets[ 4 * m_Page + i ] );
|
||||
}
|
||||
|
||||
if ( m_Page > 0 )
|
||||
{
|
||||
this.AddButton(15, 15, 5603, 5607, 1, GumpButtonType.Reply, 0);
|
||||
}
|
||||
|
||||
int totalPages = ( Sets.Length - 1 ) / 4;
|
||||
|
||||
// Prev page : 1
|
||||
// Next page : 2
|
||||
|
||||
if ( totalPages > m_Page )
|
||||
{
|
||||
this.AddButton(35, 15, 5601, 5605, 2, GumpButtonType.Reply, 0);
|
||||
}
|
||||
|
||||
this.AddLabel(60, 13, GreenHue, @"Chess set selection");
|
||||
|
||||
// Cancel 3
|
||||
this.AddButton(15, 130, 4020, 4021, 3, GumpButtonType.Reply, 0);
|
||||
this.AddLabel(55, 130, GreenHue, @"Cancel Game");
|
||||
}
|
||||
|
||||
public override void OnResponse(Server.Network.NetState sender, RelayInfo info)
|
||||
{
|
||||
switch ( info.ButtonID )
|
||||
{
|
||||
case 0 : return;
|
||||
|
||||
case 1:
|
||||
|
||||
sender.Mobile.SendGump( new ChessSetGump( m_User, m_Game, m_IsOwner, m_AllowSpectators, --m_Page ) );
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
sender.Mobile.SendGump( new ChessSetGump( m_User, m_Game, m_IsOwner, m_AllowSpectators, ++m_Page ) );
|
||||
break;
|
||||
|
||||
case 3:
|
||||
|
||||
m_Game.CancelGameStart( sender.Mobile );
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
int index = info.ButtonID - 10;
|
||||
|
||||
ChessSet s = (ChessSet) Enum.Parse( typeof( Arya.Chess.ChessSet ), Sets[ index ], false );
|
||||
m_Game.SetChessSet( s );
|
||||
|
||||
sender.Mobile.SendGump( new StartGameGump( sender.Mobile, m_Game, m_IsOwner, m_AllowSpectators ) );
|
||||
sender.Mobile.Target = new ChessTarget( m_Game, sender.Mobile, "Please select your parnter...",
|
||||
new ChessTargetCallback( m_Game.ChooseOpponent ) );
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
public class EndGameGump : Gump
|
||||
{
|
||||
private const int LabelHue = 0x480;
|
||||
private const int GreenHue = 0x40;
|
||||
|
||||
private ChessGame m_Game;
|
||||
private bool m_GameOver;
|
||||
|
||||
public EndGameGump( Mobile m, ChessGame game, bool over, string details, int timeout ) : base( 200, 200 )
|
||||
{
|
||||
m.CloseGump( typeof( EndGameGump ) );
|
||||
m_Game = game;
|
||||
m_GameOver = over;
|
||||
|
||||
this.Closable=false;
|
||||
this.Disposable=true;
|
||||
this.Dragable=true;
|
||||
this.Resizable=false;
|
||||
|
||||
this.AddPage(0);
|
||||
this.AddBackground(0, 0, 265, 160, 9250);
|
||||
this.AddImageTiled(0, 0, 265, 160, 9304);
|
||||
this.AddImageTiled(1, 1, 263, 158, 9274);
|
||||
this.AddAlphaRegion(1, 1, 263, 158);
|
||||
|
||||
// Button 1 : End Game
|
||||
this.AddButton(10, 127, 5601, 5605, 1, GumpButtonType.Reply, 0);
|
||||
|
||||
this.AddLabel(10, 10, LabelHue, string.Format( "This game is : {0}", over ? "Over" : "Pending" ) );
|
||||
this.AddLabel(10, 30, LabelHue, @"Details");
|
||||
this.AddLabel(30, 55, GreenHue, details);
|
||||
this.AddLabel(30, 125, LabelHue, @"End Game");
|
||||
|
||||
if ( timeout > -1 )
|
||||
{
|
||||
this.AddLabel(10, 80, LabelHue, string.Format( "Wait {0} minutes before the game ends", timeout ) );
|
||||
this.AddLabel(10, 95, LabelHue, @"automatically. Do not close this gump.");
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnResponse(Server.Network.NetState sender, RelayInfo info)
|
||||
{
|
||||
if ( info.ButtonID == 1 )
|
||||
{
|
||||
if ( m_GameOver )
|
||||
{
|
||||
// Reset the game
|
||||
m_Game.NotifyGameOver( sender.Mobile );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Force end the game
|
||||
m_Game.Cleanup();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
112
Scripts/Scripts-master/Games/Battle Chess/Gumps/GameGump.cs
Normal file
112
Scripts/Scripts-master/Games/Battle Chess/Gumps/GameGump.cs
Normal file
@@ -0,0 +1,112 @@
|
||||
using System;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
/// <summary>
|
||||
/// Main game gump
|
||||
/// </summary>
|
||||
public class GameGump : Gump
|
||||
{
|
||||
private const int LabelHue = 0x480;
|
||||
private const int GreenHue = 0x40;
|
||||
|
||||
private ChessGame m_Game;
|
||||
private bool m_Move;
|
||||
private bool m_Moving;
|
||||
private string m_Message;
|
||||
private ChessColor m_Color;
|
||||
|
||||
public GameGump( Mobile m, ChessGame game, ChessColor color, string message, bool move, bool moving ): base( 60, 25 )
|
||||
{
|
||||
m.CloseGump( typeof( GameGump ) );
|
||||
|
||||
m_Game = game;
|
||||
m_Message = message;
|
||||
m_Color = color;
|
||||
m_Move = move;
|
||||
m_Moving = moving;
|
||||
|
||||
if ( move && ! moving )
|
||||
m_Game.SendMoveTarget( m );
|
||||
|
||||
MakeGump();
|
||||
}
|
||||
|
||||
private void MakeGump()
|
||||
{
|
||||
this.Closable=false;
|
||||
this.Disposable=true;
|
||||
this.Dragable=true;
|
||||
this.Resizable=false;
|
||||
|
||||
this.AddPage(0);
|
||||
this.AddBackground(0, 0, 555, 50, 9250);
|
||||
this.AddImageTiled(0, 0, 555, 50, 9304);
|
||||
this.AddImageTiled(1, 1, 553, 48, 9274);
|
||||
this.AddAlphaRegion(1, 1, 553, 48);
|
||||
|
||||
if ( m_Color == ChessColor.White )
|
||||
{
|
||||
this.AddImage(5, 5, 2331);
|
||||
this.AddLabel(30, 5, LabelHue, @"You are WHITE");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.AddImage(5, 5, 2338);
|
||||
this.AddLabel(30, 5, LabelHue, @"You are BLACK");
|
||||
}
|
||||
|
||||
string msg = null;
|
||||
|
||||
if ( m_Moving )
|
||||
msg = "Making your move";
|
||||
else if ( m_Move )
|
||||
msg = "Make your move";
|
||||
else
|
||||
msg = "Waiting for opponent to move";
|
||||
|
||||
this.AddLabel(165, 5, LabelHue, msg);
|
||||
|
||||
// B1 : Make move
|
||||
if ( m_Move )
|
||||
this.AddButton(145, 7, 5601, 5605, 1, GumpButtonType.Reply, 0);
|
||||
|
||||
// B2 : Chess Help
|
||||
this.AddButton(365, 7, 5601, 5605, 2, GumpButtonType.Reply, 0);
|
||||
this.AddLabel(385, 5, LabelHue, @"Chess Help");
|
||||
|
||||
// B3 : End Game
|
||||
this.AddButton(460, 7, 5601, 5605, 3, GumpButtonType.Reply, 0);
|
||||
this.AddLabel(480, 5, LabelHue, @"End Game");
|
||||
|
||||
if ( m_Message != null )
|
||||
this.AddLabel(5, 25, GreenHue, m_Message );
|
||||
}
|
||||
|
||||
public override void OnResponse(Server.Network.NetState sender, RelayInfo info)
|
||||
{
|
||||
switch ( info.ButtonID )
|
||||
{
|
||||
case 1 : // Make move
|
||||
|
||||
sender.Mobile.SendGump( new GameGump( sender.Mobile, m_Game, m_Color, m_Message, m_Move, m_Moving ) );
|
||||
break;
|
||||
|
||||
case 2: // Chess Help
|
||||
|
||||
sender.Mobile.SendGump( new ChessHelpGump( sender.Mobile ) );
|
||||
|
||||
sender.Mobile.SendGump( this );
|
||||
break;
|
||||
|
||||
case 3: // End game
|
||||
|
||||
m_Game.Cleanup();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
public class PawnPromotionGump : Gump
|
||||
{
|
||||
private const int LabelHue = 0x480;
|
||||
private const int GreenHue = 0x40;
|
||||
|
||||
ChessGame m_Game;
|
||||
|
||||
public PawnPromotionGump( Mobile m, ChessGame game ) : base( 200, 200 )
|
||||
{
|
||||
m.CloseGump( typeof( PawnPromotionGump ) );
|
||||
m_Game = game;
|
||||
MakeGump();
|
||||
}
|
||||
|
||||
private void MakeGump()
|
||||
{
|
||||
this.Closable=false;
|
||||
this.Disposable=true;
|
||||
this.Dragable=true;
|
||||
this.Resizable=false;
|
||||
|
||||
this.AddPage(0);
|
||||
this.AddBackground(0, 0, 255, 185, 9200);
|
||||
this.AddImageTiled(0, 0, 255, 185, 9304);
|
||||
this.AddImageTiled(1, 1, 253, 183, 9274);
|
||||
this.AddAlphaRegion(1, 1, 253, 183);
|
||||
|
||||
this.AddLabel(20, 10, GreenHue, @"Your pawn is being promoted!");
|
||||
|
||||
this.AddLabel(20, 35, LabelHue, @"Promote to:");
|
||||
|
||||
this.AddButton(35, 70, 2337, 2344, 1, GumpButtonType.Reply, 0);
|
||||
this.AddLabel(25, 120, LabelHue, @"Queen");
|
||||
|
||||
this.AddButton(85, 70, 2333, 2340, 2, GumpButtonType.Reply, 0);
|
||||
this.AddLabel(80, 120, LabelHue, @"Rook");
|
||||
|
||||
this.AddButton(135, 70, 2335, 2344, 3, GumpButtonType.Reply, 0);
|
||||
this.AddLabel(130, 120, LabelHue, @"Knight");
|
||||
|
||||
this.AddButton(195, 70, 2332, 2339, 4, GumpButtonType.Reply, 0);
|
||||
this.AddLabel(185, 120, LabelHue, @"Bishop");
|
||||
|
||||
this.AddButton(25, 152, 9702, 248, 5, GumpButtonType.Reply, 0);
|
||||
this.AddLabel(50, 150, 0, @"Do not promote pawn");
|
||||
}
|
||||
|
||||
public override void OnResponse(Server.Network.NetState sender, RelayInfo info)
|
||||
{
|
||||
PawnPromotion type = PawnPromotion.None;
|
||||
|
||||
switch ( info.ButtonID )
|
||||
{
|
||||
case 0 :
|
||||
return; // This fixes a crash when staff deletes the pawn being promoted
|
||||
|
||||
case 1 : type = PawnPromotion.Queen;
|
||||
break;
|
||||
|
||||
case 2 : type = PawnPromotion.Rook;
|
||||
break;
|
||||
|
||||
case 3 : type = PawnPromotion.Knight;
|
||||
break;
|
||||
|
||||
case 4 : type = PawnPromotion.Bishop;
|
||||
break;
|
||||
|
||||
case 5: type = PawnPromotion.None;
|
||||
break;
|
||||
}
|
||||
|
||||
m_Game.OnPawnPromoted( type );
|
||||
}
|
||||
}
|
||||
}
|
||||
63
Scripts/Scripts-master/Games/Battle Chess/Gumps/ScoreGump.cs
Normal file
63
Scripts/Scripts-master/Games/Battle Chess/Gumps/ScoreGump.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for ScoreGump.
|
||||
/// </summary>
|
||||
public class ScoreGump : Gump
|
||||
{
|
||||
private ChessGame m_Game;
|
||||
private const int LabelHue = 0x480;
|
||||
private const int GreenHue = 0x40;
|
||||
|
||||
public ScoreGump( Mobile m, ChessGame game, int[] white, int[] black, int totwhite, int totblack ) : base( 0, 25 )
|
||||
{
|
||||
m.CloseGump( typeof( ScoreGump ) );
|
||||
m_Game = game;
|
||||
|
||||
MakeGump( white, black, totwhite, totblack );
|
||||
}
|
||||
|
||||
private void MakeGump( int[] white, int[] black, int whitescore, int blackscore )
|
||||
{
|
||||
this.Closable=true;
|
||||
this.Disposable=true;
|
||||
this.Dragable=true;
|
||||
this.Resizable=false;
|
||||
this.AddPage(0);
|
||||
this.AddBackground(0, 0, 60, 345, 9350);
|
||||
this.AddAlphaRegion(0, 0, 60, 345);
|
||||
this.AddImage(5, 5, 2336);
|
||||
this.AddImage(30, 6, 2343);
|
||||
this.AddImage(5, 50, 2335);
|
||||
this.AddImage(30, 50, 2342);
|
||||
this.AddImage(5, 105, 2332);
|
||||
this.AddImage(30, 105, 2339);
|
||||
this.AddImage(5, 160, 2333);
|
||||
this.AddImage(30, 160, 2340);
|
||||
this.AddImage(5, 220, 2337);
|
||||
this.AddImage(30, 220, 2344);
|
||||
this.AddImageTiled(0, 285, 60, 1, 5124);
|
||||
this.AddImage(10, 305, 2331);
|
||||
this.AddImage(10, 325, 2338);
|
||||
|
||||
this.AddLabel(11, 33, LabelHue, white[0].ToString() );
|
||||
this.AddLabel(5, 285, GreenHue, @"Score");
|
||||
this.AddLabel(36, 33, LabelHue, black[0].ToString() );
|
||||
this.AddLabel(11, 87, LabelHue, white[1].ToString() );
|
||||
this.AddLabel(36, 87, LabelHue, black[1].ToString() );
|
||||
this.AddLabel(11, 142, LabelHue, white[2].ToString() );
|
||||
this.AddLabel(36, 142, LabelHue, black[2].ToString() );
|
||||
this.AddLabel(11, 200, LabelHue, white[3].ToString() );
|
||||
this.AddLabel(36, 200, LabelHue, black[3].ToString() );
|
||||
this.AddLabel(11, 260, LabelHue, white[4].ToString() );
|
||||
this.AddLabel(36, 260, LabelHue, black[4].ToString() );
|
||||
this.AddLabel(30, 302, LabelHue, whitescore.ToString() );
|
||||
this.AddLabel(30, 322, LabelHue, blackscore.ToString() );
|
||||
}
|
||||
}
|
||||
}
|
||||
125
Scripts/Scripts-master/Games/Battle Chess/Gumps/StartGameGump.cs
Normal file
125
Scripts/Scripts-master/Games/Battle Chess/Gumps/StartGameGump.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
/// <summary>
|
||||
/// This gump is used to start the game
|
||||
/// </summary>
|
||||
public class StartGameGump : Gump
|
||||
{
|
||||
private const int LabelHue = 0x480;
|
||||
private const int GreenHue = 0x40;
|
||||
|
||||
private ChessGame m_Game;
|
||||
private Mobile m_User;
|
||||
private bool m_IsOwner;
|
||||
private bool m_AllowSpectators;
|
||||
|
||||
public StartGameGump( Mobile m, ChessGame game, bool isOwner, bool allowSpectators ) : base( 200, 200 )
|
||||
{
|
||||
m_Game = game;
|
||||
m_User = m;
|
||||
m_IsOwner = isOwner;
|
||||
m_AllowSpectators = allowSpectators;
|
||||
|
||||
m_User.CloseGump( typeof( StartGameGump ) );
|
||||
|
||||
MakeGump();
|
||||
}
|
||||
|
||||
private void MakeGump()
|
||||
{
|
||||
this.Closable=false;
|
||||
this.Disposable=true;
|
||||
this.Dragable=true;
|
||||
this.Resizable=false;
|
||||
|
||||
this.AddPage(0);
|
||||
int height = 75;
|
||||
|
||||
if ( m_IsOwner )
|
||||
height = 110;
|
||||
|
||||
this.AddBackground(0, 0, 300, height, 9250);
|
||||
this.AddImageTiled(0, 0, 300, height, 9304);
|
||||
this.AddImageTiled(1, 1, 298, height - 2, 9274);
|
||||
this.AddAlphaRegion(1, 1, 298, height - 2);
|
||||
|
||||
if ( m_IsOwner )
|
||||
{
|
||||
if ( m_Game.Guest == null )
|
||||
this.AddLabel(10, 5, GreenHue, @"Starting new chess game");
|
||||
else
|
||||
this.AddLabel(10, 5, GreenHue, @"Waiting for partner to accept");
|
||||
|
||||
this.AddImageTiled(10, 25, 280, 1, 9304);
|
||||
|
||||
// Bring again target : 1
|
||||
if ( m_Game.Guest == null )
|
||||
{
|
||||
this.AddButton(15, 30, 5601, 5605, 1, GumpButtonType.Reply, 0);
|
||||
this.AddLabel(35, 28, LabelHue, @"Please select your opponent...");
|
||||
}
|
||||
|
||||
// Cancel : 0
|
||||
this.AddButton(15, 50, 5601, 5605, 2, GumpButtonType.Reply, 0);
|
||||
this.AddLabel(35, 48, LabelHue, @"Cancel");
|
||||
|
||||
int bid = m_AllowSpectators ? 2153 : 2151;
|
||||
this.AddButton( 10, 75, bid, bid, 3, GumpButtonType.Reply, 0 );
|
||||
this.AddLabel( 45, 80, LabelHue, "Allow spectators on the Chessboard" );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.AddLabel(10, 5, GreenHue, string.Format( "Play chess with {0}?", m_Game.Owner.Name ) );
|
||||
this.AddImageTiled(10, 25, 280, 1, 9304);
|
||||
|
||||
// Accept : 1
|
||||
this.AddButton(15, 30, 5601, 5605, 1, GumpButtonType.Reply, 0);
|
||||
this.AddLabel(35, 28, LabelHue, @"Accept");
|
||||
|
||||
// Refuse : 0
|
||||
this.AddButton(15, 50, 5601, 5605, 2, GumpButtonType.Reply, 0);
|
||||
this.AddLabel(35, 48, LabelHue, @"Refuse");
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnResponse(Server.Network.NetState sender, RelayInfo info)
|
||||
{
|
||||
if ( m_IsOwner )
|
||||
{
|
||||
if ( info.ButtonID == 3 )
|
||||
{
|
||||
// Switch the allow spectators flag
|
||||
m_Game.AllowSpectators = !m_AllowSpectators;
|
||||
sender.Mobile.SendGump( new StartGameGump( sender.Mobile, m_Game, m_IsOwner, !m_AllowSpectators ) );
|
||||
}
|
||||
else if ( info.ButtonID == 2 )
|
||||
{
|
||||
m_Game.CancelGameStart( sender.Mobile );
|
||||
}
|
||||
else if ( info.ButtonID == 1 )
|
||||
{
|
||||
sender.Mobile.Target = new ChessTarget( m_Game, sender.Mobile, "Please select your partner...",
|
||||
new ChessTargetCallback( m_Game.ChooseOpponent ) );
|
||||
|
||||
sender.Mobile.SendGump( new StartGameGump( sender.Mobile, m_Game, m_IsOwner, m_AllowSpectators ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( info.ButtonID == 2 )
|
||||
{
|
||||
m_Game.CancelGameStart( sender.Mobile );
|
||||
}
|
||||
else if ( info.ButtonID == 1 )
|
||||
{
|
||||
m_Game.AcceptGame( sender.Mobile );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
508
Scripts/Scripts-master/Games/Battle Chess/Items/ChessControl.cs
Normal file
508
Scripts/Scripts-master/Games/Battle Chess/Items/ChessControl.cs
Normal file
@@ -0,0 +1,508 @@
|
||||
using System;
|
||||
|
||||
using Server;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
/// <summary>
|
||||
/// This is the control stone that allows player to play chess
|
||||
/// </summary>
|
||||
public class ChessControl : Item
|
||||
{
|
||||
#region Variables
|
||||
|
||||
private ChessGame m_Game;
|
||||
private Rectangle2D m_Bounds;
|
||||
private int m_SquareWidth = 2;
|
||||
private int m_BoardHeight = 0;
|
||||
private ChessSet m_ChessSet = ChessSet.Classic;
|
||||
private int m_WhiteHue = 91;
|
||||
private int m_BlackHue = 437;
|
||||
private int m_AttackEffect = 14068; // Fire snake
|
||||
private int m_CaptureEffect = 14186; // Blue/Gold Sparkle 2
|
||||
private bool m_BoltOnDeath = true;
|
||||
private bool m_AllowSpectators = false;
|
||||
private BoardOrientation m_Orientation = BoardOrientation.NorthSouth;
|
||||
private int m_BlackMinorHue = 447;
|
||||
private int m_WhiteMinorHue = 96;
|
||||
private bool m_OverrideMinorHue = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
[ CommandProperty( AccessLevel.GameMaster ) ]
|
||||
public Rectangle2D Bounds
|
||||
{
|
||||
get { return m_Bounds; }
|
||||
}
|
||||
|
||||
[ CommandProperty( AccessLevel.GameMaster ) ]
|
||||
public Point2D BoardNorthWestCorner
|
||||
{
|
||||
get { return m_Bounds.Start; }
|
||||
set
|
||||
{
|
||||
m_Bounds.Start = value;
|
||||
m_Bounds.Width = 8 * m_SquareWidth;
|
||||
m_Bounds.Height = 8 * m_SquareWidth;
|
||||
|
||||
InvalidateProperties();
|
||||
}
|
||||
}
|
||||
|
||||
[ CommandProperty( AccessLevel.GameMaster ) ]
|
||||
public int SquareWidth
|
||||
{
|
||||
get { return m_SquareWidth; }
|
||||
set
|
||||
{
|
||||
if ( value < 1 )
|
||||
return;
|
||||
|
||||
m_SquareWidth = value;
|
||||
|
||||
if ( m_Bounds.Start != Point2D.Zero )
|
||||
{
|
||||
m_Bounds.Width = 8 * m_SquareWidth;
|
||||
m_Bounds.Height = 8 * m_SquareWidth;
|
||||
|
||||
InvalidateProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ CommandProperty( AccessLevel.GameMaster ) ]
|
||||
public int WhiteHue
|
||||
{
|
||||
get { return m_WhiteHue; }
|
||||
set
|
||||
{
|
||||
if ( value < 0 || value > 3000 )
|
||||
return;
|
||||
|
||||
if ( value == m_WhiteHue )
|
||||
return;
|
||||
|
||||
m_WhiteHue = value;
|
||||
|
||||
if ( m_Game != null )
|
||||
m_Game.SetHues( m_WhiteHue, m_BlackHue, m_WhiteMinorHue, m_BlackMinorHue );
|
||||
}
|
||||
}
|
||||
|
||||
[ CommandProperty( AccessLevel.GameMaster ) ]
|
||||
public int BlackHue
|
||||
{
|
||||
get { return m_BlackHue; }
|
||||
set
|
||||
{
|
||||
if ( value < 0 || value > 3000 )
|
||||
return;
|
||||
|
||||
if ( value == m_BlackHue )
|
||||
return;
|
||||
|
||||
m_BlackHue = value;
|
||||
|
||||
if ( m_Game != null )
|
||||
m_Game.SetHues( m_WhiteHue, m_BlackHue, m_WhiteMinorHue, m_BlackMinorHue );
|
||||
}
|
||||
}
|
||||
|
||||
[ CommandProperty( AccessLevel.GameMaster ) ]
|
||||
public int WhiteMinorHue
|
||||
{
|
||||
get { return m_WhiteMinorHue; }
|
||||
set
|
||||
{
|
||||
if ( value < 0 || value > 3000 )
|
||||
return;
|
||||
|
||||
if ( value == m_WhiteMinorHue )
|
||||
return;
|
||||
|
||||
m_WhiteMinorHue = value;
|
||||
|
||||
if ( m_Game != null )
|
||||
m_Game.SetHues( m_WhiteHue, m_BlackHue, m_WhiteMinorHue, m_BlackMinorHue );
|
||||
}
|
||||
}
|
||||
|
||||
[ CommandProperty( AccessLevel.GameMaster ) ]
|
||||
public int BlackMinorHue
|
||||
{
|
||||
get { return m_BlackMinorHue; }
|
||||
set
|
||||
{
|
||||
if ( value < 0 || value > 3000 )
|
||||
return;
|
||||
|
||||
if ( value == m_BlackMinorHue )
|
||||
return;
|
||||
|
||||
m_BlackMinorHue = value;
|
||||
|
||||
if ( m_Game != null )
|
||||
m_Game.SetHues( m_WhiteHue, m_BlackHue, m_WhiteMinorHue, m_BlackMinorHue );
|
||||
}
|
||||
}
|
||||
|
||||
[ CommandProperty( AccessLevel.GameMaster ) ]
|
||||
public bool OverrideMinorHue
|
||||
{
|
||||
get { return m_OverrideMinorHue; }
|
||||
set
|
||||
{
|
||||
if ( value != m_OverrideMinorHue )
|
||||
{
|
||||
m_OverrideMinorHue = value;
|
||||
|
||||
if ( m_Game != null )
|
||||
m_Game.SetMinorHueOverride( m_OverrideMinorHue );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ CommandProperty( AccessLevel.GameMaster ) ]
|
||||
public int AttackEffect
|
||||
{
|
||||
get { return m_AttackEffect; }
|
||||
set { m_AttackEffect = value; }
|
||||
}
|
||||
|
||||
[ CommandProperty( AccessLevel.GameMaster ) ]
|
||||
public int CaptureEffect
|
||||
{
|
||||
get { return m_CaptureEffect; }
|
||||
set { m_CaptureEffect = value; }
|
||||
}
|
||||
|
||||
[ CommandProperty( AccessLevel.GameMaster ) ]
|
||||
public bool BoltOnDeath
|
||||
{
|
||||
get { return m_BoltOnDeath; }
|
||||
set { m_BoltOnDeath = value; }
|
||||
}
|
||||
|
||||
[ CommandProperty( AccessLevel.GameMaster ) ]
|
||||
public int BoardHeight
|
||||
{
|
||||
get { return m_BoardHeight; }
|
||||
set { m_BoardHeight = value; }
|
||||
}
|
||||
|
||||
[ CommandProperty( AccessLevel.GameMaster ) ]
|
||||
public ChessSet ChessSet
|
||||
{
|
||||
get { return m_ChessSet; }
|
||||
set
|
||||
{
|
||||
m_ChessSet = value;
|
||||
|
||||
if ( m_Game != null )
|
||||
m_Game.SetChessSet( m_ChessSet );
|
||||
}
|
||||
}
|
||||
|
||||
[ CommandProperty( AccessLevel.GameMaster ) ]
|
||||
public bool AllowSpectators
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Game != null && m_Game.Region != null )
|
||||
return m_Game.Region.AllowSpectators;
|
||||
else
|
||||
return m_AllowSpectators;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_AllowSpectators = value;
|
||||
|
||||
if ( m_Game != null && m_Game.Region != null )
|
||||
{
|
||||
m_Game.Region.AllowSpectators = m_AllowSpectators;
|
||||
InvalidateProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ CommandProperty( AccessLevel.GameMaster ) ]
|
||||
public BoardOrientation Orientation
|
||||
{
|
||||
get { return m_Orientation; }
|
||||
set
|
||||
{
|
||||
m_Orientation = value;
|
||||
|
||||
if ( m_Game != null )
|
||||
m_Game.SetOrientation( m_Orientation );
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[ Constructable ]
|
||||
public ChessControl() : base( 3796 )
|
||||
{
|
||||
Movable = false;
|
||||
Hue = 1285;
|
||||
Name = "Battle Chess";
|
||||
m_Bounds = new Rectangle2D( 0, 0, 0, 0 );
|
||||
}
|
||||
|
||||
public ChessControl( Serial serial ) : base( serial )
|
||||
{
|
||||
}
|
||||
|
||||
#region Serialization
|
||||
|
||||
public override void Serialize(GenericWriter writer)
|
||||
{
|
||||
base.Serialize (writer);
|
||||
|
||||
writer.Write( 3 ); // Version;
|
||||
|
||||
// Version 3
|
||||
writer.Write( m_OverrideMinorHue );
|
||||
writer.Write( m_AllowSpectators );
|
||||
// Version 2
|
||||
writer.Write( (byte) m_Orientation );
|
||||
writer.Write( m_BlackMinorHue );
|
||||
writer.Write( m_WhiteMinorHue );
|
||||
// Version 1
|
||||
writer.Write( (int) m_ChessSet );
|
||||
writer.Write( m_WhiteHue );
|
||||
writer.Write( m_BlackHue );
|
||||
writer.Write( m_AttackEffect );
|
||||
writer.Write( m_CaptureEffect );
|
||||
writer.Write( m_BoltOnDeath );
|
||||
// Version 0
|
||||
writer.Write( m_Bounds );
|
||||
writer.Write( m_SquareWidth );
|
||||
writer.Write( m_BoardHeight );
|
||||
}
|
||||
|
||||
public override void Deserialize(GenericReader reader)
|
||||
{
|
||||
base.Deserialize (reader);
|
||||
|
||||
int version = reader.ReadInt();
|
||||
|
||||
switch ( version )
|
||||
{
|
||||
case 3:
|
||||
|
||||
m_OverrideMinorHue = reader.ReadBool();
|
||||
m_AllowSpectators = reader.ReadBool();
|
||||
goto case 2;
|
||||
|
||||
case 2 :
|
||||
|
||||
m_Orientation = (BoardOrientation) reader.ReadByte();
|
||||
m_BlackMinorHue = reader.ReadInt();
|
||||
m_WhiteMinorHue = reader.ReadInt();
|
||||
goto case 1;
|
||||
|
||||
case 1:
|
||||
|
||||
m_ChessSet = ( ChessSet ) reader.ReadInt();
|
||||
m_WhiteHue = reader.ReadInt();
|
||||
m_BlackHue = reader.ReadInt();
|
||||
m_AttackEffect = reader.ReadInt();
|
||||
m_CaptureEffect = reader.ReadInt();
|
||||
m_BoltOnDeath = reader.ReadBool();
|
||||
goto case 0;
|
||||
|
||||
case 0:
|
||||
|
||||
m_Bounds = reader.ReadRect2D();
|
||||
m_SquareWidth = reader.ReadInt();
|
||||
m_BoardHeight = reader.ReadInt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
{
|
||||
base.GetProperties (list);
|
||||
|
||||
string status = "Not Configured";
|
||||
|
||||
if ( m_Bounds.Width > 0 )
|
||||
{
|
||||
if ( m_Game == null )
|
||||
status = "Ready";
|
||||
else
|
||||
status = "Game in progress";
|
||||
}
|
||||
|
||||
list.Add( 1060658, "Game Status\t{0}", status );
|
||||
|
||||
if ( m_Game != null )
|
||||
{
|
||||
bool spect = m_AllowSpectators;
|
||||
if ( m_Game.Region != null )
|
||||
spect = m_Game.Region.AllowSpectators;
|
||||
|
||||
list.Add( 1060659, "Spectators on the Chessboard\t{0}",
|
||||
spect ? "Allowed" : "Not Allowed" );
|
||||
list.Add( 1060660, "If you loose your target say\t{0}", ChessConfig.ResetKeyword );
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnDoubleClick(Mobile from)
|
||||
{
|
||||
if ( m_Bounds.Width == 0 )
|
||||
{
|
||||
// Not configured yet
|
||||
if ( from.AccessLevel >= AccessLevel.GameMaster )
|
||||
{
|
||||
from.Target = new ChessTarget( from, "Target the north west corner of the chessboard you wish to create",
|
||||
new ChessTargetCallback( OnBoardTarget ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
from.SendMessage( 0x40, "This chess board isn't ready for a game yet. Please contact a game master for assistance with its configuration." );
|
||||
}
|
||||
}
|
||||
else if ( m_Game != null )
|
||||
{
|
||||
if ( m_Game.IsPlayer( from ) && m_Game.AllowGame )
|
||||
m_Game.SendAllGumps( null, null );
|
||||
else
|
||||
from.SendMessage( 0x40, "A chess game is currently in progress. Please try again later." );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Game = new ChessGame( this, from, m_Bounds, m_BoardHeight );
|
||||
|
||||
InvalidateProperties();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnGameOver()
|
||||
{
|
||||
m_Game = null;
|
||||
InvalidateProperties();
|
||||
}
|
||||
|
||||
private void OnBoardTarget( Mobile from, object targeted )
|
||||
{
|
||||
IPoint3D p = targeted as IPoint3D;
|
||||
|
||||
if ( p == null )
|
||||
{
|
||||
from.SendMessage( 0x40, "Invalid location" );
|
||||
return;
|
||||
}
|
||||
|
||||
BuildBoard( this, new Point3D( p ), Map );
|
||||
InvalidateProperties();
|
||||
}
|
||||
|
||||
public override void OnDelete()
|
||||
{
|
||||
if ( m_Game != null )
|
||||
m_Game.Cleanup();
|
||||
|
||||
base.OnDelete();
|
||||
}
|
||||
|
||||
public void SetChessSet( ChessSet s )
|
||||
{
|
||||
m_ChessSet = s;
|
||||
}
|
||||
|
||||
#region Board Building
|
||||
|
||||
private static void BuildBoard( ChessControl chess, Point3D p, Map map )
|
||||
{
|
||||
chess.m_BoardHeight = p.Z + 5; // Placing stairs on the specified point
|
||||
chess.BoardNorthWestCorner = new Point2D( p.X, p.Y );
|
||||
|
||||
#region Board Tiles
|
||||
|
||||
int stairNW = 1909;
|
||||
int stairSE = 1910;
|
||||
int stairSW = 1911;
|
||||
int stairNE = 1912;
|
||||
int stairS = 1901;
|
||||
int stairE = 1902;
|
||||
int stairN = 1903;
|
||||
int stairW = 1904;
|
||||
int black = 1295;
|
||||
int white = 1298;
|
||||
|
||||
#endregion
|
||||
|
||||
for ( int x = 0; x < 8; x++ )
|
||||
{
|
||||
for ( int y = 0; y < 8; y++ )
|
||||
{
|
||||
int tile = 0;
|
||||
|
||||
if ( x % 2 == 0 )
|
||||
{
|
||||
if ( y % 2 == 0 )
|
||||
tile = black;
|
||||
else
|
||||
tile = white;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( y % 2 == 0 )
|
||||
tile = white;
|
||||
else
|
||||
tile = black;
|
||||
}
|
||||
|
||||
if ( chess.Orientation == BoardOrientation.EastWest ) // Invert tiles if the orientation is EW
|
||||
{
|
||||
if ( tile == white )
|
||||
tile = black;
|
||||
else
|
||||
tile = white;
|
||||
}
|
||||
|
||||
for ( int kx = 0; kx < chess.m_SquareWidth; kx++ )
|
||||
{
|
||||
for ( int ky = 0; ky < chess.m_SquareWidth; ky++ )
|
||||
{
|
||||
Server.Items.Static s = new Server.Items.Static( tile );
|
||||
Point3D target = new Point3D( p.X + x * chess.m_SquareWidth + kx, p.Y + y * chess.m_SquareWidth + ky, chess.m_BoardHeight );
|
||||
s.MoveToWorld( target, map );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Point3D nw = new Point3D( p.X - 1, p.Y - 1, p.Z );
|
||||
Point3D ne = new Point3D( p.X + 8 * chess.m_SquareWidth, p.Y - 1, p.Z );
|
||||
Point3D se = new Point3D( p.X + 8 * chess.m_SquareWidth, p.Y + 8 * chess.m_SquareWidth, p.Z );
|
||||
Point3D sw = new Point3D( p.X - 1, p.Y + 8 * chess.m_SquareWidth, p.Z );
|
||||
|
||||
new Server.Items.Static( stairNW ).MoveToWorld( nw, map );
|
||||
new Server.Items.Static( stairNE ).MoveToWorld( ne, map );
|
||||
new Server.Items.Static( stairSE ).MoveToWorld( se, map );
|
||||
new Server.Items.Static( stairSW ).MoveToWorld( sw, map );
|
||||
|
||||
for ( int x = 0; x < 8 * chess.m_SquareWidth; x++ )
|
||||
{
|
||||
Point3D top = new Point3D( p.X + x, p.Y - 1, p.Z );
|
||||
Point3D bottom = new Point3D( p.X + x, p.Y + 8 * chess.m_SquareWidth, p.Z );
|
||||
Point3D left = new Point3D( p.X - 1, p.Y + x, p.Z );
|
||||
Point3D right = new Point3D( p.X + chess.m_SquareWidth * 8, p.Y + x, p.Z );
|
||||
|
||||
new Server.Items.Static( stairN ).MoveToWorld( top, map );
|
||||
new Server.Items.Static( stairS ).MoveToWorld( bottom, map );
|
||||
new Server.Items.Static( stairW ).MoveToWorld( left, map );
|
||||
new Server.Items.Static( stairE ).MoveToWorld( right, map );
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
|
||||
using Server;
|
||||
using Server.Items;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
[ Flipable( 5357, 5358 ) ]
|
||||
public class WinnerPaper : Item
|
||||
{
|
||||
private string m_Winner;
|
||||
private string m_Looser;
|
||||
private DateTime m_GameEnd;
|
||||
private TimeSpan m_GameTime;
|
||||
private TimeSpan m_WinnerTime;
|
||||
private TimeSpan m_LooserTime;
|
||||
private int m_WinnerScore;
|
||||
private int m_LooserScore;
|
||||
|
||||
public WinnerPaper( Mobile winner, Mobile looser, TimeSpan gameTime, TimeSpan winnerTime, TimeSpan looserTime, int winnerScore, int looserScore) : base( 5357 )
|
||||
{
|
||||
Hue = 1159;
|
||||
Weight = 0.2;
|
||||
|
||||
m_Winner = winner.Name;
|
||||
m_Looser = looser.Name;
|
||||
m_GameEnd = DateTime.Now;
|
||||
m_GameTime = gameTime;
|
||||
m_WinnerTime = winnerTime;
|
||||
m_LooserTime = looserTime;
|
||||
m_WinnerScore = winnerScore;
|
||||
m_LooserScore = looserScore;
|
||||
|
||||
Name = string.Format( "{0} won a fair chess game vs {1}", m_Winner, m_Looser );
|
||||
}
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
{
|
||||
base.GetProperties (list);
|
||||
|
||||
list.Add( 1060658, "Date\t{0}", m_GameEnd.ToLongDateString() );
|
||||
list.Add( 1060659, "Total Game Time\t{0} Hours, {1} Minutes, {2} Seconds", m_GameTime.Hours, m_GameTime.Minutes, m_GameTime.Seconds );
|
||||
list.Add( 1060660, "{0}'s Game Time\t{1} Hours, {2} Minutes, {3} Seconds", m_Winner, m_WinnerTime.Hours, m_WinnerTime.Minutes, m_WinnerTime.Seconds );
|
||||
list.Add( 1060661, "{0}'s Game Time\t{1} Hours, {2} Minutes, {3} Seconds", m_Looser, m_LooserTime.Hours, m_LooserTime.Minutes, m_LooserTime.Seconds );
|
||||
list.Add( 1060662, "{0}'s Score\t{1}", m_Winner, m_WinnerScore );
|
||||
list.Add( 1060663, "{0}'s Score\t{1}", m_Looser, m_LooserScore );
|
||||
}
|
||||
|
||||
|
||||
public WinnerPaper( Serial serial ) : base( serial )
|
||||
{
|
||||
}
|
||||
|
||||
public override void Deserialize(GenericReader reader)
|
||||
{
|
||||
base.Deserialize (reader);
|
||||
|
||||
int version = reader.ReadInt();
|
||||
|
||||
m_Winner = reader.ReadString();
|
||||
m_Looser = reader.ReadString();
|
||||
m_GameEnd = reader.ReadDateTime();
|
||||
m_GameTime = reader.ReadTimeSpan();
|
||||
m_WinnerTime = reader.ReadTimeSpan();
|
||||
m_LooserTime = reader.ReadTimeSpan();
|
||||
m_WinnerScore = reader.ReadInt();
|
||||
m_LooserScore = reader.ReadInt();
|
||||
}
|
||||
|
||||
|
||||
public override void Serialize(GenericWriter writer)
|
||||
{
|
||||
base.Serialize (writer);
|
||||
|
||||
writer.Write( 0 );
|
||||
|
||||
writer.Write( m_Winner );
|
||||
writer.Write( m_Looser );
|
||||
writer.Write( m_GameEnd );
|
||||
writer.Write( m_GameTime );
|
||||
writer.Write( m_WinnerTime );
|
||||
writer.Write( m_LooserTime );
|
||||
writer.Write( m_WinnerScore );
|
||||
writer.Write( m_LooserScore );
|
||||
}
|
||||
}
|
||||
}
|
||||
96
Scripts/Scripts-master/Games/Battle Chess/Move.cs
Normal file
96
Scripts/Scripts-master/Games/Battle Chess/Move.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
|
||||
using Server;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
/// <summary>
|
||||
/// Describes a piece move
|
||||
/// </summary>
|
||||
public class Move
|
||||
{
|
||||
private Point2D m_From;
|
||||
private Point2D m_To;
|
||||
private BaseChessPiece m_Piece;
|
||||
private BaseChessPiece m_Captured;
|
||||
private bool m_EnPassant = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the initial position of the piece
|
||||
/// </summary>
|
||||
public Point2D From
|
||||
{
|
||||
get { return m_From; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the target destination of the move
|
||||
/// </summary>
|
||||
public Point2D To
|
||||
{
|
||||
get { return m_To; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the chess piece performing this move
|
||||
/// </summary>
|
||||
public BaseChessPiece Piece
|
||||
{
|
||||
get { return m_Piece; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the piece captured by this move
|
||||
/// </summary>
|
||||
public BaseChessPiece CapturedPiece
|
||||
{
|
||||
get { return m_Captured; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies if this move captures a piece
|
||||
/// </summary>
|
||||
public bool Capture
|
||||
{
|
||||
get { return m_Captured != null; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The color of the player making this move
|
||||
/// </summary>
|
||||
public ChessColor Color
|
||||
{
|
||||
get { return m_Piece.Color; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the color of the opponent of the player who made the move
|
||||
/// </summary>
|
||||
public ChessColor EnemyColor
|
||||
{
|
||||
get { return m_Piece.EnemyColor; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies if the capture is made EnPassant
|
||||
/// </summary>
|
||||
public bool EnPassant
|
||||
{
|
||||
get { return m_EnPassant; }
|
||||
set { m_EnPassant = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Move object without capturing a piece
|
||||
/// </summary>
|
||||
/// <param name="piece">The chess piece performing the move</param>
|
||||
/// <param name="target">The target location of the move</param>
|
||||
public Move( BaseChessPiece piece, Point2D target )
|
||||
{
|
||||
m_Piece = piece;
|
||||
m_From = m_Piece.Position;
|
||||
m_To = target;
|
||||
m_Captured = m_Piece.GetCaptured( target, ref m_EnPassant );
|
||||
}
|
||||
}
|
||||
}
|
||||
211
Scripts/Scripts-master/Games/Battle Chess/Pieces/Bishop.cs
Normal file
211
Scripts/Scripts-master/Games/Battle Chess/Pieces/Bishop.cs
Normal file
@@ -0,0 +1,211 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
using Server;
|
||||
using Server.Items;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
public class Bishop : BaseChessPiece
|
||||
{
|
||||
public static int GetGumpID( ChessColor color )
|
||||
{
|
||||
return color == ChessColor.Black ? 2339 : 2332;
|
||||
}
|
||||
|
||||
public override int Power
|
||||
{
|
||||
get
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Bishop( BChessboard board, ChessColor color, Point2D position ) : base( board, color, position )
|
||||
{
|
||||
}
|
||||
|
||||
public override void InitializePiece()
|
||||
{
|
||||
m_Piece = new ChessMobile( this );
|
||||
m_Piece.Name = string.Format( "Bishop [{0}]", m_Color.ToString() );
|
||||
|
||||
switch ( m_BChessboard.ChessSet )
|
||||
{
|
||||
case ChessSet.Classic : CreateClassic();
|
||||
break;
|
||||
|
||||
case ChessSet.Fantasy : CreateFantasy();
|
||||
break;
|
||||
|
||||
case ChessSet.FantasyGiant : CreateFantasyGiant();
|
||||
break;
|
||||
|
||||
case ChessSet.Animal : CreateAnimal();
|
||||
break;
|
||||
|
||||
case ChessSet.Undead : CreateUndead();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateUndead()
|
||||
{
|
||||
m_MoveSound = 415;
|
||||
m_CaptureSound = 1004;
|
||||
m_DeathSound = 1005;
|
||||
|
||||
m_Piece.BodyValue = 78; // Liche
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateAnimal()
|
||||
{
|
||||
m_MoveSound = 858;
|
||||
m_CaptureSound = 616;
|
||||
m_DeathSound = 623;
|
||||
|
||||
m_Piece.BodyValue = 80; // Giant toad
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasyGiant()
|
||||
{
|
||||
m_MoveSound = 373;
|
||||
m_CaptureSound = 372;
|
||||
m_DeathSound = 376;
|
||||
|
||||
m_Piece.BodyValue = 316; // Wanderer of the void
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasy()
|
||||
{
|
||||
m_MoveSound = 579;
|
||||
m_CaptureSound = 283;
|
||||
m_DeathSound = 250;
|
||||
|
||||
m_Piece.BodyValue = 124; // Evil mage
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateClassic()
|
||||
{
|
||||
m_MoveSound = 251;
|
||||
m_CaptureSound = 773;
|
||||
m_DeathSound = 1063;
|
||||
|
||||
m_Piece.Female = false;
|
||||
m_Piece.BodyValue = 0x190;
|
||||
|
||||
if ( m_BChessboard.OverrideMinorHue )
|
||||
m_Piece.Hue = Hue;
|
||||
else
|
||||
m_Piece.Hue = m_BChessboard.SkinHue;
|
||||
|
||||
Item item = null;
|
||||
|
||||
item = new HoodedShroudOfShadows( Hue );
|
||||
item.Name = "Bishop's Robe";
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new Boots( MinorHue );
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new QuarterStaff();
|
||||
item.Hue = MinorHue;
|
||||
m_Piece.AddItem( item );
|
||||
}
|
||||
|
||||
public override bool CanMoveTo(Point2D newLocation, ref string err)
|
||||
{
|
||||
if ( ! base.CanMoveTo (newLocation, ref err) )
|
||||
return false;
|
||||
|
||||
int dx = newLocation.X - m_Position.X;
|
||||
int dy = newLocation.Y - m_Position.Y;
|
||||
|
||||
if ( Math.Abs( dx ) != Math.Abs( dy ) )
|
||||
{
|
||||
err = "Bishops can move only on diagonals";
|
||||
return false; // Not a diagonal movement
|
||||
}
|
||||
|
||||
int xDirection = dx > 0 ? 1 : -1;
|
||||
int yDirection = dy > 0 ? 1 : -1;
|
||||
|
||||
if ( Math.Abs( dx ) > 1 )
|
||||
{
|
||||
// Verify that the path to target is empty
|
||||
for ( int i = 1; i < Math.Abs( dx ); i++ ) // Skip the bishop square and stop before target
|
||||
{
|
||||
int xOffset = xDirection * i;
|
||||
int yOffset = yDirection * i;
|
||||
|
||||
if ( m_BChessboard[ m_Position.X + xOffset, m_Position.Y + yOffset ] != null )
|
||||
{
|
||||
err = "Bishops can't move over other pieces";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Verify target piece
|
||||
BaseChessPiece piece = m_BChessboard[ newLocation ];
|
||||
|
||||
if ( piece == null || piece.Color != m_Color )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = "You can't capture pieces of your own color";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override ArrayList GetMoves(bool capture)
|
||||
{
|
||||
ArrayList moves = new ArrayList();
|
||||
|
||||
int[] xDirection = new int[] { -1, 1, -1, 1 };
|
||||
int[] yDirection = new int[] { -1, 1, 1, -1 };
|
||||
|
||||
for ( int i = 0; i < 4; i++ )
|
||||
{
|
||||
int xDir = xDirection[ i ];
|
||||
int yDir = yDirection[ i ];
|
||||
|
||||
int offset = 1;
|
||||
|
||||
while ( true )
|
||||
{
|
||||
Point2D p = new Point2D( m_Position.X + offset * xDir, m_Position.Y + offset * yDir );
|
||||
|
||||
if ( ! m_BChessboard.IsValid( p ) )
|
||||
break;
|
||||
|
||||
BaseChessPiece piece = m_BChessboard[ p ];
|
||||
|
||||
if ( piece == null )
|
||||
{
|
||||
moves.Add( p );
|
||||
offset++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( capture && piece.Color != m_Color )
|
||||
{
|
||||
moves.Add( p );
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return moves;
|
||||
}
|
||||
}
|
||||
}
|
||||
240
Scripts/Scripts-master/Games/Battle Chess/Pieces/King.cs
Normal file
240
Scripts/Scripts-master/Games/Battle Chess/Pieces/King.cs
Normal file
@@ -0,0 +1,240 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
using Server;
|
||||
using Server.Items;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
public class King : BaseChessPiece
|
||||
{
|
||||
private int m_CheckSound;
|
||||
private int m_CheckMateSound;
|
||||
|
||||
public override int Power
|
||||
{
|
||||
get
|
||||
{
|
||||
return 100; // Useless
|
||||
}
|
||||
}
|
||||
|
||||
public King( BChessboard board, ChessColor color, Point2D position ) : base( board, color, position )
|
||||
{
|
||||
}
|
||||
|
||||
public override void InitializePiece()
|
||||
{
|
||||
m_Piece = new ChessMobile( this );
|
||||
m_Piece.Name = string.Format( "King [{0}]", m_Color.ToString() );
|
||||
|
||||
switch ( m_BChessboard.ChessSet )
|
||||
{
|
||||
case ChessSet.Classic : CreateClassic();
|
||||
break;
|
||||
|
||||
case ChessSet.Fantasy : CreateFantasy();
|
||||
break;
|
||||
|
||||
case ChessSet.FantasyGiant : CreateFantasyGiant();
|
||||
break;
|
||||
|
||||
case ChessSet.Animal : CreateAnimal();
|
||||
break;
|
||||
|
||||
case ChessSet.Undead : CreateUndead();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateUndead()
|
||||
{
|
||||
m_MoveSound = 1163;
|
||||
m_CaptureSound = 1162;
|
||||
m_DeathSound = 361;
|
||||
m_CheckSound = 772;
|
||||
m_CheckMateSound = 716;
|
||||
|
||||
m_Piece.BodyValue = 148; // Skeletal mage
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateAnimal()
|
||||
{
|
||||
m_MoveSound = 95;
|
||||
m_CaptureSound = 1223;
|
||||
m_DeathSound = 98;
|
||||
m_CheckSound = 98;
|
||||
m_CheckMateSound = 99;
|
||||
|
||||
m_Piece.BodyValue = 213; // Polar bear
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasyGiant()
|
||||
{
|
||||
m_MoveSound = 1152;
|
||||
m_CaptureSound = 1150;
|
||||
m_DeathSound = 0;
|
||||
m_CheckSound = 1152;
|
||||
m_CheckMateSound = 1149;
|
||||
|
||||
m_Piece.BodyValue = 311; // Shadow knight
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasy()
|
||||
{
|
||||
m_MoveSound = 610;
|
||||
m_CaptureSound = 606;
|
||||
m_DeathSound = 0;
|
||||
m_CheckSound = 604;
|
||||
m_CheckMateSound = 613;
|
||||
|
||||
m_Piece.BodyValue = 767; // Betrayer
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateClassic()
|
||||
{
|
||||
m_MoveSound = 1055;
|
||||
m_CaptureSound = 1068;
|
||||
m_DeathSound = 0;
|
||||
m_CheckSound = 1086;
|
||||
m_CheckMateSound = 1088;
|
||||
|
||||
m_Piece.Female = false;
|
||||
m_Piece.BodyValue = 0x190;
|
||||
|
||||
if ( m_BChessboard.OverrideMinorHue )
|
||||
m_Piece.Hue = Hue;
|
||||
else
|
||||
m_Piece.Hue = m_BChessboard.SkinHue;
|
||||
m_Piece.AddItem( new ShortHair( m_BChessboard.OverrideMinorHue ? Hue : m_BChessboard.HairHue ) );
|
||||
|
||||
Item item = null;
|
||||
|
||||
item = new Boots( MinorHue );
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new LongPants( Hue );
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new FancyShirt( Hue );
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new Doublet( MinorHue );
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new Cloak( MinorHue );
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new Scepter();
|
||||
item.Hue = MinorHue;
|
||||
m_Piece.AddItem( item );
|
||||
}
|
||||
|
||||
public override bool CanMoveTo(Point2D newLocation, ref string err)
|
||||
{
|
||||
if ( ! base.CanMoveTo (newLocation, ref err) )
|
||||
return false;
|
||||
|
||||
// Verify if this is a castle
|
||||
BaseChessPiece rook = m_BChessboard[ newLocation ];
|
||||
|
||||
if ( rook is Rook && rook.Color == m_Color )
|
||||
{
|
||||
// Trying to castle
|
||||
return m_BChessboard.AllowCastle( this, rook, ref err );
|
||||
}
|
||||
|
||||
int dx = newLocation.X - m_Position.X;
|
||||
int dy = newLocation.Y - m_Position.Y;
|
||||
|
||||
if ( Math.Abs( dx ) > 1 || Math.Abs( dy ) > 1 )
|
||||
{
|
||||
err = "The can king can move only 1 tile at a time";
|
||||
return false; // King can move only 1 tile away from its position
|
||||
}
|
||||
|
||||
// Verify target piece
|
||||
BaseChessPiece piece = m_BChessboard[ newLocation ];
|
||||
|
||||
if ( piece == null || piece.Color != m_Color )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = "You can't capture pieces of your same color";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override ArrayList GetMoves(bool capture)
|
||||
{
|
||||
ArrayList moves = new ArrayList();
|
||||
|
||||
for ( int dx = -1; dx <= 1; dx++ )
|
||||
{
|
||||
for ( int dy = -1; dy <= 1; dy++ )
|
||||
{
|
||||
if ( dx == 0 && dy == 0 )
|
||||
continue; // Can't move to same spot
|
||||
|
||||
Point2D p = new Point2D( m_Position.X + dx, m_Position.Y + dy );
|
||||
|
||||
if ( ! m_BChessboard.IsValid( p ) )
|
||||
continue;
|
||||
|
||||
BaseChessPiece piece = m_BChessboard[ p ];
|
||||
|
||||
if ( piece == null )
|
||||
moves.Add( p );
|
||||
else if ( capture && piece.Color != m_Color )
|
||||
moves.Add( p );
|
||||
}
|
||||
}
|
||||
|
||||
return moves;
|
||||
}
|
||||
|
||||
public override bool IsCastle(Point2D loc)
|
||||
{
|
||||
Rook rook = m_BChessboard[ loc ] as Rook;
|
||||
|
||||
string err = null;
|
||||
|
||||
return rook != null && rook.Color == m_Color && m_BChessboard.AllowCastle( this, rook, ref err );
|
||||
}
|
||||
|
||||
public void EndCastle( Point2D location )
|
||||
{
|
||||
m_HasMoved = true;
|
||||
|
||||
m_Move = new Move( this, location );
|
||||
|
||||
Point2D worldLocation = m_BChessboard.BoardToWorld( location );
|
||||
|
||||
m_Piece.GoTo( worldLocation );
|
||||
}
|
||||
|
||||
public void PlayCheck()
|
||||
{
|
||||
m_BChessboard.PlaySound( m_Piece, m_CheckSound );
|
||||
m_Piece.Say( "*CHECK*" );
|
||||
}
|
||||
|
||||
public void PlayCheckMate()
|
||||
{
|
||||
m_BChessboard.PlaySound( m_Piece, m_CheckMateSound );
|
||||
m_Piece.Say( "CHECKMATE" );
|
||||
}
|
||||
|
||||
public void PlayStaleMate()
|
||||
{
|
||||
m_BChessboard.PlaySound( m_Piece, m_CheckSound );
|
||||
m_Piece.Say( "STALEMATE" );
|
||||
}
|
||||
}
|
||||
}
|
||||
209
Scripts/Scripts-master/Games/Battle Chess/Pieces/Knight.cs
Normal file
209
Scripts/Scripts-master/Games/Battle Chess/Pieces/Knight.cs
Normal file
@@ -0,0 +1,209 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
using Server;
|
||||
using Server.Items;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
public class Knight : BaseChessPiece
|
||||
{
|
||||
public static int GetGumpID( ChessColor color )
|
||||
{
|
||||
return color == ChessColor.Black ? 2342 : 2335;
|
||||
}
|
||||
|
||||
public override int Power
|
||||
{
|
||||
get
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Knight( BChessboard board, ChessColor color, Point2D position ) : base( board, color, position )
|
||||
{
|
||||
}
|
||||
|
||||
public override void InitializePiece()
|
||||
{
|
||||
m_Piece = new ChessMobile( this );
|
||||
m_Piece.Name = string.Format( "Knight [{0}]", m_Color.ToString() );
|
||||
|
||||
switch ( m_BChessboard.ChessSet )
|
||||
{
|
||||
case ChessSet.Classic : CreateClassic();
|
||||
break;
|
||||
|
||||
case ChessSet.Fantasy : CreateFantasy();
|
||||
break;
|
||||
|
||||
case ChessSet.FantasyGiant : CreateFantasyGiant();
|
||||
break;
|
||||
|
||||
case ChessSet.Animal : CreateAnimal();
|
||||
break;
|
||||
|
||||
case ChessSet.Undead : CreateUndead();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateUndead()
|
||||
{
|
||||
m_MoveSound = 588;
|
||||
m_CaptureSound = 1164;
|
||||
m_DeathSound = 416;
|
||||
|
||||
m_Piece.Female = false;
|
||||
m_Piece.BodyValue = 0x190;
|
||||
m_Piece.AddItem( new HoodedShroudOfShadows( Hue ) );
|
||||
|
||||
Server.Mobiles.SkeletalMount mount = new Server.Mobiles.SkeletalMount();
|
||||
mount.Hue = MinorHue;
|
||||
mount.Rider = m_Piece;
|
||||
|
||||
m_Piece.Direction = Facing;
|
||||
}
|
||||
|
||||
private void CreateAnimal()
|
||||
{
|
||||
m_MoveSound = 183;
|
||||
m_CaptureSound = 1011;
|
||||
m_DeathSound = 185;
|
||||
|
||||
m_Piece.BodyValue = 292; // Pack llama
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasyGiant()
|
||||
{
|
||||
m_MoveSound = 875;
|
||||
m_CaptureSound = 378;
|
||||
m_DeathSound = 879;
|
||||
|
||||
m_Piece.BodyValue = 315; // Flesh renderer
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasy()
|
||||
{
|
||||
m_MoveSound = 762;
|
||||
m_CaptureSound = 758;
|
||||
m_DeathSound = 759;
|
||||
|
||||
m_Piece.BodyValue = 101; // Centaur
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateClassic()
|
||||
{
|
||||
m_MoveSound = 588;
|
||||
m_CaptureSound = 168;
|
||||
m_DeathSound = 170;
|
||||
|
||||
m_Piece.Female = false;
|
||||
m_Piece.BodyValue = 0x190;
|
||||
|
||||
if ( m_BChessboard.OverrideMinorHue )
|
||||
m_Piece.Hue = Hue;
|
||||
else
|
||||
m_Piece.Hue = m_BChessboard.SkinHue;
|
||||
m_Piece.AddItem( new PonyTail( m_BChessboard.OverrideMinorHue ? Hue : m_BChessboard.HairHue ) );
|
||||
|
||||
Item item = null;
|
||||
|
||||
item = new PlateLegs();
|
||||
item.Hue = Hue;
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new PlateChest();
|
||||
item.Hue = Hue;
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new PlateArms();
|
||||
item.Hue = Hue;
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new PlateGorget();
|
||||
item.Hue = Hue;
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new PlateGloves();
|
||||
item.Hue = Hue;
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new Doublet( MinorHue );
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new Lance();
|
||||
item.Hue = MinorHue;
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
Server.Mobiles.Horse horse = new Server.Mobiles.Horse();
|
||||
horse.BodyValue = 200;
|
||||
horse.Hue = MinorHue;
|
||||
|
||||
horse.Rider = m_Piece;
|
||||
|
||||
m_Piece.Direction = Facing;
|
||||
}
|
||||
|
||||
public override bool CanMoveTo(Point2D newLocation, ref string err)
|
||||
{
|
||||
if ( ! base.CanMoveTo (newLocation, ref err) )
|
||||
return false;
|
||||
|
||||
// Care only about absolutes for knights
|
||||
int dx = Math.Abs( newLocation.X - m_Position.X );
|
||||
int dy = Math.Abs( newLocation.Y - m_Position.Y );
|
||||
|
||||
if ( ! ( ( dx == 1 && dy == 2 ) || ( dx == 2 && dy == 1 ) ) )
|
||||
{
|
||||
err = "Knights can only make L shaped moves (2-3 tiles length)";
|
||||
return false; // Wrong move
|
||||
}
|
||||
|
||||
// Verify target piece
|
||||
BaseChessPiece piece = m_BChessboard[ newLocation ];
|
||||
|
||||
if ( piece == null || piece.Color != m_Color )
|
||||
return true;
|
||||
else
|
||||
{
|
||||
err = "You can't capture pieces of your same color";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override ArrayList GetMoves(bool capture)
|
||||
{
|
||||
ArrayList moves = new ArrayList();
|
||||
|
||||
for ( int dx = -2; dx <= 2; dx++ )
|
||||
{
|
||||
for ( int dy = -2; dy <= 2; dy++ )
|
||||
{
|
||||
if ( ! ( ( Math.Abs( dx ) == 1 && Math.Abs( dy ) == 2 ) || ( Math.Abs( dx ) == 2 && Math.Abs( dy ) == 1 ) ) )
|
||||
continue;
|
||||
|
||||
Point2D p = new Point2D( m_Position.X + dx, m_Position.Y + dy );
|
||||
|
||||
if ( ! m_BChessboard.IsValid( p ) )
|
||||
continue;
|
||||
|
||||
BaseChessPiece piece = m_BChessboard[ p ];
|
||||
|
||||
if ( piece == null )
|
||||
moves.Add( p );
|
||||
else if ( capture && piece.Color != m_Color )
|
||||
moves.Add( p );
|
||||
}
|
||||
}
|
||||
|
||||
return moves;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
348
Scripts/Scripts-master/Games/Battle Chess/Pieces/Pawn.cs
Normal file
348
Scripts/Scripts-master/Games/Battle Chess/Pieces/Pawn.cs
Normal file
@@ -0,0 +1,348 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
using Server;
|
||||
using Server.Items;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
public class Pawn : BaseChessPiece
|
||||
{
|
||||
public static int GetGumpID( ChessColor color )
|
||||
{
|
||||
return color == ChessColor.Black ? 2343 : 2336;
|
||||
}
|
||||
|
||||
public override int Power
|
||||
{
|
||||
get
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool AllowEnPassantCapture
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_EnPassantRisk;
|
||||
}
|
||||
set { m_EnPassantRisk = value; }
|
||||
}
|
||||
|
||||
private bool m_EnPassantRisk = false;
|
||||
|
||||
public Pawn( BChessboard board, ChessColor color, Point2D position ) : base( board, color, position )
|
||||
{
|
||||
}
|
||||
|
||||
public override void InitializePiece()
|
||||
{
|
||||
m_Piece = new ChessMobile( this );
|
||||
m_Piece.Name = string.Format( "Pawn [{0}]", m_Color.ToString() );
|
||||
|
||||
switch ( m_BChessboard.ChessSet )
|
||||
{
|
||||
case ChessSet.Classic : CreateClassic();
|
||||
break;
|
||||
|
||||
case ChessSet.Fantasy : CreateFantasy();
|
||||
break;
|
||||
|
||||
case ChessSet.FantasyGiant : CreateFantasyGiant();
|
||||
break;
|
||||
|
||||
case ChessSet.Animal : CreateAnimal();
|
||||
break;
|
||||
|
||||
case ChessSet.Undead : CreateUndead();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateUndead()
|
||||
{
|
||||
m_MoveSound = 451;
|
||||
m_CaptureSound = 1169;
|
||||
m_DeathSound = 455;
|
||||
|
||||
m_Piece.BodyValue = 56; // Skeleton
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateAnimal()
|
||||
{
|
||||
m_MoveSound = 1217;
|
||||
m_CaptureSound = 226;
|
||||
m_DeathSound = 228;
|
||||
|
||||
m_Piece.BodyValue = 221; // Walrus
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasyGiant()
|
||||
{
|
||||
m_MoveSound = 709;
|
||||
m_CaptureSound = 712;
|
||||
m_DeathSound = 705;
|
||||
|
||||
m_Piece.BodyValue = 303; // Devourer
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasy()
|
||||
{
|
||||
m_MoveSound = 408;
|
||||
m_CaptureSound = 927;
|
||||
m_DeathSound = 411;
|
||||
|
||||
m_Piece.BodyValue = 776; // Horde Minion
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateClassic()
|
||||
{
|
||||
m_MoveSound = 821;
|
||||
m_CaptureSound = 1094;
|
||||
m_DeathSound = 1059;
|
||||
|
||||
m_Piece.Female = false;
|
||||
m_Piece.BodyValue = 0x190;
|
||||
|
||||
if ( m_BChessboard.OverrideMinorHue )
|
||||
m_Piece.Hue = Hue;
|
||||
else
|
||||
m_Piece.Hue = m_BChessboard.SkinHue;
|
||||
m_Piece.AddItem( new ShortHair( m_BChessboard.OverrideMinorHue ? Hue : m_BChessboard.HairHue ) );
|
||||
|
||||
Item item = null;
|
||||
|
||||
item = new ChainChest();
|
||||
item.Hue = Hue;
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new ChainLegs();
|
||||
item.Hue = MinorHue;
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new Boots();
|
||||
item.Hue = Hue;
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new Buckler();
|
||||
item.Hue = MinorHue;
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new Scimitar();
|
||||
item.Hue = MinorHue;
|
||||
m_Piece.AddItem( item );
|
||||
}
|
||||
|
||||
public override bool CanMoveTo(Point2D newLocation, ref string err)
|
||||
{
|
||||
if ( ! base.CanMoveTo (newLocation, ref err) )
|
||||
return false;
|
||||
|
||||
if ( newLocation.X == m_Position.X )
|
||||
{
|
||||
// Regular move
|
||||
int dy = newLocation.Y - m_Position.Y;
|
||||
|
||||
// Trying to move more than two pieces, or more than one piece after the first move
|
||||
if ( Math.Abs( dy ) > 2 || ( Math.Abs( dy ) ) > 1 && m_HasMoved )
|
||||
{
|
||||
err = "You can move only 1 tile at a time, or 2 if it's the pawn's first move";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify direction
|
||||
if ( m_Color == ChessColor.Black && dy < 0 )
|
||||
{
|
||||
err = "You can't move pawns backwards";
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( m_Color == ChessColor.White && dy > 0 )
|
||||
{
|
||||
err = "You can't move pawns backwards";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify if there are pieces (any) on the target squares
|
||||
for ( int i = 1; i <= Math.Abs( dy ); i++ )
|
||||
{
|
||||
int offset = m_Color == ChessColor.Black ? i : -i;
|
||||
|
||||
if ( m_BChessboard[ m_Position.X, m_Position.Y + offset ] != null )
|
||||
{
|
||||
err = "Pawns can't move over other pieces, and capture in diagonal";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Trying to capture?
|
||||
int dx = newLocation.X - m_Position.X;
|
||||
int dy = newLocation.Y - m_Position.Y;
|
||||
|
||||
if ( Math.Abs( dx ) != 1 || Math.Abs( dy ) != 1 )
|
||||
{
|
||||
err = "Pawns move straight ahead, or capture in diagonal only";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify direction
|
||||
if ( m_Color == ChessColor.Black && dy < 0 )
|
||||
{
|
||||
err = "You can't move pawns backwards";
|
||||
return false;
|
||||
}
|
||||
if ( m_Color == ChessColor.White && dy > 0 )
|
||||
{
|
||||
err = "You can't move pawns backwards";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify if there's a piece to capture
|
||||
BaseChessPiece piece = m_BChessboard[ newLocation ];
|
||||
|
||||
if ( piece != null && piece.Color != m_Color )
|
||||
return true;
|
||||
else
|
||||
{
|
||||
// Verify for an en passant capture
|
||||
Point2D passant = new Point2D( m_Position.X + dx, m_Position.Y );
|
||||
|
||||
BaseChessPiece target = m_BChessboard[ passant ];
|
||||
|
||||
if ( target != null && target.AllowEnPassantCapture && target.Color != m_Color )
|
||||
return true;
|
||||
else
|
||||
{
|
||||
err = "You must capture a piece when moving in diagonal";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override ArrayList GetMoves(bool capture)
|
||||
{
|
||||
ArrayList moves = new ArrayList();
|
||||
|
||||
int direction = m_Color == ChessColor.Black ? 1 : -1;
|
||||
|
||||
Point2D step = new Point2D( m_Position.X, m_Position.Y + direction );
|
||||
|
||||
if ( m_BChessboard.IsValid( step ) && m_BChessboard[ step ] == null )
|
||||
{
|
||||
moves.Add( step );
|
||||
|
||||
// Verify if this pawn can make a second step
|
||||
step.Y += direction;
|
||||
|
||||
if ( ! m_HasMoved && m_BChessboard[ step ] == null )
|
||||
moves.Add( step ); // Point2D is a value type
|
||||
}
|
||||
|
||||
if ( capture )
|
||||
{
|
||||
// Verify captures too
|
||||
Point2D p1 = new Point2D( m_Position.X + 1, m_Position.Y + direction );
|
||||
Point2D p2 = new Point2D( m_Position.X - 1, m_Position.Y + direction );
|
||||
|
||||
if ( m_BChessboard.IsValid( p1 ) )
|
||||
{
|
||||
BaseChessPiece piece1 = m_BChessboard[ p1 ];
|
||||
if ( piece1 != null && piece1.Color != m_Color )
|
||||
moves.Add( p1 );
|
||||
else
|
||||
{
|
||||
Point2D pass1 = new Point2D( m_Position.X - 1, m_Position.Y );
|
||||
|
||||
if ( m_BChessboard.IsValid( pass1 ) )
|
||||
{
|
||||
BaseChessPiece passpiece1 = m_BChessboard[ pass1 ];
|
||||
if ( passpiece1 != null && passpiece1.Color != m_Color && passpiece1.AllowEnPassantCapture )
|
||||
moves.Add( p1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( m_BChessboard.IsValid( p2 ) )
|
||||
{
|
||||
BaseChessPiece piece2 = m_BChessboard[ p2 ];
|
||||
if ( piece2 != null && piece2.Color != m_Color )
|
||||
moves.Add( p2 );
|
||||
else
|
||||
{
|
||||
Point2D pass2 = new Point2D( m_Position.X + 1, m_Position.Y );
|
||||
|
||||
if ( m_BChessboard.IsValid( p2 ) )
|
||||
{
|
||||
BaseChessPiece passpiece2 = m_BChessboard[ pass2 ];
|
||||
if ( passpiece2 != null && passpiece2.AllowEnPassantCapture && passpiece2.Color != m_Color )
|
||||
moves.Add( pass2 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return moves;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// States whether this pawn has reached the other side of the board and should be promoted
|
||||
/// </summary>
|
||||
public bool ShouldBePromoted
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Color == ChessColor.White && m_Position.Y == 0 )
|
||||
return true;
|
||||
else if ( m_Color == ChessColor.Black && m_Position.Y == 7 )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void MoveTo(Move move)
|
||||
{
|
||||
// Set En Passant flags
|
||||
int dy = Math.Abs( move.To.Y - m_Position.Y );
|
||||
|
||||
if ( ! m_HasMoved && dy == 2 )
|
||||
{
|
||||
m_EnPassantRisk = true;
|
||||
}
|
||||
|
||||
base.MoveTo (move);
|
||||
}
|
||||
|
||||
public override BaseChessPiece GetCaptured(Point2D at, ref bool enpassant)
|
||||
{
|
||||
BaseChessPiece basePiece = base.GetCaptured (at, ref enpassant);
|
||||
|
||||
if ( basePiece != null && basePiece.Color != m_Color )
|
||||
return basePiece; // Normal capture
|
||||
|
||||
if ( at.X == m_Position.X )
|
||||
return null; // Straight movement
|
||||
|
||||
Point2D p = new Point2D( at.X, m_Position.Y );
|
||||
basePiece = m_BChessboard[ p ];
|
||||
|
||||
if ( basePiece != null && basePiece.Color != m_Color )
|
||||
{
|
||||
enpassant = true;
|
||||
return basePiece;
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
251
Scripts/Scripts-master/Games/Battle Chess/Pieces/Queen.cs
Normal file
251
Scripts/Scripts-master/Games/Battle Chess/Pieces/Queen.cs
Normal file
@@ -0,0 +1,251 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
using Server;
|
||||
using Server.Items;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for Queen.
|
||||
/// </summary>
|
||||
public class Queen : BaseChessPiece
|
||||
{
|
||||
public static int GetGumpID( ChessColor color )
|
||||
{
|
||||
return color == ChessColor.Black ? 2344 : 2377;
|
||||
}
|
||||
|
||||
public override int Power
|
||||
{
|
||||
get
|
||||
{
|
||||
return 9;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Queen( BChessboard board, ChessColor color, Point2D position ) : base( board, color, position )
|
||||
{
|
||||
}
|
||||
|
||||
public override void InitializePiece()
|
||||
{
|
||||
m_Piece = new ChessMobile( this );
|
||||
m_Piece.Name = string.Format( "Queen [{0}]", m_Color.ToString() );
|
||||
|
||||
switch ( m_BChessboard.ChessSet )
|
||||
{
|
||||
case ChessSet.Classic : CreateClassic();
|
||||
break;
|
||||
|
||||
case ChessSet.Fantasy : CreateFantasy();
|
||||
break;
|
||||
|
||||
case ChessSet.FantasyGiant : CreateFantasyGiant();
|
||||
break;
|
||||
|
||||
case ChessSet.Animal : CreateAnimal();
|
||||
break;
|
||||
|
||||
case ChessSet.Undead: CreateUndead();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateUndead()
|
||||
{
|
||||
m_MoveSound = 896;
|
||||
m_CaptureSound = 382;
|
||||
m_DeathSound = 1202;
|
||||
|
||||
m_Piece.BodyValue = 310; // Wailing banshee
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateAnimal()
|
||||
{
|
||||
m_MoveSound = 123;
|
||||
m_CaptureSound = 120;
|
||||
m_DeathSound = 124;
|
||||
|
||||
m_Piece.BodyValue = 216; // Cow
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasyGiant()
|
||||
{
|
||||
m_MoveSound = 883;
|
||||
m_CaptureSound = 880;
|
||||
m_DeathSound = 888;
|
||||
|
||||
m_Piece.BodyValue = 174; // Semidar
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasy()
|
||||
{
|
||||
m_MoveSound = 1200;
|
||||
m_CaptureSound = 1201;
|
||||
m_DeathSound = 1202;
|
||||
|
||||
m_Piece.BodyValue = 149; // Succubus
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateClassic()
|
||||
{
|
||||
m_MoveSound = 823;
|
||||
m_CaptureSound = 824;
|
||||
m_DeathSound = 814;
|
||||
|
||||
m_Piece.Female = true;
|
||||
m_Piece.BodyValue = 0x191;
|
||||
|
||||
if ( m_BChessboard.OverrideMinorHue )
|
||||
m_Piece.Hue = Hue;
|
||||
else
|
||||
m_Piece.Hue = m_BChessboard.SkinHue;
|
||||
m_Piece.AddItem( new LongHair( m_BChessboard.OverrideMinorHue ? Hue : m_BChessboard.HairHue ) );
|
||||
|
||||
Item item = null;
|
||||
|
||||
item = new FancyDress( Hue );
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new Sandals( MinorHue );
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new Scepter();
|
||||
item.Hue = MinorHue;
|
||||
m_Piece.AddItem( item );
|
||||
}
|
||||
|
||||
public override bool CanMoveTo(Point2D newLocation, ref string err)
|
||||
{
|
||||
if ( ! base.CanMoveTo (newLocation, ref err) )
|
||||
return false;
|
||||
|
||||
int dx = newLocation.X - m_Position.X;
|
||||
int dy = newLocation.Y - m_Position.Y;
|
||||
|
||||
if ( dx == 0 || dy == 0 )
|
||||
{
|
||||
// Straight movement
|
||||
if ( Math.Abs( dx ) > 1 ) // If it's just 1 step no need to check for intermediate pieces
|
||||
{
|
||||
int direction = dx > 0 ? 1 : -1;
|
||||
|
||||
// Moving along X axis
|
||||
for ( int i = 1; i < Math.Abs( dx ); i++ )
|
||||
{
|
||||
int offset = direction * i;
|
||||
|
||||
if ( m_BChessboard[ m_Position.X + offset, m_Position.Y ] != null )
|
||||
{
|
||||
err = "The queen can't move over other pieces";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( Math.Abs( dy ) > 1 )
|
||||
{
|
||||
// Moving along Y axis
|
||||
int direction = dy > 0 ? 1 : -1;
|
||||
|
||||
for ( int i = 1; i < Math.Abs( dy ); i++ )
|
||||
{
|
||||
int offset = direction * i;
|
||||
|
||||
if ( m_BChessboard[ m_Position.X, m_Position.Y + offset ] != null )
|
||||
{
|
||||
err = "The queen can't move over other pieces";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Diagonal movement
|
||||
if ( Math.Abs( dx ) != Math.Abs( dy ) )
|
||||
{
|
||||
err = "The queen moves only on straight lines or diagonals";
|
||||
return false; // Uneven
|
||||
}
|
||||
|
||||
if ( Math.Abs( dx ) > 1 )
|
||||
{
|
||||
int xDirection = dx > 0 ? 1 : -1;
|
||||
int yDirection = dy > 0 ? 1 : -1;
|
||||
|
||||
for ( int i = 1; i < Math.Abs( dx ); i++ )
|
||||
{
|
||||
int xOffset = xDirection * i;
|
||||
int yOffset = yDirection * i;
|
||||
|
||||
if ( m_BChessboard[ m_Position.X + xOffset, m_Position.Y + yOffset ] != null )
|
||||
{
|
||||
err = "The queen can't move over other pieces";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Verify target piece
|
||||
BaseChessPiece piece = m_BChessboard[ newLocation ];
|
||||
|
||||
if ( piece == null || piece.Color != m_Color )
|
||||
return true;
|
||||
else
|
||||
{
|
||||
err = "You can't capture pieces of your same color";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override ArrayList GetMoves(bool capture)
|
||||
{
|
||||
ArrayList moves = new ArrayList();
|
||||
|
||||
int[] xDirection = new int[] { -1, 1, -1, 1, 1, -1, 0, 0 };
|
||||
int[] yDirection = new int[] { -1, 1, 1, -1, 0, 0, 1, -1 };
|
||||
|
||||
for ( int i = 0; i < 8; i++ )
|
||||
{
|
||||
int xDir = xDirection[ i ];
|
||||
int yDir = yDirection[ i ];
|
||||
|
||||
int offset = 1;
|
||||
|
||||
while ( true )
|
||||
{
|
||||
Point2D p = new Point2D( m_Position.X + offset * xDir, m_Position.Y + offset * yDir );
|
||||
|
||||
if ( ! m_BChessboard.IsValid( p ) )
|
||||
break;
|
||||
|
||||
BaseChessPiece piece = m_BChessboard[ p ];
|
||||
|
||||
if ( piece == null )
|
||||
{
|
||||
moves.Add( p );
|
||||
offset++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( capture && piece.Color != m_Color )
|
||||
{
|
||||
moves.Add( p );
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return moves;
|
||||
}
|
||||
}
|
||||
}
|
||||
286
Scripts/Scripts-master/Games/Battle Chess/Pieces/Rook.cs
Normal file
286
Scripts/Scripts-master/Games/Battle Chess/Pieces/Rook.cs
Normal file
@@ -0,0 +1,286 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
using Server;
|
||||
using Server.Items;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
public class Rook : BaseChessPiece
|
||||
{
|
||||
private bool m_Castle;
|
||||
|
||||
public static int GetGumpID( ChessColor color )
|
||||
{
|
||||
return color == ChessColor.Black ? 2340 : 2333;
|
||||
}
|
||||
|
||||
public override int Power
|
||||
{
|
||||
get
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
public Rook( BChessboard board, ChessColor color, Point2D position ) : base( board, color, position )
|
||||
{
|
||||
}
|
||||
|
||||
public override void InitializePiece()
|
||||
{
|
||||
m_Piece = new ChessMobile( this );
|
||||
m_Piece.Name = string.Format( "Rook [{0}]", m_Color.ToString() );
|
||||
|
||||
switch ( m_BChessboard.ChessSet )
|
||||
{
|
||||
case ChessSet.Classic : CreateClassic();
|
||||
break;
|
||||
|
||||
case ChessSet.Fantasy : CreateFantasy();
|
||||
break;
|
||||
|
||||
case ChessSet.FantasyGiant : CreateFantasyGiant();
|
||||
break;
|
||||
|
||||
case ChessSet.Animal : CreateAnimal();
|
||||
break;
|
||||
|
||||
case ChessSet.Undead : CreateUndead();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateUndead()
|
||||
{
|
||||
m_MoveSound = 880;
|
||||
m_CaptureSound = 357;
|
||||
m_DeathSound = 1156;
|
||||
|
||||
m_Piece.BodyValue = 154; // Mummy
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateAnimal()
|
||||
{
|
||||
m_MoveSound = 159;
|
||||
m_CaptureSound = 158;
|
||||
m_DeathSound = 162;
|
||||
|
||||
m_Piece.BodyValue = 29; // Gorilla
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasyGiant()
|
||||
{
|
||||
m_MoveSound = 767;
|
||||
m_CaptureSound = 367;
|
||||
m_DeathSound = 371;
|
||||
|
||||
m_Piece.BodyValue = 312; // Abysmal Horror
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasy()
|
||||
{
|
||||
m_MoveSound = 461;
|
||||
m_CaptureSound = 463;
|
||||
m_DeathSound = 465;
|
||||
|
||||
m_Piece.Female = false;
|
||||
m_Piece.BodyValue = 55; // Troll
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateClassic()
|
||||
{
|
||||
m_MoveSound = 287;
|
||||
m_CaptureSound = 268;
|
||||
m_DeathSound = 269;
|
||||
|
||||
m_Piece.Female = false;
|
||||
m_Piece.BodyValue = 14;
|
||||
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
public override bool CanMoveTo(Point2D newLocation, ref string err)
|
||||
{
|
||||
if ( ! base.CanMoveTo (newLocation, ref err) )
|
||||
return false;
|
||||
|
||||
// Verify if this is a castle
|
||||
BaseChessPiece king = m_BChessboard[ newLocation ];
|
||||
|
||||
if ( king is King && king.Color == m_Color )
|
||||
{
|
||||
// Trying to castle
|
||||
return m_BChessboard.AllowCastle( king, this, ref err );
|
||||
}
|
||||
|
||||
int dx = newLocation.X - m_Position.X;
|
||||
int dy = newLocation.Y - m_Position.Y;
|
||||
|
||||
// Rooks can only move in one direction
|
||||
if ( dx != 0 && dy != 0 )
|
||||
{
|
||||
err = "Rooks can only move on straight lines";
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( dx != 0 )
|
||||
{
|
||||
// Moving on the X axis
|
||||
int direction = dx > 0 ? 1 : -1;
|
||||
|
||||
if ( Math.Abs( dx ) > 1 )
|
||||
{
|
||||
// Verify that the cells in between are empty
|
||||
for ( int i = 1; i < Math.Abs( dx ); i++ ) // Start 1 tile after the rook, and stop one tile before destination
|
||||
{
|
||||
int offset = direction * i;
|
||||
|
||||
if ( m_BChessboard[ m_Position.X + offset, m_Position.Y ] != null )
|
||||
{
|
||||
err = "Rooks can't move over pieces";
|
||||
return false; // There's a piece on the
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Verify if there's a piece to each at the end
|
||||
BaseChessPiece piece = m_BChessboard[ newLocation ];
|
||||
|
||||
if ( piece == null || piece.Color != m_Color )
|
||||
return true;
|
||||
else
|
||||
{
|
||||
err = "You can't capture pieces of your same color";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Moving on the Y axis
|
||||
int direction = dy > 0 ? 1 : -1;
|
||||
|
||||
if ( Math.Abs( dy ) > 1 )
|
||||
{
|
||||
// Verify that the cells in between are empty
|
||||
for ( int i = 1; i < Math.Abs( dy ); i++ )
|
||||
{
|
||||
int offset = direction * i;
|
||||
|
||||
if ( m_BChessboard[ m_Position.X, m_Position.Y + offset ] != null )
|
||||
{
|
||||
err = "The rook can't move over other pieces";
|
||||
return false; // Piece on the way
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Verify for piece at end
|
||||
BaseChessPiece piece = m_BChessboard[ newLocation ];
|
||||
|
||||
if ( piece == null || piece.Color != m_Color )
|
||||
return true;
|
||||
else
|
||||
{
|
||||
err = "You can't capture pieces of your same color";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override ArrayList GetMoves(bool capture)
|
||||
{
|
||||
ArrayList moves = new ArrayList();
|
||||
|
||||
int[] xDirection = new int[] { -1, 1, 0, 0 };
|
||||
int[] yDirection = new int[] { 0, 0, 1, -1 };
|
||||
|
||||
for ( int i = 0; i < 4; i++ )
|
||||
{
|
||||
int xDir = xDirection[ i ];
|
||||
int yDir = yDirection[ i ];
|
||||
|
||||
int offset = 1;
|
||||
|
||||
while ( true )
|
||||
{
|
||||
Point2D p = new Point2D( m_Position.X + offset * xDir, m_Position.Y + offset * yDir );
|
||||
|
||||
if ( ! m_BChessboard.IsValid( p ) )
|
||||
break;
|
||||
|
||||
BaseChessPiece piece = m_BChessboard[ p ];
|
||||
|
||||
if ( piece == null )
|
||||
{
|
||||
moves.Add( p );
|
||||
offset++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( capture && piece.Color != m_Color )
|
||||
{
|
||||
moves.Add( p );
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return moves;
|
||||
}
|
||||
|
||||
public override bool IsCastle(Point2D loc)
|
||||
{
|
||||
King king = m_BChessboard[ loc ] as King;
|
||||
|
||||
string err = null;
|
||||
|
||||
return king != null && king.Color == m_Color && m_BChessboard.AllowCastle( king, this, ref err );
|
||||
}
|
||||
|
||||
public void Castle()
|
||||
{
|
||||
m_Castle = true;
|
||||
|
||||
int dx = 0;
|
||||
|
||||
if ( m_Position.X == 0 )
|
||||
dx = 3;
|
||||
else if ( m_Position.X == 7 )
|
||||
dx = -2;
|
||||
|
||||
Move move = new Move( this, new Point2D( m_Position.X + dx, m_Position.Y ) );
|
||||
|
||||
MoveTo( move );
|
||||
}
|
||||
|
||||
public override void OnMoveOver()
|
||||
{
|
||||
if ( ! m_Castle )
|
||||
base.OnMoveOver ();
|
||||
else
|
||||
{
|
||||
m_Castle = false;
|
||||
|
||||
m_BChessboard.ApplyMove( m_Move );
|
||||
|
||||
King king = m_BChessboard.GetKing( m_Color ) as King;
|
||||
|
||||
int dx = 0;
|
||||
|
||||
if ( m_Position.X == 3 )
|
||||
dx = -2;
|
||||
else
|
||||
dx = 2;
|
||||
|
||||
king.EndCastle( new Point2D( king.Position.X + dx, king.Position.Y ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,402 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
using Server;
|
||||
using Server.Items;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the two colors used in the chess game
|
||||
/// </summary>
|
||||
public enum ChessColor
|
||||
{
|
||||
Black,
|
||||
White
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This abstract class defines the basic features of a chess piece
|
||||
/// </summary>
|
||||
public abstract class BaseChessPiece
|
||||
{
|
||||
#region Variables
|
||||
|
||||
/// <summary>
|
||||
/// This represents the NPC that corresponds to this chess piece
|
||||
/// </summary>
|
||||
protected ChessMobile m_Piece;
|
||||
/// <summary>
|
||||
/// The BChessboard object parent of this chess piece
|
||||
/// </summary>
|
||||
protected BChessboard m_BChessboard;
|
||||
/// <summary>
|
||||
/// The color of this piece
|
||||
/// </summary>
|
||||
protected ChessColor m_Color;
|
||||
/// <summary>
|
||||
/// The position of the chess piece on the board
|
||||
/// </summary>
|
||||
protected Point2D m_Position;
|
||||
/// <summary>
|
||||
/// Specifies if this piece has been killed
|
||||
/// </summary>
|
||||
protected bool m_Dead = false;
|
||||
/// <summary>
|
||||
/// Specifies if the piece has already been moved or not
|
||||
/// </summary>
|
||||
protected bool m_HasMoved = false;
|
||||
/// <summary>
|
||||
/// The move this piece is performing
|
||||
/// </summary>
|
||||
protected Move m_Move;
|
||||
/// <summary>
|
||||
/// The sound made when the piece moves
|
||||
/// </summary>
|
||||
protected int m_MoveSound;
|
||||
/// <summary>
|
||||
/// The sound made when the piece captures
|
||||
/// </summary>
|
||||
protected int m_CaptureSound;
|
||||
/// <summary>
|
||||
/// The sound made when the piece is captured
|
||||
/// </summary>
|
||||
protected int m_DeathSound;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the NPC corresponding to this chess piece
|
||||
/// </summary>
|
||||
public ChessMobile Piece
|
||||
{
|
||||
get { return m_Piece; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the color of this piece
|
||||
/// </summary>
|
||||
public ChessColor Color
|
||||
{
|
||||
get { return m_Color; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the color of the enemy
|
||||
/// </summary>
|
||||
public ChessColor EnemyColor
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Color == ChessColor.Black )
|
||||
return ChessColor.White;
|
||||
else
|
||||
return ChessColor.Black;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the position of this chess piece.
|
||||
/// This does NOT move the chess piece on the chess board
|
||||
/// </summary>
|
||||
public Point2D Position
|
||||
{
|
||||
get { return m_Position; }
|
||||
set { m_Position = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the facing for the NPC when it's standing
|
||||
/// </summary>
|
||||
public virtual Direction Facing
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_BChessboard.Orientation == BoardOrientation.NorthSouth )
|
||||
{
|
||||
if ( m_Color == ChessColor.Black )
|
||||
return Direction.South;
|
||||
else
|
||||
return Direction.North;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( m_Color == ChessColor.Black )
|
||||
return Direction.East;
|
||||
else
|
||||
return Direction.West;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the hue used to color items for this piece
|
||||
/// </summary>
|
||||
public virtual int Hue
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Color == ChessColor.Black )
|
||||
return m_BChessboard.BlackHue;
|
||||
else
|
||||
return m_BChessboard.WhiteHue;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the opposite hue for this piece
|
||||
/// </summary>
|
||||
public virtual int SecondaryHue
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Color == ChessColor.Black )
|
||||
return m_BChessboard.WhiteHue;
|
||||
else
|
||||
return m_BChessboard.BlackHue;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int MinorHue
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Color == ChessColor.Black )
|
||||
return m_BChessboard.BlackMinorHue;
|
||||
else
|
||||
return m_BChessboard.WhiteMinorHue;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the power value of this piece
|
||||
/// </summary>
|
||||
public abstract int Power
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// States whether this piece has already moved
|
||||
/// </summary>
|
||||
public virtual bool HasMoved
|
||||
{
|
||||
get { return m_HasMoved; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies if this piece can be captured by a pawn en passant
|
||||
/// </summary>
|
||||
public virtual bool AllowEnPassantCapture
|
||||
{
|
||||
get { return false; }
|
||||
set {}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new chess piece object
|
||||
/// </summary>
|
||||
/// <param name="board">The BChessboard object hosting this piece</param>
|
||||
/// <param name="color">The color of this piece</param>
|
||||
/// <param name="position">The initial position on the board</param>
|
||||
public BaseChessPiece( BChessboard board, ChessColor color, Point2D position )
|
||||
{
|
||||
m_BChessboard = board;
|
||||
m_Color = color;
|
||||
m_Position = position;
|
||||
|
||||
CreatePiece();
|
||||
}
|
||||
|
||||
#region NPC Creation
|
||||
|
||||
/// <summary>
|
||||
/// Creates the NPC that will represent this piece and places it in the correct world location
|
||||
/// </summary>
|
||||
protected virtual void CreatePiece()
|
||||
{
|
||||
InitializePiece();
|
||||
Point3D loc = new Point3D( m_BChessboard.BoardToWorld( m_Position ), m_BChessboard.Z );
|
||||
|
||||
if ( m_BChessboard.OverrideMinorHue )
|
||||
m_Piece.SolidHueOverride = Hue;
|
||||
|
||||
m_Piece.MoveToWorld( loc, m_BChessboard.Map );
|
||||
m_Piece.FixedParticles( 14089, 1, 15, 5012, Hue, 2, EffectLayer.Waist );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and initializes the chess piece NPC
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public abstract void InitializePiece();
|
||||
|
||||
/// <summary>
|
||||
/// Rebuilds the NPC applying any changes made to the appearance
|
||||
/// </summary>
|
||||
public virtual void Rebuild()
|
||||
{
|
||||
Die( false );
|
||||
CreatePiece();
|
||||
m_Dead = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Piece Movement
|
||||
|
||||
/// <summary>
|
||||
/// Verifies if this piece can move to a specified location.
|
||||
/// </summary>
|
||||
/// <param name="newLocation">The new location</param>
|
||||
/// <param name="err">Will hold the eventual error message</param>
|
||||
/// <returns>True if the move is allowed, false otherwise.</returns>
|
||||
public virtual bool CanMoveTo( Point2D newLocation, ref string err )
|
||||
{
|
||||
if ( newLocation == m_Position )
|
||||
{
|
||||
err = "Can't move to the same spot";
|
||||
return false; // Same spot isn't a valid move
|
||||
}
|
||||
|
||||
// Base version, check only for out of bounds
|
||||
if ( newLocation.X >= 0 && newLocation.Y >= 0 && newLocation.X < 8 && newLocation.Y < 8 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = "Can't move out of chessboard";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the chess piece to the specified position. This function assumes that a previous call
|
||||
/// to CanMoveTo() has been made and the move has been authorized.
|
||||
/// </summary>
|
||||
/// <param name="move">The move performed</param>
|
||||
public virtual void MoveTo( Move move )
|
||||
{
|
||||
m_HasMoved = true;
|
||||
|
||||
m_Move = move;
|
||||
|
||||
Point2D worldLocation = m_BChessboard.BoardToWorld( move.To );
|
||||
|
||||
if ( move.Capture )
|
||||
{
|
||||
m_BChessboard.PlaySound( m_Piece, m_CaptureSound );
|
||||
|
||||
// It's a capture, do an effect
|
||||
m_Piece.MovingParticles( move.CapturedPiece.m_Piece, m_BChessboard.AttackEffect, 5, 0, false, true, Hue, 2, 0, 1, 4006, EffectLayer.Waist, 0 );
|
||||
move.CapturedPiece.Die(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_BChessboard.PlaySound( m_Piece, m_MoveSound );
|
||||
}
|
||||
|
||||
m_Piece.GoTo( worldLocation );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function is called by the NPC when its move is over
|
||||
/// </summary>
|
||||
public virtual void OnMoveOver()
|
||||
{
|
||||
m_BChessboard.OnMoveOver( m_Move );
|
||||
|
||||
m_Move = null;
|
||||
|
||||
m_Piece.Direction = Facing;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of possible moves this piece can perform
|
||||
/// </summary>
|
||||
/// <param name="capture">Specifies whether the moves should include squares where a piece would be captured</param>
|
||||
/// <returns>An ArrayList objects of Point2D values</returns>
|
||||
public abstract ArrayList GetMoves( bool capture );
|
||||
|
||||
/// <summary>
|
||||
/// Gets the piece that this piece would capture when moving to a specific location.
|
||||
/// This function assumes that the square can be reached.
|
||||
/// </summary>
|
||||
/// <param name="at">The target location with the potential capture</param>
|
||||
/// <param name="enpassant">Will hold a value stating whether this move is made en passant</param>
|
||||
/// <returns>A BaseChessPiece if a capture is possible, null otherwise</returns>
|
||||
public virtual BaseChessPiece GetCaptured( Point2D at, ref bool enpassant )
|
||||
{
|
||||
enpassant = false;
|
||||
|
||||
BaseChessPiece piece = m_BChessboard[ at ];
|
||||
|
||||
if ( piece != null && piece.Color != m_Color )
|
||||
return piece;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies if a given move would be a castle
|
||||
/// </summary>
|
||||
/// <param name="loc">The target location</param>
|
||||
/// <returns>True if the move is a castle</returns>
|
||||
public virtual bool IsCastle( Point2D loc )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Deletion and killing
|
||||
|
||||
/// <summary>
|
||||
/// This function is invoked whenever a piece NPC is deleted
|
||||
/// </summary>
|
||||
public virtual void OnPieceDeleted()
|
||||
{
|
||||
if ( ! m_Dead )
|
||||
{
|
||||
m_BChessboard.OnStaffDelete();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function is invoked when the piece is captured and the NPC should be removed from the board
|
||||
/// </summary>
|
||||
/// <param name="sound">Specifies if to play the death sound</param>
|
||||
public virtual void Die( bool sound )
|
||||
{
|
||||
if ( sound ) // Use sound for bolt too - sound is used in normal gameplay
|
||||
{
|
||||
if ( m_BChessboard.BoltOnDeath )
|
||||
m_Piece.BoltEffect( SecondaryHue );
|
||||
|
||||
m_BChessboard.PlaySound( m_Piece, m_DeathSound );
|
||||
}
|
||||
|
||||
m_Dead = true;
|
||||
m_Piece.Delete();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Forces the deletion of this piece
|
||||
/// </summary>
|
||||
public virtual void ForceDelete()
|
||||
{
|
||||
if ( m_Piece != null && ! m_Piece.Deleted )
|
||||
{
|
||||
m_Dead = true;
|
||||
m_Piece.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user