Fixes code according to modern code style. Fixes a few expression bugs.
This commit is contained in:
parent
89eea25e5f
commit
970fd563b2
3324 changed files with 441118 additions and 433755 deletions
|
|
@ -1,293 +1,298 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Server.ContextMenus;
|
||||
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;
|
||||
public class MahjongGame : Item, ISecurable
|
||||
{
|
||||
public const int MaxPlayers = 4;
|
||||
public const int BaseScore = 30000;
|
||||
private DateTime m_LastReset;
|
||||
|
||||
private bool m_ShowScores;
|
||||
private bool m_SpectatorVision;
|
||||
|
||||
[Constructible]
|
||||
public MahjongGame() : base(0xFAA)
|
||||
{
|
||||
Weight = 5.0;
|
||||
|
||||
BuildWalls();
|
||||
DealerIndicator =
|
||||
new MahjongDealerIndicator(this, new Point2D(300, 300), MahjongPieceDirection.Up, MahjongWind.North);
|
||||
WallBreakIndicator = new MahjongWallBreakIndicator(this, new Point2D(335, 335));
|
||||
Dices = new MahjongDices(this);
|
||||
Players = new MahjongPlayers(this, MaxPlayers, BaseScore);
|
||||
m_LastReset = DateTime.UtcNow;
|
||||
Level = SecureLevel.CoOwners;
|
||||
}
|
||||
|
||||
private bool m_ShowScores;
|
||||
private bool m_SpectatorVision;
|
||||
private DateTime m_LastReset;
|
||||
public MahjongGame(Serial serial) : base(serial)
|
||||
{
|
||||
}
|
||||
|
||||
public MahjongTile[] Tiles { get; private set; }
|
||||
public MahjongTile[] Tiles{ get; private set; }
|
||||
|
||||
public MahjongDealerIndicator DealerIndicator { get; private set; }
|
||||
public MahjongDealerIndicator DealerIndicator{ get; private set; }
|
||||
|
||||
public MahjongWallBreakIndicator WallBreakIndicator { get; private set; }
|
||||
public MahjongWallBreakIndicator WallBreakIndicator{ get; private set; }
|
||||
|
||||
public MahjongDices Dices { get; private set; }
|
||||
public MahjongDices Dices{ get; private set; }
|
||||
|
||||
public MahjongPlayers Players { get; private set; }
|
||||
public MahjongPlayers Players{ get; private set; }
|
||||
|
||||
[CommandProperty( AccessLevel.GameMaster )]
|
||||
public SecureLevel Level { get; set; }
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public bool ShowScores
|
||||
{
|
||||
get => m_ShowScores;
|
||||
set
|
||||
{
|
||||
if (m_ShowScores == value)
|
||||
return;
|
||||
|
||||
[CommandProperty( AccessLevel.GameMaster )]
|
||||
public bool ShowScores
|
||||
{
|
||||
get => m_ShowScores;
|
||||
set
|
||||
{
|
||||
if ( m_ShowScores == value )
|
||||
return;
|
||||
m_ShowScores = value;
|
||||
|
||||
m_ShowScores = value;
|
||||
if (value)
|
||||
Players.SendPlayersPacket(true, true);
|
||||
|
||||
if ( value )
|
||||
Players.SendPlayersPacket( true, true );
|
||||
Players.SendGeneralPacket(true, true);
|
||||
|
||||
Players.SendGeneralPacket( true, true );
|
||||
Players.SendLocalizedMessage(value ? 1062777 : 1062778); // The dealer has enabled/disabled score display.
|
||||
}
|
||||
}
|
||||
|
||||
Players.SendLocalizedMessage( value ? 1062777 : 1062778 ); // The dealer has enabled/disabled score display.
|
||||
}
|
||||
}
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public bool SpectatorVision
|
||||
{
|
||||
get => m_SpectatorVision;
|
||||
set
|
||||
{
|
||||
if (m_SpectatorVision == value)
|
||||
return;
|
||||
|
||||
[CommandProperty( AccessLevel.GameMaster )]
|
||||
public bool SpectatorVision
|
||||
{
|
||||
get => m_SpectatorVision;
|
||||
set
|
||||
{
|
||||
if ( m_SpectatorVision == value )
|
||||
return;
|
||||
m_SpectatorVision = value;
|
||||
|
||||
m_SpectatorVision = value;
|
||||
if (Players.IsInGamePlayer(Players.DealerPosition))
|
||||
Players.Dealer.Send(new MahjongGeneralInfo(this));
|
||||
|
||||
if ( Players.IsInGamePlayer( Players.DealerPosition ) )
|
||||
Players.Dealer.Send( new MahjongGeneralInfo( this ) );
|
||||
Players.SendTilesPacket(false, true);
|
||||
|
||||
Players.SendTilesPacket( false, true );
|
||||
Players.SendLocalizedMessage(value ? 1062715 : 1062716); // The dealer has enabled/disabled Spectator Vision.
|
||||
|
||||
Players.SendLocalizedMessage( value ? 1062715 : 1062716 ); // The dealer has enabled/disabled Spectator Vision.
|
||||
InvalidateProperties();
|
||||
}
|
||||
}
|
||||
|
||||
InvalidateProperties();
|
||||
}
|
||||
}
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public SecureLevel Level{ get; set; }
|
||||
|
||||
[Constructible]
|
||||
public MahjongGame() : base( 0xFAA )
|
||||
{
|
||||
Weight = 5.0;
|
||||
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);
|
||||
Tiles[index + i] = new MahjongTile(this, index + i, typeGenerator.Next(), position, stackLevel, direction,
|
||||
false);
|
||||
}
|
||||
|
||||
BuildWalls();
|
||||
DealerIndicator = new MahjongDealerIndicator( this, new Point2D( 300, 300 ), MahjongPieceDirection.Up, MahjongWind.North );
|
||||
WallBreakIndicator = new MahjongWallBreakIndicator( this, new Point2D( 335, 335 ) );
|
||||
Dices = new MahjongDices( this );
|
||||
Players = new MahjongPlayers( this, MaxPlayers, BaseScore );
|
||||
m_LastReset = DateTime.UtcNow;
|
||||
Level = SecureLevel.CoOwners;
|
||||
}
|
||||
index += 17;
|
||||
}
|
||||
|
||||
public MahjongGame( Serial serial ) : base( serial )
|
||||
{
|
||||
}
|
||||
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);
|
||||
Tiles[index + i] = new MahjongTile(this, index + i, typeGenerator.Next(), position, stackLevel, direction,
|
||||
false);
|
||||
}
|
||||
|
||||
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 );
|
||||
Tiles[index + i] = new MahjongTile( this, index + i, typeGenerator.Next(), position, stackLevel, direction, false );
|
||||
}
|
||||
index += 17;
|
||||
}
|
||||
|
||||
index += 17;
|
||||
}
|
||||
private void BuildWalls()
|
||||
{
|
||||
Tiles = new MahjongTile[17 * 8];
|
||||
|
||||
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 );
|
||||
Tiles[index + i] = new MahjongTile( this, index + i, typeGenerator.Next(), position, stackLevel, direction, false );
|
||||
}
|
||||
MahjongTileTypeGenerator typeGenerator = new MahjongTileTypeGenerator(4);
|
||||
|
||||
index += 17;
|
||||
}
|
||||
int i = 0;
|
||||
|
||||
private void BuildWalls()
|
||||
{
|
||||
Tiles = new MahjongTile[17 * 8];
|
||||
BuildHorizontalWall(ref i, 165, 110, 0, MahjongPieceDirection.Up, typeGenerator);
|
||||
BuildHorizontalWall(ref i, 165, 115, 1, MahjongPieceDirection.Up, typeGenerator);
|
||||
|
||||
MahjongTileTypeGenerator typeGenerator = new MahjongTileTypeGenerator( 4 );
|
||||
BuildVerticalWall(ref i, 530, 165, 0, MahjongPieceDirection.Left, typeGenerator);
|
||||
BuildVerticalWall(ref i, 525, 165, 1, MahjongPieceDirection.Left, typeGenerator);
|
||||
|
||||
int i = 0;
|
||||
BuildHorizontalWall(ref i, 165, 530, 0, MahjongPieceDirection.Down, typeGenerator);
|
||||
BuildHorizontalWall(ref i, 165, 525, 1, MahjongPieceDirection.Down, typeGenerator);
|
||||
|
||||
BuildHorizontalWall( ref i, 165, 110, 0, MahjongPieceDirection.Up, typeGenerator );
|
||||
BuildHorizontalWall( ref i, 165, 115, 1, MahjongPieceDirection.Up, typeGenerator );
|
||||
BuildVerticalWall(ref i, 110, 165, 0, MahjongPieceDirection.Right, typeGenerator);
|
||||
BuildVerticalWall(ref i, 115, 165, 1, MahjongPieceDirection.Right, typeGenerator);
|
||||
}
|
||||
|
||||
BuildVerticalWall( ref i, 530, 165, 0, MahjongPieceDirection.Left, typeGenerator );
|
||||
BuildVerticalWall( ref i, 525, 165, 1, MahjongPieceDirection.Left, typeGenerator );
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
BuildHorizontalWall( ref i, 165, 530, 0, MahjongPieceDirection.Down, typeGenerator );
|
||||
BuildHorizontalWall( ref i, 165, 525, 1, MahjongPieceDirection.Down, typeGenerator );
|
||||
if (m_SpectatorVision)
|
||||
list.Add(1062717); // Spectator Vision Enabled
|
||||
else
|
||||
list.Add(1062718); // Spectator Vision Disabled
|
||||
}
|
||||
|
||||
BuildVerticalWall( ref i, 110, 165, 0, MahjongPieceDirection.Right, typeGenerator );
|
||||
BuildVerticalWall( ref i, 115, 165, 1, MahjongPieceDirection.Right, typeGenerator );
|
||||
}
|
||||
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list)
|
||||
{
|
||||
base.GetContextMenuEntries(from, list);
|
||||
|
||||
public override void GetProperties( ObjectPropertyList list )
|
||||
{
|
||||
base.GetProperties( list );
|
||||
Players.CheckPlayers();
|
||||
|
||||
if ( m_SpectatorVision )
|
||||
list.Add( 1062717 ); // Spectator Vision Enabled
|
||||
else
|
||||
list.Add( 1062718 ); // Spectator Vision Disabled
|
||||
}
|
||||
if (from.Alive && IsAccessibleTo(from) && Players.GetInGameMobiles(true, false).Count == 0)
|
||||
list.Add(new ResetGameEntry(this));
|
||||
|
||||
public override void GetContextMenuEntries( Mobile from, List<ContextMenuEntry> list )
|
||||
{
|
||||
base.GetContextMenuEntries( from, list );
|
||||
SetSecureLevelEntry.AddTo(from, this, list);
|
||||
}
|
||||
|
||||
Players.CheckPlayers();
|
||||
public override void OnDoubleClick(Mobile from)
|
||||
{
|
||||
Players.CheckPlayers();
|
||||
|
||||
if ( from.Alive && IsAccessibleTo( from ) && Players.GetInGameMobiles( true, false ).Count == 0 )
|
||||
list.Add( new ResetGameEntry( this ) );
|
||||
Players.Join(from);
|
||||
}
|
||||
|
||||
SetSecureLevelEntry.AddTo( from, this, list );
|
||||
}
|
||||
public void ResetGame(Mobile from)
|
||||
{
|
||||
if (DateTime.UtcNow - m_LastReset < TimeSpan.FromSeconds(5.0))
|
||||
return;
|
||||
|
||||
private class ResetGameEntry : ContextMenuEntry
|
||||
{
|
||||
private MahjongGame m_Game;
|
||||
m_LastReset = DateTime.UtcNow;
|
||||
|
||||
public ResetGameEntry( MahjongGame game ) : base( 6162 )
|
||||
{
|
||||
m_Game = game;
|
||||
}
|
||||
if (from != null)
|
||||
Players.SendLocalizedMessage(1062771, from.Name); // ~1_name~ has reset the game.
|
||||
|
||||
public override void OnClick()
|
||||
{
|
||||
Mobile from = Owner.From;
|
||||
Players.SendRelievePacket(true, true);
|
||||
|
||||
if ( from.CheckAlive() && !m_Game.Deleted && m_Game.IsAccessibleTo( from ) && m_Game.Players.GetInGameMobiles( true, false ).Count == 0 )
|
||||
m_Game.ResetGame( from );
|
||||
}
|
||||
}
|
||||
BuildWalls();
|
||||
DealerIndicator =
|
||||
new MahjongDealerIndicator(this, new Point2D(300, 300), MahjongPieceDirection.Up, MahjongWind.North);
|
||||
WallBreakIndicator = new MahjongWallBreakIndicator(this, new Point2D(335, 335));
|
||||
Players = new MahjongPlayers(this, MaxPlayers, BaseScore);
|
||||
}
|
||||
|
||||
public override void OnDoubleClick( Mobile from )
|
||||
{
|
||||
Players.CheckPlayers();
|
||||
public void ResetWalls(Mobile from)
|
||||
{
|
||||
if (DateTime.UtcNow - m_LastReset < TimeSpan.FromSeconds(5.0))
|
||||
return;
|
||||
|
||||
Players.Join( from );
|
||||
}
|
||||
m_LastReset = DateTime.UtcNow;
|
||||
|
||||
public void ResetGame( Mobile from )
|
||||
{
|
||||
if ( DateTime.UtcNow - m_LastReset < TimeSpan.FromSeconds( 5.0 ) )
|
||||
return;
|
||||
BuildWalls();
|
||||
|
||||
m_LastReset = DateTime.UtcNow;
|
||||
Players.SendTilesPacket(true, true);
|
||||
|
||||
if ( from != null )
|
||||
Players.SendLocalizedMessage( 1062771, from.Name ); // ~1_name~ has reset the game.
|
||||
if (from != null)
|
||||
Players.SendLocalizedMessage(1062696); // The dealer rebuilds the wall.
|
||||
}
|
||||
|
||||
Players.SendRelievePacket( true, true );
|
||||
public int GetStackLevel(MahjongPieceDim dim)
|
||||
{
|
||||
int level = -1;
|
||||
foreach (MahjongTile tile in Tiles)
|
||||
if (tile.StackLevel > level && dim.IsOverlapping(tile.Dimensions))
|
||||
level = tile.StackLevel;
|
||||
return level;
|
||||
}
|
||||
|
||||
BuildWalls();
|
||||
DealerIndicator = new MahjongDealerIndicator( this, new Point2D( 300, 300 ), MahjongPieceDirection.Up, MahjongWind.North );
|
||||
WallBreakIndicator = new MahjongWallBreakIndicator( this, new Point2D( 335, 335 ) );
|
||||
Players = new MahjongPlayers( this, MaxPlayers, BaseScore );
|
||||
}
|
||||
public override void Serialize(GenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
public void ResetWalls( Mobile from )
|
||||
{
|
||||
if ( DateTime.UtcNow - m_LastReset < TimeSpan.FromSeconds( 5.0 ) )
|
||||
return;
|
||||
writer.Write(1); // version
|
||||
|
||||
m_LastReset = DateTime.UtcNow;
|
||||
writer.Write((int)Level);
|
||||
|
||||
BuildWalls();
|
||||
writer.Write(Tiles.Length);
|
||||
|
||||
Players.SendTilesPacket( true, true );
|
||||
for (int i = 0; i < Tiles.Length; i++)
|
||||
Tiles[i].Save(writer);
|
||||
|
||||
if ( from != null )
|
||||
Players.SendLocalizedMessage( 1062696 ); // The dealer rebuilds the wall.
|
||||
}
|
||||
DealerIndicator.Save(writer);
|
||||
|
||||
public int GetStackLevel( MahjongPieceDim dim )
|
||||
{
|
||||
int level = -1;
|
||||
foreach ( MahjongTile tile in Tiles )
|
||||
{
|
||||
if ( tile.StackLevel > level && dim.IsOverlapping( tile.Dimensions ) )
|
||||
level = tile.StackLevel;
|
||||
}
|
||||
return level;
|
||||
}
|
||||
WallBreakIndicator.Save(writer);
|
||||
|
||||
public override void Serialize( GenericWriter writer )
|
||||
{
|
||||
base.Serialize( writer );
|
||||
Dices.Save(writer);
|
||||
|
||||
writer.Write( (int) 1 ); // version
|
||||
Players.Save(writer);
|
||||
|
||||
writer.Write( (int) Level );
|
||||
writer.Write(m_ShowScores);
|
||||
writer.Write(m_SpectatorVision);
|
||||
}
|
||||
|
||||
writer.Write( Tiles.Length );
|
||||
public override void Deserialize(GenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
for ( int i = 0; i < Tiles.Length; i++ )
|
||||
Tiles[i].Save( writer );
|
||||
int version = reader.ReadInt();
|
||||
|
||||
DealerIndicator.Save( writer );
|
||||
switch (version)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
Level = (SecureLevel)reader.ReadInt();
|
||||
|
||||
WallBreakIndicator.Save( writer );
|
||||
goto case 0;
|
||||
}
|
||||
case 0:
|
||||
{
|
||||
if (version < 1)
|
||||
Level = SecureLevel.CoOwners;
|
||||
|
||||
Dices.Save( writer );
|
||||
int length = reader.ReadInt();
|
||||
Tiles = new MahjongTile[length];
|
||||
|
||||
Players.Save( writer );
|
||||
for (int i = 0; i < length; i++)
|
||||
Tiles[i] = new MahjongTile(this, reader);
|
||||
|
||||
writer.Write( m_ShowScores );
|
||||
writer.Write( m_SpectatorVision );
|
||||
}
|
||||
DealerIndicator = new MahjongDealerIndicator(this, reader);
|
||||
|
||||
public override void Deserialize( GenericReader reader )
|
||||
{
|
||||
base.Deserialize( reader );
|
||||
WallBreakIndicator = new MahjongWallBreakIndicator(this, reader);
|
||||
|
||||
int version = reader.ReadInt();
|
||||
Dices = new MahjongDices(this, reader);
|
||||
|
||||
switch ( version )
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
Level = (SecureLevel)reader.ReadInt();
|
||||
Players = new MahjongPlayers(this, reader);
|
||||
|
||||
goto case 0;
|
||||
}
|
||||
case 0:
|
||||
{
|
||||
if ( version < 1 )
|
||||
Level = SecureLevel.CoOwners;
|
||||
m_ShowScores = reader.ReadBool();
|
||||
m_SpectatorVision = reader.ReadBool();
|
||||
|
||||
int length = reader.ReadInt();
|
||||
Tiles = new MahjongTile[length];
|
||||
m_LastReset = DateTime.UtcNow;
|
||||
|
||||
for ( int i = 0; i < length; i++ )
|
||||
Tiles[i] = new MahjongTile( this, reader );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DealerIndicator = new MahjongDealerIndicator( this, reader );
|
||||
private class ResetGameEntry : ContextMenuEntry
|
||||
{
|
||||
private MahjongGame m_Game;
|
||||
|
||||
WallBreakIndicator = new MahjongWallBreakIndicator( this, reader );
|
||||
public ResetGameEntry(MahjongGame game) : base(6162)
|
||||
{
|
||||
m_Game = game;
|
||||
}
|
||||
|
||||
Dices = new MahjongDices( this, reader );
|
||||
public override void OnClick()
|
||||
{
|
||||
Mobile from = Owner.From;
|
||||
|
||||
Players = new MahjongPlayers( this, reader );
|
||||
|
||||
m_ShowScores = reader.ReadBool();
|
||||
m_SpectatorVision = reader.ReadBool();
|
||||
|
||||
m_LastReset = DateTime.UtcNow;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (from.CheckAlive() && !m_Game.Deleted && m_Game.IsAccessibleTo(from) &&
|
||||
m_Game.Players.GetInGameMobiles(true, false).Count == 0)
|
||||
m_Game.ResetGame(from);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue