少年修仙传客户端代码仓库
client_linchunjie
2019-07-17 04003d73510672e5609a67df6f5ffcb827e31d9c
8135 子 【开发】【主干】仙草园自动采集 / 【开发】【前端】仙草园自动采集
1个文件已修改
84 ■■■■■ 已修改文件
System/HazyRegion/ClientHazyGrassStage.cs 84 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/HazyRegion/ClientHazyGrassStage.cs
@@ -19,6 +19,8 @@
    bool hasInitializedNpc = false;
    public bool hasCompleted { get; private set; }
    static Clock s_CollectClock = null;
    static Dictionary<uint, GA_NpcClientCollect> s_CollectNpcs = new Dictionary<uint, GA_NpcClientCollect>();
    static Dictionary<uint, int> s_Sid2NpcIds = new Dictionary<uint, int>();
    static Dictionary<uint, int> s_Sid2NpcIndexs = new Dictionary<uint, int>();
@@ -31,6 +33,7 @@
    HazyGrassModel model { get { return ModelCenter.Instance.GetModel<HazyGrassModel>(); } }
    HazyRegionModel hazyRegionModel { get { return ModelCenter.Instance.GetModel<HazyRegionModel>(); } }
    DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
    PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
    public override void Initialize()
    {
@@ -59,7 +62,8 @@
        InitialPlayer();
        InitializeNpc();
        TryGotoCloserNpc();
        var npcId = TryGetScarceNpc();
        TryGotoCloserNpc(npcId);
        model.onMapNpcCountRefresh += OnMapNpcCountRefresh;
    }
@@ -67,6 +71,13 @@
    public override void UnInitialize()
    {
        base.UnInitialize();
        if (s_CollectClock != null)
        {
            Clock.Stop(s_CollectClock);
            s_CollectClock = null;
        }
        UnloadAllNpc();
@@ -81,7 +92,8 @@
        {
            InitializeNpc();
            TryGotoCloserNpc();
            var npcId = TryGetScarceNpc();
            TryGotoCloserNpc(npcId);
        }
    }
@@ -125,6 +137,14 @@
            s_CollectNpcs.Remove(_sid);
        }
        if (s_CollectClock != null)
        {
            Clock.Stop(s_CollectClock);
            s_CollectClock = null;
        }
        s_CollectClock = Clock.AlarmAfter(0.5f, () =>
        {
        var dungeon = ClientDungeonStageUtility.dungeonInfo;
        var hintId = dungeonModel.GetDungeonHintId(dungeon.mapId, dungeon.lineId);
        var dungeonHintConfig = DungeonHintConfig.Get(hintId);
@@ -140,10 +160,12 @@
            {
                if (collectCount < dungeonHintConfig.targetValue1[0] - 1)
                {
                    TryGotoCloserNpc();
                        var npcId = TryGetScarceNpc();
                        TryGotoCloserNpc(npcId);
                }
            }
        }
        });
    }
    void InitialPlayer()
@@ -157,7 +179,11 @@
        }
    }
    void TryGotoCloserNpc()
    /// <summary>
    ///
    /// </summary>
    /// <param name="npcId">指定NpcId</param>
    void TryGotoCloserNpc(int npcId = 0)
    {
        var hero = PlayerDatas.Instance.hero;
        if (hero == null)
@@ -176,6 +202,10 @@
        foreach (var npc in s_CollectNpcs.Values)
        {
            if (npcId != 0 && npc.NpcConfig.NPCID != npcId)
            {
                continue;
            }
            var dis = MathUtility.CalDistance(hero.Pos, npc.Pos);
            if (minDis > dis)
            {
@@ -192,6 +222,49 @@
        }
    }
    int TryGetScarceNpc()
    {
        if (ClientDungeonStageUtility.clientMapId == HazyGrassModel.REIKI_CLIENTDATAMAP)
        {
            return 0;
        }
        List<int> npcIds = new List<int>();
        var dungeon = ClientDungeonStageUtility.dungeonInfo;
        var hintId = dungeonModel.GetDungeonHintId(dungeon.mapId, dungeon.lineId);
        var dungeonHintConfig = DungeonHintConfig.Get(hintId);
        if (dungeonHintConfig != null)
        {
            npcIds.AddRange(dungeonHintConfig.NPC1ID);
        }
        if (npcIds.Count > 0)
        {
            npcIds.Sort((lhs, rhs) =>
            {
                var lhs_item = model.GetGrassNpcItemId(lhs);
                var rhs_item = model.GetGrassNpcItemId(rhs);
                var lhs_npcCount = model.GetMapNpcCount(lhs);
                var rhs_npcCount = model.GetMapNpcCount(rhs);
                var lhs_empty = lhs_npcCount == 0;
                var rhs_empty = rhs_npcCount == 0;
                if (lhs_empty != rhs_empty)
                {
                    return lhs_empty.CompareTo(rhs_empty);
                }
                var lhs_itemCount = packModel.GetItemCountByID(PackType.Item, lhs_item);
                var rhs_itemCount = packModel.GetItemCountByID(PackType.Item, rhs_item);
                if (lhs_itemCount != rhs_itemCount)
                {
                    return lhs_itemCount.CompareTo(rhs_itemCount);
                }
                return lhs_item.CompareTo(rhs_item);
            });
            return npcIds[0];
        }
        return 0;
    }
    private void OnHeroFindStop()
    {
        var hero = PlayerDatas.Instance.hero;
@@ -201,8 +274,6 @@
        }
        hero.OnPathFindStop -= OnHeroFindStop;
        if (ClientDungeonStageUtility.clientMapId == HazyGrassModel.REIKI_CLIENTDATAMAP)
        {
            if (PlayerDatas.Instance.baseData.LV >= model.autoCollectLevel)
            {
                if (autoNpc != null)
@@ -214,7 +285,6 @@
                    {
                        hero.SelectTarget = autoNpc;
                        ClientCollectUtility.HandleCallback(E_NpcType.Collect, autoNpc.NpcConfig.NPCID, autoNpc.ServerInstID);
                    }
                }
            }
        }