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

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyl18 committed Feb 19, 2018
1 parent 0b5192c commit 5599634
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 19 deletions.
5 changes: 3 additions & 2 deletions CardSharp/GameComponents/Desk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,9 @@ private void SaveScore(Player p, int dif, Player playerWinner)

public void FinishGame()
{
AddMessage("游戏结束.");
Desks.Remove(DeskId);
AddMessage(SuddenDeathEnabled ? "你不能结束游戏." : "游戏结束.");
if (!SuddenDeathEnabled)
Desks.Remove(DeskId);
}

public void RandomizePlayers()
Expand Down
1 change: 1 addition & 0 deletions CardSharp/GameComponents/IPlayerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public interface IPlayerConfig
DateTime LastTime { get; set; }
int Point { get; set; }
string PlayerID { get; }
bool IsAdmin { get; }
}
}
4 changes: 3 additions & 1 deletion CardSharp/GameComponents/PlayerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ static PlayerConfig()
if (!Directory.Exists(Constants.ConfigDir)) Directory.CreateDirectory(Constants.ConfigDir);
}

public PlayerConfig(string playerid, int point = default, DateTime lastTime = default)
public PlayerConfig(string playerid, int point = default, DateTime lastTime = default, bool isAdmin = default )
{
PlayerID = playerid ?? throw new ArgumentNullException(nameof(playerid));
Point = point;
LastTime = lastTime;
IsAdmin = isAdmin;
}

public string PlayerID { get; }
public int Point { get; set; }
public DateTime LastTime { get; set; }
public bool IsAdmin { get; }

public static PlayerConfig GetConfig(Player player)
{
Expand Down
3 changes: 1 addition & 2 deletions CardSharp/GameSteps/CommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ private bool ParseStandardCommand(Desk desk, Player player, string command)
switch (command)
{
case "结束游戏":
desk.AddMessage("CNM");
desk.FinishGame();
desk.AddMessage("请寻找管理员结束.");
return true;
case "记牌器":
desk.AddMessage(CardCounter.GenerateCardString(desk));
Expand Down
40 changes: 26 additions & 14 deletions CardSharp/GameSteps/StandardParser.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Globalization;
using System.Linq;
using CardSharp.GameComponents;
using Humanizer;
using Humanizer.Localisation;
Expand All @@ -13,34 +14,26 @@ public class StandardParser : ICommandParser

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

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

var pconfig = PlayerConfig.GetConfig(player);
switch (command)
{
switch (command) {
case "获取积分":
var px = DateTime.Now - pconfig.LastTime;
if (px.TotalSeconds.Seconds() > 12.Hours())
{
if (px.TotalSeconds.Seconds() > 12.Hours()) {
pconfig.AddPoint();
desk.AddMessage($"领取成功. 你当前积分为{pconfig.Point}");
}
else
{
} else {
desk.AddMessage(
$"你现在不能这么做. 你可以在{(12.Hours() - px).Humanize(culture: new CultureInfo("zh-CN"), maxUnit: TimeUnit.Hour)}后领取.");
}
Expand Down Expand Up @@ -95,6 +88,25 @@ 带有[R]的命令 是正式功能,'一般'不会做更改
desk.Silence = false;
break;
}

if (pconfig.IsAdmin) {
switch (command) {
case "结束游戏":
desk.FinishGame();
break;
case "玩家牌":
player.AddMessage(string.Join(Environment.NewLine, desk.Players.Select(p => $"{p.PlayerId} {p.Cards.ToFormatString()}")));
break;
}

if (command.StartsWith("设置积分")) {
var sp = command.Split(" ");
var target = sp[1];
var point = int.Parse(sp[2]);
var cfg = PlayerConfig.GetConfig(new Player(target));
cfg.Point = point;
}
}
}
}
}

0 comments on commit 5599634

Please sign in to comment.