Ejemplo n.º 1
0
        public character GetCharacter(uint character_id)
        {
            character new_char = new character();
            uint deity = 0, race = 0;
            var query = @"select dnd.`character`.account,
                        dnd.`character`.name,
                        dnd.`character`.avatar,
                        dnd.`character`.sex,
                        dnd.`character`.background,
                        dnd.`character`.hair,
                        dnd.`character`.eyes,
                        dnd.`character`.skin,
                        dnd.`character`.personnality,
                        dnd.`character`.race,
                        dnd.`character`.deity
                        from dnd.`character`
                        where dnd.`character`.id_character =" + character_id;

            if (OpenConnection())
            {
                using (MySqlCommand cmd = new MySqlCommand(query, connection))
                {

                    MySqlDataReader dataReader = cmd.ExecuteReader(System.Data.CommandBehavior.SequentialAccess);
                    while (dataReader.Read())
                    {
                        new_char = new character()
                        {
                            uid = character_id,
                            account = dataReader.GetUInt32(0),
                            name = dataReader.IsDBNull(1) ? null : dataReader.GetString(1),
                            avatar = dataReader.IsDBNull(2) ? null : (byte[])dataReader[2],
                            sex = dataReader.IsDBNull(3) ? '\0' : dataReader.GetChar(3),
                            background = dataReader.IsDBNull(4) ? null : dataReader.GetString(4),
                            hair = dataReader.IsDBNull(5) ? null : dataReader.GetString(5),
                            eyes = dataReader.IsDBNull(6) ? null : dataReader.GetString(6),
                            skin = dataReader.IsDBNull(7) ? null : dataReader.GetString(7),
                            personnality = dataReader.IsDBNull(8) ? null : dataReader.GetString(8)
                    };
                        race = dataReader.GetUInt32(9);
                        deity = dataReader.GetUInt32(10);
                    }
                    dataReader.Close();
                }
                this.CloseConnection();
            }

            if(deity>0)
                new_char.deity = GetDeity(deity);

            if(race>0)
                new_char.race = GetShortRace(race);

            if (new_char.uid > 0)
            {
                new_char.languages = GetCharacterLanguage(character_id);
                new_char.classes = GetShortMulticlass(character_id);
                new_char.stats = GetCharacterCharacteristics(character_id);
                new_char.age = GetCharacterAge(character_id);
                new_char.height = GetCharacterHeight(character_id);
                new_char.weight = GetCharacterWeight(character_id);
                new_char.gifts = GetCharacterGifts(character_id);
                new_char.effects = GetCharacterEffects(character_id);
                new_char.skills = GetCharacterSkills(character_id);
                new_char.aptitudes = GetCharacterAptitudes(character_id);
            }


            return new_char;
        }
Ejemplo n.º 2
0
        public bool CharacterUpdate(character player)
        {
            #region Character Table
            #endregion
            #region Race Table
            #endregion
            #region Multiclass Table
            #endregion
            #region Skills table
            #endregion
            #region Inventory Table
            #endregion
            #region Stats Table
            #endregion
            #region Spells Table
            #endregion
            #region Gifts Table
            #endregion
            #region Aptitudes Table
            #endregion
            #region Languages Table
            #endregion
            #region Effects Table
            #endregion
            #region Traits
            //Weight
            //Height
            //Age
            #endregion

            return true;
        }
Ejemplo n.º 3
0
 //Pass the updated character to the DAO and update this character if id exists
 public bool CharacterUpdate(character player)
 {
     return db.CharacterUpdate(player);
 }
Ejemplo n.º 4
0
        public int CharacterCreate(character player)
        {
            /// 0:  everything is ok
            /// 1:  DAO couldn't connect
            /// 2:  no account communicated
            /// 3:  character has no name
            /// 4:  undefined sex
            /// 5:  no class
            /// 6:  no race
            uint character_id;

            #region Character Table
            string query_character = @"insert into 
                            character(name,avatar,account,race,sex,background,hair,eyes,skin,deity,personnality) 
                            values(@name,@avatar,@account,@race,@sex,@background,@hair,@eyes,@skin,@deity,@personnality);
                            SELECT SCOPE_IDENTITY();";
            using (MySqlCommand cmd = new MySqlCommand(query_character, connection))
            {

                //Test if an account is linked
                if (player.account != 0)
                    cmd.Parameters.AddWithValue("@account", player.account);
                else
                    return 2;
                //Name
                if (player.name != null)
                    cmd.Parameters.AddWithValue("@name", player.name);
                else
                    return 3;
                //Avatar
                if (player.avatar.Length > 0)
                    cmd.Parameters.AddWithValue("@avatar", MySqlDbType.Blob).Value = player.avatar;
                //Background
                if (player.background != null)
                    cmd.Parameters.AddWithValue("@background", player.background);
                //Personnality
                if (player.personnality != null)
                    cmd.Parameters.AddWithValue("@personnality", player.personnality);
                //Hair
                if (player.hair != null)
                    cmd.Parameters.AddWithValue("@hair", player.hair);
                //Eyes
                if (player.eyes != null)
                    cmd.Parameters.AddWithValue("@eyes", player.eyes);
                //Skin
                if (player.skin != null)
                    cmd.Parameters.AddWithValue("@skin", player.skin);
                //Sex
                if (player.sex != 'M' && player.sex != 'F')
                    cmd.Parameters.AddWithValue("@sex", player.sex);
                else
                    return 4;
                //Deity
                if (player.deity != null)
                    cmd.Parameters.AddWithValue("@deity", player.deity.uid);
                //Race
                if (player.race != null)
                    cmd.Parameters.AddWithValue("@race", player.race.uid);
                else
                    return 6;

                //Executing the insertion into character
                if (OpenConnection())
                    character_id = Convert.ToUInt32(cmd.ExecuteScalar().ToString());
                else
                    return 1;
            }
            #endregion
            #region Race Dependencies
            // WEIGHT
            string query_weight = @"insert into 
                            weight_category_has_character(weight_category,character,weight) 
                            values(@weight_cat,@charac,@weight);";
            using (MySqlCommand cmd = new MySqlCommand(query_weight, connection))
            {
                //character
                cmd.Parameters.AddWithValue("@charac", character_id);
                //weight category
                cmd.Parameters.AddWithValue("@weight_cat", player.weight.Item2.uid);
                //weight
                cmd.Parameters.AddWithValue("@weight", player.weight.Item1);
                //Executing the insertion into weight
                if (OpenConnection())
                    cmd.ExecuteNonQuery();
                else
                    return 1;
            }
            // HEIGHT
            string query_height = @"insert into 
                            height_category_has_character(height_category,character,height) 
                            values(@height_cat,@charac,@height);";
            using (MySqlCommand cmd = new MySqlCommand(query_height, connection))
            {
                //character
                cmd.Parameters.AddWithValue("@charac", character_id);
                //height category
                cmd.Parameters.AddWithValue("@height_cat", player.height.Item2.uid);
                //height
                cmd.Parameters.AddWithValue("@height", player.height.Item1);
                //Executing the insertion into height
                if (OpenConnection())
                    cmd.ExecuteNonQuery();
                else
                    return 1;
            }
            // AGE
            string query_age = @"insert into 
                            age_category_has_character(age_category,character,age) 
                            values(@age_cat,@charac,@age);";
            using (MySqlCommand cmd = new MySqlCommand(query_age, connection))
            {
                //character
                cmd.Parameters.AddWithValue("@charac", character_id);
                //age category
                cmd.Parameters.AddWithValue("@age_cat", player.age.Item2.uid);
                //age
                cmd.Parameters.AddWithValue("@age", player.age.Item1);
                //Executing the insertion into weight
                if (OpenConnection())
                    cmd.ExecuteNonQuery();
                else
                    return 1;
            }
            #endregion
            #region Multiclass Table
            // MULTICLASS
            if (player.classes.values_entities.Count == 0)
                return 5;
            string query_multiclass = @"insert into 
                            multiclasses(character,class,level) 
                            values(@character,@class,@level);";
            using (MySqlCommand cmd = new MySqlCommand(query_multiclass, connection))
            {
                //character
                cmd.Parameters.AddWithValue("@character", character_id);
                //class
                cmd.Parameters.AddWithValue("@class", player.classes.values_entities[0].Item1);
                //class level
                cmd.Parameters.AddWithValue("@level", 1);
                //Executing the insertion into weight
                if (OpenConnection())
                    cmd.ExecuteNonQuery();
                else
                    return 1;
            }
            #endregion
            #region Spells Table
            uint spellbook_id;
            if(GetClass(player.classes.values_entities[0].Item2.uid).magical == true)
            {
                // Create a spellbook for this character
                var query_spellbook = "insert into spellbook;SELECT SCOPE_IDENTITY();";
                using (MySqlCommand cmd = new MySqlCommand(query_spellbook, connection))
                {
                    if (OpenConnection())
                        spellbook_id = Convert.ToUInt32((cmd.ExecuteScalar().ToString()));
                    else
                        return 1;
                }

                // Add every spell
            }
            #endregion
            #region Skills table
            // If skills are defined, loop to add everyone of them
            if (player.skills.md_skill.Count != 0)
            {
                foreach (var skill in player.skills.md_skill)
                {
                    string query_skills = @"insert into 
                            skill_has_character(skill,character,mastery_degree) 
                            values(@skill,@character,@md);";
                    using (MySqlCommand cmd = new MySqlCommand(query_skills, connection))
                    {
                        //character
                        cmd.Parameters.AddWithValue("@character", character_id);
                        //skill
                        cmd.Parameters.AddWithValue("@skill", skill.Item1);
                        //master degree
                        cmd.Parameters.AddWithValue("@md", skill.Item2.uid);
                        //Executing the insertion into weight
                        if (OpenConnection())
                            cmd.ExecuteNonQuery();
                        else
                            return 1;
                    }
                }
            }
            #endregion
            #region Inventory Table
            uint inventory_id;
            // Create an inventory for this character
            var query_inventory = "insert into inventory(character) values(" + character_id + ");SELECT SCOPE_IDENTITY();";
            using (MySqlCommand cmd = new MySqlCommand(query_inventory,connection))
            {
                if (OpenConnection())
                    inventory_id = Convert.ToUInt32((cmd.ExecuteScalar().ToString()));
                else
                    return 1;
            }
            
            // If skills are defined, loop to add everyone of them
            if (player.skills.md_skill.Count != 0)
            {
                foreach (var skill in player.skills.md_skill)
                {
                    string query_skills = @"insert into 
                            skill_has_character(skill,character,mastery_degree) 
                            values(@skill,@character,@md);";
                    using (MySqlCommand cmd = new MySqlCommand(query_skills, connection))
                    {
                        //character
                        cmd.Parameters.AddWithValue("@character", character_id);
                        //skill
                        cmd.Parameters.AddWithValue("@skill", skill.Item1);
                        //master degree
                        cmd.Parameters.AddWithValue("@md", skill.Item2.uid);
                        //Executing the insertion into weight
                        if (OpenConnection())
                            cmd.ExecuteNonQuery();
                        else
                            return 1;
                    }
                }
            }
            #endregion
            #region Stats Table
            /// ajouter le template race, 
            /// le template correspondant à la classe de niveau 1 (modifiable en level up) 
            /// et un template propre à créer basé sur la modification du default_template
            #endregion
            #region Gifts Table
            #endregion
            #region Aptitudes Table
            #endregion
            #region Languages Table
            #endregion
            #region Effects Table
            #endregion
            #region Traits
            //Weight
            //Height
            //Age
            #endregion

            // Character creation went smoothly
            return 0;

            
        }
Ejemplo n.º 5
0
 //Create a new character and return character_id;
 public int CharacterCreate(character player)
 {
     return db.CharacterCreate(player);
 }