Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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));
        }