Example #1
0
        public DestroyEvent(ref DamageEvent d, Entity ent, bool isdecay)
        {
            Fougerite.Player player = Fougerite.Player.FindByPlayerClient(d.attacker.client);
            if (player != null)
            {
                this.Destroyer = player;
            }
            else
            {
                this.Destroyer = new NPC(d.attacker.character);
            }

            this.WeaponData  = null;
            this.IsDecay     = isdecay;
            this.DamageEvent = d;
            this.Entity      = ent;

            if (d.extraData != null)
            {
                WeaponImpact extraData = d.extraData as WeaponImpact;
                this.WeaponData = extraData;
                string name = "";
                if (extraData.dataBlock != null)
                {
                    name = extraData.dataBlock.name;
                }
                this.WeaponName = name;
            }
        }
Example #2
0
 public HurtEvent(ref DamageEvent d)
 {
     Magma.Player player = Magma.Player.FindByPlayerClient(d.attacker.client);
     if (player != null)
     {
         this.Attacker = player;
     }
     else
     {
         this.Attacker = new NPC(d.attacker.character);
     }
     Magma.Player player2 = Magma.Player.FindByPlayerClient(d.victim.client);
     if (player2 != null)
     {
         this.Victim = player2;
     }
     else
     {
         this.Victim = new NPC(d.victim.character);
     }
     this.DamageEvent = d;
     this.WeaponData  = null;
     this.IsDecay     = false;
     if (d.extraData != null)
     {
         WeaponImpact extraData = d.extraData as WeaponImpact;
         this.WeaponData = extraData;
         string name = "";
         if (extraData.dataBlock != null)
         {
             name = extraData.dataBlock.name;
         }
         this.WeaponName = name;
     }
 }
Example #3
0
        void OnHurt(TakeDamage takeDamage, DamageEvent damage)
        {
            if (!(takeDamage is HumanBodyTakeDamage))
            {
                return;
            }
            if (damage.attacker.client == null)
            {
                return;
            }
            if (damage.victim.client == null)
            {
                return;
            }
            NetUser attacker = damage.attacker.client?.netUser;
            NetUser victim   = damage.victim.client?.netUser;

            if (attacker == null || victim == null)
            {
                return;
            }
            if (damage.attacker.client == damage.victim.client)
            {
                return;
            }

            WeaponImpact impact = damage.extraData as WeaponImpact;
            string       weapon = impact?.dataBlock.name ?? UNKNOWN;
            double       dmg    = Math.Floor(damage.amount);

            if (dmg == 0)
            {
                return;
            }
            string icon     = "!";
            float  duration = 5f;
            string weaponm  = "";

            if (weapon != UNKNOWN)
            {
                weaponm = string.Format("with {0}", weapon);
            }
            PlayerInventory inv = attacker.playerClient.controllable.GetComponent <PlayerInventory>();

            if (inv != null && (inv.activeItem?.datablock?.name?.Contains("Bow") ?? false))
            {
                weaponm = string.Format("with {0}", inv.activeItem.datablock.name);
            }
            if (bUserOtherDamage.ContainsKey(attacker) && bUserOtherDamage[attacker])
            {
                rust.Notice(attacker, string.Format("You attacked {0} {1} and made {2} dmg.", victim.displayName, weaponm, dmg), icon, duration);
            }
            if (bUserSelfDamage.ContainsKey(victim) && bUserSelfDamage[victim])
            {
                rust.Notice(victim, string.Format("You were attacked by {0} {1} and he made {2} dmg.", attacker.displayName, weaponm, dmg), icon, duration);
            }
            Puts(string.Format("{0} attacked {1} with {2} and made {3} dmg.", attacker.displayName, victim.displayName, weaponm, dmg));
        }
Example #4
0
        private void OnKilled(TakeDamage takedamage, DamageEvent damage)
        {
            WeaponImpact impact = damage.extraData as WeaponImpact;
            DeathTags    tags   = new DeathTags();

            tags.killer   = damage.attacker.client?.netUser.displayName ?? UNKNOWN;
            tags.killerId = damage.attacker.client?.netUser.userID.ToString() ?? UNKNOWN;
            tags.weapon   = impact?.dataBlock.name ?? UNKNOWN;
            tags.distance = Math.Floor(Vector3.Distance(damage.attacker.id.transform.position, damage.victim.id.transform.position));
            tags.location = damage.victim.id.transform.position;

            if (takedamage is HumanBodyTakeDamage)
            {
                SetPlayerDeathTags((HumanBodyTakeDamage)takedamage, damage, ref tags);
                CheckForHuntingBow(takedamage, damage, ref tags);
                switch (tags.deathType)
                {
                case DeathTypes.entity:
                case DeathTypes.human:
                {
                    Core.Interface.CallHook("OnPlayerDeath", takedamage, damage, tags);
                    break;
                }

                case DeathTypes.suicide:
                {
                    Core.Interface.CallHook("OnPlayerSuicide", takedamage, damage, tags);
                    break;
                }

                default:
                {
                    break;
                }
                }
            }
            else if (takedamage is ProtectionTakeDamage && damage.sender.gameObject.GetComponentInChildren <BasicWildLifeAI>() && damage.attacker.client != null)
            {
                SetAnimalDeathTags(takedamage, damage, ref tags);
                CheckForHuntingBow(takedamage, damage, ref tags);
                Core.Interface.CallHook("OnAnimalDeath", takedamage, damage, tags);
            }
            else
            {
                SetBuildingDeathTags(takedamage, damage, ref tags);
                if (takedamage.GetComponent <DeployableObject>())
                {
                    Core.Interface.CallHook("OnDeployableDestroyed", takedamage, damage, tags);
                }
                else
                {
                    Core.Interface.CallHook("OnStructureDestroyed", takedamage, damage, tags);
                }
            }
        }
Example #5
0
 /////////////////////////
 // OnPlayerConnected(NetUser netuser)
 // Called when a player connects
 /////////////////////////
 void CheckOverKill(TakeDamage takedamage, DamageEvent damage)
 {
     if (!(damage.extraData is WeaponImpact))
     {
         return;
     }
     cachedWeapon = damage.extraData as WeaponImpact;
     if (cachedWeapon.dataBlock == null)
     {
         return;
     }
     if (!overkillDictionary.ContainsKey(cachedWeapon.dataBlock.name))
     {
         return;
     }
     if (damage.victim.networkView == null)
     {
         return;
     }
     if (Vector3.Distance(damage.attacker.networkView.position, damage.victim.networkView.position) < Convert.ToSingle(overkillDictionary[cachedWeapon.dataBlock.name]))
     {
         return;
     }
     cachedOverkill = damage.attacker.client.GetComponent <OverKillHandler>();
     if (cachedOverkill == null)
     {
         cachedOverkill = damage.attacker.client.gameObject.AddComponent <OverKillHandler>();
     }
     if (Time.realtimeSinceStartup - cachedOverkill.lastOverkill > overkillResetTimer)
     {
         cachedOverkill.number = 0f;
     }
     cachedOverkill.lastOverkill = Time.realtimeSinceStartup;
     cachedOverkill.number++;
     AntiCheatBroadcastAdmins(string.Format("{0} did an OverKill with {1} @ {2}m", damage.attacker.client.userName, cachedWeapon.dataBlock.name, Math.Floor(Vector3.Distance(damage.attacker.networkView.position, damage.victim.networkView.position)).ToString()));
     if (overkillPunish && cachedOverkill.number >= overkillDetectionForPunish)
     {
         Punish(damage.attacker.client, string.Format("rOverKill {0} ({1})", cachedWeapon.dataBlock.name, Math.Floor(Vector3.Distance(damage.attacker.networkView.position, damage.victim.networkView.position)).ToString()));
     }
 }
Example #6
0
        public HurtEvent(ref DamageEvent d)
        {
            Fougerite.Player player = Fougerite.Player.FindByPlayerClient(d.attacker.client);
            if (player != null)
            {
                this.Attacker = player;
            }
            else
            {
                this.Attacker = new NPC(d.attacker.character);
            }
            Fougerite.Player player2 = Fougerite.Player.FindByPlayerClient(d.victim.client);
            if (player2 != null)
            {
                this.Victim = player2;
            }
            else
            {
                this.Victim = new NPC(d.victim.character);
            }
            this.DamageEvent = d;
            this.WeaponData  = null;
            this.IsDecay     = false;
            string weaponName = "Unknown";

            if (d.extraData != null)
            {
                WeaponImpact extraData = d.extraData as WeaponImpact;
                this.WeaponData = extraData;
                if (extraData.dataBlock != null)
                {
                    weaponName = extraData.dataBlock.name;
                }
            }
            else
            {
                if (d.attacker.id is TimedExplosive)
                {
                    weaponName = "Explosive Charge";
                }
                else if (d.attacker.id is TimedGrenade)
                {
                    weaponName = "F1 Grenade";
                }
                else if (d.attacker.id.ToString().Contains("MutantBear"))
                {
                    weaponName = "Mutant Bear Claw";
                }
                else if (d.attacker.id.ToString().Contains("Bear"))
                {
                    weaponName = "Bear Claw";
                }
                else if (d.attacker.id.ToString().Contains("MutantWolf"))
                {
                    weaponName = "Mutant Wolf Claw";
                }
                else if (d.attacker.id.ToString().Contains("Wolf"))
                {
                    weaponName = "Wolf Claw";
                }
                else if (d.attacker.id.Equals(d.victim.id))
                {
                    weaponName = String.Format("Self ({0})", DamageType);
                }
                else
                {
                    weaponName = "Hunting Bow";
                }
            }
            this.WeaponName = weaponName;
        }
Example #7
0
        public HurtEvent(ref DamageEvent d)
        {
            //Logger.LogDebug(string.Format("[DamageEvent] {0}", d.ToString()));
            try
            {
                this._sleeper    = false;
                this.DamageEvent = d;
                this.WeaponData  = null;
                this.IsDecay     = false;
                this._status     = d.status;
                string weaponName = "Unknown";
                if (d.victim.idMain is DeployableObject)
                {
                    if (d.victim.id.ToString().ToLower().Contains("sleeping"))
                    {
                        this._sleeper = true;
                        DeployableObject sleeper = d.victim.idMain as DeployableObject;
                        this.Victim = new Sleeper(sleeper);
                    }
                    else
                    {
                        this.Victim = new Entity(d.victim.idMain.GetComponent <DeployableObject>());
                    }
                    this._playervictim = false;
                }
                else if (d.victim.idMain is StructureComponent)
                {
                    this.Victim        = new Entity(d.victim.idMain.GetComponent <StructureComponent>());
                    this._playervictim = false;
                }
                else if (d.victim.id is SpikeWall)
                {
                    this._playerattacker = false;
                    this.Victim          = new Entity(d.victim.idMain.GetComponent <DeployableObject>());
                }
                else if (d.victim.client != null)
                {
                    this.Victim        = Fougerite.Server.Cache[d.victim.client.userID];
                    this._playervictim = true;
                }
                else if (d.victim.character != null)
                {
                    this.Victim        = new NPC(d.victim.character);
                    this._playervictim = false;
                }
                if (!(bool)d.attacker.id)
                {
                    if (d.victim.client != null)
                    {
                        weaponName           = this.DamageType;
                        this._playerattacker = false;
                        this.Attacker        = null;
                    }
                }
                else if (d.attacker.id is SpikeWall)
                {
                    this._playerattacker = false;
                    this.Attacker        = new Entity(d.attacker.idMain.GetComponent <DeployableObject>());
                    weaponName           = d.attacker.id.ToString().Contains("Large") ? "Large Spike Wall" : "Spike Wall";
                }
                else if (d.attacker.id is SupplyCrate)
                {
                    this._playerattacker = false;
                    this.Attacker        = new Entity(d.attacker.idMain.gameObject);
                    weaponName           = "Supply Crate";
                }
                else if (d.attacker.id is Metabolism && d.victim.id is Metabolism)
                {
                    //this.Attacker = Fougerite.Server.Cache[d.attacker.client.userID];
                    this.Attacker        = Fougerite.Player.FindByPlayerClient(d.attacker.client);
                    this._playerattacker = false;
                    this.Victim          = this.Attacker;
                    ICollection <string> list = new List <string>();
                    Fougerite.Player     vic  = this.Victim as Fougerite.Player;
                    if (vic.IsStarving)
                    {
                        list.Add("Starvation");
                    }
                    if (vic.IsRadPoisoned)
                    {
                        list.Add("Radiation");

                        /*if (vic.RadLevel > 5000)
                         * {
                         *  vic.AddRads(-vic.RadLevel);
                         *  d.amount = 0;
                         *  _de.amount = 0;
                         *  Logger.LogDebug("[RadiationHack] Someone tried to kill " + vic.Name + " with radiation hacks.");
                         * }*/
                    }
                    if (vic.IsPoisoned)
                    {
                        list.Add("Poison");
                    }
                    if (vic.IsBleeding)
                    {
                        list.Add("Bleeding");
                    }

                    if (list.Contains("Bleeding"))
                    {
                        if (this.DamageType != "Unknown" && !list.Contains(this.DamageType))
                        {
                            list.Add(this.DamageType);
                        }
                    }
                    if (list.Count > 0)
                    {
                        weaponName = string.Format("Self ({0})", string.Join(",", list.ToArray()));
                    }
                    else
                    {
                        weaponName = this.DamageType;
                    }
                }
                else if (d.attacker.client != null)
                {
                    this.Attacker        = Fougerite.Server.Cache[d.attacker.client.userID];
                    this._playerattacker = true;
                    if (d.extraData != null)
                    {
                        WeaponImpact extraData = d.extraData as WeaponImpact;
                        this.WeaponData = extraData;
                        if (extraData.dataBlock != null)
                        {
                            weaponName = extraData.dataBlock.name;
                        }
                    }
                    else
                    {
                        if (d.attacker.id is TimedExplosive)
                        {
                            weaponName = "Explosive Charge";
                        }
                        else if (d.attacker.id is TimedGrenade)
                        {
                            weaponName = "F1 Grenade";
                        }
                        else
                        {
                            weaponName = "Hunting Bow";
                        }
                        if (d.victim.client != null)
                        {
                            if (!d.attacker.IsDifferentPlayer(d.victim.client) && !(this.Victim is Entity))
                            {
                                weaponName = "Fall Damage";
                            }
                            else if (!d.attacker.IsDifferentPlayer(d.victim.client) && (this.Victim is Entity))
                            {
                                weaponName = "Hunting Bow";
                            }
                        }
                    }
                }
                else if (d.attacker.character != null)
                {
                    this.Attacker        = new NPC(d.attacker.character);
                    this._playerattacker = false;
                    weaponName           = string.Format("{0} Claw", (this.Attacker as NPC).Name);
                }
                this.WeaponName = weaponName;
            }
            catch (Exception ex)
            {
                Logger.LogDebug(string.Format("[HurtEvent] Error. " + ex.ToString()));
            }
        }
Example #8
0
        public DestroyEvent(ref DamageEvent d, Entity ent, bool isdecay)
        {
            Fougerite.Player player = Server.Cache[d.attacker.client.userID];
            if (player != null)
            {
                this.Attacker = player;
            }

            this.WeaponData  = null;
            this.IsDecay     = isdecay;
            this.DamageEvent = d;
            this.Entity      = ent;

            string weaponName = "Unknown";

            if (d.extraData != null)
            {
                WeaponImpact extraData = d.extraData as WeaponImpact;
                this.WeaponData = extraData;
                if (extraData.dataBlock != null)
                {
                    weaponName = extraData.dataBlock.name;
                }
            }
            else
            {
                if (d.attacker.id is TimedExplosive)
                {
                    weaponName = "Explosive Charge";
                }
                else if (d.attacker.id is TimedGrenade)
                {
                    weaponName = "F1 Grenade";
                }
                else if (d.attacker.id.ToString().Contains("MutantBear"))
                {
                    weaponName = "Mutant Bear Claw";
                }
                else if (d.attacker.id.ToString().Contains("Bear"))
                {
                    weaponName = "Bear Claw";
                }
                else if (d.attacker.id.ToString().Contains("MutantWolf"))
                {
                    weaponName = "Mutant Wolf Claw";
                }
                else if (d.attacker.id.ToString().Contains("Wolf"))
                {
                    weaponName = "Wolf Claw";
                }
                else if (d.attacker.id.Equals(d.victim.id))
                {
                    weaponName = string.Format("Self ({0})", DamageType);
                }
                else
                {
                    weaponName = "Hunting Bow";
                }
            }
            this.WeaponName = weaponName;
        }
 public static bool DamageOverride(TakeDamage take, ref DamageEvent damage, ref TakeDamage.Quantity quantity)
 {
     if (damage.attacker.idMain != damage.victim.idMain)
     {
         if (!Core.OverrideDamage || float.IsInfinity(damage.amount))
         {
             return(true);
         }
         if ((damage.victim.id.GetComponent <Character>() == null) && (damage.attacker.client != null))
         {
             ulong ownerID = (damage.victim.client != null) ? damage.victim.client.userID : ((ulong)0L);
             if (damage.victim.idMain is DeployableObject)
             {
                 ownerID = (damage.victim.idMain as DeployableObject).ownerID;
             }
             if (damage.victim.idMain is StructureComponent)
             {
                 ownerID = (damage.victim.idMain as StructureComponent)._master.ownerID;
             }
             ulong num2 = (damage.attacker.client != null) ? damage.attacker.client.userID : ((ulong)0L);
             if (damage.attacker.idMain is DeployableObject)
             {
                 num2 = (damage.attacker.idMain as DeployableObject).ownerID;
             }
             if (damage.attacker.idMain is StructureComponent)
             {
                 num2 = (damage.attacker.idMain as StructureComponent)._master.ownerID;
             }
             if (((ownerID == num2) || Users.SharedGet(ownerID, num2)) && (Core.OwnershipDestroy || Core.DestoryOwnership.ContainsKey(damage.attacker.client.userID)))
             {
                 Config.Get("OVERRIDE.DAMAGE", damage.attacker.idMain.name.Replace("(Clone)", "") + ".DAMAGE", ref damage.amount, true);
                 return(true);
             }
         }
         bool result = true;
         if ((damage.attacker.client != null) && (damage.attacker.idMain is Character))
         {
             WeaponImpact extraData = damage.extraData as WeaponImpact;
             string       str       = (extraData != null) ? extraData.dataBlock.name : "Hunting Bow";
             string       str2      = str.Replace(" ", "") + ".DAMAGE";
             string       key       = str2 + "." + damage.victim.idMain.name.Replace("(Clone)", "");
             string       str4      = str2 + ".HEADSHOT";
             if (Config.Get("OVERRIDE.DAMAGE", key, ref result, true) && !result)
             {
                 return(false);
             }
             float[] numArray = (extraData != null) ? new float[] { extraData.dataBlock.damageMin, extraData.dataBlock.damageMax } : new float[] { 75f, 75f };
             Config.Get("OVERRIDE.DAMAGE", (damage.bodyPart == BodyPart.Head) ? str4 : str2, ref numArray, true);
             damage.amount = UnityEngine.Random.Range(Math.Min(numArray[0], numArray[1]), Math.Max(numArray[0], numArray[1]));
             if ((extraData != null) && (damage.extraData is BulletWeaponDataBlock))
             {
                 damage.amount *= (damage.extraData as BulletWeaponDataBlock).IsSilenced(extraData.itemRep) ? 0.8f : 1f;
             }
             if ((extraData != null) && (damage.extraData is BulletWeaponImpact))
             {
                 quantity = new DamageTypeList(0f, damage.amount, 0f, 0f, 0f, 0f);
             }
             else
             {
                 quantity = new DamageTypeList(0f, 0f, damage.amount, 0f, 0f, 0f);
             }
             damage.amount = 0f;
             if (quantity.Unit == TakeDamage.Unit.List)
             {
                 ApplyDamageTypeList(take, ref damage, quantity.DamageTypeList);
             }
             Helper.Log(string.Concat(new object[] {
                 "Damage: ", damage.attacker.idMain, "[", damage.attacker.networkViewID, "] from ", str, " hit ", damage.victim.idMain, "[", damage.victim.networkViewID, "] on ", damage.amount, "(", numArray[0], "-", numArray[1],
                 ") pts."
             }), false);
         }
         else if (!(damage.attacker.idMain is Character))
         {
             float baseReturnDmg   = 0f;
             float explosionRadius = 0f;
             if (damage.attacker.id is TimedGrenade)
             {
                 baseReturnDmg   = (damage.attacker.id as TimedGrenade).damage;
                 explosionRadius = (damage.attacker.id as TimedGrenade).explosionRadius;
             }
             if (damage.attacker.id is TimedExplosive)
             {
                 baseReturnDmg   = (damage.attacker.id as TimedExplosive).damage;
                 explosionRadius = (damage.attacker.id as TimedExplosive).explosionRadius;
             }
             if (damage.attacker.id is SpikeWall)
             {
                 baseReturnDmg   = (damage.attacker.id as SpikeWall).baseReturnDmg;
                 explosionRadius = 0f;
             }
             if (baseReturnDmg > 0f)
             {
                 string str5 = damage.attacker.idMain.name.Replace("(Clone)", "") + ".DAMAGE";
                 string str6 = str5 + "." + damage.victim.idMain.name.Replace("(Clone)", "");
                 if (Config.Get("OVERRIDE.DAMAGE", str6, ref result, true) && !result)
                 {
                     return(false);
                 }
                 Config.Get("OVERRIDE.DAMAGE", str5, ref baseReturnDmg, true);
                 if (explosionRadius > 0f)
                 {
                     RaycastHit        hit;
                     bool              flag2;
                     MeshBatchInstance instance;
                     Vector3           center    = damage.victim.idMain.collider.bounds.center;
                     Vector3           a         = damage.attacker.idMain.collider.bounds.center;
                     Vector3           direction = center - a;
                     float             distance  = Vector3.Distance(a, center);
                     if (Facepunch.MeshBatch.MeshBatchPhysics.Raycast(a, direction, out hit, distance, 0x10360401, out flag2, out instance))
                     {
                         IDMain     main = flag2 ? instance.idMain : IDBase.GetMain(hit.collider);
                         GameObject obj2 = (main != null) ? main.gameObject : hit.collider.gameObject;
                         if (obj2 != damage.victim.idMain.gameObject)
                         {
                             damage.amount = (1f - Mathf.Clamp01(distance / explosionRadius)) * baseReturnDmg;
                             if (flag2)
                             {
                                 damage.amount *= 0.1f;
                             }
                         }
                     }
                 }
                 if (damage.attacker.id is SpikeWall)
                 {
                     quantity = new DamageTypeList(0f, 0f, damage.amount, 0f, 0f, 0f);
                 }
                 else
                 {
                     quantity = new DamageTypeList(0f, 0f, 0f, damage.amount, 0f, 0f);
                 }
                 damage.amount = 0f;
                 if (quantity.Unit == TakeDamage.Unit.List)
                 {
                     ApplyDamageTypeList(take, ref damage, quantity.DamageTypeList);
                 }
             }
             Helper.Log(string.Concat(new object[] { "Damage: ", damage.attacker.idMain, "[", damage.attacker.networkViewID, "] owned ", damage.attacker.client, " hit ", damage.victim.idMain, "[", damage.victim.networkViewID, "] on ", damage.amount, "(", baseReturnDmg, ") pts." }), false);
         }
     }
     return(true);
 }