Parcourir la source

增加根据vip等级显示不同颜色名字的功能

大爷 il y a 1 an
Parent
commit
a79839a52c

+ 2 - 0
Unity/Assets/Scripts/Codes/Hotfix/Client/battle/BattleMgr.cs

@@ -36,6 +36,8 @@ namespace ET
         public void InitBattleLayer()
         {
             BattleFuncHandler.BattleCenterIndex = 0;
+            TiktokGiftPushHandler.Reset();
+
             Layer = TemplateManager.Factory.CreateClientZoneLayer(BattleResourceMgr.Instance.GameEditorTemplates, this);
             Layer.ActorSyncMode = SyncMode.ForceByServer;
 

+ 41 - 13
Unity/Assets/Scripts/Codes/Hotfix/Client/battle/GameServer/TiktokPushHandler.cs

@@ -1,4 +1,5 @@
 
+using CommonLang;
 using ET.EventType;
 
 namespace ET.Client
@@ -16,29 +17,56 @@ namespace ET.Client
     [MessageHandler(SceneType.Client)]
     public class TiktokGiftPushHandler : AMHandler<G2C_GiftInfoPush>
     {
+        public static HashMap<int, int> map = new();
+        public static void Reset()
+        {
+            map.Clear();
+        }
         protected override async ETTask Run(Session session, G2C_GiftInfoPush a)
         {
             EventSystem.Instance.Publish(TiktokGiftEvent.Clone(a.GiftType, a.GiftNum, a.NickName, a.Url));
 
-            var unit = UnitMgr.Instance.GetUnit((uint)a.UnitId);
-            if (unit != null && unit is BattleUnit bu)
+            int vip = 0;
+            for (int i = GameSetting.VipMoney.Length - 1; i >= 0; i--)
+            {
+                if (GameSetting.VipMoney[i] <= a.TotalMoney)
+                {
+                    //花了钱,就可以显示大名
+                    vip = i + 1;
+                    EventSystem.Instance.Publish(ShowVipName.Clone((uint)a.UnitId, i + 1));
+
+                    break;
+                }
+            }
+
+            if (vip > 0)
             {
-                for (int i = GameSetting.VipMoney.Length - 1; i >= 0; i--)
+                var unit = UnitMgr.Instance.GetUnit((uint)a.UnitId);
+                if (unit != null && unit is BattleUnit bu)
                 {
-                    if (GameSetting.VipMoney[i] <= a.TotalMoney)
-                    {
-                        //花了钱,就可以显示大名
-                        bu.Vip = i + 1;
-                        EventSystem.Instance.Publish(ShowVipName.Clone((uint)a.UnitId, i + 1));
+                    bu.Vip = vip;
+                }
 
-                        break;
-                    }
+                if (map.TryGetValue(a.UnitId, out _))
+                {
+                    map.Remove(a.UnitId);
                 }
+                map.Add(a.UnitId, vip);
             }
-            else
+            await ETTask.CompletedTask;
+        }
+    }
+
+    [Event]
+    public class NewUnitVipHandler : BEvent<EventType.OnNewZoneObject>
+    {
+        protected override async ETTask OnEvent(EventType.OnNewZoneObject args)
+        {
+            var obj = UnitMgr.Instance.GetUnit(args.ObjectId);
+            if (obj != null && TiktokGiftPushHandler.map.TryGetValue((int)args.ObjectId, out int vip) && obj is BattleUnit bu)
             {
-                Log.Warning("gift unit is null");
-                return;
+                bu.Vip = vip;
+                TiktokGiftPushHandler.map.Remove((int)args.ObjectId);
             }
             await ETTask.CompletedTask;
         }

+ 11 - 4
Unity/Assets/Scripts/Codes/Hotfix/Client/battle/unit/BattleUnit.cs

@@ -44,6 +44,11 @@ public class BattleUnit : BattleObject
         zu.OnRemoveBuffByOverlayLevel += (ZoneUnit unit, ZoneUnit.BuffState buff) => { };
         zu.OnActionSubStatusChanged += OnActionSubStatusChanged;
     }
+    public override void OnSleep()
+    {
+        base.OnSleep();
+        Vip = 0;
+    }
 
     private static uint groupId = 1;
     protected static uint GroupId()
@@ -179,12 +184,12 @@ public class BattleUnit : BattleObject
             }
             else if(unit.TemplateID == ZUnit.TemplateID)
             {
-                if(hp <= 0)
+                /*if(hp <= 0)
                 {
                     hide = i;
                     EventSystem.Instance.Publish(HPRefresh.Clone(HPRefresh.Index.Boss1 + pgList.Count - 1, 0, "", "", false));
                 }
-                else
+                else*/
                 {
                     EventSystem.Instance.Publish(HPRefresh.Clone(HPRefresh.Index.Boss1 + i, hp * 100f / ZUnit.MaxHP, prop.ServerData.BaseInfo.name, hp.ToString()));
                     return;
@@ -242,7 +247,7 @@ public class BattleUnit : BattleObject
         });
         actionChangeHandler.AddListener(UnitActionStatus.HitMove, stun);
         actionChangeHandler.AddListener(UnitActionStatus.Dead, (o) => {
-            //OnHPChanged();
+            EventSystem.Instance.Publish(UnitDead.Clone(Id));
         });
         actionChangeHandler.AddListener(UnitActionStatus.Damage, (o) => { });
         actionChangeHandler.AddListener(UnitActionStatus.Pick, (o) => { });
@@ -260,7 +265,9 @@ public class BattleUnit : BattleObject
         actionChangeHandler.AddListener(UnitActionStatus.BreakShield, (o) => { });
         actionChangeHandler.AddListener(UnitActionStatus.Transport, (o) => { });
         actionChangeHandler.AddListener(UnitActionStatus.Skill, (o) => { });
-        actionChangeHandler.AddListener(UnitActionStatus.Rebirth, (o) => { });
+        actionChangeHandler.AddListener(UnitActionStatus.Rebirth, (o) => {
+            EventSystem.Instance.Publish(UnitRebirth.Clone(Id));
+        });
     }
 
 }

+ 3 - 0
Unity/Assets/Scripts/Codes/HotfixView/Client/UI/HUD/CreateHUD.cs

@@ -118,6 +118,9 @@ namespace ET.Client
                 case HPRefresh.Index.TiktokLike:
                     progress = HUDComonent.pgTKLike;
                     break;
+                default:
+                    Log.Error($"unkown hp bar: {a.HPIndex}");
+                    return;
             }
                 
             progress.visible = a.Visible;

+ 1 - 0
Unity/Assets/Scripts/Codes/HotfixView/Client/UI/OnNetClosedUI.cs

@@ -13,6 +13,7 @@ public class NetClosedEventHandler : BEvent<NetClosed>
             GlobalViewMgr.Instance.ReOpenGame();
             UnitMgr.Instance.RecycleUnits();
             BattleMgr.Instance.InitBattleLayer();
+            BattleUnit.Reset();
         }, null);
     }
 }

+ 29 - 1
Unity/Assets/Scripts/Codes/HotfixView/Client/Unit/UnitRenderSystem.cs

@@ -77,7 +77,7 @@ namespace ET.Client
         {
             await ETTask.CompletedTask;
             var unitRender = ModelViewComponent.Instance.GetChild<UnitRenderComponet>(args.ObjId);
-            if (unitRender != null)
+            if (unitRender != null && unitRender.NameBar != null)
             {
                 unitRender.NameBar.visible = true;
                 unitRender.Vip = args.Vip;
@@ -86,6 +86,34 @@ namespace ET.Client
         }
     }
     [Event]
+    [FriendOfAttribute(typeof(ET.Client.UnitRenderComponet))]
+    public class UnitDeadEventHandler : BEvent<UnitDead>
+    {
+        protected override async ETTask OnEvent(UnitDead args)
+        {
+            var unitRender = ModelViewComponent.Instance.GetChild<UnitRenderComponet>(args.ObjId);
+            if (unitRender != null && unitRender.NameBar != null && unitRender.NameBar.visible)
+            {
+                unitRender.NameBar.color = new Color(0xcc / 255, 0xcc / 255, 0xcc / 255, 1);
+            }
+            await ETTask.CompletedTask;
+        }
+    }
+    [Event]
+    [FriendOfAttribute(typeof(ET.Client.UnitRenderComponet))]
+    public class UnitRebirthEventHandler : BEvent<UnitRebirth>
+    {
+        protected override async ETTask OnEvent(UnitRebirth args)
+        {
+            var unitRender = ModelViewComponent.Instance.GetChild<UnitRenderComponet>(args.ObjId);
+            if (unitRender != null && unitRender.NameBar != null && unitRender.NameBar.visible)
+            {
+                unitRender.NameBar.color = GameSetting.VipColor[unitRender.Vip];
+            }
+            await ETTask.CompletedTask;
+        }
+    }
+    [Event]
     public class SyncUnitPosEventHandler : BEvent<EventType.SyncUnitPosEvent>
     {
         protected override async ETTask OnEvent(SyncUnitPosEvent args)

+ 20 - 0
Unity/Assets/Scripts/Codes/Model/Client/EventTypeClient.cs

@@ -362,6 +362,26 @@ namespace ET
                 return Static;
             }
         }
+        public class UnitDead
+        {
+            public uint ObjId;
+            public static UnitDead Static = new();
+            public static UnitDead Clone(uint objId)
+            {
+                Static.ObjId = objId;
+                return Static;
+            }
+        }
+        public class UnitRebirth
+        {
+            public uint ObjId;
+            public static UnitRebirth Static = new();
+            public static UnitRebirth Clone(uint objId)
+            {
+                Static.ObjId = objId;
+                return Static;
+            }
+        }
 
         public class ReOpenGame { }
         public class NetClosed { }