LogException() public static method

public static LogException ( Exception Ex, UnityEngine Context = null ) : void
Ex System.Exception
Context UnityEngine
return void
Beispiel #1
0
        public static void On_CombatEntityHurt(BaseCombatEntity combatEnt, HitInfo info, bool useProtection = true)
        {
            try {
                Assert.Test(combatEnt.isServer, "This should be called serverside only");
                if (combatEnt.IsDead())
                {
                    return;
                }
                using (TimeWarning.New("Hurt", 50)) {
                    BaseNPC    npc    = combatEnt.GetComponent <BaseNPC>();
                    BaseCorpse corpse = combatEnt.GetComponent <BaseCorpse>();
                    BasePlayer player = combatEnt.GetComponent <BasePlayer>();

                    combatEnt.ScaleDamage(info, useProtection);

                    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);
                        OnNext("On_PlayerHurt", he);
                    }
                    else if (npc != null)
                    {
                        he = new NPCHurtEvent(new NPC(npc), info);
                        OnNext("On_NPCHurt", he);
                    }
                    else if (corpse != null)
                    {
                        he = new CorpseHurtEvent(corpse, info);
                        OnNext("On_CorpseHurt", he);
                    }
                    else
                    {
                        he = new CombatEntityHurtEvent(combatEnt, info);
                        OnNext("On_CombatEntityHurt", he);
                    }

                    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);
                                }
                            }
                        }
                    }

                    // 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
                        });
                    }

                    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;
                    combatEnt.SetFieldValue("_lastAttackedTime", Time.time);
                    if (combatEnt.health <= 0f)
                    {
                        combatEnt.Die(info);
                        BuildingBlock bb = combatEnt.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);
            }
        }
Beispiel #2
0
        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 (ConsoleGlobal.developer > 1)
                        {
                            Debug.Log("BaseProtection Scaling for entity :" + combatEnt.name);
                        }
                    }
                }
                else
                {
                    if (ConsoleGlobal.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 (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
                    });
                }

                combatEnt.health -= info.damageTypes.Total();
                if (ConsoleGlobal.developer > 1)
                {
                    Debug.Log("[Combat]".PadRight(10) +
                              combatEnt.gameObject.name + " hurt " +
                              info.damageTypes.GetMajorityDamageType() + "/" +
                              info.damageTypes.Total() + " - " +
                              combatEnt.health.ToString("0") + " health left"
                              );
                }
                combatEnt.lastDamage = info.damageTypes.GetMajorityDamageType();
                if (combatEnt.health <= 0)
                {
                    combatEnt.Die(info);
                }
            } catch (Exception ex) {
                Logger.LogError("[Hooks] Error in CombatEntityHurt hook.");
                Logger.LogException(ex);
            }
        }