Esempio n. 1
0
        private void DamagePlayer(Networking.GameDataHandler handler, Entities.Player Attacker, Entities.Player Victim, short _damageTaken, bool _isHeadShot)
        {
            ushort _previousHealth  = Victim.Health;
            short  _remainingHealth = (short)((short)Victim.Health - _damageTaken);

            if (_remainingHealth > 0)
            {
                Victim.Health -= (ushort)_damageTaken;
            }
            else
            {
                Victim.Health = 0;

                handler.type = GameSubs.PlayerDeath;

                if (_isHeadShot)
                {
                    handler.Set(17, "99.000");  //headshot icon
                }
                if (isFriendlyFire(Attacker, Victim))
                {
                    Attacker.AddFakeDeath();
                    Attacker.SubtractKill();
                    Victim.IsAlive = false;  //no more fake methods ;)
                    ServerLogger.Instance.Append(ServerLogger.AlertLevel.Gaming, string.Concat(Attacker.User.Displayname, " killed his teammate ", Victim.User.Displayname));
                }
                else
                {
                    Victim.AddDeaths();
                    Attacker.AddKill(_isHeadShot);
                    OnDeath(Attacker, Victim);
                }
                ServerLogger.Instance.Append(ServerLogger.AlertLevel.Gaming, string.Concat(Attacker.User.Displayname, " killed ", Victim.User.Displayname));
            }

            handler.Set(12, Victim.Health);
            handler.Set(13, _previousHealth);
            handler.respond = true;
        }
Esempio n. 2
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();
                    }
                }
            }
        }
Esempio n. 3
0
        private void DamageVehicle(Networking.GameDataHandler handler, Entities.Player Attacker, Entities.Vehicle DamagedVehicle, short _damageTaken)
        {
            DamagedVehicle.Damage((ushort)_damageTaken);

            if (DamagedVehicle.IsAlive) //vehicle is still ok
            {
                handler.type = GameSubs.ObjectDamage;
                handler.Set(12, DamagedVehicle.Health);
                handler.Set(13, _damageTaken);
                handler.respond = true;
            }
            else  //vehicle has been destroyed
            {
                if (DamagedVehicle.Team != Team.None)
                {
                    //Creating the death packet from the original buffer
                    foreach (Objects.VehicleSeat Seat in DamagedVehicle.Seats)
                    {
                        Entities.Player Victim = Seat.UsedBy;

                        if (Victim != null && Victim.IsAlive)
                        {
                            Networking.GameDataHandler DeathHandler = Managers.PacketManager.Instance.GetHandler((ushort)GameSubs.PlayerDeath);
                            if (DeathHandler != null)
                            {
                                try
                                {
                                    DeathHandler.Process(Victim.User, handler.GetIncPacket());

                                    if (!isFriendlyFire(Attacker, Victim))
                                    {
                                        Victim.AddDeaths();
                                        Attacker.AddKill(false);
                                    }
                                    else
                                    {
                                        Attacker.SubtractKill();
                                        Attacker.AddFakeDeath();
                                    }
                                    OnDeath(Attacker, Victim);
                                }
                                catch { ServerLogger.Instance.Append(ServerLogger.AlertLevel.ServerError, string.Concat("Could not kill player ", Victim.User.Displayname, " on vehicle ", DamagedVehicle.Code)); }
                            }
                        }
                    }
                }

                //Destroying veh
                handler.type = GameSubs.ObjectDestroy;
                handler.Set(12, DamagedVehicle.Health);
                handler.Set(13, _damageTaken);
                handler.Set(14, 15);
                handler.respond = true;

                if (!isFriendlyFire(Attacker, DamagedVehicle))
                {
                    Attacker.VehiclesDestroyed++;
                    Attacker.User.VehiclesDestroyed++;
                }
                ServerLogger.Instance.Append(ServerLogger.AlertLevel.Gaming, string.Concat(Attacker.User.Displayname, " destroyed a vehicle: ", DamagedVehicle.Code));
            }
        }