Exemple #1
0
    public override string ToChatString(GameWorldController gameWorldController)
    {
        MobData mobData  = gameWorldController.Model.GetMobData(MobID);
        MobType mobType  = MobTypeManager.GetMobTypeByName(mobData.mob_type_name);
        float   distance = Point3d.Distance(FromPosition, ToPosition);

        MathConstants.eDirection direction = MathConstants.GetDirectionForAngle(ToAngle);
        string facing = "";

        switch (direction)
        {
        case MathConstants.eDirection.none:
            facing = "South";
            break;

        case MathConstants.eDirection.right:
            facing = "East";
            break;

        case MathConstants.eDirection.up:
            facing = "North";
            break;

        case MathConstants.eDirection.left:
            facing = "West";
            break;

        case MathConstants.eDirection.down:
            facing = "South";
            break;
        }

        return(base.ToChatString(gameWorldController) + mobType.Name + " moved " + distance.ToString("F1") + " feet, now facing " + facing);
    }
    public override string ToChatString(GameWorldController gameWorldController)
    {
        string characterName = gameWorldController.Model.GetCharacterData(CharacterID).character_name;

        MathConstants.eDirection direction = MathConstants.GetDirectionForAngle(ToAngle);
        string facing = "";

        switch (direction)
        {
        case MathConstants.eDirection.none:
            facing = "South";
            break;

        case MathConstants.eDirection.right:
            facing = "East";
            break;

        case MathConstants.eDirection.up:
            facing = "North";
            break;

        case MathConstants.eDirection.left:
            facing = "West";
            break;

        case MathConstants.eDirection.down:
            facing = "South";
            break;
        }

        return(base.ToChatString(gameWorldController) + characterName + " moved " + facing +
               " to room at (" + ToRoomKey.x + ", " + ToRoomKey.y + ", " + ToRoomKey.z + ")");
    }
Exemple #3
0
    public override string ToChatString(GameWorldController gameWorldController)
    {
        string characterName = gameWorldController.Model.GetCharacterData(CharacterID).character_name;
        float  distance      = (Point3d.Distance(FromPosition, ToPosition));

        MathConstants.eDirection direction = MathConstants.GetDirectionForAngle(ToAngle);
        string facing = "";

        switch (direction)
        {
        case MathConstants.eDirection.none:
            facing = "South";
            break;

        case MathConstants.eDirection.right:
            facing = "East";
            break;

        case MathConstants.eDirection.up:
            facing = "North";
            break;

        case MathConstants.eDirection.left:
            facing = "West";
            break;

        case MathConstants.eDirection.down:
            facing = "South";
            break;
        }

        return(base.ToChatString(gameWorldController) + characterName + " moved " + distance.ToString("F1") + " feet, now facing " + facing);
    }
Exemple #4
0
        public NavCellNeighborIterator(NavMesh navMesh, uint navCellIndex)
        {
            m_navMesh              = navMesh;
            m_navCellIndex         = navCellIndex;
            m_neighborDirection    = MathConstants.eDirection.none;
            m_neighborNavCellIndex = navCellIndex;

            Next();
        }
Exemple #5
0
        public NavCellNeighborIterator(NavMesh navMesh, uint navCellIndex)
        {
            m_navMesh = navMesh;
            m_navCellIndex = navCellIndex;
            m_neighborDirection = MathConstants.eDirection.none;
            m_neighborNavCellIndex = navCellIndex;

            Next();
        }
Exemple #6
0
 public bool TryGetValidNeighborNavCellIndex(
     uint navCellIndex,
     MathConstants.eDirection direction,
     out uint neighborCellIndex)
 {
     return(NavMesh.TryGetValidNeighborNavCellIndex(
                m_navCells,
                m_colomnCount,
                m_rowCount,
                navCellIndex,
                direction,
                out neighborCellIndex));
 }
    private void DebugDrawNavMesh()
    {
        RoomKey roomKey = _gameWorldController.Model.CurrentGame.CurrentRoomKey;

        AsyncRPGSharedLib.Navigation.NavMesh navMesh = PathfindingSystem.GetNavMesh(roomKey);

        if (navMesh != null)
        {
            for (uint navCellIndex = 0; navCellIndex < navMesh.GetNavCellCount(); navCellIndex++)
            {
                int connectivityId = navMesh.GetNavCellConnectivityID(navCellIndex);

                if (connectivityId != AsyncRPGSharedLib.Navigation.NavMesh.EMPTY_NAV_CELL)
                {
                    for (MathConstants.eDirection direction = MathConstants.eDirection.first;
                         direction < MathConstants.eDirection.count;
                         direction++)
                    {
                        if (!navMesh.NavCellHasNeighbor(navCellIndex, direction))
                        {
                            Point3d portalLeft, portalRight;
                            Vector3 portalVertexLeft, portalVertexRight;

                            navMesh.ComputePointsOnNavCellSide(navCellIndex, direction, out portalLeft, out portalRight);
                            portalVertexLeft  = ClientGameConstants.ConvertRoomPositionToVertexPosition(portalLeft);
                            portalVertexRight = ClientGameConstants.ConvertRoomPositionToVertexPosition(portalRight);

                            Debug.DrawLine(
                                portalVertexLeft,
                                portalVertexRight,
                                Color.yellow,
                                0.0f,   // duration
                                false); // depth test
                        }
                    }
                }
            }
        }
    }
Exemple #8
0
    private void UpdateMouseCursor(WidgetEvent widgetEvent)
    {
        if (widgetEvent.EventType == WidgetEvent.eEventType.mouseOver ||
            widgetEvent.EventType == WidgetEvent.eEventType.mouseOut ||
            widgetEvent.EventType == WidgetEvent.eEventType.mouseMove)
        {
            if (widgetEvent.EventSource is HotspotWidget)
            {
                HotspotWidget hotspotWidget = widgetEvent.EventSource as HotspotWidget;
                HotspotInfo   hotspotInfo   = hotspotWidget.Userdata as HotspotInfo;

                switch (hotspotInfo.hotspotType)
                {
                case eHotspotType.energy_tank:
                {
                    EnergyTankData energyTankData = hotspotInfo.hotspotEntity as EnergyTankData;

                    if (energyTankData.ownership != GameConstants.eFaction.player)
                    {
                        // If our faction doesn't control the energy tank, we'll have to hack it
                        SetMouseCursorState(eMouseCursorState.hack_energy_tank);
                    }
                    else if (energyTankData.energy > 0)
                    {
                        // If our faction does control the energy tank, then we can drain it if it has energy
                        SetMouseCursorState(eMouseCursorState.drain_energy_tank);
                    }
                    else
                    {
                        // Otherwise all we can do is walk to it
                        SetMouseCursorState(eMouseCursorState.walk);
                    }
                }
                break;

                case eHotspotType.portal:
                {
                    Point2d hotspotCenter =
                        hotspotWidget.WorldPosition.Offset(new Vector2d(hotspotWidget.Width / 2.0f, hotspotWidget.Height / 2.0f));
                    Point2d  screenCenter    = new Point2d(Screen.width / 2.0f, Screen.height / 2.0f);
                    Vector2d vectorToHotspot = hotspotCenter - screenCenter;

                    MathConstants.eDirection currentHotspotDirection = MathConstants.GetDirectionForVector(vectorToHotspot);

                    switch (currentHotspotDirection)
                    {
                    case MathConstants.eDirection.left:
                        SetMouseCursorState(eMouseCursorState.door_left);
                        break;

                    case MathConstants.eDirection.right:
                        SetMouseCursorState(eMouseCursorState.door_right);
                        break;

                    case MathConstants.eDirection.up:
                        SetMouseCursorState(eMouseCursorState.door_up);
                        break;

                    case MathConstants.eDirection.down:
                        SetMouseCursorState(eMouseCursorState.door_down);
                        break;

                    default:
                        SetMouseCursorState(eMouseCursorState.walk);
                        break;
                    }
                }
                break;

                default:
                {
                    SetMouseCursorState(eMouseCursorState.defaultCursor);
                }
                break;
                }
            }
            else if (widgetEvent.EventSource is TileGridWidget)
            {
                if (m_currentNavRef.IsValid)
                {
                    SetMouseCursorState(eMouseCursorState.walk);
                }
                else
                {
                    SetMouseCursorState(eMouseCursorState.defaultCursor);
                }
            }
            else
            {
                SetMouseCursorState(eMouseCursorState.defaultCursor);
            }
        }
    }
Exemple #9
0
        public bool NavCellHasNeighbor(uint navCellIndex, MathConstants.eDirection direction)
        {
            uint neighborNavCellIndex;

            return(TryGetValidNeighborNavCellIndex(navCellIndex, direction, out neighborNavCellIndex));
        }
Exemple #10
0
        private static bool TryGetValidNeighborNavCellIndex(
            NavCell[] navCells,
            uint colomnCount,
            uint rowCount,
            uint navCellIndex,
            MathConstants.eDirection direction,
            out uint neighborCellIndex)
        {
            bool hasNeighbor = false;

            neighborCellIndex = 0;

            if (navCells.Length > 1)
            {
                uint colomn = GetNavCellColomn(colomnCount, navCellIndex);
                uint row    = GetNavCellRow(colomnCount, navCellIndex);

                switch (direction)
                {
                case MathConstants.eDirection.down:
                    if ((row + 1) < rowCount)
                    {
                        neighborCellIndex = GetNavCellIndex(colomnCount, row + 1, colomn);
                        hasNeighbor       = true;
                    }
                    break;

                case MathConstants.eDirection.up:
                    if ((row - 1) > 0)
                    {
                        neighborCellIndex = GetNavCellIndex(colomnCount, row - 1, colomn);
                        hasNeighbor       = true;
                    }
                    break;

                case MathConstants.eDirection.left:
                    if ((colomn - 1) >= 0)
                    {
                        neighborCellIndex = GetNavCellIndex(colomnCount, row, colomn - 1);
                        hasNeighbor       = true;
                    }
                    break;

                case MathConstants.eDirection.right:
                    if ((colomn + 1) >= 0)
                    {
                        neighborCellIndex = GetNavCellIndex(colomnCount, row, colomn + 1);
                        hasNeighbor       = true;
                    }
                    break;
                }

                if (hasNeighbor && navCells[neighborCellIndex].connectivityId == EMPTY_NAV_CELL)
                {
                    neighborCellIndex = 0;
                    hasNeighbor       = false;
                }
            }

            return(hasNeighbor);
        }
Exemple #11
0
        public bool ComputePointsOnNavCellSide(
            uint navCellIndex,
            MathConstants.eDirection direction,
            out Point3d portalLeft,
            out Point3d portalRight)
        {
            bool validPortal = false;

            if (m_navCells.Length > 1)
            {
                float halfCellSize = GameConstants.NAV_MESH_WORLD_UNITS_SIZE * 0.5F;

                portalLeft  = ComputeNavCellCenter(navCellIndex);
                portalRight = new Point3d(portalLeft);

                // toNavRef is to the right of the fromNavRef (+X)
                switch (direction)
                {
                // (+X)
                case MathConstants.eDirection.right:
                {
                    portalLeft.x  += halfCellSize;
                    portalLeft.y  -= halfCellSize;
                    portalRight.x += halfCellSize;
                    portalRight.y += halfCellSize;

                    validPortal = true;
                } break;

                // (-X)
                case MathConstants.eDirection.left:
                {
                    portalLeft.x  -= halfCellSize;
                    portalLeft.y  += halfCellSize;
                    portalRight.x -= halfCellSize;
                    portalRight.y -= halfCellSize;

                    validPortal = true;
                } break;

                // (-Y)
                case MathConstants.eDirection.down:
                {
                    portalLeft.x  += halfCellSize;
                    portalLeft.y  -= halfCellSize;
                    portalRight.x -= halfCellSize;
                    portalRight.y -= halfCellSize;

                    validPortal = true;
                } break;

                // (+Y)
                case MathConstants.eDirection.up:
                {
                    portalLeft.x  -= halfCellSize;
                    portalLeft.y  += halfCellSize;
                    portalRight.x += halfCellSize;
                    portalRight.y += halfCellSize;

                    validPortal = true;
                } break;
                }
            }
            else
            {
                portalLeft  = new Point3d();
                portalRight = new Point3d();
            }

            return(validPortal);
        }
Exemple #12
0
        private static void BuildNavCellConnectivityGrid(
            uint colomnCount,
            uint rowCount,
            BitArray navMeshData,
            out NavCell[] navCells,
            out uint nonEmptyNavCellCount)
        {
            UnionFind <uint> navCellUnion = new UnionFind <uint>();

            // Create an initial set of nav cells
            // Any valid cell gets a connectivity id of 0
            // Any invalid cell gets a connectivity id of EMPTY_NAV_CELL
            // Valid nav cells get added to the nav cell union set
            navCells             = new NavCell[rowCount * colomnCount];
            nonEmptyNavCellCount = 0;

            for (int navCellIndex = 0; navCellIndex < navMeshData.Length; ++navCellIndex)
            {
                if (navMeshData[navCellIndex])
                {
                    uint pvsCellIndex = nonEmptyNavCellCount++;

                    navCells[navCellIndex] = new NavCell(0, pvsCellIndex);

                    navCellUnion.AddElement((uint)navCellIndex);
                }
                else
                {
                    navCells[navCellIndex] = new NavCell();
                }
            }

            // Union together all neighboring nav cells
            for (int unionElementIndex = 0; unionElementIndex < navCellUnion.SetSize; ++unionElementIndex)
            {
                uint navCellIndex = navCellUnion.GetElement(unionElementIndex);

                for (MathConstants.eDirection direction = MathConstants.eDirection.first;
                     direction < MathConstants.eDirection.count;
                     ++direction)
                {
                    uint neighborNavCellIndex;

                    if (TryGetValidNeighborNavCellIndex(
                            navCells,
                            colomnCount,
                            rowCount,
                            navCellIndex,
                            direction,
                            out neighborNavCellIndex))
                    {
                        navCellUnion.Union(navCellIndex, neighborNavCellIndex);
                    }
                }
            }

            // Write the final connectivity IDs back into the nav cells
            for (int unionElementIndex = 0; unionElementIndex < navCellUnion.SetSize; ++unionElementIndex)
            {
                uint navCellIndex   = navCellUnion.GetElement(unionElementIndex);
                int  connectivityID = navCellUnion.FindRootIndex(unionElementIndex);

                navCells[navCellIndex].connectivityId = (short)connectivityID;
            }
        }