Ejemplo n.º 1
0
 public void SetUp()
 {
     WorldTestHelper.GenerateInitData();
     InitialSaveFileCreator i = new InitialSaveFileCreator();
     _world = new World(i.CreateRelay(WorldTestHelper.INIT_DATA_PATH));
     _room = _world.roomRunner.CreateRoom<Room>("Room");
 }
Ejemplo n.º 2
0
 void SetCachedRoom() {
     _cachedRoom = _roomRunner.GetRoom(CELL_position.data.roomName);
 }
Ejemplo n.º 3
0
 public TileNode(Room pRoom, IntPoint pLocalPosition)
 {
     room = pRoom;
     localPosition = pLocalPosition;
 }
Ejemplo n.º 4
0
        // Returns true on success
        private static bool GetClosestInteractionPoint(RoomRunner pRoomRunner, Room pRoom, PointTileNode pStartTile, IntPoint[] pPossiblePoints, out IntPoint closestPoint, Character pCharacter, bool pIgnoreCharacters)
        {
            D.isNull(pRoom, "pRoom is null");
            D.isNull(pPossiblePoints, "possiblePoints is null");

            if (pRoom != pCharacter.room) {
                throw new Exception("Error for " + pCharacter.name + "! Can only pathfind to closest interaction point in the same room: " + pCharacter.room.name + ", tried to do it in: " + pRoom.name);
            }

            closestPoint = IntPoint.Zero;
            float shortestDistance = float.MaxValue;
            bool foundSomething = false;

            #if LOG
            s_logger.Log("Trying to find closest interaction point for " + pCharacter + ", nr of possible points: " + pPossiblePoints.Length);
            #endif

            foreach(IntPoint p in pPossiblePoints)
            {
                PointTileNode tileNode = pRoom.GetTile(p);
                if(tileNode == null) {
            #if LOG
                    s_logger.Log("Node at " + p + " was null, ignoring it");
            #endif
                    continue;
                }

                var ignoreList = notTrueObstacles;

                if (pIgnoreCharacters) {
                    ignoreList = notTrueObstaclesIncludingCharacters;
                }

                if(tileNode.HasOccupantsButIgnoreSomeTypes(ignoreList)) {
            #if LOG
                    s_logger.Log("Will ignore node at " + p + " since it has occupants: " + tileNode.GetOccupantsAsString());
            #endif
                    continue;
                }

            #if LOG
                s_logger.Log("Checking tile node " + tileNode);
            #endif

                pRoom.Reset();
                var path = _tilePathSolver.FindPath(pStartTile, tileNode, pRoomRunner, false);

            #if LOG
                s_logger.Log("RESULT Path from " + pStartTile + " to " + tileNode + ": " + path.status);
            #endif
                //D.Log("RESULT Path from " + pStartTile + " to " + tileNode + ": " + path.status);

                D.isNull(path, "path is null");
                if((path.status == PathStatus.FOUND_GOAL || path.status == PathStatus.ALREADY_THERE) && path.pathLength < shortestDistance) {
                    closestPoint = p;
                    shortestDistance = path.pathLength;
                    foundSomething = true;
                }

            #if LOG
                s_logger.Log("path.status = " + path.status);
            #endif
            }

            if(!foundSomething) {
            #if LOG
                s_logger.Log(pCharacter + " at position " + pCharacter.position + " can't find an interaction point for final target " + pCharacter.finalTargetTing);
            #endif
                return false;
            }

            return true;
        }
Ejemplo n.º 5
0
 private Ting[] GetExits(Room pRoom)
 {
     string roomName = pRoom.name;
     Ting[] exits;
     if (_exitForRoomsCache.TryGetValue (roomName, out exits)) {
         return exits;
     } else {
         return BuildExitsCacheForRoom (roomName);
     }
 }
Ejemplo n.º 6
0
 //        [SprakAPI("Teleport user to another position. Returns an error message as a string.", "x", "y")]
 //        public string API_TeleportUser(string targetRoom, int x, int y)
 //        {
 //            if(_user == null) {
 //                D.Log ("User for door " + name + " is null");
 //                return "Fail";
 //                //throw new Exception("User is null for door " + name);
 //            }
 //            
 //            if(targetDoor != null) {
 //                var targetRoomRef = _roomRunner.GetRoom(targetRoom);
 //                PushAwayBlockers(targetRoomRef, x, y, IntPoint.DirectionToIntPoint(targetDoor.direction));
 //                WorldCoordinate newPosition = new WorldCoordinate(targetRoom, x, y); // OLD VERSION: door.targetPosition;
 //                logger.Log(name + " opened the door " + name + " and will now teleport to " + newPosition);
 //                _user.targetPositionInRoom = targetDoor.position; // makes the Shell not freak out when it is created in the new scene but target is still in the old one
 //                _user.position = newPosition;
 //                _user.direction = targetDoor.direction;
 //                _user.StopAction();
 //                _user.StartAction("WalkingThroughDoorPhase2", null, 1.35f, 1.35f);
 //                _dialogueRunner.EventHappened(_user.name + "_open_" + name);
 //                if(isElevatorEntrance) {
 //                    targetDoor.elevatorFloor = this.elevatorFloor;
 //                }
 //                return "Success";
 //            }
 //            else {
 //                return "Door '" + name + "' doesn't have a target";
 //            }
 //        }
 void PushAwayBlockers(Room targetRoom, int x, int y, IntPoint pushDir)
 {
     var tile = targetRoom.GetTile(x, y);
     if(tile == null) return;
     var blockers = tile.GetOccupants();
     foreach(var blocker in blockers) {
         if(blocker is Character) {
             var newPosition = new WorldCoordinate(blocker.position.roomName, blocker.position.localPosition + pushDir * 2);
             if(targetRoom.GetTile(newPosition.localPosition) != null) {
                 //D.Log(blocker + " was pushed by a door from " + blocker.position + " to " + newPosition);
                 blocker.position = newPosition;
             } else {
                 D.Log("Can't push " + blocker.name + " to " + newPosition + " because there is no tile there");
             }
         }
     }
 }