private int GetDecorationModel(TurnActionComponent comp)
        {
            switch (comp.type)
            {
            case TurnActionComponentType.PromotePiece:
                return(db.PiecePrototypes[comp.promotionIndex].PromotionIndicatorModelIndex);

            default:
                return(-1);
            }
        }
        private int GetPromotionPiece(TurnActionComponent comp)
        {
            switch (comp.type)
            {
            case TurnActionComponentType.PromotePiece:
                return(comp.promotionIndex);

            default:
                return(-1);
            }
        }
예제 #3
0
        private void HandleChoiceMade(TurnAction action)
        {
            stopTurnChoosingCommand.Send();
            TurnActionExecutionResult result = TurnActionExecutionResult.Success;

            for (int c = 0; c < action.components.Count; c++)
            {
                TurnActionComponent comp = action.components[c];
                try {
                    switch (comp.type)
                    {
                    case TurnActionComponentType.MovePiece:
                        moveCommand.Send(new MoveCommand()
                        {
                            startPosition = comp.actor,
                            moveTo        = comp.target,
                        });
                        break;

                    case TurnActionComponentType.CapturePiece:
                        captureCommand.Send(new CaptureCommand()
                        {
                            space = comp.target,
                        });
                        break;

                    case TurnActionComponentType.PromotePiece:
                        promoteCommand.Send(new PromoteCommand()
                        {
                            piecePos  = comp.actor,
                            promoteTo = comp.promotionIndex,
                        });
                        break;

                    case TurnActionComponentType.Forfeit:
                        if (board.ActivePlayer == board.LocalPlayerOrder)
                        {
                            result = TurnActionExecutionResult.Forfeit;
                        }
                        break;

                    default:
                        throw new TurnActionExcecutionException("Bad component type");
                    }
                } catch (TurnActionExcecutionException ex) {
                    scripts.WriteToAuthorLog(string.Format("Turn action execution error on component {0}: {1}", c, ex.Message));
                    result = TurnActionExecutionResult.Error;
                    break;
                }
            }
            handleEndOfTurn.Send(result);
        }
        private ActionIndicatorPattern Compile(ActionIndicatorPatternCompileArgs args)
        {
            ActionIndicatorPattern pattern = new ActionIndicatorPattern();

            pattern.indicators = new List <ActionIndicator>();

            List <TurnAction> options = args.options.options;

            for (int o = 0; o < options.Count; o++)
            {
                if (args.showOnly == null || args.showOnly.Contains(o))
                {
                    TurnAction action = options[o];
                    for (int c = 0; c < action.components.Count; c++)
                    {
                        TurnActionComponent comp     = action.components[c];
                        IntVector2          boardPos = GetBoardPosition(comp);
                        ActionIndicatorType type     = GetIndicatorType(comp);
                        int decorationModel          = GetDecorationModel(comp);
                        int promotionPiece           = GetPromotionPiece(comp);
                        ActionIndicatorStrength strength;
                        if (args.mouseOverMode)
                        {
                            strength = ActionIndicatorStrength.Mouseover;
                        }
                        else if (o == args.highlightedIndex)
                        {
                            strength = ActionIndicatorStrength.Selected;
                        }
                        else
                        {
                            strength = ActionIndicatorStrength.Inactive;
                        }

                        if (!CheckForDuplicates(pattern, boardPos, type, decorationModel, promotionPiece, strength))
                        {
                            pattern.indicators.Add(new ActionIndicator()
                            {
                                boardPosition   = boardPos,
                                type            = type,
                                decorationModel = decorationModel,
                                strength        = strength,
                                promotionPiece  = promotionPiece,
                            });
                        }
                    }
                }
            }

            return(pattern);
        }
        private IntVector2 GetBoardPosition(TurnActionComponent comp)
        {
            switch (comp.type)
            {
            case TurnActionComponentType.MovePiece:
            case TurnActionComponentType.CapturePiece:
                return(comp.target);

            case TurnActionComponentType.PromotePiece:
                return(comp.actor);

            default:
                return(IntVector2.Zero);
            }
        }
        private ActionIndicatorType GetIndicatorType(TurnActionComponent comp)
        {
            switch (comp.type)
            {
            case TurnActionComponentType.MovePiece:
                return(ActionIndicatorType.Move);

            case TurnActionComponentType.CapturePiece:
                return(ActionIndicatorType.Capture);

            case TurnActionComponentType.PromotePiece:
                return(ActionIndicatorType.Promote);

            default:
                return(0);
            }
        }
        public TurnAction TranslateActionTable(int searchPiece, Table actionList, int optionIndex)
        {
            TurnAction action = new TurnAction();
            Piece      piece  = board.Pieces[searchPiece];

            action.searchPiece = piece.BoardPosition;
            string pieceName  = db.PiecePrototypes[piece.PrototypeID].LuaTag;
            int    numActions = actionList.Length;

            //BalugaDebug.Log(numActions);
            action.components = new List <TurnActionComponent>(numActions);

            for (int i = 1; i <= numActions; i++)
            {
                string exMsgHeader       = string.Format("Piece {0} action function error at Option {1} Index {2}:", pieceName, optionIndex, i);
                TurnActionComponent comp = SafeGetAction(actionList.Get(i), exMsgHeader);
                action.components.Add(comp);
            }
            return(action);
        }
예제 #8
0
        internal bool IsEquivalent(TurnActionComponent other)
        {
            if (type != other.type)
            {
                return(false);
            }
            else
            {
                switch (type)
                {
                case TurnActionComponentType.MovePiece:
                    return(actor == other.actor && target == other.target);

                case TurnActionComponentType.CapturePiece:
                    return(target == other.target);

                case TurnActionComponentType.PromotePiece:
                    return(actor == other.actor && promotionIndex == other.promotionIndex);

                default:
                    return(true);
                }
            }
        }
        private TurnActionComponent TranslateTurnActionComp(Mods.Lua.TurnActionComponent luaComp, string excMsgHeader)
        {
            TurnActionComponent logicComp = new TurnActionComponent();

            switch (luaComp.Type.ToUpperInvariant())
            {
            case "MOVE":
                logicComp.type   = TurnActionComponentType.MovePiece;
                logicComp.actor  = ToBoardPosition(luaComp.ActorX, luaComp.ActorY, excMsgHeader, "start");
                logicComp.target = ToBoardPosition(luaComp.TargetX, luaComp.TargetY, excMsgHeader, "target");
                if (logicComp.actor == logicComp.target)
                {
                    throw new BadActionException(excMsgHeader + " Start and target positions are equal");
                }
                return(logicComp);

            case "CAPTURE":
                logicComp.type   = TurnActionComponentType.CapturePiece;
                logicComp.target = ToBoardPosition(luaComp.TargetX, luaComp.TargetY, excMsgHeader, "target");
                return(logicComp);

            case "PROMOTION":
            case "PROMOTE":
                logicComp.type           = TurnActionComponentType.PromotePiece;
                logicComp.actor          = ToBoardPosition(luaComp.ActorX, luaComp.ActorY, excMsgHeader, "promoted");
                logicComp.promotionIndex = db.PieceNameToIndex(luaComp.PromotionPiece);
                if (logicComp.promotionIndex < 0)
                {
                    throw new BadActionException(excMsgHeader + " Nonexistent piece given for promotion");
                }
                return(logicComp);

            default:
                throw new BadActionException(string.Format("{0} Invalid action type \"{1}\"", excMsgHeader, luaComp.Type));
            }
        }