using UnityEngine.Scripting; [Preserve] public class XUiC_TargetBarRebirth : XUiController { private float lastValue; private float deltaTime; private float noTargetFadeTime; private float noTargetFadeTimeMax = 0.1f; private XUiC_TargetBarRebirth.EVisibility visibility; private string defaultBossIcon = "ui_game_symbol_twitch_boss_bar_default"; private GameEventManager gameEventManager; private BossGroup CurrentBossGroup; private readonly CachedStringFormatterInt statcurrentFormatterInt = new CachedStringFormatterInt(); private readonly CachedStringFormatter statcurrentWMaxFormatterAOfB = new CachedStringFormatter((Func)((_i, _i1) => string.Format("{0}/{1}", (object)_i, (object)_i1))); private readonly CachedStringFormatterFloat statfillFormatter = new CachedStringFormatterFloat(); public EntityAlive Target { get; set; } public override void Init() { base.Init(); this.IsDirty = true; this.viewComponent.IsVisible = false; } public override void Update(float _dt) { base.Update(_dt); if (Target is EntityZombieSDX) { if (Target.HasAnyTags(FastTags.Parse("invisible"))) { //Log.Out("====================INVISIBLE===================="); this.Target = null; this.viewComponent.IsVisible = false; return; } } this.deltaTime = _dt; if (this.gameEventManager == null) this.gameEventManager = GameEventManager.Current; if (!this.xui.playerUI.entityPlayer.IsAlive()) { this.viewComponent.IsVisible = false; } else { if (this.gameEventManager.CurrentBossGroup != null) { this.CurrentBossGroup = this.gameEventManager.CurrentBossGroup; this.Target = this.CurrentBossGroup.BossEntity; bool flag = false; if (this.Target != null && this.Target.IsAlive()) flag = true; if (this.CurrentBossGroup.MinionCount != 0) flag = true; if (flag) { this.viewComponent.IsVisible = true; this.noTargetFadeTime = 0.0f; } else if ((double)this.noTargetFadeTime >= (double)this.noTargetFadeTimeMax) { this.Target = null; this.viewComponent.IsVisible = false; this.CurrentBossGroup.BossEntity = null; } else this.noTargetFadeTime += Time.deltaTime; } else { if (this.CurrentBossGroup != null) { this.Target = null; this.CurrentBossGroup = null; } if (this.visibility == XUiC_TargetBarRebirth.EVisibility.Never) { this.viewComponent.IsVisible = false; return; } if (this.visibility == XUiC_TargetBarRebirth.EVisibility.GodMode && !this.xui.playerUI.entityPlayer.IsGodMode.Value) { if (RebirthVariables.customTargetBarVisibility == "none") { this.viewComponent.IsVisible = false; return; } } bool flag = false; WorldRayHitInfo hitInfo = this.xui.playerUI.entityPlayer.HitInfo; if (hitInfo.bHitValid && (bool)hitInfo.transform && hitInfo.tag.StartsWith("E_", StringComparison.Ordinal)) { Transform hitRootTransform = GameUtils.GetHitRootTransform(hitInfo.tag, hitInfo.transform); EntityAlive entityAlive = null; if (hitRootTransform != null) entityAlive = hitRootTransform.GetComponent(); if (entityAlive != null && entityAlive.IsAlive()) { flag = true; this.Target = entityAlive; } } if (this.Target == null) { this.viewComponent.IsVisible = false; this.noTargetFadeTime = this.noTargetFadeTimeMax; return; } else { //Log.Out("XUiC_TargetBarRebirth-Update tags: " + this.Target.EntityTags); bool canSeeTarget = true; if (RebirthVariables.customTargetBarVisibility == "default") { canSeeTarget = RebirthUtilities.CanSeeTargetHealth(this.xui.playerUI.entityPlayer, this.Target); bool randomNames = RebirthUtilities.GetPropertyValue("AdvancedNPCFeatures", "UseRandomNames") == "true"; if (randomNames) { canSeeTarget = true; } if (!canSeeTarget) { bool shouldAttack = RebirthUtilities.VerifyFactionStanding(this.xui.playerUI.entityPlayer, this.Target); if (this.Target.HasAnyTags(FastTags.Parse("npc")) && !shouldAttack) { } else { this.viewComponent.IsVisible = false; return; } } } } if (flag) { this.viewComponent.IsVisible = true; this.noTargetFadeTime = 0.0f; } else if ((double)this.noTargetFadeTime >= (double)this.noTargetFadeTimeMax) { this.Target = null; this.viewComponent.IsVisible = false; } else this.noTargetFadeTime += Time.deltaTime; if (this.Target != null && (this.Target.IsDead() || this.Target.Health == 0)) { this.Target = null; this.viewComponent.IsVisible = false; this.noTargetFadeTime = this.noTargetFadeTimeMax; } } this.RefreshBindings(this.IsDirty); this.IsDirty = false; } } public override bool GetBindingValue(ref string value, string bindingName) { switch (bindingName) { case "posY": if (RebirthVariables.customScenario == "purge" && RebirthVariables.purgeDisplay) { if (RebirthUtilities.IsHordeNight()) { value = "-150"; } else { value = "-135"; } return true; } if (RebirthUtilities.IsHordeNight()) { value = "-100"; } else { value = "-85"; } return true; case "boss_sprite": if (this.gameEventManager == null || this.CurrentBossGroup == null) { value = ""; return true; } value = this.CurrentBossGroup.BossIcon == "" ? this.defaultBossIcon : this.CurrentBossGroup.BossIcon; return true; case "current": if (this.Target == null) { value = ""; return true; } value = this.statcurrentFormatterInt.Format(this.Target.Health); return true; case "currentwithmax": if (this.Target == null) { value = ""; return true; } int health = (int)this.Target.Stats.Health.Value; if (this.Target is EntityVehicleRebirth) { health = (int)this.Target.Health; } value = this.statcurrentWMaxFormatterAOfB.Format(this.Target.IsAlive() ? health : 0, (int)this.Target.Stats.Health.Max); return true; case "fill": if (this.Target == null) { value = "0"; return true; } float b = (float)this.Target.Health / (float)this.Target.GetMaxHealth(); float _v1 = Math.Max(this.lastValue, 0.0f) * 1.01f; value = this.statfillFormatter.Format(_v1); this.lastValue = Mathf.Lerp(this.lastValue, b, this.deltaTime * 3f); return true; case "randNamesColor": value = RebirthUtilities.GetPropertyValue("AdvancedNPCFeatures", "RandomNamesColor"); if (this.Target != null && this.Target.HasAnyTags(FastTags.Parse("boss"))) { value = RebirthUtilities.GetPropertyValue("AdvancedNPCFeatures", "BossNameColor"); } return true; case "israndomnames": value = "false"; //Log.Out("XUiC_TargetBarRebirth-Update IS RANDOM NAMES"); if (RebirthUtilities.GetPropertyValue("AdvancedNPCFeatures", "UseRandomNames") == "true") { bool canSeeTarget = RebirthUtilities.CanSeeTargetHealth(this.xui.playerUI.entityPlayer, this.Target); //Log.Out("XUiC_TargetBarRebirth-Update IS RANDOM NAMES, canSeeTarget: " + canSeeTarget); if (!canSeeTarget) { value = "true"; } } return true; case "isboss": if (this.gameEventManager == null) { value = "false"; return true; } value = (this.CurrentBossGroup != null).ToString(); return true; case "isnotboss": if (this.gameEventManager == null) { value = "false"; return true; } value = (this.CurrentBossGroup == null).ToString(); //Log.Out("XUiC_TargetBarRebirth-Update IS NOT BOSS"); if (RebirthUtilities.GetPropertyValue("AdvancedNPCFeatures", "UseRandomNames") == "true") { bool canSeeTarget = RebirthUtilities.CanSeeTargetHealth(this.xui.playerUI.entityPlayer, this.Target); //Log.Out("XUiC_TargetBarRebirth-Update IS NOT BOSS, canSeeTarget: " + canSeeTarget); if (!canSeeTarget) { value = "false"; } } return true; case "minioncount": if (this.gameEventManager == null || this.CurrentBossGroup == null) { value = ""; return true; } value = this.CurrentBossGroup.MinionCount.ToString(); return true; case "name": if (this.Target == null) { value = ""; } else { EntityPlayer target = this.Target as EntityPlayer; if (this.Target is EntityPlayer || this.Target is EntityNPCRebirth || this.Target is EntityAnimalChickenRebirth ) { value = this.Target.EntityName; //Log.Out("XUiC_TargetBarRebirthRebirth-GetBindingValue this.Target.EntityTags: " + this.Target.EntityTags); } else { value = Localization.Get(EntityClass.list[this.Target.entityClass].entityClassName); } bool showEntityName = false; string useRandomNames = RebirthUtilities.GetPropertyValue("AdvancedNPCFeatures", "UseRandomNames"); if (useRandomNames.ToLower() == "true") { bool excludeTags = this.Target.EntityTags.Test_AnySet(FastTags.Parse(RebirthUtilities.GetPropertyValue("AdvancedNPCFeatures", "UseRandomNamesTagsExclude"))); bool group1Names = this.Target.EntityTags.Test_AnySet(FastTags.Parse(RebirthUtilities.GetPropertyValue("AdvancedNPCFeatures", "UseRandomNamesGroup1Tags"))); bool group2Names = this.Target.EntityTags.Test_AnySet(FastTags.Parse(RebirthUtilities.GetPropertyValue("AdvancedNPCFeatures", "UseRandomNamesGroup2Tags"))); bool group3Names = this.Target.EntityTags.Test_AnySet(FastTags.Parse(RebirthUtilities.GetPropertyValue("AdvancedNPCFeatures", "UseRandomNamesGroup3Tags"))); bool group4Names = this.Target.EntityTags.Test_AnySet(FastTags.Parse(RebirthUtilities.GetPropertyValue("AdvancedNPCFeatures", "UseRandomNamesGroup4Tags"))); bool groupNPC1Names = this.Target.EntityTags.Test_AnySet(FastTags.Parse(RebirthUtilities.GetPropertyValue("AdvancedNPCFeatures", "UseRandomNamesGroupNPC1Tags"))); bool groupNPC2Names = this.Target.EntityTags.Test_AnySet(FastTags.Parse(RebirthUtilities.GetPropertyValue("AdvancedNPCFeatures", "UseRandomNamesGroupNPC2Tags"))); bool groupNPC3Names = this.Target.EntityTags.Test_AnySet(FastTags.Parse(RebirthUtilities.GetPropertyValue("AdvancedNPCFeatures", "UseRandomNamesGroupNPC3Tags"))); bool groupNPC4Names = this.Target.EntityTags.Test_AnySet(FastTags.Parse(RebirthUtilities.GetPropertyValue("AdvancedNPCFeatures", "UseRandomNamesGroupNPC4Tags"))); //Log.Out("XUiC_TargetBarRebirthRebirth-GetBindingValue excludeTags: " + excludeTags); //Log.Out("XUiC_TargetBarRebirthRebirth-GetBindingValue group1Names: " + group1Names); //Log.Out("XUiC_TargetBarRebirthRebirth-GetBindingValue group2Names: " + group2Names); //Log.Out("XUiC_TargetBarRebirthRebirth-GetBindingValue group3Names: " + group3Names); //Log.Out("XUiC_TargetBarRebirthRebirth-GetBindingValue group4Names: " + group4Names); if (!excludeTags && (group1Names || group2Names || group3Names || group4Names || groupNPC1Names || groupNPC2Names || groupNPC3Names || groupNPC4Names) ) { //Log.Out("XUiC_TargetBarRebirthRebirth-GetBindingValue 1"); showEntityName = true; } if (this.Target is EntityNPCRebirth || this.Target is EntityAnimalChickenRebirth || showEntityName || this.Target is EntityZombieSDX) { //Log.Out("XUiC_TargetBarRebirthRebirth-GetBindingValue this.Target.EntityName: " + this.Target.EntityName); value = this.Target.EntityName; } } else { return true; } } return true; default: return false; } } public override bool ParseAttribute(string _name, string _value, XUiController _parent) { if (!(_name == "visibility")) { if (!(_name == "default_boss_icon")) return base.ParseAttribute(_name, _value, _parent); this.defaultBossIcon = _value; return true; } this.visibility = EnumUtils.Parse(_value, true); return true; } public enum EVisibility { Never, GodMode, Always, Boss, } }