public void HandleAction(Game game, GameAction action) { foreach (Tag tag in action.Tags) { HandleTag(game, action, tag); } }
public void HandleTag(Game game, GameAction action, Tag tag) { if (string.Equals(tag.Name, "TURN")) HandleTurnTag(game, action, tag); if (string.Equals(tag.Name, "ZONE") && string.Equals(tag.Value, "HAND") && string.Equals(action.SubType, "TRIGGER")) HandleTurnDrawTag(game, action, tag); }
public void HandleTurnTag(Game game, GameAction action, Tag tag) { var turn = new Turn(); turn.TurnIndex = int.Parse(tag.Value); if (game.Draw != null) { turn.Draw = game.Draw; game.Draw = null; } game.Turns.Add(turn); }
public void HandleTurnDrawTag(Game game, GameAction action, Tag tag) { game.Draw = tag.Entity.Card; }
private GameAction ParseActionHeader(string actionString) { var action = new GameAction(); var headerRegex = new Regex(@"ACTION_START\sEntity=(\[name=(?<entityname>[\w\s\dа-яА-Я_-]+)\sid=(?<entityid>\d+)\szone=(?<entityzone>\w+)\szonePos=(?<entityzonepos>\d)\scardId=(?<entitycardid>[\w\d_]+)\splayer=(?<entityplayer>\d)\]|(?<entityglobalname>[\w\s\d-_]*))\sSubType=(?<subtype>\w+)\sIndex=(?<index>[-\d]+)\sTarget=(\[name=(?<targetname>[\w\s\dа-яА-Я_-]+)\sid=(?<targetid>\d+)\szone=(?<targetzone>\w+)\szonePos=(?<targetzonepos>\d)\scardId=(?<targetdardid>[\w\d_]+)\splayer=(?<targetplayer>\d)\]|(?<targetglobalname>[\w\s\d-_]*))"); var match = headerRegex.Match(actionString); action.SubType = match.Groups["subtype"].Value; action.IsConsistent = true; int index = 0; if (int.TryParse(match.Groups["index"].Value, out index)) action.Index = index; if (match.Groups["entityglobalname"].Value == string.Empty) { try { action.Entity.Name = match.Groups["entityname"].Value; action.Entity.Id = int.Parse(match.Groups["entityid"].Value); action.Entity.CardId = match.Groups["entitycardid"].Value; action.Entity.ZonePos = int.Parse(match.Groups["entityzonepos"].Value); action.Entity.Zone = match.Groups["entityzone"].Value; action.Entity.Player = int.Parse(match.Groups["entityplayer"].Value); } catch { action.Entity.Type = "INVALID"; action.IsConsistent = false; } } else { action.Entity.Name = match.Groups["entityglobalname"].Value; } if (match.Groups["targetglobalname"].Value == string.Empty) { try { action.Target.Name = match.Groups["targetname"].Value; action.Target.Id = int.Parse(match.Groups["targetid"].Value); action.Target.CardId = match.Groups["targetcardid"].Value; action.Target.ZonePos = int.Parse(match.Groups["targetzonepos"].Value); action.Target.Zone = match.Groups["targetzone"].Value; action.Target.Player = int.Parse(match.Groups["targetplayer"].Value); } catch { action.Target.Type = "INVALID"; action.IsConsistent = false; } } else { action.Target.Name = match.Groups["targetglobalname"].Value; } return action; }