Reorganizes Project (#41)
This commit is contained in:
parent
08bf44af9a
commit
3614a66aee
3499 changed files with 79 additions and 55 deletions
88
Projects/Scripts/Items/Games/Mahjong/MahjongTile.cs
Normal file
88
Projects/Scripts/Items/Games/Mahjong/MahjongTile.cs
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
namespace Server.Engines.Mahjong
|
||||
{
|
||||
public class MahjongTile
|
||||
{
|
||||
protected Point2D m_Position;
|
||||
|
||||
public MahjongTile(MahjongGame game, int number, MahjongTileType value, Point2D position, int stackLevel,
|
||||
MahjongPieceDirection direction, bool flipped)
|
||||
{
|
||||
Game = game;
|
||||
Number = number;
|
||||
Value = value;
|
||||
m_Position = position;
|
||||
StackLevel = stackLevel;
|
||||
Direction = direction;
|
||||
Flipped = flipped;
|
||||
}
|
||||
|
||||
public MahjongTile(MahjongGame game, GenericReader reader)
|
||||
{
|
||||
Game = game;
|
||||
|
||||
int version = reader.ReadInt();
|
||||
|
||||
Number = reader.ReadInt();
|
||||
Value = (MahjongTileType)reader.ReadInt();
|
||||
m_Position = reader.ReadPoint2D();
|
||||
StackLevel = reader.ReadInt();
|
||||
Direction = (MahjongPieceDirection)reader.ReadInt();
|
||||
Flipped = reader.ReadBool();
|
||||
}
|
||||
|
||||
public MahjongGame Game{ get; }
|
||||
|
||||
public int Number{ get; }
|
||||
|
||||
public MahjongTileType Value{ get; }
|
||||
|
||||
public Point2D Position => m_Position;
|
||||
public int StackLevel{ get; private set; }
|
||||
|
||||
public MahjongPieceDirection Direction{ get; private set; }
|
||||
|
||||
public bool Flipped{ get; private set; }
|
||||
|
||||
public MahjongPieceDim Dimensions => GetDimensions(m_Position, Direction);
|
||||
|
||||
public bool IsMovable => Game.GetStackLevel(Dimensions) <= StackLevel;
|
||||
|
||||
public static MahjongPieceDim GetDimensions(Point2D position, MahjongPieceDirection direction)
|
||||
{
|
||||
if (direction == MahjongPieceDirection.Up || direction == MahjongPieceDirection.Down)
|
||||
return new MahjongPieceDim(position, 20, 30);
|
||||
return new MahjongPieceDim(position, 30, 20);
|
||||
}
|
||||
|
||||
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;
|
||||
Direction = direction;
|
||||
StackLevel = -1; // Avoid self interference
|
||||
StackLevel = Game.GetStackLevel(dim) + 1;
|
||||
Flipped = flip;
|
||||
|
||||
Game.Players.SendTilePacket(this, true, true);
|
||||
}
|
||||
|
||||
public void Save(GenericWriter writer)
|
||||
{
|
||||
writer.Write(0); // version
|
||||
|
||||
writer.Write(Number);
|
||||
writer.Write((int)Value);
|
||||
writer.Write(m_Position);
|
||||
writer.Write(StackLevel);
|
||||
writer.Write((int)Direction);
|
||||
writer.Write(Flipped);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue