Exemple #1
0
        /// <summary>
        /// Handling the Court action of the interaction packet.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="interact">The interaction packet.</param>
        public static void Handle(Entities.GameClient client, InteractionPacket interact)
        {
            //uint marryUID = interact.TargetUID;

            //Entities.GameClient marrytarget;
            Maps.IMapObject obj;
            if (client.Map.MapObjects.TryGetValue(interact.TargetUID, out obj))
            {
                Entities.GameClient targ = obj as Entities.GameClient;
                if (client.SpouseDatabaseUID > 0)
                {
                    using (var fmsg = Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.MARRIAGE_SELF_SPOUSE))
                        client.Send(fmsg);
                    return;
                }
                if (targ.SpouseDatabaseUID > 0)
                {
                    using (var fmsg = Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.MARRIAGE_TARGET_SPOUSE))
                        client.Send(fmsg);
                    return;
                }

                targ.Send(interact);
            }
        }
        public static bool HandleSelf(Entities.IEntity attacker, Entities.IEntity target, InteractionPacket interaction, UseSpellPacket usespell, Data.Spell spell, out uint damage)
        {
            damage = 0;
            if (target != null)
            {
                if (target is Entities.NPC)
                    return false;

                if (target.EntityUID != attacker.EntityUID)
                    return false;
            }
            if (attacker is Entities.GameClient)
            {
                Entities.GameClient client = (attacker as Entities.GameClient);
                if (!(DateTime.Now >= client.LastSmallLongSkill.AddMilliseconds(Core.TimeIntervals.SmallLongSkillInterval)) && client.AttackPacket == null)
                {
                    using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.REST))
                        client.Send(fmsg);
                    return false;
                }
                client.LastSmallLongSkill = DateTime.Now;
            }
            if (spell.ID == 1190 || spell.ID == 7016)
                attacker.HP += spell.Power;
            else
                attacker.MP += spell.Power;

            uint exp = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)spell.Power, (int)spell.Power * 2);
            if ((attacker is Entities.GameClient))
                (attacker as Entities.GameClient).AddSpellExp(spell.SpellID, exp);

            usespell.AddTarget(attacker.EntityUID, spell.Power);

            return true;
        }
Exemple #3
0
        /// <summary>
        /// Handling the Court action of the interaction packet.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="interact">The interaction packet.</param>
        public static void Handle(Entities.GameClient client, InteractionPacket interact)
        {
            //uint marryUID = interact.TargetUID;

            //Entities.GameClient marrytarget;
            Maps.IMapObject obj;
            if (client.Map.MapObjects.TryGetValue(interact.TargetUID, out obj))
            {
                Entities.GameClient targ = obj as Entities.GameClient;
                if (client.SpouseDatabaseUID > 0)
                {
                    using (var fmsg = Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.MARRIAGE_SELF_SPOUSE))
                        client.Send(fmsg);
                    return;
                }
                if (targ.SpouseDatabaseUID > 0)
                {
                    using (var fmsg = Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.MARRIAGE_TARGET_SPOUSE))
                        client.Send(fmsg);
                    return;
                }

                targ.Send(interact);
            }
        }
Exemple #4
0
        /// <summary>
        /// Handles the single attack skills.
        /// </summary>
        /// <param name="attacker">The attacker.</param>
        /// <param name="target">The target.</param>
        /// <param name="interaction">The interaction packet.</param>
        /// <param name="usespell">The usespell packet.</param>
        /// <param name="spell">The spell.</param>
        /// <param name="damage">The damage.</param>
        /// <returns>Returns true if the skill was used successfully.</returns>
        public static bool HandleMag(Entities.IEntity attacker, Entities.IEntity target, InteractionPacket interaction, UseSpellPacket usespell, Data.Spell spell, out uint damage)
        {
            damage = 0;
            if (attacker.EntityUID == target.EntityUID)
                return false;
            if (target is Entities.NPC)
                return false;

            if (target is Entities.BossMonster)
            {
                if (!(target as Entities.BossMonster).CanBeAttacked)
                    return false;
            }

            if (target is Entities.Monster)
            {
                if (((byte)(target as Entities.Monster).Behaviour) >= 3)
                    return false;
            }

            if (target is Entities.GameClient)
            {
                if (!(target as Entities.GameClient).LoggedIn)
                    return false;

                if (target.Map.MapType == Enums.MapType.NoPK && (attacker is Entities.GameClient))
                    return false;

                if (!(DateTime.Now >= (target as Entities.GameClient).LoginProtection.AddSeconds(10)))
                {
                    return false;
                }

                if (!(DateTime.Now >= (target as Entities.GameClient).ReviveProtection.AddSeconds(5)))
                {
                    return false;
                }

                if (!Combat.FixTarget(attacker, target))
                    return false;
            }

            damage = Calculations.Battle.GetMagicDamage(attacker, target, spell);
            Combat.ProcessDamage(attacker, target, ref damage, false);
            if (damage > 0)
            {
                if (!(target is Entities.GameClient))
                {
                    uint exp = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)(damage / 2), (int)damage);
                    if (target.Level > (attacker.Level + 10))
                        exp *= 2;
                    if ((attacker is Entities.GameClient))
                        (attacker as Entities.GameClient).AddSpellExp(spell.SpellID, exp);
                }
                usespell.AddTarget(target.EntityUID, damage);
            }
            return true;
        }
Exemple #5
0
        /// <summary>
        /// Handling the Marry action of the interaction packet.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="interact">The interaction packet.</param>
        public static void Handle(Entities.GameClient client, InteractionPacket interact)
        {
            //uint marryUID = interact.TargetUID;

            //Entities.GameClient marrytarget;
            Maps.IMapObject obj;
            if (client.Map.MapObjects.TryGetValue(interact.TargetUID, out obj))
            {
                Entities.GameClient spouse = obj as Entities.GameClient;
                if (client.SpouseDatabaseUID > 0)
                {
                    using (var fmsg = Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.MARRIAGE_SELF_SPOUSE))
                        client.Send(fmsg);
                    return;
                }
                if (spouse.SpouseDatabaseUID > 0)
                {
                    using (var fmsg = Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.MARRIAGE_TARGET_SPOUSE))
                        client.Send(fmsg);
                    return;
                }

                client.SpouseDatabaseUID = spouse.DatabaseUID;
                spouse.SpouseDatabaseUID = client.DatabaseUID;
                //client.CharDB.AddSpouse(client.DatabaseUID, client.SpouseDatabaseUID);
                //spouse.CharDB.AddSpouse(spouse.DatabaseUID, spouse.SpouseDatabaseUID);
                Database.CharacterDatabase.AddSpouse(client, spouse);

                using (var mate = new Packets.StringPacket(new StringPacker(spouse.Name)))
                {
                    mate.Data = client.EntityUID;
                    mate.Action = Enums.StringAction.Mate;
                    client.Send(mate);
                }
                using (var mate = new Packets.StringPacket(new StringPacker(client.Name)))
                {
                    mate.Data = spouse.EntityUID;
                    mate.Action = Enums.StringAction.Mate;
                    spouse.Send(mate);
                }
                using (var fireworks = new Packets.StringPacket(new StringPacker("firework-2love")))
                {
                    fireworks.Action = Enums.StringAction.MapEffect;
                    fireworks.PositionX = client.X;
                    fireworks.PositionY = client.Y;
                    client.SendToScreen(fireworks, true);
                    fireworks.PositionX = spouse.X;
                    fireworks.PositionY = spouse.Y;
                    spouse.SendToScreen(fireworks, true);
                }

                using (var msg =Packets.Message.MessageCore.CreateSystem("ALL",
                                                                         string.Format(Core.MessageConst.MARRIAGE_CONGRATZ, client.Name, spouse.Name)))
                {
                    Packets.Message.MessageCore.SendGlobalMessage(msg);
                }
            }
        }
Exemple #6
0
 /// <summary>
 /// Processing the client through ranged attacks.
 /// </summary>
 /// <param name="client">The attacker.</param>
 /// <param name="interact">The interact packet.</param>
 /// <returns>Returns true if the client was handled successfully.</returns>
 public static bool ProcessClient(Entities.GameClient client, InteractionPacket interact, bool MAGIC_PACKET = false, int REQUIRED_ARROWS = 1)
 {
     if (!client.Equipments.Contains(Enums.ItemLocation.WeaponR))
     {
         return(false);
     }
     if (!client.Equipments[Enums.ItemLocation.WeaponR].IsBow())
     {
         return(false);
     }
     if (!client.Equipments.Contains(Enums.ItemLocation.WeaponL))
     {
         return(false);
     }
     if (!client.Equipments[Enums.ItemLocation.WeaponL].IsArrow())
     {
         return(false);
     }
     if (client.Equipments[Enums.ItemLocation.WeaponL].CurrentDura < REQUIRED_ARROWS)
     {
         uint arrowtype = client.Equipments[Enums.ItemLocation.WeaponL].ItemID;
         if (client.Inventory.ContainsByID(arrowtype))
         {
             Data.ItemInfo arrow = client.Inventory.SearchForNonEmpty(arrowtype);
             if (arrow != null)
             {
                 if (!client.Equipments.Equip(arrow, Enums.ItemLocation.WeaponL, true))
                 {
                     using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.AUTO_RELOAD_ARROW_FAIL))
                         client.Send(fmsg);
                     return(false);
                 }
             }
             else
             {
                 return(false);
             }
         }
         else if (!client.Equipments.Unequip(Enums.ItemLocation.WeaponL))
         {
             using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.EMPTY_ARROWS))
                 client.Send(fmsg);
             return(false);
         }
         else
         {
             return(false);                    // no more arrows in inventory
         }
     }
     if (client.Battle != null)
     {
         if (!client.Battle.HandleBeginHit_Ranged(client))
         {
             return(false);
         }
     }
     return(true);
 }
Exemple #7
0
        /// <summary>
        /// Handling the Marry action of the interaction packet.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="interact">The interaction packet.</param>
        public static void Handle(Entities.GameClient client, InteractionPacket interact)
        {
            //uint marryUID = interact.TargetUID;

            //Entities.GameClient marrytarget;
            Maps.IMapObject obj;
            if (client.Map.MapObjects.TryGetValue(interact.TargetUID, out obj))
            {
                Entities.GameClient spouse = obj as Entities.GameClient;
                if (client.SpouseDatabaseUID > 0)
                {
                    using (var fmsg = Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.MARRIAGE_SELF_SPOUSE))
                        client.Send(fmsg);
                    return;
                }
                if (spouse.SpouseDatabaseUID > 0)
                {
                    using (var fmsg = Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.MARRIAGE_TARGET_SPOUSE))
                        client.Send(fmsg);
                    return;
                }

                client.SpouseDatabaseUID = spouse.DatabaseUID;
                spouse.SpouseDatabaseUID = client.DatabaseUID;
                //client.CharDB.AddSpouse(client.DatabaseUID, client.SpouseDatabaseUID);
                //spouse.CharDB.AddSpouse(spouse.DatabaseUID, spouse.SpouseDatabaseUID);
                Database.CharacterDatabase.AddSpouse(client, spouse);

                using (var mate = new Packets.StringPacket(new StringPacker(spouse.Name)))
                {
                    mate.Data   = client.EntityUID;
                    mate.Action = Enums.StringAction.Mate;
                    client.Send(mate);
                }
                using (var mate = new Packets.StringPacket(new StringPacker(client.Name)))
                {
                    mate.Data   = spouse.EntityUID;
                    mate.Action = Enums.StringAction.Mate;
                    spouse.Send(mate);
                }
                using (var fireworks = new Packets.StringPacket(new StringPacker("firework-2love")))
                {
                    fireworks.Action    = Enums.StringAction.MapEffect;
                    fireworks.PositionX = client.X;
                    fireworks.PositionY = client.Y;
                    client.SendToScreen(fireworks, true);
                    fireworks.PositionX = spouse.X;
                    fireworks.PositionY = spouse.Y;
                    spouse.SendToScreen(fireworks, true);
                }

                using (var msg = Packets.Message.MessageCore.CreateSystem("ALL",
                                                                          string.Format(Core.MessageConst.MARRIAGE_CONGRATZ, client.Name, spouse.Name)))
                {
                    Packets.Message.MessageCore.SendGlobalMessage(msg);
                }
            }
        }
        public static bool Handle(Entities.IEntity attacker, Entities.IEntity target, InteractionPacket interaction, UseSpellPacket usespell, Data.Spell spell, out uint damage)
        {
            damage = 0;
            if (!attacker.Alive)
                return false;
            if (target == null)
                return false;
            if (!target.Alive)
                return false;
            if (!(target is Entities.GameClient))
                return false;
            if (attacker is Entities.GameClient)
            {
                Entities.GameClient client = (attacker as Entities.GameClient);
                if (!(DateTime.Now >= client.LastSmallLongSkill.AddMilliseconds(Core.TimeIntervals.SmallLongSkillInterval)) && client.AttackPacket == null)
                {
                    using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.REST))
                        client.Send(fmsg);
                    return false;
                }
                client.LastSmallLongSkill = DateTime.Now;
            }

            Entities.GameClient TargetClient = (target as Entities.GameClient);
            if (!TargetClient.LoggedIn)
                return false;

            switch (spell.SpellID)
            {
                case 1075:
                    TargetClient.AddStatusEffect1(Enums.Effect1.PartiallyInvisible, spell.Duration * 1000);
                    break;
                case 1085:
                    TargetClient.AddStatusEffect1(Enums.Effect1.StarOfAccuracy, spell.Duration * 1000);
                    break;
                case 1090:
                    TargetClient.AddStatusEffect1(Enums.Effect1.Shield, spell.Duration * 1000);
                    break;
                case 1095:
                    TargetClient.AddStatusEffect1(Enums.Effect1.Stig, spell.Duration * 1000);
                    break;

                default:
                    return false;
            }
            byte level_target = (byte)(TargetClient.Level > 50 ? 50 : TargetClient.Level);
            uint exp = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)level_target, (int)level_target * 2);

            if ((attacker is Entities.GameClient))
                (attacker as Entities.GameClient).AddSpellExp(spell.SpellID, exp);

            usespell.AddTarget(TargetClient.EntityUID, damage);

            return true;
        }
        /// <summary>
        /// Handles the archerbane attack skills.
        /// </summary>
        /// <param name="attacker">The attacker.</param>
        /// <param name="target">The target.</param>
        /// <param name="interaction">The interaction packet.</param>
        /// <param name="usespell">The usespell packet.</param>
        /// <param name="spell">The spell.</param>
        /// <param name="damage">The damage.</param>
        /// <returns>Returns true if the skill was used successfully.</returns>
        public static bool HandleArcherBane(Entities.IEntity attacker, Entities.IEntity target, InteractionPacket interaction, UseSpellPacket usespell, Data.Spell spell, out uint damage)
        {
            damage = 0;
            if (attacker.EntityUID == target.EntityUID)
                return false;
            if (!(target is Entities.GameClient))
                return false;
            if (!(target as Entities.GameClient).ContainsFlag1(Enums.Effect1.Fly))
                return false;

            if (target is Entities.GameClient)
            {
                if (!(target as Entities.GameClient).LoggedIn)
                    return false;

                if (target.Map.MapType == Enums.MapType.NoPK && (attacker is Entities.GameClient))
                    return false;

                if (!(DateTime.Now >= (target as Entities.GameClient).LoginProtection.AddSeconds(10)))
                {
                    return false;
                }

                if (!(DateTime.Now >= (target as Entities.GameClient).ReviveProtection.AddSeconds(5)))
                {
                    return false;
                }

                if (!Combat.FixTarget(attacker, target))
                    return false;
            }

            (target as Entities.GameClient).RemoveFlag1(Enums.Effect1.Fly);

            //damage = Calculations.Battle.GetPhysicalMagicDamage(attacker, target, spell);
            damage = (uint)(target.HP / 10);
            Combat.ProcessDamage(attacker, target, ref damage, false);
            if (damage > 0)
            {
                if (!(target is Entities.GameClient))
                {
                    uint exp = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)(damage / 2), (int)damage);
                    if (target.Level > (attacker.Level + 10))
                        exp *= 2;
                    if ((attacker is Entities.GameClient))
                        (attacker as Entities.GameClient).AddSpellExp(spell.SpellID, exp);
                }
            }
                usespell.AddTarget(target.EntityUID, damage);
            return true;
        }
Exemple #10
0
        /// <summary>
        /// Processing the client through magic usage.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="interact">The interaction packet.</param>
        /// <param name="usespell">The usespell packet.</param>
        /// <param name="spell">The spell.</param>
        /// <returns>Returns true if the client was successfully handled.</returns>
        private static bool ProcessClient(Entities.GameClient client, InteractionPacket interact, UseSpellPacket usespell, out Data.Spell spell)
        {
            spell = null;
            ushort spellID = interact.MagicType;

            if (interact.MagicType >= 3090 && interact.MagicType <= 3306)
            {
                spellID = 3090;
            }

            if (spellID == 6012)
            {
                spell      = Core.Kernel.SpellInfos[6010][0];
                interact.X = client.X;
                interact.Y = client.Y;
            }
            else
            {
                byte choselevel = 0;
                if (spellID == interact.MagicType)
                {
                    choselevel = (byte)client.SpellData.GetSpell(spellID).Level;
                }
                if (Core.Kernel.SpellInfos[spellID] != null && !Core.Kernel.SpellInfos[spellID].ContainsKey(choselevel))
                {
                    choselevel = (byte)(Core.Kernel.SpellInfos[spellID].Count - 1);
                }
                spell = Core.Kernel.SpellInfos[spellID][choselevel];
            }
            if (spell == null)
            {
                return(false);
            }
            usespell.SpellID    = spell.SpellID;
            usespell.SpellLevel = spell.Level;

            if (client.Battle != null)
            {
                if (!client.Battle.HandleBeginHit_Magic(client, usespell))
                {
                    return(false);
                }
            }

            //if (!client.SpellData.ContainsSpell(interact.MagicType))
            //	return false;

            return(true);
        }
 public static bool Handle(Entities.IEntity attacker, Entities.IEntity target, InteractionPacket interaction, UseSpellPacket usespell, Data.Spell spell, out uint damage)
 {
     damage = 0;
     if (!attacker.Alive)
         return false;
     if (target == null)
         return false;
     if (target.Alive)
         return false;
     if (attacker.EntityUID == target.EntityUID)
         return false;
     if (!(target is Entities.GameClient))
         return false;
     Entities.GameClient TargetClient = (target as Entities.GameClient);
     TargetClient.ForceRevive();
     usespell.AddTarget(TargetClient.EntityUID, 0);
     return true;
 }
Exemple #12
0
        public static bool Handle(Entities.IEntity attacker, Entities.IEntity target, InteractionPacket interaction, UseSpellPacket usespell, Data.Spell spell, out uint damage)
        {
            damage = 0;
            if (!attacker.Alive)
                return false;

            if (!(attacker is Entities.GameClient))
                return false;

            if (!(attacker as Entities.GameClient).Equipments.Contains(Enums.ItemLocation.WeaponR))
                return false;

            if (!(attacker as Entities.GameClient).Equipments[Enums.ItemLocation.WeaponR].IsBow())
                return false;

            (attacker as Entities.GameClient).AddStatusEffect1(Enums.Effect1.Fly, 40000);

            return true;
        }
        public static InteractionPacket HandlePacket(Models.Entities.Player player, InteractionPacket packet, out uint subPacketId)
        {
            packet.Packetstamp = Drivers.Time.GetSystemTime();

            if (packet.Action == Enums.InteractionAction.MagicAttack ||
                packet.Action == Enums.InteractionAction.Attack ||
                packet.Action == Enums.InteractionAction.Shoot)
            {
                packet.Decrypt(player);

                Helpers.Packets.Interaction.Battle.Combat.Handle(player, packet);
                subPacketId = Security.Api.SubCallState.DontHandle;
            }
            else
            {
                subPacketId = (uint)packet.Action;
            }

            return(packet);
        }
Exemple #14
0
        /// <summary>
        /// Handling the combat of the interact packet.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="interact">The interact packet.</param>
        public static void Handle(Entities.GameClient client, InteractionPacket interact)
        {
            if (interact == null)
                return;

            if (!client.Alive)
                return;

            if (client.Paralyzed)
                return;

            if (!client.CanAttack)
                return;

            if (!(DateTime.Now >= client.LoginProtection.AddSeconds(10)))
            {
                using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.REST))
                    client.Send(fmsg);
                return;
            }
            if (!(DateTime.Now >= client.ReviveProtection.AddSeconds(5)))
            {
                using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.REST))
                    client.Send(fmsg);
                return;
            }

            if (!(DateTime.Now >= client.LastAttack.AddMilliseconds(Core.TimeIntervals.AttackInterval)) && client.AttackPacket == null)
            {
                using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.REST))
                    client.Send(fmsg);
                return;
            }

            if (client.Battle != null)
            {
                if (!client.Battle.HandleBeginAttack(client))
                {
                    using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.REST))
                        client.Send(fmsg);
                    return;
                }
            }
            client.LastAttack = DateTime.Now;
            //client.AutoAttacking = false;
            switch (interact.Action)
            {
                case Enums.InteractAction.MagicAttack:
                    {
                        #region TemporaryDecryption
                        if (!interact.UnPacked)
                        {
                            interact.UnPacked = true;

                            byte[] packet = interact.Copy();
                            ushort SkillId = Convert.ToUInt16(((long)packet[24] & 0xFF) | (((long)packet[25] & 0xFF) << 8));
                            SkillId ^= (ushort)0x915d;
                            SkillId ^= (ushort)client.EntityUID;
                            SkillId = (ushort)(SkillId << 0x3 | SkillId >> 0xd);
                            SkillId -= 0xeb42;

                            uint Target = ((uint)packet[12] & 0xFF) | (((uint)packet[13] & 0xFF) << 8) | (((uint)packet[14] & 0xFF) << 16) | (((uint)packet[15] & 0xFF) << 24);
                            Target = ((((Target & 0xffffe000) >> 13) | ((Target & 0x1fff) << 19)) ^ 0x5F2D2463 ^ client.EntityUID) - 0x746F4AE6;

                            ushort TargetX = 0;
                            ushort TargetY = 0;
                            long xx = (packet[16] & 0xFF) | ((packet[17] & 0xFF) << 8);
                            long yy = (packet[18] & 0xFF) | ((packet[19] & 0xFF) << 8);
                            xx = xx ^ (client.EntityUID & 0xffff) ^ 0x2ed6;
                            xx = ((xx << 1) | ((xx & 0x8000) >> 15)) & 0xffff;
                            xx |= 0xffff0000;
                            xx -= 0xffff22ee;
                            yy = yy ^ (client.EntityUID & 0xffff) ^ 0xb99b;
                            yy = ((yy << 5) | ((yy & 0xF800) >> 11)) & 0xffff;
                            yy |= 0xffff0000;
                            yy -= 0xffff8922;
                            TargetX = Convert.ToUInt16(xx);
                            TargetY = Convert.ToUInt16(yy);

                            interact.TargetUID = Target;
                            interact.MagicType = SkillId;
                            interact.X = TargetX;
                            interact.Y = TargetY;
                        }
                        #endregion

                        if (client.ContainsFlag1(Enums.Effect1.Riding) && interact.MagicType != 7001)
                        {
                            if (client.Stamina >= 100)
                            {
                                client.Stamina = 0;
                                client.RemoveFlag1(Enums.Effect1.Riding);
                            }
                            return;
                        }

                        Magic.Handle(client, interact);
                        break;
                    }
                case Enums.InteractAction.Attack:
                    if (client.ContainsFlag1(Enums.Effect1.Riding))
                    {
                        if (client.Stamina >= 100)
                        {
                            client.Stamina = 0;
                            client.RemoveFlag1(Enums.Effect1.Riding);
                        }
                        return;
                    }
                    Physical.Handle(client, interact);
                    break;
                case Enums.InteractAction.Shoot:
                    if (client.ContainsFlag1(Enums.Effect1.Riding))
                    {
                        if (client.Stamina >= 100)
                        {
                            client.Stamina = 0;
                            client.RemoveFlag1(Enums.Effect1.Riding);
                        }
                        return;
                    }
                    Ranged.Handle(client, interact);
                    break;
            }
        }
Exemple #15
0
        public static void Handle(Entities.IEntity attacker, InteractionPacket interact)
        {
            if (interact == null)
                return;
            ConcurrentBag<Entities.IEntity> targets = new ConcurrentBag<ProjectX_V3_Game.Entities.IEntity>();

            Maps.IMapObject attackermap = attacker as Maps.IMapObject;
            if (!Core.Screen.ValidDistance(attackermap.X, attackermap.Y, interact.X, interact.Y))
            {
                return;
            }
            //			if (!attackermap.Screen.ContainsEntity(interact.TargetUID))
            //			{
            //				return;
            //			}
            //			Maps.IMapObject target = null;
            //			if (!attackermap.Screen.GetEntity(interact.TargetUID, out target))
            //			{
            //				return;
            //			}
            //			Entities.IEntity targetentity = target as Entities.IEntity;
            //			if (!Core.Screen.ValidDistance(attackermap.X, attackermap.Y, target.X, target.Y))
            //			{
            //				return;
            //			}
            if (!attacker.Alive)
            {
                return;
            }

            Maps.IMapObject target = null;
            if (interact.TargetUID > 0)
            {
                if (!attackermap.Screen.GetEntity(interact.TargetUID, out target) && interact.TargetUID != attacker.EntityUID)
                {
                    return; // fail here
                }
            }
            if (target != null)
            {
                if (target is Entities.NPC)
                    return;
                if (target is Entities.GameClient)
                {
                    if (!(target as Entities.GameClient).LoggedIn)
                        return;

                    if (target.Map.MapType == Enums.MapType.NoPK && (attacker is Entities.GameClient))
                    {
                        if (interact.MagicType != 1045 && interact.MagicType != 1046)
                        {
                            return;
                        }
                    }
                    if (!(DateTime.Now >= (target as Entities.GameClient).LoginProtection.AddSeconds(10)))
                    {
                        return;
                    }

                    // check if revive skill here and above as well!
                    if (!(DateTime.Now >= (target as Entities.GameClient).ReviveProtection.AddSeconds(5)))
                    {
                        return;
                    }

                }

                Entities.IEntity targetentity = target as Entities.IEntity;
                if (!Core.Screen.ValidDistance(attackermap.X, attackermap.Y, target.X, target.Y))
                {
                    return;
                }

                if (!Combat.FixTarget(attacker, targetentity))
                    return;

                if (!targetentity.Alive && interact.MagicType != 1100 && interact.MagicType != 1050)
                {
                    return;
                }
            }

            UseSpellPacket usespell = new UseSpellPacket();
            usespell.EntityUID = attacker.EntityUID;
            usespell.SpellID = interact.MagicType;
            usespell.SpellX = interact.X;
            usespell.SpellY = interact.Y;
            usespell.SpellLevel = 0;

            Data.Spell spell = null;
            if (attacker is Entities.GameClient)
            {
                if (!(attacker as Entities.GameClient).IsAIBot)
                {
                    if (!ProcessClient((attacker as Entities.GameClient), interact, usespell, out spell))
                        return;
                }
                else
                {
                    usespell.SpellLevel = interact.MagicLevel;
                    spell = Core.Kernel.SpellInfos[usespell.SpellID][(byte)usespell.SpellLevel];
                }
            }
            else if (attacker is Entities.Monster)
            {
                if (Core.Kernel.SpellInfos.ContainsKey(interact.MagicType))
                {
                    byte maxlevel = (byte)Core.Kernel.SpellInfos[interact.MagicType].Keys.Count;
                    maxlevel--;
                    if (Core.Kernel.SpellInfos[interact.MagicType].ContainsKey(maxlevel))
                        spell = Core.Kernel.SpellInfos[interact.MagicType][maxlevel];
                }
            }
            // AI
            // Guards
            // Mobs with skills ??
            if (spell == null)
                return;

            if (interact.EntityUID != attacker.EntityUID && target != null)
            {
                usespell.SpellX = target.X;
                usespell.SpellY = target.Y;
            }

            if (spell.UseEP > 0)
            {
                if (attacker is Entities.GameClient)
                {
                    if (!(attacker as Entities.GameClient).IsAIBot)
                    {
                        if (spell.ID == 7001)
                        {
                            if (!(attacker as Entities.GameClient).ContainsFlag1(Enums.Effect1.Riding))
                            {
                                if ((attacker as Entities.GameClient).Stamina < spell.UseEP)
                                    return;
                            }
                        }
                        else
                            if ((attacker as Entities.GameClient).Stamina < spell.UseEP)
                                return;
                    }
                }
            }

            if (spell.UseMP > 0)
            {

                if (attacker is Entities.Monster)
                {
                    if (attacker.MP < spell.UseMP && ((byte)(attacker as Entities.Monster).Behaviour) < 3)
                        return;
                }
                else if (attacker.MP < spell.UseMP)
                    return;
            }

            bool success = false;
            uint damage = 0;
            if (attacker.Map == null)
                return;

            if (attacker.Map.MapType == Enums.MapType.Tournament)
            {
                if (interact.MagicType != 1045 && interact.MagicType != 1046)
                    return;
            }

            bool singleSkill = false;
            switch (interact.MagicType)
            {
                    #region Line Skills
                case 1045:
                case 1046:
                case 11005:
                case 11000:
                    success = Skills.LineSkills.Handle(attacker, targets, interact, usespell, spell, out damage);
                    break;
                    #endregion
                    #region SectorSkills

                    #region Physical
                case 1250:
                case 5050:
                case 5020:
                case 1300:
                    success = Skills.SectoreSkills.HandlePhy(attacker, targets, interact, usespell, spell, out damage);
                    break;
                    #endregion
                    #region Magic
                case 1165:
                case 7014:
                    success = Skills.SectoreSkills.HandleMag(attacker, targets, interact, usespell, spell, out damage);
                    break;
                    #endregion

                    #endregion
                    #region Single
                    #region Magic
                case 10310:
                case 1000:
                case 1001:
                case 1002:
                case 1150:
                case 1160:
                case 1180:
                    if (target == null)
                        return;

                    singleSkill = true;
                    success = Skills.Single.HandleMag(attacker, (target as Entities.IEntity), interact, usespell, spell, out damage);
                    break;
                    #endregion
                    #region Physical
                case 1290:
                case 5030:
                case 5040:
                case 7000:
                case 7010:
                case 7030:
                case 7040:
                    if (target == null)
                        return;

                    singleSkill = true;
                    success = Skills.Single.HandlePhys(attacker, (target as Entities.IEntity), interact, usespell, spell, out damage);
                    break;
                    #endregion
                    #endregion
                    #region Circle

                    #region Physical
                case 5010:
                case 7020:
                case 1115://herc
                    success = Skills.CircleSkills.HandlePhy(attacker, targets, interact, usespell, spell, out damage);
                    break;
                    #endregion
                    #region Magic
                case 1010://lightning tao
                case 1120://fc
                case 1125://volc
                case 3090://pervade
                case 5001://speed
                case 8030://arrows
                case 7013://flame shower
                case 30011://small ice circle
                case 30012://large ice circle
                case 10360:
                case 10361:
                case 10392:
                case 10308:
                    success = Skills.CircleSkills.HandleMag(attacker, targets, interact, usespell, spell, out damage);
                    break;
                    #endregion

                    #endregion
                    #region MountSkill
                case 7001:
                    singleSkill = true;
                    if (attacker is Entities.GameClient)
                    {
                        success = Skills.MountSkill.Handle((attacker as Entities.GameClient), usespell);
                    }
                    else
                        success = false;
                    break;
                    #endregion
                    #region Buff
                case 1075:
                case 1085:
                case 1090:
                case 1095:
                    if (target == null)
                        return;
                    singleSkill = true;
                    success = Skills.BuffSkills.Handle(attacker, (target as Entities.IEntity), interact, usespell, spell, out damage);
                    break;
                    #endregion
                    #region Revive
                case 1050:
                case 1100:
                    if (target == null)
                        return;
                    singleSkill = true;
                    success = Skills.ReviveSkills.Handle(attacker, (target as Entities.IEntity), interact, usespell, spell, out damage);
                    break;
                    #endregion
                    #region Fly
                case 8002:
                case 8003:
                    singleSkill = true;
                    success = Skills.FlySkill.Handle(attacker, (target as Entities.IEntity), interact, usespell, spell, out damage);
                    break;
                    #endregion
                    #region Scatter
                case 8001:
                    success = Skills.ScatterSkill.Handle(attacker, targets, interact, usespell, spell, out damage);
                    break;
                    #endregion
                    #region Cure

                    #region Self
                case 1190:
                case 1195:
                case 7016:
                    if (target == null)
                        return;
                    singleSkill = true;
                    success = Skills.CureSkills.HandleSelf(attacker, (target as Entities.IEntity), interact, usespell, spell, out damage);
                    break;
                    #endregion
                    #region Surroundings
                case 1005:
                case 1055:
                case 1170:
                case 1175:
                    if (target == null)
                        return;
                    singleSkill = true;
                    success = Skills.CureSkills.HandleSurrounding(attacker, (target as Entities.IEntity), interact, usespell, spell, out damage);
                    break;
                    #endregion

                    #endregion
                    #region Archer
                case 10313:
                case 8000:
                case 9991:
                case 7012:
                case 7015:
                case 7017:
                case 1320:
                    if (target == null)
                        return;

                    singleSkill = true;
                    success = Skills.ArcherSkills.Handle(attacker, (target as Entities.IEntity), interact, usespell, spell, out damage);
                    break;
                    #endregion
                    #region Ninja
                    #region Toxic Fog
                case 6001:
                    success = Skills.NinjaSkills.HandlePoison(attacker, targets, interact, usespell, spell, out damage);
                    break;
                    #endregion
                    #region TwoFold
                case 6000:
                    if (target == null)
                        return;

                    singleSkill = true;
                    success = Skills.NinjaSkills.HandleTwoFold(attacker, (target as Entities.IEntity), interact, usespell, spell, out damage);
                    break;
                    #endregion
                    #region PoisonStar
                case 6002:
                    if (target == null)
                        return;

                    singleSkill = true;
                    success = Skills.NinjaSkills.HandlePoisonStar(attacker, (target as Entities.IEntity), interact, usespell, spell, out damage);
                    break;
                    #endregion
                    #region ArcherBane
                case 6004:
                    if (target == null)
                        return;

                    singleSkill = true;
                    success = Skills.NinjaSkills.HandleArcherBane(attacker, (target as Entities.IEntity), interact, usespell, spell, out damage);
                    break;
                    #endregion
                    #endregion

                default:
                    if (attacker is Entities.GameClient)
                    {
                        Entities.GameClient client = (attacker as Entities.GameClient);
                        using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.INVALID_SKILL))
                            client.Send(fmsg);
                    }
                    return;
            }
            if (success)
            {
                if (spell.UseEP > 0)
                {
                    if (attacker is Entities.GameClient)
                    {
                        if ((attacker as Entities.GameClient).Stamina >= spell.UseEP)
                            (attacker as Entities.GameClient).Stamina -= spell.UseEP;
                    }
                }

                if (spell.UseMP > 0)
                {
                    if (attacker.MP >= spell.UseMP)
                        attacker.MP -= spell.UseMP;
                }

            //				if (spell.UseItemNum == 0) // fix
            //				{
            //					if (attacker is Entities.GameClient)
            //					{
            //						Entities.GameClient client = attacker as Entities.GameClient;
            //						if (!client.Equipments.Contains(Enums.ItemLocation.WeaponL))
            //							return;
            //						if (!client.Equipments[Enums.ItemLocation.WeaponL].IsArrow())
            //							return;
            //						if (client.Equipments[Enums.ItemLocation.WeaponL].CurrentDura == 0)
            //						{
            //							uint arrowtype = client.Equipments[Enums.ItemLocation.WeaponL].ItemID;
            //							if (client.Inventory.ContainsByID(arrowtype))
            //							{
            //								Data.ItemInfo arrow = client.Inventory.SearchForNonEmpty(arrowtype);
            //								if (arrow != null)
            //								{
            //									if (!client.Equipments.Equip(arrow, Enums.ItemLocation.WeaponL, true))
            //									{
            //										using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.AUTO_RELOAD_ARROW_FAIL))
            //											client.Send(fmsg);
            //										return;
            //									}
            //								}
            //								else
            //									return;
            //							}
            //							else if (!client.Equipments.Unequip(Enums.ItemLocation.WeaponL))
            //							{
            //								using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.EMPTY_ARROWS))
            //									client.Send(fmsg);
            //								return;
            //							}
            //							else
            //								return; // no more arrows in inventory
            //						}
            //					}
            //				}
            //
                attacker.Screen.UpdateScreen(usespell);
                Entities.IEntity targetentity = target as Entities.IEntity;

                if (targetentity != null && singleSkill)
                {
                    if (targetentity.EntityUID != attacker.EntityUID)
                        Combat.HitDamage(attacker, targetentity, damage);
                    else if (targets.Count > 0)
                    {
                        foreach (Entities.IEntity targete in targets)
                            Combat.HitDamage(attacker, targete, damage);
                    }
                }
                else if (targets.Count > 0)
                {
                    foreach (Entities.IEntity targete in targets)
                        Combat.HitDamage(attacker, targete, damage);
                }

                if (attacker is Entities.GameClient)
                {
                    Entities.GameClient attackerclient = attacker as Entities.GameClient;
                    attackerclient.Send(usespell);

                    if (usespell.SpellID >= 1000 && usespell.SpellID <= 1002)
                    {
                        //interact.Data = 0;
                        interact.ActivationType = 0;
                        interact.ActivationValue = 0;
                        attackerclient.AttackPacket = interact;
                        attackerclient.UseAutoAttack(interact);
                    }
                }

            }
        }
Exemple #16
0
 /// <summary>
 /// Processing the client through ranged attacks.
 /// </summary>
 /// <param name="client">The attacker.</param>
 /// <param name="interact">The interact packet.</param>
 /// <returns>Returns true if the client was handled successfully.</returns>
 public static bool ProcessClient(Entities.GameClient client, InteractionPacket interact, bool MAGIC_PACKET = false, int REQUIRED_ARROWS = 1)
 {
     if (!client.Equipments.Contains(Enums.ItemLocation.WeaponR))
         return false;
     if (!client.Equipments[Enums.ItemLocation.WeaponR].IsBow())
         return false;
     if (!client.Equipments.Contains(Enums.ItemLocation.WeaponL))
         return false;
     if (!client.Equipments[Enums.ItemLocation.WeaponL].IsArrow())
         return false;
     if (client.Equipments[Enums.ItemLocation.WeaponL].CurrentDura < REQUIRED_ARROWS)
     {
         uint arrowtype = client.Equipments[Enums.ItemLocation.WeaponL].ItemID;
         if (client.Inventory.ContainsByID(arrowtype))
         {
             Data.ItemInfo arrow = client.Inventory.SearchForNonEmpty(arrowtype);
             if (arrow != null)
             {
                 if (!client.Equipments.Equip(arrow, Enums.ItemLocation.WeaponL, true))
                 {
                     using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.AUTO_RELOAD_ARROW_FAIL))
                         client.Send(fmsg);
                     return false;
                 }
             }
             else
                 return false;
         }
         else if (!client.Equipments.Unequip(Enums.ItemLocation.WeaponL))
         {
             using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.EMPTY_ARROWS))
                 client.Send(fmsg);
             return false;
         }
         else
             return false; // no more arrows in inventory
     }
     if (client.Battle != null)
     {
         if (!client.Battle.HandleBeginHit_Ranged(client))
             return false;
     }
     return true;
 }
Exemple #17
0
        public static void Handle(Entities.IEntity attacker, InteractionPacket interact)
        {
            if (interact == null)
            {
                return;
            }
            ConcurrentBag <Entities.IEntity> targets = new ConcurrentBag <ProjectX_V3_Game.Entities.IEntity>();

            Maps.IMapObject attackermap = attacker as Maps.IMapObject;
            if (!Core.Screen.ValidDistance(attackermap.X, attackermap.Y, interact.X, interact.Y))
            {
                return;
            }
//			if (!attackermap.Screen.ContainsEntity(interact.TargetUID))
//			{
//				return;
//			}
//			Maps.IMapObject target = null;
//			if (!attackermap.Screen.GetEntity(interact.TargetUID, out target))
//			{
//				return;
//			}
//			Entities.IEntity targetentity = target as Entities.IEntity;
//			if (!Core.Screen.ValidDistance(attackermap.X, attackermap.Y, target.X, target.Y))
//			{
//				return;
//			}
            if (!attacker.Alive)
            {
                return;
            }

            Maps.IMapObject target = null;
            if (interact.TargetUID > 0)
            {
                if (!attackermap.Screen.GetEntity(interact.TargetUID, out target) && interact.TargetUID != attacker.EntityUID)
                {
                    return;                     // fail here
                }
            }
            if (target != null)
            {
                if (target is Entities.NPC)
                {
                    return;
                }
                if (target is Entities.GameClient)
                {
                    if (!(target as Entities.GameClient).LoggedIn)
                    {
                        return;
                    }

                    if (target.Map.MapType == Enums.MapType.NoPK && (attacker is Entities.GameClient))
                    {
                        if (interact.MagicType != 1045 && interact.MagicType != 1046)
                        {
                            return;
                        }
                    }
                    if (!(DateTime.Now >= (target as Entities.GameClient).LoginProtection.AddSeconds(10)))
                    {
                        return;
                    }

                    // check if revive skill here and above as well!
                    if (!(DateTime.Now >= (target as Entities.GameClient).ReviveProtection.AddSeconds(5)))
                    {
                        return;
                    }
                }

                Entities.IEntity targetentity = target as Entities.IEntity;
                if (!Core.Screen.ValidDistance(attackermap.X, attackermap.Y, target.X, target.Y))
                {
                    return;
                }


                if (!Combat.FixTarget(attacker, targetentity))
                {
                    return;
                }

                if (!targetentity.Alive && interact.MagicType != 1100 && interact.MagicType != 1050)
                {
                    return;
                }
            }

            UseSpellPacket usespell = new UseSpellPacket();

            usespell.EntityUID  = attacker.EntityUID;
            usespell.SpellID    = interact.MagicType;
            usespell.SpellX     = interact.X;
            usespell.SpellY     = interact.Y;
            usespell.SpellLevel = 0;

            Data.Spell spell = null;
            if (attacker is Entities.GameClient)
            {
                if (!(attacker as Entities.GameClient).IsAIBot)
                {
                    if (!ProcessClient((attacker as Entities.GameClient), interact, usespell, out spell))
                    {
                        return;
                    }
                }
                else
                {
                    usespell.SpellLevel = interact.MagicLevel;
                    spell = Core.Kernel.SpellInfos[usespell.SpellID][(byte)usespell.SpellLevel];
                }
            }
            else if (attacker is Entities.Monster)
            {
                if (Core.Kernel.SpellInfos.ContainsKey(interact.MagicType))
                {
                    byte maxlevel = (byte)Core.Kernel.SpellInfos[interact.MagicType].Keys.Count;
                    maxlevel--;
                    if (Core.Kernel.SpellInfos[interact.MagicType].ContainsKey(maxlevel))
                    {
                        spell = Core.Kernel.SpellInfos[interact.MagicType][maxlevel];
                    }
                }
            }
            // AI
            // Guards
            // Mobs with skills ??
            if (spell == null)
            {
                return;
            }

            if (interact.EntityUID != attacker.EntityUID && target != null)
            {
                usespell.SpellX = target.X;
                usespell.SpellY = target.Y;
            }

            if (spell.UseEP > 0)
            {
                if (attacker is Entities.GameClient)
                {
                    if (!(attacker as Entities.GameClient).IsAIBot)
                    {
                        if (spell.ID == 7001)
                        {
                            if (!(attacker as Entities.GameClient).ContainsFlag1(Enums.Effect1.Riding))
                            {
                                if ((attacker as Entities.GameClient).Stamina < spell.UseEP)
                                {
                                    return;
                                }
                            }
                        }
                        else
                        if ((attacker as Entities.GameClient).Stamina < spell.UseEP)
                        {
                            return;
                        }
                    }
                }
            }

            if (spell.UseMP > 0)
            {
                if (attacker is Entities.Monster)
                {
                    if (attacker.MP < spell.UseMP && ((byte)(attacker as Entities.Monster).Behaviour) < 3)
                    {
                        return;
                    }
                }
                else if (attacker.MP < spell.UseMP)
                {
                    return;
                }
            }

            bool success = false;
            uint damage  = 0;

            if (attacker.Map == null)
            {
                return;
            }

            if (attacker.Map.MapType == Enums.MapType.Tournament)
            {
                if (interact.MagicType != 1045 && interact.MagicType != 1046)
                {
                    return;
                }
            }

            bool singleSkill = false;

            switch (interact.MagicType)
            {
                #region Line Skills
            case 1045:
            case 1046:
            case 11005:
            case 11000:
                success = Skills.LineSkills.Handle(attacker, targets, interact, usespell, spell, out damage);
                break;
                #endregion
                #region SectorSkills

                #region Physical
            case 1250:
            case 5050:
            case 5020:
            case 1300:
                success = Skills.SectoreSkills.HandlePhy(attacker, targets, interact, usespell, spell, out damage);
                break;

                #endregion
                #region Magic
            case 1165:
            case 7014:
                success = Skills.SectoreSkills.HandleMag(attacker, targets, interact, usespell, spell, out damage);
                break;
                #endregion

                #endregion
                #region Single
                #region Magic
            case 10310:
            case 1000:
            case 1001:
            case 1002:
            case 1150:
            case 1160:
            case 1180:
                if (target == null)
                {
                    return;
                }

                singleSkill = true;
                success     = Skills.Single.HandleMag(attacker, (target as Entities.IEntity), interact, usespell, spell, out damage);
                break;

                #endregion
                #region Physical
            case 1290:
            case 5030:
            case 5040:
            case 7000:
            case 7010:
            case 7030:
            case 7040:
                if (target == null)
                {
                    return;
                }

                singleSkill = true;
                success     = Skills.Single.HandlePhys(attacker, (target as Entities.IEntity), interact, usespell, spell, out damage);
                break;
                #endregion
                #endregion
                #region Circle

                #region Physical
            case 5010:
            case 7020:
            case 1115:                    //herc
                success = Skills.CircleSkills.HandlePhy(attacker, targets, interact, usespell, spell, out damage);
                break;

                #endregion
                #region Magic
            case 1010:                    //lightning tao
            case 1120:                    //fc
            case 1125:                    //volc
            case 3090:                    //pervade
            case 5001:                    //speed
            case 8030:                    //arrows
            case 7013:                    //flame shower
            case 30011:                   //small ice circle
            case 30012:                   //large ice circle
            case 10360:
            case 10361:
            case 10392:
            case 10308:
                success = Skills.CircleSkills.HandleMag(attacker, targets, interact, usespell, spell, out damage);
                break;
                #endregion

                #endregion
                #region MountSkill
            case 7001:
                singleSkill = true;
                if (attacker is Entities.GameClient)
                {
                    success = Skills.MountSkill.Handle((attacker as Entities.GameClient), usespell);
                }
                else
                {
                    success = false;
                }
                break;

                #endregion
                #region Buff
            case 1075:
            case 1085:
            case 1090:
            case 1095:
                if (target == null)
                {
                    return;
                }
                singleSkill = true;
                success     = Skills.BuffSkills.Handle(attacker, (target as Entities.IEntity), interact, usespell, spell, out damage);
                break;

                #endregion
                #region Revive
            case 1050:
            case 1100:
                if (target == null)
                {
                    return;
                }
                singleSkill = true;
                success     = Skills.ReviveSkills.Handle(attacker, (target as Entities.IEntity), interact, usespell, spell, out damage);
                break;

                #endregion
                #region Fly
            case 8002:
            case 8003:
                singleSkill = true;
                success     = Skills.FlySkill.Handle(attacker, (target as Entities.IEntity), interact, usespell, spell, out damage);
                break;

                #endregion
                #region Scatter
            case 8001:
                success = Skills.ScatterSkill.Handle(attacker, targets, interact, usespell, spell, out damage);
                break;
                #endregion
                #region Cure

                #region Self
            case 1190:
            case 1195:
            case 7016:
                if (target == null)
                {
                    return;
                }
                singleSkill = true;
                success     = Skills.CureSkills.HandleSelf(attacker, (target as Entities.IEntity), interact, usespell, spell, out damage);
                break;

                #endregion
                #region Surroundings
            case 1005:
            case 1055:
            case 1170:
            case 1175:
                if (target == null)
                {
                    return;
                }
                singleSkill = true;
                success     = Skills.CureSkills.HandleSurrounding(attacker, (target as Entities.IEntity), interact, usespell, spell, out damage);
                break;
                #endregion

                #endregion
                #region Archer
            case 10313:
            case 8000:
            case 9991:
            case 7012:
            case 7015:
            case 7017:
            case 1320:
                if (target == null)
                {
                    return;
                }

                singleSkill = true;
                success     = Skills.ArcherSkills.Handle(attacker, (target as Entities.IEntity), interact, usespell, spell, out damage);
                break;

                #endregion
                #region Ninja
                #region Toxic Fog
            case 6001:
                success = Skills.NinjaSkills.HandlePoison(attacker, targets, interact, usespell, spell, out damage);
                break;

                #endregion
                #region TwoFold
            case 6000:
                if (target == null)
                {
                    return;
                }

                singleSkill = true;
                success     = Skills.NinjaSkills.HandleTwoFold(attacker, (target as Entities.IEntity), interact, usespell, spell, out damage);
                break;

                #endregion
                #region PoisonStar
            case 6002:
                if (target == null)
                {
                    return;
                }

                singleSkill = true;
                success     = Skills.NinjaSkills.HandlePoisonStar(attacker, (target as Entities.IEntity), interact, usespell, spell, out damage);
                break;

                #endregion
                #region ArcherBane
            case 6004:
                if (target == null)
                {
                    return;
                }

                singleSkill = true;
                success     = Skills.NinjaSkills.HandleArcherBane(attacker, (target as Entities.IEntity), interact, usespell, spell, out damage);
                break;
                #endregion
                #endregion

            default:
                if (attacker is Entities.GameClient)
                {
                    Entities.GameClient client = (attacker as Entities.GameClient);
                    using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.INVALID_SKILL))
                        client.Send(fmsg);
                }
                return;
            }
            if (success)
            {
                if (spell.UseEP > 0)
                {
                    if (attacker is Entities.GameClient)
                    {
                        if ((attacker as Entities.GameClient).Stamina >= spell.UseEP)
                        {
                            (attacker as Entities.GameClient).Stamina -= spell.UseEP;
                        }
                    }
                }

                if (spell.UseMP > 0)
                {
                    if (attacker.MP >= spell.UseMP)
                    {
                        attacker.MP -= spell.UseMP;
                    }
                }

//				if (spell.UseItemNum == 0) // fix
//				{
//					if (attacker is Entities.GameClient)
//					{
//						Entities.GameClient client = attacker as Entities.GameClient;
//						if (!client.Equipments.Contains(Enums.ItemLocation.WeaponL))
//							return;
//						if (!client.Equipments[Enums.ItemLocation.WeaponL].IsArrow())
//							return;
//						if (client.Equipments[Enums.ItemLocation.WeaponL].CurrentDura == 0)
//						{
//							uint arrowtype = client.Equipments[Enums.ItemLocation.WeaponL].ItemID;
//							if (client.Inventory.ContainsByID(arrowtype))
//							{
//								Data.ItemInfo arrow = client.Inventory.SearchForNonEmpty(arrowtype);
//								if (arrow != null)
//								{
//									if (!client.Equipments.Equip(arrow, Enums.ItemLocation.WeaponL, true))
//									{
//										using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.AUTO_RELOAD_ARROW_FAIL))
//											client.Send(fmsg);
//										return;
//									}
//								}
//								else
//									return;
//							}
//							else if (!client.Equipments.Unequip(Enums.ItemLocation.WeaponL))
//							{
//								using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.EMPTY_ARROWS))
//									client.Send(fmsg);
//								return;
//							}
//							else
//								return; // no more arrows in inventory
//						}
//					}
//				}
//
                attacker.Screen.UpdateScreen(usespell);
                Entities.IEntity targetentity = target as Entities.IEntity;

                if (targetentity != null && singleSkill)
                {
                    if (targetentity.EntityUID != attacker.EntityUID)
                    {
                        Combat.HitDamage(attacker, targetentity, damage);
                    }
                    else if (targets.Count > 0)
                    {
                        foreach (Entities.IEntity targete in targets)
                        {
                            Combat.HitDamage(attacker, targete, damage);
                        }
                    }
                }
                else if (targets.Count > 0)
                {
                    foreach (Entities.IEntity targete in targets)
                    {
                        Combat.HitDamage(attacker, targete, damage);
                    }
                }

                if (attacker is Entities.GameClient)
                {
                    Entities.GameClient attackerclient = attacker as Entities.GameClient;
                    attackerclient.Send(usespell);

                    if (usespell.SpellID >= 1000 && usespell.SpellID <= 1002)
                    {
                        //interact.Data = 0;
                        interact.ActivationType     = 0;
                        interact.ActivationValue    = 0;
                        attackerclient.AttackPacket = interact;
                        attackerclient.UseAutoAttack(interact);
                    }
                }
            }
        }
        /// <summary>
        /// Handles the archerbane attack skills.
        /// </summary>
        /// <param name="attacker">The attacker.</param>
        /// <param name="target">The target.</param>
        /// <param name="interaction">The interaction packet.</param>
        /// <param name="usespell">The usespell packet.</param>
        /// <param name="spell">The spell.</param>
        /// <param name="damage">The damage.</param>
        /// <returns>Returns true if the skill was used successfully.</returns>
        public static bool HandleArcherBane(Entities.IEntity attacker, Entities.IEntity target, InteractionPacket interaction, UseSpellPacket usespell, Data.Spell spell, out uint damage)
        {
            damage = 0;
            if (attacker.EntityUID == target.EntityUID)
            {
                return(false);
            }
            if (!(target is Entities.GameClient))
            {
                return(false);
            }
            if (!(target as Entities.GameClient).ContainsFlag1(Enums.Effect1.Fly))
            {
                return(false);
            }

            if (target is Entities.GameClient)
            {
                if (!(target as Entities.GameClient).LoggedIn)
                {
                    return(false);
                }

                if (target.Map.MapType == Enums.MapType.NoPK && (attacker is Entities.GameClient))
                {
                    return(false);
                }

                if (!(DateTime.Now >= (target as Entities.GameClient).LoginProtection.AddSeconds(10)))
                {
                    return(false);
                }

                if (!(DateTime.Now >= (target as Entities.GameClient).ReviveProtection.AddSeconds(5)))
                {
                    return(false);
                }

                if (!Combat.FixTarget(attacker, target))
                {
                    return(false);
                }
            }

            (target as Entities.GameClient).RemoveFlag1(Enums.Effect1.Fly);

            //damage = Calculations.Battle.GetPhysicalMagicDamage(attacker, target, spell);
            damage = (uint)(target.HP / 10);
            Combat.ProcessDamage(attacker, target, ref damage, false);
            if (damage > 0)
            {
                if (!(target is Entities.GameClient))
                {
                    uint exp = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)(damage / 2), (int)damage);
                    if (target.Level > (attacker.Level + 10))
                    {
                        exp *= 2;
                    }
                    if ((attacker is Entities.GameClient))
                    {
                        (attacker as Entities.GameClient).AddSpellExp(spell.SpellID, exp);
                    }
                }
            }
            usespell.AddTarget(target.EntityUID, damage);
            return(true);
        }
        /// <summary>
        /// Handles the poisonstar attack skills.
        /// </summary>
        /// <param name="attacker">The attacker.</param>
        /// <param name="target">The target.</param>
        /// <param name="interaction">The interaction packet.</param>
        /// <param name="usespell">The usespell packet.</param>
        /// <param name="spell">The spell.</param>
        /// <param name="damage">The damage.</param>
        /// <returns>Returns true if the skill was used successfully.</returns>
        public static bool HandlePoisonStar(Entities.IEntity attacker, Entities.IEntity target, InteractionPacket interaction, UseSpellPacket usespell, Data.Spell spell, out uint damage)
        {
            damage = 0;
            if (attacker.EntityUID == target.EntityUID)
            {
                return(false);
            }
            if (!(target is Entities.GameClient))
            {
                return(false);
            }
            if ((target as Entities.GameClient).ContainsFlag1(Enums.Effect1.Fly))
            {
                return(false);
            }

            if (Core.Screen.GetDistance(target.X, target.Y, attacker.X, attacker.Y) > spell.Distance)
            {
                return(false);
            }

            if (attacker is Entities.GameClient)
            {
                Entities.GameClient client = (attacker as Entities.GameClient);
                if (!(DateTime.Now >= client.LastSmallLongSkill.AddMilliseconds(Core.TimeIntervals.SmallLongSkillInterval)) && client.AttackPacket == null)
                {
                    using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.REST))
                        client.Send(fmsg);
                    return(false);
                }
                client.LastSmallLongSkill = DateTime.Now;
            }

            if (target is Entities.GameClient)
            {
                if (!(target as Entities.GameClient).LoggedIn)
                {
                    return(false);
                }

                if (target.Map.MapType == Enums.MapType.NoPK && (attacker is Entities.GameClient))
                {
                    return(false);
                }

                if (!(DateTime.Now >= (target as Entities.GameClient).LoginProtection.AddSeconds(10)))
                {
                    return(false);
                }

                if (!(DateTime.Now >= (target as Entities.GameClient).ReviveProtection.AddSeconds(5)))
                {
                    return(false);
                }

                if (!Combat.FixTarget(attacker, target))
                {
                    return(false);
                }
            }

            (target as Entities.GameClient).AddStatusEffect1(Enums.Effect1.NoPotion, (5000 * (spell.Level + 1)));

            uint exp = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)target.Level, (int)target.Level * 2);

            if ((attacker is Entities.GameClient))
            {
                (attacker as Entities.GameClient).AddSpellExp(spell.SpellID, exp);
            }

            usespell.AddTarget(target.EntityUID, 0);

            return(true);
        }
        /// <summary>
        /// Handles the twofold attack skills.
        /// </summary>
        /// <param name="attacker">The attacker.</param>
        /// <param name="target">The target.</param>
        /// <param name="interaction">The interaction packet.</param>
        /// <param name="usespell">The usespell packet.</param>
        /// <param name="spell">The spell.</param>
        /// <param name="damage">The damage.</param>
        /// <returns>Returns true if the skill was used successfully.</returns>
        public static bool HandleTwoFold(Entities.IEntity attacker, Entities.IEntity target, InteractionPacket interaction, UseSpellPacket usespell, Data.Spell spell, out uint damage)
        {
            damage = 0;
            if (attacker.EntityUID == target.EntityUID)
            {
                return(false);
            }
            if (target is Entities.NPC)
            {
                return(false);
            }

            if (target is Entities.BossMonster)
            {
                if (!(target as Entities.BossMonster).CanBeAttacked)
                {
                    return(false);
                }
            }

            if (target is Entities.Monster)
            {
                if (((byte)(target as Entities.Monster).Behaviour) >= 3)
                {
                    return(false);
                }
            }

            if (Core.Screen.GetDistance(target.X, target.Y, attacker.X, attacker.Y) > spell.Distance)
            {
                return(false);
            }



            if (target is Entities.GameClient)
            {
                if (!(target as Entities.GameClient).LoggedIn)
                {
                    return(false);
                }
                if ((target as Entities.GameClient).ContainsFlag1(Enums.Effect1.Fly))
                {
                    return(false);
                }

                if (target.Map.MapType == Enums.MapType.NoPK && (attacker is Entities.GameClient))
                {
                    return(false);
                }

                if (!(DateTime.Now >= (target as Entities.GameClient).LoginProtection.AddSeconds(10)))
                {
                    return(false);
                }

                if (!(DateTime.Now >= (target as Entities.GameClient).ReviveProtection.AddSeconds(5)))
                {
                    return(false);
                }

                if (!Combat.FixTarget(attacker, target))
                {
                    return(false);
                }
            }

            damage = Calculations.Battle.GetPhysicalMagicDamage(attacker, target, spell);
            damage = (uint)((damage / 100) * (spell.Power - 30000));
            Combat.ProcessDamage(attacker, target, ref damage, false);
            if (damage > 0)
            {
                if (!(target is Entities.GameClient))
                {
                    uint exp = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)(damage / 2), (int)damage);
                    if (target.Level > (attacker.Level + 10))
                    {
                        exp *= 2;
                    }
                    if ((attacker is Entities.GameClient))
                    {
                        (attacker as Entities.GameClient).AddSpellExp(spell.SpellID, exp);
                    }
                }
                usespell.AddTarget(target.EntityUID, damage);
            }
            return(true);
        }
        public static bool HandleSelf(Entities.IEntity attacker, Entities.IEntity target, InteractionPacket interaction, UseSpellPacket usespell, Data.Spell spell, out uint damage)
        {
            damage = 0;
            if (target != null)
            {
                if (target is Entities.NPC)
                {
                    return(false);
                }

                if (target.EntityUID != attacker.EntityUID)
                {
                    return(false);
                }
            }
            if (attacker is Entities.GameClient)
            {
                Entities.GameClient client = (attacker as Entities.GameClient);
                if (!(DateTime.Now >= client.LastSmallLongSkill.AddMilliseconds(Core.TimeIntervals.SmallLongSkillInterval)) && client.AttackPacket == null)
                {
                    using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.REST))
                        client.Send(fmsg);
                    return(false);
                }
                client.LastSmallLongSkill = DateTime.Now;
            }
            if (spell.ID == 1190 || spell.ID == 7016)
            {
                attacker.HP += spell.Power;
            }
            else
            {
                attacker.MP += spell.Power;
            }

            uint exp = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)spell.Power, (int)spell.Power * 2);

            if ((attacker is Entities.GameClient))
            {
                (attacker as Entities.GameClient).AddSpellExp(spell.SpellID, exp);
            }

            usespell.AddTarget(attacker.EntityUID, spell.Power);

            return(true);
        }
Exemple #22
0
        public static bool Handle(Entities.IEntity attacker, Entities.IEntity target, InteractionPacket interaction, UseSpellPacket usespell, Data.Spell spell, out uint damage)
        {
            damage = 0;
            if (!attacker.Alive)
            {
                return(false);
            }

            if (!(attacker is Entities.GameClient))
            {
                return(false);
            }

            if (!(attacker as Entities.GameClient).Equipments.Contains(Enums.ItemLocation.WeaponR))
            {
                return(false);
            }

            if (!(attacker as Entities.GameClient).Equipments[Enums.ItemLocation.WeaponR].IsBow())
            {
                return(false);
            }

            (attacker as Entities.GameClient).AddStatusEffect1(Enums.Effect1.Fly, 40000);

            return(true);
        }
        /// <summary>
        /// Handles the circle skills.
        /// </summary>
        /// <param name="attacker">The attacker.</param>
        /// <param name="targets">The targets. [not set yet]</param>
        /// <param name="interaction">The interaction packet.</param>
        /// <param name="usespell">The usespell packet.</param>
        /// <param name="spell">The spell.</param>
        /// <param name="damage">The damage.</param>
        /// <returns>Returns true if the skill was used successfully.</returns>
        public static bool HandleMag(Entities.IEntity attacker, ConcurrentBag<Entities.IEntity> targets, InteractionPacket interaction, UseSpellPacket usespell, Data.Spell spell, out uint damage)
        {
            damage = 0;

            if (attacker is Entities.GameClient)
            {
                if (spell.SpellID == 8030 || spell.SpellID == 10308 || spell.SpellID == 7013 || spell.SpellID > 10360)
                {
                    if (!Ranged.ProcessClient(attacker as Entities.GameClient, interaction, true, 3))
                    {
                        return false;
                    }
                }
            }

            /*Calculations.InLineAlgorithm ila = new ProjectX_V3_Game.Calculations.InLineAlgorithm(
                attacker.X, interaction.X, attacker.Y, interaction.Y,
                (byte)spell.Range, Calculations.InLineAlgorithm.Algorithm.DDA);*/

            //	Calculations.Sector sector = new ProjectX_V3_Game.Calculations.Sector(attacker.X, attacker.Y, interaction.X, interaction.Y);
            //	sector.Arrange(spell.Sector, spell.Range);

            byte count = 0;
            bool bluename = false;
            foreach (Maps.IMapObject obj in attacker.Screen.MapObjects.Values)
            {
                if (count > 28)
                    return true;

                if(!(obj as Entities.IEntity).Alive)
                    continue;

                if (obj is Entities.NPC)
                    continue;

                if (obj.EntityUID == attacker.EntityUID)
                    continue;

                if (obj is Entities.BossMonster)
                {
                    if (!(obj as Entities.BossMonster).CanBeAttacked)
                        continue;
                }

                if (obj is Entities.Monster)
                {
                    if (((byte)(obj as Entities.Monster).Behaviour) >= 3)
                        continue;
                }

                if (!Core.Screen.ValidDistance(obj.X, obj.Y, attacker.X, attacker.Y))
                    continue;

                if (obj is Entities.GameClient)
                {
                    if (!(obj as Entities.GameClient).LoggedIn)
                        continue;

                    if (obj.Map.MapType == Enums.MapType.NoPK && (attacker is Entities.GameClient))
                        continue;

                    if (attacker is Entities.GameClient)
                    {
                        if ((attacker as Entities.GameClient).PKMode != Enums.PKMode.PK)
                            continue;

                        if (!Combat.FixTarget(attacker, obj as Entities.IEntity))
                            continue;
                    }
                    if ((obj as Entities.GameClient).ContainsFlag1(Enums.Effect1.Fly))
                        continue;

                    if (!(DateTime.Now >= (obj as Entities.GameClient).LoginProtection.AddSeconds(10)))
                    {
                        continue;
                    }

                    if (!(DateTime.Now >= (obj as Entities.GameClient).ReviveProtection.AddSeconds(5)))
                    {
                        continue;
                    }

                    if (!Combat.FixTarget(attacker, (obj as Entities.GameClient)))
                        continue;

                    if ((obj as Entities.GameClient).ContainsFlag1(Enums.Effect1.BlueName))
                        bluename = true;
                }

                //if (!ila.InLine(obj.X, obj.Y))
                //	continue;

                //if (!sector.Inside(obj.X, obj.Y))
                //	continue;

                Entities.IEntity targetentity = obj as Entities.IEntity;
                if (spell.SpellID == 8030 || spell.SpellID == 10308 || spell.SpellID == 7013 || spell.SpellID > 10360)
                    damage = Calculations.Battle.GetRangedDamage(attacker, targetentity);
                else
                    damage = Calculations.Battle.GetMagicDamage(attacker, targetentity, spell);
                Combat.ProcessDamage(attacker, targetentity, ref damage, false);
                if (damage > 0)
                {
                    if (!(targetentity is Entities.GameClient))
                    {
                        uint exp = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)(damage / 2), (int)damage);
                        if (targetentity.Level > (attacker.Level + 10))
                            exp *= 2;
                        else if (attacker.Level > (targetentity.Level + 10))
                            exp = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(1, (int)targetentity.Level);
                        if ((attacker is Entities.GameClient))
                            (attacker as Entities.GameClient).AddSpellExp(spell.SpellID, exp);
                    }
                    usespell.AddTarget(targetentity.EntityUID, damage);
                    targets.Add(targetentity);
                }
                count++;
            }
            if (spell.SpellID == 8030 || spell.SpellID == 10308 || spell.SpellID == 7013 || spell.SpellID > 10360)
            {
                if (attacker is Entities.GameClient)
                {
                    Ranged.DecreaseArrows(attacker as Entities.GameClient, 3);
                }
            }
            if (attacker is Entities.GameClient && bluename)
                (attacker as Entities.GameClient).AddStatusEffect1(Enums.Effect1.BlueName, 10000);
            return true;
        }
Exemple #24
0
        public static void Handle(Entities.IEntity attacker, InteractionPacket interact)
        {
            if (interact == null)
            {
                return;
            }

            Maps.IMapObject attackermap = attacker as Maps.IMapObject;
            if (!attackermap.Screen.ContainsEntity(interact.TargetUID))
            {
                return;
            }
            Maps.IMapObject target = null;
            if (!attackermap.Screen.GetEntity(interact.TargetUID, out target))
            {
                return;
            }
            if (target is Entities.NPC)
            {
                return;
            }
            if (target is Entities.GameClient)
            {
                if (!(target as Entities.GameClient).LoggedIn)
                {
                    return;
                }

                if ((target as Entities.GameClient).ContainsFlag1(Enums.Effect1.Fly))
                {
                    return;
                }

                if (target.Map.MapType == Enums.MapType.NoPK && (attacker is Entities.GameClient))
                {
                    return;
                }

                if (!(DateTime.Now >= (target as Entities.GameClient).LoginProtection.AddSeconds(10)))
                {
                    return;
                }


                if (!(DateTime.Now >= (target as Entities.GameClient).ReviveProtection.AddSeconds(5)))
                {
                    return;
                }
            }

            Entities.IEntity targetentity = target as Entities.IEntity;
            if (targetentity is Entities.BossMonster)
            {
                if (!(targetentity as Entities.BossMonster).CanBeAttacked)
                {
                    return;
                }
            }
            if (!Core.Screen.ValidDistance(attackermap.X, attackermap.Y, target.X, target.Y))
            {
                return;
            }
            if (!attacker.Alive)
            {
                return;
            }
            if (!targetentity.Alive)
            {
                return;
            }
            if (attacker is Entities.GameClient)
            {
                if (!ProcessClient((attacker as Entities.GameClient), interact))
                {
                    return;
                }
            }

            uint damage = Calculations.Battle.GetPhysicalDamage(attacker, targetentity);

            Combat.ProcessDamage(attacker, targetentity, ref damage);
            if (damage > 0)
            {
                if (attacker is Entities.GameClient && !(target is Entities.GameClient))
                {
                    Entities.GameClient client = attacker as Entities.GameClient;

                    uint exp = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)(damage / 2), (int)damage);
                    if (targetentity.Level > (attacker.Level + 10))
                    {
                        exp *= 2;
                    }
                    else if (attacker.Level > (targetentity.Level + 10))
                    {
                        exp = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(1, (int)targetentity.Level);
                    }

                    if (interact.WeaponTypeRight > 0)
                    {
                        client.AddProfExp(interact.WeaponTypeRight, exp);
                    }
                    if (interact.WeaponTypeLeft > 0)
                    {
                        client.AddProfExp(interact.WeaponTypeLeft, exp);
                    }
                }
            }
            interact.Data = damage;
            attacker.Screen.UpdateScreen(interact);
            if (attacker is Entities.GameClient)
            {
                (attacker as Entities.GameClient).Send(interact);
            }
        }
Exemple #25
0
        /// <summary>
        /// Processing the client through physical attacks.
        /// </summary>
        /// <param name="attacker">The attacker.</param>
        /// <param name="interact">The interact packet.</param>
        /// <returns>Returns true if the client was handled successfully.</returns>
        private static bool ProcessClient(Entities.GameClient attacker, InteractionPacket interact)
        {
            bool used = false;

            if (attacker.Equipments.Contains(Enums.ItemLocation.WeaponR))
            {
                ushort subtype = (ushort)(attacker.Equipments[Enums.ItemLocation.WeaponR].ItemID / 1000);
                interact.WeaponTypeRight = subtype;

                if (subtype == 421)
                {
                    subtype--;
                }
                if (Core.Kernel.WeaponSpells.ContainsKey(subtype))
                {
                    subtype = Core.Kernel.WeaponSpells[subtype];
                }
                if (attacker.SpellData.ContainsSpell(subtype) && attacker.Battle == null)
                {
                    // use weapon spell ex. phoenix
                    if (Core.Kernel.SpellInfos.ContainsKey(subtype))
                    {
                        Data.Spell spell = Core.Kernel.SpellInfos[subtype][(byte)attacker.SpellData.GetSpell(subtype).Level];
                        if (spell != null)
                        {
                            if (Calculations.BasicCalculations.ChanceSuccess(spell.Percentage))
                            {
                                interact.MagicType  = spell.SpellID;
                                interact.MagicLevel = spell.Level;
                                interact.Action     = Enums.InteractAction.MagicAttack;
                                Magic.Handle(attacker, interact);
                                used = false;
                                return(false);
                            }
                        }
                    }
                }
            }
            if (attacker.Equipments.Contains(Enums.ItemLocation.WeaponL) && !used)
            {
                ushort subtype = (ushort)(attacker.Equipments[Enums.ItemLocation.WeaponL].ItemID / 1000);
                interact.WeaponTypeLeft = subtype;
                if (subtype == 421)
                {
                    subtype--;
                }
                if (Core.Kernel.WeaponSpells.ContainsKey(subtype))
                {
                    subtype = Core.Kernel.WeaponSpells[subtype];
                }
                if (attacker.SpellData.ContainsSpell(subtype) && attacker.Battle == null)
                {
                    // use weapon spell ex. phoenix
                    if (Core.Kernel.SpellInfos.ContainsKey(subtype))
                    {
                        Data.Spell spell = Core.Kernel.SpellInfos[subtype][(byte)attacker.SpellData.GetSpell(subtype).Level];
                        if (spell != null)
                        {
                            if (Calculations.BasicCalculations.ChanceSuccess(spell.Percentage))
                            {
                                interact.MagicType  = spell.SpellID;
                                interact.MagicLevel = spell.Level;
                                interact.Action     = Enums.InteractAction.MagicAttack;
                                Magic.Handle(attacker, interact);
                                used = false;
                                return(false);
                            }
                        }
                    }
                }
            }

            if (attacker.Battle != null)
            {
                if (!attacker.Battle.HandleBeginHit_Physical(attacker))
                {
                    return(false);
                }
            }

            return(true);
        }
        /// <summary>
        /// Handles the sector skills.
        /// </summary>
        /// <param name="attacker">The attacker.</param>
        /// <param name="targets">The targets. [not set yet]</param>
        /// <param name="interaction">The interaction packet.</param>
        /// <param name="usespell">The usespell packet.</param>
        /// <param name="spell">The spell.</param>
        /// <param name="damage">The damage.</param>
        /// <returns>Returns true if the skill was used successfully.</returns>
        public static bool HandleMag(Entities.IEntity attacker, ConcurrentBag<Entities.IEntity> targets, InteractionPacket interaction, UseSpellPacket usespell, Data.Spell spell, out uint damage)
        {
            damage = 0;
            bool self = (interaction.TargetUID == attacker.EntityUID);
            if (self)
                return false;
            if (attacker is Entities.GameClient)
            {
                Entities.GameClient client = (attacker as Entities.GameClient);
                if (!(DateTime.Now >= client.LastLongSkill.AddMilliseconds(Core.TimeIntervals.LongSkillInterval)) && client.AttackPacket == null)
                {
                    using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.REST))
                        client.Send(fmsg);
                    return false;
                }
                client.LastLongSkill = DateTime.Now;
            }
            /*Calculations.InLineAlgorithm ila = new ProjectX_V3_Game.Calculations.InLineAlgorithm(
                attacker.X, interaction.X, attacker.Y, interaction.Y,
                (byte)spell.Range, Calculations.InLineAlgorithm.Algorithm.DDA);*/

            Calculations.Sector sector = new ProjectX_V3_Game.Calculations.Sector(attacker.X, attacker.Y, interaction.X, interaction.Y);
            sector.Arrange(spell.Sector, spell.Range);

            byte count = 0;
            bool bluename = false;
            foreach (Maps.IMapObject obj in attacker.Screen.MapObjects.Values)
            {
                if (count > 28)
                    return true;

                if(!(obj as Entities.IEntity).Alive)
                    continue;

                if (obj is Entities.NPC)
                    continue;

                if (obj.EntityUID == attacker.EntityUID)
                    continue;

                if (obj is Entities.BossMonster)
                {
                    if (!(obj as Entities.BossMonster).CanBeAttacked)
                        continue;
                }

                if (obj is Entities.Monster)
                {
                    if (((byte)(obj as Entities.Monster).Behaviour) >= 3)
                        continue;
                }

                if (obj is Entities.GameClient)
                {
                    if (!(obj as Entities.GameClient).LoggedIn)
                        continue;

                    if ((obj as Entities.GameClient).ContainsFlag1(Enums.Effect1.Fly))
                        continue;

                    if (obj.Map.MapType == Enums.MapType.NoPK && (attacker is Entities.GameClient))
                        continue;

                    if (attacker is Entities.GameClient)
                    {
                        if ((attacker as Entities.GameClient).PKMode != Enums.PKMode.PK)
                            continue;

                        if (!Combat.FixTarget(attacker, obj as Entities.IEntity))
                            continue;
                    }

                    if (!(DateTime.Now >= (obj as Entities.GameClient).LoginProtection.AddSeconds(10)))
                    {
                        continue;
                    }

                    if (!(DateTime.Now >= (obj as Entities.GameClient).ReviveProtection.AddSeconds(5)))
                    {
                        continue;
                    }

                    if (!Combat.FixTarget(attacker, (obj as Entities.GameClient)))
                        continue;

                    if ((obj as Entities.GameClient).ContainsFlag1(Enums.Effect1.BlueName))
                        bluename = true;
                }

                //if (!ila.InLine(obj.X, obj.Y))
                //	continue;

                if (!sector.Inside(obj.X, obj.Y))
                    continue;

                Entities.IEntity targetentity = obj as Entities.IEntity;
                damage = Calculations.Battle.GetMagicDamage(attacker, targetentity, spell);
                Combat.ProcessDamage(attacker, targetentity, ref damage, false);
                if (damage > 0)
                {
                    if (!(targetentity is Entities.GameClient))
                    {
                        uint exp = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)(damage / 2), (int)damage);
                        if (targetentity.Level > (attacker.Level + 10))
                            exp *= 2;
                        if ((attacker is Entities.GameClient))
                            (attacker as Entities.GameClient).AddSpellExp(spell.SpellID, exp);
                    }
                    usespell.AddTarget(targetentity.EntityUID, damage);
                    targets.Add(targetentity);
                }
                count++;
            }
            if (attacker is Entities.GameClient && bluename)
                (attacker as Entities.GameClient).AddStatusEffect1(Enums.Effect1.BlueName, 10000);
            return true;
        }
Exemple #27
0
        public static void Handle(Entities.IEntity attacker, InteractionPacket interact)
        {
            if (interact == null)
                return;

            Maps.IMapObject attackermap = attacker as Maps.IMapObject;
            if (!attackermap.Screen.ContainsEntity(interact.TargetUID))
            {
                return;
            }

            Maps.IMapObject target = null;
            if (!attackermap.Screen.GetEntity(interact.TargetUID, out target))
            {
                return;
            }
            if (target is Entities.NPC)
                return;

            if (target is Entities.GameClient)
            {
                if (!(target as Entities.GameClient).LoggedIn)
                    return;

                if (target.Map.MapType == Enums.MapType.NoPK && (attacker is Entities.GameClient))
                {
                    return;
                }
                if (!(DateTime.Now >= (target as Entities.GameClient).LoginProtection.AddSeconds(10)))
                {
                    return;
                }

                if (!(DateTime.Now >= (target as Entities.GameClient).ReviveProtection.AddSeconds(5)))
                {
                    return;
                }
            }

            Entities.IEntity targetentity = target as Entities.IEntity;
            if (targetentity is Entities.BossMonster)
            {
                if (!(targetentity as Entities.BossMonster).CanBeAttacked)
                    return;
            }
            if (!Combat.FixTarget(attacker, targetentity))
                return;

            if (!Core.Screen.ValidDistance(attackermap.X, attackermap.Y, target.X, target.Y))
            {
                return;
            }
            if (!attacker.Alive)
            {
                return;
            }
            if (!targetentity.Alive)
            {
                return;
            }
            if (attacker is Entities.GameClient)
            {
                if (!ProcessClient((attacker as Entities.GameClient), interact))
                    return;
            }

            uint damage = Calculations.Battle.GetRangedDamage(attacker, targetentity);
            Combat.ProcessDamage(attacker, targetentity, ref damage);
            interact.Data = damage;
            attacker.Screen.UpdateScreen(interact);
            if (attacker is Entities.GameClient)
            {
                Entities.GameClient attackerclient = attacker as Entities.GameClient;
                if (damage > 0)
                {
                    if (!(target is Entities.GameClient))
                    {
                        uint exp = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)(damage / 2), (int)damage);
                        if (targetentity.Level > (attacker.Level + 10))
                            exp *= 2;
                        else if (attacker.Level > (targetentity.Level + 10))
                            exp = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(1, (int)targetentity.Level);

                        if (interact.WeaponTypeRight > 0)
                            attackerclient.AddProfExp(500, exp); // bow
                    }
                }
                Data.ItemInfo arrow = attackerclient.Equipments[Enums.ItemLocation.WeaponL];
                arrow.CurrentDura--;
                Database.CharacterDatabase.SaveEquipment(attackerclient, arrow, Enums.ItemLocation.WeaponL);
                arrow.SendPacket(attackerclient, 3);

                attackerclient.Send(interact);

                //interact.Data = 0;
                interact.ActivationType = 0;
                interact.ActivationValue = 0;
                attackerclient.AttackPacket = interact;
                attackerclient.UseAutoAttack(interact);
            }
        }
Exemple #28
0
        /// <summary>
        /// Handles the single attack skills.
        /// </summary>
        /// <param name="attacker">The attacker.</param>
        /// <param name="target">The target.</param>
        /// <param name="interaction">The interaction packet.</param>
        /// <param name="usespell">The usespell packet.</param>
        /// <param name="spell">The spell.</param>
        /// <param name="damage">The damage.</param>
        /// <returns>Returns true if the skill was used successfully.</returns>
        public static bool Handle(Entities.IEntity attacker, Entities.IEntity target, InteractionPacket interaction, UseSpellPacket usespell, Data.Spell spell, out uint damage)
        {
            damage = 0;
            if (attacker is Entities.GameClient)
            {
                if (!Ranged.ProcessClient(attacker as Entities.GameClient, interaction, true))
                {
                    return(false);
                }
            }
            if (attacker.EntityUID == target.EntityUID)
            {
                return(false);
            }
            if (target is Entities.NPC)
            {
                return(false);
            }

            if (target is Entities.BossMonster)
            {
                if (!(target as Entities.BossMonster).CanBeAttacked)
                {
                    return(false);
                }
            }

            if (target is Entities.Monster)
            {
                if (((byte)(target as Entities.Monster).Behaviour) >= 3)
                {
                    return(false);
                }
            }

            if (target is Entities.GameClient)
            {
                if (!(target as Entities.GameClient).LoggedIn)
                {
                    return(false);
                }

                if (target.Map.MapType == Enums.MapType.NoPK && (attacker is Entities.GameClient))
                {
                    return(false);
                }

                if (!(DateTime.Now >= (target as Entities.GameClient).LoginProtection.AddSeconds(10)))
                {
                    return(false);
                }

                if (!(DateTime.Now >= (target as Entities.GameClient).ReviveProtection.AddSeconds(5)))
                {
                    return(false);
                }

                if (!Combat.FixTarget(attacker, target))
                {
                    return(false);
                }
            }

            if (attacker is Entities.GameClient)
            {
                Ranged.DecreaseArrows(attacker as Entities.GameClient, 1);
            }
            damage = Calculations.Battle.GetRangedDamage(attacker, target);
            damage = (uint)(damage * 1.5);
            Combat.ProcessDamage(attacker, target, ref damage, false);
            if (damage > 0)
            {
                if (!(target is Entities.GameClient))
                {
                    uint exp = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)(damage / 2), (int)damage);
                    if (target.Level > (attacker.Level + 10))
                    {
                        exp *= 2;
                    }
                    if ((attacker is Entities.GameClient))
                    {
                        (attacker as Entities.GameClient).AddSpellExp(spell.SpellID, exp);
                    }
                }
                usespell.AddTarget(target.EntityUID, damage);
            }
            return(true);
        }
Exemple #29
0
        /// <summary>
        /// Processing the client through magic usage.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="interact">The interaction packet.</param>
        /// <param name="usespell">The usespell packet.</param>
        /// <param name="spell">The spell.</param>
        /// <returns>Returns true if the client was successfully handled.</returns>
        private static bool ProcessClient(Entities.GameClient client, InteractionPacket interact, UseSpellPacket usespell, out Data.Spell spell)
        {
            spell = null;
            ushort spellID = interact.MagicType;
            if (interact.MagicType >= 3090 && interact.MagicType <= 3306)
                spellID = 3090;

            if (spellID == 6012)
            {
                spell = Core.Kernel.SpellInfos[6010][0];
                interact.X = client.X;
                interact.Y = client.Y;
            }
            else
            {
                byte choselevel = 0;
                if (spellID == interact.MagicType)
                    choselevel = (byte)client.SpellData.GetSpell(spellID).Level;
                if (Core.Kernel.SpellInfos[spellID] != null && !Core.Kernel.SpellInfos[spellID].ContainsKey(choselevel))
                    choselevel = (byte)(Core.Kernel.SpellInfos[spellID].Count - 1);
                spell = Core.Kernel.SpellInfos[spellID][choselevel];
            }
            if (spell == null)
            {
                return false;
            }
            usespell.SpellID = spell.SpellID;
            usespell.SpellLevel = spell.Level;

            if (client.Battle != null)
            {
                if (!client.Battle.HandleBeginHit_Magic(client, usespell))
                    return false;
            }

            //if (!client.SpellData.ContainsSpell(interact.MagicType))
            //	return false;

            return true;
        }
        /// <summary>
        /// Handles the poisonstar attack skills.
        /// </summary>
        /// <param name="attacker">The attacker.</param>
        /// <param name="target">The target.</param>
        /// <param name="interaction">The interaction packet.</param>
        /// <param name="usespell">The usespell packet.</param>
        /// <param name="spell">The spell.</param>
        /// <param name="damage">The damage.</param>
        /// <returns>Returns true if the skill was used successfully.</returns>
        public static bool HandlePoisonStar(Entities.IEntity attacker, Entities.IEntity target, InteractionPacket interaction, UseSpellPacket usespell, Data.Spell spell, out uint damage)
        {
            damage = 0;
            if (attacker.EntityUID == target.EntityUID)
                return false;
            if (!(target is Entities.GameClient))
                return false;
            if ((target as Entities.GameClient).ContainsFlag1(Enums.Effect1.Fly))
                return false;

            if (Core.Screen.GetDistance(target.X, target.Y, attacker.X, attacker.Y) > spell.Distance)
                return false;

            if (attacker is Entities.GameClient)
            {
                Entities.GameClient client = (attacker as Entities.GameClient);
                if (!(DateTime.Now >= client.LastSmallLongSkill.AddMilliseconds(Core.TimeIntervals.SmallLongSkillInterval)) && client.AttackPacket == null)
                {
                    using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.REST))
                        client.Send(fmsg);
                    return false;
                }
                client.LastSmallLongSkill = DateTime.Now;
            }

            if (target is Entities.GameClient)
            {
                if (!(target as Entities.GameClient).LoggedIn)
                    return false;

                if (target.Map.MapType == Enums.MapType.NoPK && (attacker is Entities.GameClient))
                    return false;

                if (!(DateTime.Now >= (target as Entities.GameClient).LoginProtection.AddSeconds(10)))
                {
                    return false;
                }

                if (!(DateTime.Now >= (target as Entities.GameClient).ReviveProtection.AddSeconds(5)))
                {
                    return false;
                }

                if (!Combat.FixTarget(attacker, target))
                    return false;
            }

            (target as Entities.GameClient).AddStatusEffect1(Enums.Effect1.NoPotion, (5000 * (spell.Level + 1)));

            uint exp = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)target.Level, (int)target.Level * 2);
            if ((attacker is Entities.GameClient))
                (attacker as Entities.GameClient).AddSpellExp(spell.SpellID, exp);

            usespell.AddTarget(target.EntityUID, 0);

            return true;
        }
Exemple #31
0
        /// <summary>
        /// Handles the sector skills.
        /// </summary>
        /// <param name="attacker">The attacker.</param>
        /// <param name="targets">The targets. [not set yet]</param>
        /// <param name="interaction">The interaction packet.</param>
        /// <param name="usespell">The usespell packet.</param>
        /// <param name="spell">The spell.</param>
        /// <param name="damage">The damage.</param>
        /// <returns>Returns true if the skill was used successfully.</returns>
        public static bool HandlePhy(Entities.IEntity attacker, ConcurrentBag <Entities.IEntity> targets, InteractionPacket interaction, UseSpellPacket usespell, Data.Spell spell, out uint damage)
        {
            damage = 0;
            bool self = (interaction.TargetUID == attacker.EntityUID);

            if (self)
            {
                return(false);
            }

            /*Calculations.InLineAlgorithm ila = new ProjectX_V3_Game.Calculations.InLineAlgorithm(
             *      attacker.X, interaction.X, attacker.Y, interaction.Y,
             *      (byte)spell.Range, Calculations.InLineAlgorithm.Algorithm.DDA);*/

            Calculations.Sector sector = new ProjectX_V3_Game.Calculations.Sector(attacker.X, attacker.Y, interaction.X, interaction.Y);
            sector.Arrange(spell.Sector, spell.Range);

            byte count    = 0;
            bool bluename = false;

            foreach (Maps.IMapObject obj in attacker.Screen.MapObjects.Values)
            {
                if (count > 28)
                {
                    return(true);
                }

                if (!(obj as Entities.IEntity).Alive)
                {
                    continue;
                }

                if (obj is Entities.NPC)
                {
                    continue;
                }

                if (obj.EntityUID == attacker.EntityUID)
                {
                    continue;
                }

                if (obj is Entities.BossMonster)
                {
                    if (!(obj as Entities.BossMonster).CanBeAttacked)
                    {
                        continue;
                    }
                }

                if (obj is Entities.Monster)
                {
                    if (((byte)(obj as Entities.Monster).Behaviour) >= 3)
                    {
                        continue;
                    }
                }

                if (obj is Entities.GameClient)
                {
                    if (!(obj as Entities.GameClient).LoggedIn)
                    {
                        continue;
                    }

                    if ((obj as Entities.GameClient).ContainsFlag1(Enums.Effect1.Fly))
                    {
                        continue;
                    }

                    if (obj.Map.MapType == Enums.MapType.NoPK && (attacker is Entities.GameClient))
                    {
                        continue;
                    }

                    if (attacker is Entities.GameClient)
                    {
                        if ((attacker as Entities.GameClient).PKMode != Enums.PKMode.PK)
                        {
                            continue;
                        }

                        if (!Combat.FixTarget(attacker, obj as Entities.IEntity))
                        {
                            continue;
                        }
                    }

                    if (!(DateTime.Now >= (obj as Entities.GameClient).LoginProtection.AddSeconds(10)))
                    {
                        continue;
                    }

                    if (!(DateTime.Now >= (obj as Entities.GameClient).ReviveProtection.AddSeconds(5)))
                    {
                        continue;
                    }

                    if (!Combat.FixTarget(attacker, (obj as Entities.GameClient)))
                    {
                        continue;
                    }


                    if ((obj as Entities.GameClient).ContainsFlag1(Enums.Effect1.BlueName))
                    {
                        bluename = true;
                    }
                }

                //if (!ila.InLine(obj.X, obj.Y))
                //	continue;

                if (!sector.Inside(obj.X, obj.Y))
                {
                    continue;
                }

                Entities.IEntity targetentity = obj as Entities.IEntity;
                damage = Calculations.Battle.GetPhysicalDamage(attacker, targetentity);
                Combat.ProcessDamage(attacker, targetentity, ref damage, false);
                if (damage > 0)
                {
                    if (!(targetentity is Entities.GameClient))
                    {
                        uint exp = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)(damage / 2), (int)damage);
                        if (targetentity.Level > (attacker.Level + 10))
                        {
                            exp *= 2;
                        }
                        if ((attacker is Entities.GameClient))
                        {
                            (attacker as Entities.GameClient).AddSpellExp(spell.SpellID, exp);
                        }
                    }
                    usespell.AddTarget(targetentity.EntityUID, damage);
                    targets.Add(targetentity);
                }
                count++;
            }
            if (attacker is Entities.GameClient && bluename)
            {
                (attacker as Entities.GameClient).AddStatusEffect1(Enums.Effect1.BlueName, 10000);
            }
            return(true);
        }
        public static bool HandleSurrounding(Entities.IEntity attacker, Entities.IEntity target, InteractionPacket interaction, UseSpellPacket usespell, Data.Spell spell, out uint damage)
        {
            damage = 0;
            if (target == null)
                return false;
            if (target is Entities.NPC)
                return false;
            if (target is Entities.Monster)
            {
                if (((byte)(target as Entities.Monster).Behaviour) >= 3)
                    return false;
            }
            if (target is Entities.GameClient)
            {
                if (!(target as Entities.GameClient).LoggedIn)
                    return false;
            }
            if (attacker is Entities.GameClient)
            {
                Entities.GameClient client = (attacker as Entities.GameClient);
                if (!(DateTime.Now >= client.LastSmallLongSkill.AddMilliseconds(Core.TimeIntervals.SmallLongSkillInterval)) && client.AttackPacket == null)
                {
                    using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.REST))
                        client.Send(fmsg);
                    return false;
                }
                client.LastSmallLongSkill = DateTime.Now;
            }

            target.HP += spell.Power;
            uint targetcount = 1;
            if (spell.SpellID == 1055)
            {
                foreach (Maps.IMapObject obj in target.Screen.MapObjects.Values)
                {
                    if (obj == null)
                        continue;
                    if (obj.EntityUID == attacker.EntityUID)
                        continue;
                    if (obj.EntityUID == target.EntityUID)
                        continue;
                    if (obj is Entities.NPC)
                        continue;
                    if (Core.Screen.GetDistance(obj.X, obj.Y, target.X, target.Y) > spell.Distance)
                        continue;
                    if (obj is Entities.Monster)
                    {
                        if (((byte)(obj as Entities.Monster).Behaviour) >= 3)
                            continue;
                    }
                    if (obj is Entities.GameClient)
                    {
                        if (!(obj as Entities.GameClient).LoggedIn)
                            continue;
                    }
                    (obj as Entities.IEntity).HP += spell.Power;
                    usespell.AddTarget(obj.EntityUID, spell.Power);
                    targetcount++;
                }
            }

            uint exp = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)spell.Power, (int)spell.Power * 2);
            exp *= targetcount;
            if ((attacker is Entities.GameClient))
                (attacker as Entities.GameClient).AddSpellExp(spell.SpellID, exp);

            usespell.AddTarget(target.EntityUID, spell.Power);

            return true;
        }
Exemple #33
0
        public static void Handle(Entities.IEntity attacker, InteractionPacket interact)
        {
            if (interact == null)
            {
                return;
            }

            Maps.IMapObject attackermap = attacker as Maps.IMapObject;
            if (!attackermap.Screen.ContainsEntity(interact.TargetUID))
            {
                return;
            }

            Maps.IMapObject target = null;
            if (!attackermap.Screen.GetEntity(interact.TargetUID, out target))
            {
                return;
            }
            if (target is Entities.NPC)
            {
                return;
            }

            if (target is Entities.GameClient)
            {
                if (!(target as Entities.GameClient).LoggedIn)
                {
                    return;
                }

                if (target.Map.MapType == Enums.MapType.NoPK && (attacker is Entities.GameClient))
                {
                    return;
                }
                if (!(DateTime.Now >= (target as Entities.GameClient).LoginProtection.AddSeconds(10)))
                {
                    return;
                }


                if (!(DateTime.Now >= (target as Entities.GameClient).ReviveProtection.AddSeconds(5)))
                {
                    return;
                }
            }


            Entities.IEntity targetentity = target as Entities.IEntity;
            if (targetentity is Entities.BossMonster)
            {
                if (!(targetentity as Entities.BossMonster).CanBeAttacked)
                {
                    return;
                }
            }
            if (!Combat.FixTarget(attacker, targetentity))
            {
                return;
            }

            if (!Core.Screen.ValidDistance(attackermap.X, attackermap.Y, target.X, target.Y))
            {
                return;
            }
            if (!attacker.Alive)
            {
                return;
            }
            if (!targetentity.Alive)
            {
                return;
            }
            if (attacker is Entities.GameClient)
            {
                if (!ProcessClient((attacker as Entities.GameClient), interact))
                {
                    return;
                }
            }

            uint damage = Calculations.Battle.GetRangedDamage(attacker, targetentity);

            Combat.ProcessDamage(attacker, targetentity, ref damage);
            interact.Data = damage;
            attacker.Screen.UpdateScreen(interact);
            if (attacker is Entities.GameClient)
            {
                Entities.GameClient attackerclient = attacker as Entities.GameClient;
                if (damage > 0)
                {
                    if (!(target is Entities.GameClient))
                    {
                        uint exp = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)(damage / 2), (int)damage);
                        if (targetentity.Level > (attacker.Level + 10))
                        {
                            exp *= 2;
                        }
                        else if (attacker.Level > (targetentity.Level + 10))
                        {
                            exp = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(1, (int)targetentity.Level);
                        }

                        if (interact.WeaponTypeRight > 0)
                        {
                            attackerclient.AddProfExp(500, exp);                             // bow
                        }
                    }
                }
                Data.ItemInfo arrow = attackerclient.Equipments[Enums.ItemLocation.WeaponL];
                arrow.CurrentDura--;
                Database.CharacterDatabase.SaveEquipment(attackerclient, arrow, Enums.ItemLocation.WeaponL);
                arrow.SendPacket(attackerclient, 3);

                attackerclient.Send(interact);

                //interact.Data = 0;
                interact.ActivationType     = 0;
                interact.ActivationValue    = 0;
                attackerclient.AttackPacket = interact;
                attackerclient.UseAutoAttack(interact);
            }
        }
        public static bool HandleSurrounding(Entities.IEntity attacker, Entities.IEntity target, InteractionPacket interaction, UseSpellPacket usespell, Data.Spell spell, out uint damage)
        {
            damage = 0;
            if (target == null)
            {
                return(false);
            }
            if (target is Entities.NPC)
            {
                return(false);
            }
            if (target is Entities.Monster)
            {
                if (((byte)(target as Entities.Monster).Behaviour) >= 3)
                {
                    return(false);
                }
            }
            if (target is Entities.GameClient)
            {
                if (!(target as Entities.GameClient).LoggedIn)
                {
                    return(false);
                }
            }
            if (attacker is Entities.GameClient)
            {
                Entities.GameClient client = (attacker as Entities.GameClient);
                if (!(DateTime.Now >= client.LastSmallLongSkill.AddMilliseconds(Core.TimeIntervals.SmallLongSkillInterval)) && client.AttackPacket == null)
                {
                    using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.REST))
                        client.Send(fmsg);
                    return(false);
                }
                client.LastSmallLongSkill = DateTime.Now;
            }

            target.HP += spell.Power;
            uint targetcount = 1;

            if (spell.SpellID == 1055)
            {
                foreach (Maps.IMapObject obj in target.Screen.MapObjects.Values)
                {
                    if (obj == null)
                    {
                        continue;
                    }
                    if (obj.EntityUID == attacker.EntityUID)
                    {
                        continue;
                    }
                    if (obj.EntityUID == target.EntityUID)
                    {
                        continue;
                    }
                    if (obj is Entities.NPC)
                    {
                        continue;
                    }
                    if (Core.Screen.GetDistance(obj.X, obj.Y, target.X, target.Y) > spell.Distance)
                    {
                        continue;
                    }
                    if (obj is Entities.Monster)
                    {
                        if (((byte)(obj as Entities.Monster).Behaviour) >= 3)
                        {
                            continue;
                        }
                    }
                    if (obj is Entities.GameClient)
                    {
                        if (!(obj as Entities.GameClient).LoggedIn)
                        {
                            continue;
                        }
                    }
                    (obj as Entities.IEntity).HP += spell.Power;
                    usespell.AddTarget(obj.EntityUID, spell.Power);
                    targetcount++;
                }
            }

            uint exp = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)spell.Power, (int)spell.Power * 2);

            exp *= targetcount;
            if ((attacker is Entities.GameClient))
            {
                (attacker as Entities.GameClient).AddSpellExp(spell.SpellID, exp);
            }

            usespell.AddTarget(target.EntityUID, spell.Power);

            return(true);
        }
        /// <summary>
        /// Handles the line skills.
        /// </summary>
        /// <param name="attacker">The attacker.</param>
        /// <param name="targets">The targets. [not set yet]</param>
        /// <param name="interaction">The interaction packet.</param>
        /// <param name="usespell">The usespell packet.</param>
        /// <param name="spell">The spell.</param>
        /// <param name="damage">The damage.</param>
        /// <returns>Returns true if the skill was used successfully.</returns>
        public static bool Handle(Entities.IEntity attacker, ConcurrentBag<Entities.IEntity> targets, InteractionPacket interaction, UseSpellPacket usespell, Data.Spell spell, out uint damage)
        {
            damage = 0;
            bool self = (interaction.TargetUID == attacker.EntityUID);
            if (self)
                return false;

            Calculations.InLineAlgorithm ila = new ProjectX_V3_Game.Calculations.InLineAlgorithm(
                attacker.X, interaction.X, attacker.Y, interaction.Y,
                (byte)spell.Range, Calculations.InLineAlgorithm.Algorithm.DDA);

            byte count = 0;
            bool bluename = false;
            foreach (Maps.IMapObject obj in attacker.Screen.MapObjects.Values)
            {
                if (count > 28)
                    return true;

                if(!(obj as Entities.IEntity).Alive)
                    continue;

                if (obj is Entities.NPC)
                    continue;

                if (obj.EntityUID == attacker.EntityUID)
                    continue;

                if (obj is Entities.BossMonster)
                {
                    if (!(obj as Entities.BossMonster).CanBeAttacked)
                        continue;
                }

                if (obj is Entities.Monster)
                {
                    if (((byte)(obj as Entities.Monster).Behaviour) >= 3)
                        continue;
                }

                if (obj is Entities.GameClient)
                {
                    if (!(obj as Entities.GameClient).LoggedIn)
                        continue;

                    if ((obj as Entities.GameClient).ContainsFlag1(Enums.Effect1.Fly))
                        continue;

                    if (obj.Map.MapType == Enums.MapType.NoPK && (attacker is Entities.GameClient))
                        continue;

                    if (!(DateTime.Now >= (obj as Entities.GameClient).LoginProtection.AddSeconds(10)))
                    {
                        continue;
                    }

                    if (!(DateTime.Now >= (obj as Entities.GameClient).ReviveProtection.AddSeconds(5)))
                    {
                        continue;
                    }

                    if (!Combat.FixTarget(attacker, (obj as Entities.GameClient)))
                        continue;

                    if ((obj as Entities.GameClient).ContainsFlag1(Enums.Effect1.BlueName))
                        bluename = true;
                }

                if (!ila.InLine(obj.X, obj.Y))
                    continue;

                Entities.IEntity targetentity = obj as Entities.IEntity;
                damage = Calculations.Battle.GetPhysicalDamage(attacker, targetentity);
                Combat.ProcessDamage(attacker, targetentity, ref damage, false);
                if (damage > 0)
                {
                    if (!(targetentity is Entities.GameClient))
                    {
                        uint exp = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)(damage / 2), (int)damage);
                        if (targetentity.Level > (attacker.Level + 10))
                            exp *= 2;

                        if ((attacker is Entities.GameClient))
                            (attacker as Entities.GameClient).AddSpellExp(spell.SpellID, exp);
                    }
                    usespell.AddTarget(targetentity.EntityUID, damage);
                    targets.Add(targetentity);
                }
                count++;
            }
            if (attacker is Entities.GameClient && bluename)
                (attacker as Entities.GameClient).AddStatusEffect1(Enums.Effect1.BlueName, 10000);
            return true;
        }
Exemple #36
0
        /// <summary>
        /// Handling the combat of the interact packet.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="interact">The interact packet.</param>
        public static void Handle(Entities.GameClient client, InteractionPacket interact)
        {
            if (interact == null)
            {
                return;
            }

            if (!client.Alive)
            {
                return;
            }

            if (client.Paralyzed)
            {
                return;
            }

            if (!client.CanAttack)
            {
                return;
            }

            if (!(DateTime.Now >= client.LoginProtection.AddSeconds(10)))
            {
                using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.REST))
                    client.Send(fmsg);
                return;
            }
            if (!(DateTime.Now >= client.ReviveProtection.AddSeconds(5)))
            {
                using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.REST))
                    client.Send(fmsg);
                return;
            }

            if (!(DateTime.Now >= client.LastAttack.AddMilliseconds(Core.TimeIntervals.AttackInterval)) && client.AttackPacket == null)
            {
                using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.REST))
                    client.Send(fmsg);
                return;
            }

            if (client.Battle != null)
            {
                if (!client.Battle.HandleBeginAttack(client))
                {
                    using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.REST))
                        client.Send(fmsg);
                    return;
                }
            }
            client.LastAttack = DateTime.Now;
            //client.AutoAttacking = false;
            switch (interact.Action)
            {
            case Enums.InteractAction.MagicAttack:
            {
                #region TemporaryDecryption
                if (!interact.UnPacked)
                {
                    interact.UnPacked = true;

                    byte[] packet  = interact.Copy();
                    ushort SkillId = Convert.ToUInt16(((long)packet[24] & 0xFF) | (((long)packet[25] & 0xFF) << 8));
                    SkillId ^= (ushort)0x915d;
                    SkillId ^= (ushort)client.EntityUID;
                    SkillId  = (ushort)(SkillId << 0x3 | SkillId >> 0xd);
                    SkillId -= 0xeb42;

                    uint Target = ((uint)packet[12] & 0xFF) | (((uint)packet[13] & 0xFF) << 8) | (((uint)packet[14] & 0xFF) << 16) | (((uint)packet[15] & 0xFF) << 24);
                    Target = ((((Target & 0xffffe000) >> 13) | ((Target & 0x1fff) << 19)) ^ 0x5F2D2463 ^ client.EntityUID) - 0x746F4AE6;

                    ushort TargetX = 0;
                    ushort TargetY = 0;
                    long   xx      = (packet[16] & 0xFF) | ((packet[17] & 0xFF) << 8);
                    long   yy      = (packet[18] & 0xFF) | ((packet[19] & 0xFF) << 8);
                    xx      = xx ^ (client.EntityUID & 0xffff) ^ 0x2ed6;
                    xx      = ((xx << 1) | ((xx & 0x8000) >> 15)) & 0xffff;
                    xx     |= 0xffff0000;
                    xx     -= 0xffff22ee;
                    yy      = yy ^ (client.EntityUID & 0xffff) ^ 0xb99b;
                    yy      = ((yy << 5) | ((yy & 0xF800) >> 11)) & 0xffff;
                    yy     |= 0xffff0000;
                    yy     -= 0xffff8922;
                    TargetX = Convert.ToUInt16(xx);
                    TargetY = Convert.ToUInt16(yy);

                    interact.TargetUID = Target;
                    interact.MagicType = SkillId;
                    interact.X         = TargetX;
                    interact.Y         = TargetY;
                }
                #endregion

                if (client.ContainsFlag1(Enums.Effect1.Riding) && interact.MagicType != 7001)
                {
                    if (client.Stamina >= 100)
                    {
                        client.Stamina = 0;
                        client.RemoveFlag1(Enums.Effect1.Riding);
                    }
                    return;
                }

                Magic.Handle(client, interact);
                break;
            }

            case Enums.InteractAction.Attack:
                if (client.ContainsFlag1(Enums.Effect1.Riding))
                {
                    if (client.Stamina >= 100)
                    {
                        client.Stamina = 0;
                        client.RemoveFlag1(Enums.Effect1.Riding);
                    }
                    return;
                }
                Physical.Handle(client, interact);
                break;

            case Enums.InteractAction.Shoot:
                if (client.ContainsFlag1(Enums.Effect1.Riding))
                {
                    if (client.Stamina >= 100)
                    {
                        client.Stamina = 0;
                        client.RemoveFlag1(Enums.Effect1.Riding);
                    }
                    return;
                }
                Ranged.Handle(client, interact);
                break;
            }
        }
 public static bool Handle(Entities.IEntity attacker, Entities.IEntity target, InteractionPacket interaction, UseSpellPacket usespell, Data.Spell spell, out uint damage)
 {
     damage = 0;
     if (!attacker.Alive)
     {
         return(false);
     }
     if (target == null)
     {
         return(false);
     }
     if (target.Alive)
     {
         return(false);
     }
     if (attacker.EntityUID == target.EntityUID)
     {
         return(false);
     }
     if (!(target is Entities.GameClient))
     {
         return(false);
     }
     Entities.GameClient TargetClient = (target as Entities.GameClient);
     TargetClient.ForceRevive();
     usespell.AddTarget(TargetClient.EntityUID, 0);
     return(true);
 }
Exemple #38
0
        public static bool Handle(Entities.IEntity attacker, Entities.IEntity target, InteractionPacket interaction, UseSpellPacket usespell, Data.Spell spell, out uint damage)
        {
            damage = 0;
            if (!attacker.Alive)
            {
                return(false);
            }
            if (target == null)
            {
                return(false);
            }
            if (!target.Alive)
            {
                return(false);
            }
            if (!(target is Entities.GameClient))
            {
                return(false);
            }
            if (attacker is Entities.GameClient)
            {
                Entities.GameClient client = (attacker as Entities.GameClient);
                if (!(DateTime.Now >= client.LastSmallLongSkill.AddMilliseconds(Core.TimeIntervals.SmallLongSkillInterval)) && client.AttackPacket == null)
                {
                    using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.REST))
                        client.Send(fmsg);
                    return(false);
                }
                client.LastSmallLongSkill = DateTime.Now;
            }

            Entities.GameClient TargetClient = (target as Entities.GameClient);
            if (!TargetClient.LoggedIn)
            {
                return(false);
            }

            switch (spell.SpellID)
            {
            case 1075:
                TargetClient.AddStatusEffect1(Enums.Effect1.PartiallyInvisible, spell.Duration * 1000);
                break;

            case 1085:
                TargetClient.AddStatusEffect1(Enums.Effect1.StarOfAccuracy, spell.Duration * 1000);
                break;

            case 1090:
                TargetClient.AddStatusEffect1(Enums.Effect1.Shield, spell.Duration * 1000);
                break;

            case 1095:
                TargetClient.AddStatusEffect1(Enums.Effect1.Stig, spell.Duration * 1000);
                break;

            default:
                return(false);
            }
            byte level_target = (byte)(TargetClient.Level > 50 ? 50 : TargetClient.Level);
            uint exp          = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)level_target, (int)level_target * 2);

            if ((attacker is Entities.GameClient))
            {
                (attacker as Entities.GameClient).AddSpellExp(spell.SpellID, exp);
            }

            usespell.AddTarget(TargetClient.EntityUID, damage);

            return(true);
        }