Beispiel #1
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);
        }
Beispiel #2
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;
            }
        }