VSMod_AriasServerUtils/AriasServerUtils/PlayerData.cs

101 lines
No EOL
2.7 KiB
C#

using System;
using System.Collections.Generic;
using Vintagestory.API.Common;
using Vintagestory.API.Common.Entities;
using Vintagestory.API.MathTools;
namespace AriasServerUtils
{
[Serializable]
public class PlayerPosition
{
public int X { get; set; } = 0;
public int Y { get; set; } = 0;
public int Z { get; set; } = 0;
public int Dimension { get; set; } = 0;
public float Yaw { get; set; } = 0.0f;
public float Pitch { get; set; } = 0.0f;
public static readonly PlayerPosition ZERO = new(0, 0, 0, 0, 0.0f, 0.0f);
public PlayerPosition() { }
internal PlayerPosition(int x, int y, int z, int dim, float yaw, float pitch)
{
this.X = x;
this.Y = y;
this.Z = z;
this.Dimension = dim;
this.Yaw = yaw;
this.Pitch = pitch;
}
public void Merge(Entity entity)
{
entity.TeleportTo(new BlockPos(X, Y, Z, Dimension));
entity.Pos.SetYaw(Yaw);
entity.Pos.Pitch = Pitch;
}
/// <summary>
/// Generates a PlayerPosition object using a entity.
/// </summary>
/// <param name="entity">A player entity</param>
/// <returns>PlayerPos snapshot object of the entity</returns>
public static PlayerPosition from(Entity entity)
{
PlayerPosition pos = new PlayerPosition();
BlockPos playerPos = entity.Pos.AsBlockPos;
pos.X = playerPos.X;
pos.Y = playerPos.Y;
pos.Z = playerPos.Z;
pos.Dimension = playerPos.dimension;
pos.Yaw = entity.Pos.Yaw;
pos.Pitch = entity.Pos.Pitch;
return pos;
}
public PlayerPosition Clone()
{
return new PlayerPosition(this.X, this.Y, this.Z, this.Dimension, this.Yaw, this.Pitch);
}
}
public class PlayerInventory
{
public List<ItemStack> Items = new List<ItemStack>();
}
/// <summary>
/// This class creates a simple storage for all memory within this mod
/// </summary>
[Serializable]
public class PlayerStorage
{
public Dictionary<string, Home> Homes = new Dictionary<string, Home>();
public Dictionary<CooldownType, long> ActiveCooldowns = new();
}
/// <summary>
/// This class represents a single home object
/// </summary>
[Serializable]
public class Home
{
public PlayerPosition Location { get; set; }
public static Home MakeHome(Entity player, string homeName)
{
Home home = new Home();
home.Location = PlayerPosition.from(player);
return home;
}
}
}