Beispiel #1
0
        private void addCardToZone(IZone zone, Card card, Controller player)
        {
            var tags = new Dictionary <GameTag, int>
            {
                [GameTag.ENTITY_ID]  = _game.NextId,
                [GameTag.CONTROLLER] = player.PlayerId,
                [GameTag.ZONE]       = (int)zone.Type
            };
            IPlayable playable = null;


            switch (card.Type)
            {
            case CardType.MINION:
                playable = new Minion(player, card, tags);
                break;

            case CardType.SPELL:
                playable = new Spell(player, card, tags);
                break;

            case CardType.WEAPON:
                playable = new Weapon(player, card, tags);
                break;

            case CardType.HERO:
                tags[GameTag.ZONE]     = (int)SabberStoneCore.Enums.Zone.PLAY;
                tags[GameTag.CARDTYPE] = card[GameTag.CARDTYPE];
                playable = new Hero(player, card, tags);
                break;

            case CardType.HERO_POWER:
                tags[GameTag.COST]     = card[GameTag.COST];
                tags[GameTag.ZONE]     = (int)SabberStoneCore.Enums.Zone.PLAY;
                tags[GameTag.CARDTYPE] = card[GameTag.CARDTYPE];
                playable = new HeroPower(player, card, tags);
                break;

            default:
                throw new EntityException($"Couldn't create entity, because of an unknown cardType {card.Type}.");
            }

            zone?.Add(playable);
        }
Beispiel #2
0
        /// <summary>Builds a new subclass of entity that can be added to a SabberStone game instance.</summary>
        /// <param name="controller">The controller of the entity.</param>
        /// <param name="card">The card from which the entity must be derived.</param>
        /// <param name="tags">The tags preset for the entity.</param>
        /// <param name="zone">The zone in which the entity must spawn.</param>
        /// <param name="id">The EntityID to assign to the newly created entity.</param>
        /// <returns></returns>
        /// <exception cref="EntityException"></exception>
        public static IPlayable FromCard(Controller controller, Card card, Dictionary <GameTag, int> tags = null, IZone zone = null, int id = -1)
        {
            tags = tags ?? new Dictionary <GameTag, int>();
            tags[GameTag.ENTITY_ID]  = id > 0 ? id : controller.Game.NextId;
            tags[GameTag.CONTROLLER] = controller.PlayerId;
            tags[GameTag.ZONE]       = zone != null ? (int)zone.Type : 0;
            //tags[GameTag.CARD_ID] = card.AssetId;

            IPlayable result = null;

            switch (card.Type)
            {
            case CardType.MINION:
                result = new Minion(controller, card, tags);
                break;

            case CardType.SPELL:
                result = new Spell(controller, card, tags);
                break;

            case CardType.WEAPON:
                result = new Weapon(controller, card, tags);
                break;

            case CardType.HERO:

                // removing this because it's always the cards health or it is given by previous heros like for deathknight
                //tags[GameTag.HEALTH] = card[GameTag.HEALTH];

                tags[GameTag.ZONE] = (int)Enums.Zone.PLAY;
                //tags[GameTag.FACTION] = card[GameTag.FACTION];
                tags[GameTag.CARDTYPE] = card[GameTag.CARDTYPE];
                //tags[GameTag.RARITY] = card[GameTag.RARITY];
                //tags[GameTag.HERO_POWER] = card[GameTag.HERO_POWER];

                result = new Hero(controller, card, tags);
                break;

            case CardType.HERO_POWER:
                tags[GameTag.COST] = card[GameTag.COST];
                tags[GameTag.ZONE] = (int)Enums.Zone.PLAY;
                //tags[GameTag.FACTION] = card[GameTag.FACTION];
                tags[GameTag.CARDTYPE] = card[GameTag.CARDTYPE];
                //tags[GameTag.RARITY] = card[GameTag.RARITY];
                //tags[GameTag.TAG_LAST_KNOWN_COST_IN_HAND] = card[GameTag.COST];
                result = new HeroPower(controller, card, tags);
                break;

            default:
                throw new EntityException($"Couldn't create entity, because of an unknown cardType {card.Type}.");
            }

            // add entity to the game dic
            controller.Game.IdEntityDic.Add(result.Id, result);

            // add power history full entity
            if (controller.Game.History)
            {
                controller.Game.PowerHistory.Add(PowerHistoryBuilder.FullEntity(result));
            }

            // add entity to the appropriate zone if it was given
            zone?.Add(result);

            if (result.ChooseOne)
            {
                result.ChooseOnePlayables[0] =
                    id < 0 ? FromCard(controller,
                                      Cards.FromId(result.Card.Id + "a"),
                                      new Dictionary <GameTag, int>
                {
                    [GameTag.CREATOR]     = result.Id,
                    [GameTag.PARENT_CARD] = result.Id
                },
                                      controller.SetasideZone) :
                    controller.SetasideZone.GetAll.Find(p => p[GameTag.CREATOR] == result.Id && p.Card.Id == result.Card.Id + "a");

                result.ChooseOnePlayables[1] =
                    id < 0 ? FromCard(controller,
                                      Cards.FromId(result.Card.Id + "b"),
                                      new Dictionary <GameTag, int>
                {
                    [GameTag.CREATOR]     = result.Id,
                    [GameTag.PARENT_CARD] = result.Id
                },
                                      controller.SetasideZone) :
                    controller.SetasideZone.GetAll.Find(p => p[GameTag.CREATOR] == result.Id && p.Card.Id == result.Card.Id + "b");
            }

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Creates a zone for the opponent using the specified cards and zone.
        /// </summary>
        /// <param name="opponent">the controller of the opponent</param>
        /// <param name="predictedCards">the predicted cards the zone is populated with</param>
        /// <param name="zone">the zone who will be created</param>
        /// <param name="setasideZone">the setaside zone</param>
        /// <returns>the playables of the zone based on the cards</returns>
        private List <IPlayable> createZone(Controller opponent, List <Card> predictedCards,
                                            IZone zone, ref SetasideZone setasideZone)
        {
            var deck = new List <IPlayable>();

            foreach (Card card in predictedCards)
            {
                var tags = new Dictionary <GameTag, int>();
                tags[GameTag.ENTITY_ID]  = opponent.Game.NextId;
                tags[GameTag.CONTROLLER] = opponent.PlayerId;
                tags[GameTag.ZONE]       = (int)zone.Type;
                IPlayable playable = null;
                switch (card.Type)
                {
                case CardType.MINION:
                    playable = new Minion(opponent, card, tags);
                    break;

                case CardType.SPELL:
                    playable = new Spell(opponent, card, tags);
                    break;

                case CardType.WEAPON:
                    playable = new Weapon(opponent, card, tags);
                    break;

                case CardType.HERO:
                    tags[GameTag.ZONE]     = (int)SabberStoneCore.Enums.Zone.PLAY;
                    tags[GameTag.CARDTYPE] = card[GameTag.CARDTYPE];
                    playable = new Hero(opponent, card, tags);
                    break;

                case CardType.HERO_POWER:
                    tags[GameTag.COST]     = card[GameTag.COST];
                    tags[GameTag.ZONE]     = (int)SabberStoneCore.Enums.Zone.PLAY;
                    tags[GameTag.CARDTYPE] = card[GameTag.CARDTYPE];
                    playable = new HeroPower(opponent, card, tags);
                    break;

                default:
                    throw new EntityException($"Couldn't create entity, because of an unknown cardType {card.Type}.");
                }

                opponent.Game.IdEntityDic.Add(playable.Id, playable);

                // add entity to the appropriate zone if it was given
                zone?.Add(playable);

                if (playable.ChooseOne)
                {
                    playable.ChooseOnePlayables[0] = Entity.FromCard(opponent,
                                                                     Cards.FromId(playable.Card.Id + "a"),
                                                                     new Dictionary <GameTag, int>
                    {
                        [GameTag.CREATOR]     = playable.Id,
                        [GameTag.PARENT_CARD] = playable.Id
                    },
                                                                     setasideZone);
                    playable.ChooseOnePlayables[1] = Entity.FromCard(opponent,
                                                                     Cards.FromId(playable.Card.Id + "b"),
                                                                     new Dictionary <GameTag, int>
                    {
                        [GameTag.CREATOR]     = playable.Id,
                        [GameTag.PARENT_CARD] = playable.Id
                    },
                                                                     setasideZone);
                }
                deck.Add(playable);
            }
            return(deck);
        }