Exemple #1
0
        public bool HeroAttack(int gamePlayerID, int targetID, bool isTargetServant)
        {
            if (CurrentGamePlayerID != gamePlayerID)
            {
                return(false);
            }
            GamePlayer gamePlayer = (gamePlayerID == 1) ? GamePlayer1 : GamePlayer2;

            if (isTargetServant)
            {
                CardRecord targetCardRecord;
                if (GameCardManager.FindCard(targetID, out targetCardRecord) && targetCardRecord is ServantCardRecord)
                {
                    return(gamePlayer.Hero.AttackServant(targetCardRecord as ServantCardRecord, gamePlayer));
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                if (targetID != 1 && targetID != 2 || targetID == CurrentGamePlayerID)
                {
                    return(false);
                }
                else
                {
                    Hero hero = (targetID == 1) ? GamePlayer1.Hero : GamePlayer2.Hero;
                    return(gamePlayer.Hero.AttackHero(hero, gamePlayer));
                }
            }
        }
Exemple #2
0
        public bool NonTargeCasttSpell(int gamePlayerID, int spellCardRecordID)
        {
            if (CurrentGamePlayerID != gamePlayerID)
            {
                return(false);
            }
            CardRecord spellCardRecord;

            if (!GameCardManager.FindCard(spellCardRecordID, out spellCardRecord) || !(spellCardRecord is SpellCardRecord))
            {
                return(false);
            }
            if (spellCardRecord.Effectors(GameCardManager).Any(x => x is TargetEffector || x is MinionTargetEffector))
            {
                return(false);
            }
            GamePlayer gamePlayer = (gamePlayerID == 1) ? GamePlayer1 : GamePlayer2;

            if (CanUseCard(gamePlayer, spellCardRecord))
            {
                UseCard(gamePlayer, spellCardRecord);
                foreach (var effector in spellCardRecord.Effectors(GameCardManager))
                {
                    if (effector is AutoExecutetEffector)
                    {
                        (effector as AutoExecutetEffector).Affect(gamePlayer);
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #3
0
 private void Hero_OnWeaponChanged(Hero hero, DataChangeCode changeCode)
 {
     if (changeCode == DataChangeCode.Remove)
     {
         CardRecord record;
         if (GameCardManager.FindCard(hero.WeaponCardRecordID, out record) && record is WeaponCardRecord)
         {
             (record as WeaponCardRecord).Destroy();
         }
     }
 }
Exemple #4
0
        public GameDeck CreateGameDeck(int gameDeckID, Deck deck)
        {
            List <int> cardRecordIDs = new List <int>();

            foreach (Card card in deck.Cards)
            {
                cardRecordIDs.Add(GameCardManager.CreateCardRecord(card).CardRecordID);
            }
            GameDeck gameDeck = new GameDeck(gameDeckID, cardRecordIDs);

            gameDeck.Shuffle(100);
            return(gameDeck);
        }
Exemple #5
0
        public WeaponCardRecord Weapon(GameCardManager gameCardManager)
        {
            CardRecord card;

            if (gameCardManager.FindCard(WeaponCardRecordID, out card) && (card is WeaponCardRecord))
            {
                return(card as WeaponCardRecord);
            }
            else
            {
                return(null);
            }
        }
Exemple #6
0
 public Game(int gameID, GamePlayer gamePlayer1, GamePlayer gamePlayer2, int roundCount, int currentGamePlayerID, GameCardManager gameCardManager)
 {
     GameID              = gameID;
     GamePlayer1         = gamePlayer1;
     GamePlayer2         = gamePlayer2;
     RoundCount          = roundCount;
     CurrentGamePlayerID = currentGamePlayerID;
     Field1              = new Field(1);
     Field1.BindGame(this);
     Field2 = new Field(2);
     Field2.BindGame(this);
     GameCardManager = gameCardManager;
     EventManager    = new GameEventManager(this);
 }
Exemple #7
0
        public IEnumerable <CardRecord> Cards(GameCardManager gameCardManager)
        {
            List <CardRecord> cards = new List <CardRecord>();

            foreach (var fieldCard in FieldCards)
            {
                CardRecord cardRecord;
                if (gameCardManager.FindCard(fieldCard.CardRecordID, out cardRecord))
                {
                    cards.Add(cardRecord);
                }
            }
            return(cards);
        }
Exemple #8
0
        public IEnumerable <Effector> Effectors(GameCardManager gameCardManager)
        {
            List <Effector> efffectors = new List <Effector>();

            foreach (var effectorID in EffectorIDs)
            {
                Effector efffector;
                if (gameCardManager.FindEffector(effectorID, out efffector))
                {
                    efffectors.Add(efffector);
                }
            }
            return(efffectors);
        }
Exemple #9
0
 private void AssemblyFieldEvents(Field field)
 {
     field.OnCardChanged += (fieldCardRecord, changeCode) =>
     {
         if (changeCode == DataChangeCode.Add)
         {
             CardRecord record;
             if (GameCardManager.FindCard(fieldCardRecord.CardRecordID, out record) && record is ServantCardRecord)
             {
                 (record as ServantCardRecord).OnDestroyed += (servantCard) =>
                 {
                     field.RemoveCard(fieldCardRecord.CardRecordID);
                 };
             }
         }
     };
 }
Exemple #10
0
        public bool NonTargetDisplayServant(int gamePlayerID, int servantCardRecordID, int positionIndex)
        {
            if (CurrentGamePlayerID != gamePlayerID)
            {
                return(false);
            }
            Field field = (gamePlayerID == 1) ? Field1 : Field2;

            if (!field.DisplayCheck(positionIndex))
            {
                return(false);
            }
            CardRecord servantCardRecord;

            if (!GameCardManager.FindCard(servantCardRecordID, out servantCardRecord) || !(servantCardRecord is ServantCardRecord))
            {
                return(false);
            }
            if (servantCardRecord.Effectors(GameCardManager).Any(x => x is TargetEffector || x is MinionTargetEffector))
            {
                return(false);
            }
            GamePlayer gamePlayer = (gamePlayerID == 1) ? GamePlayer1 : GamePlayer2;

            if (CanUseCard(gamePlayer, servantCardRecord))
            {
                UseCard(gamePlayer, servantCardRecord);
                foreach (var effector in servantCardRecord.Effectors(GameCardManager))
                {
                    if (effector is AutoExecutetEffector)
                    {
                        (effector as AutoExecutetEffector).Affect(gamePlayer);
                    }
                }
                (servantCardRecord as ServantCardRecord).IsDisplayInThisTurn = true;
                field.AddCard(servantCardRecordID, positionIndex);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #11
0
        public Game(int gameID, Player player1, Player player2, Deck player1Deck, Deck player2Deck)
        {
            GameCardManager = new GameCardManager();
            GameCardManager.BindGame(this);

            GameID      = gameID;
            GamePlayer1 = new GamePlayer(player1, new Hero(1, 30, 30), CreateGameDeck(1, player1Deck));
            GamePlayer1.BindGame(this);
            GamePlayer2 = new GamePlayer(player2, new Hero(2, 30, 30), CreateGameDeck(2, player2Deck));
            GamePlayer2.BindGame(this);
            RoundCount = 0;
            Random randomGenerator = new Random();

            if (randomGenerator.NextDouble() > 0.5)
            {
                CurrentGamePlayerID = 1;
                GamePlayer1.Draw(3);
                GamePlayer2.Draw(4);
            }
            else
            {
                CurrentGamePlayerID = 2;
                GamePlayer1.Draw(4);
                GamePlayer2.Draw(3);
            }
            Field1 = new Field(1);
            Field1.BindGame(this);
            Field2 = new Field(2);
            Field2.BindGame(this);

            AssemblyGamePlayerEvents(GamePlayer1);
            AssemblyGamePlayerEvents(GamePlayer2);
            AssemblyFieldEvents(Field1);
            AssemblyFieldEvents(Field2);

            EventManager = new GameEventManager(this);
        }
Exemple #12
0
        //public bool TargetEquipWeapon(int gamePlayerID, int weaponCardRecordID, int targetID, bool isTargetServant)
        //{
        //    if (CurrentGamePlayerID != gamePlayerID)
        //        return false;
        //    CardRecord weaponCardRecord;
        //    if (!GameCardManager.FindCard(weaponCardRecordID, out weaponCardRecord) || !(weaponCardRecord is WeaponCardRecord))
        //        return false;
        //    if (!weaponCardRecord.Effectors(GameCardManager).Any(x => x is TargetEffector || x is MinionTargetEffector))
        //        return false;
        //    GamePlayer gamePlayer = (gamePlayerID == 1) ? GamePlayer1 : GamePlayer2;
        //    if (CanUseCard(gamePlayer, weaponCardRecord))
        //    {
        //        if (isTargetServant)
        //        {
        //            CardRecord targetCardRecord;
        //            if (GameCardManager.FindCard(targetID, out targetCardRecord) && targetCardRecord is ServantCardRecord)
        //            {
        //                UseCard(gamePlayer, weaponCardRecord);
        //                foreach (var effector in weaponCardRecord.Effectors(GameCardManager))
        //                {
        //                    if (effector is TargetEffector)
        //                    {
        //                        (effector as TargetEffector).AffectServant(targetCardRecord as ServantCardRecord, gamePlayer);
        //                    }
        //                    else if (effector is MinionTargetEffector)
        //                    {
        //                        (effector as MinionTargetEffector).AffectServant(targetCardRecord as ServantCardRecord, gamePlayer);
        //                    }
        //                    else if (effector is AutoExecutetEffector)
        //                    {
        //                        (effector as AutoExecutetEffector).Affect(gamePlayer);
        //                    }
        //                }
        //            }
        //            else
        //            {
        //                return false;
        //            }
        //        }
        //        else
        //        {
        //            if (targetID != 1 && targetID != 2)
        //                return false;
        //            else
        //            {
        //                UseCard(gamePlayer, weaponCardRecord);
        //                Hero hero = (targetID == 1) ? GamePlayer1.Hero : GamePlayer2.Hero;
        //                foreach (var effector in weaponCardRecord.Effectors(GameCardManager))
        //                {
        //                    if (effector is TargetEffector)
        //                    {
        //                        (effector as TargetEffector).AffectHero(hero, gamePlayer);
        //                    }
        //                    else if (effector is AutoExecutetEffector)
        //                    {
        //                        (effector as AutoExecutetEffector).Affect(gamePlayer);
        //                    }
        //                }
        //            }
        //        }
        //        gamePlayer.Hero.WeaponCardRecordID = weaponCardRecordID;
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}
        public bool NonTargetEquipWeapon(int gamePlayerID, int weaponCardRecordID)
        {
            if (CurrentGamePlayerID != gamePlayerID)
            {
                return(false);
            }
            CardRecord weaponCardRecord;

            if (!GameCardManager.FindCard(weaponCardRecordID, out weaponCardRecord) || !(weaponCardRecord is WeaponCardRecord))
            {
                return(false);
            }
            if (weaponCardRecord.Effectors(GameCardManager).Any(x => x is TargetEffector || x is MinionTargetEffector))
            {
                return(false);
            }
            GamePlayer gamePlayer = (gamePlayerID == 1) ? GamePlayer1 : GamePlayer2;

            if (CanUseCard(gamePlayer, weaponCardRecord))
            {
                UseCard(gamePlayer, weaponCardRecord);
                foreach (var effector in weaponCardRecord.Effectors(GameCardManager))
                {
                    if (effector is AutoExecutetEffector)
                    {
                        (effector as AutoExecutetEffector).Affect(gamePlayer);
                    }
                }
                gamePlayer.Hero.WeaponCardRecordID = weaponCardRecordID;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #13
0
        public bool TargetCastSpell(int gamePlayerID, int spellCardRecordID, int targetID, bool isTargetServant)
        {
            if (CurrentGamePlayerID != gamePlayerID)
            {
                return(false);
            }
            CardRecord spellCardRecord;

            if (!GameCardManager.FindCard(spellCardRecordID, out spellCardRecord) || !(spellCardRecord is SpellCardRecord))
            {
                return(false);
            }
            if (!spellCardRecord.Effectors(GameCardManager).Any(x => x is TargetEffector || (isTargetServant && x is MinionTargetEffector)))
            {
                return(false);
            }
            GamePlayer gamePlayer = (gamePlayerID == 1) ? GamePlayer1 : GamePlayer2;

            if (CanUseCard(gamePlayer, spellCardRecord))
            {
                if (isTargetServant)
                {
                    CardRecord targetCardRecord;
                    if (GameCardManager.FindCard(targetID, out targetCardRecord) && targetCardRecord is ServantCardRecord)
                    {
                        UseCard(gamePlayer, spellCardRecord);
                        foreach (var effector in spellCardRecord.Effectors(GameCardManager))
                        {
                            if (effector is TargetEffector)
                            {
                                (effector as TargetEffector).AffectServant(targetCardRecord as ServantCardRecord, gamePlayer);
                            }
                            else if (effector is MinionTargetEffector)
                            {
                                (effector as MinionTargetEffector).AffectServant(targetCardRecord as ServantCardRecord, gamePlayer);
                            }
                            else if (effector is AutoExecutetEffector)
                            {
                                (effector as AutoExecutetEffector).Affect(gamePlayer);
                            }
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    if (targetID != 1 && targetID != 2)
                    {
                        return(false);
                    }
                    else
                    {
                        UseCard(gamePlayer, spellCardRecord);
                        Hero hero = (targetID == 1) ? GamePlayer1.Hero : GamePlayer2.Hero;
                        foreach (var effector in spellCardRecord.Effectors(GameCardManager))
                        {
                            if (effector is TargetEffector)
                            {
                                (effector as TargetEffector).AffectHero(hero, gamePlayer);
                            }
                            else if (effector is AutoExecutetEffector)
                            {
                                (effector as AutoExecutetEffector).Affect(gamePlayer);
                            }
                        }
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #14
0
        public bool TargetDisplayServant(int gamePlayerID, int servantCardRecordID, int positionIndex, int targetID, bool isTargetServant)
        {
            if (CurrentGamePlayerID != gamePlayerID)
            {
                return(false);
            }
            Field field = (gamePlayerID == 1) ? Field1 : Field2;

            if (!field.DisplayCheck(positionIndex))
            {
                return(false);
            }
            CardRecord servantCardRecord;

            if (!GameCardManager.FindCard(servantCardRecordID, out servantCardRecord) || !(servantCardRecord is ServantCardRecord))
            {
                return(false);
            }
            if (!servantCardRecord.Effectors(GameCardManager).Any(x => x is TargetEffector || (isTargetServant && x is MinionTargetEffector)))
            {
                return(false);
            }
            GamePlayer gamePlayer = (gamePlayerID == 1) ? GamePlayer1 : GamePlayer2;

            if (CanUseCard(gamePlayer, servantCardRecord))
            {
                if (isTargetServant)
                {
                    CardRecord targetCardRecord;
                    if (GameCardManager.FindCard(targetID, out targetCardRecord) && targetCardRecord is ServantCardRecord)
                    {
                        UseCard(gamePlayer, servantCardRecord);
                        foreach (var effector in servantCardRecord.Effectors(GameCardManager))
                        {
                            if (effector is TargetEffector)
                            {
                                (effector as TargetEffector).AffectServant(targetCardRecord as ServantCardRecord, gamePlayer);
                            }
                            else if (effector is MinionTargetEffector)
                            {
                                (effector as MinionTargetEffector).AffectServant(targetCardRecord as ServantCardRecord, gamePlayer);
                            }
                            else if (effector is AutoExecutetEffector)
                            {
                                (effector as AutoExecutetEffector).Affect(gamePlayer);
                            }
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    if (targetID != 1 && targetID != 2)
                    {
                        return(false);
                    }
                    else
                    {
                        UseCard(gamePlayer, servantCardRecord);
                        Hero hero = (targetID == 1) ? GamePlayer1.Hero : GamePlayer2.Hero;
                        foreach (var effector in servantCardRecord.Effectors(GameCardManager))
                        {
                            if (effector is TargetEffector)
                            {
                                (effector as TargetEffector).AffectHero(hero, gamePlayer);
                            }
                            else if (effector is AutoExecutetEffector)
                            {
                                (effector as AutoExecutetEffector).Affect(gamePlayer);
                            }
                        }
                    }
                }
                (servantCardRecord as ServantCardRecord).IsDisplayInThisTurn = true;
                field.AddCard(servantCardRecordID, positionIndex);
                return(true);
            }
            else
            {
                return(false);
            }
        }