using System; using UILib; using UnityEngine; using XMainClient.UI; using XUtliPoolLib; namespace XMainClient { internal sealed class XMobaBillboardComponent : XComponent { public override uint ID { get { return XMobaBillboardComponent.uuID; } } public new static readonly uint uuID = XSingleton.singleton.XHash("Moba_Billboard"); private XMobaBattleDocument _mobaDoc; private Transform _billboard = null; private IUIDummy _uiDummy = null; private IUIBloodGrid _bloodGrid = null; private IXUIProgress _bloodBar; private IXUIProgress _indureBar; public IXUILabelSymbol _name; public IXUILabel _level; public IXUISprite _exp; public string NameStr = ""; private XBuffMonitorHandler _buffMonitor; private bool InitByMaster = false; private float _heroHeight = 10f; private static float k = 0.007f; private float _viewDistance = 10f; private int _alwaysHide = 0; public static string HPBAR_TEMPLATE = "UI/Billboard/MobaBillboard"; private static readonly string MILITARY_ATLAS = "common/Billboard"; public static readonly string billboardString_red = "[e8280c]"; public static readonly string billboardString_green = "[53d103]"; public static readonly string billboardString_blue = "[0aabd0]"; public static readonly Color billboard_red = new Color32(232, 40, 12, byte.MaxValue); public static readonly Color billboard_green = new Color32(83, 209, 3, byte.MaxValue); public static readonly Color billboard_blue = new Color32(10, 171, 208, byte.MaxValue); private BillboardUsage _secondbar_usage = BillboardUsage.MP; public override void OnAttachToHost(XObject host) { base.OnAttachToHost(host); this._mobaDoc = XDocuments.GetSpecificDocument(XMobaBattleDocument.uuID); GameObject gameObject = XSingleton.singleton.CreateFromPrefab(XMobaBillboardComponent.HPBAR_TEMPLATE, this._entity.EngineObject.Position, this._entity.EngineObject.Rotation, true, false); bool flag = gameObject != null; if (flag) { this._billboard = gameObject.transform; } this._uiDummy = (this._billboard.GetComponent("UIDummy") as IUIDummy); IUIRect parent = XSingleton.singleton.HpbarRoot.UIComponent as IUIRect; XSingleton.singleton.AddChild(parent, gameObject, XSingleton.singleton.HpbarRoot); } protected override void EventSubscribe() { base.RegisterEvent(XEventDefine.XEvent_BillboardShowCtrl, new XComponent.XEventHandler(this.OnShowCtrl)); base.RegisterEvent(XEventDefine.XEvent_BuffChange, new XComponent.XEventHandler(this.OnBuffChange)); } public override void Attached() { base.Attached(); this._bloodBar = (this._billboard.Find("Hpbar").GetComponent("XUIProgress") as IXUIProgress); this._bloodGrid = (this._billboard.Find("Hpbar/BloodGrid").GetComponent("UIBloodGrid") as IUIBloodGrid); this._bloodGrid.SetMAXHP((int)this._entity.Attributes.GetAttr(XAttributeDefine.XAttr_MaxHP_Total)); this._indureBar = (this._billboard.Find("Indure").GetComponent("XUIProgress") as IXUIProgress); this._name = (this._billboard.Find("Name").GetComponent("XUILabelSymbol") as IXUILabelSymbol); this._level = (this._billboard.Find("Level").GetComponent("XUILabel") as IXUILabel); this._exp = (this._level.gameObject.transform.Find("frame").GetComponent("XUISprite") as IXUISprite); GameObject gameObject = this._billboard.transform.Find("BuffFrame").gameObject; DlgHandlerBase.EnsureCreate(ref this._buffMonitor, gameObject, null, true); bool isPlayer = this._entity.IsPlayer; if (isPlayer) { this._bloodBar.SetForegroundColor(XMobaBillboardComponent.billboard_green); } else { bool flag = XSingleton.singleton.IsOpponent(this._entity); if (flag) { this._bloodBar.SetForegroundColor(XMobaBillboardComponent.billboard_red); } else { this._bloodBar.SetForegroundColor(XMobaBillboardComponent.billboard_blue); } } bool isRole = this._entity.IsRole; if (isRole) { uint num = this._entity.IsPlayer ? XSingleton.singleton.XPlayerData.MilitaryRank : (this._entity.Attributes as XRoleAttributes).MilitaryRank; bool flag2 = num == 0u; if (flag2) { this.SetNameStr(this._entity.Attributes.Name); } else { MilitaryRankByExploit.RowData byMilitaryRank = XMilitaryRankDocument._militaryReader.GetByMilitaryRank(num); this.SetNameStr(XLabelSymbolHelper.FormatImage(XMobaBillboardComponent.MILITARY_ATLAS, byMilitaryRank.Icon) + this._entity.Attributes.Name); } } else { this._name.SetVisible(false); } bool flag3 = this._buffMonitor != null; if (flag3) { this._buffMonitor.InitMonitor(XSingleton.singleton.BuffMaxDisplayCountTeam, true, false); } this._heroHeight = this._entity.Height; this._billboard.transform.localScale = Vector3.one * XMobaBillboardComponent.k; this._uiDummy.alpha = 0f; } private void SetNameStr(string str) { this.NameStr = str; this._name.InputText = str; } private void DestroyGameObjects() { bool flag = this._billboard != null; if (flag) { XSingleton.singleton.UnSafeDestroy(this._billboard.gameObject, true, false); this._billboard = null; } } public override void OnDetachFromHost() { this._alwaysHide = 0; this.DestroyGameObjects(); base.OnDetachFromHost(); } private bool OnShowCtrl(XEventArgs e) { XBillboardShowCtrlEventArgs xbillboardShowCtrlEventArgs = e as XBillboardShowCtrlEventArgs; bool flag = xbillboardShowCtrlEventArgs.type == BillBoardHideType.Invalid; bool result; if (flag) { XSingleton.singleton.AddErrorLog("undefine billboard hide type. check code or contect pyc.", null, null, null, null, null); result = false; } else { bool show = xbillboardShowCtrlEventArgs.show; if (show) { this._alwaysHide &= ~(1 << XFastEnumIntEqualityComparer.ToInt(xbillboardShowCtrlEventArgs.type)); } else { this._alwaysHide |= 1 << XFastEnumIntEqualityComparer.ToInt(xbillboardShowCtrlEventArgs.type); } result = true; } return result; } private bool OnBuffChange(XEventArgs args) { XBuffChangeEventArgs xbuffChangeEventArgs = args as XBuffChangeEventArgs; bool isRole = xbuffChangeEventArgs.entity.IsRole; if (isRole) { XBuffComponent buffs = xbuffChangeEventArgs.entity.Buffs; bool flag = buffs != null; if (flag) { this._buffMonitor.OnBuffChanged(buffs.GetUIBuffList()); } } return true; } private void SetBillBoardSameByMaster() { bool flag = XEntity.ValideEntity(this._entity.MobbedBy); if (flag) { XMobaBillboardComponent xmobaBillboardComponent = this._entity.MobbedBy.GetXComponent(XMobaBillboardComponent.uuID) as XMobaBillboardComponent; this._name.SetVisible(true); this._name.InputText = xmobaBillboardComponent.NameStr; this._level.SetText(xmobaBillboardComponent._level.GetText()); } } public override void PostUpdate(float fDeltaT) { XEntity xentity = this._host as XEntity; bool flag = xentity == null; if (!flag) { bool flag2 = !this.InitByMaster && this._entity.MobbedBy != null; if (flag2) { this.InitByMaster = true; XOthersAttributes xothersAttributes = this._entity.Attributes as XOthersAttributes; bool sameBillBoardByMaster = xothersAttributes.SameBillBoardByMaster; if (sameBillBoardByMaster) { this.SetBillBoardSameByMaster(); } } bool flag3 = !XEntity.ValideEntity(xentity); if (flag3) { this._uiDummy.alpha = 0f; } else { bool flag4 = this._alwaysHide != 0; if (flag4) { this._uiDummy.alpha = 0f; } else { XPlayer player = XSingleton.singleton.Player; bool flag5 = player == null || player.EngineObject == null; if (flag5) { this.DestroyGameObjects(); } else { float num = Vector3.Distance(xentity.EngineObject.Position, player.EngineObject.Position); bool flag6 = num > this._viewDistance; if (flag6) { bool flag7 = this._billboard != null; if (flag7) { this._uiDummy.alpha = 0f; return; } } bool flag8 = this._billboard != null; if (flag8) { this.UpdateHpBar(); } } } } } } private void UpdateHpBar() { bool flag = this._uiDummy.alpha == 0f; if (flag) { this._uiDummy.alpha = 1f; } float num = 0.2f; bool flag2 = !this._bloodBar.gameObject.activeSelf; if (flag2) { num -= 0.05f; } bool flag3 = !this._indureBar.gameObject.activeSelf; if (flag3) { num -= 0.05f; } Vector3 position = this._entity.EngineObject.Position; Vector3 position2; position2= new Vector3(position.x, position.y + this._heroHeight + num, position.z); this._billboard.position = position2; this._billboard.rotation = XSingleton.singleton.GameCamera.Rotaton; bool flag4 = XSingleton.singleton.Player != null; if (flag4) { float num2 = 6.27f; float num3 = Vector3.Distance(XSingleton.singleton.GameCamera.UnityCamera.transform.position, this._billboard.position); float num4 = XMobaBillboardComponent.k * num3 / num2; this._billboard.localScale = new Vector3(num4, num4, num4); } bool isRole = this._entity.IsRole; if (isRole) { int num5; float fillAmount; this._mobaDoc.GetRoleLevelAndExp(this._entity.ID, out num5, out fillAmount); this._level.SetText(num5.ToString()); this._exp.SetFillAmount(fillAmount); } double attr = this._entity.Attributes.GetAttr(XAttributeDefine.XAttr_MaxHP_Total); bool flag5 = this._bloodGrid.MAXHP != (int)attr; if (flag5) { this._bloodGrid.SetMAXHP((int)attr); } double num6 = this._entity.Attributes.GetAttr(XAttributeDefine.XAttr_CurrentHP_Basic); bool flag6 = num6 < 0.0; if (flag6) { num6 = 0.0; } this._bloodBar.value = (float)(num6 / attr); bool activeInHierarchy = this._indureBar.gameObject.activeInHierarchy; if (activeInHierarchy) { bool flag7 = this._secondbar_usage == BillboardUsage.MP; if (flag7) { double attr2 = this._entity.Attributes.GetAttr(XAttributeDefine.XAttr_MaxMP_Total); double attr3 = this._entity.Attributes.GetAttr(XAttributeDefine.XAttr_CurrentMP_Basic); bool flag8 = attr3 < attr2; if (flag8) { this._indureBar.value = (float)(attr3 / attr2); } else { this._indureBar.value = 1f; } } } } } }