Пример #1
0
 public MonsterAI(Monster monster, ChannelServer server)
     : base(monster, 1000)
 {
     this.Server = server;
     AITimer.Elapsed += new System.Timers.ElapsedEventHandler(AITimer_Elapsed);
     AITimer.Enabled = false;
     Random = new Random();
 }
Пример #2
0
        public MonsterAI(Monster monster, List<BaseEntity> surroundings)
        {
            aiTimer = new Timer();
            aiTimer.Elapsed += new ElapsedEventHandler(aiTimer_Elapsed);
            aiTimer.Disposed += new EventHandler(aiTimer_Disposed);
            aiTimer.Enabled = true;
            aiTimer.AutoReset = true;
            aiTimer.Interval = 1000; //1000 for movemetn update, or 100

            this.surroundings = surroundings;

            this.Monster = monster;
            this.state = MonsterAIState.Wander;
        }
Пример #3
0
        public override AttackInfo OnAttack(Monster m)
        {
            if (m.Alive)
            {
                AttackInfo info = new AttackInfo();
                info.Damage = 0;
                info.Critical = false;
                info.Type = AttackType.Miss;

                info.TargetID = PetID;
                info.TargetType = (byte)Type;
                info.TargetX = (short)Position.X;
                info.TargetY = (short)Position.Y;
                info.TargetZ = 0;

                info.AttackerID = m.MonsterID;
                info.AttackerType = (byte)m.Type;

                if (m.AttackRating > TotalAttackRating)
                {
                    info.Type = AttackType.Hit;
                    if (PercentSuccess(10))
                        info.Critical = true;
                }
                else
                {
                    int chance = Random().Next(1, TotalAttackRating);
                    if (chance <= m.AttackRating)
                        info.Type = AttackType.Hit;
                    else
                        info.Type = AttackType.Miss;
                }
                if (info.Type == AttackType.Hit)
                {
                    info.Damage = m.Damage - TotalDefense / 3;
                    if (info.Damage <= 0)
                        info.Damage = 1;
                    if (info.Critical)
                        info.Damage *= 6;
                    if (info.Damage <= CurHealth)
                    {
                        CurHealth -= info.Damage;
                    }
                    else if (info.Damage >= CurHealth)
                    {
                        Alive = false;
                        CurHealth = 0;
                        info.Dead = true;
                    }
                }

                return info;
            }
            else
                return base.OnAttack(m);
        }
Пример #4
0
 public virtual CastSkillInfo OnCast(Monster m)
 {
     return null;
 }
Пример #5
0
 public virtual AttackInfo OnAttack(Monster m)
 {
     return null;
 }
Пример #6
0
        public override AttackInfo OnAttack(Monster m)
        {
            if (m.Alive)
            {
                AttackInfo info = new AttackInfo();
                info.Damage = 0;
                info.Critical = false;
                info.Type = AttackType.Miss;

                info.TargetID = CharacterId;
                info.TargetType = (byte)Type;
                info.TargetX = (short)Position.X;
                info.TargetY = (short)Position.Y;
                info.TargetZ = 0;

                info.AttackerID = m.MonsterID;
                info.AttackerType = (byte)m.Type;

                if (m.AttackRating > TotalAttackRating)
                {
                    info.Type = AttackType.Hit;
                    if (PercentSuccess(10))
                        info.Critical = true;
                }
                else
                {
                    int chance = Random().Next(1, TotalAttackRating);
                    if (chance <= m.AttackRating)
                        info.Type = AttackType.Hit;
                    else
                        info.Type = AttackType.Miss;
                }
                if (info.Type == AttackType.Hit)
                {
                    info.Damage = m.Damage - TotalDefence / 3;
                    if (info.Damage <= 0)
                        info.Damage = 1;
                    if (info.Critical)
                        info.Damage *= 6;

                    if (UsingReflection())
                    {
                        float damageInc = ReflectPerc;
                        float increase = (damageInc / 100);
                        int amount = (int)(info.Damage * increase);
                        info.Damage -= amount;
                        if (info.Damage <= 0)
                            info.Damage = 1;

                        info.DoRefDamage = true;
                    }

                    if (UsingShadow())
                    {
                        if (info.Damage <= tempPet.CurHealth)
                        {
                            tempPet.CurHealth -= info.Damage;
                            info.PetDamaged = true;
                        }
                        else if (info.Damage >= tempPet.CurHealth)
                        {
                            info.PetDamaged = true;
                            info.PetDied = true;
                        }
                    }
                    else
                    {
                        if (info.Damage <= CurrentHp)
                        {
                            CurrentHp -= info.Damage;
                        }
                        else if (info.Damage >= CurrentHp)
                        {
                            Alive = false;
                            CurrentHp = 0;
                            DeathTime = DateTime.Now;
                            info.Dead = true;
                        }
                    }
                }

                return info;
            }
            else
                return base.OnAttack(m);
        }
Пример #7
0
        public BaseItem GetBookDropItem(Monster m)
        {
            DbParameter monsterTypeParameter = _db.CreateParameter(DbNames.GETBOOKDROPITEM_MONSTERTYPE, m.MonsterType);
            monsterTypeParameter.DbType = DbType.Byte;

            List<BaseItem> items = new List<BaseItem>();

            _db.Open();

            DbDataReader reader = _db.ExcecuteReader(DbNames.GETBOOKDROPITEM_STOREDPROC, CommandType.StoredProcedure, monsterTypeParameter);

            int ordinalITEM_REFERENCEID = reader.GetOrdinal(DbNames.ITEM_REFERENCEID);
            int ordinalITEM_BTYPE = reader.GetOrdinal(DbNames.ITEM_BTYPE);
            int ordinalITEM_BKIND = reader.GetOrdinal(DbNames.ITEM_BKIND);
            int ordinalITEM_VISUALID = reader.GetOrdinal(DbNames.ITEM_VISUALID);
            int ordinalITEM_COST = reader.GetOrdinal(DbNames.ITEM_COST);
            int ordinalITEM_CLASS = reader.GetOrdinal(DbNames.ITEM_CLASS);
            int ordinalITEM_LEVEL = reader.GetOrdinal(DbNames.ITEM_LEVEL);
            int ordinalITEM_DEX = reader.GetOrdinal(DbNames.ITEM_DEX);
            int ordinalITEM_STR = reader.GetOrdinal(DbNames.ITEM_STR);
            int ordinalITEM_STA = reader.GetOrdinal(DbNames.ITEM_STA);
            int ordinalITEM_ENE = reader.GetOrdinal(DbNames.ITEM_ENE);
            int ordinalITEM_MAXIMBUES = reader.GetOrdinal(DbNames.ITEM_MAXIMBUES);
            int ordinalITEM_MAXDURA = reader.GetOrdinal(DbNames.DROPITEM_DURABILITY);
            int ordinalITEM_DAMAGE = reader.GetOrdinal(DbNames.ITEM_DAMAGE);
            int ordinalITEM_DEFENCE = reader.GetOrdinal(DbNames.ITEM_DEFENCE);
            int ordinalITEM_ATTACKRATING = reader.GetOrdinal(DbNames.ITEM_ATTACKRATING);
            int ordinalITEM_ATTACKSPEED = reader.GetOrdinal(DbNames.ITEM_ATTACKSPEED);
            int ordinalITEM_ATTACKRANGE = reader.GetOrdinal(DbNames.ITEM_ATTACKRANGE);
            int ordinalITEM_INCMAXLIFE = reader.GetOrdinal(DbNames.ITEM_INCMAXLIFE);
            int ordinalITEM_INCMAXMANA = reader.GetOrdinal(DbNames.ITEM_INCMAXMANA);
            int ordinalITEM_LIFEREGEN = reader.GetOrdinal(DbNames.ITEM_LIFEREGEN);
            int ordinalITEM_MANAREGEN = reader.GetOrdinal(DbNames.ITEM_MANAREGEN);
            int ordinalITEM_CRITICAL = reader.GetOrdinal(DbNames.ITEM_CRITICAL);
            int ordinalITEM_TOMAPID = reader.GetOrdinal(DbNames.ITEM_TOMAPID);
            int ordinalITEM_IMBUERATE = reader.GetOrdinal(DbNames.ITEM_IMBUERATE);
            int ordinalITEM_IMBUEINCREASE = reader.GetOrdinal(DbNames.ITEM_IMBUEINCREASE);
            int ordinalITEM_BOOKSKILLID = reader.GetOrdinal(DbNames.ITEM_BOOKSKILLID);
            int ordinalITEM_BOOKSKILLLEVEL = reader.GetOrdinal(DbNames.ITEM_BOOKSKILLLEVEL);
            int ordinalITEM_BOOKSKILLDATA = reader.GetOrdinal(DbNames.ITEM_BOOKSKILLDATA);
            int ordinalITEM_MAXPOLISHTRIES = reader.GetOrdinal(DbNames.ITEM_MAXPOLISHTRIES);
            int ordinalITEM_POLISHTRIES = reader.GetOrdinal(DbNames.ITEM_POLISHTRIES);
            int ordinalITEM_SIZEX = reader.GetOrdinal(DbNames.ITEM_SIZEX);
            int ordinalITEM_SIZEY = reader.GetOrdinal(DbNames.ITEM_SIZEY);

            while (reader.Read())
            {
                BaseItem b = null;

                int BType = reader.GetByte(ordinalITEM_BTYPE);
                int BKind = reader.GetByte(ordinalITEM_BKIND);

                if (BType == (byte)bType.Book)
                {
                    if (BKind == (byte)bKindBooks.SoftBook)
                    {
                        b = new SoftBook();
                    }
                    if (BKind == (byte)bKindBooks.HardBook)
                    {
                        b = new HardBook();
                    }
                    if (BKind == (byte)bKindBooks.RebirdBook)
                    {
                        b = new RebirthBook();
                    }
                    if (BKind == (byte)bKindBooks.FourthBook)
                    {
                        b = new FourthBook();
                    }
                    if (BKind == (byte)bKindBooks.FeSkillBook)
                    {
                        b = new FeSkillBook();
                    }
                    if (BKind == (byte)bKindBooks.FeBook)
                    {
                        b = new FiveElementBook();
                    }
                    if (BKind == (byte)bKindBooks.FocusBook)
                    {
                        b = new FocusBook();
                    }

                    BookItem book = b as BookItem;
                    book.RequiredClass = reader.GetByte(ordinalITEM_CLASS);
                    book.RequiredLevel = reader.GetInt16(ordinalITEM_LEVEL);
                    book.SkillID = reader.GetInt32(ordinalITEM_BOOKSKILLID);
                    book.SkillLevel = reader.GetByte(ordinalITEM_BOOKSKILLLEVEL);
                    book.SkillData = reader.GetInt32(ordinalITEM_BOOKSKILLDATA);
                }

                b.ItemID = 0;
                b.OwnerID = 0;
                b.ReferenceID = reader.GetInt16(ordinalITEM_REFERENCEID);
                b.VisualID = reader.GetInt16(ordinalITEM_VISUALID);
                b.Bag = 0;
                b.Slot = 0;
                b.bType = reader.GetByte(ordinalITEM_BTYPE);
                b.bKind = reader.GetByte(ordinalITEM_BKIND);
                b.RequiredClass = reader.GetByte(ordinalITEM_CLASS);
                b.Amount = 1;
                b.SizeX = reader.GetByte(ordinalITEM_SIZEX);
                b.SizeY = reader.GetByte(ordinalITEM_SIZEY);
                b.Price = reader.GetInt32(ordinalITEM_COST);
                items.Add(b);
            }

            reader.Close();
            _db.Close();

            if (items.Count > 0)
            {
                Random rand = new Random();
                int itemPos = rand.Next(0, items.Count);
                return items[itemPos];
            }
            else
                return null;
        }
Пример #8
0
 public BaseAI(Monster monster, int TimerInterval)
 {
     this.Monster = monster;
     this.AITimer = new System.Timers.Timer(TimerInterval);
     RaiseDesire(new Desire_Idle(), new object[] { });
 }
Пример #9
0
 public Pet TamePet(Monster m, Character ch)
 {
     Pet pet = new Pet
     {
         OwnerID = ch.CharacterId,
         MapID = ch.MapId,
         Position = m.Position.NormalizedCopy(),
         PetType = m.MonsterType,
         Name = m.Name,
         Level = m.Level,
         CurHealth = m.MaxHealth,
         MaxHealth = m.MaxHealth,
         Damage = m.Damage,
         Defense = m.Defense,
         AttackRating = m.AttackRating,
     };
     pet.PetID = InsertPet(pet, true);
     pet.ExperienceToLevel = GetExperienceToLevelByLevel(pet.Level);
     pet.NegativeExperience = GetNegativeExpByLevel(pet.Level);
     pet.CurrentExperience = pet.NegativeExperience;
     pet.EvolutionTable = GetPetEvolutionByType(pet.PetType);
     pet.Alive = true;
     UpdatePet(pet);
     return pet;
 }
Пример #10
0
 public static byte[] SendSpawnMonster(Monster m)
 {
     Packet p = new Packet(200);
     p.WriteHexString("00"); // something
     p.WriteInt(m.MonsterID);
     p.WriteByte(m.MonsterType);
     p.WriteInt(m.MapID);
     p.WriteShort((short)m.Position.X);
     p.WriteShort(m.Level);
     p.WriteShort((short)m.Position.Y);
     p.WriteHexString("00"); // unknown
     p.WriteShort(m.Direction);
     p.WriteInt(m.MonsterReferenceID);
     p.WriteHexString("14");
     p.WriteShort((short)m.Position.X);
     p.WriteShort((short)m.Position.Y);
     p.WriteHexString("00");
     p.WriteInt(m.MaxHealth);
     p.WriteInt(m.CurHealth);
     p.WriteByte(m.MovementSpeed);
     p.WriteByte(m.LeaderID);
     p.WriteHexString("FF 00 00 00 00");
     p.WriteHexString("00 00 00 00");
     return p.GetWrittenBuffer(PacketIds.SendSpawnMonster);
 }
Пример #11
0
        public static byte[] SendPetBaitTaken(Monster m, Pet pet)
        {
            Packet p = new Packet(200);

            p.WriteInt(m.MonsterID);
            p.WriteByte((byte)m.Type);
            p.WriteHexString("00 00 00 00");
            p.WriteInt(pet.PetID);
            p.WriteByte((byte)pet.Type);
            p.WriteInt(pet.OwnerID);
            p.WriteString(pet.Name);
            return p.GetWrittenBuffer(PacketIds.SendPetBaitTaken);
        }
Пример #12
0
 public static byte[] SendExpEffectPacket(Monster m)
 {
     Packet p = new Packet(200);
     p.WriteByte((byte)m.Type);
     p.WriteInt(m.MonsterID);
     p.WriteInt(m.Experience);
     return p.GetWrittenBuffer(PacketIds.SendExpEffectPacket);
 }
Пример #13
0
 public static byte[] SendCast2(BaseSkill skill, CastSkillInfo i, Monster m)
 {
     Packet p = new Packet(500);
     p.WriteByte((byte)i.Type);
     p.WriteInt(skill.SkillID);
     p.WriteByte(skill.SkillLevel);
     p.WriteByte(i.CasterType);
     p.WriteInt(i.CasterID);
     p.WriteShort(i.CasterX);
     p.WriteShort(i.CasterY);
     p.WriteByte(i.CasterZ);
     if (m != null)
     {
         p.WriteByte(3);
         p.WriteInt(m.MonsterID);
         p.WriteInt(m.MaxHealth);
         p.WriteInt(m.CurHealth);
         p.WriteInt(i.Damage);
         p.WriteInt(i.Experience);
         p.WriteHexString("00");
     }
     else
     {
         p.WriteByte(i.TargetType);
         p.WriteInt(i.TargetID);
         p.WriteHexString("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00");
     }
     return p.GetWrittenBuffer(PacketIds.SendCast2);
 }
Пример #14
0
 public Movement(Monster owner)
 {
     m_owner = owner;
     m_MayMove = true;
 }
Пример #15
0
        public Client[] GetNearClientsByMonster(Monster m)
        {
            try
            {
                var nearbyClients = clients.Where(x => (MapEngine.GetDistance(m.Position.X, m.Position.Y, x.MyCharacter.Position.X, x.MyCharacter.Position.Y) <= m.SightRange + 15) && x.Map.MapID == m.MapID);

                return nearbyClients.ToArray();
            }
            catch
            {
                return null;
            }
        }
Пример #16
0
        private Client[] GetNearByClients(Monster m)
        {
            try
            {
                var nearbyClients = clients.Where(x => (x.MyCharacter.MapId == m.MapID && MapEngine.GetDistance(x.MyCharacter.Position.X, x.MyCharacter.Position.Y, m.Position.X, m.Position.Y) < 150));

                return nearbyClients.ToArray();
            }
            catch
            {
                return null;
            }
        }
Пример #17
0
        public List<Monster> GetMonstersByMapId(int mapId)
        {
            DbParameter mapIdParameter = _db.CreateParameter(DbNames.GETMONSTERSBYMAPID_ID_PARAMETER, mapId);
            mapIdParameter.DbType = System.Data.DbType.Int32;

            _db.Open();

            DbDataReader reader = _db.ExcecuteReader(DbNames.GETMONSTERSBYMAPID_STOREDPROC, System.Data.CommandType.StoredProcedure, mapIdParameter);

            int ordinalMonster_count = reader.GetOrdinal(DbNames.MONSTER_COUNT);
            int ordinalMonster_type = reader.GetOrdinal(DbNames.MONSTER_TYPE);
            int ordinalMonster_level = reader.GetOrdinal(DbNames.MONSTER_LEVEL);
            int ordinalMonster_name = reader.GetOrdinal(DbNames.MONSTER_NAME);
            int ordinalMonster_health = reader.GetOrdinal(DbNames.MONSTER_HEALTH);
            int ordinalMonster_damage = reader.GetOrdinal(DbNames.MONSTER_DAMAGE);
            int ordinalMonster_defense = reader.GetOrdinal(DbNames.MONSTER_DEFENSE);
            int ordinalMonster_attackrating = reader.GetOrdinal(DbNames.MONSTER_ATTACKRATING);
            int ordinalMonster_walkspeed = reader.GetOrdinal(DbNames.MONSTER_WALKSPEED);
            int ordinalMonster_sightrange = reader.GetOrdinal(DbNames.MONSTER_SIGHTRANGE);
            int ordinalMonster_wanderrange = reader.GetOrdinal(DbNames.MONSTER_WANDERRANGE);
            int ordinalMonster_attackrange = reader.GetOrdinal(DbNames.MONSTER_ATTACKRANGE);
            int ordinalMonster_experience = reader.GetOrdinal(DbNames.MONSTER_EXPERIENCE);
            int ordinalMonster_healpoint = reader.GetOrdinal(DbNames.MONSTER_HEALPOINT);
            int ordinalMonster_regeneration = reader.GetOrdinal(DbNames.MONSTER_REGENERATION);
            int ordinalMonster_id = reader.GetOrdinal(DbNames.MONSTER_ID); // monster ref id
            int ordinalMonster_mapid = reader.GetOrdinal(DbNames.MONSTER_MAPID);
            int ordinalMonster_spawnx = reader.GetOrdinal(DbNames.MONSTER_SPAWNX);
            int ordinalMonster_spawny = reader.GetOrdinal(DbNames.MONSTER_SPAWNY);
            int ordinalMonster_groupid = reader.GetOrdinal(DbNames.MONSTER_GROUPID);
            int ordinalMonster_grouporder = reader.GetOrdinal(DbNames.MONSTER_GROUPORDER);
            int ordinalMonster_leaderid = reader.GetOrdinal(DbNames.MONSTER_LEADERID);
            int ordinalMonster_healthinc = reader.GetOrdinal(DbNames.MONSTER_HEALTHINC);
            int ordinalMonster_damageinc = reader.GetOrdinal(DbNames.MONSTER_DAMAGEINC);
            int ordinalMonster_defenseinc = reader.GetOrdinal(DbNames.MONSTER_DEFENSEINC);
            int ordinalMonster_attackratinginc = reader.GetOrdinal(DbNames.MONSTER_ATTACKRATINGINC);
            int ordinalMonster_attackrangeinc = reader.GetOrdinal(DbNames.MONSTER_ATTACKRANGEINC);
            int ordinalMonster_expinc = reader.GetOrdinal(DbNames.MONSTER_EXPINC);
            int ordinalMonster_istameable = reader.GetOrdinal(DbNames.MONSTER_ISTAMEABLE);

            List<Monster> listMonsters = new List<Monster>();

            while (reader.Read())
            {
                int count = reader.GetInt32(ordinalMonster_count);

                for (int i = 0; i < count; i++)
                {
                    Monster p = new Monster
                    {
                        MonsterType = reader.GetByte(ordinalMonster_type),
                        Level = reader.GetInt16(ordinalMonster_level),
                        Name = reader.GetString(ordinalMonster_name),
                        MaxHealth = reader.GetInt32(ordinalMonster_health),
                        HealthInc = reader.GetInt32(ordinalMonster_healthinc),
                        Damage = reader.GetInt32(ordinalMonster_damage),
                        DamageInc = reader.GetInt16(ordinalMonster_damageinc),
                        Defense = reader.GetInt32(ordinalMonster_defense),
                        DefenseInc = reader.GetInt16(ordinalMonster_defenseinc),
                        AttackRating = reader.GetInt32(ordinalMonster_attackrating),
                        AttackRatingInc = reader.GetInt16(ordinalMonster_attackratinginc),
                        AttackRange = reader.GetInt16(ordinalMonster_attackrange),
                        AttackRangeInc = reader.GetInt16(ordinalMonster_attackrangeinc),
                        MovementSpeed = reader.GetByte(ordinalMonster_walkspeed),
                        SightRange = reader.GetInt16(ordinalMonster_sightrange),
                        WanderRange = reader.GetInt16(ordinalMonster_wanderrange),
                        Experience = reader.GetInt32(ordinalMonster_experience),
                        ExperienceInc = reader.GetInt32(ordinalMonster_expinc),
                        HealPoint = reader.GetInt32(ordinalMonster_healpoint),
                        Regeneration = reader.GetInt16(ordinalMonster_regeneration),
                        MonsterID = reader.GetInt32(ordinalMonster_id),
                        MapID = reader.GetInt32(ordinalMonster_mapid),
                        SpawnX = reader.GetInt16(ordinalMonster_spawnx),
                        SpawnY = reader.GetInt16(ordinalMonster_spawny),
                        GroupID = reader.GetInt16(ordinalMonster_groupid),
                        GroupOrder = reader.GetByte(ordinalMonster_grouporder),
                        LeaderID = reader.GetInt32(ordinalMonster_leaderid),
                        IsTameable = reader.GetBoolean(ordinalMonster_istameable)
                    };

                    totalMonstersLoaded++;

                    // it loads the monster id as reference id so keh
                    p.MonsterReferenceID = p.MonsterID;

                    // so we can have multiple monsters for one reference id :)
                    p.MonsterID = totalMonstersLoaded;

                    p.CurHealth = p.MaxHealth;

                    // so all wont stack together now they have small distances between others
                    p.SpawnX = (short)rand.Next(p.SpawnX, p.SpawnX + p.WanderRange);
                    p.SpawnY = (short)rand.Next(p.SpawnY, p.SpawnY + p.WanderRange);

                    p.Position = new Position();
                    p.Position.X = p.SpawnX;
                    p.Position.Y = p.SpawnY;
                    p.Alive = true;

                    listMonsters.Add(p);
                }
            }

            reader.Close();
            _db.Close();

            return listMonsters;
        }
Пример #18
0
        public Monster[] GetMonstersByRange(Monster m, int distance)
        {
            try
            {
                //var map = maps.Where(x => x.MapID == m.MapID).First();
                var monsters = Map.Monsters.Where(x => x.Alive && GetDistance(x.Position.X, x.Position.Y, m.Position.X, m.Position.Y) < distance);

                return monsters.ToArray();
            }
            catch
            {
                return null;
            }
        }
Пример #19
0
        public BaseItem GetRebirthPillDrop(Monster m)
        {
            DbParameter levelParameter = _db.CreateParameter(DbNames.GETPILLDROPITEM_LEVEL_PARAMETER, m.Level);
            levelParameter.DbType = DbType.Int32;

            List<BaseItem> items = new List<BaseItem>();

            _db.Open();

            DbDataReader reader = _db.ExcecuteReader(DbNames.GETPILLDROPITEM_STOREDPROC, CommandType.StoredProcedure, levelParameter);

            int ordinalITEM_REFERENCEID = reader.GetOrdinal(DbNames.ITEM_REFERENCEID);
            int ordinalITEM_BTYPE = reader.GetOrdinal(DbNames.ITEM_BTYPE);
            int ordinalITEM_BKIND = reader.GetOrdinal(DbNames.ITEM_BKIND);
            int ordinalITEM_VISUALID = reader.GetOrdinal(DbNames.ITEM_VISUALID);
            int ordinalITEM_COST = reader.GetOrdinal(DbNames.ITEM_COST);
            int ordinalITEM_CLASS = reader.GetOrdinal(DbNames.ITEM_CLASS);
            int ordinalITEM_LEVEL = reader.GetOrdinal(DbNames.ITEM_LEVEL);
            int ordinalITEM_DEX = reader.GetOrdinal(DbNames.ITEM_DEX);
            int ordinalITEM_STR = reader.GetOrdinal(DbNames.ITEM_STR);
            int ordinalITEM_STA = reader.GetOrdinal(DbNames.ITEM_STA);
            int ordinalITEM_ENE = reader.GetOrdinal(DbNames.ITEM_ENE);
            int ordinalITEM_MAXIMBUES = reader.GetOrdinal(DbNames.ITEM_MAXIMBUES);
            int ordinalITEM_MAXDURA = reader.GetOrdinal(DbNames.DROPITEM_DURABILITY);
            int ordinalITEM_DAMAGE = reader.GetOrdinal(DbNames.ITEM_DAMAGE);
            int ordinalITEM_DEFENCE = reader.GetOrdinal(DbNames.ITEM_DEFENCE);
            int ordinalITEM_ATTACKRATING = reader.GetOrdinal(DbNames.ITEM_ATTACKRATING);
            int ordinalITEM_ATTACKSPEED = reader.GetOrdinal(DbNames.ITEM_ATTACKSPEED);
            int ordinalITEM_ATTACKRANGE = reader.GetOrdinal(DbNames.ITEM_ATTACKRANGE);
            int ordinalITEM_INCMAXLIFE = reader.GetOrdinal(DbNames.ITEM_INCMAXLIFE);
            int ordinalITEM_INCMAXMANA = reader.GetOrdinal(DbNames.ITEM_INCMAXMANA);
            int ordinalITEM_LIFEREGEN = reader.GetOrdinal(DbNames.ITEM_LIFEREGEN);
            int ordinalITEM_MANAREGEN = reader.GetOrdinal(DbNames.ITEM_MANAREGEN);
            int ordinalITEM_CRITICAL = reader.GetOrdinal(DbNames.ITEM_CRITICAL);
            int ordinalITEM_TOMAPID = reader.GetOrdinal(DbNames.ITEM_TOMAPID);
            int ordinalITEM_IMBUERATE = reader.GetOrdinal(DbNames.ITEM_IMBUERATE);
            int ordinalITEM_IMBUEINCREASE = reader.GetOrdinal(DbNames.ITEM_IMBUEINCREASE);
            int ordinalITEM_BOOKSKILLID = reader.GetOrdinal(DbNames.ITEM_BOOKSKILLID);
            int ordinalITEM_BOOKSKILLLEVEL = reader.GetOrdinal(DbNames.ITEM_BOOKSKILLLEVEL);
            int ordinalITEM_BOOKSKILLDATA = reader.GetOrdinal(DbNames.ITEM_BOOKSKILLDATA);
            int ordinalITEM_MAXPOLISHTRIES = reader.GetOrdinal(DbNames.ITEM_MAXPOLISHTRIES);
            int ordinalITEM_POLISHTRIES = reader.GetOrdinal(DbNames.ITEM_POLISHTRIES);
            int ordinalITEM_SIZEX = reader.GetOrdinal(DbNames.ITEM_SIZEX);
            int ordinalITEM_SIZEY = reader.GetOrdinal(DbNames.ITEM_SIZEY);
            while (reader.Read())
            {
                BaseItem b = null;

                int BType = reader.GetByte(ordinalITEM_BTYPE);
                int BKind = reader.GetByte(ordinalITEM_BKIND);

                if (BType == (byte)bType.Weapon || BType == (byte)bType.Clothes || BType == (byte)bType.Hat || BType == (byte)bType.Necklace
                    || BType == (byte)bType.Ring || BType == (byte)bType.Shoes || BType == (byte)bType.Cape)
                {

                    if (BKind == (byte)bKindWeapons.Sword && BType == (byte)bType.Weapon)
                    {
                        b = new Sword();
                    }
                    if (BKind == (byte)bKindWeapons.Blade && BType == (byte)bType.Weapon)
                    {
                        b = new Blade();
                    }
                    if (BKind == (byte)bKindWeapons.Fan && BType == (byte)bType.Weapon)
                    {
                        b = new Fan();
                    }
                    if (BKind == (byte)bKindWeapons.Brush && BType == (byte)bType.Weapon)
                    {
                        b = new Brush();
                    }
                    if (BKind == (byte)bKindWeapons.Claw && BType == (byte)bType.Weapon)
                    {
                        b = new Claw();
                    }
                    if (BKind == (byte)bKindWeapons.Axe && BType == (byte)bType.Weapon)
                    {
                        b = new Axe();
                    }
                    if (BKind == (byte)bKindWeapons.Talon && BType == (byte)bType.Weapon)
                    {
                        b = new Talon();
                    }
                    if (BKind == (byte)bKindWeapons.Tonfa && BType == (byte)bType.Weapon)
                    {
                        b = new Tonfa();
                    }
                    if (BKind == (byte)bKindArmors.SwordMan && BType == (byte)bType.Clothes)
                    {
                        b = new Clothes();
                    }
                    if (BKind == (byte)bKindArmors.Mage && BType == (byte)bType.Clothes)
                    {
                        b = new Dress();
                    }
                    if (BKind == (byte)bKindArmors.Warrior && BType == (byte)bType.Clothes)
                    {
                        b = new Armor();
                    }
                    if (BKind == (byte)bKindArmors.GhostFighter && BType == (byte)bType.Clothes)
                    {
                        b = new LeatherClothes();
                    }
                    if (BKind == (byte)bKindHats.SwordMan && BType == (byte)bType.Hat)
                    {
                        b = new Hood();
                    }
                    if (BKind == (byte)bKindHats.Mage && BType == (byte)bType.Hat)
                    {
                        b = new Tiara();
                    }
                    if (BKind == (byte)bKindHats.Warrior && BType == (byte)bType.Hat)
                    {
                        b = new Helmet();
                    }
                    if (BKind == (byte)bKindHats.GhostFighter && BType == (byte)bType.Hat)
                    {
                        b = new Hat();
                    }
                    if (BKind == (byte)bKindHats.SwordMan && BType == (byte)bType.Shoes)
                    {
                        b = new SmBoots();
                    }
                    if (BKind == (byte)bKindHats.Mage && BType == (byte)bType.Shoes)
                    {
                        b = new MageBoots();
                    }
                    if (BKind == (byte)bKindHats.Warrior && BType == (byte)bType.Shoes)
                    {
                        b = new WarriorShoes();
                    }
                    if (BKind == (byte)bKindHats.GhostFighter && BType == (byte)bType.Shoes)
                    {
                        b = new GhostFighterShoes();
                    }
                    if (BKind == 0 && BType == (byte)bType.Ring)
                    {
                        b = new Ring();
                    }
                    if (BKind == 0 && BType == (byte)bType.Necklace)
                    {
                        b = new Necklace();
                    }
                    if (BType == (byte)bType.Cape)
                    {
                        b = new Cape();
                        Cape c = b as Cape;
                        c.MaxPolishImbueTries = reader.GetInt16(ordinalITEM_MAXPOLISHTRIES);
                        c.PolishImbueTries = reader.GetByte(ordinalITEM_POLISHTRIES);
                    }

                    Equipment e = b as Equipment;
                    e.RequiredLevel = reader.GetInt16(ordinalITEM_LEVEL);
                    e.RequiredDexterity = reader.GetInt16(ordinalITEM_DEX);
                    e.RequiredStrength = reader.GetInt16(ordinalITEM_STR);
                    e.RequiredStamina = reader.GetInt16(ordinalITEM_STA);
                    e.RequiredEnergy = reader.GetInt16(ordinalITEM_ENE);
                    e.MaxImbueTries = reader.GetByte(ordinalITEM_MAXIMBUES);
                    e.Durability = reader.GetInt32(ordinalITEM_MAXDURA);
                    e.MaxDurability = reader.GetInt32(ordinalITEM_MAXDURA);
                    e.Damage = reader.GetInt32(ordinalITEM_DAMAGE);
                    e.Defence = reader.GetInt32(ordinalITEM_DEFENCE);
                    e.AttackRating = reader.GetInt32(ordinalITEM_ATTACKRATING);
                    e.AttackSpeed = reader.GetInt16(ordinalITEM_ATTACKSPEED);
                    e.AttackRange = reader.GetInt16(ordinalITEM_ATTACKRANGE);
                    e.IncMaxLife = reader.GetInt16(ordinalITEM_INCMAXLIFE);
                    e.IncMaxMana = reader.GetInt16(ordinalITEM_INCMAXMANA);
                    e.IncLifeRegen = reader.GetInt16(ordinalITEM_LIFEREGEN);
                    e.IncManaRegen = reader.GetInt16(ordinalITEM_MANAREGEN);
                    e.Critical = reader.GetInt16(ordinalITEM_CRITICAL);
                }

                if (BType == (byte)bType.ImbueItem)
                {
                    if (BKind == (byte)bKindStones.Black)
                    {
                        b = new Black();
                    }
                    if (BKind == (byte)bKindStones.White)
                    {
                        b = new White();
                    }
                    if (BKind == (byte)bKindStones.Red)
                    {
                        b = new Red();
                    }
                    if (BKind == (byte)bKindStones.Dragon)
                    {
                        b = new Dragon();
                    }
                    if (BKind == (byte)bKindStones.RbItem)
                    {
                        b = new RbHoleItem();
                    }

                    ImbueItem im = b as ImbueItem;
                    im.ImbueChance = reader.GetInt16(ordinalITEM_IMBUERATE);
                    im.IncreaseValue = reader.GetInt16(ordinalITEM_IMBUEINCREASE);
                }

                if (BType == (byte)bType.Potion)
                {
                    if (BKind == (byte)bKindPotions.Normal)
                    {
                        b = new Potion();
                    }
                    if (BKind == (byte)bKindPotions.Elixir)
                    {
                        b = new Elixir();
                    }

                    PotionItem pot = b as PotionItem;
                    pot.HealHp = reader.GetInt16(ordinalITEM_INCMAXLIFE);
                    pot.HealMana = reader.GetInt16(ordinalITEM_INCMAXMANA);
                }
                if (BType == (byte)bType.Book)
                {
                    if (BKind == (byte)bKindBooks.SoftBook)
                    {
                        b = new SoftBook();
                    }
                    if (BKind == (byte)bKindBooks.HardBook)
                    {
                        b = new HardBook();
                    }
                    if (BKind == (byte)bKindBooks.RebirdBook)
                    {
                        b = new RebirthBook();
                    }
                    if (BKind == (byte)bKindBooks.FourthBook)
                    {
                        b = new FourthBook();
                    }
                    if (BKind == (byte)bKindBooks.FeSkillBook)
                    {
                        b = new FeSkillBook();
                    }
                    if (BKind == (byte)bKindBooks.FeBook)
                    {
                        b = new FiveElementBook();
                    }
                    if (BKind == (byte)bKindBooks.FocusBook)
                    {
                        b = new FocusBook();
                    }

                    BookItem book = b as BookItem;
                    book.RequiredClass = reader.GetByte(ordinalITEM_CLASS);
                    book.RequiredLevel = reader.GetInt16(ordinalITEM_LEVEL);
                    book.SkillID = reader.GetInt32(ordinalITEM_BOOKSKILLID);
                    book.SkillLevel = reader.GetByte(ordinalITEM_BOOKSKILLLEVEL);
                    book.SkillData = reader.GetInt32(ordinalITEM_BOOKSKILLDATA);
                }
                if (BType == (byte)bType.Bead)
                {
                    if (BKind == (byte)bKindBeads.Normal)
                    {
                        b = new Bead();
                    }
                    BeadItem bead = b as BeadItem;
                    bead.ToMapID = reader.GetInt32(ordinalITEM_TOMAPID);
                }
                if (BType == (byte)bType.StoreTag)
                {
                    b = new StoreTag();

                    StoreTag tag = b as StoreTag;
                    tag.TimeLeft = reader.GetInt16(ordinalITEM_MAXDURA);
                    tag.TimeMax = reader.GetInt16(ordinalITEM_MAXDURA);
                }
                if (BType == (byte)bType.PetItem)
                {
                    if (BKind == (byte)bKindPetItems.Taming)
                        b = new TameItem();
                    if (BKind == (byte)bKindPetItems.Food)
                        b = new PetFood();
                    if (BKind == (byte)bKindPetItems.Potion)
                        b = new PetPotion();
                    if (BKind == (byte)bKindPetItems.Resurect)
                        b = new PetResurrectItem();

                    PetItem p = b as PetItem;
                    p.TameChance = reader.GetInt16(ordinalITEM_IMBUERATE);
                    p.DecreaseWildness = reader.GetInt16(ordinalITEM_IMBUEINCREASE);
                    p.HealLife = reader.GetInt16(ordinalITEM_INCMAXLIFE);
                }
                if (BType == (byte)bType.Pill)
                {
                    if (BKind == (byte)bKindPills.Rebirth)
                        b = new RebirthPill();

                    RebirthPill p = b as RebirthPill;
                    p.RequiredLevel = reader.GetInt16(ordinalITEM_LEVEL);
                    p.RequiredRebirth = reader.GetByte(ordinalITEM_CLASS);
                    p.ToRebirth = (byte)(p.RequiredRebirth + 1);
                    p.IncreaseSp = reader.GetInt16(ordinalITEM_DEX);
                }

                b.ItemID = 0;
                b.OwnerID = 0;
                b.ReferenceID = reader.GetInt16(ordinalITEM_REFERENCEID);
                b.VisualID = reader.GetInt16(ordinalITEM_VISUALID);
                b.Bag = 0;
                b.Slot = 0;
                b.bType = reader.GetByte(ordinalITEM_BTYPE);
                b.bKind = reader.GetByte(ordinalITEM_BKIND);
                b.RequiredClass = reader.GetByte(ordinalITEM_CLASS);
                b.Amount = 1;
                b.SizeX = reader.GetByte(ordinalITEM_SIZEX);
                b.SizeY = reader.GetByte(ordinalITEM_SIZEY);
                b.Price = reader.GetInt32(ordinalITEM_COST);
                items.Add(b);
            }

            reader.Close();
            _db.Close();

            if (items.Count > 0)
            {
                Random rand = new Random();
                int itemPos = rand.Next(0, items.Count);
                return items[itemPos];
            }
            else
                return null;
        }