Exemple #1
0
        public static async Task UseActionCard <T>(Game game, T useActionCard, ActionCard card, Func <Game, T, Task> effect) where T : PlayerAction.FreeUse
        {
            Player player = game.GetPlayer(useActionCard.PlayerId);
            await player.DropActionCard(game, useActionCard.Source);

            //由于行动牌可能是由多张牌转换过来的,要根据source处理
            UsingInfo usingInfo = new UsingInfo()
            {
                Card = card,
                Info = $"{player.Hero.Name}使用了{card.Name}",
            };

            //结算前把牌放入结算区
            foreach (var cardId in useActionCard.Source)
            {
                var c = game.GetCard(cardId);
                game.AddUsingCard(c);
                usingInfo.Source.Add(c);
            }
            game.AddUsingInfo(usingInfo);
            await effect(game, useActionCard);

            foreach (var cardId in useActionCard.Source)
            {
                var c = game.GetCard(cardId) as ActionCard;
                game.RemoveUsingCard(c);
                //结算完毕进入弃牌堆
                game.UsedActionDeck.Add(c);
            }
        }
Exemple #2
0
        private void CheckSemanticExtern(MoveInfo treeInfo, ScriptInfo scriptInfo, CheckingInfo checkingInfo)
        {
            _path = _pathOrUsing;

            #region Finding using
            UsingInfo usingInfoTry = scriptInfo.FindUsing(_path);
            if (usingInfoTry != null)
            {
                if (usingInfoTry.SF != scriptInfo.SF && usingInfoTry.Access != MemberAccess.Public)
                {
                    scriptInfo.SF.Errors.Add(new SemanticError("Could not access using '" + usingInfoTry.SF.SFPath + "::" + usingInfoTry.Name + "'",
                                                               treeInfo.GetErrorInfo(_pathElem)));
                    return;
                }

                _path = usingInfoTry.SFPath;
                UsingName usingName = UsingName.ConvertToMe(this, _pathElem, usingInfoTry);

                scriptInfo.References.Add(new UsingRefInfo(scriptInfo.SF, usingInfoTry,
                                                           usingName.CharIndex, usingName.CharLength, checkingInfo.SC.SourceCode.Substring(usingName.CharIndex, usingName.CharLength)));
            }
            #endregion

            ScriptFile sf = scriptInfo.SF.Manager.GetSF(_path);
            if (sf == null)
            {
                scriptInfo.SF.Errors.Add(
                    new SemanticError("Could not find file '" + _path + "'",
                                      treeInfo.GetErrorInfo(treeInfo.Current)));
                return;
            }
            else if (sf.SI == null)
            {
                scriptInfo.SF.Errors.Add(
                    new WarningError("Could not read file '" + _path + "'",
                                     treeInfo.GetErrorInfo(treeInfo.Current)));
                return;
            }

            _funcInfo = sf.SI.FindLocalFunc(_name);
            if (_funcInfo == null)
            {
                scriptInfo.SF.Errors.Add(
                    new SemanticError("Unknown function '" + _path + "::" + _name + "'",
                                      treeInfo.GetErrorInfo(treeInfo.Current)));
                return;
            }

            // member is private
            if (sf != scriptInfo.SF && _funcInfo.Access != MemberAccess.Public)
            {
                scriptInfo.SF.Errors.Add(
                    new SemanticError("Cannot access function '" + _path + "::" + _name + "'",
                                      treeInfo.GetErrorInfo(treeInfo.Current)));
            }
        }
Exemple #3
0
        public static UsingName ConvertToMe(IBlock parentBlock, Path path, UsingInfo usingInfo)
        {
            UsingName       usingName   = new UsingName(path.GetChildren(), usingInfo);
            List <IElement> defChildren = parentBlock.GetChildren();
            int             index       = defChildren.IndexOf(path);

            defChildren.RemoveAt(index);
            defChildren.Insert(index, usingName);
            return(usingName);
        }
Exemple #4
0
        public static async Task NormalUse <T>(Game game, T useOneCard, Card card, Func <Game, T, Task> effect) where T : PlayerAction.FreeUse
        {
            Player player = game.GetPlayer(useOneCard.PlayerId);

            if (card is ActionCard actionCard)
            {
                await player.DropActionCard(game, useOneCard.Source);
            }
            else if (card is EventCard eventCard)
            {
                await player.DropEventCard(game, eventCard);
            }
            //结算前把牌放入结算区
            UsingInfo usingInfo = new UsingInfo()
            {
                Card = card,
                Info = $"{player.Hero.Name}使用了{card.Name}",
            };

            foreach (var cardId in useOneCard.Source)
            {
                var c = game.GetCard(cardId);
                game.AddUsingCard(c);
                usingInfo.Source.Add(c);
            }
            game.AddUsingInfo(usingInfo);
            await effect(game, useOneCard);

            game.RemoveUsingCard(card);
            //结算完毕进入弃牌堆
            if (card is ActionCard actionCard1)
            {
                game.UsedActionDeck.Add(actionCard1);
            }
            else if (card is EventCard eventCard1 && !game.ChainEventDeck.Contains(eventCard1))
            {
                game.UsedEventDeck.Add(eventCard1);
            }
        }
        public static async Task UseActionCard <T>(Game game, T useActionCard, ActionCard card, Func <Game, T, Task> effect) where T : PlayerAction.FreeUse
        {
            Player player = game.GetPlayer(useActionCard.PlayerId);
            await player.DropActionCard(game, useActionCard.Source);

            //由于行动牌可能是由多张牌转换过来的,要根据source处理
            UsingInfo usingInfo = new UsingInfo()
            {
                Card = card,
                Info = $"{player.Hero.Name}使用了{card.Name}",
            };

            //结算前把牌放入结算区
            foreach (var cardId in useActionCard.Source)
            {
                var c = game.GetCard(cardId);
                game.AddUsingCard(c);
                usingInfo.Source.Add(c);
            }
            game.AddUsingInfo(usingInfo);
            if (card.isDelay)
            {
                game.DelayActionDeck.Add(card);//延迟牌置入延迟区
            }
            Log.Game(player.Name + "使用" + card.Name);
            await effect(game, useActionCard);

            foreach (var cardId in useActionCard.Source)
            {
                var c = game.GetCard(cardId) as ActionCard;
                game.RemoveUsingCard(c);
                if (!card.isDelay)//延迟牌不会结算完毕
                {
                    await c.onEffected(game);
                }
                c.Owner = null;
            }
        }
        public AssemblyTreeMember(IMemberInfo member)
            : this()
        {
            memberInfo = member;

            Name = member.Name;
            Text = Name;

            #region ToolTipText
            if (member is FuncInfo)
            {
                ToolTipText = FileManager.GetCallTipText((FuncInfo)member, ((FuncInfo)member).Parameters.Count);
            }
            else if (member is ConstInfo)
            {
                ToolTipText = FileManager.GetCallTipText((ConstInfo)member);
            }
            else if (member is UsingInfo)
            {
                ToolTipText = FileManager.GetCallTipText((UsingInfo)member);
            }
            else
            {
                ToolTipText = Name;
            }
            #endregion

            #region Image
            if (member is ConstInfo)
            {
                ConstInfo c = (ConstInfo)member;
                if (c.Sealed)
                {
                    ImageIndex = AssemblyTreeIcons.ConstantSealed;
                }
                else if (c.Access == MemberAccess.Private)
                {
                    ImageIndex = AssemblyTreeIcons.ConstantPrivate;
                }
                else if (c.Access == MemberAccess.Public)
                {
                    ImageIndex = AssemblyTreeIcons.ConstantPublic;
                }
                else
                {
                    throw new ArgumentException("Unknown icon");
                }
            }
            else if (member is FuncInfo)
            {
                FuncInfo f = (FuncInfo)member;
                if (f.Access == MemberAccess.Private)
                {
                    ImageIndex = AssemblyTreeIcons.FunctionPrivate;
                }
                else if (f.Access == MemberAccess.Public)
                {
                    ImageIndex = AssemblyTreeIcons.FunctionPublic;
                }
                else
                {
                    throw new ArgumentException("Unknown icon");
                }
            }
            else if (member is UsingInfo)
            {
                UsingInfo u = (UsingInfo)member;
                if (u.Access == MemberAccess.Private)
                {
                    ImageIndex = AssemblyTreeIcons.UsingPrivate;
                }
                else if (u.Access == MemberAccess.Public)
                {
                    ImageIndex = AssemblyTreeIcons.UsingPublic;
                }
                else
                {
                    throw new ArgumentException("Unknown icon");
                }
            }
            else
            {
                throw new ArgumentException("member");
            }

            SelectedImageIndex = ImageIndex;
            #endregion

            this.ContextMenuStrip = new MemberContextMenuStrip(this, member);
        }
Exemple #7
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            int      startIndex = parentInfo.CurrentIndex;
            MoveInfo moveInfo   = new MoveInfo(parentInfo);

            // modifier
            MemberAccess   access;
            AccessModifier modifier = AccessModifier.GetModifier(moveInfo, out access);

            if (modifier != null)
            {
                startIndex = moveInfo.CurrentIndex;
            }

            // name
            moveInfo = new MoveInfo(parentInfo);
            IElement tryName = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (tryName == null || !tryName.IsTT(TokenType.Word))
            {
                throw new SyntaxException("Could not find using name", parentInfo.GetErrorInfo());
            }

            string   name     = tryName.ToString();
            UsingDef usingDef = new UsingDef(moveInfo.Current.CharIndex, moveInfo.Current.CharLength, moveInfo.Current.LineIndex);

            // assign
            moveInfo.FindNextBlack(SearchDirection.LeftToRight); // =
            moveInfo.FindNextBlack(SearchDirection.LeftToRight); // behind =

            // expression
            Path pathTry = Path.Parse(moveInfo, parsingInfo, scriptInfo);

            if (pathTry == null)
            {
                throw new SyntaxException("Could not find using path", parentInfo.GetErrorInfo());
            }

            // terminal
            IElement terminalTry = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (terminalTry == null || !(terminalTry.IsTT(TokenType.SemiColon)))
            {
                throw new SyntaxException("Missing directive ';'?", parentInfo.GetErrorInfo());
            }

            int length = (moveInfo.CurrentIndex + 1) - startIndex;

            usingDef.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.MoveToIndex(startIndex);
            parentInfo.Replace(length, usingDef);

            // info

            // add const def to list
            parsingInfo.UsingDefList.Add(usingDef);

            /*if (scriptInfo.Constants.FindIndex(a => a.Name == name) != -1)
             *  ErrorManager.Semantic("Constant '" + name + "' already defined", new ErrorInfo(parentInfo.ErrorInfo));
             * else
             * {*/
            UsingInfo usingInfo = new UsingInfo(scriptInfo.SF, name, pathTry.ToString(), access, usingDef);

            scriptInfo.AddUsing(usingInfo);
            usingDef._usingInfo = usingInfo;
            //}
        }
Exemple #8
0
 public UsingName(List <IElement> elems, UsingInfo usingInfo)
     : base(elems)
 {
     this._usingInfo = usingInfo;
 }
Exemple #9
0
        /// <summary>
        /// Inserts 'newUsing' in the current scope.
        /// This method will try to insert new usings in the correct position (depending on
        /// where the existing usings are; and maintaining the sort order).
        /// </summary>
        public static void InsertUsing(RefactoringContext context, Script script, AstNode newUsing)
        {
            UsingInfo newUsingInfo       = new UsingInfo(newUsing, context);
            AstNode   enclosingNamespace = context.GetNode <NamespaceDeclaration>() ?? context.RootNode;
            // Find nearest enclosing parent that has usings:
            AstNode usingParent = enclosingNamespace;

            while (usingParent != null && !usingParent.Children.OfType <UsingDeclaration>().Any())
            {
                usingParent = usingParent.Parent;
            }
            if (usingParent == null)
            {
                // No existing usings at all -> use the default location
                if (script.FormattingOptions.UsingPlacement == UsingPlacement.TopOfFile)
                {
                    usingParent = context.RootNode;
                }
                else
                {
                    usingParent = enclosingNamespace;
                }
            }
            // Find the main block of using declarations in the chosen scope:
            AstNode blockStart = usingParent.Children.FirstOrDefault(IsUsingDeclaration);
            AstNode insertionPoint;
            bool    insertAfter = false;

            if (blockStart == null)
            {
                // no using declarations in the file
                Debug.Assert(SyntaxTree.MemberRole == NamespaceDeclaration.MemberRole);
                insertionPoint = usingParent.GetChildrenByRole(SyntaxTree.MemberRole).SkipWhile(CanAppearBeforeUsings).FirstOrDefault();
            }
            else
            {
                insertionPoint = blockStart;
                while (IsUsingFollowing(ref insertionPoint) && newUsingInfo.CompareTo(new UsingInfo(insertionPoint, context)) > 0)
                {
                    insertionPoint = insertionPoint.NextSibling;
                }
                if (!IsUsingDeclaration(insertionPoint))
                {
                    // Insert after last using instead of before next node
                    // This affects where empty lines get placed.
                    insertionPoint = insertionPoint.PrevSibling;
                    insertAfter    = true;
                }
            }
            if (insertionPoint != null)
            {
                if (insertAfter)
                {
                    script.InsertAfter(insertionPoint, newUsing);
                }
                else
                {
                    script.InsertBefore(insertionPoint, newUsing);
                }
            }
        }
Exemple #10
0
        private void CheckSemanticExtern(MoveInfo treeInfo, ScriptInfo scriptInfo, CheckingInfo checkingInfo)
        {
            _path = _pathOrUsing;

            #region Finding using
            UsingInfo usingInfoTry = scriptInfo.FindUsing(_path);
            if (usingInfoTry != null)
            {
                if (usingInfoTry.SF != scriptInfo.SF && usingInfoTry.Access != MemberAccess.Public)
                {
                    scriptInfo.SF.Errors.Add(new SemanticError("Could not access using '" + usingInfoTry.SF.SFPath + "::" + usingInfoTry.Name + "'",
                                                               treeInfo.GetErrorInfo(this._pathElem)));
                    return;
                }

                _path = usingInfoTry.SFPath;
                UsingName usingName = UsingName.ConvertToMe(this, this._pathElem, usingInfoTry);

                scriptInfo.References.Add(new UsingRefInfo(scriptInfo.SF, usingInfoTry,
                                                           usingName.CharIndex, usingName.CharLength, checkingInfo.SC.SourceCode.Substring(usingName.CharIndex, usingName.CharLength)));
            }
            #endregion

            ScriptFile sf = scriptInfo.SF.Manager.GetSF(_path);
            if (sf == null || sf.SI == null)
            {
                scriptInfo.SF.Errors.Add(
                    new SemanticError("Could not find file '" + _path + "'",
                                      treeInfo.GetErrorInfo(treeInfo.Current)));
                return;
            }
            else if (sf.SI == null)
            {
                scriptInfo.SF.Errors.Add(
                    new WarningError("Could not read file '" + _path + "'",
                                     treeInfo.GetErrorInfo(treeInfo.Current)));
                return;
            }

            IMemberInfo member = sf.SI.FindLocalMember(_name);
            if (member == null)
            {
                scriptInfo.SF.Errors.Add(
                    new SemanticError("Unknown member '" + _path + "::" + _name + "'",
                                      treeInfo.GetErrorInfo(treeInfo.Current)));
                return;
            }

            // member is private
            if (sf != scriptInfo.SF &&
                ((member is FuncInfo && ((FuncInfo)member).Access != MemberAccess.Public) ||
                 (member is ConstInfo && ((ConstInfo)member).Access != MemberAccess.Public)))
            {
                scriptInfo.SF.Errors.Add(
                    new SemanticError("Cannot access member '" + _path + "::" + _name + "'",
                                      treeInfo.GetErrorInfo(treeInfo.Current)));
            }

            // create constant
            if (member is ConstInfo)
            {
                ToConstant(treeInfo, (ConstInfo)member);
                scriptInfo.References.Add(new ConstRefInfo(scriptInfo.SF, (ConstInfo)member,
                                                           this.CharIndex, this.CharLength, checkingInfo.SC.SourceCode.Substring(this.CharIndex, this.CharLength)));
                return;
            }
            else if (member is FuncInfo)
            {
                _funcInfo = (FuncInfo)member;
                scriptInfo.References.Add(new FuncRefInfo(scriptInfo.SF, (FuncInfo)member, this.CharIndex, this.CharLength,
                                                          checkingInfo.SC.SourceCode.Substring(this.CharIndex, this.CharLength), false));
            }
            else
            {
                scriptInfo.SF.Errors.Add(
                    new SemanticError("Unknown member type '" + _path + "::" + _name + "'",
                                      treeInfo.GetErrorInfo(treeInfo.Current)));
            }
        }