Example #1
0
        public bool CanTarget(Entities.Monster Target, Skills.Skill Skill)
        {
            if (Target.HitPoints == 0)
            {
                return(false);
            }
            if (Calculations.GetDistance(X, Y, Target.X, Target.Y) > Skill.SkillInfo.Range)
            {
                return(false);
            }

            if (Skill.SkillInfo.DamageType == Enums.DamageType.HealHP)
            {
                return(true);
            }
            else if (Skill.SkillInfo.DamageType == Enums.DamageType.HealMP)
            {
                return(false);
            }

            if (Skill.SkillInfo.ExtraEffect == Enums.SkillExtraEffect.Poison)
            {
                return(true);
            }
            else if (Skill.SkillInfo.ExtraEffect != Enums.SkillExtraEffect.None)
            {
                return(false);
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// Gets the physical magic damage. (MVP)
        /// </summary>
        /// <param name="attacker">The attacker.</param>
        /// <param name="attacked">The attacked.</param>
        /// <param name="spell">The spell.</param>
        /// <returns>Returns the damage.</returns>
        private static double GetPhysicalMagicDamage_MVP(Entities.Monster attacker, Entities.GameClient attacked, Data.Spell spell)
        {
            double damage = (double)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)attacker.MaxAttack, (int)attacker.MaxAttack * 2);

            damage -= attacked.Defense;
            damage *= 0.65;
            // penetration extra damage
            if (spell.SpellID == 1290 && damage > 0)
            {
                double hunperc = (double)((damage / 100) * 26.6);
                damage += (hunperc * spell.Level);
            }

            if (attacked.ContainsFlag1(Enums.Effect1.Shield))
            {
                damage *= 0.5;
            }
            //	damage += spell.Power;
            //damage *= 1 + attacker.PhoenixGemPercentage;
            //	damage -= attacked.Defense;
            //	double damage_perc = damage;
            //	damage_perc = (damage / 100) * attacked.TortoiseGemPercentage;
            //	damage -= damage_perc;
            //	damage_perc = (damage / 100) * attacked.Bless;
            //	damage -= damage_perc;

            return(damage);
        }
Example #3
0
 public bool CanTarget(Entities.Monster Target)
 {
     if (Target.HitPoints == 0)
     {
         return(false);
     }
     if (Calculations.GetDistance(X, Y, Target.X, Target.Y) > AttackRange)
     {
         return(false);
     }
     return(true);
 }
Example #4
0
 public void Insert(Entities.Monster Mob)
 {
     if (Monsters.TryAdd(Mob.UniqueID, Mob))
     {
         foreach (SocketClient client in Players.Values)
         {
             if (Calculations.GetDistance(client.Character.X, client.Character.Y, Mob.X, Mob.Y) <= Constants.ScreenDistance)
             {
                 client.Character.Screen.Insert(Mob);
             }
         }
     }
 }
Example #5
0
        public static void AddNewMonsterSpawn(ushort mapid, ushort x, ushort y, int monsterid, int count, int drop, int range, bool guard)
        {
            using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.INSERT, false))
                {
                    cmd.AddInsertValue("MonsterID", monsterid);
                    cmd.AddInsertValue("CenterX", x);
                    cmd.AddInsertValue("CenterY", y);
                    cmd.AddInsertValue("Drop", drop);
                    cmd.AddInsertValue("Count", count);
                    if (guard)
                    {
                        cmd.AddInsertValue("Range", (int)1);
                    }
                    else
                    {
                        cmd.AddInsertValue("Range", range);
                    }
                    cmd.Finish("DB_MobSpawns");
                }
                sql.Execute();
            }

            for (int i = 0; i < count; i++)
            {
                Entities.Monster spawnmob = Core.Kernel.Monsters[monsterid].Copy();
                spawnmob.Direction = (byte)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(0, 8);
                if (Core.Kernel.Maps[mapid].EnterMap(spawnmob))
                {
                    Maps.MapPoint Location = spawnmob.Map.CreateAvailableLocation <Entities.Monster>(x, y, range);
                    if (Location != null)
                    {
                        spawnmob.X             = Location.X;
                        spawnmob.Y             = Location.Y;
                        spawnmob.OriginalRange = range;
                        spawnmob.OriginalX     = x;
                        spawnmob.OriginalY     = y;

                        //if (drop > 0)
                        //{
                        //	spawnmob.DropData = Core.Kernel.DropData[drop].Copy();
                        //}

                        Threads.MonsterThread.AddToMonsterThread(spawnmob, !(((byte)spawnmob.Behaviour) < 3 || spawnmob.Behaviour == Enums.MonsterBehaviour.PhysicalGuard));

                        spawnmob.Screen.UpdateScreen(null);
                    }
                }
            }
        }
Example #6
0
        /// <summary>
        /// Gets the physical damage (MVM).
        /// </summary>
        /// <param name="attacker">The attacker.</param>
        /// <param name="attacked">The attacked.</param>
        /// <returns>Returns the damage.</returns>
        private static double GetPhysicalDamage_MVM(Entities.Monster attacker, Entities.Monster attacked)
        {
            double damage = ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)attacker.MinAttack, (int)attacker.MaxAttack);

            //damage *= 1 + attacker.DragonGemPercentage;
            damage -= attacked.Defense;
            //double damage_perc = damage;
            //damage_perc = (damage / 100) * attacked.TortoiseGemPercentage;
            //damage -= damage_perc;
            //damage_perc = (damage / 100) * attacked.Bless;
            //damage -= damage_perc;

            return(damage);
        }
Example #7
0
        /// <summary>
        /// Gets the magic damage. (MVM)
        /// </summary>
        /// <param name="attacker">The attacker.</param>
        /// <param name="attacked">The attacked.</param>
        /// <param name="spell">The spell.</param>
        /// <returns>Returns the damage.</returns>
        private static double GetMagicDamage_MVM(Entities.Monster attacker, Entities.Monster attacked, Data.Spell spell)
        {
            double damage = attacker.MaxAttack;

            damage -= attacked.MagicDefense;
            damage *= 0.65;
            damage += spell.Power;
            //	damage *= 1 + attacker.PhoenixGemPercentage;
            //	damage -= attacked.Defense;
            //	double damage_perc = damage;
            //	damage_perc = (damage / 100) * attacked.TortoiseGemPercentage;
            //	damage -= damage_perc;
            //	damage_perc = (damage / 100) * attacked.Bless;
            //	damage -= damage_perc;

            return(damage);
        }
Example #8
0
 public bool Insert(Entities.Monster Monster)
 {
     if (Monsters.TryAdd(Monster.UniqueID, Monster))
     {
         Monster.Screen.TryAdd(Owner.UniqueID, Owner);
         Owner.Send(Monster.ToBytes());
         return(true);
     }
     if (Monster.Target == null)
     {
         Monster.Target = Owner;
     }
     else if (Calculations.GetDistance(Monster.X, Monster.Y, Monster.Target.Character.X, Monster.Target.Character.Y) > Calculations.GetDistance(Monster.X, Monster.Y, Owner.Character.X, Owner.Character.Y))
     {
         Monster.Target = Owner;
     }
     return(false);
 }
Example #9
0
        /// <summary>
        /// Gets the physical damage (PVM).
        /// </summary>
        /// <param name="attacker">The attacker.</param>
        /// <param name="attacked">The attacked.</param>
        /// <returns>Returns the damage.</returns>
        private static double GetPhysicalDamage_PVM(Entities.GameClient attacker, Entities.Monster attacked)
        {
            double damage = ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(attacker.MinAttack, attacker.MaxAttack);

            damage *= 1 + attacker.DragonGemPercentage;
            damage -= attacked.Defense;

            if (attacker.ContainsFlag1(Enums.Effect1.Stig))
            {
                damage *= 1.75;
            }
            //double damage_perc = damage;
            //damage_perc = (damage / 100) * attacked.TortoiseGemPercentage;
            //damage -= damage_perc;
            //damage_perc = (damage / 100) * attacked.Bless;
            //damage -= damage_perc;

            return(damage);
        }
Example #10
0
 public static void LoadMonsterSpawns()
 {
     foreach (Mapping.Map M in Kernel.Maps.Values)
     {
         if (Directory.Exists("C:/db/Mobs/" + M.UniqueID))
         {
             string[] Files = Directory.GetFiles("C:/db/Mobs/" + M.UniqueID);
             foreach (string FilePath in Files)
             {
                 uint MobID = uint.Parse(FilePath.Remove(0, FilePath.LastIndexOf('\\') + 1).Replace(".ini", ""));
                 Entities.MonsterType MonsterType;
                 if (Kernel.MonsterTypes.TryGetValue(MobID, out MonsterType))
                 {
                     string[] Data = File.ReadAllLines(FilePath);
                     foreach (string spawnData in Data)
                     {
                         if (spawnData != "")
                         {
                             string[] line = spawnData.Split(' ');
                             Mapping.MobSpawn Spawn = new Mapping.MobSpawn(int.Parse(line[0]), int.Parse(line[1]), int.Parse(line[2]), int.Parse(line[3]));
                             Spawn.UniqueID = Increments.NextSpawnUID;
                             byte MobAmount = byte.Parse(line[4]);
                             for (int x = 0; x < MobAmount; x++)
                             {
                                 Entities.Monster Mob = new Entities.Monster(MonsterType, Spawn);
                                 int px, py;
                                 Spawn.GetLocation(out px, out py);
                                 Mob.Map = M;
                                 Mob.RespawnDelay = Program.Random.Next(1000, 4000);
                                 Mob.X = Mob.SpawnX = (ushort)px;
                                 Mob.Y = Mob.SpawnY = (ushort)py;
                                 M.Insert(Mob);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Example #11
0
 public static void LoadMonsterSpawns()
 {
     foreach (Mapping.Map M in Kernel.Maps.Values)
     {
         if (Directory.Exists("C:/db/Mobs/" + M.UniqueID))
         {
             string[] Files = Directory.GetFiles("C:/db/Mobs/" + M.UniqueID);
             foreach (string FilePath in Files)
             {
                 uint MobID = uint.Parse(FilePath.Remove(0, FilePath.LastIndexOf('\\') + 1).Replace(".ini", ""));
                 Entities.MonsterType MonsterType;
                 if (Kernel.MonsterTypes.TryGetValue(MobID, out MonsterType))
                 {
                     string[] Data = File.ReadAllLines(FilePath);
                     foreach (string spawnData in Data)
                     {
                         if (spawnData != "")
                         {
                             string[]         line  = spawnData.Split(' ');
                             Mapping.MobSpawn Spawn = new Mapping.MobSpawn(int.Parse(line[0]), int.Parse(line[1]), int.Parse(line[2]), int.Parse(line[3]));
                             Spawn.UniqueID = Increments.NextSpawnUID;
                             byte MobAmount = byte.Parse(line[4]);
                             for (int x = 0; x < MobAmount; x++)
                             {
                                 Entities.Monster Mob = new Entities.Monster(MonsterType, Spawn);
                                 int px, py;
                                 Spawn.GetLocation(out px, out py);
                                 Mob.Map          = M;
                                 Mob.RespawnDelay = Program.Random.Next(1000, 4000);
                                 Mob.X            = Mob.SpawnX = (ushort)px;
                                 Mob.Y            = Mob.SpawnY = (ushort)py;
                                 M.Insert(Mob);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Example #12
0
        void Movement(Entities.Monster mob)
        {
            if (!mob.Alive)
            {
                return;
            }

            try
            {
                if (mob.Target != null)
                {
                    if (DateTime.Now >= mob.MoveTime)
                    {
                        try
                        {
                            if (Core.Screen.GetDistance(mob.X, mob.Y, mob.Target.X, mob.Target.Y) >= mob.ViewRange)
                            {
                                byte          dir       = (byte)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(0, 8);
                                Maps.MapPoint movepoint = Packets.MovementPacket.CreateDirectionPoint(mob.X, mob.Y, dir);
                                if (mob.Map.ValidMoveCoord <Entities.Monster>(movepoint.X, movepoint.Y))
                                {
                                    mob.X         = movepoint.X;
                                    mob.Y         = movepoint.Y;
                                    mob.Direction = dir;
                                    using (var movepacket = new Packets.MovementPacket())
                                    {
                                        movepacket.EntityUID = mob.EntityUID;
                                        movepacket.TimeStamp = ProjectX_V3_Lib.Native.Winmm.timeGetTime();
                                        movepacket.Direction = (uint)dir;
                                        movepacket.WalkMode  = Enums.WalkMode.Run;
                                        mob.Screen.UpdateScreen(movepacket);
                                    }
                                    mob.MoveTime = DateTime.Now.AddMilliseconds(mob.MoveSpeed * 5);
                                }
                                return;
                            }
                            else
                            {
                                byte          dir       = (byte)Core.Screen.GetFacing(Core.Screen.GetAngle(mob.X, mob.Y, mob.Target.X, mob.Target.Y));
                                Maps.MapPoint movepoint = Packets.MovementPacket.CreateDirectionPoint(mob.X, mob.Y, dir);
                                if (mob.Map.ValidMoveCoord <Entities.Monster>(movepoint.X, movepoint.Y))
                                {
                                    mob.X         = movepoint.X;
                                    mob.Y         = movepoint.Y;
                                    mob.Direction = dir;
                                    using (var movepacket = new Packets.MovementPacket())
                                    {
                                        movepacket.EntityUID = mob.EntityUID;
                                        movepacket.TimeStamp = ProjectX_V3_Lib.Native.Winmm.timeGetTime();
                                        movepacket.Direction = (uint)dir;
                                        movepacket.WalkMode  = Enums.WalkMode.Run;
                                        mob.Screen.UpdateScreen(movepacket);
                                    }
                                }
                                int nextmove = ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(mob.MoveSpeed, mob.MoveSpeed * 2);
                                mob.MoveTime = DateTime.Now.AddMilliseconds(nextmove);
                            }
                        }
                        catch
                        {
                        }                         // target was removed again / out of range :s there is a concurrency problem, just cba to look for it as it's nothing major
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Example #13
0
        /// <summary>
        /// Processing damage.
        /// </summary>
        /// <param name="attacker">The attacker.</param>
        /// <param name="attacked">The attacked.</param>
        /// <param name="damage">The damage.</param>
        public static void ProcessDamage(Entities.IEntity attacker, Entities.IEntity attacked, ref uint damage, bool kill_damage = true)
        {
            // Removed dura, bugged atm. the dura works, although client doesn't update proper etc. CBA to fix it as I never intended to use it
            // Although you can go ahead and fix it yourself if you want, I may do it if I ever feel like it
            // The dura lose is commented out below.
            #region ATTACKER : GAMECLIENT
            if (attacker is Entities.GameClient)
            {
                Entities.GameClient attackerclient = attacker as Entities.GameClient;
                attackerclient.LoseAttackDura(damage);

                #region ATTACKED : GAMECLIENT
                if (attacked is Entities.GameClient)
                {
                    Entities.GameClient attackedclient = attacked as Entities.GameClient;
                    // tournament check, damage = 1 + return
                    if (attackerclient.Battle != null)
                    {
                        if (!attackerclient.Battle.HandleAttack(attackerclient, attackedclient, ref damage))
                        {
                            damage = 0;
                            return;
                        }
                    }
                    else
                    {
                        if (attacked.Map.GotKillCons() && !attackedclient.ContainsFlag1(Enums.Effect1.BlueName) && !attackedclient.ContainsFlag1(Enums.Effect1.RedName) && !attackedclient.ContainsFlag1(Enums.Effect1.BlackName))
                        {
                            attackerclient.AddStatusEffect1(Enums.Effect1.BlueName, 20000);
                        }

                        attackedclient.LoseDefenseDura(damage);
                    }
                }
                #endregion
                #region ATTACKED : MONSTER
                if (attacked is Entities.Monster)
                {
                    Entities.Monster attackedmob = attacked as Entities.Monster;

                    if (((byte)attackedmob.Behaviour) >= 3)
                    {
                        attackerclient.AddStatusEffect1(Enums.Effect1.BlueName, 20000);
                    }
                    if (damage > 0)
                    {
                        ulong exp = (ulong)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)(damage / 2), (int)damage);
                        if (attacked.Level > (attacker.Level + 10))
                        {
                            exp *= 2;
                        }
                        else if (attacker.Level > (attacked.Level + 10))
                        {
                            exp = (ulong)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(1, (int)attackedmob.Level);
                        }
                        attackerclient.AddExp(exp);
                    }
                }
                #endregion
                //if (Calculations.Battle.LoseDuraAttak())
                //attackerclient.LoseAttackDura(damage);
            }
            #endregion
            #region ATTACKER : MONSTER

            #region ATTACKED : GAMECLIENT
            if (attacked is Entities.GameClient)
            {
                Entities.GameClient attackedclient = attacked as Entities.GameClient;

                attackedclient.LoseDefenseDura(damage);
            }
            #endregion

            #endregion

            if (kill_damage)
            {
                HitDamage(attacker, attacked, damage);
            }
        }
Example #14
0
        public static bool LoadMonsterSpawns()
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            string wrt = "\tLoading Monster Spawns...";

            Console.WriteLine(wrt);
            int SpawnCount      = 0;
            int GuardSpawnCount = 0;

            using (var spawn = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                using (var cmd = new SqlCommandBuilder(spawn, SqlCommandType.SELECT, false))
                {
                    cmd.Finish("DB_MobSpawns");
                }
                while (spawn.Read())
                {
                    ushort mapid = spawn.ReadUInt16("MapID");

                    Maps.Map map;
                    if (!Core.Kernel.Maps.TrySelect(mapid, out map))
                    {
                        return(false);
                    }

                    ushort CenterX = spawn.ReadUInt16("CenterX");
                    ushort CenterY = spawn.ReadUInt16("CenterY");
                    int    Range   = spawn.ReadUInt16("Range");
                    //	int DropData = spawn.ReadInt32("DropID");
                    int Monster  = spawn.ReadInt32("MonsterID");
                    int MobCount = spawn.ReadInt32("Count");

                    if (CenterX > 0 && CenterY > 0 && Range > 0 && Monster > 0 && MobCount > 0)
                    {
                        for (int j = 0; j < MobCount; j++)
                        {
                            Entities.Monster spawnmob = Core.Kernel.Monsters[Monster].Copy();
                            spawnmob.MobID     = Monster;
                            spawnmob.Direction = (byte)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(0, 8);
                            if (!map.EnterMap(spawnmob))
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("[MAP] Failed to load spawns. Failed at Map: {0} and MobID: {1}", mapid, Monster);
                                Console.ResetColor();
                                return(false);
                            }
                            Maps.MapPoint Location = spawnmob.Map.CreateAvailableLocation <Entities.Monster>(CenterX, CenterY, Range);
                            if (Location != null)
                            {
                                spawnmob.X             = Location.X;
                                spawnmob.Y             = Location.Y;
                                spawnmob.OriginalRange = Range;
                                spawnmob.OriginalX     = CenterX;
                                spawnmob.OriginalY     = CenterY;

                                spawnmob.DropData = Core.Kernel.DropData[map.MapID].Copy();

                                if (((byte)spawnmob.Behaviour) < 3 || spawnmob.Behaviour == Enums.MonsterBehaviour.PhysicalGuard)                                 // physical guards should walk around
                                {
                                                                        #if SPAWN_MOBS
                                    Threads.MonsterThread.AddToMonsterThread(spawnmob, false);
                                    SpawnCount++;
                                                                        #endif
                                }
                                else
                                {
                                    Threads.MonsterThread.AddToMonsterThread(spawnmob, true);
                                    GuardSpawnCount++;
                                }
                            }
                            else
                            {
                                spawnmob.Map.LeaveMap(spawnmob);                                 // there was no location available
                            }
                            Console.Clear();
                            Console.WriteLine(wrt);
                            Console.WriteLine("\tLoaded {0} Monster Spawns and {1} Guard Spawns...", SpawnCount, GuardSpawnCount);
                        }
                    }
                }
            }
            return(true);
        }
Example #15
0
        public static bool LoadMonsterInfo()
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("\tLoading Monsters...");

            using (var mob = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                using (var cmd = new SqlCommandBuilder(mob, SqlCommandType.SELECT, false))
                {
                    cmd.Finish("DB_MobInfo");
                }
                while (mob.Read())
                {
                    int mobid = mob.ReadInt32("MobID");
                    Entities.Monster monster = new Entities.Monster();
                    monster.Name        = mob.ReadString("Name");
                    monster.Level       = mob.ReadByte("MobLevel");
                    monster.Mesh        = mob.ReadUInt32("Lookface");
                    monster.MinAttack   = mob.ReadUInt32("MinAttack");
                    monster.MaxAttack   = mob.ReadUInt32("MaxAttack");
                    monster.Defense     = mob.ReadUInt32("Defense");
                    monster.Dexterity   = mob.ReadByte("Dexterity");
                    monster.Dodge       = mob.ReadByte("Dodge");
                    monster.AttackRange = mob.ReadInt32("AttackRange");
                    monster.ViewRange   = mob.ReadInt32("ViewRange");
                    monster.AttackSpeed = mob.ReadInt32("AttackSpeed");
                    monster.MoveSpeed   = mob.ReadInt32("MoveSpeed");
                    if (monster.MoveSpeed < 100)
                    {
                        monster.MoveSpeed = 100;
                    }
                    if (monster.MoveSpeed > 5000)
                    {
                        monster.MoveSpeed = 5000;
                    }
                    monster.AttackType      = mob.ReadInt32("AttackType");
                    monster.Behaviour       = (Enums.MonsterBehaviour)Enum.Parse(typeof(Enums.MonsterBehaviour), mob.ReadString("Behaviour"));
                    monster.MagicType       = mob.ReadInt32("MagicType");
                    monster.MagicDefense    = mob.ReadInt32("MagicDefense");
                    monster.MagicHitRate    = mob.ReadInt32("MagicHitRate");
                    monster.ExtraExperience = mob.ReadUInt64("ExtraExp");
                    monster.ExtraDamage     = mob.ReadUInt32("ExtraDamage");
                    monster.Boss            = (mob.ReadByte("Boss") != 0);
                    monster.Action          = mob.ReadUInt32("Action");
                    monster.MaxHP           = mob.ReadInt32("Life");

                    monster.HP    = monster.MaxHP;
                    monster.MaxMP = mob.ReadInt32("Mana");
                    monster.MP    = monster.MaxMP;

                    if (monster.Boss)
                    {
                        monster.AttackRange = 20;
                    }

                    string skillstring = mob.ReadString("Skills");
                    if (!string.IsNullOrWhiteSpace(skillstring))
                    {
                        int[] ids = new int[0];
                        skillstring.Split(',').ConverToInt32(out ids);
                        if (ids[0] != 0)
                        {
                            foreach (int skillid in ids)
                            {
                                monster.Skills.Add((ushort)skillid);
                            }
                        }
                    }

                    if (!Core.Kernel.Monsters.TryAdd(mobid, monster))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Failed to load monster. Failed at ID: {0}", mobid);
                        Console.ResetColor();
                        return(false);
                    }
                }
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\tLoaded {0} Monsters...", Core.Kernel.Monsters.Count);
            return(true);
        }
Example #16
0
        /// <summary>
        /// Gets the physical magic damage. (PVM)
        /// </summary>
        /// <param name="attacker">The attacker.</param>
        /// <param name="attacked">The attacked.</param>
        /// <param name="spell">The spell.</param>
        /// <returns>Returns the damage.</returns>
        private static double GetPhysicalMagicDamage_PVM(Entities.GameClient attacker, Entities.Monster attacked, Data.Spell spell)
        {
            double damage = (double)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(attacker.MinAttack, attacker.MaxAttack * 2);

            damage -= attacked.Defense;
            damage *= 0.65;
            // penetration extra damage
            if (spell.SpellID == 1290 && damage > 0)
            {
                double hunperc = (double)((damage / 100) * 26.6);
                damage += (hunperc * spell.Level);
            }
            //damage += spell.Power;
            damage *= 1 + attacker.DragonGemPercentage;
            //	damage -= attacked.Defense;
            //	double damage_perc = damage;
            //	damage_perc = (damage / 100) * attacked.TortoiseGemPercentage;
            //	damage -= damage_perc;
            //	damage_perc = (damage / 100) * attacked.Bless;
            //	damage -= damage_perc;

            return(damage);
        }
Example #17
0
        void Regular(Entities.Monster mob)
        {
            #region Poison
            if (mob.ContainsFlag1(Enums.Effect1.Poisoned))
            {
                if (DateTime.Now >= mob.LastPoison.AddMilliseconds(3000))
                {
                    mob.LastPoison = DateTime.Now;
                    if (mob.PoisonEffect > 0)
                    {
                        uint damage = (uint)((mob.HP / 100) * mob.PoisonEffect);
                        if (mob.HP > damage)
                        {
                            Packets.Interaction.Battle.Combat.HitDamage(null, mob, damage);
                            using (var interact = new Packets.InteractionPacket())
                            {
                                interact.Action    = Enums.InteractAction.Attack;
                                interact.EntityUID = mob.EntityUID;
                                interact.TargetUID = mob.EntityUID;
                                interact.UnPacked  = true;
                                interact.X         = mob.X;
                                interact.Y         = mob.Y;
                                interact.Data      = damage;
                                mob.Screen.UpdateScreen(interact, false);
                            }
                        }
                        else
                        {
                            mob.RemoveFlag1(Enums.Effect1.Poisoned);
                        }
                    }
                }
            }
            #endregion

            if (mob.Target != null)
            {
                if (mob.Target.Alive)
                {
                    if (mob.Screen.MapObjects.ContainsKey(mob.Target.EntityUID))
                    {
                        if (Core.Screen.GetDistance(mob.X, mob.Y, mob.Target.X, mob.Target.Y) <= mob.AttackRange &&
                            DateTime.Now >= mob.AttackTime)
                        {
                            mob.AttackTime = DateTime.Now.AddMilliseconds(
                                ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(
                                    mob.AttackSpeed, mob.AttackSpeed * 3));

                            #region physical attack
                            using (var interact = new Packets.InteractionPacket())
                            {
                                interact.Action    = Enums.InteractAction.Attack;
                                interact.EntityUID = mob.EntityUID;
                                interact.TargetUID = mob.Target.EntityUID;
                                interact.UnPacked  = true;
                                interact.X         = mob.Target.X;
                                interact.Y         = mob.Target.Y;
                                Packets.Interaction.Battle.Physical.Handle(mob, interact);
                            }
                            #endregion

                            return;
                        }
                    }
                }
            }

            mob.Target = null;
            foreach (Maps.IMapObject obj in mob.Screen.MapObjects.Values)
            {
                if (obj is Entities.GameClient)
                {
                    if ((obj as Entities.GameClient).ContainsFlag1(Enums.Effect1.PartiallyInvisible))
                    {
                        continue;
                    }
                    mob.Target = obj as Entities.IEntity;
                    if (!mob.Target.Alive)
                    {
                        mob.Target = null;
                        continue;
                    }
                    break;
                }
            }
        }
Example #18
0
        void Guards(Entities.Monster guard)
        {
            switch (guard.Behaviour)
            {
                #region Magic Guard
            case Enums.MonsterBehaviour.MagicGuard:
            {
                if (guard.Target != null)
                {
                    if (guard.Target.Alive)
                    {
                        if (guard.Screen.MapObjects.ContainsKey(guard.Target.EntityUID))
                        {
                            if (Core.Screen.GetDistance(guard.X, guard.Y, guard.Target.X, guard.Target.Y) <= guard.AttackRange)
                            {
                                #region magic attack
                                using (var interact = new Packets.InteractionPacket())
                                {
                                    interact.Action    = Enums.InteractAction.MagicAttack;
                                    interact.MagicType = 1002;
                                    interact.EntityUID = guard.EntityUID;
                                    interact.TargetUID = guard.Target.EntityUID;
                                    interact.UnPacked  = true;
                                    interact.X         = guard.Target.X;
                                    interact.Y         = guard.Target.Y;
                                    Packets.Interaction.Battle.Magic.Handle(guard, interact);
                                }
                                #endregion

                                return;
                            }
                        }
                    }
                }

                guard.Target = null;
                foreach (Maps.IMapObject obj in guard.Screen.MapObjects.Values)
                {
                    if (obj is Entities.GameClient || obj is Entities.Monster)
                    {
                        guard.Target = obj as Entities.IEntity;
                        if (guard.Target.EntityUID == guard.EntityUID)
                        {
                            guard.Target = null;
                            continue;
                        }
                        if (guard.Target is Entities.Monster)
                        {
                            if (((byte)(guard.Target as Entities.Monster).Behaviour) >= 3)
                            {
                                guard.Target = null;
                                continue;
                            }
                        }
                        if (guard.Target is Entities.GameClient)
                        {
                            if (!(guard.Target as Entities.GameClient).ContainsFlag1(Enums.Effect1.BlueName))
                            {
                                guard.Target = null;
                                continue;
                            }
                        }
                        if (!guard.Target.Alive)
                        {
                            guard.Target = null;
                            continue;
                        }
                        break;
                    }
                }
                break;
            }

                #endregion
                #region Physical Guard
            case Enums.MonsterBehaviour.PhysicalGuard:
            {
                break;
            }

                #endregion
                #region Death Guard
            case Enums.MonsterBehaviour.DeathGuard:
            {
                break;
            }

                #endregion
                #region Reviver Guard1
            case Enums.MonsterBehaviour.ReviverGuard1:
            {
                break;
            }

                #endregion
                #region Reviver Guard2
            case Enums.MonsterBehaviour.ReviverGuard2:
            {
                break;
            }
                #endregion
            }
        }
        public static bool LoadMonsterInfo()
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("\tLoading Monsters...");

            using (var mob = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                using (var cmd = new SqlCommandBuilder(mob, SqlCommandType.SELECT, false))
                {
                    cmd.Finish("DB_MobInfo");
                }
                while (mob.Read())
                {
                    int mobid = mob.ReadInt32("MobID");
                    Entities.Monster monster = new Entities.Monster();
                    monster.Name = mob.ReadString("Name");
                    monster.Level = mob.ReadByte("MobLevel");
                    monster.Mesh = mob.ReadUInt32("Lookface");
                    monster.MinAttack = mob.ReadUInt32("MinAttack");
                    monster.MaxAttack = mob.ReadUInt32("MaxAttack");
                    monster.Defense = mob.ReadUInt32("Defense");
                    monster.Dexterity = mob.ReadByte("Dexterity");
                    monster.Dodge = mob.ReadByte("Dodge");
                    monster.AttackRange = mob.ReadInt32("AttackRange");
                    monster.ViewRange = mob.ReadInt32("ViewRange");
                    monster.AttackSpeed = mob.ReadInt32("AttackSpeed");
                    monster.MoveSpeed = mob.ReadInt32("MoveSpeed");
                    if (monster.MoveSpeed < 100)
                        monster.MoveSpeed = 100;
                    if (monster.MoveSpeed > 5000)
                        monster.MoveSpeed = 5000;
                    monster.AttackType = mob.ReadInt32("AttackType");
                    monster.Behaviour = (Enums.MonsterBehaviour)Enum.Parse(typeof(Enums.MonsterBehaviour), mob.ReadString("Behaviour"));
                    monster.MagicType = mob.ReadInt32("MagicType");
                    monster.MagicDefense = mob.ReadInt32("MagicDefense");
                    monster.MagicHitRate = mob.ReadInt32("MagicHitRate");
                    monster.ExtraExperience = mob.ReadUInt64("ExtraExp");
                    monster.ExtraDamage = mob.ReadUInt32("ExtraDamage");
                    monster.Boss = (mob.ReadByte("Boss") != 0);
                    monster.Action = mob.ReadUInt32("Action");
                    monster.MaxHP = mob.ReadInt32("Life");

                    monster.HP = monster.MaxHP;
                    monster.MaxMP = mob.ReadInt32("Mana");
                    monster.MP = monster.MaxMP;

                    if (monster.Boss)
                    {
                        monster.AttackRange = 20;
                    }

                    string skillstring = mob.ReadString("Skills");
                    if (!string.IsNullOrWhiteSpace(skillstring))
                    {
                        int[] ids = new int[0];
                        skillstring.Split(',').ConverToInt32(out ids);
                        if (ids[0] != 0)
                        {
                            foreach (int skillid in ids)
                                monster.Skills.Add((ushort)skillid);
                        }
                    }

                    if (!Core.Kernel.Monsters.TryAdd(mobid, monster))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Failed to load monster. Failed at ID: {0}", mobid);
                        Console.ResetColor();
                        return false;
                    }
                }
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\tLoaded {0} Monsters...", Core.Kernel.Monsters.Count);
            return true;
        }