Esempio n. 1
0
        public bool MobDrainEnergyTank(EnergyTank energyTank, int desiredDrainAmount)
        {
            bool success = true;

            float min_distance_squared = WorldConstants.ROOM_TILE_SIZE * WorldConstants.ROOM_TILE_SIZE;

            // Move to the energy tank first if it's too far away
            if (Point3d.DistanceSquared(mob.Position, energyTank.Position) > min_distance_squared)
            {
                success = MoveMob(energyTank.Position);
            }

            if (success)
            {
                int energyDrained = Math.Min(energyTank.Energy, desiredDrainAmount);

                // Drain the energy from the tank
                energyTank.Energy -= energyDrained;

                // Give energy to the mob
                mob.Energy = Math.Min(mob.Energy + energyDrained, mob.MobType.MaxEnergy);

                // Post an event that we moved
                output_game_events.Add(
                    new GameEvent_EnergyTankDrained()
                {
                    energy_tank_id  = energyTank.ID,
                    drainer_id      = mob.ID,
                    drainer_faction = GameConstants.eFaction.ai,
                    energy_drained  = energyDrained
                });
            }

            return(success);
        }
        private bool VerifyNavMeshConnectivity(out string result_code)
        {
            bool success;

            if (Point3d.DistanceSquared(m_current_character_position, m_target_position) > MathConstants.POSITIONAL_EPSILON_SQUARED)
            {
                // Player has to walk to the portal target
                NavRef characterNavRef = m_room.runtime_nav_mesh.ComputeNavRefAtPoint(m_current_character_position);
                NavRef targetNavRef    = m_room.runtime_nav_mesh.ComputeNavRefAtPoint(m_target_position);

                if (m_room.runtime_nav_mesh.AreNavRefsConnected(characterNavRef, targetNavRef))
                {
                    result_code = SuccessMessages.GENERAL_SUCCESS;
                    success     = true;
                }
                else
                {
                    // It isn't possible to reach the target on the nav mesh from where the player is standing
                    result_code = ErrorMessages.TARGET_UNREACHABLE;
                    success     = false;
                }
            }
            else
            {
                // Character already on top of the portal
                result_code = SuccessMessages.GENERAL_SUCCESS;
                success     = true;
            }

            return(success);
        }
Esempio n. 3
0
        private bool VerifyEnergyTank(
            RequestCache requestCache,
            out bool out_is_touching,
            out string result_code)
        {
            bool success = false;

            out_is_touching = false;

            // Make sure the portal actually exists in the room the player is in
            m_energy_tank = requestCache.GetEnergyTank(m_current_room_key, m_energy_tank_id);

            if (m_energy_tank != null)
            {
                // Remember how much energy the tank had before we drained it
                m_energy_tank_old_energy = m_energy_tank.Energy;

                switch (m_energy_tank.Faction)
                {
                case GameConstants.eFaction.player:
                    result_code = SuccessMessages.GENERAL_SUCCESS;
                    success     = true;
                    break;

                case GameConstants.eFaction.ai:
                case GameConstants.eFaction.neutral:
                    result_code = ErrorMessages.ENERGY_TANK_NOT_PLAYER_OWNED;
                    success     = false;
                    break;

                default:
                    result_code = ErrorMessages.DB_ERROR + "(Invalid energy tank faction)";
                    success     = false;
                    break;
                }

                if (success && m_energy_tank.Energy <= 0)
                {
                    result_code = ErrorMessages.ENERGY_TANK_EMPTY;
                    success     = false;
                }

                if (success)
                {
                    float min_distance_squared = WorldConstants.ROOM_TILE_SIZE * WorldConstants.ROOM_TILE_SIZE;
                    float distance             = Point3d.DistanceSquared(m_current_character_position, m_energy_tank.Position);

                    out_is_touching = distance <= min_distance_squared;
                }
            }
            else
            {
                result_code = ErrorMessages.INVALID_REQUEST;
            }

            return(success);
        }
Esempio n. 4
0
    private static bool WaypointWithinToleranceRule(PathfindingComponent pathfindingInterface)
    {
        float distanceToWaypointSquared =
            Point3d.DistanceSquared(
                pathfindingInterface.m_entity.Position,
                pathfindingInterface.CurrentWaypoint.StepPoint);
        float toleranceSquared =
            pathfindingInterface.IsLastStep ?
            DESTINATION_TOLERANCE * DESTINATION_TOLERANCE :
            WAYPOINT_TOLERANCE * WAYPOINT_TOLERANCE;
        bool hitWaypoint = (distanceToWaypointSquared <= toleranceSquared);

        return(hitWaypoint);
    }
Esempio n. 5
0
    // Requests
    public bool SubmitPathRequest(
        Point3d point,
        Vector2d facing,
        PathComputer.OnPathComputerComplete pathCompletedCallback)
    {
        bool success = false;

        m_pathSteps            = new List <PathStep>();
        m_pathStepIndex        = 0;
        m_pathCompleteCallback = pathCompletedCallback;

        m_destinationPoint.Set(point);
        m_destinationFacing.Copy(facing);

        if (Point3d.DistanceSquared(m_destinationPoint, m_entity.Position) > MathConstants.EPSILON_SQUARED)
        {
            success =
                PathfindingSystem.AddPathRequest(
                    m_entity.CurrentRoomKey,
                    m_entity.Position,
                    m_destinationPoint,
                    (PathComputer pathResult) =>
            {
                if (pathResult.ResultCode == PathComputer.eResult.success)
                {
                    m_state     = ePathFindingState.in_progress;
                    m_pathSteps = pathResult.FinalPath;
                }
                else
                {
                    OnPathCompleted(pathResult);
                }
            });
        }
        else
        {
            OnPathCompleted(null);
            success = true;
        }

        return(success);
    }
Esempio n. 6
0
        public uint[] ComputeNavCellsInRadius(Point3d center, float radius, bool include_center)
        {
            List <uint> navCells       = new List <uint>();
            NavRef      centerRef      = ComputeNavRefAtPoint(center);
            float       radius_squared = radius * radius;

            if (centerRef.NavCellIndex != EMPTY_NAV_CELL)
            {
                uint centerCellIndex = (uint)centerRef.NavCellIndex;
                uint centerColomn    = GetNavCellColomn(centerCellIndex);
                uint centerRow       = GetNavCellRow(centerCellIndex);

                uint radiusInCells  = (uint)Math.Ceiling(radius / GameConstants.NAV_MESH_WORLD_UNITS_SIZE);
                uint minColomnIndex = (centerColomn >= radiusInCells) ? centerColomn - radiusInCells : 0;
                uint maxColomnIndex = Math.Min(centerColomn + radiusInCells, m_colomnCount - 1);
                uint minRowIndex    = (centerRow >= radiusInCells) ? centerRow - radiusInCells : 0;
                uint maxRowIndex    = Math.Min(centerRow + radiusInCells, m_rowCount - 1);

                for (uint row = minRowIndex; row <= maxRowIndex; ++row)
                {
                    for (uint colomn = minColomnIndex; colomn <= maxColomnIndex; ++colomn)
                    {
                        uint cellIndex = GetNavCellIndex(row, colomn);

                        if ((cellIndex != centerCellIndex || include_center) &&
                            m_navCells[cellIndex].connectivityId == m_navCells[centerCellIndex].connectivityId)
                        {
                            Point3d cellCenter = ComputeNavCellCenter(cellIndex);

                            if (Point3d.DistanceSquared(cellCenter, center) <= radius_squared)
                            {
                                navCells.Add(cellIndex);
                            }
                        }
                    }
                }
            }

            return(navCells.ToArray());
        }
    public void Execute(OnRequestCompleteDelegate onComplete)
    {
        if (Status != eRequestStatus.pending_path_find || Status != eRequestStatus.pending_server_response)
        {
            m_onCompleteCallback = onComplete;

            if (Point3d.DistanceSquared(OriginalPosition, OriginPortalEntryPoint) > WITHIN_PORTAL_TOLERANCE_SQUARED)
            {
                Status = eRequestStatus.pending_path_find;

                PathfindingSystem.AddPathRequest(
                    m_entity.CurrentRoomKey,
                    m_entity.Position,
                    OriginPortalEntryPoint,
                    this.OnPathComputed);
            }
            else
            {
                Status = eRequestStatus.pending_server_response;
            }
        }
    }
Esempio n. 8
0
        public bool MobHackEnergyTank(EnergyTank energyTank)
        {
            bool success = true;

            float min_distance_squared = WorldConstants.ROOM_TILE_SIZE * WorldConstants.ROOM_TILE_SIZE;

            // Move to the energy tank first if it's too far away
            if (Point3d.DistanceSquared(mob.Position, energyTank.Position) > min_distance_squared)
            {
                success = MoveMob(energyTank.Position);
            }

            if (success)
            {
                // If the energy tank's faction was player it's now neutral
                // If the energy tank's faction was neutral it's now ai
                GameConstants.eFaction newFaction =
                    (energyTank.Faction == GameConstants.eFaction.player)
                    ? GameConstants.eFaction.neutral : GameConstants.eFaction.ai;

                // Update the faction on the energy tank
                energyTank.Faction = newFaction;

                // Post an event that we moved
                output_game_events.Add(
                    new GameEvent_EnergyTankHacked()
                {
                    energy_tank_id      = energyTank.ID,
                    energy_tank_faction = newFaction,
                    hacker_id           = mob.ID,
                    hacker_faction      = GameConstants.eFaction.ai
                });
            }

            return(success);
        }