internal CardInstance Clone(Player owner)
        {
            var clonedCard = new CardInstance
            {
                Model = Model,
                Owner = owner,
                Guid = Guid,
                Zone = Zone
            };

            clonedCard.Behaviors.Capacity = Behaviors.Capacity;
            for (int i = 0; i < Behaviors.Count; ++i)
            {
                var bhv = Behaviors[i];
                clonedCard.Behaviors.Add(bhv.IsStatic ? bhv : (bhv.Model as Behaviors.IInternalBehaviorModel).Instantiate());
            }

            clonedCard.m_counters.Capacity = m_counters.Capacity;
            foreach (var item in m_counters)
            {
                clonedCard.m_counters.Add(item);
            }

            return clonedCard;
        }
Example #2
0
 internal Zone(Player owner, int id, ZoneType type, ZoneVisibility visibility)
 {
     Owner = owner;
     Id = id;
     Type = type;
     Visibility = visibility;
     CardInstances = type != ZoneType.Library ? new List<CardInstance>() : null;
     CardModels = type == ZoneType.Library ? new List<ICardModel>() : null;
 }
Example #3
0
        internal Zones(IIndexable<ZoneConfig> zoneConfigs, Player owner)
        {
            Debug.Assert(m_zones == null);

            m_zones = new Zone[zoneConfigs.Count];
            for (int i = 0; i < zoneConfigs.Count; ++i)
            {
                m_zones[i] = new Zone(owner, zoneConfigs[i].Id, zoneConfigs[i].Type, zoneConfigs[i].Visibility);
            }
        }
Example #4
0
        private CardInstance(ICardModel model, Player owner, bool hasGuid) : this()
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            else if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }

            Model = model;
            Owner = owner;
            Guid = hasGuid ? owner.Game.GenerateNextCardGuid() : 0;
            InstantiateBehaviors();
        }
Example #5
0
        public Game(List<string> playerNames, BaseController controller)
        {
            if (playerNames == null)
            {
                throw new ArgumentNullException("playerNames");
            }
            else if (controller == null)
            {
                throw new ArgumentNullException("controller");
            }
            else if (controller.Game != null)
            {
                throw new ArgumentException("The controller is already bound.", "controller");
            }

            int numPlayers = playerNames.Count;
            if (numPlayers != 2)
            {
                //TODO: support game among more than 2 players
                throw new NotSupportedException("Battle of more than two players are not supported.");
            }

            m_players = new Player[numPlayers];
            for (int i = 0; i < numPlayers; ++i)
            {
                m_players[i] = new Player(playerNames[i], i, this);
            }

            controller.Game = this;

            CurrentPhase = "";

            Players = m_players.ToIndexable();
            Random = new Random(controller.GetRandomSeed());
            Controller = controller;
            LetterBox = new Messaging.LetterBox();
        }
Example #6
0
        internal Player Clone(Game game)
        {
            var clonedPlayer = new Player(Name, Index, game);

            clonedPlayer.Health = Health;
            clonedPlayer.Mana = Mana;

            clonedPlayer.m_zones = new Zones(Game.ZoneConfigs, clonedPlayer);
            clonedPlayer.m_handSet = clonedPlayer.m_zones.GetZone(SystemZone.Hand).CardInstances;
            clonedPlayer.m_sacrifices = clonedPlayer.m_zones.GetZone(SystemZone.Sacrifice).CardInstances;
            clonedPlayer.m_battlefieldCards = clonedPlayer.m_zones.GetZone(SystemZone.Battlefield).CardInstances;
            clonedPlayer.m_assists = clonedPlayer.m_zones.GetZone(SystemZone.Assist).CardInstances;
            clonedPlayer.m_library = clonedPlayer.m_zones.GetZone(SystemZone.Library).CardModels;
            clonedPlayer.m_graveyard = clonedPlayer.m_zones.GetZone(SystemZone.Graveyard).CardModels;
            clonedPlayer.m_activatedAssists = new List<CardInstance>();

            clonedPlayer.CardsOnHand = clonedPlayer.m_handSet.ToIndexable();
            clonedPlayer.CardsSacrificed = clonedPlayer.m_sacrifices.ToIndexable();
            clonedPlayer.CardsOnBattlefield = clonedPlayer.m_battlefieldCards.ToIndexable();
            clonedPlayer.Assists = clonedPlayer.m_assists.ToIndexable();
            clonedPlayer.ActivatedAssits = clonedPlayer.m_activatedAssists.ToIndexable();
            clonedPlayer.Library = new Pile(clonedPlayer.m_library);
            clonedPlayer.Graveyard = new Pile(clonedPlayer.m_graveyard);

            clonedPlayer.m_manaAddModifiers.Capacity = m_manaAddModifiers.Capacity;
            foreach (var mod in m_manaAddModifiers)
            {
                clonedPlayer.m_manaAddModifiers.Add(mod);
            }

            clonedPlayer.m_manaSubtractModifiers.Capacity = m_manaSubtractModifiers.Capacity;
            foreach (var mod in m_manaSubtractModifiers)
            {
                clonedPlayer.m_manaSubtractModifiers.Add(mod);
            }

            clonedPlayer.m_lifeAddModifiers.Capacity = m_lifeAddModifiers.Capacity;
            foreach (var mod in m_lifeAddModifiers)
            {
                clonedPlayer.m_lifeAddModifiers.Add(mod);
            }

            clonedPlayer.m_lifeSubtractModifiers.Capacity = m_lifeSubtractModifiers.Capacity;
            foreach (var mod in m_lifeSubtractModifiers)
            {
                clonedPlayer.m_lifeSubtractModifiers.Add(mod);
            }

            clonedPlayer.m_handSet.Capacity = m_handSet.Capacity;
            for (int i = 0; i < m_handSet.Count; ++i)
            {
                clonedPlayer.m_handSet.Add(m_handSet[i].Clone(clonedPlayer));
            }

            clonedPlayer.m_sacrifices.Capacity = m_sacrifices.Capacity;
            for (int i = 0; i < m_sacrifices.Count; ++i)
            {
                clonedPlayer.m_sacrifices.Add(m_sacrifices[i].Clone(clonedPlayer));
            }

            clonedPlayer.m_battlefieldCards.Capacity = m_battlefieldCards.Capacity;
            for (int i = 0; i < m_battlefieldCards.Count; ++i)
            {
                var clonedCard = m_battlefieldCards[i].Clone(clonedPlayer);
                clonedPlayer.m_battlefieldCards.Add(clonedCard);
                clonedPlayer.Game.SubscribeCardToCommands(clonedCard);
            }

            if (Hero != null)
            {
                throw new NotImplementedException("Hero clone not implemented");
            }

            clonedPlayer.m_assists.Capacity = m_assists.Capacity;
            for (int i = 0; i < m_assists.Count; ++i)
            {
                clonedPlayer.m_assists.Add(m_assists[i].Clone(clonedPlayer));
            }

            clonedPlayer.m_activatedAssists.Capacity = m_activatedAssists.Capacity;
            for (int i = 0; i < m_activatedAssists.Count; ++i)
            {
                clonedPlayer.m_activatedAssists.Add(clonedPlayer.m_assists[m_assists.IndexOf(m_activatedAssists[i])]);
                clonedPlayer.Game.SubscribeCardToCommands(clonedPlayer.m_activatedAssists[i]);
            }

            clonedPlayer.m_library.Capacity = m_library.Capacity;
            for (int i = 0; i < m_library.Count; ++i)
            {
                clonedPlayer.m_library.Add(m_library[i]);
            }

            clonedPlayer.m_graveyard.Capacity = m_graveyard.Capacity;
            for (int i = 0; i < m_graveyard.Count; ++i)
            {
                clonedPlayer.m_graveyard.Add(m_graveyard[i]);
            }

            return clonedPlayer;
        }
Example #7
0
        internal void TransferCardsFrom(Player original)
        {
            for (int i = 0; i < m_handSet.Count; ++i)
            {
                m_handSet[i].TransferFrom(original.m_handSet[i]);
            }

            for (int i = 0; i < m_sacrifices.Count; ++i)
            {
                m_sacrifices[i].TransferFrom(original.m_sacrifices[i]);
            }

            for (int i = 0; i < m_battlefieldCards.Count; ++i)
            {
                m_battlefieldCards[i].TransferFrom(original.m_battlefieldCards[i]);
            }

            if (Hero != null)
            {
                throw new NotImplementedException("Hero clone not implemented");
            }

            for (int i = 0; i < m_assists.Count; ++i)
            {
                m_assists[i].TransferFrom(original.m_assists[i]);
            }
        }
Example #8
0
 internal CardInstance(ICardModel model, Player owner)
     : this(model, owner, true)
 { }