コード例 #1
0
        public string Add2Leaderboard(string TableName, string User2Add)
        {
            string        jsonGetData = string.Empty;
            int           responseCode;
            StringBuilder theMessage = new StringBuilder();

            // Add user to Leaderboard
            theMessage.Append("Adding User " + User2Add + " to LeaderBoard");
            responseCode = JTAzureTableRESTCommands.GetEntityProperty("GET", storageName, sAS, TableName, out jsonGetData, "Hero", "User");
            HeroEntity       userHero = JsonConvert.DeserializeObject <HeroEntity>(jsonGetData);
            LeaderBoardEntry newEntry = new LeaderBoardEntry();

            newEntry.RowKey       = User2Add;
            newEntry.AttackCount  = userHero.AttackCount;
            newEntry.RespawnCount = userHero.RespawnCount;
            newEntry.Score        = userHero.Score;
            newEntry.AttackDate   = DateTime.Now.ToShortDateString();

            // Create new Leaderboard Entry
            responseCode = JTAzureTableRESTCommands.ChangeEntity("POST", storageName, sAS, TableName, JsonConvert.SerializeObject(newEntry), string.Empty, string.Empty);
            theMessage.Append(responseCode + newLine);

            responseCode = 200; // Leaderboard Entry Added

            ResponseMessage response = new ResponseMessage(theMessage.ToString(), responseCode);

            return(JsonConvert.SerializeObject(response));
        }
コード例 #2
0
        public string IncreaseStat(string TableName, string UserName, string Relic)
        {
            string        jsonGetData = string.Empty;
            int           responseCode;
            StringBuilder theMessage = new StringBuilder();

            // User clicked on a "Relic" which will increase the stat based on the Relic selected.
            responseCode = JTAzureTableRESTCommands.GetEntityProperty("GET", storageName, sAS, TableName, out jsonGetData, "Hero", UserName);
            IEntity loadUser = new Hero();

            loadUser.LoadEntity(jsonGetData);

            // Make sure User is not dead
            if (Convert.ToInt32(loadUser.GetEntityStat(EntityStat.Health)) > 0)
            {
                theMessage.Append("Increasing " + Relic + " =>");
                loadUser.ChangeEntityStatByRelic(Relic);
                responseCode = JTAzureTableRESTCommands.ChangeEntity("PUT", storageName, sAS, TableName, JsonConvert.SerializeObject(loadUser), loadUser.GetEntityStat(EntityStat.PartitionKey), loadUser.GetEntityStat(EntityStat.RowKey));
                theMessage.Append(responseCode + newLine);

                responseCode = 200; // Stat Increase Complete
            }
            else
            {
                theMessage.Append("User is DEAD. Respawning now =>");
                responseCode = 498; // User is dead. Need to Respawn
            }
            ResponseMessage response = new ResponseMessage(theMessage.ToString(), responseCode);

            return(JsonConvert.SerializeObject(response));
        }
コード例 #3
0
        public string Respawn(string TableName, string UserName)
        {
            string        jsonGetData = string.Empty;
            int           responseCode;
            StringBuilder theMessage = new StringBuilder();

            // Reset User
            theMessage.Append("Respawn User=>");
            responseCode = JTAzureTableRESTCommands.GetEntityProperty("GET", storageName, sAS, TableName, out jsonGetData, "Hero", UserName);
            // Factory Version
            IEntity loadUser = new Hero();

            loadUser.LoadEntity(jsonGetData);
            loadUser.ChangeEntityStat(EntityStat.RespawnCount, ChangeStatDirection.Up, 1);
            loadUser.ChangeEntityStat(EntityStat.Health, ChangeStatDirection.Set, Convert.ToInt32(loadUser.GetEntityStat(EntityStat.Health)) + Convert.ToInt32(loadUser.GetEntityStat(EntityStat.AddedHealth)));
            loadUser.CalculateEntityScore();

            responseCode = JTAzureTableRESTCommands.ChangeEntity("PUT", storageName, sAS, TableName, JsonConvert.SerializeObject(loadUser), loadUser.GetEntityStat(EntityStat.PartitionKey), loadUser.GetEntityStat(EntityStat.RowKey));
            theMessage.Append(responseCode + newLine);

            responseCode = 200; // Reset Complete

            ResponseMessage response = new ResponseMessage(theMessage.ToString(), responseCode);

            return(JsonConvert.SerializeObject(response));
        }
コード例 #4
0
        public string ResetGame(string TableName, string UserName, string BossName)
        {
            string        jsonGetData = string.Empty;
            int           responseCode;
            StringBuilder theMessage = new StringBuilder();

            // Reset User
            theMessage.Append("Resetting User=>");
            IEntity defaultUser = new Hero(); // Create a Blank User

            defaultUser.CreateBlankEntity();
            responseCode = JTAzureTableRESTCommands.ChangeEntity("PUT", storageName, sAS, TableName, JsonConvert.SerializeObject(defaultUser), defaultUser.GetEntityStat(EntityStat.PartitionKey), defaultUser.GetEntityStat(EntityStat.RowKey));
            theMessage.Append(responseCode + newLine);

            // Reset Boss
            theMessage.Append("Resetting Boss=>");
            IEntity defaultBoss = new Boss(); // Create a Blank Boss

            defaultBoss.CreateBlankEntity();
            responseCode = JTAzureTableRESTCommands.ChangeEntity("PUT", storageName, sAS, TableName, JsonConvert.SerializeObject(defaultBoss), defaultBoss.GetEntityStat(EntityStat.PartitionKey), defaultBoss.GetEntityStat(EntityStat.RowKey));
            theMessage.Append(responseCode + newLine);

            responseCode = 200; // Reset Complete

            ResponseMessage response = new ResponseMessage(theMessage.ToString(), responseCode);

            return(JsonConvert.SerializeObject(response));
        }
コード例 #5
0
        public int StartGame()
        {
            string jsonGetData = string.Empty;
            int    responseCode;

            AzureTable NewTable = new AzureTable("BossHuntv1");

            responseCode = JTAzureTableRESTCommands.GetAllTables(storageName, sAS, "('" + NewTable.TableName + "')", out jsonGetData);
            if (responseCode == 7)
            {
                responseCode = JTAzureTableRESTCommands.CreateTable("POST", storageName, sAS, "Tables", JsonConvert.SerializeObject(NewTable), string.Empty, string.Empty);
                responseCode = JTAzureTableRESTCommands.GetAllTables(storageName, sAS, "('" + NewTable.TableName + "')", out jsonGetData);
            }

            if (responseCode == 200)
            {
                // If the Boss Hunt Table is successfully created or it exists, then check to see if there is an existing user and load, otherwise create the user
                IEntity defaultUser = new Hero(); // Create a Blank User
                //Entity blankUser = defaultUser.CreateBlankEntity(); // Create a Blank User
                defaultUser.CreateBlankEntity();  // Create a Blank User
                responseCode = JTAzureTableRESTCommands.GetAllEntities(storageName, sAS, NewTable.TableName + "(PartitionKey='" + defaultUser.GetEntityStat(EntityStat.PartitionKey) + "',RowKey='" + defaultUser.GetEntityStat(EntityStat.RowKey) + "')", out jsonGetData);
                string test = JsonConvert.SerializeObject(defaultUser);

                if (responseCode == 7)
                {
                    responseCode = JTAzureTableRESTCommands.ChangeEntity("POST", storageName, sAS, NewTable.TableName, JsonConvert.SerializeObject(defaultUser), string.Empty, string.Empty);
                }
                else
                {
                    responseCode = 201; // User Loaded or Created successfully.
                }

                // If the User is successfully created or already existed, then check to see if there is an existing boss and load, otherwise create the boss
                IEntity defaultBoss = new Boss(); // Create a Blank Boss
                //Entity blankBoss = defaultBoss.CreateBlankEntity();
                defaultBoss.CreateBlankEntity();
                responseCode = JTAzureTableRESTCommands.GetAllEntities(storageName, sAS, NewTable.TableName + "(PartitionKey='" + defaultBoss.GetEntityStat(EntityStat.PartitionKey) + "',RowKey='" + defaultBoss.GetEntityStat(EntityStat.RowKey) + "')", out jsonGetData);

                if (responseCode == 7)
                {
                    responseCode = JTAzureTableRESTCommands.ChangeEntity("POST", storageName, sAS, NewTable.TableName, JsonConvert.SerializeObject(defaultBoss), string.Empty, string.Empty);
                }
                else
                {
                    responseCode = 201; // Boss Loaded or Created successfully.
                }

                // ###########################################################################
                // Create Relic Entries if they doesn't exist
                if (responseCode == 201)
                {
                    responseCode = Helper.CreateRelics(NewTable.TableName);
                }
                // ###########################################################################
            }
            return(responseCode);
        }
コード例 #6
0
        public string ReturnData(string TableName, string PartitionK, string RowK)
        {
            string jsonGetData = string.Empty;
            int    responseCode;

            responseCode = JTAzureTableRESTCommands.GetEntityProperty("GET", storageName, sAS, TableName, out jsonGetData, PartitionK, RowK);

            //HeroEntity heroProperty = JsonConvert.DeserializeObject<HeroEntity>(jsonGetData);
            return(jsonGetData);
        }
コード例 #7
0
        public string ReturnRelicData(string TableName)
        {
            string          jsonGetData = string.Empty;
            int             responseCode;
            StringBuilder   theMessage = new StringBuilder();
            RootRelicObject RelicList  = new RootRelicObject();

            // Get LeaderBoard
            responseCode = JTAzureTableRESTCommands.GetLBProperty("GET", storageName, sAS, TableName, out jsonGetData, "Relic");
            RelicList    = JsonConvert.DeserializeObject <RootRelicObject>(jsonGetData);

            if (RelicList.value != null)
            {
                // return Relic List
                //RelicList.value.Sort(sort);
                return(JsonConvert.SerializeObject(RelicList));
            }
            else
            {
                return("NoData");
            }
        }
コード例 #8
0
        public string GetLeaderboard(string TableName)
        {
            string                jsonGetData = string.Empty;
            int                   responseCode;
            StringBuilder         theMessage = new StringBuilder();
            RootLeaderBoardObject theLB      = new RootLeaderBoardObject();

            // Get LeaderBoard
            responseCode = JTAzureTableRESTCommands.GetLBProperty("GET", storageName, sAS, TableName, out jsonGetData, "Leaderboard");
            theLB        = JsonConvert.DeserializeObject <RootLeaderBoardObject>(jsonGetData);

            if (theLB.value != null)
            {
                // Sort Leaderboard
                Sorter sort = new Sorter();
                theLB.value.Sort(sort);
                //theLB.value.Reverse();
                return(JsonConvert.SerializeObject(theLB));
            }
            else
            {
                return("NoData");
            }
        }
コード例 #9
0
        public static int CreateRelics(string table)
        {
            int    responseCode;
            string jsonGetData = string.Empty;

            // #########################################################################################
            // Create the Attack Relic
            BaseRelic AtkRelic = new AttackRelic();

            responseCode = JTAzureTableRESTCommands.GetAllEntities(storageName, sAS, table + "(PartitionKey='" + AtkRelic.PartitionKey + "',RowKey='" + AtkRelic.RowKey + "')", out jsonGetData);
            if (responseCode == 7)
            {
                responseCode = JTAzureTableRESTCommands.ChangeEntity("POST", storageName, sAS, table, JsonConvert.SerializeObject(AtkRelic), string.Empty, string.Empty);
            }
            else
            {
                responseCode = 201;
            }
            // #########################################################################################

            // #########################################################################################
            // Create the Health Relic
            BaseRelic HPRelic = new HealthRelic();

            responseCode = JTAzureTableRESTCommands.GetAllEntities(storageName, sAS, table + "(PartitionKey='" + HPRelic.PartitionKey + "',RowKey='" + HPRelic.RowKey + "')", out jsonGetData);
            if (responseCode == 7)
            {
                responseCode = JTAzureTableRESTCommands.ChangeEntity("POST", storageName, sAS, table, JsonConvert.SerializeObject(HPRelic), string.Empty, string.Empty);
            }
            else
            {
                responseCode = 201;
            }
            // #########################################################################################

            // #########################################################################################
            // Create the Speed Relic
            BaseRelic SPRelic = new SpeedRelic();

            responseCode = JTAzureTableRESTCommands.GetAllEntities(storageName, sAS, table + "(PartitionKey='" + SPRelic.PartitionKey + "',RowKey='" + SPRelic.RowKey + "')", out jsonGetData);
            if (responseCode == 7)
            {
                responseCode = JTAzureTableRESTCommands.ChangeEntity("POST", storageName, sAS, table, JsonConvert.SerializeObject(SPRelic), string.Empty, string.Empty);
            }
            else
            {
                responseCode = 201;
            }
            // #########################################################################################

            // #########################################################################################
            // Create the Accuracy Relic
            BaseRelic AccRelic = new AccuracyRelic();

            responseCode = JTAzureTableRESTCommands.GetAllEntities(storageName, sAS, table + "(PartitionKey='" + AccRelic.PartitionKey + "',RowKey='" + AccRelic.RowKey + "')", out jsonGetData);
            if (responseCode == 7)
            {
                responseCode = JTAzureTableRESTCommands.ChangeEntity("POST", storageName, sAS, table, JsonConvert.SerializeObject(AccRelic), string.Empty, string.Empty);
            }
            else
            {
                responseCode = 201;
            }
            // #########################################################################################

            return(responseCode);
        }
コード例 #10
0
        public string StartAttack(string TableName, string UserName, string BossName)
        {
            // Start the Attack
            // Entity with the highest speed goes first
            string        jsonGetData = string.Empty;
            int           responseCode;
            int           DeadCode     = 200; // This is used to determine if the User or Boss are dead.
            string        PartitionKey = "Hero";
            StringBuilder theMessage   = new StringBuilder();

            // Get User Data
            theMessage.Append("Loading User=>");
            responseCode = JTAzureTableRESTCommands.GetEntityProperty("GET", storageName, sAS, TableName, out jsonGetData, PartitionKey, UserName);

            //HeroEntity userHero = JsonConvert.DeserializeObject<HeroEntity>(jsonGetData);
            //userHero.AttackCount++; // Increment the attack count for this user on this boss.
            //userHero = Helper.CalculateScore(userHero);
            //AnyEntity genUser = new AnyEntity(userHero); // Convert to Basic hero entity for the Attacker Class

            // Factory Version
            IEntity genericUser = new Hero();

            genericUser.LoadEntity(jsonGetData);
            genericUser.ChangeEntityStat(EntityStat.AttackCount, ChangeStatDirection.Up, 1);
            genericUser.CalculateEntityScore();

            theMessage.Append(responseCode + newLine);

            // Get Boss Data
            theMessage.Append("Loading Boss=>");
            responseCode = JTAzureTableRESTCommands.GetEntityProperty("GET", storageName, sAS, TableName, out jsonGetData, PartitionKey, BossName);
            //BossEntity bossHero = JsonConvert.DeserializeObject<BossEntity>(jsonGetData);
            //AnyEntity genBoss = new AnyEntity(bossHero); // Convert to Basic hero entity for the Attacker Class

            // Factory Version
            IEntity genericBoss = new Boss();

            genericBoss.LoadEntity(jsonGetData);

            theMessage.Append(responseCode + newLine);

            //Start the Attack
            theMessage.Append("==Start Attack==" + newLine);
            //genUser.AttackCount++; // Increment the attack count for this user on this boss.
            Attack thisAttack = new Attack(genericUser, genericBoss, 0, 0);

            theMessage.Append("==User Goes First==" + newLine);

            // Determine who goes first
            if (Convert.ToInt32(genericUser.GetEntityStat(EntityStat.Speed)) < Convert.ToInt32(genericBoss.GetEntityStat(EntityStat.Speed)))
            {
                theMessage.Append("==Nope Boss Goes First==" + newLine);
                thisAttack.Attacker = genericBoss;
                thisAttack.Defender = genericUser;
            }

            // Check to see if the Attacker hit the Defender based on the Attackers Accuracy
            if (thisAttack.Attacker.CheckEntityHit() == 1)
            {
                // Attack was Successful
                // ###############################################################
                thisAttack.Defender.ChangeEntityStat(EntityStat.Health, ChangeStatDirection.Down, Convert.ToInt32(thisAttack.Attacker.GetEntityStat(EntityStat.Attack))); // Lower Health
                theMessage.Append(thisAttack.Attacker.GetEntityStat(EntityStat.RowKey) + " hits " + thisAttack.Defender.GetEntityStat(EntityStat.RowKey) + " for " + thisAttack.Attacker.GetEntityStat(EntityStat.Attack) + " damage" + newLine);

                if (thisAttack.Defender.GetEntityStat(EntityStat.RowKey) == BossName) // Check Boss Threshold
                {
                    // Get the current Boss threshold Value. Increase the speed based on this new value.
                    thisAttack.Defender.ChangeEntityStat(EntityStat.CurrentThreshold, ChangeStatDirection.Set, Convert.ToInt32(thisAttack.Defender.GetEntityThresholdValue(10)));
                    thisAttack.Defender.ChangeEntityStat(EntityStat.Speed, ChangeStatDirection.Up, Convert.ToInt32(thisAttack.Defender.GetEntityStat(EntityStat.CurrentThreshold)));
                }

                if (thisAttack.Attacker.GetEntityStat(EntityStat.RowKey) == UserName)
                {
                    // If the attack was done by the User, Increase the XP of the User.
                    thisAttack.Attacker.ChangeEntityStat(EntityStat.XP, ChangeStatDirection.Up, Convert.ToInt32(thisAttack.Attacker.GetEntityStat(EntityStat.Attack)));
                }

                // Check if the Defender Died during this attack. If so, end current Attack
                if (Convert.ToInt32(thisAttack.Defender.GetEntityStat(EntityStat.Health)) < 1)
                {
                    thisAttack.DefenderDead = 1;
                    theMessage.Append(thisAttack.Defender.GetEntityStat(EntityStat.RowKey) + " as Defender Died" + newLine);
                    if (thisAttack.Defender.GetEntityStat(EntityStat.RowKey) == UserName)
                    {
                        DeadCode = 201; // Means the User died
                    }
                    else
                    {
                        DeadCode = 202; // Means the Boss died
                    }
                }

                // Update the Defender Health
                theMessage.Append("Saving Defender Stats=>");
                responseCode = JTAzureTableRESTCommands.ChangeEntity("PUT", storageName, sAS, TableName, JsonConvert.SerializeObject(thisAttack.Defender), thisAttack.Defender.GetEntityStat(EntityStat.PartitionKey), thisAttack.Defender.GetEntityStat(EntityStat.RowKey));
                theMessage.Append(responseCode + newLine);
                // ###############################################################
            }
            else
            {
                // Attack failed
                // ###############################################################
                theMessage.Append("ATTACK MISSED" + newLine);
                // ###############################################################
            }

            if (thisAttack.DefenderDead == 0) // Check if the defender is still Alive, if so Defenders turn to Attack
            {
                theMessage.Append("==Defender NOT Dead==" + newLine);
                thisAttack = Helper.SwitchRoles(thisAttack, thisAttack.Attacker, thisAttack.Defender);
                theMessage.Append("==Switch Roles==" + newLine);

                // Check to see if the Attacker hit the Defender based on the Attackers Accuracy
                if (thisAttack.Attacker.CheckEntityHit() == 1)
                {
                    // Attack was Successful
                    // ###############################################################
                    thisAttack.Defender.ChangeEntityStat(EntityStat.Health, ChangeStatDirection.Down, Convert.ToInt32(thisAttack.Attacker.GetEntityStat(EntityStat.Attack)));
                    theMessage.Append(thisAttack.Attacker.GetEntityStat(EntityStat.RowKey) + " hits " + thisAttack.Defender.GetEntityStat(EntityStat.RowKey) + " for " + thisAttack.Attacker.GetEntityStat(EntityStat.Attack) + " damage" + newLine);

                    if (thisAttack.Defender.GetEntityStat(EntityStat.RowKey) == BossName) // Check Boss Threshold
                    {
                        // Get the current Boss threshold Value. Increase the speed based on this new value.
                        thisAttack.Defender.ChangeEntityStat(EntityStat.CurrentThreshold, ChangeStatDirection.Set, Convert.ToInt32(thisAttack.Defender.GetEntityThresholdValue(10)));
                        thisAttack.Defender.ChangeEntityStat(EntityStat.Speed, ChangeStatDirection.Up, Convert.ToInt32(thisAttack.Defender.GetEntityStat(EntityStat.CurrentThreshold)));
                    }

                    if (thisAttack.Attacker.GetEntityStat(EntityStat.RowKey) == UserName)
                    {
                        // If the attack was done by the User, Increase the XP of the User.
                        thisAttack.Attacker.ChangeEntityStat(EntityStat.XP, ChangeStatDirection.Up, Convert.ToInt32(thisAttack.Attacker.GetEntityStat(EntityStat.Attack)));
                    }

                    if (Convert.ToInt32(thisAttack.Defender.GetEntityStat(EntityStat.Health)) < 1)
                    {
                        thisAttack.DefenderDead = 1;
                        theMessage.Append(thisAttack.Defender.GetEntityStat(EntityStat.RowKey) + " as Defender Died" + newLine);
                        if (thisAttack.Defender.GetEntityStat(EntityStat.RowKey) == UserName)
                        {
                            DeadCode = 201; // Means the User died
                        }
                        else
                        {
                            DeadCode = 202; // Means the Boss died
                        }
                    }

                    // Update the new Defender Health
                    theMessage.Append("Saving Defender Stats=>");
                    responseCode = JTAzureTableRESTCommands.ChangeEntity("PUT", storageName, sAS, TableName, JsonConvert.SerializeObject(thisAttack.Defender), thisAttack.Defender.GetEntityStat(EntityStat.PartitionKey), thisAttack.Defender.GetEntityStat(EntityStat.RowKey));
                    theMessage.Append(responseCode + newLine);
                    // ###############################################################
                }
                else
                {
                    // Attack failed
                    // ###############################################################
                    theMessage.Append("ATTACK MISSED" + newLine);
                    // ###############################################################
                }
            }
            else
            {
                theMessage.Append("==Defender Dead==" + newLine);
                responseCode = JTAzureTableRESTCommands.ChangeEntity("PUT", storageName, sAS, TableName, JsonConvert.SerializeObject(thisAttack.Attacker), thisAttack.Attacker.GetEntityStat(EntityStat.PartitionKey), thisAttack.Attacker.GetEntityStat(EntityStat.RowKey));
            }

            theMessage.Append("==Attack Over==");

            ResponseMessage response = new ResponseMessage(theMessage.ToString(), DeadCode);

            return(JsonConvert.SerializeObject(response));
        }