Ported .Net Core commits:
hondacrx: - Initial commit: Switch to .Net Core 2.0 - Fix build and removed not needed files Fabi: - Updated solution platforms. - Changed folder structure. - Change library target framework to netstandard2.0. - Updated solution platforms again... - Removed windows specific kernel32 function usage (Ctrl-C handler).
This commit is contained in:
@@ -0,0 +1,349 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using System;
|
||||
|
||||
namespace Game.Entities
|
||||
{
|
||||
public struct ObjectGuid : IEquatable<ObjectGuid>
|
||||
{
|
||||
public static ObjectGuid Empty = new ObjectGuid();
|
||||
public static ObjectGuid TradeItem = Create(HighGuid.Uniq, 10ul);
|
||||
|
||||
public ObjectGuid(ulong high, ulong low)
|
||||
{
|
||||
_low = low;
|
||||
_high = high;
|
||||
}
|
||||
|
||||
public static ObjectGuid Create(HighGuid type, ulong counter)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case HighGuid.Uniq:
|
||||
case HighGuid.Party:
|
||||
case HighGuid.WowAccount:
|
||||
case HighGuid.BNetAccount:
|
||||
case HighGuid.GMTask:
|
||||
case HighGuid.RaidGroup:
|
||||
case HighGuid.Spell:
|
||||
case HighGuid.Mail:
|
||||
case HighGuid.UserRouter:
|
||||
case HighGuid.PVPQueueGroup:
|
||||
case HighGuid.UserClient:
|
||||
case HighGuid.UniqUserClient:
|
||||
case HighGuid.BattlePet:
|
||||
case HighGuid.CommerceObj:
|
||||
case HighGuid.ClientSession:
|
||||
return GlobalCreate(type, counter);
|
||||
case HighGuid.Player:
|
||||
case HighGuid.Item: // This is not exactly correct, there are 2 more unknown parts in highguid: (high >> 10 & 0xFF), (high >> 18 & 0xFFFFFF)
|
||||
case HighGuid.Guild:
|
||||
case HighGuid.Transport:
|
||||
return RealmSpecificCreate(type, counter);
|
||||
default:
|
||||
Log.outError(LogFilter.Server, "This guid type cannot be constructed using Create(HighGuid: {0} ulong counter).", type);
|
||||
break;
|
||||
}
|
||||
return ObjectGuid.Empty;
|
||||
}
|
||||
public static ObjectGuid Create(HighGuid type, uint mapId, uint entry, ulong counter)
|
||||
{
|
||||
if (type == HighGuid.Transport)
|
||||
return ObjectGuid.Empty;
|
||||
|
||||
return MapSpecificCreate(type, 0, (ushort)mapId, 0, entry, counter);
|
||||
}
|
||||
|
||||
public static ObjectGuid Create(HighGuid type, SpellCastSource subType, uint mapId, uint entry, ulong counter) { return MapSpecificCreate(type, (byte)subType, (ushort)mapId, 0, entry, counter); }
|
||||
|
||||
static ObjectGuid GlobalCreate(HighGuid type, ulong counter)
|
||||
{
|
||||
return new ObjectGuid(((ulong)type << 58), counter);
|
||||
}
|
||||
static ObjectGuid RealmSpecificCreate(HighGuid type, ulong counter)
|
||||
{
|
||||
return new ObjectGuid(((ulong)type << 58 | (ulong)Global.WorldMgr.GetRealm().Id.Realm << 42), counter);
|
||||
}
|
||||
static ObjectGuid MapSpecificCreate(HighGuid type, byte subType, ushort mapId, uint serverId, uint entry, ulong counter)
|
||||
{
|
||||
return new ObjectGuid((((ulong)type << 58) | ((ulong)(Global.WorldMgr.GetRealm().Id.Realm & 0x1FFF) << 42) | ((ulong)(mapId & 0x1FFF) << 29) | ((ulong)(entry & 0x7FFFFF) << 6) | ((ulong)subType & 0x3F)),
|
||||
(((ulong)(serverId & 0xFFFFFF) << 40) | (counter & 0xFFFFFFFFFF)));
|
||||
}
|
||||
|
||||
public byte[] GetRawValue()
|
||||
{
|
||||
byte[] temp = new byte[16];
|
||||
var hiBytes = BitConverter.GetBytes(_high);
|
||||
var lowBytes = BitConverter.GetBytes(_low);
|
||||
for (var i = 0; i < temp.Length / 2; ++i)
|
||||
{
|
||||
temp[i] = hiBytes[i];
|
||||
temp[8 + i] = lowBytes[i];
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
public void SetRawValue(byte[] bytes)
|
||||
{
|
||||
_high = BitConverter.ToUInt64(bytes, 0);
|
||||
_low = BitConverter.ToUInt64(bytes, 8);
|
||||
}
|
||||
|
||||
public void SetRawValue(ulong high, ulong low) { _high = high; _low = low; }
|
||||
public void Clear() { _high = 0; _low = 0; }
|
||||
public ulong GetHighValue()
|
||||
{
|
||||
return _high;
|
||||
}
|
||||
public ulong GetLowValue()
|
||||
{
|
||||
return _low;
|
||||
}
|
||||
|
||||
public HighGuid GetHigh() { return (HighGuid)(_high >> 58); }
|
||||
byte GetSubType() { return (byte)(_high & 0x3F); }
|
||||
uint GetRealmId() { return (uint)((_high >> 42) & 0x1FFF); }
|
||||
uint GetServerId() { return (uint)((_low >> 40) & 0x1FFF); }
|
||||
uint GetMapId() { return (uint)((_high >> 29) & 0x1FFF); }
|
||||
public uint GetEntry() { return (uint)((_high >> 6) & 0x7FFFFF); }
|
||||
public ulong GetCounter() { return _low & 0xFFFFFFFFFF; }
|
||||
|
||||
public bool IsEmpty() { return _low == 0 && _high == 0; }
|
||||
public bool IsCreature() { return GetHigh() == HighGuid.Creature; }
|
||||
public bool IsPet() { return GetHigh() == HighGuid.Pet; }
|
||||
public bool IsVehicle() { return GetHigh() == HighGuid.Vehicle; }
|
||||
public bool IsCreatureOrPet() { return IsCreature() || IsPet(); }
|
||||
public bool IsCreatureOrVehicle() { return IsCreature() || IsVehicle(); }
|
||||
public bool IsAnyTypeCreature() { return IsCreature() || IsPet() || IsVehicle(); }
|
||||
public bool IsPlayer() { return !IsEmpty() && GetHigh() == HighGuid.Player; }
|
||||
public bool IsUnit() { return IsAnyTypeCreature() || IsPlayer(); }
|
||||
public bool IsItem() { return GetHigh() == HighGuid.Item; }
|
||||
public bool IsGameObject() { return GetHigh() == HighGuid.GameObject; }
|
||||
public bool IsDynamicObject() { return GetHigh() == HighGuid.DynamicObject; }
|
||||
public bool IsCorpse() { return GetHigh() == HighGuid.Corpse; }
|
||||
public bool IsAreaTrigger() { return GetHigh() == HighGuid.AreaTrigger; }
|
||||
public bool IsMOTransport() { return GetHigh() == HighGuid.Transport; }
|
||||
public bool IsAnyTypeGameObject() { return IsGameObject() || IsMOTransport(); }
|
||||
public bool IsParty() { return GetHigh() == HighGuid.Party; }
|
||||
public bool IsGuild() { return GetHigh() == HighGuid.Guild; }
|
||||
bool IsSceneObject() { return GetHigh() == HighGuid.SceneObject; }
|
||||
bool IsConversation() { return GetHigh() == HighGuid.Conversation; }
|
||||
bool IsCast() { return GetHigh() == HighGuid.Cast; }
|
||||
|
||||
public TypeId GetTypeId() { return GetTypeId(GetHigh()); }
|
||||
bool HasEntry() { return HasEntry(GetHigh()); }
|
||||
|
||||
public static bool operator <(ObjectGuid left, ObjectGuid right)
|
||||
{
|
||||
if (left._high < right._high)
|
||||
return true;
|
||||
else if (left._high > right._high)
|
||||
return false;
|
||||
|
||||
return left._low < right._low;
|
||||
}
|
||||
public static bool operator >(ObjectGuid left, ObjectGuid right)
|
||||
{
|
||||
if (left._high > right._high)
|
||||
return true;
|
||||
else if (left._high < right._high)
|
||||
return false;
|
||||
|
||||
return left._low > right._low;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string str = string.Format("GUID Full: 0x{0}, Type: {1}", _low, GetHigh());
|
||||
if (HasEntry())
|
||||
str += (IsPet() ? " Pet number: " : " Entry: ") + GetEntry() + " ";
|
||||
|
||||
str += " Low: " + GetCounter();
|
||||
return str;
|
||||
}
|
||||
|
||||
public static bool operator ==(ObjectGuid first, ObjectGuid other)
|
||||
{
|
||||
if (ReferenceEquals(first, other))
|
||||
return true;
|
||||
|
||||
if ((object)first == null || (object)other == null)
|
||||
return false;
|
||||
|
||||
return first.Equals(other);
|
||||
}
|
||||
|
||||
public static bool operator !=(ObjectGuid first, ObjectGuid other)
|
||||
{
|
||||
return !(first == other);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj != null && obj is ObjectGuid && Equals((ObjectGuid)obj);
|
||||
}
|
||||
|
||||
public bool Equals(ObjectGuid other)
|
||||
{
|
||||
return other._high == _high && other._low == _low;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return new { _high, _low }.GetHashCode();
|
||||
}
|
||||
|
||||
//Static Methods
|
||||
static TypeId GetTypeId(HighGuid high)
|
||||
{
|
||||
switch (high)
|
||||
{
|
||||
case HighGuid.Item:
|
||||
return TypeId.Item;
|
||||
case HighGuid.Creature:
|
||||
case HighGuid.Pet:
|
||||
case HighGuid.Vehicle:
|
||||
return TypeId.Unit;
|
||||
case HighGuid.Player:
|
||||
return TypeId.Player;
|
||||
case HighGuid.GameObject:
|
||||
case HighGuid.Transport:
|
||||
return TypeId.GameObject;
|
||||
case HighGuid.DynamicObject:
|
||||
return TypeId.DynamicObject;
|
||||
case HighGuid.Corpse:
|
||||
return TypeId.Corpse;
|
||||
case HighGuid.AreaTrigger:
|
||||
return TypeId.AreaTrigger;
|
||||
case HighGuid.SceneObject:
|
||||
return TypeId.SceneObject;
|
||||
case HighGuid.Conversation:
|
||||
return TypeId.Conversation;
|
||||
default:
|
||||
return TypeId.Object;
|
||||
}
|
||||
}
|
||||
static bool HasEntry(HighGuid high)
|
||||
{
|
||||
switch (high)
|
||||
{
|
||||
case HighGuid.GameObject:
|
||||
case HighGuid.Creature:
|
||||
case HighGuid.Pet:
|
||||
case HighGuid.Vehicle:
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public static bool IsMapSpecific(HighGuid high)
|
||||
{
|
||||
switch (high)
|
||||
{
|
||||
case HighGuid.Conversation:
|
||||
case HighGuid.Creature:
|
||||
case HighGuid.Vehicle:
|
||||
case HighGuid.Pet:
|
||||
case HighGuid.GameObject:
|
||||
case HighGuid.DynamicObject:
|
||||
case HighGuid.AreaTrigger:
|
||||
case HighGuid.Corpse:
|
||||
case HighGuid.LootObject:
|
||||
case HighGuid.SceneObject:
|
||||
case HighGuid.Scenario:
|
||||
case HighGuid.AIGroup:
|
||||
case HighGuid.DynamicDoor:
|
||||
case HighGuid.Vignette:
|
||||
case HighGuid.CallForHelp:
|
||||
case HighGuid.AIResource:
|
||||
case HighGuid.AILock:
|
||||
case HighGuid.AILockTicket:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static bool IsRealmSpecific(HighGuid high)
|
||||
{
|
||||
switch (high)
|
||||
{
|
||||
case HighGuid.Player:
|
||||
case HighGuid.Item:
|
||||
case HighGuid.Transport:
|
||||
case HighGuid.Guild:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static bool IsGlobal(HighGuid high)
|
||||
{
|
||||
switch (high)
|
||||
{
|
||||
case HighGuid.Uniq:
|
||||
case HighGuid.Party:
|
||||
case HighGuid.WowAccount:
|
||||
case HighGuid.BNetAccount:
|
||||
case HighGuid.GMTask:
|
||||
case HighGuid.RaidGroup:
|
||||
case HighGuid.Spell:
|
||||
case HighGuid.Mail:
|
||||
case HighGuid.UserRouter:
|
||||
case HighGuid.PVPQueueGroup:
|
||||
case HighGuid.UserClient:
|
||||
case HighGuid.UniqUserClient:
|
||||
case HighGuid.BattlePet:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ulong _low;
|
||||
ulong _high;
|
||||
}
|
||||
|
||||
public class ObjectGuidGenerator
|
||||
{
|
||||
public ObjectGuidGenerator(HighGuid highGuid, ulong start = 1)
|
||||
{
|
||||
_highGuid = highGuid;
|
||||
_nextGuid = start;
|
||||
}
|
||||
|
||||
public void Set(ulong val) { _nextGuid = val; }
|
||||
|
||||
public ulong Generate()
|
||||
{
|
||||
if (_nextGuid >= ulong.MaxValue - 1)
|
||||
HandleCounterOverflow();
|
||||
return _nextGuid++;
|
||||
}
|
||||
|
||||
public ulong GetNextAfterMaxUsed() { return _nextGuid; }
|
||||
|
||||
void HandleCounterOverflow()
|
||||
{
|
||||
Log.outFatal(LogFilter.Server, "{0} guid overflow!! Can't continue, shutting down server. ", _highGuid);
|
||||
Global.WorldMgr.StopNow();
|
||||
}
|
||||
|
||||
ulong _nextGuid;
|
||||
HighGuid _highGuid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,372 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.GameMath;
|
||||
using Game.Maps;
|
||||
using System;
|
||||
|
||||
namespace Game.Entities
|
||||
{
|
||||
public class Position
|
||||
{
|
||||
public Position(float x = 0f, float y = 0f, float z = 0f, float o = 0f)
|
||||
{
|
||||
posX = x;
|
||||
posY = y;
|
||||
posZ = z;
|
||||
Orientation = o;
|
||||
}
|
||||
|
||||
public float GetPositionX()
|
||||
{
|
||||
return posX;
|
||||
}
|
||||
public float GetPositionY()
|
||||
{
|
||||
return posY;
|
||||
}
|
||||
public float GetPositionZ()
|
||||
{
|
||||
return posZ;
|
||||
}
|
||||
public float GetOrientation()
|
||||
{
|
||||
return Orientation;
|
||||
}
|
||||
|
||||
public void Relocate(float x, float y)
|
||||
{
|
||||
posX = x;
|
||||
posY = y;
|
||||
}
|
||||
public void Relocate(float x, float y, float z)
|
||||
{
|
||||
posX = x;
|
||||
posY = y;
|
||||
posZ = z;
|
||||
}
|
||||
public void Relocate(float x, float y, float z, float o)
|
||||
{
|
||||
posX = x;
|
||||
posY = y;
|
||||
posZ = z;
|
||||
SetOrientation(o);
|
||||
}
|
||||
public void Relocate(Position loc)
|
||||
{
|
||||
Relocate(loc.posX, loc.posY, loc.posZ, loc.Orientation);
|
||||
}
|
||||
public void Relocate(Vector3 pos)
|
||||
{
|
||||
Relocate(pos.X, pos.Y, pos.Z);
|
||||
}
|
||||
public void RelocateOffset(Position offset)
|
||||
{
|
||||
posX = (float)(posX + (offset.posX * Math.Cos(Orientation) + offset.posY * Math.Sin(Orientation + MathFunctions.PI)));
|
||||
posY = (float)(posY + (offset.posY * Math.Cos(Orientation) + offset.posX * Math.Sin(Orientation)));
|
||||
posZ = posZ + offset.posZ;
|
||||
SetOrientation(Orientation + offset.Orientation);
|
||||
}
|
||||
|
||||
public bool IsPositionValid()
|
||||
{
|
||||
return GridDefines.IsValidMapCoord(posX, posY, posZ, Orientation);
|
||||
}
|
||||
|
||||
public float GetRelativeAngle(Position pos)
|
||||
{
|
||||
return GetAngle(pos) - Orientation;
|
||||
}
|
||||
public float GetRelativeAngle(float x, float y)
|
||||
{
|
||||
return GetAngle(x, y) - Orientation;
|
||||
}
|
||||
|
||||
public void GetPosition(out float x, out float y)
|
||||
{
|
||||
x = posX; y = posY;
|
||||
}
|
||||
public void GetPosition(out float x, out float y, out float z)
|
||||
{
|
||||
x = posX; y = posY; z = posZ;
|
||||
}
|
||||
public void GetPosition(out float x, out float y, out float z, out float o)
|
||||
{
|
||||
x = posX;
|
||||
y = posY;
|
||||
z = posZ;
|
||||
o = Orientation;
|
||||
}
|
||||
public Position GetPosition()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public void GetPositionOffsetTo(Position endPos, out Position retOffset)
|
||||
{
|
||||
retOffset = new Position();
|
||||
|
||||
float dx = endPos.GetPositionX() - GetPositionX();
|
||||
float dy = endPos.GetPositionY() - GetPositionY();
|
||||
|
||||
retOffset.posX = (float)(dx * Math.Cos(GetOrientation()) + dy * Math.Sin(GetOrientation()));
|
||||
retOffset.posY = (float)(dy * Math.Cos(GetOrientation()) - dx * Math.Sin(GetOrientation()));
|
||||
retOffset.posZ = endPos.GetPositionZ() - GetPositionZ();
|
||||
retOffset.SetOrientation(endPos.GetOrientation() - GetOrientation());
|
||||
}
|
||||
|
||||
public Position GetPositionWithOffset(Position offset)
|
||||
{
|
||||
Position ret = this;
|
||||
ret.RelocateOffset(offset);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static float NormalizeOrientation(float o)
|
||||
{
|
||||
// fmod only supports positive numbers. Thus we have
|
||||
// to emulate negative numbers
|
||||
if (o < 0)
|
||||
{
|
||||
float mod = o * -1;
|
||||
mod = mod % (2.0f * MathFunctions.PI);
|
||||
mod = -mod + 2.0f * MathFunctions.PI;
|
||||
return mod;
|
||||
}
|
||||
return o % (2.0f * MathFunctions.PI);
|
||||
}
|
||||
|
||||
public float GetExactDist(float x, float y, float z)
|
||||
{
|
||||
return (float)Math.Sqrt(GetExactDistSq(x, y, z));
|
||||
}
|
||||
public float GetExactDist(Position pos)
|
||||
{
|
||||
return (float)Math.Sqrt(GetExactDistSq(pos));
|
||||
}
|
||||
public float GetExactDistSq(float x, float y, float z)
|
||||
{
|
||||
float dz = posZ - z;
|
||||
|
||||
return GetExactDist2dSq(x, y) + dz * dz;
|
||||
}
|
||||
public float GetExactDistSq(Position pos)
|
||||
{
|
||||
float dx = posX - pos.posX;
|
||||
float dy = posY - pos.posY;
|
||||
float dz = posZ - pos.posZ;
|
||||
|
||||
return dx * dx + dy * dy + dz * dz;
|
||||
}
|
||||
public float GetExactDist2d(float x, float y)
|
||||
{
|
||||
return (float)Math.Sqrt(GetExactDist2dSq(x, y));
|
||||
}
|
||||
public float GetExactDist2d(Position pos)
|
||||
{
|
||||
return (float)Math.Sqrt(GetExactDist2dSq(pos));
|
||||
}
|
||||
public float GetExactDist2dSq(float x, float y)
|
||||
{
|
||||
float dx = posX - x;
|
||||
float dy = posY - y;
|
||||
|
||||
return dx * dx + dy * dy;
|
||||
}
|
||||
public float GetExactDist2dSq(Position pos)
|
||||
{
|
||||
float dx = posX - pos.posX;
|
||||
float dy = posY - pos.posY;
|
||||
|
||||
return dx * dx + dy * dy;
|
||||
}
|
||||
|
||||
public float GetAngle(float x, float y)
|
||||
{
|
||||
float dx = x - GetPositionX();
|
||||
float dy = y - GetPositionY();
|
||||
|
||||
float ang = (float)Math.Atan2(dy, dx);
|
||||
ang = ang >= 0 ? ang : 2 * MathFunctions.PI + ang;
|
||||
return ang;
|
||||
}
|
||||
public float GetAngle(Position pos)
|
||||
{
|
||||
if (pos == null)
|
||||
return 0;
|
||||
|
||||
return GetAngle(pos.GetPositionX(), pos.GetPositionY());
|
||||
}
|
||||
|
||||
public bool IsInDist(float x, float y, float z, float dist)
|
||||
{
|
||||
return GetExactDistSq(x, y, z) < dist * dist;
|
||||
}
|
||||
public bool IsInDist(Position pos, float dist)
|
||||
{
|
||||
return GetExactDistSq(pos) < dist * dist;
|
||||
}
|
||||
|
||||
public bool IsInDist2d(float x, float y, float dist)
|
||||
{
|
||||
return GetExactDist2dSq(x, y) < dist * dist;
|
||||
}
|
||||
public bool IsInDist2d(Position pos, float dist)
|
||||
{
|
||||
return GetExactDist2dSq(pos) < dist * dist;
|
||||
}
|
||||
|
||||
public void SetOrientation(float orientation)
|
||||
{
|
||||
Orientation = NormalizeOrientation(orientation);
|
||||
}
|
||||
|
||||
public bool IsWithinBox(Position center, float xradius, float yradius, float zradius)
|
||||
{
|
||||
// rotate the WorldObject position instead of rotating the whole cube, that way we can make a simplified
|
||||
// is-in-cube check and we have to calculate only one point instead of 4
|
||||
|
||||
// 2PI = 360*, keep in mind that ingame orientation is counter-clockwise
|
||||
double rotation = 2 * Math.PI - center.GetOrientation();
|
||||
double sinVal = Math.Sin(rotation);
|
||||
double cosVal = Math.Cos(rotation);
|
||||
|
||||
float BoxDistX = GetPositionX() - center.GetPositionX();
|
||||
float BoxDistY = GetPositionY() - center.GetPositionY();
|
||||
|
||||
float rotX = (float)(center.GetPositionX() + BoxDistX * cosVal - BoxDistY * sinVal);
|
||||
float rotY = (float)(center.GetPositionY() + BoxDistY * cosVal + BoxDistX * sinVal);
|
||||
|
||||
// box edges are parallel to coordiante axis, so we can treat every dimension independently :D
|
||||
float dz = GetPositionZ() - center.GetPositionZ();
|
||||
float dx = rotX - center.GetPositionX();
|
||||
float dy = rotY - center.GetPositionY();
|
||||
if ((Math.Abs(dx) > xradius) || (Math.Abs(dy) > yradius) || (Math.Abs(dz) > zradius))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
public bool HasInArc(float arc, Position obj, float border = 2.0f)
|
||||
{
|
||||
// always have self in arc
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
float angle = GetAngle(obj);
|
||||
angle -= GetOrientation();
|
||||
|
||||
// move angle to range -pi ... +pi
|
||||
if (angle > MathFunctions.PI)
|
||||
angle -= 2.0f * MathFunctions.PI;
|
||||
|
||||
float lborder = -1 * (arc / border); // in range -pi..0
|
||||
float rborder = (arc / border); // in range 0..pi
|
||||
return ((angle >= lborder) && (angle <= rborder));
|
||||
}
|
||||
public void GetSinCos(float x, float y, out float vsin, out float vcos)
|
||||
{
|
||||
float dx = GetPositionX() - x;
|
||||
float dy = GetPositionY() - y;
|
||||
|
||||
if (Math.Abs(dx) < 0.001f && Math.Abs(dy) < 0.001f)
|
||||
{
|
||||
float angle = (float)RandomHelper.NextDouble() * MathFunctions.TwoPi;
|
||||
vcos = (float)Math.Cos(angle);
|
||||
vsin = (float)Math.Sin(angle);
|
||||
}
|
||||
else
|
||||
{
|
||||
float dist = (float)Math.Sqrt((dx * dx) + (dy * dy));
|
||||
vcos = dx / dist;
|
||||
vsin = dy / dist;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("X: {0} Y: {1} Z: {2} O: {3}", posX, posY, posZ, Orientation);
|
||||
}
|
||||
|
||||
public float posX;
|
||||
public float posY;
|
||||
public float posZ;
|
||||
public float Orientation;
|
||||
}
|
||||
|
||||
public class WorldLocation : Position
|
||||
{
|
||||
public WorldLocation(uint mapId = 0xFFFFFFFF, float x = 0, float y = 0, float z = 0, float o = 0)
|
||||
{
|
||||
_mapId = mapId;
|
||||
Relocate(x, y, z, o);
|
||||
}
|
||||
public WorldLocation(uint mapId, Position pos)
|
||||
{
|
||||
_mapId = mapId;
|
||||
Relocate(pos);
|
||||
}
|
||||
public WorldLocation(WorldLocation loc)
|
||||
{
|
||||
_mapId = loc._mapId;
|
||||
Relocate(loc);
|
||||
}
|
||||
public WorldLocation(Position pos)
|
||||
{
|
||||
_mapId = 0xFFFFFFFF;
|
||||
Relocate(pos);
|
||||
}
|
||||
|
||||
public void WorldRelocate(WorldLocation loc)
|
||||
{
|
||||
_mapId = loc._mapId;
|
||||
Relocate(loc);
|
||||
}
|
||||
|
||||
public void WorldRelocate(uint mapId = 0xFFFFFFFF, float x = 0.0f, float y = 0.0f, float z = 0.0f, float o = 0.0f)
|
||||
{
|
||||
_mapId = mapId;
|
||||
Relocate(x, y, z, o);
|
||||
}
|
||||
|
||||
public uint GetMapId() { return _mapId; }
|
||||
public void SetMapId(uint _mapId) { this._mapId = _mapId; }
|
||||
|
||||
public Cell GetCurrentCell()
|
||||
{
|
||||
if (currentCell == null)
|
||||
Log.outError(LogFilter.Server, "Calling currentCell but its null");
|
||||
|
||||
return currentCell;
|
||||
}
|
||||
public void SetCurrentCell(Cell cell) { currentCell = cell; }
|
||||
public void SetNewCellPosition(float x, float y, float z, float o)
|
||||
{
|
||||
_moveState = ObjectCellMoveState.Active;
|
||||
_newPosition.Relocate(x, y, z, o);
|
||||
}
|
||||
|
||||
public WorldLocation GetWorldLocation()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
uint _mapId;
|
||||
Cell currentCell;
|
||||
public ObjectCellMoveState _moveState;
|
||||
|
||||
public Position _newPosition = new Position();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.IO;
|
||||
using Game.Network;
|
||||
using Game.Network.Packets;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Game.Entities
|
||||
{
|
||||
public class UpdateData
|
||||
{
|
||||
public UpdateData(uint mapId)
|
||||
{
|
||||
MapId = mapId;
|
||||
}
|
||||
|
||||
public void AddOutOfRangeGUID(List<ObjectGuid> guids)
|
||||
{
|
||||
outOfRangeGUIDs.AddRange(guids);
|
||||
}
|
||||
|
||||
public void AddOutOfRangeGUID(ObjectGuid guid)
|
||||
{
|
||||
outOfRangeGUIDs.Add(guid);
|
||||
}
|
||||
|
||||
public void AddUpdateBlock(ByteBuffer block)
|
||||
{
|
||||
data.WriteBytes(block.GetData());
|
||||
++BlockCount;
|
||||
}
|
||||
|
||||
public bool BuildPacket(out UpdateObject packet)
|
||||
{
|
||||
packet = new UpdateObject();
|
||||
|
||||
packet.NumObjUpdates = BlockCount;
|
||||
packet.MapID = (ushort)MapId;
|
||||
|
||||
WorldPacket buffer = new WorldPacket();
|
||||
if (buffer.WriteBit(!outOfRangeGUIDs.Empty()))
|
||||
{
|
||||
buffer.WriteUInt16(0); // object limit to instantly destroy - objects before this index on m_outOfRangeGUIDs list get "smoothly phased out"
|
||||
buffer.WriteUInt32(outOfRangeGUIDs.Count);
|
||||
|
||||
foreach (var guid in outOfRangeGUIDs)
|
||||
buffer.WritePackedGuid(guid);
|
||||
}
|
||||
var bytes = data.GetData();
|
||||
buffer.WriteUInt32(bytes.Length);
|
||||
buffer.WriteBytes(bytes);
|
||||
|
||||
packet.Data = buffer.GetData();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
data.Clear();
|
||||
outOfRangeGUIDs.Clear();
|
||||
BlockCount = 0;
|
||||
MapId = 0;
|
||||
}
|
||||
|
||||
public bool HasData() { return BlockCount > 0 || outOfRangeGUIDs.Count != 0; }
|
||||
|
||||
public List<ObjectGuid> GetOutOfRangeGUIDs() { return outOfRangeGUIDs; }
|
||||
|
||||
public void SetMapId(ushort mapId) { MapId = mapId; }
|
||||
|
||||
uint MapId;
|
||||
uint BlockCount;
|
||||
List<ObjectGuid> outOfRangeGUIDs = new List<ObjectGuid>();
|
||||
ByteBuffer data = new ByteBuffer();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
using System.Collections;
|
||||
using System;
|
||||
|
||||
namespace Game.Entities
|
||||
{
|
||||
public class UpdateMask
|
||||
{
|
||||
public UpdateMask(uint valuesCount = 0)
|
||||
{
|
||||
_fieldCount = valuesCount;
|
||||
_blockCount = (valuesCount + 32 - 1) / 32;
|
||||
|
||||
_mask = new BitArray((int)valuesCount, false);
|
||||
}
|
||||
|
||||
public void SetCount(int valuesCount)
|
||||
{
|
||||
_fieldCount = (uint)valuesCount;
|
||||
_blockCount = (uint)(valuesCount + 32 - 1) / 32;
|
||||
|
||||
_mask = new BitArray((int)valuesCount, false);
|
||||
}
|
||||
|
||||
public uint GetCount() { return _fieldCount; }
|
||||
|
||||
public virtual void AppendToPacket(ByteBuffer data)
|
||||
{
|
||||
data.WriteUInt8(_blockCount);
|
||||
var maskArray = new byte[_blockCount << 2];
|
||||
|
||||
_mask.CopyTo(maskArray, 0);
|
||||
data.WriteBytes(maskArray);
|
||||
}
|
||||
|
||||
public bool GetBit(int index)
|
||||
{
|
||||
return _mask.Get(index);
|
||||
}
|
||||
|
||||
public void SetBit(int index)
|
||||
{
|
||||
_mask.Set(index, true);
|
||||
}
|
||||
|
||||
void UnsetBit(int index)
|
||||
{
|
||||
_mask.Set(index, false);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_mask.SetAll(false);
|
||||
}
|
||||
|
||||
protected uint _fieldCount;
|
||||
protected uint _blockCount;
|
||||
protected BitArray _mask;
|
||||
}
|
||||
|
||||
public class DynamicUpdateMask : UpdateMask
|
||||
{
|
||||
public DynamicUpdateMask(uint valuesCount) : base(valuesCount) { }
|
||||
|
||||
public void EncodeDynamicFieldChangeType(DynamicFieldChangeType changeType, UpdateType updateType)
|
||||
{
|
||||
DynamicFieldChangeType = (uint)(_blockCount | ((uint)(changeType & Entities.DynamicFieldChangeType.ValueAndSizeChanged) * ((3 - (int)updateType /*this part evaluates to 0 if update type is not VALUES*/) / 3)));
|
||||
}
|
||||
|
||||
public override void AppendToPacket(ByteBuffer data)
|
||||
{
|
||||
data.WriteUInt16(DynamicFieldChangeType);
|
||||
if (DynamicFieldChangeType.HasAnyFlag((uint)Entities.DynamicFieldChangeType.ValueAndSizeChanged))
|
||||
data.WriteUInt32(_fieldCount);
|
||||
|
||||
var maskArray = new byte[_blockCount << 2];
|
||||
|
||||
_mask.CopyTo(maskArray, 0);
|
||||
data.WriteBytes(maskArray);
|
||||
}
|
||||
|
||||
public uint DynamicFieldChangeType;
|
||||
}
|
||||
|
||||
public enum DynamicFieldChangeType
|
||||
{
|
||||
Unchanged = 0,
|
||||
ValueChanged = 0x7FFF,
|
||||
ValueAndSizeChanged = 0x8000
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user