少年修仙传客户端代码仓库
client_linchunjie
2019-04-16 6dde220aad8d90ef32128c5de178db8c3d9c3e26
System/HazyRegion/ClientHazyGrassStage.cs
@@ -12,9 +12,10 @@
    static Dictionary<Vector3, GA_NpcClientCollect> s_CollectNpcs = new Dictionary<Vector3, GA_NpcClientCollect>();
    static Dictionary<uint, Vector3> s_Sid2NpcPos = new Dictionary<uint, Vector3>();
    static Dictionary<uint, int> s_Sid2NpcIds = new Dictionary<uint, int>();
    static List<GA_NpcClientFightNorm> s_ClientFightNpcs = new List<GA_NpcClientFightNorm>();
    //static List<GA_NpcClientFightNorm> s_ClientFightNpcs = new List<GA_NpcClientFightNorm>();
    static List<HazyGrassNpcInfo> s_NpcRefreshInfos = new List<HazyGrassNpcInfo>();
    static int grassRefreshCount = 0;
    static Dictionary<int, int> s_NpcRefreshTimes = new Dictionary<int, int>();
    bool mapLoadFinish = false;
    bool initedFightNpc = false;
@@ -31,16 +32,20 @@
        s_NpcInfos.Clear();
        s_Sid2NpcIds.Clear();
        s_Sid2NpcPos.Clear();
        s_NpcRefreshTimes.Clear();
        mapLoadFinish = false;
        initedFightNpc = false;
        grassRefreshCount = 0;
        var config = HazyRegionConfig.Get(hazyRegionModel.processingIncidentId);
        if (config != null)
        {
            incidentType = (HazyRegionIncidentType)config.incidentType;
            s_NpcRefreshInfos = model.GetGrassNpcInfos(config.dungeonId);
            foreach (var npcInfo in s_NpcRefreshInfos)
            {
                s_NpcRefreshTimes.Add(npcInfo.npcId, GetNpcRefreshCount(npcInfo));
            }
        }
        UnloadAllNpc();
@@ -53,7 +58,6 @@
        base.OnStageLoadFinish();
        mapLoadFinish = true;
        model.RefreshGrassBornTime(TimeUtility.ServerNow);
        InitialPlayer();
        InitializeNpc();
@@ -67,12 +71,15 @@
        if (mapLoadFinish)
        {
            var used = Mathf.Max(0, (int)(TimeUtility.ServerNow - model.grassBornTime).TotalSeconds);
            var count = used / model.grassRefreshSeconds;
            if (count != grassRefreshCount)
            foreach (var npcInfo in s_NpcRefreshInfos)
            {
                RebornCollectedNpc();
                grassRefreshCount = count;
                var _lastCount = s_NpcRefreshTimes[npcInfo.npcId];
                var count = GetNpcRefreshCount(npcInfo);
                if (_lastCount != count)
                {
                    RebornCollectedNpc(npcInfo.npcId);
                    s_NpcRefreshTimes[npcInfo.npcId] = count;
                }
            }
        }
    }
@@ -86,12 +93,24 @@
        GA_NpcClientCollect.OnCollectFinished -= OnCollectFinished;
    }
    int GetNpcRefreshCount(HazyGrassNpcInfo npcInfo)
    {
        var used = TimeUtility.Minute * 60 + TimeUtility.Second;
        var refreshSeconds = npcInfo.refreshMinute * 60;
        return used / refreshSeconds;
    }
    private void OnCollectFinished(uint _sid)
    {
        if (s_Sid2NpcIds.ContainsKey(_sid))
        {
            var npcId = s_Sid2NpcIds[_sid];
            Debug.Log("采集了Npc:--" + npcId);
            var pak = new CA234_tagCMGetCustomSceneCollectAward();
            pak.NPCID = (uint)npcId;
            GameNetSystem.Instance.SendInfo(pak);
            s_Sid2NpcIds.Remove(_sid);
        }
        if (s_Sid2NpcPos.ContainsKey(_sid))
@@ -102,6 +121,8 @@
                s_CollectNpcs.Remove(pos);
            }
        }
        RefreshMapNpcCount();
    }
    void InitializeNpc()
@@ -131,10 +152,14 @@
        CameraController.Instance.Apply();
    }
    void RebornCollectedNpc()
    void RebornCollectedNpc(int npcId = 0)
    {
        foreach (var npcInfo in s_NpcInfos)
        {
            if (npcId != 0 && npcInfo.npcId != npcId)
            {
                continue;
            }
            switch (npcInfo.npcType)
            {
                case E_NpcType.Collect:
@@ -155,20 +180,38 @@
                    }
                    break;
                case E_NpcType.Fight:
                    if (!initedFightNpc)
                    {
                        var fightNpc = GAMgr.Instance.ReqClntFightNpc<GA_NpcClientFightNorm>((uint)npcInfo.npcId,
                             E_ActorGroup.Enemy);
                        if (fightNpc != null)
                        {
                            fightNpc.Pos = npcInfo.position;
                            fightNpc.OnAttacked -= OnAttackNpc;
                            fightNpc.OnAttacked += OnAttackNpc;
                        }
                        s_ClientFightNpcs.Add(fightNpc);
                    }
                    //if (!initedFightNpc)
                    //{
                    //    var fightNpc = GAMgr.Instance.ReqClntFightNpc<GA_NpcClientFightNorm>((uint)npcInfo.npcId,
                    //         E_ActorGroup.Enemy);
                    //    if (fightNpc != null)
                    //    {
                    //        fightNpc.Pos = npcInfo.position;
                    //        fightNpc.OnAttacked -= OnAttackNpc;
                    //        fightNpc.OnAttacked += OnAttackNpc;
                    //    }
                    //    s_ClientFightNpcs.Add(fightNpc);
                    //}
                    break;
            }
        }
        RefreshMapNpcCount();
    }
    void RefreshMapNpcCount()
    {
        foreach (var npcInfo in s_NpcRefreshInfos)
        {
            var count = 0;
            foreach (var npcId in s_Sid2NpcIds.Values)
            {
                if (npcId == npcInfo.npcId)
                {
                    count++;
                }
            }
            model.RefreshMapNpcCount(npcInfo.npcId, count);
        }
    }
@@ -190,18 +233,18 @@
            }
        }
        foreach (var _npc in s_ClientFightNpcs)
        {
            if (_npc != null)
            {
                _npc.OnAttacked -= OnAttackNpc;
                _npc.ActorInfo.serverDie = true;
                GAMgr.Instance.ServerDie(_npc.ServerInstID);
                GAMgr.Instance.Release(_npc);
            }
        }
        s_ClientFightNpcs.Clear();
        //foreach (var _npc in s_ClientFightNpcs)
        //{
        //    if (_npc != null)
        //    {
        //        _npc.OnAttacked -= OnAttackNpc;
        //        _npc.ActorInfo.serverDie = true;
        //        GAMgr.Instance.ServerDie(_npc.ServerInstID);
        //        GAMgr.Instance.Release(_npc);
        //    }
        //}
        //
        //s_ClientFightNpcs.Clear();
        s_CollectNpcs.Clear();
    }