Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
PlayerRestState.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#include "PlayerRestState.h"
7
8#include <cmath>
9#include <iomanip>
10#include <sstream>
11
12namespace Skyfire
13{
14namespace Rest
15{
16 namespace
17 {
18 constexpr double TwoPi = 6.28318530717958647692;
19 }
20
21 bool HasInnAreaBounds(InnAreaBounds const& bounds)
22 {
23 return bounds.Radius > 0.0f || bounds.BoxX > 0.0f || bounds.BoxY > 0.0f || bounds.BoxZ > 0.0f;
24 }
25
26 bool IsInsideInnArea(InnAreaBounds const& bounds, uint32 mapId, float x, float y, float z, float padding)
27 {
28 if (mapId != bounds.MapId)
29 return false;
30
31 if (bounds.Radius > 0.0f)
32 {
33 float const dx = x - bounds.X;
34 float const dy = y - bounds.Y;
35 float const dz = z - bounds.Z;
36 float const distanceSquared = dx * dx + dy * dy + dz * dz;
37 float const allowedDistance = bounds.Radius + padding;
38 return distanceSquared <= allowedDistance * allowedDistance;
39 }
40
41 if (bounds.BoxX <= 0.0f || bounds.BoxY <= 0.0f || bounds.BoxZ <= 0.0f)
42 return false;
43
44 double const rotation = TwoPi - bounds.BoxOrientation;
45 double const sinVal = std::sin(rotation);
46 double const cosVal = std::cos(rotation);
47
48 float const boxDistX = x - bounds.X;
49 float const boxDistY = y - bounds.Y;
50
51 float const rotatedX = float(bounds.X + boxDistX * cosVal - boxDistY * sinVal);
52 float const rotatedY = float(bounds.Y + boxDistY * cosVal + boxDistX * sinVal);
53
54 return std::fabs(rotatedX - bounds.X) <= bounds.BoxX / 2.0f + padding &&
55 std::fabs(rotatedY - bounds.Y) <= bounds.BoxY / 2.0f + padding &&
56 std::fabs(z - bounds.Z) <= bounds.BoxZ / 2.0f + padding;
57 }
58
59 std::string FormatInnAreaBounds(InnAreaBounds const& bounds)
60 {
61 std::ostringstream output;
62 output << std::fixed << std::setprecision(2);
63 output << "map=" << bounds.MapId
64 << " center=(" << bounds.X << ',' << bounds.Y << ',' << bounds.Z << ')'
65 << " radius=" << bounds.Radius
66 << " box=(" << bounds.BoxX << ',' << bounds.BoxY << ',' << bounds.BoxZ << ',' << bounds.BoxOrientation << ')';
67 return output.str();
68 }
69}
70}
std::uint32_t uint32
Definition Define.h:77
std::string FormatInnAreaBounds(InnAreaBounds const &bounds)
bool HasInnAreaBounds(InnAreaBounds const &bounds)
bool IsInsideInnArea(InnAreaBounds const &bounds, uint32 mapId, float x, float y, float z, float padding)