#W# Source and Scripts added. Added Scripts/Settings.cs to expose some basic tweak able settings.

This commit is contained in:
WarrentyExpired 2026-08-06 11:06:05 -04:00
parent b51c58f514
commit 3045c83799
3512 changed files with 627673 additions and 0 deletions

View file

@ -0,0 +1,55 @@
using System;
using System.Collections;
namespace Server.Items
{
[Flipable( 0xE1C, 0xFAD )]
public class Backgammon : BaseBoard
{
[Constructable]
public Backgammon() : base( 0xE1C )
{
}
public override void CreatePieces()
{
for ( int i = 0; i < 5; i++ )
{
CreatePiece( new PieceWhiteChecker( this ), 42, ( 17 * i ) + 6 );
CreatePiece( new PieceBlackChecker( this ), 42, ( 17 * i ) + 119 );
CreatePiece( new PieceBlackChecker( this ), 142, ( 17 * i ) + 6 );
CreatePiece( new PieceWhiteChecker( this ), 142, ( 17 * i ) + 119 );
}
for ( int i = 0; i < 3; i++ )
{
CreatePiece( new PieceBlackChecker( this ), 108, ( 17 * i ) + 6 );
CreatePiece( new PieceWhiteChecker( this ), 108, ( 17 * i ) + 153 );
}
for ( int i = 0; i < 2; i++ )
{
CreatePiece( new PieceWhiteChecker( this ), 223, ( 17 * i ) + 6 );
CreatePiece( new PieceBlackChecker( this ), 223, ( 17 * i ) + 170 );
}
}
public Backgammon( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 ); // version
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
}

View file

@ -0,0 +1,169 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Server;
using Server.Items;
using Server.Multis;
using Server.Network;
using Server.ContextMenus;
using Server.Gumps;
namespace Server.Items
{
public abstract class BaseBoard : Container, ISecurable
{
private SecureLevel m_Level;
[CommandProperty( AccessLevel.GameMaster )]
public SecureLevel Level
{
get{ return m_Level; }
set{ m_Level = value; }
}
public BaseBoard( int itemID ) : base( itemID )
{
CreatePieces();
Weight = 5.0;
}
public abstract void CreatePieces();
public void Reset()
{
for ( int i = Items.Count - 1; i >= 0; --i )
{
if ( i < Items.Count )
Items[i].Delete();
}
CreatePieces();
}
public void CreatePiece( BasePiece piece, int x, int y )
{
AddItem( piece );
piece.Location = new Point3D( x, y, 0 );
}
public override bool DisplaysContent{ get{ return false; } } // Do not display (x items, y stones)
public override bool IsDecoContainer{ get{ return false; } }
public BaseBoard( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 1 ); // version
writer.Write( (int)m_Level );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
if ( version == 1 )
m_Level = (SecureLevel)reader.ReadInt();
if ( Weight == 1.0 )
Weight = 5.0;
}
public override TimeSpan DecayTime{ get{ return TimeSpan.FromDays( 1.0 ); } }
public override bool OnDragDrop( Mobile from, Item dropped )
{
BasePiece piece = dropped as BasePiece;
return ( piece != null && piece.Board == this && base.OnDragDrop( from, dropped ) );
}
public override bool OnDragDropInto( Mobile from, Item dropped, Point3D point )
{
BasePiece piece = dropped as BasePiece;
if ( piece != null && piece.Board == this && base.OnDragDropInto( from, dropped, point ) )
{
Packet p = new PlaySound( 0x127, GetWorldLocation() );
p.Acquire();
if ( RootParent == from )
{
from.Send( p );
}
else
{
foreach ( NetState state in this.GetClientsInRange( 2 ) )
state.Send( p );
}
p.Release();
return true;
}
else
{
return false;
}
}
public override void GetContextMenuEntries( Mobile from, List<ContextMenuEntry> list )
{
base.GetContextMenuEntries( from, list );
if ( ValidateDefault( from, this ) )
list.Add( new DefaultEntry( from, this ) );
SetSecureLevelEntry.AddTo( from, this, list );
}
public static bool ValidateDefault( Mobile from, BaseBoard board )
{
if ( from.AccessLevel >= AccessLevel.GameMaster )
return true;
if ( !from.Alive )
return false;
if ( board.IsChildOf( from.Backpack ) )
return true;
object root = board.RootParent;
if ( root is Mobile && root != from )
return false;
if ( board.Deleted || board.Map != from.Map || !from.InRange( board.GetWorldLocation(), 1 ) )
return false;
BaseHouse house = BaseHouse.FindHouseAt( board );
return ( house != null && house.IsOwner( from ) );
}
public class DefaultEntry : ContextMenuEntry
{
private Mobile m_From;
private BaseBoard m_Board;
public DefaultEntry( Mobile from, BaseBoard board ) : base( 6162, from.AccessLevel >= AccessLevel.GameMaster ? -1 : 1 )
{
m_From = from;
m_Board = board;
}
public override void OnClick()
{
if ( BaseBoard.ValidateDefault( m_From, m_Board ) )
m_Board.Reset();
}
}
}
}

View file

@ -0,0 +1,105 @@
using System;
using Server;
namespace Server.Items
{
public class BasePiece : Item
{
private BaseBoard m_Board;
public BaseBoard Board
{
get { return m_Board; }
set { m_Board = value; }
}
public override bool IsVirtualItem{ get{ return true; } }
public BasePiece( int itemID, BaseBoard board ) : base( itemID )
{
m_Board = board;
}
public BasePiece( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 );
writer.Write( m_Board );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
switch ( version )
{
case 0:
{
m_Board = (BaseBoard)reader.ReadItem();
if ( m_Board == null || Parent == null )
Delete();
break;
}
}
}
public override void OnSingleClick( Mobile from )
{
if ( m_Board == null || m_Board.Deleted )
Delete();
else if ( !IsChildOf( m_Board ) )
m_Board.DropItem( this );
else
base.OnSingleClick( from );
}
public override bool OnDragLift( Mobile from )
{
if ( m_Board == null || m_Board.Deleted )
{
Delete();
return false;
}
else if ( !IsChildOf( m_Board ) )
{
m_Board.DropItem( this );
return false;
}
else
{
return true;
}
}
public override bool CanTarget{ get{ return false; } }
public override bool DropToMobile( Mobile from, Mobile target, Point3D p )
{
return false;
}
public override bool DropToItem( Mobile from, Item target, Point3D p )
{
return ( target == m_Board && p.X != -1 && p.Y != -1 && base.DropToItem( from, target, p ) );
}
public override bool DropToWorld( Mobile from, Point3D p )
{
return false;
}
public override int GetLiftSound( Mobile from )
{
return -1;
}
}
}

View file

@ -0,0 +1,44 @@
using System;
using System.Collections;
namespace Server.Items
{
public class CheckerBoard : BaseBoard
{
public override int LabelNumber{ get{ return 1016449; } } // a checker board
[Constructable]
public CheckerBoard() : base( 0xFA6 )
{
}
public override void CreatePieces()
{
for ( int i = 0; i < 4; i++ )
{
CreatePiece( new PieceWhiteChecker( this ), ( 50 * i ) + 45, 25 );
CreatePiece( new PieceWhiteChecker( this ), ( 50 * i ) + 70, 50 );
CreatePiece( new PieceWhiteChecker( this ), ( 50 * i ) + 45, 75 );
CreatePiece( new PieceBlackChecker( this ), ( 50 * i ) + 70, 150 );
CreatePiece( new PieceBlackChecker( this ), ( 50 * i ) + 45, 175 );
CreatePiece( new PieceBlackChecker( this ), ( 50 * i ) + 70, 200 );
}
}
public CheckerBoard( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 ); // version
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
}

View file

@ -0,0 +1,61 @@
using System;
using Server;
namespace Server.Items
{
public class PieceWhiteChecker : BasePiece
{
public override string DefaultName
{
get { return "white checker"; }
}
public PieceWhiteChecker( BaseBoard board ) : base( 0x3584, board )
{
}
public PieceWhiteChecker( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
public class PieceBlackChecker : BasePiece
{
public override string DefaultName
{
get { return "black checker"; }
}
public PieceBlackChecker( BaseBoard board ) : base( 0x358B, board )
{
}
public PieceBlackChecker( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
}

View file

@ -0,0 +1,341 @@
using System;
using Server;
namespace Server.Items
{
public class PieceWhiteKing : BasePiece
{
public override string DefaultName
{
get { return "white king"; }
}
public PieceWhiteKing( BaseBoard board ) : base( 0x3587, board )
{
}
public PieceWhiteKing( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
public class PieceBlackKing : BasePiece
{
public override string DefaultName
{
get { return "black king"; }
}
public PieceBlackKing( BaseBoard board ) : base( 0x358E, board )
{
}
public PieceBlackKing( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
public class PieceWhiteQueen : BasePiece
{
public override string DefaultName
{
get { return "white queen"; }
}
public PieceWhiteQueen( BaseBoard board ) : base( 0x358A, board )
{
}
public PieceWhiteQueen( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
public class PieceBlackQueen : BasePiece
{
public override string DefaultName
{
get { return "black queen"; }
}
public PieceBlackQueen( BaseBoard board ) : base( 0x3591, board )
{
}
public PieceBlackQueen( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
public class PieceWhiteRook : BasePiece
{
public override string DefaultName
{
get { return "white rook"; }
}
public PieceWhiteRook( BaseBoard board ) : base( 0x3586, board )
{
}
public PieceWhiteRook( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
public class PieceBlackRook : BasePiece
{
public override string DefaultName
{
get { return "black rook"; }
}
public PieceBlackRook( BaseBoard board ) : base( 0x358D, board )
{
}
public PieceBlackRook( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
public class PieceWhiteBishop : BasePiece
{
public override string DefaultName
{
get { return "white bishop"; }
}
public PieceWhiteBishop( BaseBoard board ) : base( 0x3585, board )
{
}
public PieceWhiteBishop( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
public class PieceBlackBishop : BasePiece
{
public override string DefaultName
{
get { return "black bishop"; }
}
public PieceBlackBishop( BaseBoard board ) : base( 0x358C, board )
{
}
public PieceBlackBishop( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
public class PieceWhiteKnight : BasePiece
{
public override string DefaultName
{
get { return "white knight"; }
}
public PieceWhiteKnight( BaseBoard board ) : base( 0x3588, board )
{
}
public PieceWhiteKnight( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
public class PieceBlackKnight : BasePiece
{
public override string DefaultName
{
get { return "black knight"; }
}
public PieceBlackKnight( BaseBoard board ) : base( 0x358F, board )
{
}
public PieceBlackKnight( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
public class PieceWhitePawn : BasePiece
{
public override string DefaultName
{
get { return "white pawn"; }
}
public PieceWhitePawn( BaseBoard board ) : base( 0x3589, board )
{
}
public PieceWhitePawn( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
public class PieceBlackPawn : BasePiece
{
public override string DefaultName
{
get { return "black pawn"; }
}
public PieceBlackPawn( BaseBoard board ) : base( 0x3590, board )
{
}
public PieceBlackPawn( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
}

View file

@ -0,0 +1,69 @@
using System;
using System.Collections;
namespace Server.Items
{
public class Chessboard : BaseBoard
{
public override int LabelNumber{ get{ return 1016450; } } // a chessboard
[Constructable]
public Chessboard() : base( 0xFA6 )
{
}
public override void CreatePieces()
{
for ( int i = 0; i < 8; i++ )
{
CreatePiece( new PieceBlackPawn( this ), 67, ( 25 * i ) + 17 );
CreatePiece( new PieceWhitePawn( this ), 192, ( 25 * i ) + 17 );
}
// Rook
CreatePiece( new PieceBlackRook( this ), 42, 5 );
CreatePiece( new PieceBlackRook( this ), 42, 180 );
CreatePiece( new PieceWhiteRook( this ), 216, 5 );
CreatePiece( new PieceWhiteRook( this ), 216, 180 );
// Knight
CreatePiece( new PieceBlackKnight( this ), 42, 30 );
CreatePiece( new PieceBlackKnight( this ), 42, 155 );
CreatePiece( new PieceWhiteKnight( this ), 216, 30 );
CreatePiece( new PieceWhiteKnight( this ), 216, 155 );
// Bishop
CreatePiece( new PieceBlackBishop( this ), 42, 55 );
CreatePiece( new PieceBlackBishop( this ), 42, 130 );
CreatePiece( new PieceWhiteBishop( this ), 216, 55 );
CreatePiece( new PieceWhiteBishop( this ), 216, 130 );
// Queen
CreatePiece( new PieceBlackQueen( this ), 42, 105 );
CreatePiece( new PieceWhiteQueen( this ), 216, 105 );
// King
CreatePiece( new PieceBlackKing( this ), 42, 80 );
CreatePiece( new PieceWhiteKing( this ), 216, 80 );
}
public Chessboard( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 ); // version
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
}

View file

@ -0,0 +1,52 @@
using System;
using Server;
using Server.Network;
namespace Server.Items
{
public class Dices : Item, ITelekinesisable
{
[Constructable]
public Dices() : base( 0xFA7 )
{
Weight = 1.0;
}
public Dices( Serial serial ) : base( serial )
{
}
public override void OnDoubleClick( Mobile from )
{
if ( !from.InRange( this.GetWorldLocation(), 2 ) )
return;
Roll( from );
}
public void OnTelekinesis( Mobile from )
{
Effects.SendLocationParticles( EffectItem.Create( Location, Map, EffectItem.DefaultDuration ), 0x376A, 9, 32, 5022 );
Effects.PlaySound( Location, Map, 0x1F5 );
Roll( from );
}
public void Roll( Mobile from )
{
this.PublicOverheadMessage( MessageType.Regular, 0, false, string.Format( "*{0} rolls {1}, {2}*", from.Name, Utility.Random( 1, 6 ), Utility.Random( 1, 6 ) ) );
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
}

View file

@ -0,0 +1,73 @@
using System;
using Server;
namespace Server.Engines.Mahjong
{
public class MahjongDealerIndicator
{
public static MahjongPieceDim GetDimensions( Point2D position, MahjongPieceDirection direction )
{
if ( direction == MahjongPieceDirection.Up || direction == MahjongPieceDirection.Down )
return new MahjongPieceDim( position, 40, 20 );
else
return new MahjongPieceDim( position, 20, 40 );
}
private MahjongGame m_Game;
private Point2D m_Position;
private MahjongPieceDirection m_Direction;
private MahjongWind m_Wind;
public MahjongGame Game { get { return m_Game; } }
public Point2D Position { get { return m_Position; } }
public MahjongPieceDirection Direction { get { return m_Direction; } }
public MahjongWind Wind { get { return m_Wind; } }
public MahjongDealerIndicator( MahjongGame game, Point2D position, MahjongPieceDirection direction, MahjongWind wind )
{
m_Game = game;
m_Position = position;
m_Direction = direction;
m_Wind = wind;
}
public MahjongPieceDim Dimensions
{
get { return GetDimensions( m_Position, m_Direction ); }
}
public void Move( Point2D position, MahjongPieceDirection direction, MahjongWind wind )
{
MahjongPieceDim dim = GetDimensions( position, direction );
if ( !dim.IsValid() )
return;
m_Position = position;
m_Direction = direction;
m_Wind = wind;
m_Game.Players.SendGeneralPacket( true, true );
}
public void Save( GenericWriter writer )
{
writer.Write( (int) 0 ); // version
writer.Write( m_Position );
writer.Write( (int) m_Direction );
writer.Write( (int) m_Wind );
}
public MahjongDealerIndicator( MahjongGame game, GenericReader reader )
{
m_Game = game;
int version = reader.ReadInt();
m_Position = reader.ReadPoint2D();
m_Direction = (MahjongPieceDirection) reader.ReadInt();
m_Wind = (MahjongWind) reader.ReadInt();
}
}
}

View file

@ -0,0 +1,52 @@
using System;
using Server;
namespace Server.Engines.Mahjong
{
public class MahjongDices
{
private MahjongGame m_Game;
private int m_First;
private int m_Second;
public MahjongGame Game { get { return m_Game; } }
public int First { get { return m_First; } }
public int Second { get { return m_Second; } }
public MahjongDices( MahjongGame game )
{
m_Game = game;
m_First = Utility.Random( 1, 6 );
m_Second = Utility.Random( 1, 6 );
}
public void RollDices( Mobile from )
{
m_First = Utility.Random( 1, 6 );
m_Second = Utility.Random( 1, 6 );
m_Game.Players.SendGeneralPacket( true, true );
if ( from != null )
m_Game.Players.SendLocalizedMessage( 1062695, string.Format( "{0}\t{1}\t{2}", from.Name, m_First, m_Second ) ); // ~1_name~ rolls the dice and gets a ~2_number~ and a ~3_number~!
}
public void Save( GenericWriter writer )
{
writer.Write( (int) 0 ); // version
writer.Write( m_First );
writer.Write( m_Second );
}
public MahjongDices( MahjongGame game, GenericReader reader )
{
m_Game = game;
int version = reader.ReadInt();
m_First = reader.ReadInt();
m_Second = reader.ReadInt();
}
}
}

View file

@ -0,0 +1,58 @@
using System;
namespace Server.Engines.Mahjong
{
public enum MahjongPieceDirection
{
Up,
Left,
Down,
Right
}
public enum MahjongWind
{
North,
East,
South,
West
}
public enum MahjongTileType
{
Dagger1 = 1,
Dagger2,
Dagger3,
Dagger4,
Dagger5,
Dagger6,
Dagger7,
Dagger8,
Dagger9,
Gem1,
Gem2,
Gem3,
Gem4,
Gem5,
Gem6,
Gem7,
Gem8,
Gem9,
Number1,
Number2,
Number3,
Number4,
Number5,
Number6,
Number7,
Number8,
Number9,
North,
East,
South,
West,
Green,
Red,
White
}
}

View file

@ -0,0 +1,302 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Server;
using Server.Gumps;
using Server.Multis;
using Server.ContextMenus;
namespace Server.Engines.Mahjong
{
public class MahjongGame : Item, ISecurable
{
public const int MaxPlayers = 4;
public const int BaseScore = 30000;
private MahjongTile[] m_Tiles;
private MahjongDealerIndicator m_DealerIndicator;
private MahjongWallBreakIndicator m_WallBreakIndicator;
private MahjongDices m_Dices;
private MahjongPlayers m_Players;
private bool m_ShowScores;
private bool m_SpectatorVision;
private DateTime m_LastReset;
public MahjongTile[] Tiles { get { return m_Tiles; } }
public MahjongDealerIndicator DealerIndicator { get { return m_DealerIndicator; } }
public MahjongWallBreakIndicator WallBreakIndicator { get { return m_WallBreakIndicator; } }
public MahjongDices Dices { get { return m_Dices; } }
public MahjongPlayers Players { get { return m_Players; } }
private SecureLevel m_Level;
[CommandProperty( AccessLevel.GameMaster )]
public SecureLevel Level
{
get{ return m_Level; }
set{ m_Level = value; }
}
[CommandProperty( AccessLevel.GameMaster )]
public bool ShowScores
{
get { return m_ShowScores; }
set
{
if ( m_ShowScores == value )
return;
m_ShowScores = value;
if ( value )
m_Players.SendPlayersPacket( true, true );
m_Players.SendGeneralPacket( true, true );
m_Players.SendLocalizedMessage( value ? 1062777 : 1062778 ); // The dealer has enabled/disabled score display.
}
}
[CommandProperty( AccessLevel.GameMaster )]
public bool SpectatorVision
{
get { return m_SpectatorVision; }
set
{
if ( m_SpectatorVision == value )
return;
m_SpectatorVision = value;
if ( m_Players.IsInGamePlayer( m_Players.DealerPosition ) )
m_Players.Dealer.Send( new MahjongGeneralInfo( this ) );
m_Players.SendTilesPacket( false, true );
m_Players.SendLocalizedMessage( value ? 1062715 : 1062716 ); // The dealer has enabled/disabled Spectator Vision.
InvalidateProperties();
}
}
[Constructable]
public MahjongGame() : base( 0xFAA )
{
Weight = 5.0;
BuildWalls();
m_DealerIndicator = new MahjongDealerIndicator( this, new Point2D( 300, 300 ), MahjongPieceDirection.Up, MahjongWind.North );
m_WallBreakIndicator = new MahjongWallBreakIndicator( this, new Point2D( 335, 335 ) );
m_Dices = new MahjongDices( this );
m_Players = new MahjongPlayers( this, MaxPlayers, BaseScore );
m_LastReset = DateTime.UtcNow;
m_Level = SecureLevel.CoOwners;
}
public MahjongGame( Serial serial ) : base( serial )
{
}
private void BuildHorizontalWall( ref int index, int x, int y, int stackLevel, MahjongPieceDirection direction, MahjongTileTypeGenerator typeGenerator )
{
for ( int i = 0; i < 17; i++ )
{
Point2D position = new Point2D( x + i*20, y );
m_Tiles[index + i] = new MahjongTile( this, index + i, typeGenerator.Next(), position, stackLevel, direction, false );
}
index += 17;
}
private void BuildVerticalWall( ref int index, int x, int y, int stackLevel, MahjongPieceDirection direction, MahjongTileTypeGenerator typeGenerator )
{
for ( int i = 0; i < 17; i++ )
{
Point2D position = new Point2D( x, y + i*20 );
m_Tiles[index + i] = new MahjongTile( this, index + i, typeGenerator.Next(), position, stackLevel, direction, false );
}
index += 17;
}
private void BuildWalls()
{
m_Tiles = new MahjongTile[17 * 8];
MahjongTileTypeGenerator typeGenerator = new MahjongTileTypeGenerator( 4 );
int i = 0;
BuildHorizontalWall( ref i, 165, 110, 0, MahjongPieceDirection.Up, typeGenerator );
BuildHorizontalWall( ref i, 165, 115, 1, MahjongPieceDirection.Up, typeGenerator );
BuildVerticalWall( ref i, 530, 165, 0, MahjongPieceDirection.Left, typeGenerator );
BuildVerticalWall( ref i, 525, 165, 1, MahjongPieceDirection.Left, typeGenerator );
BuildHorizontalWall( ref i, 165, 530, 0, MahjongPieceDirection.Down, typeGenerator );
BuildHorizontalWall( ref i, 165, 525, 1, MahjongPieceDirection.Down, typeGenerator );
BuildVerticalWall( ref i, 110, 165, 0, MahjongPieceDirection.Right, typeGenerator );
BuildVerticalWall( ref i, 115, 165, 1, MahjongPieceDirection.Right, typeGenerator );
}
public override void GetProperties( ObjectPropertyList list )
{
base.GetProperties( list );
if ( m_SpectatorVision )
list.Add( 1062717 ); // Spectator Vision Enabled
else
list.Add( 1062718 ); // Spectator Vision Disabled
}
public override void GetContextMenuEntries( Mobile from, List<ContextMenuEntry> list )
{
base.GetContextMenuEntries( from, list );
m_Players.CheckPlayers();
if ( from.Alive && IsAccessibleTo( from ) && m_Players.GetInGameMobiles( true, false ).Count == 0 )
list.Add( new ResetGameEntry( this ) );
SetSecureLevelEntry.AddTo( from, this, list );
}
private class ResetGameEntry : ContextMenuEntry
{
private MahjongGame m_Game;
public ResetGameEntry( MahjongGame game ) : base( 6162 )
{
m_Game = game;
}
public override void OnClick()
{
Mobile from = Owner.From;
if ( from.CheckAlive() && !m_Game.Deleted && m_Game.IsAccessibleTo( from ) && m_Game.Players.GetInGameMobiles( true, false ).Count == 0 )
m_Game.ResetGame( from );
}
}
public override void OnDoubleClick( Mobile from )
{
m_Players.CheckPlayers();
m_Players.Join( from );
}
public void ResetGame( Mobile from )
{
if ( DateTime.UtcNow - m_LastReset < TimeSpan.FromSeconds( 5.0 ) )
return;
m_LastReset = DateTime.UtcNow;
if ( from != null )
m_Players.SendLocalizedMessage( 1062771, from.Name ); // ~1_name~ has reset the game.
m_Players.SendRelievePacket( true, true );
BuildWalls();
m_DealerIndicator = new MahjongDealerIndicator( this, new Point2D( 300, 300 ), MahjongPieceDirection.Up, MahjongWind.North );
m_WallBreakIndicator = new MahjongWallBreakIndicator( this, new Point2D( 335, 335 ) );
m_Players = new MahjongPlayers( this, MaxPlayers, BaseScore );
}
public void ResetWalls( Mobile from )
{
if ( DateTime.UtcNow - m_LastReset < TimeSpan.FromSeconds( 5.0 ) )
return;
m_LastReset = DateTime.UtcNow;
BuildWalls();
m_Players.SendTilesPacket( true, true );
if ( from != null )
m_Players.SendLocalizedMessage( 1062696 ); // The dealer rebuilds the wall.
}
public int GetStackLevel( MahjongPieceDim dim )
{
int level = -1;
foreach ( MahjongTile tile in m_Tiles )
{
if ( tile.StackLevel > level && dim.IsOverlapping( tile.Dimensions ) )
level = tile.StackLevel;
}
return level;
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 1 ); // version
writer.Write( (int) m_Level );
writer.Write( m_Tiles.Length );
for ( int i = 0; i < m_Tiles.Length; i++ )
m_Tiles[i].Save( writer );
m_DealerIndicator.Save( writer );
m_WallBreakIndicator.Save( writer );
m_Dices.Save( writer );
m_Players.Save( writer );
writer.Write( m_ShowScores );
writer.Write( m_SpectatorVision );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
switch ( version )
{
case 1:
{
m_Level = (SecureLevel)reader.ReadInt();
goto case 0;
}
case 0:
{
if ( version < 1 )
m_Level = SecureLevel.CoOwners;
int length = reader.ReadInt();
m_Tiles = new MahjongTile[length];
for ( int i = 0; i < length; i++ )
m_Tiles[i] = new MahjongTile( this, reader );
m_DealerIndicator = new MahjongDealerIndicator( this, reader );
m_WallBreakIndicator = new MahjongWallBreakIndicator( this, reader );
m_Dices = new MahjongDices( this, reader );
m_Players = new MahjongPlayers( this, reader );
m_ShowScores = reader.ReadBool();
m_SpectatorVision = reader.ReadBool();
m_LastReset = DateTime.UtcNow;
break;
}
}
}
}
}

View file

@ -0,0 +1,245 @@
using System;
using Server;
using Server.Network;
namespace Server.Engines.Mahjong
{
public delegate void OnMahjongPacketReceive( MahjongGame game, NetState state, PacketReader pvSrc );
public sealed class MahjongPacketHandlers
{
private static OnMahjongPacketReceive[] m_SubCommandDelegates = new OnMahjongPacketReceive[0x100];
public static void RegisterSubCommand( int subCmd, OnMahjongPacketReceive onReceive )
{
m_SubCommandDelegates[subCmd] = onReceive;
}
public static OnMahjongPacketReceive GetSubCommandDelegate( int cmd )
{
if ( cmd >= 0 && cmd < 0x100 )
{
return m_SubCommandDelegates[cmd];
}
else
{
return null;
}
}
public static void Initialize()
{
PacketHandlers.Register( 0xDA, 0, true, new OnPacketReceive( OnPacket ) );
RegisterSubCommand( 0x6, new OnMahjongPacketReceive( ExitGame ) );
RegisterSubCommand( 0xA, new OnMahjongPacketReceive( GivePoints ) );
RegisterSubCommand( 0xB, new OnMahjongPacketReceive( RollDice ) );
RegisterSubCommand( 0xC, new OnMahjongPacketReceive( BuildWalls ) );
RegisterSubCommand( 0xD, new OnMahjongPacketReceive( ResetScores ) );
RegisterSubCommand( 0xF, new OnMahjongPacketReceive( AssignDealer ) );
RegisterSubCommand( 0x10, new OnMahjongPacketReceive( OpenSeat ) );
RegisterSubCommand( 0x11, new OnMahjongPacketReceive( ChangeOption ) );
RegisterSubCommand( 0x15, new OnMahjongPacketReceive( MoveWallBreakIndicator ) );
RegisterSubCommand( 0x16, new OnMahjongPacketReceive( TogglePublicHand ) );
RegisterSubCommand( 0x17, new OnMahjongPacketReceive( MoveTile ) );
RegisterSubCommand( 0x18, new OnMahjongPacketReceive( MoveDealerIndicator ) );
}
public static void OnPacket( NetState state, PacketReader pvSrc )
{
MahjongGame game = World.FindItem( pvSrc.ReadInt32() ) as MahjongGame;
if ( game != null )
game.Players.CheckPlayers();
pvSrc.ReadByte();
int cmd = pvSrc.ReadByte();
OnMahjongPacketReceive onReceive = GetSubCommandDelegate( cmd );
if ( onReceive != null )
{
onReceive( game, state, pvSrc );
}
else
{
pvSrc.Trace( state );
}
}
private static MahjongPieceDirection GetDirection( int value )
{
switch ( value )
{
case 0: return MahjongPieceDirection.Up;
case 1: return MahjongPieceDirection.Left;
case 2: return MahjongPieceDirection.Down;
default: return MahjongPieceDirection.Right;
}
}
private static MahjongWind GetWind( int value )
{
switch ( value )
{
case 0: return MahjongWind.North;
case 1: return MahjongWind.East;
case 2: return MahjongWind.South;
default: return MahjongWind.West;
}
}
public static void ExitGame( MahjongGame game, NetState state, PacketReader pvSrc )
{
if ( game == null )
return;
Mobile from = state.Mobile;
game.Players.LeaveGame( from );
}
public static void GivePoints( MahjongGame game, NetState state, PacketReader pvSrc )
{
if ( game == null || !game.Players.IsInGamePlayer( state.Mobile ) )
return;
int to = pvSrc.ReadByte();
int amount = pvSrc.ReadInt32();
game.Players.TransferScore( state.Mobile, to, amount );
}
public static void RollDice( MahjongGame game, NetState state, PacketReader pvSrc )
{
if ( game == null || !game.Players.IsInGamePlayer( state.Mobile ) )
return;
game.Dices.RollDices( state.Mobile );
}
public static void BuildWalls( MahjongGame game, NetState state, PacketReader pvSrc )
{
if ( game == null || !game.Players.IsInGameDealer( state.Mobile ) )
return;
game.ResetWalls( state.Mobile );
}
public static void ResetScores( MahjongGame game, NetState state, PacketReader pvSrc )
{
if ( game == null || !game.Players.IsInGameDealer( state.Mobile ) )
return;
game.Players.ResetScores( MahjongGame.BaseScore );
}
public static void AssignDealer( MahjongGame game, NetState state, PacketReader pvSrc )
{
if ( game == null || !game.Players.IsInGameDealer( state.Mobile ) )
return;
int position = pvSrc.ReadByte();
game.Players.AssignDealer( position );
}
public static void OpenSeat( MahjongGame game, NetState state, PacketReader pvSrc )
{
if ( game == null || !game.Players.IsInGameDealer( state.Mobile ) )
return;
int position = pvSrc.ReadByte();
if ( game.Players.GetPlayer( position ) == state.Mobile )
return;
game.Players.OpenSeat( position );
}
public static void ChangeOption( MahjongGame game, NetState state, PacketReader pvSrc )
{
if ( game == null || !game.Players.IsInGameDealer( state.Mobile ) )
return;
pvSrc.ReadInt16();
pvSrc.ReadByte();
int options = pvSrc.ReadByte();
game.ShowScores = (options & 0x1) != 0;
game.SpectatorVision = (options & 0x2) != 0;
}
public static void MoveWallBreakIndicator( MahjongGame game, NetState state, PacketReader pvSrc )
{
if ( game == null || !game.Players.IsInGameDealer( state.Mobile ) )
return;
int y = pvSrc.ReadInt16();
int x = pvSrc.ReadInt16();
game.WallBreakIndicator.Move( new Point2D( x, y ) );
}
public static void TogglePublicHand( MahjongGame game, NetState state, PacketReader pvSrc )
{
if ( game == null || !game.Players.IsInGamePlayer( state.Mobile ) )
return;
pvSrc.ReadInt16();
pvSrc.ReadByte();
bool publicHand = pvSrc.ReadBoolean();
game.Players.SetPublic( game.Players.GetPlayerIndex( state.Mobile ), publicHand );
}
public static void MoveTile( MahjongGame game, NetState state, PacketReader pvSrc )
{
if ( game == null || !game.Players.IsInGamePlayer( state.Mobile ) )
return;
int number = pvSrc.ReadByte();
if ( number < 0 || number >= game.Tiles.Length )
return;
pvSrc.ReadByte(); // Current direction
MahjongPieceDirection direction = GetDirection( pvSrc.ReadByte() );
pvSrc.ReadByte();
bool flip = pvSrc.ReadBoolean();
pvSrc.ReadInt16(); // Current Y
pvSrc.ReadInt16(); // Current X
pvSrc.ReadByte();
int y = pvSrc.ReadInt16();
int x = pvSrc.ReadInt16();
pvSrc.ReadByte();
game.Tiles[number].Move( new Point2D( x, y ), direction, flip, game.Players.GetPlayerIndex( state.Mobile ) );
}
public static void MoveDealerIndicator( MahjongGame game, NetState state, PacketReader pvSrc )
{
if ( game == null || !game.Players.IsInGameDealer( state.Mobile ) )
return;
MahjongPieceDirection direction = GetDirection( pvSrc.ReadByte() );
MahjongWind wind = GetWind( pvSrc.ReadByte() );
int y = pvSrc.ReadInt16();
int x = pvSrc.ReadInt16();
game.DealerIndicator.Move( new Point2D( x, y ), direction, wind );
}
}
}

View file

@ -0,0 +1,50 @@
using System;
using Server;
namespace Server.Engines.Mahjong
{
public struct MahjongPieceDim
{
private Point2D m_Position;
private int m_Width;
private int m_Height;
public Point2D Position { get { return m_Position; } }
public int Width { get { return m_Width; } }
public int Height { get { return m_Height; } }
public MahjongPieceDim( Point2D position, int width, int height )
{
m_Position = position;
m_Width = width;
m_Height = height;
}
public bool IsValid()
{
return m_Position.X >= 0 && m_Position.Y >= 0 && m_Position.X + m_Width <= 670 && m_Position.Y + m_Height <= 670;
}
public bool IsOverlapping( MahjongPieceDim dim )
{
return m_Position.X < dim.m_Position.X + dim.m_Width && m_Position.Y < dim.m_Position.Y + dim.m_Height && m_Position.X + m_Width > dim.m_Position.X && m_Position.Y + m_Height > dim.m_Position.Y;
}
public int GetHandArea()
{
if ( m_Position.X + m_Width > 150 && m_Position.X < 520 && m_Position.Y < 35 )
return 0;
if ( m_Position.X + m_Width > 635 && m_Position.Y + m_Height > 150 && m_Position.Y < 520 )
return 1;
if ( m_Position.X + m_Width > 150 && m_Position.X < 520 && m_Position.Y + m_Height > 635 )
return 2;
if ( m_Position.X < 35 && m_Position.Y + m_Height > 150 && m_Position.Y < 520 )
return 3;
return -1;
}
}
}

View file

@ -0,0 +1,552 @@
using System;
using System.Collections;
using Server;
namespace Server.Engines.Mahjong
{
public class MahjongPlayers
{
private MahjongGame m_Game;
private Mobile[] m_Players;
private bool[] m_InGame;
private bool[] m_PublicHand;
private int[] m_Scores;
private int m_DealerPosition;
private ArrayList m_Spectators;
public MahjongGame Game { get { return m_Game; } }
public int Seats { get { return m_Players.Length; } }
public Mobile Dealer { get { return m_Players[m_DealerPosition]; } }
public int DealerPosition { get { return m_DealerPosition; } }
public MahjongPlayers( MahjongGame game, int maxPlayers, int baseScore )
{
m_Game = game;
m_Spectators = new ArrayList();
m_Players = new Mobile[maxPlayers];
m_InGame = new bool[maxPlayers];
m_PublicHand = new bool[maxPlayers];
m_Scores = new int[maxPlayers];
for ( int i = 0; i < m_Scores.Length; i++ )
m_Scores[i] = baseScore;
}
public Mobile GetPlayer( int index )
{
if ( index < 0 || index >= m_Players.Length )
return null;
else
return m_Players[index];
}
public int GetPlayerIndex( Mobile mobile )
{
for ( int i = 0; i < m_Players.Length; i++ )
{
if ( m_Players[i] == mobile )
return i;
}
return -1;
}
public bool IsInGameDealer( Mobile mobile )
{
if ( Dealer != mobile )
return false;
else
return m_InGame[m_DealerPosition];
}
public bool IsInGamePlayer( int index )
{
if ( index < 0 || index >= m_Players.Length || m_Players[index] == null )
return false;
else
return m_InGame[index];
}
public bool IsInGamePlayer( Mobile mobile )
{
int index = GetPlayerIndex( mobile );
return IsInGamePlayer( index );
}
public bool IsSpectator( Mobile mobile )
{
return m_Spectators.Contains( mobile );
}
public int GetScore( int index )
{
if ( index < 0 || index >= m_Scores.Length )
return 0;
else
return m_Scores[index];
}
public bool IsPublic( int index )
{
if ( index < 0 || index >= m_PublicHand.Length )
return false;
else
return m_PublicHand[index];
}
public void SetPublic( int index, bool value )
{
if ( index < 0 || index >= m_PublicHand.Length || m_PublicHand[index] == value )
return;
m_PublicHand[index] = value;
SendTilesPacket( true, !m_Game.SpectatorVision );
if ( IsInGamePlayer( index ) )
m_Players[index].SendLocalizedMessage( value ? 1062775 : 1062776 ); // Your hand is [not] publicly viewable.
}
public ArrayList GetInGameMobiles( bool players, bool spectators )
{
ArrayList list = new ArrayList();
if ( players )
{
for ( int i = 0; i < m_Players.Length; i++ )
{
if ( IsInGamePlayer( i ) )
list.Add( m_Players[i] );
}
}
if ( spectators )
{
list.AddRange( m_Spectators );
}
return list;
}
public void CheckPlayers()
{
bool removed = false;
for ( int i = 0; i < m_Players.Length; i++ )
{
Mobile player = m_Players[i];
if ( player != null )
{
if ( player.Deleted )
{
m_Players[i] = null;
SendPlayerExitMessage( player );
UpdateDealer( true );
removed = true;
}
else if ( m_InGame[i] )
{
if ( player.NetState == null )
{
m_InGame[i] = false;
SendPlayerExitMessage( player );
UpdateDealer( true );
removed = true;
}
else if ( !m_Game.IsAccessibleTo( player ) || player.Map != m_Game.Map || !player.InRange( m_Game.GetWorldLocation(), 5 ) )
{
m_InGame[i] = false;
player.Send( new MahjongRelieve( m_Game ) );
SendPlayerExitMessage( player );
UpdateDealer( true );
removed = true;
}
}
}
}
for ( int i = 0; i < m_Spectators.Count; )
{
Mobile mobile = (Mobile)m_Spectators[i];
if ( mobile.NetState == null || mobile.Deleted )
{
m_Spectators.RemoveAt( i );
}
else if ( !m_Game.IsAccessibleTo( mobile ) || mobile.Map != m_Game.Map || !mobile.InRange( m_Game.GetWorldLocation(), 5 ) )
{
m_Spectators.RemoveAt( i );
mobile.Send( new MahjongRelieve( m_Game ) );
}
else
{
i++;
}
}
if ( removed && !UpdateSpectators() )
SendPlayersPacket( true, true );
}
private void UpdateDealer( bool message )
{
if ( IsInGamePlayer( m_DealerPosition ) )
return;
for ( int i = m_DealerPosition + 1; i < m_Players.Length; i++ )
{
if ( IsInGamePlayer( i ) )
{
m_DealerPosition = i;
if ( message )
SendDealerChangedMessage();
return;
}
}
for ( int i = 0; i < m_DealerPosition; i++ )
{
if ( IsInGamePlayer( i ) )
{
m_DealerPosition = i;
if ( message )
SendDealerChangedMessage();
return;
}
}
}
private int GetNextSeat()
{
for ( int i = m_DealerPosition; i < m_Players.Length; i++ )
{
if ( m_Players[i] == null )
return i;
}
for ( int i = 0; i < m_DealerPosition; i++ )
{
if ( m_Players[i] == null )
return i;
}
return -1;
}
private bool UpdateSpectators()
{
if ( m_Spectators.Count == 0 )
return false;
int nextSeat = GetNextSeat();
if ( nextSeat >= 0 )
{
Mobile newPlayer = (Mobile)m_Spectators[0];
m_Spectators.RemoveAt( 0 );
AddPlayer( newPlayer, nextSeat, false );
UpdateSpectators();
return true;
}
else
{
return false;
}
}
private void AddPlayer( Mobile player, int index, bool sendJoinGame )
{
m_Players[index] = player;
m_InGame[index] = true;
UpdateDealer( false );
if ( sendJoinGame )
player.Send( new MahjongJoinGame( m_Game ) );
SendPlayersPacket( true, true );
player.Send( new MahjongGeneralInfo( m_Game ) );
player.Send( new MahjongTilesInfo( m_Game, player ) );
if ( m_DealerPosition == index )
SendLocalizedMessage( 1062773, player.Name ); // ~1_name~ has entered the game as the dealer.
else
SendLocalizedMessage( 1062772, player.Name ); // ~1_name~ has entered the game as a player.
}
private void AddSpectator( Mobile mobile )
{
if ( !IsSpectator( mobile ) )
{
m_Spectators.Add( mobile );
}
mobile.Send( new MahjongJoinGame( m_Game ) );
mobile.Send( new MahjongPlayersInfo( m_Game, mobile ) );
mobile.Send( new MahjongGeneralInfo( m_Game ) );
mobile.Send( new MahjongTilesInfo( m_Game, mobile ) );
}
public void Join( Mobile mobile )
{
int index = GetPlayerIndex( mobile );
if ( index >= 0 )
{
AddPlayer( mobile, index, true );
}
else
{
int nextSeat = GetNextSeat();
if ( nextSeat >= 0 )
{
AddPlayer( mobile, nextSeat, true );
}
else
{
AddSpectator( mobile );
}
}
}
public void LeaveGame( Mobile player )
{
int index = GetPlayerIndex( player );
if ( index >= 0 )
{
m_InGame[index] = false;
SendPlayerExitMessage( player );
UpdateDealer( true );
SendPlayersPacket( true, true );
}
else
{
m_Spectators.Remove( player );
}
}
public void ResetScores( int value )
{
for ( int i = 0; i < m_Scores.Length; i++ )
{
m_Scores[i] = value;
}
SendPlayersPacket( true, m_Game.ShowScores );
SendLocalizedMessage( 1062697 ); // The dealer redistributes the score sticks evenly.
}
public void TransferScore( Mobile from, int toPosition, int amount )
{
int fromPosition = GetPlayerIndex( from );
Mobile to = GetPlayer( toPosition );
if ( fromPosition < 0 || to == null || m_Scores[fromPosition] < amount )
return;
m_Scores[fromPosition] -= amount;
m_Scores[toPosition] += amount;
if ( m_Game.ShowScores )
{
SendPlayersPacket( true, true );
}
else
{
from.Send( new MahjongPlayersInfo( m_Game, from ) );
to.Send( new MahjongPlayersInfo( m_Game, to ) );
}
SendLocalizedMessage( 1062774, string.Format( "{0}\t{1}\t{2}", from.Name, to.Name, amount ) ); // ~1_giver~ gives ~2_receiver~ ~3_number~ points.
}
public void OpenSeat( int index )
{
Mobile player = GetPlayer( index );
if ( player == null )
return;
if ( m_InGame[index] )
player.Send( new MahjongRelieve( m_Game ) );
m_Players[index] = null;
SendLocalizedMessage( 1062699, player.Name ); // ~1_name~ is relieved from the game by the dealer.
UpdateDealer( true );
if ( !UpdateSpectators() )
SendPlayersPacket( true, true );
}
public void AssignDealer( int index )
{
Mobile to = GetPlayer( index );
if ( to == null || !m_InGame[index] )
return;
int oldDealer = m_DealerPosition;
m_DealerPosition = index;
if ( IsInGamePlayer( oldDealer ) )
m_Players[oldDealer].Send( new MahjongPlayersInfo( m_Game, m_Players[oldDealer] ) );
to.Send( new MahjongPlayersInfo( m_Game, to ) );
SendDealerChangedMessage();
}
private void SendDealerChangedMessage()
{
if ( Dealer != null )
SendLocalizedMessage( 1062698, Dealer.Name ); // ~1_name~ is assigned the dealer.
}
private void SendPlayerExitMessage( Mobile who )
{
SendLocalizedMessage( 1062762, who.Name ); // ~1_name~ has left the game.
}
public void SendPlayersPacket( bool players, bool spectators )
{
foreach ( Mobile mobile in GetInGameMobiles( players, spectators ) )
{
mobile.Send( new MahjongPlayersInfo( m_Game, mobile ) );
}
}
public void SendGeneralPacket( bool players, bool spectators )
{
ArrayList mobiles = GetInGameMobiles( players, spectators );
if ( mobiles.Count == 0 )
return;
MahjongGeneralInfo generalInfo = new MahjongGeneralInfo( m_Game );
generalInfo.Acquire();
foreach ( Mobile mobile in mobiles )
{
mobile.Send( generalInfo );
}
generalInfo.Release();
}
public void SendTilesPacket( bool players, bool spectators )
{
foreach ( Mobile mobile in GetInGameMobiles( players, spectators ) )
{
mobile.Send( new MahjongTilesInfo( m_Game, mobile ) );
}
}
public void SendTilePacket( MahjongTile tile, bool players, bool spectators )
{
foreach ( Mobile mobile in GetInGameMobiles( players, spectators ) )
{
mobile.Send( new MahjongTileInfo( tile, mobile ) );
}
}
public void SendRelievePacket( bool players, bool spectators )
{
ArrayList mobiles = GetInGameMobiles( players, spectators );
if ( mobiles.Count == 0 )
return;
MahjongRelieve relieve = new MahjongRelieve( m_Game );
relieve.Acquire();
foreach ( Mobile mobile in mobiles )
{
mobile.Send( relieve );
}
relieve.Release();
}
public void SendLocalizedMessage( int number )
{
foreach ( Mobile mobile in GetInGameMobiles( true, true ) )
{
mobile.SendLocalizedMessage( number );
}
}
public void SendLocalizedMessage( int number, string args )
{
foreach ( Mobile mobile in GetInGameMobiles( true, true ) )
{
mobile.SendLocalizedMessage( number, args );
}
}
public void Save( GenericWriter writer )
{
writer.Write( (int) 0 ); // version
writer.Write( Seats );
for ( int i = 0; i < Seats; i++ )
{
writer.Write( m_Players[i] );
writer.Write( m_PublicHand[i] );
writer.Write( m_Scores[i] );
}
writer.Write( m_DealerPosition );
}
public MahjongPlayers( MahjongGame game, GenericReader reader )
{
m_Game = game;
m_Spectators = new ArrayList();
int version = reader.ReadInt();
int seats = reader.ReadInt();
m_Players = new Mobile[seats];
m_InGame = new bool[seats];
m_PublicHand = new bool[seats];
m_Scores = new int[seats];
for ( int i = 0; i < seats; i++ )
{
m_Players[i] = reader.ReadMobile();
m_PublicHand[i] = reader.ReadBool();
m_Scores[i] = reader.ReadInt();
}
m_DealerPosition = reader.ReadInt();
}
}
}

View file

@ -0,0 +1,97 @@
using System;
using Server;
namespace Server.Engines.Mahjong
{
public class MahjongTile
{
public static MahjongPieceDim GetDimensions( Point2D position, MahjongPieceDirection direction )
{
if ( direction == MahjongPieceDirection.Up || direction == MahjongPieceDirection.Down )
return new MahjongPieceDim( position, 20, 30 );
else
return new MahjongPieceDim( position, 30, 20 );
}
private MahjongGame m_Game;
private int m_Number;
private MahjongTileType m_Value;
protected Point2D m_Position;
private int m_StackLevel;
private MahjongPieceDirection m_Direction;
private bool m_Flipped;
public MahjongGame Game { get { return m_Game; } }
public int Number { get { return m_Number; } }
public MahjongTileType Value { get { return m_Value; } }
public Point2D Position { get { return m_Position; } }
public int StackLevel { get { return m_StackLevel; } }
public MahjongPieceDirection Direction { get { return m_Direction; } }
public bool Flipped { get { return m_Flipped; } }
public MahjongTile( MahjongGame game, int number, MahjongTileType value, Point2D position, int stackLevel, MahjongPieceDirection direction, bool flipped )
{
m_Game = game;
m_Number = number;
m_Value = value;
m_Position = position;
m_StackLevel = stackLevel;
m_Direction = direction;
m_Flipped = flipped;
}
public MahjongPieceDim Dimensions
{
get { return GetDimensions( m_Position, m_Direction ); }
}
public bool IsMovable
{
get { return m_Game.GetStackLevel( Dimensions ) <= m_StackLevel; }
}
public void Move( Point2D position, MahjongPieceDirection direction, bool flip, int validHandArea )
{
MahjongPieceDim dim = GetDimensions( position, direction );
int curHandArea = Dimensions.GetHandArea();
int newHandArea = dim.GetHandArea();
if ( !IsMovable || !dim.IsValid() || ( validHandArea >= 0 && ((curHandArea >= 0 && curHandArea != validHandArea) || (newHandArea >= 0 && newHandArea != validHandArea)) ) )
return;
m_Position = position;
m_Direction = direction;
m_StackLevel = -1; // Avoid self interference
m_StackLevel = m_Game.GetStackLevel( dim ) + 1;
m_Flipped = flip;
m_Game.Players.SendTilePacket( this, true, true );
}
public void Save( GenericWriter writer )
{
writer.Write( (int) 0 ); // version
writer.Write( m_Number );
writer.Write( (int) m_Value );
writer.Write( m_Position );
writer.Write( m_StackLevel );
writer.Write( (int) m_Direction );
writer.Write( m_Flipped );
}
public MahjongTile( MahjongGame game, GenericReader reader )
{
m_Game = game;
int version = reader.ReadInt();
m_Number = reader.ReadInt();
m_Value = (MahjongTileType) reader.ReadInt();
m_Position = reader.ReadPoint2D();
m_StackLevel = reader.ReadInt();
m_Direction = (MahjongPieceDirection) reader.ReadInt();
m_Flipped = reader.ReadBool();
}
}
}

View file

@ -0,0 +1,35 @@
using System;
using System.Collections;
using Server;
namespace Server.Engines.Mahjong
{
public class MahjongTileTypeGenerator
{
private ArrayList m_LeftTileTypes;
public ArrayList LeftTileTypes { get { return m_LeftTileTypes; } }
public MahjongTileTypeGenerator( int count )
{
m_LeftTileTypes = new ArrayList( 34 * count );
for ( int i = 1; i <= 34; i++ )
{
for ( int j = 0; j < count; j++ )
{
m_LeftTileTypes.Add( (MahjongTileType)i );
}
}
}
public MahjongTileType Next()
{
int random = Utility.Random( m_LeftTileTypes.Count );
MahjongTileType next = (MahjongTileType)m_LeftTileTypes[random];
m_LeftTileTypes.RemoveAt( random );
return next;
}
}
}

View file

@ -0,0 +1,58 @@
using System;
using Server;
namespace Server.Engines.Mahjong
{
public class MahjongWallBreakIndicator
{
public static MahjongPieceDim GetDimensions( Point2D position )
{
return new MahjongPieceDim( position, 20, 20 );
}
private MahjongGame m_Game;
private Point2D m_Position;
public MahjongGame Game { get { return m_Game; } }
public Point2D Position { get { return m_Position; } }
public MahjongWallBreakIndicator( MahjongGame game, Point2D position )
{
m_Game = game;
m_Position = position;
}
public MahjongPieceDim Dimensions
{
get { return GetDimensions( m_Position ); }
}
public void Move( Point2D position )
{
MahjongPieceDim dim = GetDimensions( position );
if ( !dim.IsValid() )
return;
m_Position = position;
m_Game.Players.SendGeneralPacket( true, true );
}
public void Save( GenericWriter writer )
{
writer.Write( (int) 0 ); // version
writer.Write( m_Position );
}
public MahjongWallBreakIndicator( MahjongGame game, GenericReader reader )
{
m_Game = game;
int version = reader.ReadInt();
m_Position = reader.ReadPoint2D();
}
}
}

View file

@ -0,0 +1,208 @@
using System;
using Server;
using Server.Network;
namespace Server.Engines.Mahjong
{
public sealed class MahjongJoinGame : Packet
{
public MahjongJoinGame( MahjongGame game ) : base( 0xDA )
{
EnsureCapacity( 9 );
m_Stream.Write( (int) game.Serial );
m_Stream.Write( (byte) 0 );
m_Stream.Write( (byte) 0x19 );
}
}
public sealed class MahjongPlayersInfo : Packet
{
public MahjongPlayersInfo( MahjongGame game, Mobile to ) : base( 0xDA )
{
MahjongPlayers players = game.Players;
EnsureCapacity( 11 + 45 * players.Seats );
m_Stream.Write( (int) game.Serial );
m_Stream.Write( (byte) 0 );
m_Stream.Write( (byte) 0x2 );
m_Stream.Write( (byte) 0 );
m_Stream.Write( (byte) players.Seats );
int n = 0;
for ( int i = 0; i < players.Seats; i++ )
{
Mobile mobile = players.GetPlayer( i );
if ( mobile != null )
{
m_Stream.Write( (int) mobile.Serial );
m_Stream.Write( players.DealerPosition == i ? (byte) 0x1 : (byte) 0x2 );
m_Stream.Write( (byte) i );
if ( game.ShowScores || mobile == to )
m_Stream.Write( (int) players.GetScore( i ) );
else
m_Stream.Write( (int) 0 );
m_Stream.Write( (short) 0 );
m_Stream.Write( (byte) 0 );
m_Stream.Write( players.IsPublic( i ) );
m_Stream.WriteAsciiFixed( mobile.Name, 30 );
m_Stream.Write( !players.IsInGamePlayer( i ) );
n++;
}
else if ( game.ShowScores )
{
m_Stream.Write( (int) 0 );
m_Stream.Write( (byte) 0x2 );
m_Stream.Write( (byte) i );
m_Stream.Write( (int) players.GetScore( i ) );
m_Stream.Write( (short) 0 );
m_Stream.Write( (byte) 0 );
m_Stream.Write( players.IsPublic( i ) );
m_Stream.WriteAsciiFixed( "", 30 );
m_Stream.Write( true );
n++;
}
}
if ( n != players.Seats )
{
m_Stream.Seek( 10, System.IO.SeekOrigin.Begin );
m_Stream.Write( (byte) n );
}
}
}
public sealed class MahjongGeneralInfo : Packet
{
public MahjongGeneralInfo( MahjongGame game ) : base( 0xDA )
{
EnsureCapacity( 13 );
m_Stream.Write( (int) game.Serial );
m_Stream.Write( (byte) 0 );
m_Stream.Write( (byte) 0x5 );
m_Stream.Write( (short) 0 );
m_Stream.Write( (byte) 0 );
m_Stream.Write( (byte) ((game.ShowScores ? 0x1 : 0x0) | (game.SpectatorVision ? 0x2 : 0x0)) );
m_Stream.Write( (byte) game.Dices.First );
m_Stream.Write( (byte) game.Dices.Second );
m_Stream.Write( (byte) game.DealerIndicator.Wind );
m_Stream.Write( (short) game.DealerIndicator.Position.Y );
m_Stream.Write( (short) game.DealerIndicator.Position.X );
m_Stream.Write( (byte) game.DealerIndicator.Direction );
m_Stream.Write( (short) game.WallBreakIndicator.Position.Y );
m_Stream.Write( (short) game.WallBreakIndicator.Position.X );
}
}
public sealed class MahjongTilesInfo : Packet
{
public MahjongTilesInfo( MahjongGame game, Mobile to ) : base( 0xDA )
{
MahjongTile[] tiles = game.Tiles;
MahjongPlayers players = game.Players;
EnsureCapacity( 11 + 9 * tiles.Length );
m_Stream.Write( (int) game.Serial );
m_Stream.Write( (byte) 0 );
m_Stream.Write( (byte) 0x4 );
m_Stream.Write( (short) tiles.Length );
foreach ( MahjongTile tile in tiles )
{
m_Stream.Write( (byte) tile.Number );
if ( tile.Flipped )
{
int hand = tile.Dimensions.GetHandArea();
if ( hand < 0 || players.IsPublic( hand ) || players.GetPlayer( hand ) == to || (game.SpectatorVision && players.IsSpectator( to )) )
m_Stream.Write( (byte)tile.Value );
else
m_Stream.Write( (byte) 0 );
}
else
{
m_Stream.Write( (byte) 0 );
}
m_Stream.Write( (short) tile.Position.Y );
m_Stream.Write( (short) tile.Position.X );
m_Stream.Write( (byte) tile.StackLevel );
m_Stream.Write( (byte) tile.Direction );
m_Stream.Write( tile.Flipped ? (byte) 0x10 : (byte) 0x0 );
}
}
}
public sealed class MahjongTileInfo : Packet
{
public MahjongTileInfo( MahjongTile tile, Mobile to ) : base( 0xDA )
{
MahjongGame game = tile.Game;
MahjongPlayers players = game.Players;
EnsureCapacity( 18 );
m_Stream.Write( (int) tile.Game.Serial );
m_Stream.Write( (byte) 0 );
m_Stream.Write( (byte) 0x3 );
m_Stream.Write( (byte) tile.Number );
if ( tile.Flipped )
{
int hand = tile.Dimensions.GetHandArea();
if ( hand < 0 || players.IsPublic( hand ) || players.GetPlayer( hand ) == to || (game.SpectatorVision && players.IsSpectator( to )) )
m_Stream.Write( (byte)tile.Value );
else
m_Stream.Write( (byte) 0 );
}
else
{
m_Stream.Write( (byte) 0 );
}
m_Stream.Write( (short) tile.Position.Y );
m_Stream.Write( (short) tile.Position.X );
m_Stream.Write( (byte) tile.StackLevel );
m_Stream.Write( (byte) tile.Direction );
m_Stream.Write( tile.Flipped ? (byte) 0x10 : (byte) 0x0 );
}
}
public sealed class MahjongRelieve : Packet
{
public MahjongRelieve( MahjongGame game ) : base( 0xDA )
{
EnsureCapacity( 9 );
m_Stream.Write( (int) game.Serial );
m_Stream.Write( (byte) 0 );
m_Stream.Write( (byte) 0x1A );
}
}
}