38a12bd3fa
revert Merge pull request 'feature/movement' (#22) from feature/movement into develop Reviewed-on: https://git.brew.monster/Unity/perfect-world-unity/pulls/22 mất package
131 lines
3.6 KiB
C#
131 lines
3.6 KiB
C#
using BrewMonster;
|
|
using CSNetwork.GPDataType;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Runtime.InteropServices;
|
|
using UnityEngine;
|
|
using static EC_Player;
|
|
|
|
public static class EC_Utility
|
|
{
|
|
public static byte glb_CompressDirH(float x, float z)
|
|
{
|
|
const float fInvInter = 256.0f / 360.0f;
|
|
|
|
if (Math.Abs(x) < 0.00001f)
|
|
{
|
|
if (z > 0.0f)
|
|
return 64;
|
|
else
|
|
return 192;
|
|
}
|
|
else
|
|
{
|
|
// atan2 trong C# trả về radian, cần đổi sang độ
|
|
float fDeg = (float)(Math.Atan2(z, x) * (180.0 / Math.PI));
|
|
|
|
// đảm bảo góc nằm trong [0, 360)
|
|
if (fDeg < 0)
|
|
fDeg += 360.0f;
|
|
|
|
return (byte)(fDeg * fInvInter);
|
|
}
|
|
}
|
|
public static float FIX8TOFLOAT(int x) => x / 256.0f;
|
|
public static T ByteArrayToStructure<T>(byte[] bytes) where T : struct
|
|
{
|
|
GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
|
|
try
|
|
{
|
|
return Marshal.PtrToStructure<T>(handle.AddrOfPinnedObject());
|
|
}
|
|
finally
|
|
{
|
|
handle.Free();
|
|
}
|
|
}
|
|
public static Vector3 glb_DecompressDirH(byte byDir)
|
|
{
|
|
const float fInter = 360.0f / 256.0f;
|
|
float fRad = Mathf.Deg2Rad * (byDir * fInter);
|
|
|
|
Vector3 v;
|
|
v.x = Mathf.Cos(fRad);
|
|
v.z = Mathf.Sin(fRad);
|
|
v.y = 0.0f;
|
|
|
|
return v;
|
|
}
|
|
public static System.Numerics.Vector3 ToNumerics(this UnityEngine.Vector3 v)
|
|
{
|
|
return new System.Numerics.Vector3(v.x, v.y, v.z);
|
|
}
|
|
public static A3DVECTOR3 ToA3DVECTOR3(this UnityEngine.Vector3 v)
|
|
{
|
|
return new A3DVECTOR3(v.x, v.y, v.z);
|
|
}
|
|
public static Vector3 ToVector3(A3DVECTOR3 a3DVECTOR3)
|
|
{
|
|
return new Vector3(a3DVECTOR3.x, a3DVECTOR3.y, a3DVECTOR3.z);
|
|
}
|
|
public static float MagnitudeH(this Vector3 v)
|
|
{
|
|
return Mathf.Sqrt(v.x * v.x + v.z * v.z);
|
|
}
|
|
public static string BuildActionName(PLAYER_ACTION action, int weaponType)
|
|
{
|
|
string prefix = action.data.ActionPrefix ?? string.Empty;
|
|
string suffix = string.Empty;
|
|
|
|
if (action.data.action_weapon_suffix != null
|
|
&& weaponType >= 0
|
|
&& weaponType < action.data.action_weapon_suffix.Length)
|
|
{
|
|
suffix = action.data.action_weapon_suffix[weaponType].Suffix ?? string.Empty;
|
|
}
|
|
|
|
return $"{prefix}_{suffix}";
|
|
}
|
|
|
|
// Build pvp mask
|
|
public static byte glb_BuildPVPMask(bool bForceAttack)
|
|
{
|
|
byte byMask = 0;
|
|
if (bForceAttack)
|
|
byMask |= (byte)PVP_mask.GP_PVPMASK_FORCE;
|
|
//else
|
|
//{
|
|
// CECConfigs* pConfigs = g_pGame->GetConfigs();
|
|
|
|
// if (pConfigs->GetGameSettings().bAtk_Player)
|
|
// {
|
|
// byMask |= GP_PVPMASK_FORCE;
|
|
|
|
// if (pConfigs->GetGameSettings().bAtk_NoMafia)
|
|
// byMask |= GP_PVPMASK_NOMAFIA;
|
|
|
|
// if (pConfigs->GetGameSettings().bAtk_NoWhite)
|
|
// byMask |= GP_PVPMASK_NOWHITE;
|
|
|
|
// if (pConfigs->GetGameSettings().bAtk_NoAlliance)
|
|
// byMask |= GP_PVPMASK_NOALLIANCE;
|
|
|
|
// if (pConfigs->GetGameSettings().bAtk_NoForce)
|
|
// byMask |= GP_PVPMASK_NOFORCE;
|
|
// }
|
|
//}
|
|
|
|
return byMask;
|
|
}
|
|
|
|
public static T a_ClampFloor<T>(T x, T min) where T : IComparable<T>
|
|
{
|
|
return (x.CompareTo(min) < 0) ? min : x;
|
|
}
|
|
|
|
public static T a_Min<T>(T x, T y) where T : IComparable<T>
|
|
{
|
|
return (y.CompareTo(x) < 0) ? y : x;
|
|
}
|
|
}
|