示例#1
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);
        }