Ejemplo n.º 1
0
 public void StartBlock(IEntity source, ActionGraph g, BlockStart gameBlock = null)
 {
     if (g != null)
     {
         StartBlock(source, g.Unravel(), gameBlock);
     }
 }
Ejemplo n.º 2
0
        public void QueueActionBlock(BlockType Type, IEntity Source, List <QueueAction> Actions, IEntity Target = null, int Index = -2)
        {
#if _GAME_DEBUG
            DebugLog.WriteLine("Game " + GameId + ": Queueing " + Type + " for " + Source.ShortDescription + " => " + (Target?.ShortDescription ?? "no target"));
#endif
            int index = Index != -2 ? Index : (Type == BlockType.POWER || Type == BlockType.ATTACK ? -1 : 0);
            var block = new BlockStart(Type, Source, Target, index);
            Queue(Source, new QueueActions.GameBlock(block, Actions));
        }
Ejemplo n.º 3
0
 public void StartBlock(IEntity source, QueueAction a, BlockStart gameBlock = null)
 {
     if (a != null)
     {
         StartBlock(source, new List <QueueAction> {
             a
         }, gameBlock);
     }
 }
Ejemplo n.º 4
0
        private static void FormatCodeBlock(this string text, int indent, List <string> lines)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            if (lines == null)
            {
                throw new ArgumentNullException(nameof(lines));
            }

            int beginPos = 0;
            int endPos   = 0;

            void AddCodeLines(string txt, int idt, List <string> list)
            {
                string[] items = txt.SplitBlockLine();

                list.AddRange(items.Where(l => l.Length > 0)
                              .Select(l => l.SetIndent(idt))
                              .ToArray());
            }

            if (GetBlockPositions(text, ref beginPos, ref endPos) == true)
            {
                AddCodeLines(text.Partialstring(0, beginPos - 1), indent, lines);

                if (BlockStartPrefix.Equals(Environment.NewLine))
                {
                    lines.Add(BlockStart.ToString().SetIndent(indent));
                }
                else
                {
                    lines[lines.Count - 1] = $"{lines[lines.Count - 1]}{BlockStartPrefix}{BlockStart}";
                }

                text.Partialstring(beginPos + 1, endPos - 1).FormatCodeBlock(indent + 1, lines);

                if (BlockEndPrefix.Equals(Environment.NewLine))
                {
                    lines.Add(BlockEnd.ToString().SetIndent(indent));
                }
                else
                {
                    lines[lines.Count - 1] = $"{lines[lines.Count - 1]}{BlockEndPrefix}{BlockEnd}";
                }

                text.Partialstring(endPos + 1, text.Length - 1).FormatCodeBlock(indent, lines);
            }
            else
            {
                AddCodeLines(text, indent, lines);
            }
        }
Ejemplo n.º 5
0
        public Task <ActionResult> RunActionBlockAsync(BlockType Type, IEntity Source, List <QueueAction> Actions, IEntity Target = null, int Index = -2)
        {
#if _GAME_DEBUG
            DebugLog.WriteLine("Game " + GameId + ": Running " + Type + " for " + Source.ShortDescription + " => " + (Target?.ShortDescription ?? "no target"));
#endif
            int index = Index != -2 ? Index : (Type == BlockType.POWER || Type == BlockType.ATTACK ? -1 : 0);
            var block = new BlockStart(Type, Source, Target, index);
            PowerHistory?.Add(block);
            ActionQueue.StartBlock(Source, Actions, block);
            return(ActionQueue.ProcessBlockAsync());
        }
Ejemplo n.º 6
0
		public void StartBlock(IEntity source, List<QueueAction> qa, BlockStart gameBlock = null) {
			if (qa == null) {
				Game.OnBlockEmpty(gameBlock);
				return;
			}
#if _QUEUE_DEBUG
			DebugLog.WriteLine("Queue (Game " + Game.GameId + "): Spawning new queue at depth " + (Depth + 1) + " for " + source.ShortDescription + " with actions: " +
			                   string.Join(" ", qa.Select(a => a.ToString())) + " for action block: " + (gameBlock?.ToString() ?? "none"));
#endif
			QueueStack.Push(Queue);
			Queue = new Deque<QueueActionEventArgs>();
			BlockStack.Push(gameBlock);
			EnqueueDeferred(source, qa);
		}
Ejemplo n.º 7
0
        internal void OnBlockEmpty(BlockStart Block)
        {
#if _GAME_DEBUG
            DebugLog.WriteLine("Game " + GameId + ": Action block " + Block.Type + " for " + Entities[Block.Source].ShortDescription + " resolved");
#endif
            PowerHistory?.Add(new BlockEnd(Block.Type));

            if (Block.Type == BlockType.TRIGGER)
            {
                ActiveTriggers.TriggerResolved();
            }

            // Post-ATTACK or Post-final TRIGGER DEATHS block
            if (Block.Type == BlockType.ATTACK || (Block.Type == BlockType.TRIGGER && ActiveTriggers.QueuedTriggersCount == 0))
            {
                RunDeathCreationStepIfNeeded();
            }
        }
Ejemplo n.º 8
0
 public GameBlock(BlockStart Block, List <QueueAction> Actions)
 {
     this.Block   = Block;
     this.Actions = Actions;
 }
Ejemplo n.º 9
0
    protected void HandleBlockBrush(MapSegment mapSegment)
    {
        if (!AltPress)
        {
            // Find the tile to paint
            RaycastHit raycastHit;
            var        isMouseOver = Physics.Raycast(HandleUtility.GUIPointToWorldRay(Event.current.mousePosition), out raycastHit);

            if (isMouseOver)
            {
                // Find the cordinates of the selected tile
                var tilePosition = mapSegment.GetTilePosition(raycastHit.point);

                // Use this to create the preview
                if (BlockStart != null)
                {
                    IntVector2 endBlock = new IntVector2(tilePosition);

                    TileSetPreview.SetPreviewZoneBlock(MapSegment.CurrentTileSelection, BlockStart.ToPoint(), endBlock.ToPoint());
                }

                if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
                {
                    BlockStart = new IntVector2(tilePosition);
                }
                else if (Event.current.type == EventType.MouseUp && Event.current.button == 0)
                {
                    if (BlockStart != null)
                    {
                        IntVector2 endBlock = new IntVector2(tilePosition);

                        var uvs = MapSegment.StartPaint();
                        for (int y = Mathf.Min(BlockStart.Y, endBlock.Y); y <= Mathf.Max(BlockStart.Y, endBlock.Y); y++)
                        {
                            for (int x = Mathf.Min(BlockStart.X, endBlock.X); x <= Mathf.Max(BlockStart.X, endBlock.X); x++)
                            {
                                mapSegment.Paint(new Point(x, y), MapSegment.CurrentTileSelection, uvs);
                            }
                        }

                        FinalizePaint(uvs);

                        // Set dirty so the editor serializes it
                        EditorUtility.SetDirty(mapSegment.CurrentLayer);
                        BlockStart = null;
                    }
                }
            }
            else
            {
                BlockStart = null;
                TileSetPreview.Clear();
            }
        }
    }
Ejemplo n.º 10
0
        private void HandlePowerTaskList(Line line)
        {
            var match = _gameEntityRegex.Match(line.Text);

            if (match.Success)
            {
                var id = int.Parse(match.Groups["id"].Value);
                _currentEntity = id;
                GameStateChange?.Invoke(new FullEntity(new GameEntityData(id), null));
                return;
            }

            match = _playerEntityRegex.Match(line.Text);
            if (match.Success)
            {
                var entityId = int.Parse(match.Groups["id"].Value);
                var playerId = int.Parse(match.Groups["playerId"].Value);
                _currentEntity = entityId;
                GameStateChange?.Invoke(new FullEntity(new PlayerEntityData(entityId, playerId), null));
                return;
            }

            match = _fullEntityRegex.Match(line.Text);
            if (match.Success)
            {
                var id = int.Parse(match.Groups["id"].Value);
                _currentEntity = id;
                var cardId = match.Groups["cardId"].Value;
                var zone   = GameTagParser.ParseEnum <Zone>(match.Groups["zone"].Value);
                if (string.IsNullOrEmpty(cardId) && zone != Zone.SETASIDE)
                {
                    cardId = _currentBlock?.Data.NextPredictedCard() ?? cardId;
                }
                GameStateChange?.Invoke(new FullEntity(new EntityData(id, null, cardId, zone), _currentBlock?.Data));
                return;
            }

            match = _tagChangeRegex.Match(line.Text);
            if (match.Success)
            {
                var entity = ParseEntity(match.Groups["entity"].Value);
                Enum.TryParse(match.Groups["tag"].Value, out GameTag tag);
                var value    = GameTagParser.ParseTag(tag, match.Groups["value"].Value);
                var entityId = entity.Id == -1 ? null : (int?)entity.Id;
                GameStateChange?.Invoke(new TagChange(new TagChangeData(tag, value, false, entityId, entity.Name)));
                return;
            }

            match = _updatingEntityRegex.Match(line.Text);
            if (match.Success)
            {
                var cardId = match.Groups["cardId"].Value;
                var entity = ParseEntity(match.Groups["entity"].Value);
                _currentEntity = entity.Id;
                var type = match.Groups["type"].Value;
                if (type == "CHANGE_ENTITY")
                {
                    GameStateChange?.Invoke(new ChangeEntity(new EntityData(entity.Id, entity.Name, cardId, null)));
                }
                else
                {
                    GameStateChange?.Invoke(new ShowEntity(new EntityData(entity.Id, entity.Name, cardId, null), _currentBlock?.Data));
                }
                return;
            }

            match = _creationTagRegex.Match(line.Text);
            if (match.Success && !line.Text.Contains("HIDE_ENTITY"))
            {
                var tag   = GameTagParser.ParseEnum <GameTag>(match.Groups["tag"].Value);
                var value = GameTagParser.ParseTag(tag, match.Groups["value"].Value);
                GameStateChange?.Invoke(new TagChange(new TagChangeData(tag, value, true, _currentEntity, null)));
                return;
            }

            match = _hideEntityRegex.Match(line.Text);
            if (match.Success)
            {
                var id = int.Parse(match.Groups["id"].Value);
                _currentEntity = id;
                GameStateChange?.Invoke(new HideEntity(new EntityData(id, "", null, null)));
            }

            match = _blockStartRegex.Match(line.Text);
            if (match.Success)
            {
                var type              = match.Groups["type"].Value;
                var entity            = ParseEntity(match.Groups["entity"].Value.Trim());
                var target            = ParseEntity(match.Groups["target"].Value.Trim());
                var effectCardId      = match.Groups["effectCardId"].Value;
                var effectIndex       = int.Parse(match.Groups["effectIndex"].Value);
                var rawTriggerKeyword = match.Groups["triggerKeyword"].Value;
                var triggerKeyword    = string.IsNullOrEmpty(rawTriggerKeyword) || rawTriggerKeyword == "0" ? null
                                        : (GameTag?)GameTagParser.ParseEnum <GameTag>(rawTriggerKeyword);
                var blockData = new BlockData(type, entity.Id, entity.CardId, effectCardId, effectIndex, triggerKeyword, target);
                _currentBlock = _currentBlock?.CreateChild(blockData) ?? new Block(null, blockData);
                foreach (var card in _blockHelper.GetCreatedCards(blockData))
                {
                    blockData.PredictedCards.Add(card);
                }
                BlockStart?.Invoke(blockData);
                return;
            }

            match = _debugDumpRegex.Match(line.Text);
            if (match.Success)
            {
                if (int.Parse(match.Groups["id"].Value) == 2)
                {
                    SetupComplete?.Invoke();
                }
            }

            if (line.Text.Contains("BLOCK_END"))
            {
                BlockEnd?.Invoke(_currentBlock?.Data);
                _currentBlock = _currentBlock?.Parent;
            }
        }