Exemple #1
0
        private void ServerGetActionCommand(bool _isMine, int _roundNum, int _cardUid, int _posX)
        {
            if ((actionState == State.O && _isMine) || (actionState == State.M && !_isMine))
            {
                throw new Exception("action error0!");
            }

            IRoundSDS roundSDS = getRoundData(roundNum);

            bool isNowAction = _roundNum == roundNum;

            if (isNowAction)
            {
                if (!roundSDS.GetCanDoAcion())
                {
                    throw new Exception("action error1!");
                }
            }
            else
            {
                if (Array.IndexOf(roundSDS.GetCanDoTimeActionRound(), _roundNum) == -1)
                {
                    throw new Exception("action error2!");
                }
            }

            Dictionary <int, int> handCards = _isMine ? mHandCards : oHandCards;

            int cardID;

            if (!handCards.TryGetValue(_cardUid, out cardID))
            {
                throw new Exception("action error3!");
            }

            int[] command = commands[_roundNum];

            int posX = _isMine ? _posX : _posX + BattleConst.mapHeight;

            if (command[posX] != 0)
            {
                throw new Exception("action error4!");
            }

            ICardSDS cardSDS = getCardData(cardID);

            int power = GetPower(isNowAction, _isMine);

            if (power < cardSDS.GetCost())
            {
                throw new Exception("action error5!");
            }

            command[posX] = cardID;

            commandsTime[_roundNum][posX] = roundNum;

            handCards.Remove(_cardUid);
        }
Exemple #2
0
        private static void UseCard(int _roundNum, State[] _states, Dictionary <int, int[]> _commands, Hero[][] _heroMap)
        {
            int[] tmpCommands;

            bool b = _commands.TryGetValue(_roundNum, out tmpCommands);

            if (b)
            {
                for (int i = 0; i < BattleConst.mapHeight; i++)
                {
                    if (_states[i] == State.N)
                    {
                        int cardID = tmpCommands[i];

                        if (cardID != 0 && _heroMap[i][0] == null)
                        {
                            ICardSDS cardSDS = getCardData(cardID);

                            if (cardSDS.GetIsHero())
                            {
                                Hero hero = new Hero();

                                hero.Init(true, getHeroData(cardSDS.GetUseID()), i);

                                _heroMap[i][0] = hero;

                                heroDic.Add(hero.pos, hero);
                            }
                            else
                            {
                                CastSpell(true, cardSDS.GetUseID(), i);
                            }
                        }

                        cardID = tmpCommands[BattleConst.mapHeight + i];

                        if (cardID != 0 && _heroMap[i][BattleConst.mapWidth - 1] == null)
                        {
                            ICardSDS cardSDS = getCardData(cardID);

                            if (cardSDS.GetIsHero())
                            {
                                Hero hero = new Hero();

                                hero.Init(false, getHeroData(cardSDS.GetUseID()), i);

                                _heroMap[i][BattleConst.mapWidth - 1] = hero;

                                heroDic.Add(hero.pos, hero);
                            }
                            else
                            {
                                CastSpell(false, cardSDS.GetUseID(), i);
                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
        private int GetPower(bool _isNowPower, bool _isMine)
        {
            int power = 0;

            for (int i = 0; i < roundNum; i++)
            {
                IRoundSDS roundSDS = getRoundData(i);

                power += _isNowPower ? roundSDS.GetPower() : roundSDS.GetTimePower();

                int[] command;

                bool b = commands.TryGetValue(i, out command);

                if (b)
                {
                    int[] commandTime = commandsTime[i];

                    int start = _isMine ? 0 : BattleConst.mapHeight;

                    for (int m = start; m < start + BattleConst.mapHeight; m++)
                    {
                        int cardID = command[m];

                        if (cardID != 0 && (commandTime[m] == i) == _isNowPower)
                        {
                            ICardSDS cardSDS = getCardData(cardID);

                            power -= cardSDS.GetCost();
                        }
                    }
                }
            }

            return(power);
        }