private void OnEntityDeath(BaseCombatEntity entity, HitInfo info) { if (entity == null) { return; } if (animalList.Contains(entity)) { AnimalController baseNpc = entity.GetComponent <AnimalController>(); if (baseNpc != null) { baseNpc.naturalDeath = true; timer.In(configData.Settings.Respawn, () => SpawnAnimalEntity(baseNpc.prefabName, baseNpc.homePos)); UnityEngine.Object.Destroy(entity.GetComponent <AnimalController>()); } HumanController npcPlayer = entity.GetComponent <HumanController>(); if (npcPlayer != null) { npcPlayer.naturalDeath = true; timer.In(configData.Settings.Respawn, () => SpawnNpcEntity(npcPlayer.prefabName, npcPlayer.homePos)); UnityEngine.Object.Destroy(entity.GetComponent <HumanController>()); } animalList.Remove(entity); } }
private void OnEntityDeath(BaseCombatEntity victim, HitInfo info) { var prefabname = victim.name; var crate = victim?.GetComponent <LockedByEntCrate>() ?? null; if (crate != null && lockedCrates.Contains(crate)) { lockedCrates.Remove(crate); } if (prefabname.Contains("servergibs_bradley")) { var debris = victim?.GetComponent <HelicopterDebris>() ?? null; if (debris != null && gibs.Contains(debris)) { gibs.Remove(debris); } } if (prefabname.Contains("bradleyapc")) { var bradley = victim?.GetComponent <BradleyAPC>() ?? null; if (bradley != null && bradleys.Contains(bradley)) { bradleys.Remove(bradley); } lastBradleyDeath = Time.realtimeSinceStartup; } }
void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info) { if (entity == null) { return; } if (info == null) { return; } BasePlayer attacker = null; attacker = info?.Initiator?.ToPlayer(); if (attacker) { if (usePermissions) { if (permission.UserHasPermission(attacker.UserIDString, "nobowraid.bypass")) { return; } } if (attacker.IsAdmin() && adminBypass) { return; } string weapon = info.Weapon.name.ToString(); if (weapon.Contains("bow_hunting.entity") || weapon.Contains("crossbow.entity")) { BuildingBlock block = null; if (entity.GetComponent <BuildingBlock>() != null) { block = entity.GetComponent <BuildingBlock>(); } if (!whitelist.Any(entity.name.Contains) && !block) { info.damageTypes.ScaleAll(damageScale); } if (block) { if (block.grade.ToString().Equals("Twigs") && ignoreTwig) { return; } info.damageTypes.ScaleAll(damageScale); } } } }
private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info) { if (entity == null || info == null) { return; } if (entity.GetComponent <CarController>()) { entity.GetComponent <CarController>().ManageDamage(info); } }
void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo) { if (usingCS && hasStarted && entity != null && !isEnding) { var attacker = hitInfo.InitiatorPlayer; if (attacker == null) { return; } var helicopter = entity.GetComponent <CSHelicopter>(); if (helicopter != null && !attacker.GetComponent <CSPlayer>()) { hitInfo.damageTypes = new DamageTypeList(); hitInfo.HitEntity = null; hitInfo.HitMaterial = 0; hitInfo.PointStart = Vector3.zero; return; } if (attacker.GetComponent <CSPlayer>()) { if (entity is BasePlayer) { if (entity.ToPlayer() == null || hitInfo == null) { return; } if (entity.ToPlayer().userID != hitInfo.Initiator.ToPlayer().userID) { if (entity.GetComponent <CSPlayer>()) { hitInfo.damageTypes.ScaleAll(configData.PlayerSettings.FFDamageScale); SendReply(attacker, MSG("fFire")); } } } if (helicopter != null) { int points = entity.GetComponent <CSHelicopter>().TakeDamage(hitInfo); RefreshHealthUI(helicopter); hitInfo.damageTypes = new DamageTypeList(); hitInfo.HitEntity = null; hitInfo.HitMaterial = 0; hitInfo.PointStart = Vector3.zero; attacker.GetComponent <CSPlayer>().points += points; } } } }
void OnEntityDeath(BaseCombatEntity entity, HitInfo info) { try { if (entity.GetComponent <BaseNpc>() != null) { if (animalCache.Contains(entity as BaseEntity)) { UnityEngine.Object.Destroy(entity.GetComponent <NPCController>()); InitiateRefresh(entity as BaseEntity); } } } catch { } }
private void HandleRemoval(BaseCombatEntity entity) { var buildingBlock = entity?.GetComponent <BuildingBlock>() ?? null; if (buildingBlock == null) { return; } var blockName = buildingBlock.PrefabName; if (blockName == null || blockName != foundation && blockName != triFoundation) { return; } if (buildingIds.ContainsKey(buildingBlock.buildingID)) { var blockList = buildingIds[buildingBlock.buildingID].Where(b => b == buildingBlock).ToList(); foreach (var block in blockList) { buildingIds[buildingBlock.buildingID].Remove(buildingBlock); } } }
void OnStructureDemolish(BaseCombatEntity entity, BasePlayer player) { var buildingBlock = entity?.GetComponent <BuildingBlock>() ?? null; if (buildingBlock == null || buildingBlock.Equals(null)) { return; } else { if (buildingBlock.name == Foundation || buildingBlock.name == TriangleFoundation) { if (buildingids.ContainsKey(buildingBlock.buildingID)) { foreach (BuildingBlock Block in buildingids[buildingBlock.buildingID]) { if (buildingBlock == Block) { buildingids[buildingBlock.buildingID].Remove(buildingBlock); break; } } } } } }
void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo) { if (entity == null || hitInfo == null || hitInfo?.Initiator == null) { return; } var attacker = hitInfo?.Initiator?.GetComponent <BasePlayer>() ?? null; var victim = entity?.GetComponent <BasePlayer>() ?? null; if (attacker != null) { if ((bool)Config["UseGlobalDamageScaler"]) { hitInfo.damageTypes.ScaleAll(float.Parse(Config["GlobalDamageScaler"].ToString())); return; } if ((bool)Config["PlayersOnly"] && victim != null) { ScaleDealtDamage(hitInfo); } else { ScaleDealtDamage(hitInfo); } } }
void OnEntityDeath(BaseCombatEntity entity, HitInfo info) { if (!Economics) { return; } if (!entity.GetComponent("BaseNPC")) { return; } if (!info.Initiator?.ToPlayer()) { return; } var player = info.Initiator?.ToPlayer(); var animal = UppercaseFirst(entity.ShortPrefabName.Replace(".prefab", "")); int amount; if (!config.Settings.Rewards.TryGetValue(animal, out amount) || amount <= 0) { return; } Economics.CallHook("Deposit", player.userID, amount); if (config.Settings.ShowMessages) { PrintToChat(player, string.Format(config.Messages[PluginMessage.ReceivedForKill], amount, animal.ToLower())); } }
bool?OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo) { if (entity != null && hitInfo != null) { JDeployable.Child c = entity?.GetComponent <JDeployable.Child>(); if (c != null && c.parent != null) { if (true) // if nodecay { hitInfo.damageTypes.Scale(Rust.DamageType.Decay, 0f); // no decay damage } float damage = hitInfo.damageTypes.Total(); if (damage > 0) { float newhealth = entity.health - damage; if (newhealth > 0f) { c.parent.SetHealth(newhealth); } else { KillDeployable(c.parent); } } return(true); } } return(null); }
private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitinfo) { if (usingCTF && hasStarted) { if (entity is Signage && entity.GetComponent <CTFFlag>()) { hitinfo.damageTypes = new DamageTypeList(); hitinfo.DoHitEffects = false; return; } if (entity is BasePlayer && hitinfo?.Initiator is BasePlayer) { var victim = entity?.GetComponent <CTFPlayer>(); var attacker = hitinfo?.Initiator?.GetComponent <CTFPlayer>(); if (victim != null && attacker != null && victim.player.userID != attacker.player.userID) { if (victim.team == attacker.team) { if (configData.GameSettings.FFDamageModifier <= 0) { hitinfo.damageTypes = new DamageTypeList(); hitinfo.DoHitEffects = false; } else { hitinfo.damageTypes.ScaleAll(configData.GameSettings.FFDamageModifier); } SendReply(attacker.player, "Friendly Fire!"); } } } } }
void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo) { if (entity is BaseNPC) { entity.GetComponent <NpcAI>()?.OnAttacked(hitInfo); } }
private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitinfo) { if (UseTDM && Started) { if (entity is BasePlayer && hitinfo?.Initiator is BasePlayer) { var victim = entity.GetComponent <TDMPlayer>(); var attacker = hitinfo.Initiator.GetComponent <TDMPlayer>(); if (victim != null && attacker != null && victim.player.userID != attacker.player.userID) { if (victim.team == attacker.team) { if (configData.FF_Damage_Modifier <= 0) { hitinfo.damageTypes = new DamageTypeList(); hitinfo.DoHitEffects = false; } else { hitinfo.damageTypes.ScaleAll(configData.FF_Damage_Modifier); } SendReply(attacker.player, TitleM() + lang.GetMessage("ff", this, attacker.player.UserIDString)); } } } } }
private object CanBeTargeted(BaseCombatEntity target, MonoBehaviour turret) { if (target is BasePlayer) { var isInvisible = Vanish?.Call("IsInvisible", target); if (isInvisible != null && (bool)isInvisible) { return(null); } var isStealthed = Skills?.Call("isStealthed", target); if (isStealthed != null && (bool)isStealthed) { return(null); } } if (!(turret is AutoTurret)) { return(null); } if (animalOverride == true && target.GetComponent <BaseNPC>() != null) { if (animals.Count > 0) { if (animals.Contains(target.ShortPrefabName.Replace(".prefab", "").ToLower())) { return(false); } else { return(null); } } else { return(false); } } if (target.ToPlayer() == null) { return(null); } BasePlayer targetPlayer = target.ToPlayer(); if (adminOverride && targetPlayer.IsConnected() && targetPlayer.net.connection.authLevel > 0) { return(false); } else if (sleepOverride && targetPlayer.IsSleeping()) { return(false); } return(null); }
void OnStructureRepair(BaseCombatEntity entity, BasePlayer player) { JDeployable.Child c = entity?.GetComponent <JDeployable.Child>(); if (c != null && c.parent != null && player != null) { NextTick(() => c.parent.OnStructureRepair(entity, player)); } }
bool?CanPickupEntity(BaseCombatEntity entity, BasePlayer player) { JDeployable.Child c = entity?.GetComponent <JDeployable.Child>(); if (c != null && c.parent != null && player != null) { return(c.parent.CanPickupEntity(c, player)); } return(null); }
bool?OnStructureUpgrade(BaseCombatEntity entity, BasePlayer player, BuildingGrade.Enum grade) { JDeployable.Child c = entity?.GetComponent <JDeployable.Child>(); if (c != null && c.parent != null && player != null) { return(c.parent.OnStructureUpgrade(c, player, grade)); } return(null); }
public CombatEntityHurtEvent(BaseCombatEntity combatEnt, HitInfo info) : base(info) { var block = combatEnt.GetComponent<BuildingBlock>(); if (block != null) Victim = new BuildingPart(block); else Victim = new Entity(combatEnt); }
static bool Decay(BaseCombatEntity entity, float amount) { entity.health -= amount; entity.SendNetworkUpdate(); if (!(entity.health <= 0f)) { return(true); } entity.GetComponent <BaseEntity>().KillMessage(); return(false); }
private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info) { if (entity == null || info == null) { return; } if (entity.GetComponent <CarController>()) { entity.GetComponent <CarController>().ManageDamage(info); } else if (entity.GetComponent <CarController.InvisibleMount>()) { NullifyDamage(info); } else if (entity.GetComponent <StorageContainer>() && entity.GetParentEntity()?.GetComponent <CarController>()) { NullifyDamage(info); } }
private void DieInstantly(BaseCombatEntity entity) { if (!entity.IsDestroyed) { Effect.server.Run(heliExplosion, entity.transform.position, Vector3.up, null, true); OnChopperDeath(entity.GetComponent <CSHelicopter>()); entity.health = 0f; entity.lifestate = BaseCombatEntity.LifeState.Dead; entity.Kill(BaseNetworkable.DestroyMode.None); } }
void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo) { if (entity is BaseNPC) { NpcAI ai = entity.GetComponent <NpcAI>(); if (ai != null) { ai.OnAttacked(hitInfo); } } }
private void OnEntityDeath(BaseCombatEntity entity, HitInfo info) { if (entity == null || info == null) { ItemPlacement placement = entity.GetComponent <ItemPlacement>(); if (placement != null) { placement.OnPlayerDeath(); } } }
private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo) { if (entity == null || hitInfo == null) { return; } if (entity is BaseNpc) { entity.GetComponent <NpcAI>()?.OnAttacked(hitInfo); } }
object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hit) { if (entity == null || hit == null) { return(null); } object externalResult = Interface.CallHook("CanEntityTakeDamage", new object[] { entity, hit }); if (externalResult != null) { if ((bool)externalResult == false) { return(false); } return(null); } if (hit.damageTypes.Has(Rust.DamageType.Decay)) { return(Decay.AlterDecayDamage(entity, hit)); } User attacker = null; User defender = entity.GetComponent <User>(); if (hit.InitiatorPlayer != null) { attacker = hit.InitiatorPlayer.GetComponent <User>(); } // A player is being injured by something other than a player/NPC. if (attacker == null && defender != null) { return(Pvp.HandleIncidentalDamage(defender, hit)); } // One player is damaging another player. if (attacker != null && defender != null) { return(Pvp.HandleDamageBetweenPlayers(attacker, defender, hit)); } // A player is damaging a structure. if (attacker != null && defender == null) { return(Raiding.HandleDamageAgainstStructure(attacker, entity, hit)); } // A structure is taking damage from something that isn't a player. return(Raiding.HandleIncidentalDamage(entity, hit)); }
private void OnEntityDeath(BaseCombatEntity entity, HitInfo hitInfo) { if (entity == null || hitInfo == null) { return; } if (entity is BaseNpc) { entity.GetComponent <NpcAI>()?.OnDeath(); } }
void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo) { if (isCurrent && Active && entity != null) { if (entity.GetComponent <CS_Helicopter>() && hitInfo.Initiator != null && hitInfo.Initiator is BasePlayer && !hitInfo.Initiator.GetComponent <CS_Player>()) { hitInfo.damageTypes = new DamageTypeList(); return; } if (hitInfo.Initiator != null && hitInfo.Initiator is BasePlayer && hitInfo.Initiator.GetComponent <CS_Player>()) { var attacker = hitInfo.Initiator as BasePlayer; if (entity is BasePlayer) { if (entity.ToPlayer() == null || hitInfo == null) { return; } if (entity.ToPlayer().userID != hitInfo.Initiator.ToPlayer().userID) { if (entity.GetComponent <CS_Player>()) { hitInfo.damageTypes.ScaleAll(config.PlayerSettings.FFDamageScale); MessagePlayer(attacker, "", MSG("fFire")); } } } if (entity.GetComponent <CS_Helicopter>()) { int points = entity.GetComponent <CS_Helicopter>().DealDamage(hitInfo); RefreshHealthUI(entity.GetComponent <CS_Helicopter>()); hitInfo.damageTypes = new DamageTypeList(); hitInfo.HitMaterial = 0; hitInfo.PointStart = Vector3.zero; attacker.GetComponent <CS_Player>().points += points; } } } }
public CombatEntityHurtEvent(BaseCombatEntity combatEnt, HitInfo info) : base(info) { var block = combatEnt.GetComponent <BuildingBlock>(); if (block != null) { Victim = new BuildingPart(block); } else { Victim = new Entity(combatEnt); } }
void OnAnimalDeath(BaseCombatEntity entity, HitInfo hitinfo) { if (hitinfo == null) { return; } if (hitinfo.Initiator == null) { return; } if (hitinfo.Initiator.ToPlayer() == null) { return; } if (entity.GetComponent <BaseNPC>() == null) { return; } BasePlayer player = hitinfo.Initiator.ToPlayer(); string animalName = entity.GetComponent <BaseNPC>().corpseEntity.Substring(12).Split('_')[0].ToLower(); hasPlayerFinishedQuest_KillAnimal(player, animalName); }
private object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info) { if (!ignoreProjectiles) { return(null); } BaseTrap trap = entity.GetComponent <BaseTrap>(); if (!trap) { return(null); } if (!info.IsProjectile()) { return(null); } BearTrap bearTrap = entity.GetComponent <BearTrap>(); if (bearTrap) { bearTrap.Arm(); } return(true); }
void OnEntityTakeDamage(BaseCombatEntity entity, ref HitInfo hit) { if (entity is BuildingBlock) { // Building being attacked? Which one? EventBlock event_block = entity.GetComponent<EventBlock>(); if (event_block != null) { hit.damageTypes = new Rust.DamageTypeList(); hit.HitMaterial = 0; hit.PointStart = Vector3.zero; } } if (entity.GetComponent<EventPlayerTeleporting>() != null) { hit.damageTypes = new Rust.DamageTypeList(); hit.HitMaterial = 0; hit.PointStart = Vector3.zero; entity.GetComponent<BasePlayer>().metabolism.bleeding.Reset(); } if (!EventLobby && eventPlayers.Count > 0 && entity is BasePlayer) { if (entity is BasePlayer && hit.Initiator is BasePlayer && hit.Initiator.GetComponent<EventPlayer>() != null) { OnAttackShared(hit.Initiator as BasePlayer, entity as BasePlayer, ref hit); } else if (entity is BasePlayer && !(hit.Initiator is BasePlayer) && entity.GetComponent<EventPlayer>() != null) { hit.damageTypes = new Rust.DamageTypeList(); hit.HitMaterial = 0; hit.PointStart = Vector3.zero; entity.GetComponent<BasePlayer>().metabolism.bleeding.Reset(); } } }
///////////////////////////////////////// // OnEntityAttacked(BaseCombatEntity entity, HitInfo hitinfo) // Called when any entity is attacked ///////////////////////////////////////// private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitinfo) { if (entity == null) return; var resource = entity.GetComponent<ResourceDispenser>(); if (resource != null) { } else if (entity is BasePlayer) { var player = (BasePlayer)entity; if (player.IsSleeping() && HasPlayerFlag(player, ZoneFlags.SleepGod)) { CancelDamage(hitinfo); } else if (hitinfo.Initiator is BasePlayer) { if (((BasePlayer)hitinfo.Initiator).userID < 76560000000000000L) return; if (HasPlayerFlag(player, ZoneFlags.PvpGod)) CancelDamage(hitinfo); else if (HasPlayerFlag((BasePlayer)hitinfo.Initiator, ZoneFlags.PvpGod)) CancelDamage(hitinfo); } else if (HasPlayerFlag(player, ZoneFlags.PveGod)) CancelDamage(hitinfo); } else if (entity is BaseNPC) { var npcai = (BaseNPC)entity; HashSet<Zone> zones; if (!npcZones.TryGetValue(npcai, out zones)) return; foreach (var zone in zones) { if (HasZoneFlag(zone, ZoneFlags.NoPve)) { CancelDamage(hitinfo); break; } } } else if (!(entity is LootContainer) && !(entity is BaseHelicopter)) { HashSet<Zone> zones; if (!buildingZones.TryGetValue(entity, out zones)) return; foreach (var zone in zones) { if (HasZoneFlag(zone, ZoneFlags.UnDestr)) { CancelDamage(hitinfo); break; } } } else { HashSet<Zone> zones; if (otherZones.TryGetValue(entity, out zones)) { } } }
///////////////////////////////////////// // OnEntityDeath(BaseNetworkable basenet) // Called when any entity dies ///////////////////////////////////////// private void OnEntityDeath(BaseCombatEntity entity, HitInfo hitinfo) { if (entity == null) return; var resource = entity.GetComponent<ResourceDispenser>(); if (resource != null) { HashSet<Zone> zones; if (resourceZones.TryGetValue(resource, out zones)) { foreach (var zone in zones) zone.OnEntityDeath(entity); resourceZones.Remove(resource); } } else if (entity is BasePlayer) { var player = (BasePlayer) entity; HashSet<Zone> zones; if (playerZones.TryGetValue(player, out zones)) { foreach (var zone in zones) zone.OnEntityDeath(entity); zones.Clear(); UpdateFlags(player); } } else if (entity is BaseNPC) { HashSet<Zone> zones; if (npcZones.TryGetValue((BaseNPC)entity, out zones)) { foreach (var zone in zones) zone.OnEntityDeath(entity); npcZones.Remove((BaseNPC)entity); } } else if (!(entity is LootContainer) && !(entity is BaseHelicopter)) { HashSet<Zone> zones; if (buildingZones.TryGetValue(entity, out zones)) { foreach (var zone in zones) zone.OnEntityDeath(entity); buildingZones.Remove(entity); } } else { HashSet<Zone> zones; if (otherZones.TryGetValue(entity, out zones)) { foreach (var zone in zones) zone.OnEntityDeath(entity); otherZones.Remove(entity); } } }
/// <summary> /// Called from <c>BaseCombatEntity.Hurt(HitInfo)</c> . /// </summary> public static void On_CombatEntityHurt(BaseCombatEntity combatEntity, HitInfo info) { try { Assert.Test(combatEntity.isServer, "This should be called serverside only"); if (combatEntity.IsDead()) return; using (TimeWarning.New("Hurt", 50)) { BaseNPC baseNPC = combatEntity.GetComponent<BaseNPC>(); BaseCorpse baseCorpse = combatEntity.GetComponent<BaseCorpse>(); BasePlayer basePlayer = combatEntity.GetComponent<BasePlayer>(); combatEntity.ScaleDamage(info); if (basePlayer != null) { Player player = Server.GetPlayer(basePlayer); if (player.Teleporting) { for (int i = 0; i < info.damageTypes.types.Length; i++) { info.damageTypes.types[i] = 0f; } } HurtEvent he = new PlayerHurtEvent(player, info); OnNext("On_PlayerHurt", he); } else if (baseNPC != null) { HurtEvent he = new NPCHurtEvent(new NPC(baseNPC), info); OnNext("On_NPCHurt", he); } else if (baseCorpse != null) { HurtEvent he = new CorpseHurtEvent(baseCorpse, info); OnNext("On_CorpseHurt", he); } else { HurtEvent he = new CombatEntityHurtEvent(combatEntity, info); OnNext("On_CombatEntityHurt", he); } if (info.PointStart != Vector3.zero) { DirectionProperties[] directionProperties = (DirectionProperties[])combatEntity.GetFieldValue("propDirection"); for (int i = 0; i < directionProperties.Length; i++) { if (!(directionProperties[i].extraProtection == null)) { if (directionProperties[i].IsWeakspot(combatEntity.transform, info)) { directionProperties[i].extraProtection.Scale(info.damageTypes); } } } } // the DebugHurt() method if (ConVar.Vis.attack) { if (info.PointStart != info.PointEnd) { ConsoleNetwork.BroadcastToAllClients("ddraw.arrow", new object[] { 60, UnityEngine.Color.cyan, info.PointStart, info.PointEnd, 0.1 }); ConsoleNetwork.BroadcastToAllClients("ddraw.sphere", new object[] { 60, UnityEngine.Color.cyan, info.HitPositionWorld, 0.05 }); } string text = String.Empty; for (int i = 0; i < info.damageTypes.types.Length; i++) { float num = info.damageTypes.types[i]; if (num != 0) { string text2 = text; text = String.Concat(new string[] { text2, " ", ((global::Rust.DamageType)i).ToString().PadRight(10), num.ToString("0.00"), "\r\n" }); } } string text3 = String.Concat(new object[] { "<color=lightblue>Damage:</color>".PadRight(10), info.damageTypes.Total().ToString("0.00"), "\r\n<color=lightblue>Health:</color>".PadRight(10), combatEntity.health.ToString("0.00"), " / ", (combatEntity.health - info.damageTypes.Total() > 0) ? "<color=green>" : "<color=red>", (combatEntity.health - info.damageTypes.Total()).ToString("0.00"), "</color>", "\r\n<color=lightblue>Hit Ent:</color>".PadRight(10), combatEntity, "\r\n<color=lightblue>Attacker:</color>".PadRight(10), info.Initiator, "\r\n<color=lightblue>Weapon:</color>".PadRight(10), info.Weapon, "\r\n<color=lightblue>Damages:</color>\r\n", text }); ConsoleNetwork.BroadcastToAllClients("ddraw.text", new object[] { 60, UnityEngine.Color.white, info.HitPositionWorld, text3 }); } combatEntity.health -= info.damageTypes.Total(); combatEntity.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); if (ConVar.Global.developer > 1) { Debug.Log(string.Concat(new object[] { "[Combat]".PadRight(10), combatEntity.gameObject.name, " hurt ", info.damageTypes.GetMajorityDamageType(), "/", info.damageTypes.Total(), " - ", combatEntity.health.ToString("0"), " health left" })); } combatEntity.lastDamage = info.damageTypes.GetMajorityDamageType(); combatEntity.lastAttacker = info.Initiator; BaseCombatEntity baseCombatEntity = combatEntity.lastAttacker as BaseCombatEntity; if (baseCombatEntity != null) baseCombatEntity.MarkHostileTime(); combatEntity.SetFieldValue("_lastAttackedTime", Time.time); if (combatEntity.health <= 0f) { combatEntity.Die(info); BuildingBlock bb = combatEntity.GetComponent<BuildingBlock>(); if (bb != null) { OnNext("On_BuildingPartDestroyed", new BuildingPartDestroyedEvent(bb, info)); } } } } catch (Exception ex) { Logger.LogError("[Hooks] Error in CombatEntityHurt hook."); Logger.LogException(ex); } }
public void OnEntityDeath(BaseCombatEntity entity) { if (entity == null) return; var resource = entity.GetComponent<ResourceDispenser>(); if (resource != null) Resource.Remove(resource); else if (entity is BasePlayer) Player.Remove((BasePlayer) entity); else if (entity is BaseNPC) Npc.Remove((BaseNPC)entity); else if (!(entity is LootContainer) && !(entity is BaseHelicopter) && !(entity is BaseCorpse)) Building.Remove(entity); else Other.Remove(entity); }
public static void CombatEntityHurt(BaseCombatEntity combatEnt, HitInfo info) { try { Assert.Test(combatEnt.isServer, "This should be called serverside only"); if (combatEnt.IsDead()) { return; } BaseNPC npc = combatEnt.GetComponent<BaseNPC>(); BaseCorpse corpse = combatEnt.GetComponent<BaseCorpse>(); BasePlayer player = combatEnt.GetComponent<BasePlayer>(); if (!SkinnedMeshCollider.ScaleDamage(info)) { if (combatEnt.baseProtection != null) { combatEnt.baseProtection.Scale(info.damageTypes); if (ConVar.Global.developer > 1) { Debug.Log("BaseProtection Scaling for entity :" + combatEnt.name); } } } else if (ConVar.Global.developer > 1) { Debug.Log("SMC scaling damage for entity :" + combatEnt.name); } HurtEvent he; if (player != null) { Player p = Server.GetPlayer(player); if (p.Teleporting) { for (int i = 0; i < info.damageTypes.types.Length; i++) { info.damageTypes.types[i] = 0f; } } he = new PlayerHurtEvent(p, info); OnPlayerHurt.OnNext(he as PlayerHurtEvent); } else if (npc != null) { he = new NPCHurtEvent(new NPC(npc), info); OnNPCHurt.OnNext(he as NPCHurtEvent); } else if (corpse != null) { he = new CorpseHurtEvent(corpse, info); OnCorpseHurt.OnNext(he as CorpseHurtEvent); } else { he = new CombatEntityHurtEvent(combatEnt, info); OnCombatEntityHurt.OnNext(he as CombatEntityHurtEvent); } // the DebugHurt() method if (ConVar.Vis.attack) { if (info.PointStart != info.PointEnd) { ConsoleSystem.Broadcast("ddraw.arrow", new object[] { 60, Color.cyan, info.PointStart, info.PointEnd, 0.1 }); ConsoleSystem.Broadcast("ddraw.sphere", new object[] { 60, Color.cyan, info.HitPositionWorld, 0.05 }); } string text = String.Empty; for (int i = 0; i < info.damageTypes.types.Length; i++) { float num = info.damageTypes.types[i]; if (num != 0) { string text2 = text; text = String.Concat(new string[] { text2, " ", ((Rust.DamageType)i).ToString().PadRight(10), num.ToString("0.00"), "\r\n" }); } } string text3 = String.Concat(new object[] { "<color=lightblue>Damage:</color>".PadRight(10), info.damageTypes.Total().ToString("0.00"), "\r\n<color=lightblue>Health:</color>".PadRight(10), combatEnt.health.ToString("0.00"), " / ", (combatEnt.health - info.damageTypes.Total() > 0) ? "<color=green>" : "<color=red>", (combatEnt.health - info.damageTypes.Total()).ToString("0.00"), "</color>", "\r\n<color=lightblue>Hit Ent:</color>".PadRight(10), combatEnt, "\r\n<color=lightblue>Attacker:</color>".PadRight(10), info.Initiator, "\r\n<color=lightblue>Weapon:</color>".PadRight(10), info.Weapon, "\r\n<color=lightblue>Damages:</color>\r\n", text }); ConsoleSystem.Broadcast("ddraw.text", new object[] { 60, Color.white, info.HitPositionWorld, text3 }); } if (combatEnt.skeletonProperties) { combatEnt.skeletonProperties.ScaleDamage(info); } if (info.PointStart != Vector3.zero) { DirectionProperties[] directionProperties = (DirectionProperties[])combatEnt.GetFieldValue("propDirection"); for (int i = 0; i < directionProperties.Length; i++) { if (!(directionProperties[i].extraProtection == null)) { if (directionProperties[i].IsPointWithinRadius(combatEnt.transform, info.PointStart)) { directionProperties[i].extraProtection.Scale(info.damageTypes); } } } } combatEnt.health -= info.damageTypes.Total(); combatEnt.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); if (ConVar.Global.developer > 1) { Debug.Log(string.Concat(new object[] { "[Combat]".PadRight(10), combatEnt.gameObject.name, " hurt ", info.damageTypes.GetMajorityDamageType(), "/", info.damageTypes.Total(), " - ", combatEnt.health.ToString("0"), " health left" })); } combatEnt.lastDamage = info.damageTypes.GetMajorityDamageType(); combatEnt.lastAttacker = info.Initiator; if (combatEnt.health <= 0f) { combatEnt.Die(info); BuildingBlock bb = combatEnt.GetComponent<BuildingBlock>(); if (bb != null) { OnBuildingPartDestroyed.OnNext(new BuildingPartDestroyedEvent(bb, info)); } } } catch (Exception ex) { Logger.LogError("[Hooks] Error in CombatEntityHurt hook."); Logger.LogException(ex); } }