コード例 #1
0
        public NPCs(MySQLHandler dataBase, Items ItemsDatabase)
        {
            npclist = new List <NPC>();
            if (dataBase.Connection.State != ConnectionState.Open)
            {
                try
                {
                    dataBase.Connection.Open();
                }
                catch
                {
                    //
                }
            }

            MySqlCommand query = dataBase.Connection.CreateCommand();

            query.CommandText = "SELECT * FROM `npcs`";

            try
            {
                using (MySqlDataReader reader = query.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        int[]  tmpcost    = Array.ConvertAll(reader.GetString("cost").Split(','), int.Parse);
                        int[]  tmpitemids = Array.ConvertAll(reader.GetString("itemids").Split(','), int.Parse);
                        Item[] items      = new Item[tmpitemids.Length];
                        for (int i = 0; i < tmpitemids.Length; i++)
                        {
                            Item tmpitem = ItemsDatabase.GetItemByID(tmpitemids[i]);
                            items[i] = tmpitem;
                        }
                        NPC npc = new NPC(
                            reader.GetInt32("id"),
                            reader.GetInt32("mapid"),
                            reader.GetString("name"),
                            reader.GetFloat("x"),
                            reader.GetFloat("y"),
                            items,
                            reader.GetString("cost")
                            );
                        npclist.Add(npc);
                    }
                }
            }
            catch
            {
                //
            }
        }
コード例 #2
0
        public Monsters(MySQLHandler dataBase)
        {
            monlist = new List <Monster>();

            if (dataBase.Connection.State != ConnectionState.Open)
            {
                try
                {
                    dataBase.Connection.Open();
                }
                catch
                {
                    //
                }
            }

            MySqlCommand query = dataBase.Connection.CreateCommand();

            query.CommandText = "SELECT * FROM `monsters`";

            try
            {
                using (MySqlDataReader reader = query.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        int[]   dropids         = Array.ConvertAll(reader.GetString("drop_item_id").Split(','), int.Parse);
                        int[]   dropprobability = Array.ConvertAll(reader.GetString("drop_probability").Split(','), int.Parse);
                        Monster mon             = new Monster(
                            reader.GetInt32("id"),
                            reader.GetString("title"),
                            reader.GetInt32("level"),
                            reader.GetInt32("attack"),
                            reader.GetInt32("maxhp"),
                            reader.GetInt32("exp"),
                            reader.GetInt32("respawntime"),
                            dropids,
                            dropprobability,
                            reader.GetUInt32("gold")
                            );
                        monlist.Add(mon);
                    }
                }
            }
            catch
            {
                //
            }
        }
コード例 #3
0
        public ItemsWeapon(MySQLHandler dataBase)
        {
            itemWList = new List <ItemWeapon>();

            if (dataBase.Connection.State != ConnectionState.Open)
            {
                try
                {
                    dataBase.Connection.Open();
                }
                catch
                {
                    //
                }
            }

            MySqlCommand query = dataBase.Connection.CreateCommand();

            //query.CommandText = "SELECT ITEM.*, WEAPON_DETAILS.min_attack, WEAPON_DETAILS.max_attack, BONUSES.strength, BONUSES.stamina, BONUSES.dexterity, BONUSES.luck FROM `item` ITEM, `weapon_details` WEAPON_DETAILS, `bonuses` BONUSES WHERE ITEM.type='weapon' AND ITEM.id=WEAPON_DETAILS.id AND ITEM.id=BONUSES.id";
            query.CommandText = "SELECT * FROM `items_weapon`";
            try
            {
                using (MySqlDataReader reader = query.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        ItemWeapon weapon = new ItemWeapon(
                            reader.GetUInt32("id"),
                            reader.GetString("type"),
                            reader.GetUInt32("price"),
                            reader.GetString("name"),
                            reader.GetUInt32("min_attack"),
                            reader.GetUInt32("max_attack"),
                            reader.GetUInt32("strength"),
                            reader.GetUInt32("stamina"),
                            reader.GetUInt32("dexterity"),
                            reader.GetUInt32("luck")
                            );
                        itemWList.Add(weapon);
                    }
                }
            }
            catch
            {
                //
            }
        }
コード例 #4
0
        public Items(MySQLHandler dataBase)
        {
            itemList = new List <Item>();

            if (dataBase.Connection.State != ConnectionState.Open)
            {
                try
                {
                    dataBase.Connection.Open();
                }
                catch
                {
                    //
                }
            }

            MySqlCommand query = dataBase.Connection.CreateCommand();

            query.CommandText = "SELECT * FROM `items_information`";
            try
            {
                using (MySqlDataReader reader = query.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Item item = new Item(
                            reader.GetInt32("id"),
                            reader.GetString("title"),
                            reader.GetInt32("power"),
                            reader.GetInt32("defense"),
                            reader.GetInt32("hp"),
                            reader.GetBoolean("stackable"),
                            reader.GetInt32("rarity"),
                            reader.GetInt32("lvl_req"),
                            reader.GetString("type")
                            );
                        itemList.Add(item);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("There was an error while loading items. \n\n\n" + e.ToString(), "Error while loading Items", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
コード例 #5
0
        public Skills(MySQLHandler dataBase)
        {
            skillList = new List <Skill>();

            if (dataBase.Connection.State != ConnectionState.Open)
            {
                try
                {
                    dataBase.Connection.Open();
                }
                catch
                {
                    //
                }
            }

            MySqlCommand query = dataBase.Connection.CreateCommand();

            query.CommandText = "SELECT * FROM `skills`";

            try
            {
                using (MySqlDataReader reader = query.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Skill skill = new Skill(
                            reader.GetInt32("id"),
                            reader.GetInt32("attack"),
                            reader.GetInt32("level"),
                            reader.GetString("name")
                            );
                        skillList.Add(skill);
                    }
                }
            }
            catch
            {
                //
            }
        }
コード例 #6
0
        public Waves(MySQLHandler dataBase, Monsters monstersdb)
        {
            wavelist = new List <Wave>();
            if (dataBase.Connection.State != ConnectionState.Open)
            {
                try
                {
                    dataBase.Connection.Open();
                }
                catch
                {
                    //
                }
            }

            MySqlCommand query = dataBase.Connection.CreateCommand();

            query.CommandText = "SELECT * FROM `wavelist`";

            try
            {
                using (MySqlDataReader reader = query.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        List <Monster> mons            = new List <Monster>();
                        string[]       tmpmonsterids   = reader.GetString("monsters").Split(',');
                        string[]       tmpmonstercount = reader.GetString("monstercount").Split(',');
                        string[]       tmpx            = reader.GetString("x").Split(',');
                        string[]       tmpy            = reader.GetString("y").Split(',');

                        int[] monids   = new int[tmpmonsterids.Length];
                        int[] moncount = new int[tmpmonsterids.Length];
                        int[] x        = new int[tmpmonsterids.Length];
                        int[] y        = new int[tmpmonsterids.Length];
                        for (int i = 0; i < tmpmonsterids.Length; i++)
                        {
                            monids[i]   = int.Parse(tmpmonsterids[i]);
                            moncount[i] = int.Parse(tmpmonstercount[i]);
                            x[i]        = int.Parse(tmpx[i]);
                            y[i]        = int.Parse(tmpy[i]);
                            float tmpspacing = 0;
                            for (int j = 0; j < moncount[i]; j++)
                            {
                                Monster tmpmon = new Monster();
                                tmpspacing             = (float)(j) / 10.0f;
                                tmpmon                 = monstersdb.GetMonsterByID(monids[i]);
                                tmpmon.position.XCoord = x[i] + tmpspacing;
                                tmpmon.position.YCoord = y[i];
                                mons.Add(tmpmon);
                            }
                        }
                        Wave wave = new Wave(
                            reader.GetInt32("id"),
                            monids,
                            moncount,
                            x,
                            y,
                            mons,
                            reader.GetInt32("mapid"));

                        /*for (int i = 0; i < mons.Count; i++)
                         *  MessageBox.Show(mons[i].Test.ToString());*/
                        wavelist.Add(wave);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
コード例 #7
0
        public Character(ulong playerID, MySQLHandler GlobalMysql, Socket s, Items itemsDB)
        {
            MYSQL = GlobalMysql;
            // Equipment and Storage goes here.
            // equipment = new CharacterEquipment(playerID, GlobalMysql);
            // storage = new CharacterStorage(playerID, GlobalMysql);
            _skillList    = new List <Skill>();
            AllSkills     = new Skills(MYSQL);
            ItemsDB       = itemsDB;
            _socketClient = s;

            // Entire item list for all items in database
            _equipmentList = new List <Item>();

            if (MYSQL.Connection.State != ConnectionState.Open)
            {
                try
                {
                    MYSQL.Connection.Open();
                }
                catch
                {
                    // err
                }
            }


            MySqlCommand query = MYSQL.Connection.CreateCommand();

            query.CommandText = "SELECT * FROM `characters` WHERE `characters`.`id` = " + playerID;
            // 0,10;     1,30;2,30;
            lock (GlobalMysql)
            {
                try
                {
                    using (MySqlDataReader reader = query.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            name        = reader.GetString("name");
                            level       = reader.GetInt32("level");
                            id          = reader.GetUInt64("id");
                            str         = reader.GetUInt32("str");
                            dex         = reader.GetUInt32("dex");
                            _int        = reader.GetUInt32("_int");
                            luck        = reader.GetUInt32("luck");
                            maxhp       = reader.GetUInt32("maxhp");
                            maxmp       = reader.GetUInt32("maxmp");
                            curhp       = reader.GetUInt32("curhp");
                            curmp       = reader.GetUInt32("curmp");
                            mapid       = reader.GetInt32("mapid");
                            _maxwave    = reader.GetInt32("wavenumber");
                            skillpoints = reader.GetUInt32("skillpoints");
                            statpoints  = reader.GetUInt32("statpoints");
                            exp         = reader.GetInt32("exp");
                            gold        = reader.GetUInt32("gold");
                            hash        = MyEncryption.CreateCharacterHash(reader.GetString("account_id"));
                            this.Id     = id;
                            accID       = reader.GetInt32("account_id");

                            // skill stuff
                            string[] tmpactiveskill  = reader.GetString("active_skill").Split(',');
                            int[]    tmpactiveskills = new int[4];
                            string[] skillids        = reader.GetString("skill_id").Split(',');
                            int[]    skillidlist     = new int[11];
                            int      skillCounter    = 0;
                            string[] skilllevel      = reader.GetString("skill_level").Split(',');
                            int[]    skilllevels     = new int[11];
                            foreach (string _skillid in skillids)
                            {
                                if (skillCounter >= 10)
                                {
                                    break;
                                }
                                int tempID;
                                int val = Int32.TryParse(_skillid, out tempID) ? tempID : 0;
                                if (val == 0)
                                {
                                    continue;
                                }
                                skillidlist[skillCounter] = val;
                                skillCounter++;
                            }
                            skillCounter = 0;
                            foreach (string _skilllevel in skilllevel)
                            {
                                if (skillCounter >= 10)
                                {
                                    break;
                                }
                                int tempID;
                                int val = Int32.TryParse(_skilllevel, out tempID) ? tempID : 0;
                                if (val == 0)
                                {
                                    continue;
                                }
                                skilllevels[skillCounter] = val;
                                skillCounter++;
                            }
                            skillCounter = 0;
                            foreach (string _tmpactiveskill in tmpactiveskill)
                            {
                                if (skillCounter > 3)
                                {
                                    break;
                                }
                                int tempID;
                                int val = Int32.TryParse(_tmpactiveskill, out tempID) ? tempID : 0;
                                if (val == 0)
                                {
                                    continue;
                                }
                                tmpactiveskills[skillCounter] = val;
                                skillCounter++;
                            }

                            for (int i = 0; i < skillidlist.Count(); i++)
                            {
                                Skill skill = AllSkills.GetSkillByID(skillidlist[i]);
                                if (skill == null)
                                {
                                    continue;
                                }
                                for (int j = 0; j < tmpactiveskills.Count(); j++)
                                {
                                    if (tmpactiveskills[j] == skill.Id)
                                    {
                                        skill.Active = true;
                                    }
                                }
                                skill.Level = skilllevels[i];
                                //Skill skill = new Skill(skillidlist[i], AllSkills.SkillList[j].Attack, skilllevels[i], AllSkills.SkillList[j].Name);
                                _skillList.Add(skill);
                            }
                        }
                    }
                }
                catch (MySqlException e)
                {
                    MessageBox.Show(e.ToString(), "Server can't start.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            // Items Now
            // fill up the list
            for (int i = 0; i < MAX_SLOTS; i++)
            {
                _equipmentList.Add(new Item());
            }
            query.CommandText = "SELECT * FROM `character_items` WHERE `ownerID` = " + (int)id + " ORDER BY slot DESC";
            try
            {
                using (MySqlDataReader reader = query.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Item tmpItem = new Item();
                        tmpItem         = ItemsDB.GetItemByID(reader.GetInt32("itemid"));
                        tmpItem.Slot    = reader.GetInt32("slot");
                        tmpItem.Amount  = reader.GetInt32("amount");
                        tmpItem.Power   = reader.GetInt32("attack");
                        tmpItem.Defense = reader.GetInt32("defense");
                        tmpItem.HP      = reader.GetInt32("hp");
                        tmpItem.Stat1   = reader.GetInt32("extra_stat1");
                        tmpItem.Stat2   = reader.GetInt32("extra_stat2");
                        if (tmpItem.ID != -1)
                        {
                            //_equipmentList.Add(tmpItem);
                            _equipmentList[tmpItem.Slot] = tmpItem;
                        }
                        else
                        {
                            MessageBox.Show("Invalid item", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
            }
            catch (MySqlException e)
            {
                MessageBox.Show("Error while loading items for charid = " + id + " \n\n\n" + e.ToString(), "Charater.cs Error - Failed to load items", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            LastSave = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
        }