Example #1
0
        public List <PhysicsObj> GetVisibleObjectsDist(ObjCell cell, VisibleObjectType type)
        {
            rwLock.EnterReadLock();
            try
            {
                var visibleObjs = GetVisibleObjects(cell, type);

                var dist = new List <PhysicsObj>();
                foreach (var obj in visibleObjs)
                {
                    var distSq = PhysicsObj.Position.Distance2DSquared(obj.Position);

                    if (distSq <= InitialClamp_DistSq)
                    {
                        dist.Add(obj);
                    }
                }

                return(dist);
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }
Example #2
0
        /// <summary>
        /// Returns a list of objects that are currently visible from a cell
        /// </summary>
        public List <PhysicsObj> GetVisibleObjects(ObjCell cell, VisibleObjectType type = VisibleObjectType.All)
        {
            rwLock.EnterReadLock();
            try
            {
                if (PhysicsObj.CurLandblock == null || cell == null)
                {
                    return(new List <PhysicsObj>());
                }

                // use PVS / VisibleCells for EnvCells not seen outside
                // (mostly dungeons, also some large indoor areas ie. caves)
                if (cell is EnvCell envCell && !envCell.SeenOutside)
                {
                    return(GetVisibleObjects(envCell, type));
                }

                // use current landblock + adjacents for outdoors,
                // and envcells seen from outside (all buildings)
                var visibleObjs = PhysicsObj.CurLandblock.GetServerObjects(true);

                return(ApplyFilter(visibleObjs, type).Where(i => i.ID != PhysicsObj.ID && (!(i.CurCell is EnvCell indoors) || indoors.SeenOutside)).ToList());
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }
Example #3
0
        private IEnumerable <PhysicsObj> ApplyFilter(List <PhysicsObj> objs, VisibleObjectType type)
        {
            IEnumerable <PhysicsObj> results = objs;

            if (type == VisibleObjectType.Players)
            {
                results = objs.Where(i => i.IsPlayer);
            }
            else if (type == VisibleObjectType.AttackTargets)
            {
                if (PhysicsObj.WeenieObj.IsCombatPet)
                {
                    results = objs.Where(i => i.WeenieObj.IsMonster);
                }
                else if (PhysicsObj.WeenieObj.IsFactionMob)
                {
                    results = objs.Where(i => i.IsPlayer || i.WeenieObj.IsCombatPet || i.WeenieObj.IsMonster && !i.WeenieObj.SameFaction(PhysicsObj));
                }
                else
                {
                    // adding faction mobs here, even though they are retaliate-only, for inverse visible targets
                    results = objs.Where(i => i.IsPlayer || i.WeenieObj.IsCombatPet || i.WeenieObj.IsFactionMob);
                }
            }
            return(results);
        }
Example #4
0
        /// <summary>
        /// Returns a list of objects that are currently visible from a dungeon cell
        /// </summary>
        private List <PhysicsObj> GetVisibleObjects(EnvCell cell, VisibleObjectType type)
        {
            var visibleObjs = new List <PhysicsObj>();

            // add objects from current cell
            cell.AddObjectListTo(visibleObjs);

            // add objects from visible cells
            foreach (var envCell in cell.VisibleCells.Values)
            {
                if (envCell != null)
                {
                    envCell.AddObjectListTo(visibleObjs);
                }
            }

            // if SeenOutside, add objects from outdoor landblock
            if (cell.SeenOutside)
            {
                var outsideObjs = PhysicsObj.CurLandblock.GetServerObjects(true).Where(i => !(i.CurCell is EnvCell indoors) || indoors.SeenOutside);

                visibleObjs.AddRange(outsideObjs);
            }

            return(ApplyFilter(visibleObjs, type).Where(i => !i.DatObject && i.ID != PhysicsObj.ID).Distinct().ToList());
        }
Example #5
0
        /// <summary>
        /// Returns a list of objects that are currently visible from a cell
        /// </summary>
        public List <PhysicsObj> GetVisibleObjects(ObjCell cell, VisibleObjectType type = VisibleObjectType.All)
        {
            if (PhysicsObj.CurLandblock == null || cell == null)
            {
                return(new List <PhysicsObj>());
            }

            // use PVS / VisibleCells for EnvCells not seen outside
            // (mostly dungeons, also some large indoor areas ie. caves)
            if (cell is EnvCell envCell && !envCell.SeenOutside)
            {
                return(GetVisibleObjects(envCell, type));
            }

            // use current landblock + adjacents for outdoors,
            // and envcells seen from outside (all buildings)
            var visibleObjs = new List <PhysicsObj>(PhysicsObj.CurLandblock.ServerObjects);

            var adjacents = PhysicsObj.CurLandblock.get_adjacents();

            if (adjacents != null)
            {
                foreach (var adjacent in adjacents)
                {
                    visibleObjs.AddRange(adjacent.ServerObjects);
                }
            }

            return(ApplyFilter(visibleObjs, type).Where(i => i.ID != PhysicsObj.ID && (!(i.CurCell is EnvCell indoors) || indoors.SeenOutside)).ToList());
        }
Example #6
0
        private IEnumerable <PhysicsObj> ApplyFilter(List <PhysicsObj> objs, VisibleObjectType type)
        {
            IEnumerable <PhysicsObj> results = objs;

            if (type == VisibleObjectType.Players)
            {
                results = objs.Where(i => i.IsPlayer);
            }
            else if (type == VisibleObjectType.AttackTargets)
            {
                if (PhysicsObj.WeenieObj.IsCombatPet)
                {
                    results = objs.Where(i => i.WeenieObj.IsMonster && i.WeenieObj.PlayerKillerStatus != PlayerKillerStatus.PK);    // combat pets cannot attack pk-only creatures (ie. faction banners)
                }
                else if (PhysicsObj.WeenieObj.IsFactionMob)
                {
                    results = objs.Where(i => i.IsPlayer || i.WeenieObj.IsCombatPet || i.WeenieObj.IsMonster && !i.WeenieObj.SameFaction(PhysicsObj));
                }
                else
                {
                    // adding faction mobs here, even though they are retaliate-only, for inverse visible targets
                    results = objs.Where(i => i.IsPlayer || i.WeenieObj.IsCombatPet && PhysicsObj.WeenieObj.PlayerKillerStatus != PlayerKillerStatus.PK || i.WeenieObj.IsFactionMob || i.WeenieObj.PotentialFoe(PhysicsObj));
                }
            }
            return(results);
        }
Example #7
0
        /// <summary>
        /// Returns a list of objects that are currently visible from a dungeon cell
        /// </summary>
        private List <PhysicsObj> GetVisibleObjects(EnvCell cell, VisibleObjectType type)
        {
            var visibleObjs = new List <PhysicsObj>();

            // add objects from current cell
            cell.AddObjectListTo(visibleObjs);

            // add objects from visible cells
            foreach (var envCell in cell.VisibleCells.Values)
            {
                if (envCell != null)
                {
                    envCell.AddObjectListTo(visibleObjs);
                }
            }

            return(ApplyFilter(visibleObjs, type).Where(i => !i.DatObject && i.ID != PhysicsObj.ID).Distinct().ToList());
        }
Example #8
0
        public IEnumerable <PhysicsObj> ApplyFilter(List <PhysicsObj> objs, VisibleObjectType type)
        {
            IEnumerable <PhysicsObj> results = objs;

            if (type == VisibleObjectType.Players)
            {
                results = objs.Where(i => i.IsPlayer);
            }
            else if (type == VisibleObjectType.AttackTargets)
            {
                if (PhysicsObj.WeenieObj.IsCombatPet)
                {
                    results = objs.Where(i => i.WeenieObj.IsMonster);
                }
                else
                {
                    results = objs.Where(i => i.IsPlayer || i.WeenieObj.IsCombatPet);
                }
            }
            return(results);
        }