/// <summary>
        /// 更新 AoiUnitInfo ,当换格时
        /// </summary>
        /// <param name="aoiUnit"></param>
        public static void UpdateAoiUnitInfo(this AoiGridComponent self, AoiUnitComponent aoiUnit)
        {
            // 把新的AOI节点转移到旧的节点里
            aoiUnit.playerIds.OldMovesSet = aoiUnit.playerIds.MovesSet.Select(d => d).ToHashSet();
            aoiUnit.enemyIds.OldMovesSet  = aoiUnit.enemyIds.MovesSet.Select(d => d).ToHashSet();
            aoiUnit.npcerIds.OldMovesSet  = aoiUnit.npcerIds.MovesSet.Select(d => d).ToHashSet();

            //// 移动到新的位置
            self.MoveToChangeAoiGrid(aoiUnit);

            // 查找 周围 可见九宫格内单元 unitId
            self.FindAoi(aoiUnit);

            // 差集计算
            aoiUnit.playerIds.Enters = aoiUnit.playerIds.MovesSet.Except(aoiUnit.playerIds.OldMovesSet).ToHashSet();
            aoiUnit.playerIds.Leaves = aoiUnit.playerIds.OldMovesSet.Except(aoiUnit.playerIds.MovesSet).ToHashSet();
            aoiUnit.enemyIds.Enters  = aoiUnit.enemyIds.MovesSet.Except(aoiUnit.enemyIds.OldMovesSet).ToHashSet();
            aoiUnit.enemyIds.Leaves  = aoiUnit.enemyIds.OldMovesSet.Except(aoiUnit.enemyIds.MovesSet).ToHashSet();
            aoiUnit.npcerIds.Enters  = aoiUnit.npcerIds.MovesSet.Except(aoiUnit.npcerIds.OldMovesSet).ToHashSet();
            aoiUnit.npcerIds.Leaves  = aoiUnit.npcerIds.OldMovesSet.Except(aoiUnit.npcerIds.MovesSet).ToHashSet();

            ///20190715
            AoiPlayerComponent aoiPlayer = aoiUnit.GetParent <Unit>().GetComponent <AoiPlayerComponent>();

            if (aoiPlayer != null)
            {
                aoiPlayer.UpdateAddRemove();
            }

            ///将进入自己视野的人 加进来;将自己加入别的人视野
            aoiUnit.UpdateEnters();

            ///将离开自己视野的人 删除掉;同时将自己从别人的视野里删除
            aoiUnit.UpdateLeaves();
        }
Example #2
0
        /// <summary>
        /// 给客户端 添加 小怪 单元实例
        /// </summary>
        /// <param name="unitIds"></param>
        /// <param name="unit"></param>
        public static void AddMonsters(this AoiPlayerComponent self, long[] unitIds, long[] playerUnitIds)
        {
            /// 广播创建的unit
            M2M_AddUnits m2M_AddUnits = new M2M_AddUnits()
            {
                UnitType = (int)UnitType.Monster, UnitIds = unitIds.ToHashSet(), PlayerUnitIds = playerUnitIds.ToHashSet()
            };

            SessionHelper.MapSession().Send(m2M_AddUnits);

            Console.WriteLine(" AoiPlayerComponentHelper-77-playerId/us/ps: " + self.GetParent <Unit>().Id + " : " + unitIds.Length + " / " + playerUnitIds.Length);
        }
Example #3
0
        public static void UpdateAddRemove(this AoiPlayerComponent self)
        {
            AoiUnitComponent aoiUnit = self.GetParent <Unit>().GetComponent <AoiUnitComponent>();

            if (aoiUnit.playerIds.Enters.Count > 0)
            {
                //ToTo 通知self客户端(1个)  加入这些玩家(多个)
                self.AddPlayers(aoiUnit.playerIds.Enters.ToArray(), new long[1] {
                    self.GetParent <Unit>().Id
                });

                Console.WriteLine(" AoiPlayer-20-玩家:" + aoiUnit.playerIds.Enters.Count + " 个," + " 进入 PlayerId:" + self.GetParent <Unit>().Id + "(" + aoiUnit.gridId + ") 的视野。");
                Console.WriteLine(" AoiPlayer-21-玩家:" + self.GetParent <Unit>().Id + "(" + aoiUnit.gridId + ") 看到玩家:" + aoiUnit.enemyIds.MovesSet.Count);
            }
            if (aoiUnit.enemyIds.Enters.Count > 0)
            {
                //ToTo 通知self客户端(1个)  加入这些小怪(多个)
                self.AddMonsters(aoiUnit.enemyIds.Enters.ToArray(), new long[1] {
                    self.GetParent <Unit>().Id
                });

                Console.WriteLine(" AoiPlayer-28-小怪:" + aoiUnit.enemyIds.Enters.Count + " 个," + " 进入 PlayerId:" + self.GetParent <Unit>().Id + "(" + aoiUnit.gridId + ") 的视野。");
                Console.WriteLine(" AoiPlayer-29-玩家:" + self.GetParent <Unit>().Id + "(" + aoiUnit.gridId + ") 看到小怪:" + aoiUnit.enemyIds.MovesSet.Count);
            }
            if (aoiUnit.playerIds.Leaves.Count > 0)
            {
                //ToTo 通知self客户端(1个)  删除这些玩家(多个)
                self.RemovePlayers(aoiUnit.playerIds.Leaves.ToArray(), new long[1] {
                    self.GetParent <Unit>().Id
                });

                Console.WriteLine(" AoiPlayer-36-玩家:" + aoiUnit.playerIds.Leaves.Count + " 个," + " 离开 PlayerId:" + self.GetParent <Unit>().Id + "(" + aoiUnit.gridId + ") 的视野。");
                Console.WriteLine(" AoiPlayer-37-玩家:" + self.GetParent <Unit>().Id + "(" + aoiUnit.gridId + ") 看到玩家:" + aoiUnit.playerIds.MovesSet.Count);
            }
            if (aoiUnit.enemyIds.Leaves.Count > 0)
            {
                //ToTo 通知self客户端(1个)  删除这些小怪(多个)
                self.RemoveMonsters(aoiUnit.enemyIds.Leaves.ToArray(), new long[1] {
                    self.GetParent <Unit>().Id
                });

                Console.WriteLine(" AoiPlayer-44-小怪:" + aoiUnit.enemyIds.Leaves.Count + " 个," + "离开 PlayerId:" + self.GetParent <Unit>().Id + "(" + aoiUnit.gridId + ") 视野。");
                Console.WriteLine(" AoiPlayer-45-玩家:" + self.GetParent <Unit>().Id + "(" + aoiUnit.gridId + ") 看到小怪:" + aoiUnit.enemyIds.MovesSet.Count);
            }
        }
        /// <summary>
        /// 将离开自己视野的人 删除掉;同时将自己从别人的视野里删除
        /// </summary>
        public static void UpdateLeaves(this AoiUnitComponent self)
        {
            foreach (long tem in self.playerIds.Leaves)
            {
                ///通知 刚进入小怪视野的玩家(多个) 加入这个小怪的Id(1个)
                AoiPlayerComponent temAoiPlayer1 = Game.Scene.GetComponent <UnitComponent>().Get(tem).GetComponent <AoiPlayerComponent>();
                AoiUnitComponent   temAoiUnit1   = Game.Scene.GetComponent <UnitComponent>().Get(tem).GetComponent <AoiUnitComponent>();
                UnitType           unitType      = self.GetParent <Unit>().UnitType;
                switch (unitType)
                {
                case UnitType.Player:
                    temAoiUnit1.playerIds.MovesSet.Remove(self.GetParent <Unit>().Id);
                    temAoiUnit1.playerIds.Leaves.Add(self.GetParent <Unit>().Id);

                    ///ToTo 通知tem客户端(多个) 删除此玩家(1个)
                    temAoiPlayer1.RemovePlayers(new long[1] {
                        self.GetParent <Unit>().Id
                    }, new long[1] {
                        tem
                    });

                    Console.WriteLine(" AoiUnit-86-玩家-Id:" + self.GetParent <Unit>().Id + " 离开 PlayerId:" + tem + "(" + temAoiUnit1.gridId + ") 的视野。");
                    Console.WriteLine(" AoiUnit-87-玩家-Id:" + tem + "(" + temAoiUnit1.gridId + ") 看到玩家:" + temAoiUnit1.playerIds.MovesSet.Count);
                    break;

                case UnitType.Monster:
                    temAoiUnit1.enemyIds.MovesSet.Remove(self.GetParent <Unit>().Id);
                    temAoiUnit1.enemyIds.Leaves.Add(self.GetParent <Unit>().Id);

                    ///ToTo 通知tem客户端(多个) 删除此小怪(1个)
                    temAoiPlayer1.RemoveMonsters(new long[1] {
                        self.GetParent <Unit>().Id
                    }, new long[1] {
                        tem
                    });

                    Console.WriteLine(" AoiUnit-96-小怪-Id:" + self.GetParent <Unit>().Id + " 离开 PlayerId:" + tem + "(" + temAoiUnit1.gridId + ") 的视野。");
                    Console.WriteLine(" AoiUnit-97-玩家-Id:" + tem + "(" + temAoiUnit1.gridId + ") 看到小怪:" + temAoiUnit1.enemyIds.MovesSet.Count);
                    break;
                }
            }

            foreach (long tem in self.enemyIds.Enters)
            {
                ///通知 刚进入本人视野的小怪(多个) 加入本人的Id(1个)
                AoiUnitComponent temAoiUnit0 = Game.Scene.GetComponent <MonsterUnitComponent>().Get(tem).GetComponent <AoiUnitComponent>();
                UnitType         unitType    = self.GetParent <Unit>().UnitType;
                switch (unitType)
                {
                case UnitType.Player:
                    temAoiUnit0.playerIds.MovesSet.Remove(self.GetParent <Unit>().Id);
                    temAoiUnit0.playerIds.Leaves.Add(self.GetParent <Unit>().Id);
                    break;

                case UnitType.Monster:
                    temAoiUnit0.enemyIds.MovesSet.Remove(self.GetParent <Unit>().Id);
                    temAoiUnit0.enemyIds.Leaves.Add(self.GetParent <Unit>().Id);
                    break;
                }
            }
        }
        /// <summary>
        /// 自己死亡后 将自己从别人的视野里删除
        /// </summary>
        public static void DeathRemove(this AoiUnitComponent self)
        {
            long     unitId   = self.GetParent <Unit>().Id;
            UnitType unitType = self.GetParent <Unit>().UnitType;

            switch (unitType)
            {
            case UnitType.Player:
                foreach (long tem in self.playerIds.MovesSet)
                {
                    AoiPlayerComponent temAoiPlayer1 = Game.Scene.GetComponent <UnitComponent>().Get(tem).GetComponent <AoiPlayerComponent>();
                    AoiUnitComponent   temAoiUnit1   = Game.Scene.GetComponent <UnitComponent>().Get(tem).GetComponent <AoiUnitComponent>();

                    ///将自己从别人玩家的视野里删除
                    if (tem != unitId)
                    {
                        temAoiUnit1.playerIds.MovesSet.Remove(unitId);
                    }

                    ///通知tem客户端(多个) 删除此玩家(1个)实例,如果是本客户端则重置此玩家自己实例位置
                    temAoiPlayer1.RemovePlayers(new long[1] {
                        unitId
                    }, new long[1] {
                        tem
                    });

                    Console.WriteLine(" AoiUnit-145-玩家死亡-Id:" + unitId + " 离开 PlayerId:" + tem + "(" + temAoiUnit1.gridId + ") 的视野。");
                }

                foreach (long tem in self.enemyIds.MovesSet)
                {
                    ///将自己 从小怪(多个)的视野里删除
                    AoiUnitComponent temAoiUnit2 = Game.Scene.GetComponent <MonsterUnitComponent>().Get(tem).GetComponent <AoiUnitComponent>();
                    temAoiUnit2.playerIds.MovesSet.Remove(unitId);

                    Console.WriteLine(" AoiUnit-151-玩家死亡-Id:" + unitId + " 离开 MonsterId:" + tem + "(" + temAoiUnit2.gridId + ") 的视野。");
                }

                break;

            case UnitType.Monster:
                foreach (long tem in self.playerIds.MovesSet)
                {
                    AoiPlayerComponent temAoiPlayer1 = Game.Scene.GetComponent <UnitComponent>().Get(tem).GetComponent <AoiPlayerComponent>();
                    AoiUnitComponent   temAoiUnit1   = Game.Scene.GetComponent <UnitComponent>().Get(tem).GetComponent <AoiUnitComponent>();

                    ///将死亡的小怪 从玩家的视野里删除
                    temAoiUnit1.enemyIds.MovesSet.Remove(unitId);

                    ///ToTo 通知tem客户端(多个) 删除此小怪(1个)实例
                    temAoiPlayer1.RemoveMonsters(new long[1] {
                        unitId
                    }, new long[1] {
                        tem
                    });

                    Console.WriteLine(" AoiUnit-165-小怪死亡-Id:" + unitId + " 离开 PlayerId:" + tem + "(" + temAoiUnit1.gridId + ") 的视野。");
                }

                //foreach (long tem in self.enemyIds.MovesSet)
                //{
                //    ///将死亡小怪 从其他小怪(多个)的视野里删除
                //    AoiUnitComponent temAoiUnit2 = Game.Scene.GetComponent<MonsterUnitComponent>().Get(tem).GetComponent<AoiUnitComponent>();
                //    temAoiUnit2.enemyIds.MovesSet.Remove(unitId);
                //}

                break;
            }
        }