Exemplo n.º 1
0
        public static void JoinRoom(Client client, string roomName)
        {
            client.account.chatroomList.Add(roomName);

            RoomAPI.AddPlayer(roomName, client.account.username);
            List<string> playerList = RoomAPI.GetPlayerList(roomName);

            RoomEnter roomEnterServer = new RoomEnter();
            roomEnterServer.roomName = roomName;

            client.Send(roomEnterServer);

            RoomInfo roomInfo = new RoomInfo();
            roomInfo.updated  = new List<RoomInfo.PlayerInfo>();
            roomInfo.roomName = roomName;
            roomInfo.reset    = false;

            foreach (string playerName in playerList)
            {
                Client roomClient = PlayerAPI.GetSession(playerName, false);

                RoomInfo.PlayerInfo playerInfo = new RoomInfo.PlayerInfo();
                playerInfo.id               = roomClient.account.id;
                playerInfo.name             = roomClient.account.username;
                playerInfo.acceptChallenges = roomClient.account.acceptChallenges;
                playerInfo.acceptTrades     = roomClient.account.acceptTrades;
                playerInfo.adminRole        = roomClient.account.adminRole;

                roomInfo.updated.Add(playerInfo);
            }

            client.Send(roomInfo);

            RoomAPI.Message(roomName, "Scrolls", "You have joined \"" + roomName + "\"", client);

            RoomInfo newPlayerAlert = new RoomInfo();
            newPlayerAlert.updated  = new List<RoomInfo.PlayerInfo>();
            newPlayerAlert.roomName = roomName;

            RoomInfo.PlayerInfo newPlayerInfo = new RoomInfo.PlayerInfo();
            newPlayerInfo.id               = client.account.id;
            newPlayerInfo.name             = client.account.username;
            newPlayerInfo.acceptChallenges = client.account.acceptChallenges;
            newPlayerInfo.acceptTrades     = client.account.acceptTrades;
            newPlayerInfo.adminRole        = client.account.adminRole;

            newPlayerAlert.updated.Add(newPlayerInfo);

            foreach (string playerName in playerList)
            {
                PlayerAPI.GetSession(playerName, false).Send(newPlayerAlert);
            }
        }
Exemplo n.º 2
0
        public static void DeckCards(Client client, string jsonPacketData)
        {
            client.packetMap.Remove("DeckCards");

            DeckCards deckCardsClient = JsonConvert.DeserializeObject<DeckCards>(jsonPacketData);
            DeckCards deckCardsServer = new DeckCards();

            if (client.account.deckMap.ContainsKey(deckCardsClient.deck))
            {
                Deck deck = client.account.deckMap[deckCardsClient.deck];

                deckCardsServer.deck     = deckCardsClient.deck;
                deckCardsServer.valid    = deck.valid;
                deckCardsServer.metadata = deck.metadata;

                foreach (string resource in deck.resources)
                {
                    deckCardsServer.resources.Add(resource);
                }

                foreach (Card card in deck.cards)
                {
                    deckCardsServer.cards.Add(card);
                }

                client.Send(deckCardsServer);
            }
            else
            {
                Console.WriteLine("{0} requested the deck {1} which they don't own!", client.account.username, deckCardsClient.deck);
                PlayerAPI.KickPlayer(client, "AntiCheat: You have been disconnected from the server!");
            }
        }
Exemplo n.º 3
0
        public static void KickPlayer(Client client, string reason)
        {
            FailMessage failMessage = new FailMessage();
            failMessage.op   = "Reconnect";
            failMessage.info = reason;

            client.Send(failMessage);

            FailMessage infoFailMessage = new FailMessage();
            infoFailMessage.info = reason;

            client.Send(infoFailMessage);

            Variables.sessionMap.Remove(client.account.username);
            client.account = new Account();
        }
Exemplo n.º 4
0
        public static void PurchaseItem(Client client, string itemType)
        {
            BuyStoreItemResponse buyStoreItemResponse = new BuyStoreItemResponse();

            Random random = new Random();

            switch (itemType)
            {
                case "CARD_DECAY":
                    {
                        Card card = CardAPI.AddCard(client, Variables.cardTypeDecayMap[Variables.cardTypeDecayMap.Keys.ToList()[random.Next(Variables.cardTypeDecayMap.Count)]]);
                        buyStoreItemResponse.cards.Add(card);

                        break;
                    }
                case "CARD_ENERGY":
                    {
                        Card card = CardAPI.AddCard(client, Variables.cardTypeEnergyMap[Variables.cardTypeEnergyMap.Keys.ToList()[random.Next(Variables.cardTypeEnergyMap.Count)]]);
                        buyStoreItemResponse.cards.Add(card);

                        break;
                    }
                case "CARD_FACE_DOWN":
                    {
                        Card card = CardAPI.AddCard(client, Variables.cardTypeMap[Variables.cardTypeMap.Keys.ToList()[random.Next(Variables.cardTypeMap.Count)]]);
                        buyStoreItemResponse.cards.Add(card);

                        break;
                    }
                case "CARD_GROWTH":
                    {
                        Card card = CardAPI.AddCard(client, Variables.cardTypeGrowthMap[Variables.cardTypeGrowthMap.Keys.ToList()[random.Next(Variables.cardTypeGrowthMap.Count)]]);
                        buyStoreItemResponse.cards.Add(card);

                        break;
                    }
                case "CARD_ORDER":
                    {
                        Card card = CardAPI.AddCard(client, Variables.cardTypeOrderMap[Variables.cardTypeOrderMap.Keys.ToList()[random.Next(Variables.cardTypeOrderMap.Count)]]);
                        buyStoreItemResponse.cards.Add(card);

                        break;
                    }
                case "CARD_PACK":
                    {
                        for (int i = 0; i < 10; i++)
                        {
                            Card card = CardAPI.AddCard(client, Variables.cardTypeMap[Variables.cardTypeMap.Keys.ToList()[random.Next(Variables.cardTypeMap.Count)]]);
                            buyStoreItemResponse.cards.Add(card);
                        }

                        break;
                    }
            }

            client.Send(buyStoreItemResponse);
        }
Exemplo n.º 5
0
        public static void LobbyLookup(Client client)
        {
            client.packetMap.Remove("LobbyLookup");

            LobbyLookup lobbyLookup = new LobbyLookup();
            lobbyLookup.ip   = ConfigReader.serverHost;
            lobbyLookup.port = ConfigReader.lobbyPort;

            client.Send(lobbyLookup);
        }
Exemplo n.º 6
0
        public static void AvatarTypes(Client client)
        {
            client.packetMap.Remove("AvatarTypes");

            AvatarTypes avatarTypes = new AvatarTypes();

            foreach (KeyValuePair<int, AvatarType> avatarType in Variables.avatarTypeMap)
            {
                avatarTypes.types.Add(avatarType.Value);
            }

            client.Send(avatarTypes);
        }
Exemplo n.º 7
0
        public static void ProfileInfo(Client client)
        {
            client.packetMap.Remove("ProfileInfo");

            ProfileInfo profileInfo = new ProfileInfo();
            profileInfo.profile.id               = client.account.id;
            profileInfo.profile.userUuid         = ""; //Note: Unsure what exactly the userUuid does or how it is generated
            profileInfo.profile.name             = client.account.username;
            profileInfo.profile.acceptChallenges = client.account.acceptChallenges;
            profileInfo.profile.acceptTrades     = client.account.acceptTrades;
            profileInfo.profile.adminRole        = client.account.adminRole;
            profileInfo.profile.userType         = "Beta";

            client.Send(profileInfo);
        }
Exemplo n.º 8
0
        public static void ProfileDataInfo(Client client)
        {
            client.packetMap.Remove("ProfileDataInfo");

            ProfileDataInfo profileDataInfo = new ProfileDataInfo();
            profileDataInfo.profileData.gold   = client.account.gold;
            profileDataInfo.profileData.shards = client.account.shards;
            profileDataInfo.profileData.rating = 0;

            if (client.account.selectedPreconstructed != 0)
            {
                profileDataInfo.profileData.selectedPreconstructed = client.account.selectedPreconstructed;
            }

            client.Send(profileDataInfo);
        }
Exemplo n.º 9
0
        public static void BuyStoreItem(Client client, string jsonPacketData)
        {
            client.packetMap.Remove("BuyStoreItem");

            BuyStoreItem buyStoreItem = JsonConvert.DeserializeObject<BuyStoreItem>(jsonPacketData);

            string purchaseMessage = "";
            StoreItem storeItem    = null;

            if (Variables.storeItemMap.ContainsKey(buyStoreItem.itemId))
            {
                storeItem = Variables.storeItemMap[buyStoreItem.itemId];

                if (buyStoreItem.payWithShards)
                {
                    if (client.account.shards >= storeItem.costShards)
                    {
                        PlayerAPI.RemoveShards(client, storeItem.costShards);
                    }
                    else { purchaseMessage  = "Not enough shards to purchase this item."; }
                }
                else
                {
                    if (client.account.gold >= storeItem.costGold)
                    {
                        PlayerAPI.RemoveGold(client, storeItem.costGold);
                    }
                    else { purchaseMessage = "Not enough gold to purchase this item."; }
                }
            }

            if (String.IsNullOrEmpty(purchaseMessage))
            {
                StoreItemHandler.PurchaseItem(client, storeItem.itemType);
                ProfileHandler.ProfileDataInfo(client);

                PlayerAPI.UpdateScrollTypeCount(client);
            }
            else
            {
                FailMessage failMessage = new FailMessage();
                failMessage.op   = "BuyStoreItem";
                failMessage.info = purchaseMessage;

                client.Send(failMessage);
            }
        }
Exemplo n.º 10
0
        public static void Reconnect(Client client, string jsonPacketData)
        {
            client.packetMap.Remove("Reconnect");

            Reconnect reconnect = JsonConvert.DeserializeObject<Reconnect>(jsonPacketData);

            if (InternalSignIn(client, reconnect.email, reconnect.password))
            {
                OkMessage okMessage = new OkMessage();
                okMessage.op = "Reconnect";

                client.Send(okMessage);

                ProfileHandler.ProfileInfo(client);
                ProfileHandler.ProfileDataInfo(client);
            }
        }
Exemplo n.º 11
0
        public static void OverallStats(Client client)
        {
            client.packetMap.Remove("OverallStats");

            SQLResult serverStatsResult = DB.Database.Select(client.connection, true, false, "SELECT * FROM server_stats");
            SQLResult cardCountResult   = DB.Database.Select(client.connection, false, true, "SELECT COUNT(*) FROM account_cards");

            OverallStats overallStats = new OverallStats();
            overallStats.serverName        = ConfigReader.serverName;
            overallStats.loginsLast24h     = serverStatsResult.Read<int>(0, "loginsLast24h");
            overallStats.totalCards        = cardCountResult.Read  <int>(0, "COUNT(*)"); //Note: Maybe some sort of cache instead?
            overallStats.totalGoldRewarded = serverStatsResult.Read<int>(0, "totalGoldRewarded");
            overallStats.totalSoldCards    = serverStatsResult.Read<int>(0, "totalSoldCards"); ;
            overallStats.nrOfProfiles      = Variables.sessionMap.Count;

            client.Send(overallStats);
        }
Exemplo n.º 12
0
        public static void SignIn(Client client, string jsonPacketData)
        {
            client.packetMap.Remove("SignIn");

            SignIn signIn = JsonConvert.DeserializeObject<SignIn>(jsonPacketData);

            if (InternalSignIn(client, signIn.email, signIn.password))
            {
                OkMessage okMessage = new OkMessage();
                okMessage.op = "SignIn";

                client.Send(okMessage);

                ProfileHandler.ProfileInfo(client);
                ProfileHandler.ProfileDataInfo(client);
            }
        }
Exemplo n.º 13
0
        public static void DeckDelete(Client client, string jsonPacketData)
        {
            client.packetMap.Remove("DeckDelete");

            DeckDelete deckDelete = JsonConvert.DeserializeObject<DeckDelete>(jsonPacketData);

            if (client.account.deckMap.ContainsKey(deckDelete.name))
            {
                int lastId;
                DB.Database.Execute(client.connection, out lastId, true, true, "DELETE FROM account_decks WHERE guid = ? AND name = ?", client.account.id, deckDelete.name);

                client.account.deckMap.Remove(deckDelete.name);

                OkMessage okMessage = new OkMessage();
                okMessage.op = "DeckDelete";

                client.Send(okMessage);
            }
            else
            {
                Console.WriteLine("{0} is trying to delete the deck {1} which they don't own!", client.account.username, deckDelete.name);
                PlayerAPI.KickPlayer(client, "AntiCheat: You have been disconnected from the server!");
            }
        }
Exemplo n.º 14
0
        public static void DeckList(Client client)
        {
            client.packetMap.Remove("DeckList");

            DeckList deckList = new DeckList();

            foreach (KeyValuePair<string, Deck> deckServer in client.account.deckMap)
            {
                DeckList.Deck deckClient = new DeckList.Deck();
                deckClient.name = deckServer.Value.name;

                string resources = "";
                foreach (string resource in deckServer.Value.resources)
                {
                    resources += resource + ",";
                }

                resources.Remove(resources.Length - 1);

                deckClient.resources = resources;
                deckClient.valid     = deckServer.Value.valid;
                deckClient.timestamp = deckServer.Value.timestamp;

                DateTime dateTimeTimestamp = new DateTime(deckServer.Value.timestamp);
                DateTime dateTimeNow       = DateTime.Now;

                TimeBlock timeBlock = new TimeBlock(dateTimeTimestamp, dateTimeNow);

                if (timeBlock.DurationDescription == String.Empty)
                {
                    deckClient.updated = "A few moments ago";
                }
                else
                {
                    deckClient.updated = timeBlock.DurationDescription;
                }

                deckList.decks.Add(deckClient);

            }

            client.Send(deckList);
        }
Exemplo n.º 15
0
        public static void LibraryView(Client client)
        {
            client.packetMap.Remove("LibraryView");

            LibraryView libraryView = new LibraryView();
            libraryView.profileId   = client.account.id;

            foreach (KeyValuePair<int, Card> cardServer in client.account.cardMap)
            {
                libraryView.cards.Add(cardServer.Value);
            }

            client.Send(libraryView);
        }
Exemplo n.º 16
0
        public static void DeckValidate(Client client, string jsonPacketData)
        {
            client.packetMap.Remove("DeckValidate");

            client.account.deckValidate.Clear();

            Dictionary<int, int> cardCount = new Dictionary<int, int>();

            int cardTotal       = 0;
            bool cardsValidated = true;
            string failMessage  = "";

            DeckValidate deckValidateClient = JsonConvert.DeserializeObject<DeckValidate>(jsonPacketData);
            DeckValidate deckValidateServer = new DeckValidate();

            foreach (int cardId in deckValidateClient.cards)
            {
                if (client.account.cardMap.ContainsKey(cardId))
                {
                    Card card = CardAPI.GetCard(client, cardId);

                    if (!cardCount.ContainsKey(card.typeId))
                    {
                        cardCount.Add(card.typeId, 1);
                    }
                    else
                    {
                        cardCount[card.typeId]++;

                        if (cardCount[card.typeId] >= 4)
                        {
                            cardsValidated = false;
                            failMessage    = client.account.username + " failed card validation: Too many cards of type " + card.typeId + "!";

                            break;
                        }
                    }

                    client.account.deckValidate.Add(cardId);
                    cardTotal++;
                }
                else
                {
                    cardsValidated = false;
                    failMessage    = client.account.username + " failed card validation: Player doesn't own card ID " + cardId + "!";

                    break;
                }
            }

            if (cardsValidated == true)
            {
                deckValidateServer.errors = new List<DeckValidate.Error>();

                if (cardTotal < 50)
                {
                    //Note: Game doesn't respond with deck save dialog when sending an error. Doing something wrong?
                }

                client.Send(deckValidateServer);
            }
            else
            {
                Console.WriteLine(failMessage);
                PlayerAPI.KickPlayer(client, "AntiCheat: You have been disconnected from the server!");
            }
        }
Exemplo n.º 17
0
        public static void PlayCardInfo(Client client, string jsonPacketData)
        {
            client.packetMap.Remove("PlayCardInfo");

            PlayCardInfo playCardInfo = JsonConvert.DeserializeObject<PlayCardInfo>(jsonPacketData);

            Battle battle = BattleAPI.GetBattle(client.account.username);

            if (battle.handMap.ContainsKey(playCardInfo.card))
            {
                Card card         = battle.handMap[playCardInfo.card];
                CardType cardType = CardAPI.GetCardType(card.typeId);

                CardInfo cardInfo = new CardInfo();
                cardInfo.card = card;

                if (BattleAPI.EnoughResources(battle, cardType))
                {
                    cardInfo.hasEnoughResources = true;
                    cardInfo.isPlayable         = true;

                    if (cardType.kind == "CREATURE" || cardType.kind == "STRUCTURE")
                    {
                        List<CardInfo.Data.SelectableTiles.TileSet> tileSets = new List<CardInfo.Data.SelectableTiles.TileSet>();

                        for (int i = 0; i < 5; i++)
                        {
                            for (int ii = 0; ii < 3; ii++)
                            {
                                if (battle.board[ii, i] == null)
                                {
                                    CardInfo.Data.SelectableTiles.TileSet tileSet = new CardInfo.Data.SelectableTiles.TileSet();
                                    tileSet.color    = battle.color;
                                    tileSet.position = i + "," + ii;

                                    tileSets.Add(tileSet);
                                }
                            }
                        }

                        cardInfo.data.selectableTiles.tileSets.Add(tileSets);
                    }
                    else
                    {
                        cardInfo.data.selectableTiles.tileSets.Add(RuleHandler.HandleCardSelect(battle, cardType));
                    }

                    if (cardType.targetArea == String.Empty)
                    {
                        cardType.targetArea = "TILE";
                    }
                    else
                    {
                        cardInfo.data.targetArea = cardType.targetArea;
                    }
                }
                else
                {
                    cardInfo.hasEnoughResources = false;
                    cardInfo.isPlayable         = false;

                    cardInfo.alerts.Add("Not enough resources");
                }

                client.Send(cardInfo);
            }
            else
            {
                Console.WriteLine("{0} requested card information on card {1} which they don't have in hand!", client.account.username, playCardInfo.card);
            }
        }
Exemplo n.º 18
0
        public static void GameChallengeDecline(Client client, string jsonPacketData)
        {
            client.packetMap.Remove("GameChallengeDecline");

            GameChallengeDecline gameChallengeDecline = JsonConvert.DeserializeObject<GameChallengeDecline>(jsonPacketData);
            Client opponentSession = PlayerAPI.GetSession(gameChallengeDecline.profile, true);

            if (PlayerAPI.IsOnline(opponentSession.account.username))
            {
                OkMessage okMessage = new OkMessage();
                okMessage.op = "GameChallengeDecline";

                client.Send(okMessage);

                GameChallengeResponse gameChallengeResponse = new GameChallengeResponse();
                gameChallengeResponse.status = "DECLINE";

                gameChallengeResponse.from.id               = opponentSession.account.id;
                gameChallengeResponse.from.userUuid         = "";
                gameChallengeResponse.from.name             = opponentSession.account.username;
                gameChallengeResponse.from.acceptChallenges = opponentSession.account.acceptChallenges;
                gameChallengeResponse.from.acceptTrades     = opponentSession.account.acceptTrades;
                gameChallengeResponse.from.adminRole        = opponentSession.account.adminRole;
                gameChallengeResponse.from.userType         = "Beta";

                gameChallengeResponse.to.id               = client.account.id;
                gameChallengeResponse.to.userUuid         = "";
                gameChallengeResponse.to.name             = client.account.username;
                gameChallengeResponse.to.acceptChallenges = client.account.acceptChallenges;
                gameChallengeResponse.to.acceptTrades     = client.account.acceptTrades;
                gameChallengeResponse.to.adminRole        = client.account.adminRole;
                gameChallengeResponse.to.userType         = "Beta";

                client.Send(gameChallengeResponse);
                opponentSession.Send(gameChallengeResponse);
            }
        }
Exemplo n.º 19
0
        public static void UpdateHand(Client client, Battle battle)
        {
            NewEffects newEffects = new NewEffects();

            NewEffects.Effect handUpdateEffect = new NewEffects.Effect();
            handUpdateEffect.HandUpdate        = new NewEffects.Effect.HandUpdateEffect();

            handUpdateEffect.HandUpdate.profileId = client.account.id;

            foreach (KeyValuePair<int, Card> card in battle.handMap)
            {
                handUpdateEffect.HandUpdate.cards.Add(card.Value);
            }

            newEffects.effects.Add(handUpdateEffect);

            client.Send(newEffects);
        }
Exemplo n.º 20
0
        public static void GetStoreItems(Client client)
        {
            client.packetMap.Remove("GetStoreItems");

            GetStoreItems getStoreItems = new GetStoreItems();

            foreach (KeyValuePair<int, StoreItem> storeItem in Variables.storeItemMap)
            {
                if (storeItem.Value.isPublic)
                {
                    getStoreItems.items.Add(storeItem.Value);
                }
            }

            getStoreItems.cardSellbackGold.Add(ConfigReader.sellCommon);
            getStoreItems.cardSellbackGold.Add(ConfigReader.sellUncommon);
            getStoreItems.cardSellbackGold.Add(ConfigReader.sellRare);
            getStoreItems.cardSellbackGold.Add(1000);
            getStoreItems.cardSellbackGold.Add(1000);
            getStoreItems.cardSellbackGold.Add(1000);

            client.Send(getStoreItems);
        }
Exemplo n.º 21
0
        public static void Redirect(Client client)
        {
            BattleRedirect battleRedirect = new BattleRedirect();
            battleRedirect.ip   = ConfigReader.serverHost;
            battleRedirect.port = ConfigReader.battlePort;

            client.Send(battleRedirect);
        }
Exemplo n.º 22
0
        public static void GameInfo(Client client)
        {
            client.packetMap.Remove("GameInfo");

            Battle battle         = BattleAPI.GetBattle(client.account.username);
            Client opponentClient = PlayerAPI.GetSession(battle.opponent, false);

            GameInfo gameInfo = new GameInfo();

            gameInfo.gameType          = battle.gameType;
            gameInfo.deck              = battle.deck.name;
            gameInfo.gameId            = 1;
            gameInfo.color             = battle.color;
            gameInfo.roundTimerSeconds = 90;
            gameInfo.phase             = battle.phase;
            gameInfo.rewardForIdolKill = 10;
            gameInfo.nodeId            = ConfigReader.serverHost;
            gameInfo.port              = ConfigReader.lobbyPort;

            Account whiteAccount; Account blackAccount;

            if (battle.color == "white")
            {
                gameInfo.white = client.account.username;
                gameInfo.black = battle.opponent;
                whiteAccount   = client.account;
                blackAccount   = opponentClient.account;
            }
            else
            {
                gameInfo.white = battle.opponent;
                gameInfo.black = client.account.username;
                whiteAccount   = opponentClient.account;
                blackAccount   = client.account;
            }

            gameInfo.whiteAvatar.profileId = whiteAccount.id;
            gameInfo.whiteAvatar.head      = whiteAccount.avatar.head;
            gameInfo.whiteAvatar.body      = whiteAccount.avatar.body;
            gameInfo.whiteAvatar.leg       = whiteAccount.avatar.leg;
            gameInfo.whiteAvatar.armBack   = whiteAccount.avatar.armBack;
            gameInfo.whiteAvatar.armFront  = whiteAccount.avatar.armFront;
            gameInfo.blackAvatar.profileId = blackAccount.id;
            gameInfo.blackAvatar.head      = blackAccount.avatar.head;
            gameInfo.blackAvatar.body      = blackAccount.avatar.body;
            gameInfo.blackAvatar.leg       = blackAccount.avatar.leg;
            gameInfo.blackAvatar.armBack   = blackAccount.avatar.armBack;
            gameInfo.blackAvatar.armFront  = blackAccount.avatar.armFront;

            client.Send(gameInfo);
        }
Exemplo n.º 23
0
        public static void Surrender(Client client)
        {
            client.packetMap.Remove("Surrender");

            Battle battle = BattleAPI.GetBattle(client.account.username);

            if (battle.phase != "End")
            {
                Battle.Stats whiteStats; Battle.Stats blackStats;
                string whiteProfileId; string blackProfileId;

                Battle opponentBattle = BattleAPI.GetOpponentBattle(battle);
                Client opponentClient = BattleAPI.GetOpponentClient(battle);

                battle.phase         = "End";
                opponentBattle.phase = "End";

                NewEffects newEffects = new NewEffects();

                NewEffects.Effect surrenderEffectEffect = new NewEffects.Effect();
                NewEffects.Effect endGameEffect         = new NewEffects.Effect();

                surrenderEffectEffect.SurrenderEffect       = new NewEffects.Effect.SurrenderEffectEffect();
                surrenderEffectEffect.SurrenderEffect.color = battle.color;

                endGameEffect.EndGame        = new NewEffects.Effect.EndGameEffect();
                endGameEffect.EndGame.winner = opponentBattle.color;

                if (battle.color == "white")
                {
                    whiteProfileId = client.account.id;
                    blackProfileId = "";

                    whiteStats = battle.stats;
                    blackStats = opponentBattle.stats;
                }
                else
                {
                    whiteProfileId = "";
                    blackProfileId = client.account.id;

                    whiteStats = opponentBattle.stats;
                    blackStats = battle.stats;
                }

                endGameEffect.EndGame.whiteStats.profileId          = whiteProfileId;
                endGameEffect.EndGame.whiteStats.idolDamage         = whiteStats.idolDamage;
                endGameEffect.EndGame.whiteStats.unitDamage         = whiteStats.unitDamage;
                endGameEffect.EndGame.whiteStats.unitsPlayed        = whiteStats.unitsPlayed;
                endGameEffect.EndGame.whiteStats.spellsPlayed       = whiteStats.spellsPlayed;
                endGameEffect.EndGame.whiteStats.enchantmentsPlayed = whiteStats.enchantmentsPlayed;
                endGameEffect.EndGame.whiteStats.scrollsDrawn       = whiteStats.scrollsDrawn;
                endGameEffect.EndGame.whiteStats.totalMs            = 0;
                endGameEffect.EndGame.whiteStats.mostDamageUnit     = 0;
                endGameEffect.EndGame.whiteStats.idolsDestroyed     = 0;

                endGameEffect.EndGame.blackStats.profileId          = blackProfileId;
                endGameEffect.EndGame.blackStats.idolDamage         = blackStats.idolDamage;
                endGameEffect.EndGame.blackStats.unitDamage         = blackStats.unitDamage;
                endGameEffect.EndGame.blackStats.unitsPlayed        = blackStats.unitsPlayed;
                endGameEffect.EndGame.blackStats.spellsPlayed       = blackStats.spellsPlayed;
                endGameEffect.EndGame.blackStats.enchantmentsPlayed = blackStats.enchantmentsPlayed;
                endGameEffect.EndGame.blackStats.scrollsDrawn       = blackStats.scrollsDrawn;
                endGameEffect.EndGame.blackStats.totalMs            = 0;
                endGameEffect.EndGame.blackStats.mostDamageUnit     = 0;
                endGameEffect.EndGame.blackStats.idolsDestroyed     = 0;

                endGameEffect.EndGame.whiteGoldReward.matchReward           = 0;
                endGameEffect.EndGame.whiteGoldReward.matchCompletionReward = 0;
                endGameEffect.EndGame.whiteGoldReward.idolsDestroyedReward  = 0;
                endGameEffect.EndGame.whiteGoldReward.totalReward           = 0;

                endGameEffect.EndGame.blackGoldReward.matchReward           = 0;
                endGameEffect.EndGame.blackGoldReward.matchCompletionReward = 0;
                endGameEffect.EndGame.blackGoldReward.idolsDestroyedReward  = 0;
                endGameEffect.EndGame.blackGoldReward.totalReward           = 0;

                newEffects.effects.Add(surrenderEffectEffect);
                newEffects.effects.Add(endGameEffect);

                client.Send(newEffects);
                opponentClient.Send(newEffects);
            }
            else
            {
                Console.WriteLine("{0} tried to surrender in a game that has already finished!", client.account.username);
            }
        }
Exemplo n.º 24
0
        public static void GameChallengeRequest(Client client, string jsonPacketData)
        {
            client.packetMap.Remove("GameChallengeRequest");

            GameChallengeRequest gameChallengeRequest = JsonConvert.DeserializeObject<GameChallengeRequest>(jsonPacketData);
            Client opponentSession = PlayerAPI.GetSession(gameChallengeRequest.profile, true);

            if (PlayerAPI.IsOnline(opponentSession.account.username))
            {
                if (client.account.deckMap.ContainsKey(gameChallengeRequest.deck))
                {
                    client.account.challengeMap.Add(opponentSession.account.username, gameChallengeRequest.deck);

                    OkMessage okMessage = new OkMessage();
                    okMessage.op = "GameChallengeRequest";

                    client.Send(okMessage);

                    GameChallenge gameChallenge = new GameChallenge();
                    gameChallenge.from.id               = client.account.id;
                    gameChallenge.from.userUuid         = "";
                    gameChallenge.from.name             = client.account.username;
                    gameChallenge.from.acceptChallenges = client.account.acceptChallenges;
                    gameChallenge.from.acceptTrades     = client.account.acceptTrades;
                    gameChallenge.from.adminRole        = client.account.adminRole;
                    gameChallenge.from.userType         = "Beta";

                    opponentSession.Send(gameChallenge);
                }
                else
                {
                    Console.WriteLine("{0} is trying to challenge {1} with the deck {2} which they don't own!", client.account.username, opponentSession.account.username, gameChallengeRequest.deck);
                    PlayerAPI.KickPlayer(client, "AntiCheat: You have been disconnected from the server!");
                }
            }
            else
            {
                Console.WriteLine("{0} is trying to challenge someone who is offline or doesn't exist!", opponentSession.account.username);
                PlayerAPI.KickPlayer(client, "AntiCheat: You have been disconnected from the server!");
            }
        }
Exemplo n.º 25
0
        public static void GetTowerInfo(Client client)
        {
            client.packetMap.Remove("GetTowerInfo");

            GetTowerInfo getTowerInfo = new GetTowerInfo();

            foreach (KeyValuePair<int, Trial> trial in Variables.trialMap)
            {
                GetTowerInfo.Level level = new GetTowerInfo.Level();
                level.id          = trial.Value.id;
                level.name        = trial.Value.name;
                level.goldReward  = trial.Value.goldReward;
                level.description = trial.Value.description;
                level.difficulty  = trial.Value.difficulty;
                level.flavour     = trial.Value.flavour;
                level.isComplete  = false;

                getTowerInfo.levels.Add(level);
            }

            client.Send(getTowerInfo);
        }
Exemplo n.º 26
0
        public static void CreatureUpdate(Client client, Battle battle, Creature creature)
        {
            NewEffects newEffects               = new NewEffects();
            NewEffects.Effect statsUpdateEffect = new NewEffects.Effect();

            NewEffects.Effect.Target target = new NewEffects.Effect.Target();
            target.color    = battle.color;
            target.position = creature.posY + "," + creature.posX;

            statsUpdateEffect.StatsUpdate        = new NewEffects.Effect.StatsUpdateEffect();
            statsUpdateEffect.StatsUpdate.target = target;
            statsUpdateEffect.StatsUpdate.hp     = creature.currentHp;
            statsUpdateEffect.StatsUpdate.ac     = creature.currentAc;
            statsUpdateEffect.StatsUpdate.ap     = creature.currentAp;

            newEffects.effects.Add(statsUpdateEffect);

            client.Send(newEffects);
            GetOpponentClient(battle).Send(newEffects);
        }
Exemplo n.º 27
0
        public static void ResourcesUpdate(Client client, Battle battle)
        {
            NewEffects newEffects = new NewEffects();

            NewEffects.Effect resourcesUpdateEffect = new NewEffects.Effect();
            resourcesUpdateEffect.ResourcesUpdate   = new NewEffects.Effect.ResourcesUpdateEffect();

            Battle whiteBattle; Battle blackBattle;

            if (battle.color == "white")
            {
                whiteBattle = battle;
                blackBattle = GetOpponentBattle(battle);
            }
            else
            {
                whiteBattle = GetOpponentBattle(battle);
                blackBattle = battle;
            }

            resourcesUpdateEffect.ResourcesUpdate.whiteAssets.handSize = whiteBattle.handMap.Count;
            resourcesUpdateEffect.ResourcesUpdate.blackAssets.handSize = blackBattle.handMap.Count;

            resourcesUpdateEffect.ResourcesUpdate.whiteAssets.availableResources.DECAY  = whiteBattle.resources[(int)resourceType.decay, 0];
            resourcesUpdateEffect.ResourcesUpdate.whiteAssets.availableResources.ENERGY = whiteBattle.resources[(int)resourceType.energy, 0];
            resourcesUpdateEffect.ResourcesUpdate.whiteAssets.availableResources.GROWTH = whiteBattle.resources[(int)resourceType.growth, 0];
            resourcesUpdateEffect.ResourcesUpdate.whiteAssets.availableResources.ORDER  = whiteBattle.resources[(int)resourceType.order, 0];
            resourcesUpdateEffect.ResourcesUpdate.whiteAssets.outputResources.DECAY     = whiteBattle.resources[(int)resourceType.decay, 1];
            resourcesUpdateEffect.ResourcesUpdate.whiteAssets.outputResources.ENERGY    = whiteBattle.resources[(int)resourceType.energy, 1];
            resourcesUpdateEffect.ResourcesUpdate.whiteAssets.outputResources.GROWTH    = whiteBattle.resources[(int)resourceType.growth, 1];
            resourcesUpdateEffect.ResourcesUpdate.whiteAssets.outputResources.ORDER     = whiteBattle.resources[(int)resourceType.order, 1];

            resourcesUpdateEffect.ResourcesUpdate.blackAssets.availableResources.DECAY  = blackBattle.resources[(int)resourceType.decay, 0];
            resourcesUpdateEffect.ResourcesUpdate.blackAssets.availableResources.ENERGY = blackBattle.resources[(int)resourceType.energy, 0];
            resourcesUpdateEffect.ResourcesUpdate.blackAssets.availableResources.GROWTH = blackBattle.resources[(int)resourceType.growth, 0];
            resourcesUpdateEffect.ResourcesUpdate.blackAssets.availableResources.ORDER  = blackBattle.resources[(int)resourceType.order, 0];
            resourcesUpdateEffect.ResourcesUpdate.blackAssets.outputResources.DECAY     = blackBattle.resources[(int)resourceType.decay, 1];
            resourcesUpdateEffect.ResourcesUpdate.blackAssets.outputResources.ENERGY    = blackBattle.resources[(int)resourceType.energy, 1];
            resourcesUpdateEffect.ResourcesUpdate.blackAssets.outputResources.GROWTH    = blackBattle.resources[(int)resourceType.growth, 1];
            resourcesUpdateEffect.ResourcesUpdate.blackAssets.outputResources.ORDER     = blackBattle.resources[(int)resourceType.order, 1];

            newEffects.effects.Add(resourcesUpdateEffect);

            client.Send(newEffects);
            GetOpponentClient(battle).Send(newEffects);
        }
Exemplo n.º 28
0
        public static void EndPhase(Client client, string jsonPacketData)
        {
            client.packetMap.Remove("EndPhase");

            EndPhase endPhase = JsonConvert.DeserializeObject<EndPhase>(jsonPacketData);

            Battle battle = BattleAPI.GetBattle(client.account.username);

            //Note: Phase checking needs to be added
            switch (endPhase.phase)
            {
                case "Init":
                    {
                        battle.turn = 0;

                        for (int i = 0; i < 5; i++)
                        {
                            battle.idols[i] = 10;
                        }

                        for (int i = 0; i < 4; i++)
                        {
                            for (int ii = 0; ii < 2; ii++)
                            {
                                battle.resources[i, ii] = 0;
                            }
                        }

                        CardAPI.ShuffleDeck(battle.deck);
                        CardAPI.DrawCard(battle, 5);

                        ActiveResources activeResources = new ActiveResources();

                        foreach (string resource in battle.deck.resources)
                        {
                            activeResources.types.Add(resource);
                        }

                        client.Send(activeResources);

                        BattleAPI.TurnBegin(client, battle);
                        BattleAPI.UpdateHand(client, battle);

                        battle.phase = "PreMain";
                        break;
                    }
                case "PreMain":
                    {
                        if (battle.turn != 1)
                        {
                            CardAPI.DrawCard(battle, 1);
                        }

                        BattleAPI.UpdateHand(client, battle);
                        BattleAPI.ResetResources(battle);
                        BattleAPI.ResourcesUpdate(client, battle);
                        BattleAPI.CreatureTick(client, battle);

                        battle.phase = "Main";
                        break;
                    }
                case "Main":
                    {
                        BattleAPI.CreatureAttack(client, battle);
                        BattleAPI.TurnBegin(client, battle);

                        break;
                    }
            }
        }
Exemplo n.º 29
0
        public static void SellCards(Client client, string jsonPacketData)
        {
            client.packetMap.Remove("SellCards");

            SellCards sellCards = JsonConvert.DeserializeObject<SellCards>(jsonPacketData);

            bool saleError = false;
            int totalGold  = 0;

            foreach (int cardId in sellCards.cardIds)
            {
                if (CardAPI.Exists(client, cardId))
                {
                    if (CardAPI.GetCard(client, cardId).tradable)
                    {
                        switch (CardAPI.GetCardType(client.account.cardMap[cardId].typeId).rarity)
                        {
                            case 0: { totalGold += ConfigReader.sellCommon; break; }
                            case 1: { totalGold += ConfigReader.sellUncommon; break; }
                            case 2: { totalGold += ConfigReader.sellRare; break; }
                        }

                        CardAPI.RemoveCard(client, cardId);
                    }
                    else { saleError = true; }
                }
                else { saleError = true; }
            }

            if (!saleError)
            {
                int lastId;
                DB.Database.Execute(client.connection, out lastId, true, true, "UPDATE server_stats SET totalSoldCards = totalSoldCards + ?", sellCards.cardIds.Count);

                PlayerAPI.IncreaseGold(client, totalGold);
                PlayerAPI.UpdateScrollTypeCount(client);

                OkMessage okMessage = new OkMessage();
                okMessage.op = "SellCards";

                client.Send(okMessage);
            }
        }
Exemplo n.º 30
0
        public static void TurnBegin(Client client, Battle battle)
        {
            battle.turn++;

            NewEffects newEffects = new NewEffects();

            NewEffects.Effect turnBeginEffect = new NewEffects.Effect();
            turnBeginEffect.TurnBegin         = new NewEffects.Effect.TurnBeginEffect();

            turnBeginEffect.TurnBegin.turn = battle.turn;

            Battle opponentBattle = GetOpponentBattle(battle);

            if (battle.turn != 1)
            {
                opponentBattle.turn++;

                if (battle.turnColor == "white")
                {
                    battle.turnColor         = "black";
                    opponentBattle.turnColor = "black";

                    turnBeginEffect.TurnBegin.color = "black";
                }
                else
                {
                    battle.turnColor         = "white";
                    opponentBattle.turnColor = "white";

                    turnBeginEffect.TurnBegin.color = "white";
                }
            }
            else { turnBeginEffect.TurnBegin.color = battle.turnColor; }

            newEffects.effects.Add(turnBeginEffect);
            client.Send(newEffects);

            if (battle.turn != 1)
            {
                GetOpponentClient(battle).Send(newEffects);
            }
        }