Example #1
0
        protected override bool SubInRange(WorldRelativeOrientation ownLocation, Hitbox target, WorldRelativeOrientation targetLocation)
        {
            switch (target.Type)
            {
            case HitboxType.Square:
                //Square hitboxes essentially do not rotate. If a square hitbox would be laying down, the sizes swap instead.
                //TODO: This may not entirely make sense if/when there are rooms that rotate outside of 90 degree multiples.
                SquareHitbox otherSquare     = target as SquareHitbox;
                bool         selfIsVertical  = ((Rotation)ownLocation).IsVertical();
                bool         otherIsVertical = ((Rotation)targetLocation).IsVertical();
                int          totalWidth      = (selfIsVertical ? halfWidth : ((height + 1) / 2)) +
                                               (otherIsVertical ? otherSquare.halfWidth : ((otherSquare.height + 1) / 2));
                if (ownLocation.x > targetLocation.x + totalWidth || ownLocation.x < targetLocation.x - totalWidth)
                {
                    return(false);
                }
                if (ownLocation.y > targetLocation.y + totalWidth || ownLocation.y < targetLocation.y - totalWidth)
                {
                    return(false);
                }
                if (ownLocation.z > targetLocation.z + (otherIsVertical ? otherSquare.height : (otherSquare.halfWidth * 2)))
                {
                    return(false);
                }
                if (targetLocation.z > ownLocation.z + (selfIsVertical ? height : (halfWidth * 2)))
                {
                    return(false);
                }

                return(true);

            default:
                return(GenericInRange(ownLocation, target, targetLocation));
            }
        }
Example #2
0
 /// <summary>
 /// Check if the source item's hitbox includes the target. This includes just barely touching.
 /// Surfaces at the same position are considered touching, but not overlapping hitboxes.
 /// </summary>
 /// <param name="ownLocation">Hitbox's position. Not necessarily an item's position, an offset may be applied due to some obstaclesurface alignment or something similar</param>
 /// <param name="target"></param>
 /// <param name="targetLocation">Other hitbox's position. Not necessarily an item's position, an offset may be applied due to some obstaclesurface alignment or something similar</param>
 /// <returns></returns>
 public bool InRange(WorldRelativeOrientation ownLocation, Hitbox target, WorldRelativeOrientation targetLocation)
 {
     if (ownLocation.OriginRoom != targetLocation.OriginRoom)
     {
         return(false);
     }
     return(SubInRange(ownLocation, target, targetLocation));
 }
Example #3
0
 public WorldRelativeOrientation WorldOrientation()
 {
     if (cachedOrientation.OriginRoom == null)
     {
         WorldRelativeOrientation p   = forRoom.Position.WorldOrientation();
         Orientation innerOrientation = new Orientation(x, y, z, direction, roll, tilt);
         cachedOrientation            = (WorldRelativeOrientation)MUDGeometry.ApplyRotationToOrientation((Rotation)p, innerOrientation);
         cachedOrientation.OriginRoom = p.OriginRoom;
     }
     return(cachedOrientation);
 }
Example #4
0
 public WorldRelativeOrientation WorldOrientation()
 {
     if (cachedOrientation.OriginRoom == null)
     {
         if (room != null)
         {
             WorldRelativeOrientation p   = room.Position.WorldOrientation();
             Orientation innerOrientation = new Orientation(x, y, z, direction, roll, tilt);
             cachedOrientation            = (WorldRelativeOrientation)MUDGeometry.ApplyRotationToOrientation((Rotation)p, innerOrientation);
             cachedOrientation.OriginRoom = p.OriginRoom;
         }
         else
         {
             cachedOrientation.OriginRoom = parent;
             cachedOrientation.Direction  = 0;
             cachedOrientation.Roll       = 0;
             cachedOrientation.Tilt       = 0;
             cachedOrientation.x          = 0;
             cachedOrientation.y          = 0;
             cachedOrientation.z          = 0;
         }
     }
     return(cachedOrientation);
 }
Example #5
0
 protected bool GenericInRange(WorldRelativeOrientation ownLocation, Hitbox target, WorldRelativeOrientation targetLocation)
 {
     throw new NotImplementedException("Generic case not implemented yet.");
 }
Example #6
0
 protected abstract bool SubInRange(WorldRelativeOrientation ownLocation, Hitbox target, WorldRelativeOrientation targetLocation);
Example #7
0
        public virtual List <Item> FindNearbyInterestingItems(InterestingCheck interestCheck, WorldRelativeOrientation orientation, Hitbox range)
        {
            //Handles finding items that an event is observing or interacting with.

            if (range != null)
            {
                //TODO: Use Hitbox to spread to other rooms. Probably something like
                //foreach exit, if range.inRange(source, exit) && forEvent.spread(exit), exit.otherRoom.stuff(...)
                //Also TODO: Probably have alternatives for range that allow the room to account for visability or audibility
            }

            List <Item> foundItems = new List <Item>();

            for (int stop = contents.Count, i = 0; i < stop; i++)
            {
                Item nextItem = contents.Get(i);
                if (range != null && !range.InRange(orientation, nextItem.Size, nextItem.Position.WorldOrientation()))
                {
                    continue;
                }
                if (interestCheck(nextItem))
                {
                    foundItems.Add(nextItem);
                }
            }
            return(foundItems);
        }