Exemplo n.º 1
0
        Ting[] BuildExitsCacheForRoom(string pRoomName)
        {
            var exits       = new List <Ting>();
            var tingsInRoom = _tingRunner.GetTingsInRoom(pRoomName);

            foreach (var ting in tingsInRoom)
            {
                if (ting is IExit)
                {
                    exits.Add(ting);
                }
            }
            var exitsArray = exits.ToArray();

            _exitForRoomsCache [pRoomName] = exitsArray;
            return(exitsArray);
        }
Exemplo n.º 2
0
        Ting[] BuildExitsCacheForRoom(string pRoomName)
        {
            //D.Log("Building exits cache for " + pRoomName + ": ");
            var exits       = new HashSet <Ting>();
            var tingsInRoom = _tingRunner.GetTingsInRoom(pRoomName);

            foreach (var ting in tingsInRoom)
            {
                if (ting is IExit)
                {
                    exits.Add(ting);
                    //D.Log(" - " + ting.name);
                }
            }
            var exitsArray = exits.ToArray();

            _exitForRoomsCache [pRoomName] = exitsArray;
            return(exitsArray);
        }
Exemplo n.º 3
0
        private bool MimanPathfindToTargetRoom()
        {
#if PROFILE
            Stopwatch sw = new Stopwatch();
            sw.Start();
#endif

            Ting start = _character;
            Ting goal  = null;

            if (_character.finalTargetTing != null)
            {
                goal = _character.finalTargetTing;
            }
            else
            {
                // HACK!!!
                // Since there is no specific ting to pathfind to we just grab one in the final room where we want to go
                // The final target position will not be affected since we have no final target ting

                string finalRoomName = _character.finalTargetPosition.roomName;

                if (finalRoomName == WorldCoordinate.UNDEFINED_ROOM)
                {
#if LOG
                    s_logger.Log("No finalTargetTing and no final target position");
#endif
                    return(false);
                }

                Ting targetTing       = null;
                var  tingsInFinalRoom = _tingRunner.GetTingsInRoom(finalRoomName);
                if (tingsInFinalRoom.Length == 0)
                {
                    D.Log(_character + ": No tings in final room " + finalRoomName + ", can't do room pathfinding to there!");
                    return(false);
                }
                else
                {
                    targetTing = tingsInFinalRoom[0];
                }
                goal = targetTing;
                //throw new Exception("No ting to pathfind to for " + _character.name);
            }

            if (start == null)
            {
#if LOG
                s_logger.Log("start is null");
#endif
                return(false);
            }
            if (goal == null)
            {
#if LOG
                s_logger.Log("goal is null");
#endif
                return(false);
            }

            _mimanPath = _mimanPathFinder.Search(start, goal);
#if LOG
            s_logger.Log(_mimanPath.ToString());
#endif
            //D.Log(_character + " did pathfinding between rooms: " + _mimanPath.ToString());

#if PROFILE
            sw.Stop();
            if (sw.Elapsed.TotalSeconds > 0.015f)
            {
                D.Log("MimanRoomPathFinding for " + _character + " from " + start + "(" + start.position + ")" + " to " + goal + "(" + goal.position + ")" + " took " + sw.Elapsed.TotalSeconds + " s. Status = " + _mimanPath.ToString());
            }
#endif

            if (_mimanPath.status == MimanPathStatus.FOUND_GOAL)
            {
                if (_mimanPath.tings == null)
                {
                    throw new Exception("tings == null in _mimanPath!");
                }
                else if (_mimanPath.tings.Length == 0)
                {
                    throw new Exception("No tings in _mimanPath!");
                }
                else
                {
#if LOG
                    s_logger.Log("Setting " + _character.name + "'s targetPositionInRoom to " + _mimanPath.tings[0].name + "'s interaction point");
#endif
                    var firstTingToInteractWith = _mimanPath.tings[0];
                    D.isNull(firstTingToInteractWith, "firstTingToInteractWith is null");
                    _character.targetPositionInRoom = new WorldCoordinate(firstTingToInteractWith.room.name,
                                                                          firstTingToInteractWith.interactionPoints[0]);
                    return(true);
                }
            }
            else if (_mimanPath.status == MimanPathStatus.IN_THE_SAME_ROOM_ALREADY)
            {
                return(true);
            }
            else if (_mimanPath.status == MimanPathStatus.NO_PATH_FOUND)
            {
#if LOG
                s_logger.Log("Can't find path through rooms, cancels walking.");
#endif
                _character.CancelWalking();
                return(false);
            }
            else
            {
                throw new Exception("Failed to find matching case");
            }
        }