Skip to content
This repository has been archived by the owner on Jul 27, 2018. It is now read-only.

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyl18 committed Feb 18, 2018
1 parent ef12bec commit c2a773c
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 12 deletions.
14 changes: 11 additions & 3 deletions CardSharp/GameComponents/Desk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Desk : MessageSenderBase, IDesk, IEquatable<Desk>

#endregion

private readonly Dictionary<string, Player> _playersDictionary = new Dictionary<string, Player>();
private Dictionary<string, Player> _playersDictionary = new Dictionary<string, Player>();

private readonly StandardParser _standardParser;

Expand Down Expand Up @@ -114,6 +114,7 @@ public bool Start()
if (Players.Count() != Constants.MaxPlayer)
return false;

RandomizePlayers();
SendCards();
SendCardsMessage();
AddMessage("现在可以使用 [加倍/超级加倍/明牌] 之类的命令.");
Expand Down Expand Up @@ -215,11 +216,11 @@ public void BoardcastCards()
if (CurrentPlayer.FirstBlood)
{
CurrentPlayer.FirstBlood = false;
AddMessage($"{CurrentPlayer.ToAtCode()}请开始你的表演");
AddMessage($"{CurrentPlayer.ToAtCodeWithRole()}请开始你的表演");
}
else
{
AddMessageLine($"{CurrentPlayer.ToAtCode()}请出牌");
AddMessageLine($"{CurrentPlayer.ToAtCodeWithRole()}请出牌");
}
else
AddMessage($"{CurrentRule.ToString()}-{LastCards.ToFormatString()} {CurrentPlayer.ToAtCode()}请出牌");
Expand Down Expand Up @@ -299,6 +300,13 @@ public void FinishGame()
Desks.Remove(DeskId);
}

public void RandomizePlayers()
{
var players = new List<Player>(PlayerList);
players.Shuffle();
_playersDictionary = players.ToDictionary(player => player.PlayerId);
}

public void SendToAllPlayers(string message)
{
PlayerList.ForEach(player => player.AddMessage(message));
Expand Down
17 changes: 17 additions & 0 deletions CardSharp/GameComponents/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ public virtual string ToAtCode()
#endif
}

public string ToAtCodeWithRole()
{
return $"{RoleToString()}[CQ:at,qq={PlayerId}]";
}

private string RoleToString()
{
switch (Type)
{
case PlayerType.Farmer:
return "农民";
case PlayerType.Landlord:
return "地主";
default:
throw new ArgumentOutOfRangeException();
}
}

public void SendCards(Desk desk)
{
Expand Down
10 changes: 5 additions & 5 deletions CardSharp/GameSteps/CommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public CommandParser(Desk desk)

public void Prepare(Desk desk)
{
desk.AddMessage($"{desk.CurrentPlayer.ToAtCode()}出牌");
desk.AddMessage($"{desk.CurrentPlayer.ToAtCodeWithRole()}出牌");
RunHostedCheck(desk);
}

Expand Down Expand Up @@ -58,7 +58,7 @@ private void ParsePlayerSubmitCard(Desk desk, Player player, string command)
player.SendCards(desk);
if (CheckPlayerWin(desk)) return;
if (player.Cards.Count <= Constants.BoardcastCardNumThreshold)
desk.AddMessageLine($"{player.ToAtCode()} 只剩{player.Cards.Count}张牌啦~");
desk.AddMessageLine($"{player.ToAtCodeWithRole()} 只剩{player.Cards.Count}张牌啦~");

if (desk.SuddenDeathEnabled) desk.AddMessageLine("WARNING: SUDDEN DEATH ENABLED");

Expand Down Expand Up @@ -156,7 +156,7 @@ private bool ParseStandardCommand(Desk desk, Player player, string command)
return true;
case "全场牌数":
desk.AddMessage(string.Join(Environment.NewLine,
desk.PlayerList.Select(p => $"{p.ToAtCode()}: {p.Cards.Count}")));
desk.PlayerList.Select(p => $"{p.ToAtCodeWithRole()}: {p.Cards.Count}")));
return true;
case "弃牌":
player.GiveUp = true;
Expand Down Expand Up @@ -200,11 +200,11 @@ private bool RunHostedCheck(Desk desk)
switch (exists)
{
case true:
desk.AddMessageLine($" {cp.ToAtCode()} 托管出牌 {cards.ToFormatString()}");
desk.AddMessageLine($" {cp.ToAtCodeWithRole()} 托管出牌 {cards.ToFormatString()}");
Parse(desk, cp, $"{string.Join("", cards.Select(card => card.ToString()))}");
return true;
case false:
desk.AddMessageLine($" {cp.ToAtCode()} 托管过牌");
desk.AddMessageLine($" {cp.ToAtCodeWithRole()} 托管过牌");
Parse(desk, cp, "pass");
return true;
}
Expand Down
7 changes: 5 additions & 2 deletions CardSharp/GameSteps/LandlordDiscuss.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public LandlordDiscuss(IEnumerable<Card> landlordCards, Desk desk)
var player = desk.GetPlayerFromIndex(CurrentIndex);
desk.AddMessage($"开始游戏, {player.ToAtCode()}你要抢地主吗?[抢地主/不抢]");
if (player is FakePlayer) {
Parse(desk, player, "");
Parse(desk, player, "不抢");
}
}

Expand Down Expand Up @@ -103,10 +103,13 @@ public void Parse(Desk desk, Player player, string command)
case "抢你妈的飞旋回踢张大麻子苟枫凌他当妈rbq":
MoveNext();
desk.AddMessage(
$"{player.ToAtCode()}不抢地主, {desk.GetPlayerFromIndex(CurrentIndex).ToAtCode()}你要抢地主嘛?");
$"{player.ToAtCode()}不抢地主, {desk.CurrentPlayer.ToAtCode()}你要抢地主嘛?");
_count++;
break;
}
if (desk.CurrentPlayer is FakePlayer) {
Parse(desk, player, "不抢");
}
}
}
}
4 changes: 2 additions & 2 deletions CardSharp/GameSteps/StandardParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void Parse(Desk desk, Player player, string command)
desk.AddMessage(@"= 命令列表 =
/////没牌的直接添加机器人好友(有牌的最好也添加)机器人会自动同意请求\\\\\
Plugin by Cy.
Powered by Cy.
命令说明:
带有[D]的命令 还未开发完成
带有[B]的命令 是测试功能,可能会更改
Expand All @@ -62,7 +62,7 @@ 带有[R]的命令 是正式功能,'一般'不会做更改
[B]|结束游戏|:只有参与游戏的人可以使用
[R]|获取积分|:获取积分,12小时可获取10000分。
[R]|我的信息|:你的积分
[B]|记牌器|:消耗500积分,显示每种牌在场上还剩下多少张
[B]|记牌器|:显示每种牌在场上还剩下多少张
[B]|安静出牌启用|:所有信息都会私聊发送
[B]|安静出牌禁用|:所有信息不都会私聊发送
Expand Down
5 changes: 5 additions & 0 deletions CardSharp/GameSteps/WaitingParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public void Parse(Desk desk, Player player, string command)
desk.RemovePlayer(player);
break;
case "开始游戏":
if (desk.Players.All(p => p is FakePlayer))
{
desk.AddMessage("仨机器人可不行哟~");
return;
}
if (desk.PlayerList.Count == 3)
desk.Start();
else
Expand Down

0 comments on commit c2a773c

Please sign in to comment.