Exemplo n.º 1
0
        public virtual void OnDamage(Networking.GameDataHandler handler)
        {
            bool isPlayer = handler.GetBool(2);
            byte targetId = handler.GetByte(3);

            Entities.Player p = null;

            try
            {
                handler.Room.Players.TryGetValue(targetId, out p);
            }
            catch { p = null; }

            if (p != null)
            {
                string weaponCode = handler.GetString(22).ToUpper();
                if (weaponCode.Length == 4)
                {
                    if (isPlayer)
                    {
                        Objects.Items.ItemData itemData = null;
                        try
                        {
                            itemData = Managers.ItemManager.Instance.Items.Values.Where(n => n.Code == weaponCode).First();
                        }
                        catch { itemData = null; }

                        if (itemData != null && itemData.IsWeapon)
                        {
                            Objects.Items.Weapon weapon = (Objects.Items.Weapon)itemData;
                            if (weapon != null)
                            {
                                Objects.Inventory.Item item = handler.Player.User.Inventory.Equipment.Get(handler.Player.Class, weaponCode);
                                if (item != null)
                                {
                                    if (handler.Player.IsAlive && handler.Player.Health > 0)
                                    {
                                        if (p.IsAlive && p.Health > 0)
                                        {
                                            uint boneId = handler.GetuInt(11);
                                            if (boneId > 0)
                                            {
                                                byte  realBoneId      = 0;
                                                bool  head            = false;
                                                short remainingHealth = 0;
                                                bool  useRadius       = handler.GetBool(10);

                                                ushort previousHealth = p.Health;
                                                short  damageTaken    = 0;

                                                if (!useRadius)
                                                {
                                                    switch ((boneId - handler.Player.User.SessionID))
                                                    {
                                                    case 1237:
                                                    {
                                                        realBoneId = 0;         // Head
                                                        head       = true;
                                                        break;
                                                    }

                                                    case 1239:
                                                    {
                                                        realBoneId = 1;         // Chest
                                                        break;
                                                    }

                                                    case 1241:
                                                    {
                                                        realBoneId = 2;
                                                        break;
                                                    }

                                                    default:
                                                    {
                                                        Log.Instance.WriteLine("Unknown Bone :: " + (boneId - handler.Player.User.SessionID) + " :: " + boneId);
                                                        //handler.Player.User.Disconnect();
                                                        break;
                                                    }
                                                    }

                                                    damageTaken = (short)((float)weapon.Power * ((float)weapon.PowerPersonal[realBoneId] / 100));
                                                }
                                                else
                                                {
                                                    damageTaken = (short)((1000 / 100) * boneId);
                                                }


                                                if (handler.Room.Mode != Enums.Mode.Free_For_All && handler.Player.Team == p.Team)
                                                {
                                                    damageTaken = 0;
                                                }

                                                remainingHealth = (short)((short)p.Health - damageTaken);

                                                if (remainingHealth < 0)
                                                {
                                                    damageTaken = (short)p.Health;
                                                }

                                                if (remainingHealth <= 0)
                                                {
                                                    handler.type = Enums.GameSubs.PlayerDeath;
                                                    p.AddDeaths();
                                                    handler.Player.AddKill(head);
                                                    OnDeath(handler.Player, p);
                                                }
                                                else
                                                {
                                                    p.Health -= (ushort)damageTaken;
                                                }

                                                handler.Set(12, p.Health);
                                                handler.Set(13, previousHealth);
                                                handler.respond = true;

                                                //System.Log.Instance.WriteLine("DAMAGE :: " + handler.Player.User.Displayname + " -> " + p.User.Displayname + ": " + damageTaken);
                                            }
                                            else
                                            {
                                                handler.Player.User.Disconnect();
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    handler.Player.User.Disconnect();
                                }
                            }
                            else
                            {
                                handler.Player.User.Disconnect();
                            }
                        }
                        else
                        {
                            handler.Player.User.Disconnect();
                        }
                    }
                    else
                    {
                        handler.Player.User.Disconnect();
                    }
                }
            }
        }
Exemplo n.º 2
0
        public override void Handle(User sender, InPacket packetReader)
        {
            if (sender.Authenticated)
            {
                bool equipItem    = !packetReader.ReadBool();
                byte bTargetClass = packetReader.ReadByte();
                if (bTargetClass < Objects.Inventory.Equipment.MAX_CLASSES)
                {
                    Classes targetClass = (Classes)bTargetClass;
                    string  weaponCode  = packetReader.ReadString(4).ToUpper();
                    byte    targetSlot  = 0;

                    if (weaponCode.Length == 4)
                    {
                        if (targetSlot < 8)
                        {
                            if (equipItem)
                            {
                                targetSlot = packetReader.ReadByte(5);
                                if (targetSlot < Objects.Inventory.Equipment.MAX_SLOTS)
                                {
                                    if (Managers.ItemManager.Instance.Items.ContainsKey(weaponCode))
                                    {
                                        Objects.Items.ItemData item = null;
                                        if (Managers.ItemManager.Instance.Items.TryGetValue(weaponCode, out item))
                                        {
                                            if (item.IsWeapon)
                                            {
                                                Objects.Items.Weapon weapon = (Objects.Items.Weapon)item;
                                                if (weapon != null)
                                                {
                                                    if (weapon.Active && weapon.CanEquip[(byte)targetClass, targetSlot])
                                                    {
                                                        Objects.Inventory.Item equipmentItem = sender.Inventory.Get(weapon.Code);
                                                        if (equipmentItem != null && equipmentItem.Slot >= 0)
                                                        { // Does the user have the item.
                                                            Objects.Inventory.Item equipedItem = sender.Inventory.Equipment.Get(targetClass, targetSlot);
                                                            if (equipedItem == null || equipmentItem.Slot != equipedItem.Slot)
                                                            {
                                                                // string Type = getBlock(2);
                                                                if (equipmentItem.Equiped[(byte)targetClass] >= 0)
                                                                {
                                                                    sender.Inventory.Equipment.Remove(targetClass, (byte)equipmentItem.Equiped[(byte)targetClass]);
                                                                }

                                                                sender.Inventory.Equipment.Add(targetClass, targetSlot, equipmentItem);
                                                                sender.Inventory.Equipment.Build();
                                                                sender.Inventory.Equipment.BuildInternal();
                                                                sender.Send(new Packets.Equipment(targetClass, sender.Inventory.Equipment.ListsInternal[(byte)targetClass]));
                                                            }
                                                            else
                                                            {
                                                                sender.Send(new Packets.Equipment(Packets.Equipment.ErrorCode.AlreadyEquipped)); // Already equiped.
                                                            }
                                                        }
                                                        else
                                                        {
                                                            bool isFound = false; // ATTAMPT TO CHECK IF THE ITEM IS A DEFAULT ITEM.
                                                            Objects.Inventory.Item equipedItem = sender.Inventory.Equipment.Get(targetClass, targetSlot);
                                                            for (byte j = 0; j < Objects.Inventory.Inventory.DEFAULT_ITEMS.Length; j++)
                                                            {
                                                                if (weaponCode == Objects.Inventory.Inventory.DEFAULT_ITEMS[j])
                                                                {
                                                                    isFound = true;
                                                                    if (equipedItem == null || equipedItem.Slot != -1)
                                                                    {
                                                                        sender.Inventory.Equipment.Add(targetClass, targetSlot, new Objects.Inventory.Item(-1, 0, Objects.Inventory.Inventory.DEFAULT_ITEMS[j], 0));
                                                                        sender.Inventory.Equipment.Build();
                                                                        sender.Inventory.Equipment.BuildInternal();
                                                                        sender.Send(new Packets.Equipment(targetClass, sender.Inventory.Equipment.ListsInternal[(byte)targetClass]));
                                                                    }
                                                                    else
                                                                    {
                                                                        sender.Send(new Packets.Equipment(Packets.Equipment.ErrorCode.AlreadyEquipped)); // Already equiped.
                                                                    }
                                                                    break;
                                                                }
                                                            }
                                                            if (!isFound)
                                                            {
                                                                sender.Disconnect(); // potentiality scripting or packet changing.. TODO: LOG
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        sender.Disconnect(); // potentiality scripting or packet changing.. TODO: LOG
                                                    }
                                                }
                                                else
                                                {
                                                    sender.Disconnect(); // Server error?
                                                }
                                            }
                                        }
                                        else
                                        {
                                            sender.Disconnect(); // Server error?
                                        }
                                    }
                                    else
                                    {
                                        sender.Disconnect(); // potentiality scripting or packet changing.. TODO: LOG
                                    }
                                }
                                else
                                {
                                    sender.Disconnect(); // potentiality scripting or packet changing.. TODO: LOG
                                }
                            }
                            else
                            {
                                targetSlot = packetReader.ReadByte(3);
                                Objects.Inventory.Item equipedItem = sender.Inventory.Equipment.Get(targetClass, targetSlot);
                                if (equipedItem != null)
                                {
                                    sender.Inventory.Equipment.Remove(targetClass, targetSlot);
                                    sender.Inventory.Equipment.Build();
                                    sender.Send(new Packets.Equipment(targetClass, sender.Inventory.Equipment.Lists[(byte)targetClass]));
                                }
                            }
                        }
                    }
                }
                else
                {
                    sender.Disconnect();
                }
            }
        }
Exemplo n.º 3
0
        public virtual void OnDamage(Networking.GameDataHandler handler)
        {
            bool   _isPlayer       = handler.GetBool(2);
            byte   _targetId       = handler.GetByte(3);
            bool   _isRadiusWeapon = handler.GetBool(10);
            uint   _boneId         = handler.GetuInt(11);
            string _weaponCode     = handler.GetString(22).ToUpper();

            //Radius is used when _isradiusWeapon is true. Values range from 0 to 100
            uint _radius = _boneId;

            Entities.Player Victim   = null;
            Entities.Player Attacker = handler.Player;

            try { handler.Room.Players.TryGetValue(_targetId, out Victim); }
            catch { Victim = null; }

            if (Victim != null)
            {
                if (_isPlayer)
                {
                    Objects.Items.ItemData ItemData = null;

                    try { ItemData = Managers.ItemManager.Instance.Items.Values.Where(n => n.Code == _weaponCode).First(); }
                    catch { ItemData = null; }

                    if (ItemData != null && ItemData.IsWeapon)
                    {
                        Objects.Items.Weapon   Weapon     = (Objects.Items.Weapon)ItemData;
                        Objects.Inventory.Item PlayerItem = Attacker.User.Inventory.Equipment.Get(handler.Player.Class, _weaponCode);

                        if (PlayerItem != null) //player have the wep
                        {
                            if (CanInFlictDamageTo(Attacker, Victim))
                            {
                                uint         _realBoneId       = _boneId - handler.Player.User.SessionID;
                                bool         _isHeadShot       = false;
                                short        _damageTaken      = 0;
                                double       _hitboxMultiplier = 1.0;
                                Enums.Hitbox Location;
                                try { Location = (Hitbox)_realBoneId; }
                                catch { Location = Hitbox.TorsoLimbs; }

                                if (Location == Hitbox.HeadNeck && !Weapon.Code.Contains("DA") && !Weapon.Code.Contains("DJ") && !Weapon.Code.Contains("DK"))
                                {
                                    _isHeadShot = true;
                                }

                                #region Explanation to the DJ03 case
                                //RPG-7 vanilla behaviour requires some tweaks... our reverse-engineered damage calc. is not consistent
                                //with vanilla in-game experience suggesting some more shit is going on
                                //server side
                                //SO... most DJ-DK weapons have reduced personal hitMult. in the DB... consistent with gamefiles and damage calc.
                                //but RPG-7
                                #endregion

                                if (!_isRadiusWeapon)
                                {
                                    if (Weapon.Code == "DJ03")
                                    {
                                        _damageTaken = 1000;
                                    }
                                    else
                                    {
                                        _hitboxMultiplier = GetHitBoxMultiplier(Location);
                                        _damageTaken      = DamageCalculator(Weapon.Power, Weapon.PowerPersonal[0], _hitboxMultiplier, 100);
                                    }
                                }
                                else
                                {
                                    _damageTaken = DamageCalculator(Weapon.Power, Weapon.PowerPersonal[0], 1.0, _radius);
                                }

                                DamagePlayer(handler, Attacker, Victim, _damageTaken, _isHeadShot);
                            }
                        }
                        //  else
                        //      Attacker.User.Disconnect(); ---> Commented out because of client bug with knifes
                    }
                }
                else //a vehicle attacked our poor player :(
                {
                    OnVehicleAttackToPlayer(handler, Attacker, Victim);
                }
            }
        }