Overwrite
Complete Overwrite of the Folder with the free shard. ServUO 57.3 has been added.
This commit is contained in:
96
Scripts/Items/Containers/Mahjong/MahjongDealerIndicator.cs
Normal file
96
Scripts/Items/Containers/Mahjong/MahjongDealerIndicator.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
|
||||
namespace Server.Engines.Mahjong
|
||||
{
|
||||
public class MahjongDealerIndicator
|
||||
{
|
||||
private readonly MahjongGame m_Game;
|
||||
private Point2D m_Position;
|
||||
private MahjongPieceDirection m_Direction;
|
||||
private MahjongWind m_Wind;
|
||||
public MahjongDealerIndicator(MahjongGame game, Point2D position, MahjongPieceDirection direction, MahjongWind wind)
|
||||
{
|
||||
this.m_Game = game;
|
||||
this.m_Position = position;
|
||||
this.m_Direction = direction;
|
||||
this.m_Wind = wind;
|
||||
}
|
||||
|
||||
public MahjongDealerIndicator(MahjongGame game, GenericReader reader)
|
||||
{
|
||||
this.m_Game = game;
|
||||
|
||||
int version = reader.ReadInt();
|
||||
|
||||
this.m_Position = reader.ReadPoint2D();
|
||||
this.m_Direction = (MahjongPieceDirection)reader.ReadInt();
|
||||
this.m_Wind = (MahjongWind)reader.ReadInt();
|
||||
}
|
||||
|
||||
public MahjongGame Game
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Game;
|
||||
}
|
||||
}
|
||||
public Point2D Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Position;
|
||||
}
|
||||
}
|
||||
public MahjongPieceDirection Direction
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Direction;
|
||||
}
|
||||
}
|
||||
public MahjongWind Wind
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Wind;
|
||||
}
|
||||
}
|
||||
public MahjongPieceDim Dimensions
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetDimensions(this.m_Position, this.m_Direction);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
public void Move(Point2D position, MahjongPieceDirection direction, MahjongWind wind)
|
||||
{
|
||||
MahjongPieceDim dim = GetDimensions(position, direction);
|
||||
|
||||
if (!dim.IsValid())
|
||||
return;
|
||||
|
||||
this.m_Position = position;
|
||||
this.m_Direction = direction;
|
||||
this.m_Wind = wind;
|
||||
|
||||
this.m_Game.Players.SendGeneralPacket(true, true);
|
||||
}
|
||||
|
||||
public void Save(GenericWriter writer)
|
||||
{
|
||||
writer.Write((int)0); // version
|
||||
|
||||
writer.Write(this.m_Position);
|
||||
writer.Write((int)this.m_Direction);
|
||||
writer.Write((int)this.m_Wind);
|
||||
}
|
||||
}
|
||||
}
|
||||
67
Scripts/Items/Containers/Mahjong/MahjongDices.cs
Normal file
67
Scripts/Items/Containers/Mahjong/MahjongDices.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
|
||||
namespace Server.Engines.Mahjong
|
||||
{
|
||||
public class MahjongDices
|
||||
{
|
||||
private readonly MahjongGame m_Game;
|
||||
private int m_First;
|
||||
private int m_Second;
|
||||
public MahjongDices(MahjongGame game)
|
||||
{
|
||||
this.m_Game = game;
|
||||
this.m_First = Utility.Random(1, 6);
|
||||
this.m_Second = Utility.Random(1, 6);
|
||||
}
|
||||
|
||||
public MahjongDices(MahjongGame game, GenericReader reader)
|
||||
{
|
||||
this.m_Game = game;
|
||||
|
||||
int version = reader.ReadInt();
|
||||
|
||||
this.m_First = reader.ReadInt();
|
||||
this.m_Second = reader.ReadInt();
|
||||
}
|
||||
|
||||
public MahjongGame Game
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Game;
|
||||
}
|
||||
}
|
||||
public int First
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_First;
|
||||
}
|
||||
}
|
||||
public int Second
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Second;
|
||||
}
|
||||
}
|
||||
public void RollDices(Mobile from)
|
||||
{
|
||||
this.m_First = Utility.Random(1, 6);
|
||||
this.m_Second = Utility.Random(1, 6);
|
||||
|
||||
this.m_Game.Players.SendGeneralPacket(true, true);
|
||||
|
||||
if (from != null)
|
||||
this.m_Game.Players.SendLocalizedMessage(1062695, string.Format("{0}\t{1}\t{2}", from.Name, this.m_First, this.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(this.m_First);
|
||||
writer.Write(this.m_Second);
|
||||
}
|
||||
}
|
||||
}
|
||||
58
Scripts/Items/Containers/Mahjong/MahjongEnums.cs
Normal file
58
Scripts/Items/Containers/Mahjong/MahjongEnums.cs
Normal 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
|
||||
}
|
||||
}
|
||||
337
Scripts/Items/Containers/Mahjong/MahjongGame.cs
Normal file
337
Scripts/Items/Containers/Mahjong/MahjongGame.cs
Normal file
@@ -0,0 +1,337 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Server.ContextMenus;
|
||||
using Server.Gumps;
|
||||
using Server.Multis;
|
||||
|
||||
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;
|
||||
private SecureLevel m_Level;
|
||||
[Constructable]
|
||||
public MahjongGame()
|
||||
: base(0xFAA)
|
||||
{
|
||||
this.Weight = 5.0;
|
||||
|
||||
this.BuildWalls();
|
||||
this.m_DealerIndicator = new MahjongDealerIndicator(this, new Point2D(300, 300), MahjongPieceDirection.Up, MahjongWind.North);
|
||||
this.m_WallBreakIndicator = new MahjongWallBreakIndicator(this, new Point2D(335, 335));
|
||||
this.m_Dices = new MahjongDices(this);
|
||||
this.m_Players = new MahjongPlayers(this, MaxPlayers, BaseScore);
|
||||
this.m_LastReset = DateTime.UtcNow;
|
||||
this.m_Level = SecureLevel.CoOwners;
|
||||
}
|
||||
|
||||
public MahjongGame(Serial serial)
|
||||
: base(serial)
|
||||
{
|
||||
}
|
||||
|
||||
public MahjongTile[] Tiles
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Tiles;
|
||||
}
|
||||
}
|
||||
public MahjongDealerIndicator DealerIndicator
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_DealerIndicator;
|
||||
}
|
||||
}
|
||||
public MahjongWallBreakIndicator WallBreakIndicator
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_WallBreakIndicator;
|
||||
}
|
||||
}
|
||||
public MahjongDices Dices
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Dices;
|
||||
}
|
||||
}
|
||||
public MahjongPlayers Players
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Players;
|
||||
}
|
||||
}
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public SecureLevel Level
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Level;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.m_Level = value;
|
||||
}
|
||||
}
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public bool ShowScores
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_ShowScores;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (this.m_ShowScores == value)
|
||||
return;
|
||||
|
||||
this.m_ShowScores = value;
|
||||
|
||||
if (value)
|
||||
this.m_Players.SendPlayersPacket(true, true);
|
||||
|
||||
this.m_Players.SendGeneralPacket(true, true);
|
||||
|
||||
this.m_Players.SendLocalizedMessage(value ? 1062777 : 1062778); // The dealer has enabled/disabled score display.
|
||||
}
|
||||
}
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public bool SpectatorVision
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_SpectatorVision;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (this.m_SpectatorVision == value)
|
||||
return;
|
||||
|
||||
this.m_SpectatorVision = value;
|
||||
|
||||
if (this.m_Players.IsInGamePlayer(this.m_Players.DealerPosition))
|
||||
this.m_Players.Dealer.Send(new MahjongGeneralInfo(this));
|
||||
|
||||
this.m_Players.SendTilesPacket(false, true);
|
||||
|
||||
this.m_Players.SendLocalizedMessage(value ? 1062715 : 1062716); // The dealer has enabled/disabled Spectator Vision.
|
||||
|
||||
this.InvalidateProperties();
|
||||
}
|
||||
}
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
if (this.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);
|
||||
|
||||
this.m_Players.CheckPlayers();
|
||||
|
||||
if (from.Alive && this.IsAccessibleTo(from) && this.m_Players.GetInGameMobiles(true, false).Count == 0)
|
||||
list.Add(new ResetGameEntry(this));
|
||||
|
||||
SetSecureLevelEntry.AddTo(from, this, list);
|
||||
}
|
||||
|
||||
public override void OnDoubleClick(Mobile from)
|
||||
{
|
||||
this.m_Players.CheckPlayers();
|
||||
|
||||
this.m_Players.Join(from);
|
||||
}
|
||||
|
||||
public void ResetGame(Mobile from)
|
||||
{
|
||||
if (DateTime.UtcNow - this.m_LastReset < TimeSpan.FromSeconds(5.0))
|
||||
return;
|
||||
|
||||
this.m_LastReset = DateTime.UtcNow;
|
||||
|
||||
if (from != null)
|
||||
this.m_Players.SendLocalizedMessage(1062771, from.Name); // ~1_name~ has reset the game.
|
||||
|
||||
this.m_Players.SendRelievePacket(true, true);
|
||||
|
||||
this.BuildWalls();
|
||||
this.m_DealerIndicator = new MahjongDealerIndicator(this, new Point2D(300, 300), MahjongPieceDirection.Up, MahjongWind.North);
|
||||
this.m_WallBreakIndicator = new MahjongWallBreakIndicator(this, new Point2D(335, 335));
|
||||
this.m_Players = new MahjongPlayers(this, MaxPlayers, BaseScore);
|
||||
}
|
||||
|
||||
public void ResetWalls(Mobile from)
|
||||
{
|
||||
if (DateTime.UtcNow - this.m_LastReset < TimeSpan.FromSeconds(5.0))
|
||||
return;
|
||||
|
||||
this.m_LastReset = DateTime.UtcNow;
|
||||
|
||||
this.BuildWalls();
|
||||
|
||||
this.m_Players.SendTilesPacket(true, true);
|
||||
|
||||
if (from != null)
|
||||
this.m_Players.SendLocalizedMessage(1062696); // The dealer rebuilds the wall.
|
||||
}
|
||||
|
||||
public int GetStackLevel(MahjongPieceDim dim)
|
||||
{
|
||||
int level = -1;
|
||||
foreach (MahjongTile tile in this.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)this.m_Level);
|
||||
|
||||
writer.Write(this.m_Tiles.Length);
|
||||
|
||||
for (int i = 0; i < this.m_Tiles.Length; i++)
|
||||
this.m_Tiles[i].Save(writer);
|
||||
|
||||
this.m_DealerIndicator.Save(writer);
|
||||
|
||||
this.m_WallBreakIndicator.Save(writer);
|
||||
|
||||
this.m_Dices.Save(writer);
|
||||
|
||||
this.m_Players.Save(writer);
|
||||
|
||||
writer.Write(this.m_ShowScores);
|
||||
writer.Write(this.m_SpectatorVision);
|
||||
}
|
||||
|
||||
public override void Deserialize(GenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
int version = reader.ReadInt();
|
||||
|
||||
switch ( version )
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
this.m_Level = (SecureLevel)reader.ReadInt();
|
||||
|
||||
goto case 0;
|
||||
}
|
||||
case 0:
|
||||
{
|
||||
if (version < 1)
|
||||
this.m_Level = SecureLevel.CoOwners;
|
||||
|
||||
int length = reader.ReadInt();
|
||||
this.m_Tiles = new MahjongTile[length];
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
this.m_Tiles[i] = new MahjongTile(this, reader);
|
||||
|
||||
this.m_DealerIndicator = new MahjongDealerIndicator(this, reader);
|
||||
|
||||
this.m_WallBreakIndicator = new MahjongWallBreakIndicator(this, reader);
|
||||
|
||||
this.m_Dices = new MahjongDices(this, reader);
|
||||
|
||||
this.m_Players = new MahjongPlayers(this, reader);
|
||||
|
||||
this.m_ShowScores = reader.ReadBool();
|
||||
this.m_SpectatorVision = reader.ReadBool();
|
||||
|
||||
this.m_LastReset = DateTime.UtcNow;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
this.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);
|
||||
this.m_Tiles[index + i] = new MahjongTile(this, index + i, typeGenerator.Next(), position, stackLevel, direction, false);
|
||||
}
|
||||
|
||||
index += 17;
|
||||
}
|
||||
|
||||
private void BuildWalls()
|
||||
{
|
||||
this.m_Tiles = new MahjongTile[17 * 8];
|
||||
|
||||
MahjongTileTypeGenerator typeGenerator = new MahjongTileTypeGenerator(4);
|
||||
|
||||
int i = 0;
|
||||
|
||||
this.BuildHorizontalWall(ref i, 165, 110, 0, MahjongPieceDirection.Up, typeGenerator);
|
||||
this.BuildHorizontalWall(ref i, 165, 115, 1, MahjongPieceDirection.Up, typeGenerator);
|
||||
|
||||
this.BuildVerticalWall(ref i, 530, 165, 0, MahjongPieceDirection.Left, typeGenerator);
|
||||
this.BuildVerticalWall(ref i, 525, 165, 1, MahjongPieceDirection.Left, typeGenerator);
|
||||
|
||||
this.BuildHorizontalWall(ref i, 165, 530, 0, MahjongPieceDirection.Down, typeGenerator);
|
||||
this.BuildHorizontalWall(ref i, 165, 525, 1, MahjongPieceDirection.Down, typeGenerator);
|
||||
|
||||
this.BuildVerticalWall(ref i, 110, 165, 0, MahjongPieceDirection.Right, typeGenerator);
|
||||
this.BuildVerticalWall(ref i, 115, 165, 1, MahjongPieceDirection.Right, typeGenerator);
|
||||
}
|
||||
|
||||
private class ResetGameEntry : ContextMenuEntry
|
||||
{
|
||||
private readonly MahjongGame m_Game;
|
||||
public ResetGameEntry(MahjongGame game)
|
||||
: base(6162)
|
||||
{
|
||||
this.m_Game = game;
|
||||
}
|
||||
|
||||
public override void OnClick()
|
||||
{
|
||||
Mobile from = this.Owner.From;
|
||||
|
||||
if (from.CheckAlive() && !this.m_Game.Deleted && this.m_Game.IsAccessibleTo(from) && this.m_Game.Players.GetInGameMobiles(true, false).Count == 0)
|
||||
this.m_Game.ResetGame(from);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
251
Scripts/Items/Containers/Mahjong/MahjongPacketHandlers.cs
Normal file
251
Scripts/Items/Containers/Mahjong/MahjongPacketHandlers.cs
Normal file
@@ -0,0 +1,251 @@
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Engines.Mahjong
|
||||
{
|
||||
public delegate void OnMahjongPacketReceive(MahjongGame game, NetState state, PacketReader pvSrc);
|
||||
|
||||
public sealed class MahjongPacketHandlers
|
||||
{
|
||||
private static readonly 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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
65
Scripts/Items/Containers/Mahjong/MahjongPieceDim.cs
Normal file
65
Scripts/Items/Containers/Mahjong/MahjongPieceDim.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
|
||||
namespace Server.Engines.Mahjong
|
||||
{
|
||||
public struct MahjongPieceDim
|
||||
{
|
||||
private readonly Point2D m_Position;
|
||||
private readonly int m_Width;
|
||||
private readonly int m_Height;
|
||||
public MahjongPieceDim(Point2D position, int width, int height)
|
||||
{
|
||||
this.m_Position = position;
|
||||
this.m_Width = width;
|
||||
this.m_Height = height;
|
||||
}
|
||||
|
||||
public Point2D Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Position;
|
||||
}
|
||||
}
|
||||
public int Width
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Width;
|
||||
}
|
||||
}
|
||||
public int Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Height;
|
||||
}
|
||||
}
|
||||
public bool IsValid()
|
||||
{
|
||||
return this.m_Position.X >= 0 && this.m_Position.Y >= 0 && this.m_Position.X + this.m_Width <= 670 && this.m_Position.Y + this.m_Height <= 670;
|
||||
}
|
||||
|
||||
public bool IsOverlapping(MahjongPieceDim dim)
|
||||
{
|
||||
return this.m_Position.X < dim.m_Position.X + dim.m_Width && this.m_Position.Y < dim.m_Position.Y + dim.m_Height && this.m_Position.X + this.m_Width > dim.m_Position.X && this.m_Position.Y + this.m_Height > dim.m_Position.Y;
|
||||
}
|
||||
|
||||
public int GetHandArea()
|
||||
{
|
||||
if (this.m_Position.X + this.m_Width > 150 && this.m_Position.X < 520 && this.m_Position.Y < 35)
|
||||
return 0;
|
||||
|
||||
if (this.m_Position.X + this.m_Width > 635 && this.m_Position.Y + this.m_Height > 150 && this.m_Position.Y < 520)
|
||||
return 1;
|
||||
|
||||
if (this.m_Position.X + this.m_Width > 150 && this.m_Position.X < 520 && this.m_Position.Y + this.m_Height > 635)
|
||||
return 2;
|
||||
|
||||
if (this.m_Position.X < 35 && this.m_Position.Y + this.m_Height > 150 && this.m_Position.Y < 520)
|
||||
return 3;
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
573
Scripts/Items/Containers/Mahjong/MahjongPlayers.cs
Normal file
573
Scripts/Items/Containers/Mahjong/MahjongPlayers.cs
Normal file
@@ -0,0 +1,573 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace Server.Engines.Mahjong
|
||||
{
|
||||
public class MahjongPlayers
|
||||
{
|
||||
private readonly MahjongGame m_Game;
|
||||
private readonly Mobile[] m_Players;
|
||||
private readonly bool[] m_InGame;
|
||||
private readonly bool[] m_PublicHand;
|
||||
private readonly int[] m_Scores;
|
||||
private readonly ArrayList m_Spectators;
|
||||
private int m_DealerPosition;
|
||||
public MahjongPlayers(MahjongGame game, int maxPlayers, int baseScore)
|
||||
{
|
||||
this.m_Game = game;
|
||||
this.m_Spectators = new ArrayList();
|
||||
|
||||
this.m_Players = new Mobile[maxPlayers];
|
||||
this.m_InGame = new bool[maxPlayers];
|
||||
this.m_PublicHand = new bool[maxPlayers];
|
||||
this.m_Scores = new int[maxPlayers];
|
||||
|
||||
for (int i = 0; i < this.m_Scores.Length; i++)
|
||||
this.m_Scores[i] = baseScore;
|
||||
}
|
||||
|
||||
public MahjongPlayers(MahjongGame game, GenericReader reader)
|
||||
{
|
||||
this.m_Game = game;
|
||||
this.m_Spectators = new ArrayList();
|
||||
|
||||
int version = reader.ReadInt();
|
||||
|
||||
int seats = reader.ReadInt();
|
||||
this.m_Players = new Mobile[seats];
|
||||
this.m_InGame = new bool[seats];
|
||||
this.m_PublicHand = new bool[seats];
|
||||
this.m_Scores = new int[seats];
|
||||
|
||||
for (int i = 0; i < seats; i++)
|
||||
{
|
||||
this.m_Players[i] = reader.ReadMobile();
|
||||
this.m_PublicHand[i] = reader.ReadBool();
|
||||
this.m_Scores[i] = reader.ReadInt();
|
||||
}
|
||||
|
||||
this.m_DealerPosition = reader.ReadInt();
|
||||
}
|
||||
|
||||
public MahjongGame Game
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Game;
|
||||
}
|
||||
}
|
||||
public int Seats
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Players.Length;
|
||||
}
|
||||
}
|
||||
public Mobile Dealer
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Players[this.m_DealerPosition];
|
||||
}
|
||||
}
|
||||
public int DealerPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_DealerPosition;
|
||||
}
|
||||
}
|
||||
public Mobile GetPlayer(int index)
|
||||
{
|
||||
if (index < 0 || index >= this.m_Players.Length)
|
||||
return null;
|
||||
else
|
||||
return this.m_Players[index];
|
||||
}
|
||||
|
||||
public int GetPlayerIndex(Mobile mobile)
|
||||
{
|
||||
for (int i = 0; i < this.m_Players.Length; i++)
|
||||
{
|
||||
if (this.m_Players[i] == mobile)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public bool IsInGameDealer(Mobile mobile)
|
||||
{
|
||||
if (this.Dealer != mobile)
|
||||
return false;
|
||||
else
|
||||
return this.m_InGame[this.m_DealerPosition];
|
||||
}
|
||||
|
||||
public bool IsInGamePlayer(int index)
|
||||
{
|
||||
if (index < 0 || index >= this.m_Players.Length || this.m_Players[index] == null)
|
||||
return false;
|
||||
else
|
||||
return this.m_InGame[index];
|
||||
}
|
||||
|
||||
public bool IsInGamePlayer(Mobile mobile)
|
||||
{
|
||||
int index = this.GetPlayerIndex(mobile);
|
||||
|
||||
return this.IsInGamePlayer(index);
|
||||
}
|
||||
|
||||
public bool IsSpectator(Mobile mobile)
|
||||
{
|
||||
return this.m_Spectators.Contains(mobile);
|
||||
}
|
||||
|
||||
public int GetScore(int index)
|
||||
{
|
||||
if (index < 0 || index >= this.m_Scores.Length)
|
||||
return 0;
|
||||
else
|
||||
return this.m_Scores[index];
|
||||
}
|
||||
|
||||
public bool IsPublic(int index)
|
||||
{
|
||||
if (index < 0 || index >= this.m_PublicHand.Length)
|
||||
return false;
|
||||
else
|
||||
return this.m_PublicHand[index];
|
||||
}
|
||||
|
||||
public void SetPublic(int index, bool value)
|
||||
{
|
||||
if (index < 0 || index >= this.m_PublicHand.Length || this.m_PublicHand[index] == value)
|
||||
return;
|
||||
|
||||
this.m_PublicHand[index] = value;
|
||||
|
||||
this.SendTilesPacket(true, !this.m_Game.SpectatorVision);
|
||||
|
||||
if (this.IsInGamePlayer(index))
|
||||
this.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 < this.m_Players.Length; i++)
|
||||
{
|
||||
if (this.IsInGamePlayer(i))
|
||||
list.Add(this.m_Players[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (spectators)
|
||||
{
|
||||
list.AddRange(this.m_Spectators);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public void CheckPlayers()
|
||||
{
|
||||
bool removed = false;
|
||||
|
||||
for (int i = 0; i < this.m_Players.Length; i++)
|
||||
{
|
||||
Mobile player = this.m_Players[i];
|
||||
|
||||
if (player != null)
|
||||
{
|
||||
if (player.Deleted)
|
||||
{
|
||||
this.m_Players[i] = null;
|
||||
|
||||
this.SendPlayerExitMessage(player);
|
||||
this.UpdateDealer(true);
|
||||
|
||||
removed = true;
|
||||
}
|
||||
else if (this.m_InGame[i])
|
||||
{
|
||||
if (player.NetState == null)
|
||||
{
|
||||
this.m_InGame[i] = false;
|
||||
|
||||
this.SendPlayerExitMessage(player);
|
||||
this.UpdateDealer(true);
|
||||
|
||||
removed = true;
|
||||
}
|
||||
else if (!this.m_Game.IsAccessibleTo(player) || player.Map != this.m_Game.Map || !player.InRange(this.m_Game.GetWorldLocation(), 5))
|
||||
{
|
||||
this.m_InGame[i] = false;
|
||||
|
||||
player.Send(new MahjongRelieve(this.m_Game));
|
||||
|
||||
this.SendPlayerExitMessage(player);
|
||||
this.UpdateDealer(true);
|
||||
|
||||
removed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.m_Spectators.Count;)
|
||||
{
|
||||
Mobile mobile = (Mobile)this.m_Spectators[i];
|
||||
|
||||
if (mobile.NetState == null || mobile.Deleted)
|
||||
{
|
||||
this.m_Spectators.RemoveAt(i);
|
||||
}
|
||||
else if (!this.m_Game.IsAccessibleTo(mobile) || mobile.Map != this.m_Game.Map || !mobile.InRange(this.m_Game.GetWorldLocation(), 5))
|
||||
{
|
||||
this.m_Spectators.RemoveAt(i);
|
||||
|
||||
mobile.Send(new MahjongRelieve(this.m_Game));
|
||||
}
|
||||
else
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (removed && !this.UpdateSpectators())
|
||||
this.SendPlayersPacket(true, true);
|
||||
}
|
||||
|
||||
public void Join(Mobile mobile)
|
||||
{
|
||||
int index = this.GetPlayerIndex(mobile);
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
this.AddPlayer(mobile, index, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
int nextSeat = this.GetNextSeat();
|
||||
|
||||
if (nextSeat >= 0)
|
||||
{
|
||||
this.AddPlayer(mobile, nextSeat, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.AddSpectator(mobile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void LeaveGame(Mobile player)
|
||||
{
|
||||
int index = this.GetPlayerIndex(player);
|
||||
if (index >= 0)
|
||||
{
|
||||
this.m_InGame[index] = false;
|
||||
|
||||
this.SendPlayerExitMessage(player);
|
||||
this.UpdateDealer(true);
|
||||
|
||||
this.SendPlayersPacket(true, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.m_Spectators.Remove(player);
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetScores(int value)
|
||||
{
|
||||
for (int i = 0; i < this.m_Scores.Length; i++)
|
||||
{
|
||||
this.m_Scores[i] = value;
|
||||
}
|
||||
|
||||
this.SendPlayersPacket(true, this.m_Game.ShowScores);
|
||||
|
||||
this.SendLocalizedMessage(1062697); // The dealer redistributes the score sticks evenly.
|
||||
}
|
||||
|
||||
public void TransferScore(Mobile from, int toPosition, int amount)
|
||||
{
|
||||
int fromPosition = this.GetPlayerIndex(from);
|
||||
Mobile to = this.GetPlayer(toPosition);
|
||||
|
||||
if (fromPosition < 0 || to == null || this.m_Scores[fromPosition] < amount)
|
||||
return;
|
||||
|
||||
this.m_Scores[fromPosition] -= amount;
|
||||
this.m_Scores[toPosition] += amount;
|
||||
|
||||
if (this.m_Game.ShowScores)
|
||||
{
|
||||
this.SendPlayersPacket(true, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
from.Send(new MahjongPlayersInfo(this.m_Game, from));
|
||||
to.Send(new MahjongPlayersInfo(this.m_Game, to));
|
||||
}
|
||||
|
||||
this.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 = this.GetPlayer(index);
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
if (this.m_InGame[index])
|
||||
player.Send(new MahjongRelieve(this.m_Game));
|
||||
|
||||
this.m_Players[index] = null;
|
||||
|
||||
this.SendLocalizedMessage(1062699, player.Name); // ~1_name~ is relieved from the game by the dealer.
|
||||
|
||||
this.UpdateDealer(true);
|
||||
|
||||
if (!this.UpdateSpectators())
|
||||
this.SendPlayersPacket(true, true);
|
||||
}
|
||||
|
||||
public void AssignDealer(int index)
|
||||
{
|
||||
Mobile to = this.GetPlayer(index);
|
||||
|
||||
if (to == null || !this.m_InGame[index])
|
||||
return;
|
||||
|
||||
int oldDealer = this.m_DealerPosition;
|
||||
|
||||
this.m_DealerPosition = index;
|
||||
|
||||
if (this.IsInGamePlayer(oldDealer))
|
||||
this.m_Players[oldDealer].Send(new MahjongPlayersInfo(this.m_Game, this.m_Players[oldDealer]));
|
||||
|
||||
to.Send(new MahjongPlayersInfo(this.m_Game, to));
|
||||
|
||||
this.SendDealerChangedMessage();
|
||||
}
|
||||
|
||||
public void SendPlayersPacket(bool players, bool spectators)
|
||||
{
|
||||
foreach (Mobile mobile in this.GetInGameMobiles(players, spectators))
|
||||
{
|
||||
mobile.Send(new MahjongPlayersInfo(this.m_Game, mobile));
|
||||
}
|
||||
}
|
||||
|
||||
public void SendGeneralPacket(bool players, bool spectators)
|
||||
{
|
||||
ArrayList mobiles = this.GetInGameMobiles(players, spectators);
|
||||
|
||||
if (mobiles.Count == 0)
|
||||
return;
|
||||
|
||||
MahjongGeneralInfo generalInfo = new MahjongGeneralInfo(this.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 this.GetInGameMobiles(players, spectators))
|
||||
{
|
||||
mobile.Send(new MahjongTilesInfo(this.m_Game, mobile));
|
||||
}
|
||||
}
|
||||
|
||||
public void SendTilePacket(MahjongTile tile, bool players, bool spectators)
|
||||
{
|
||||
foreach (Mobile mobile in this.GetInGameMobiles(players, spectators))
|
||||
{
|
||||
mobile.Send(new MahjongTileInfo(tile, mobile));
|
||||
}
|
||||
}
|
||||
|
||||
public void SendRelievePacket(bool players, bool spectators)
|
||||
{
|
||||
ArrayList mobiles = this.GetInGameMobiles(players, spectators);
|
||||
|
||||
if (mobiles.Count == 0)
|
||||
return;
|
||||
|
||||
MahjongRelieve relieve = new MahjongRelieve(this.m_Game);
|
||||
|
||||
relieve.Acquire();
|
||||
|
||||
foreach (Mobile mobile in mobiles)
|
||||
{
|
||||
mobile.Send(relieve);
|
||||
}
|
||||
|
||||
relieve.Release();
|
||||
}
|
||||
|
||||
public void SendLocalizedMessage(int number)
|
||||
{
|
||||
foreach (Mobile mobile in this.GetInGameMobiles(true, true))
|
||||
{
|
||||
mobile.SendLocalizedMessage(number);
|
||||
}
|
||||
}
|
||||
|
||||
public void SendLocalizedMessage(int number, string args)
|
||||
{
|
||||
foreach (Mobile mobile in this.GetInGameMobiles(true, true))
|
||||
{
|
||||
mobile.SendLocalizedMessage(number, args);
|
||||
}
|
||||
}
|
||||
|
||||
public void Save(GenericWriter writer)
|
||||
{
|
||||
writer.Write((int)0); // version
|
||||
|
||||
writer.Write(this.Seats);
|
||||
|
||||
for (int i = 0; i < this.Seats; i++)
|
||||
{
|
||||
writer.Write(this.m_Players[i]);
|
||||
writer.Write(this.m_PublicHand[i]);
|
||||
writer.Write(this.m_Scores[i]);
|
||||
}
|
||||
|
||||
writer.Write(this.m_DealerPosition);
|
||||
}
|
||||
|
||||
private void UpdateDealer(bool message)
|
||||
{
|
||||
if (this.IsInGamePlayer(this.m_DealerPosition))
|
||||
return;
|
||||
|
||||
for (int i = this.m_DealerPosition + 1; i < this.m_Players.Length; i++)
|
||||
{
|
||||
if (this.IsInGamePlayer(i))
|
||||
{
|
||||
this.m_DealerPosition = i;
|
||||
|
||||
if (message)
|
||||
this.SendDealerChangedMessage();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.m_DealerPosition; i++)
|
||||
{
|
||||
if (this.IsInGamePlayer(i))
|
||||
{
|
||||
this.m_DealerPosition = i;
|
||||
|
||||
if (message)
|
||||
this.SendDealerChangedMessage();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int GetNextSeat()
|
||||
{
|
||||
for (int i = this.m_DealerPosition; i < this.m_Players.Length; i++)
|
||||
{
|
||||
if (this.m_Players[i] == null)
|
||||
return i;
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.m_DealerPosition; i++)
|
||||
{
|
||||
if (this.m_Players[i] == null)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private bool UpdateSpectators()
|
||||
{
|
||||
if (this.m_Spectators.Count == 0)
|
||||
return false;
|
||||
|
||||
int nextSeat = this.GetNextSeat();
|
||||
|
||||
if (nextSeat >= 0)
|
||||
{
|
||||
Mobile newPlayer = (Mobile)this.m_Spectators[0];
|
||||
|
||||
this.m_Spectators.RemoveAt(0);
|
||||
|
||||
this.AddPlayer(newPlayer, nextSeat, false);
|
||||
|
||||
this.UpdateSpectators();
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void AddPlayer(Mobile player, int index, bool sendJoinGame)
|
||||
{
|
||||
this.m_Players[index] = player;
|
||||
this.m_InGame[index] = true;
|
||||
|
||||
this.UpdateDealer(false);
|
||||
|
||||
if (sendJoinGame)
|
||||
player.Send(new MahjongJoinGame(this.m_Game));
|
||||
|
||||
this.SendPlayersPacket(true, true);
|
||||
|
||||
player.Send(new MahjongGeneralInfo(this.m_Game));
|
||||
player.Send(new MahjongTilesInfo(this.m_Game, player));
|
||||
|
||||
if (this.m_DealerPosition == index)
|
||||
this.SendLocalizedMessage(1062773, player.Name); // ~1_name~ has entered the game as the dealer.
|
||||
else
|
||||
this.SendLocalizedMessage(1062772, player.Name); // ~1_name~ has entered the game as a player.
|
||||
}
|
||||
|
||||
private void AddSpectator(Mobile mobile)
|
||||
{
|
||||
if (!this.IsSpectator(mobile))
|
||||
{
|
||||
this.m_Spectators.Add(mobile);
|
||||
}
|
||||
|
||||
mobile.Send(new MahjongJoinGame(this.m_Game));
|
||||
mobile.Send(new MahjongPlayersInfo(this.m_Game, mobile));
|
||||
mobile.Send(new MahjongGeneralInfo(this.m_Game));
|
||||
mobile.Send(new MahjongTilesInfo(this.m_Game, mobile));
|
||||
}
|
||||
|
||||
private void SendDealerChangedMessage()
|
||||
{
|
||||
if (this.Dealer != null)
|
||||
this.SendLocalizedMessage(1062698, this.Dealer.Name); // ~1_name~ is assigned the dealer.
|
||||
}
|
||||
|
||||
private void SendPlayerExitMessage(Mobile who)
|
||||
{
|
||||
this.SendLocalizedMessage(1062762, who.Name); // ~1_name~ has left the game.
|
||||
}
|
||||
}
|
||||
}
|
||||
140
Scripts/Items/Containers/Mahjong/MahjongTile.cs
Normal file
140
Scripts/Items/Containers/Mahjong/MahjongTile.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
using System;
|
||||
|
||||
namespace Server.Engines.Mahjong
|
||||
{
|
||||
public class MahjongTile
|
||||
{
|
||||
protected Point2D m_Position;
|
||||
private readonly MahjongGame m_Game;
|
||||
private readonly int m_Number;
|
||||
private readonly MahjongTileType m_Value;
|
||||
private int m_StackLevel;
|
||||
private MahjongPieceDirection m_Direction;
|
||||
private bool m_Flipped;
|
||||
public MahjongTile(MahjongGame game, int number, MahjongTileType value, Point2D position, int stackLevel, MahjongPieceDirection direction, bool flipped)
|
||||
{
|
||||
this.m_Game = game;
|
||||
this.m_Number = number;
|
||||
this.m_Value = value;
|
||||
this.m_Position = position;
|
||||
this.m_StackLevel = stackLevel;
|
||||
this.m_Direction = direction;
|
||||
this.m_Flipped = flipped;
|
||||
}
|
||||
|
||||
public MahjongTile(MahjongGame game, GenericReader reader)
|
||||
{
|
||||
this.m_Game = game;
|
||||
|
||||
int version = reader.ReadInt();
|
||||
|
||||
this.m_Number = reader.ReadInt();
|
||||
this.m_Value = (MahjongTileType)reader.ReadInt();
|
||||
this.m_Position = reader.ReadPoint2D();
|
||||
this.m_StackLevel = reader.ReadInt();
|
||||
this.m_Direction = (MahjongPieceDirection)reader.ReadInt();
|
||||
this.m_Flipped = reader.ReadBool();
|
||||
}
|
||||
|
||||
public MahjongGame Game
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Game;
|
||||
}
|
||||
}
|
||||
public int Number
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Number;
|
||||
}
|
||||
}
|
||||
public MahjongTileType Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Value;
|
||||
}
|
||||
}
|
||||
public Point2D Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Position;
|
||||
}
|
||||
}
|
||||
public int StackLevel
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_StackLevel;
|
||||
}
|
||||
}
|
||||
public MahjongPieceDirection Direction
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Direction;
|
||||
}
|
||||
}
|
||||
public bool Flipped
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Flipped;
|
||||
}
|
||||
}
|
||||
public MahjongPieceDim Dimensions
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetDimensions(this.m_Position, this.m_Direction);
|
||||
}
|
||||
}
|
||||
public bool IsMovable
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Game.GetStackLevel(this.Dimensions) <= this.m_StackLevel;
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
public void Move(Point2D position, MahjongPieceDirection direction, bool flip, int validHandArea)
|
||||
{
|
||||
MahjongPieceDim dim = GetDimensions(position, direction);
|
||||
int curHandArea = this.Dimensions.GetHandArea();
|
||||
int newHandArea = dim.GetHandArea();
|
||||
|
||||
if (!this.IsMovable || !dim.IsValid() || (validHandArea >= 0 && ((curHandArea >= 0 && curHandArea != validHandArea) || (newHandArea >= 0 && newHandArea != validHandArea))))
|
||||
return;
|
||||
|
||||
this.m_Position = position;
|
||||
this.m_Direction = direction;
|
||||
this.m_StackLevel = -1; // Avoid self interference
|
||||
this.m_StackLevel = this.m_Game.GetStackLevel(dim) + 1;
|
||||
this.m_Flipped = flip;
|
||||
|
||||
this.m_Game.Players.SendTilePacket(this, true, true);
|
||||
}
|
||||
|
||||
public void Save(GenericWriter writer)
|
||||
{
|
||||
writer.Write((int)0); // version
|
||||
|
||||
writer.Write(this.m_Number);
|
||||
writer.Write((int)this.m_Value);
|
||||
writer.Write(this.m_Position);
|
||||
writer.Write(this.m_StackLevel);
|
||||
writer.Write((int)this.m_Direction);
|
||||
writer.Write(this.m_Flipped);
|
||||
}
|
||||
}
|
||||
}
|
||||
38
Scripts/Items/Containers/Mahjong/MahjongTileTypeGenerator.cs
Normal file
38
Scripts/Items/Containers/Mahjong/MahjongTileTypeGenerator.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace Server.Engines.Mahjong
|
||||
{
|
||||
public class MahjongTileTypeGenerator
|
||||
{
|
||||
private readonly ArrayList m_LeftTileTypes;
|
||||
public MahjongTileTypeGenerator(int count)
|
||||
{
|
||||
this.m_LeftTileTypes = new ArrayList(34 * count);
|
||||
|
||||
for (int i = 1; i <= 34; i++)
|
||||
{
|
||||
for (int j = 0; j < count; j++)
|
||||
{
|
||||
this.m_LeftTileTypes.Add((MahjongTileType)i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList LeftTileTypes
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_LeftTileTypes;
|
||||
}
|
||||
}
|
||||
public MahjongTileType Next()
|
||||
{
|
||||
int random = Utility.Random(this.m_LeftTileTypes.Count);
|
||||
MahjongTileType next = (MahjongTileType)this.m_LeftTileTypes[random];
|
||||
this.m_LeftTileTypes.RemoveAt(random);
|
||||
|
||||
return next;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
|
||||
namespace Server.Engines.Mahjong
|
||||
{
|
||||
public class MahjongWallBreakIndicator
|
||||
{
|
||||
private readonly MahjongGame m_Game;
|
||||
private Point2D m_Position;
|
||||
public MahjongWallBreakIndicator(MahjongGame game, Point2D position)
|
||||
{
|
||||
this.m_Game = game;
|
||||
this.m_Position = position;
|
||||
}
|
||||
|
||||
public MahjongWallBreakIndicator(MahjongGame game, GenericReader reader)
|
||||
{
|
||||
this.m_Game = game;
|
||||
|
||||
int version = reader.ReadInt();
|
||||
|
||||
this.m_Position = reader.ReadPoint2D();
|
||||
}
|
||||
|
||||
public MahjongGame Game
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Game;
|
||||
}
|
||||
}
|
||||
public Point2D Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_Position;
|
||||
}
|
||||
}
|
||||
public MahjongPieceDim Dimensions
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetDimensions(this.m_Position);
|
||||
}
|
||||
}
|
||||
public static MahjongPieceDim GetDimensions(Point2D position)
|
||||
{
|
||||
return new MahjongPieceDim(position, 20, 20);
|
||||
}
|
||||
|
||||
public void Move(Point2D position)
|
||||
{
|
||||
MahjongPieceDim dim = GetDimensions(position);
|
||||
|
||||
if (!dim.IsValid())
|
||||
return;
|
||||
|
||||
this.m_Position = position;
|
||||
|
||||
this.m_Game.Players.SendGeneralPacket(true, true);
|
||||
}
|
||||
|
||||
public void Save(GenericWriter writer)
|
||||
{
|
||||
writer.Write((int)0); // version
|
||||
|
||||
writer.Write(this.m_Position);
|
||||
}
|
||||
}
|
||||
}
|
||||
213
Scripts/Items/Containers/Mahjong/Packets.cs
Normal file
213
Scripts/Items/Containers/Mahjong/Packets.cs
Normal file
@@ -0,0 +1,213 @@
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Engines.Mahjong
|
||||
{
|
||||
public sealed class MahjongJoinGame : Packet
|
||||
{
|
||||
public MahjongJoinGame(MahjongGame game)
|
||||
: base(0xDA)
|
||||
{
|
||||
this.EnsureCapacity(9);
|
||||
|
||||
this.m_Stream.Write((int)game.Serial);
|
||||
this.m_Stream.Write((byte)0);
|
||||
this.m_Stream.Write((byte)0x19);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MahjongPlayersInfo : Packet
|
||||
{
|
||||
public MahjongPlayersInfo(MahjongGame game, Mobile to)
|
||||
: base(0xDA)
|
||||
{
|
||||
MahjongPlayers players = game.Players;
|
||||
|
||||
this.EnsureCapacity(11 + 45 * players.Seats);
|
||||
|
||||
this.m_Stream.Write((int)game.Serial);
|
||||
this.m_Stream.Write((byte)0);
|
||||
this.m_Stream.Write((byte)0x2);
|
||||
|
||||
this.m_Stream.Write((byte)0);
|
||||
this.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)
|
||||
{
|
||||
this.m_Stream.Write((int)mobile.Serial);
|
||||
this.m_Stream.Write(players.DealerPosition == i ? (byte)0x1 : (byte)0x2);
|
||||
this.m_Stream.Write((byte)i);
|
||||
|
||||
if (game.ShowScores || mobile == to)
|
||||
this.m_Stream.Write((int)players.GetScore(i));
|
||||
else
|
||||
this.m_Stream.Write((int)0);
|
||||
|
||||
this.m_Stream.Write((short)0);
|
||||
this.m_Stream.Write((byte)0);
|
||||
|
||||
this.m_Stream.Write(players.IsPublic(i));
|
||||
|
||||
this.m_Stream.WriteAsciiFixed(mobile.Name, 30);
|
||||
this.m_Stream.Write(!players.IsInGamePlayer(i));
|
||||
|
||||
n++;
|
||||
}
|
||||
else if (game.ShowScores)
|
||||
{
|
||||
this.m_Stream.Write((int)0);
|
||||
this.m_Stream.Write((byte)0x2);
|
||||
this.m_Stream.Write((byte)i);
|
||||
|
||||
this.m_Stream.Write((int)players.GetScore(i));
|
||||
|
||||
this.m_Stream.Write((short)0);
|
||||
this.m_Stream.Write((byte)0);
|
||||
|
||||
this.m_Stream.Write(players.IsPublic(i));
|
||||
|
||||
this.m_Stream.WriteAsciiFixed("", 30);
|
||||
this.m_Stream.Write(true);
|
||||
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
if (n != players.Seats)
|
||||
{
|
||||
this.m_Stream.Seek(10, System.IO.SeekOrigin.Begin);
|
||||
this.m_Stream.Write((byte)n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MahjongGeneralInfo : Packet
|
||||
{
|
||||
public MahjongGeneralInfo(MahjongGame game)
|
||||
: base(0xDA)
|
||||
{
|
||||
this.EnsureCapacity(13);
|
||||
|
||||
this.m_Stream.Write((int)game.Serial);
|
||||
this.m_Stream.Write((byte)0);
|
||||
this.m_Stream.Write((byte)0x5);
|
||||
|
||||
this.m_Stream.Write((short)0);
|
||||
this.m_Stream.Write((byte)0);
|
||||
|
||||
this.m_Stream.Write((byte)((game.ShowScores ? 0x1 : 0x0) | (game.SpectatorVision ? 0x2 : 0x0)));
|
||||
|
||||
this.m_Stream.Write((byte)game.Dices.First);
|
||||
this.m_Stream.Write((byte)game.Dices.Second);
|
||||
|
||||
this.m_Stream.Write((byte)game.DealerIndicator.Wind);
|
||||
this.m_Stream.Write((short)game.DealerIndicator.Position.Y);
|
||||
this.m_Stream.Write((short)game.DealerIndicator.Position.X);
|
||||
this.m_Stream.Write((byte)game.DealerIndicator.Direction);
|
||||
|
||||
this.m_Stream.Write((short)game.WallBreakIndicator.Position.Y);
|
||||
this.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;
|
||||
|
||||
this.EnsureCapacity(11 + 9 * tiles.Length);
|
||||
|
||||
this.m_Stream.Write((int)game.Serial);
|
||||
this.m_Stream.Write((byte)0);
|
||||
this.m_Stream.Write((byte)0x4);
|
||||
|
||||
this.m_Stream.Write((short)tiles.Length);
|
||||
|
||||
foreach (MahjongTile tile in tiles)
|
||||
{
|
||||
this.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)))
|
||||
this.m_Stream.Write((byte)tile.Value);
|
||||
else
|
||||
this.m_Stream.Write((byte)0);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.m_Stream.Write((byte)0);
|
||||
}
|
||||
|
||||
this.m_Stream.Write((short)tile.Position.Y);
|
||||
this.m_Stream.Write((short)tile.Position.X);
|
||||
this.m_Stream.Write((byte)tile.StackLevel);
|
||||
this.m_Stream.Write((byte)tile.Direction);
|
||||
|
||||
this.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;
|
||||
|
||||
this.EnsureCapacity(18);
|
||||
|
||||
this.m_Stream.Write((int)tile.Game.Serial);
|
||||
this.m_Stream.Write((byte)0);
|
||||
this.m_Stream.Write((byte)0x3);
|
||||
|
||||
this.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)))
|
||||
this.m_Stream.Write((byte)tile.Value);
|
||||
else
|
||||
this.m_Stream.Write((byte)0);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.m_Stream.Write((byte)0);
|
||||
}
|
||||
|
||||
this.m_Stream.Write((short)tile.Position.Y);
|
||||
this.m_Stream.Write((short)tile.Position.X);
|
||||
this.m_Stream.Write((byte)tile.StackLevel);
|
||||
this.m_Stream.Write((byte)tile.Direction);
|
||||
|
||||
this.m_Stream.Write(tile.Flipped ? (byte)0x10 : (byte)0x0);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MahjongRelieve : Packet
|
||||
{
|
||||
public MahjongRelieve(MahjongGame game)
|
||||
: base(0xDA)
|
||||
{
|
||||
this.EnsureCapacity(9);
|
||||
|
||||
this.m_Stream.Write((int)game.Serial);
|
||||
this.m_Stream.Write((byte)0);
|
||||
this.m_Stream.Write((byte)0x1A);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user