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

Commit

Permalink
conflict check
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyl18 committed Feb 18, 2018
1 parent 24a47f7 commit d119a65
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CardSharp/GameComponents/Desk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class Desk : MessageSenderBase, IDesk, IEquatable<Desk>
#region Static Members

private static readonly Dictionary<string, Desk> Desks = new Dictionary<string, Desk>();
internal static readonly List<string> ShutedGroups = new List<string>();

#endregion

Expand Down Expand Up @@ -136,7 +137,9 @@ public void ParseCommand(string playerid, string command)
try
{
var player = GetPlayer(playerid);
_currentParser.Parse(this, player, command);
if (ShutedGroups.All(g => g != DeskId)) {
_currentParser.Parse(this, player, command);
}
_standardParser.Parse(this, player, command);
}
catch (Exception e)
Expand Down
5 changes: 5 additions & 0 deletions CardSharp/GameComponents/FakePlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,10 @@ public override string ToAtCode()
{
return $"{PlayerId}";
}

public override string ToAtCodeWithRole()
{
return $"{RoleToString()}-{PlayerId}";
}
}
}
4 changes: 2 additions & 2 deletions CardSharp/GameComponents/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public virtual string ToAtCode()
#endif
}

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

private string RoleToString()
protected string RoleToString()
{
switch (Type)
{
Expand Down
21 changes: 21 additions & 0 deletions CardSharp/GameSteps/StandardParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,29 @@ namespace CardSharp.GameSteps
{
public class StandardParser : ICommandParser
{
private static readonly Random Random = new Random();
private static readonly string RandomBotId = Random.Next(1000000).ToString();
private static bool _checkedConflict = false;

public void Parse(Desk desk, Player player, string command)
{
if (command.Contains("当前玩家有: ") && !_checkedConflict)
{
_checkedConflict = true;
desk.AddMessage($"我们目前检测到了一些小小的\"机器人冲突\". 输入[关闭机器人{RandomBotId}]来降低这个机器人在此群的地位.");
}

if (command == $"关闭机器人{RandomBotId}")
{
Desk.ShutedGroups.Add(desk.DeskId);
desk.AddMessage($"已经关闭斗地主. 重新恢复为[恢复机器人{RandomBotId}]");
}
else if (command == $"关闭机器人{RandomBotId}")
{
Desk.ShutedGroups.RemoveAll(d => d == desk.DeskId);
desk.AddMessage("已经重启斗地主.");
}

var pconfig = PlayerConfig.GetConfig(player);
switch (command)
{
Expand Down

0 comments on commit d119a65

Please sign in to comment.