示例#1
0
 private void attach_PlayerSkills(PlayerSkill entity)
 {
     this.SendPropertyChanging();
     entity.Skill = this;
 }
示例#2
0
 private void detach_PlayerSkills(PlayerSkill entity)
 {
     this.SendPropertyChanging();
     entity.Skill = null;
 }
示例#3
0
 partial void DeletePlayerSkill(PlayerSkill instance);
示例#4
0
 partial void UpdatePlayerSkill(PlayerSkill instance);
示例#5
0
 partial void InsertPlayerSkill(PlayerSkill instance);
示例#6
0
        public static List <SkillData> UpdateSkills(string username, string data)
        {
            ToolsDataContext db                = new ToolsDataContext();
            Player           playerToUpdate    = db.Players.Where(a => a.RS_Username == username).FirstOrDefault();
            List <SkillData> skillListToReturn = new List <SkillData>();

            // Split the data string from the API into individual parts
            string[] skillsRaw = data.Split(';'),
            order = { "Overall", "Attack", "Defense", "Strength", "Hitpoints", "Ranged", "Prayer", "Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining", "Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecraft", "Hunter", "Construction" };

            // Player already exists, update the data
            if (playerToUpdate != null)
            {
                int skillIndex = 0; //Keeps track of the skill order
                foreach (string skill in order)
                {
                    string[] stats      = skillsRaw[skillIndex].Split(',');
                    string   skillName  = skill,
                             skillRank  = stats[0],
                             skillLevel = stats[1],
                             skillExp   = stats[2];

                    // Update the values in the database
                    Skill       sk = db.Skills.Where(a => a.Name == skill).FirstOrDefault();
                    PlayerSkill ps = db.PlayerSkills.Where(a => a.RS_Skill == sk.SkillID && a.RS_Player == playerToUpdate.PlayerID).FirstOrDefault();

                    if (ps == null) // If no entry exists for the player
                    {
                        ps           = new PlayerSkill();
                        ps.RS_Player = playerToUpdate.PlayerID;
                        ps.RS_Skill  = db.Skills.Where(a => a.Name == skill).FirstOrDefault().SkillID;
                    }

                    ps.Rank       = Convert.ToInt32(skillRank);
                    ps.Level      = Convert.ToInt32(skillLevel);
                    ps.Experience = Convert.ToInt32(skillExp);

                    skillIndex++;

                    SkillData toList = new SkillData();
                    toList.exp      = Convert.ToInt32(ps.Experience);
                    toList.lvl      = Convert.ToInt32(ps.Level);
                    toList.rank     = Convert.ToInt32(ps.Rank);
                    toList.req      = Convert.ToInt32(sk.QuestMinimum);
                    toList.name     = skill;
                    toList.progress = 100;

                    if (toList.name != "Overall")
                    {
                        if (toList.lvl < 99)
                        {
                            Level nl = db.Levels.Where(a => a.LevelNumber == toList.req).FirstOrDefault();
                            toList.progress = Math.Round(((decimal)toList.exp) / ((decimal)nl.Experience) * 100, 2);
                            if (toList.progress > 100)
                            {
                                toList.progress = 100;
                            }
                        }
                    }


                    skillListToReturn.Add(toList);
                }
                db.SubmitChanges();
            }
            // Create new Player in the DB
            else
            {
                playerToUpdate             = new Player();
                playerToUpdate.RS_Username = username;
                db.Players.InsertOnSubmit(playerToUpdate);
                db.SubmitChanges();

                int skillIndex = 0; //Keeps track of the skill order
                foreach (string skill in order)
                {
                    if (skillIndex < order.Length) // Make sure not to overflow into Bounty Hunder + LMS
                    {
                        string[] stats      = skillsRaw[skillIndex].Split(',');
                        string   skillName  = skill,
                                 skillRank  = stats[0],
                                 skillLevel = stats[1],
                                 skillExp   = stats[2];

                        // Create the association with the skill
                        PlayerSkill ps = new PlayerSkill();
                        ps.Rank       = Convert.ToInt32(skillRank);
                        ps.Level      = Convert.ToInt32(skillLevel);
                        ps.Experience = Convert.ToInt32(skillExp);
                        ps.RS_Player  = playerToUpdate.PlayerID;
                        Skill sk = db.Skills.Where(a => a.Name == skillName).FirstOrDefault();
                        ps.RS_Skill = sk.SkillID;

                        skillIndex++;
                        db.PlayerSkills.InsertOnSubmit(ps);
                        SkillData toList = new SkillData();
                        toList.exp      = Convert.ToInt32(ps.Experience);
                        toList.lvl      = Convert.ToInt32(ps.Level);
                        toList.rank     = Convert.ToInt32(ps.Rank);
                        toList.req      = Convert.ToInt32(sk.QuestMinimum);
                        toList.name     = skill;
                        toList.progress = 100;

                        if (toList.name != "Overall")
                        {
                            if (toList.lvl < 99)
                            {
                                Level ll = db.Levels.Where(a => a.LevelNumber == toList.lvl).FirstOrDefault();
                                Level nl = db.Levels.Where(a => a.LevelNumber == toList.lvl + 1).FirstOrDefault();
                                toList.progress = Math.Round(((decimal)toList.exp - ll.Experience) / ((decimal)nl.Experience - ll.Experience) * 100, 2);
                            }
                        }


                        skillListToReturn.Add(toList);
                    }
                }
                db.SubmitChanges();
            }

            return(skillListToReturn);
        }
示例#7
0
        /// <summary>
        /// Create a Player entry in the Runescape database containing the username, skills, and blank quest progress
        /// Skills are retrieved dynamically via the Runescape.com api
        /// </summary>
        /// <param name="username">The Runescape username to create</param>
        /// <returns>Whether the Player was successfully created</returns>
        public static bool CreatePlayer(string username)
        {
            RunescapeDataContext db = new RunescapeDataContext();

            // The order that the skills will be recieved by Runscape API. THIS ORDER MATTERS
            string[] order = { "Overall", "Attack", "Defense", "Strength", "Hitpoints", "Ranged", "Prayer", "Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining", "Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecraft", "Hunter", "Construction" };

            // Check if the player exists already
            // TODO: Alter so that it instead looks up the current user's player and replaces them with the new one
            Player playerToCreate = db.Players.Where(a => a.RS_Username == "username").FirstOrDefault();

            // The player does not exist, proceed with the creation
            if (playerToCreate == null)
            {
                //Create the new user
                playerToCreate             = new Player();
                playerToCreate.RS_Username = username;
                playerToCreate.Admin       = false;
                db.Players.InsertOnSubmit(playerToCreate);
                db.SubmitChanges();

                // Create quests for the user
                foreach (Quest quest in db.Quests.ToList())
                {
                    PlayerQuest pq = new PlayerQuest();
                    pq.Status   = false;
                    pq.PlayerID = playerToCreate.PlayerID;
                    pq.QuestID  = quest.QuestID;
                    db.PlayerQuests.InsertOnSubmit(pq);
                }

                // Get skill data from Runescape
                WebClient client     = new WebClient();
                string[]  jsonResult = client.DownloadString("http://services.runescape.com/m=hiscore_oldschool/index_lite.ws?player=" + username.ToLower()).Replace('\n', ';').Split(';');

                // Create skills for the user
                int skillIndex = 0;
                foreach (string skillName in order)
                {
                    string[] stats      = jsonResult[skillIndex].Split(',');
                    string   skillRank  = stats[0],
                             skillLevel = stats[1],
                             skillExp   = stats[2];

                    PlayerSkill ps = new PlayerSkill();
                    ps.SkillID  = db.Skills.Where(a => a.Name == skillName).FirstOrDefault().SkillID;
                    ps.Rank     = Convert.ToInt32(stats[0]);
                    ps.Exp      = Convert.ToInt32(stats[2]);
                    ps.Level    = Convert.ToInt32(stats[1]);
                    ps.PlayerID = playerToCreate.PlayerID;

                    db.PlayerSkills.InsertOnSubmit(ps);
                    skillIndex++;
                }



                db.SubmitChanges();
                return(true);
            }

            // If the player exists, it doesn't need to be created, make sure they have stats
            else
            {
                // Check the skills
                foreach (Skill skill in db.Skills.ToList())
                {
                    PlayerSkill ps = db.PlayerSkills.Where(a => a.PlayerID == playerToCreate.PlayerID && a.SkillID == skill.SkillID).FirstOrDefault();

                    // The skill does not exist for the player; create it
                    if (ps == null)
                    {
                        ps.PlayerID = playerToCreate.PlayerID;
                        ps.SkillID  = skill.SkillID;
                        ps.Rank     = 0;
                        ps.Level    = 1;
                        ps.Exp      = 1; // Set these stats to 1 until the next update
                        db.PlayerSkills.InsertOnSubmit(ps);
                    }
                }

                // Check the quests
                foreach (Quest quest in db.Quests.ToList())
                {
                    PlayerQuest pq = db.PlayerQuests.Where(a => a.PlayerID == playerToCreate.PlayerID && a.QuestID == quest.QuestID).FirstOrDefault();

                    // The quest does not exist for the player; create it
                    if (pq == null)
                    {
                        pq.PlayerID = playerToCreate.PlayerID;
                        pq.QuestID  = quest.QuestID;
                        pq.Status   = false;
                        db.PlayerQuests.InsertOnSubmit(pq);
                    }
                }

                db.SubmitChanges();
                return(true);
            }
        }