62 lines
1.2 KiB
C#
62 lines
1.2 KiB
C#
using Godot;
|
|
|
|
public class Character(Sector sector, Vector3 localCoordinates) : GameObject(sector, localCoordinates)
|
|
{
|
|
private Player player;
|
|
|
|
public bool SheduledUpdateNode = false;
|
|
|
|
public override void AssignSector(Sector sector)
|
|
{
|
|
CurrentSector = sector;
|
|
|
|
ResetLocalCoordinates();
|
|
UpdateSectorOffsetToMainPlayer();
|
|
UpdateNodePosition();
|
|
|
|
if (IsMainPlayer())
|
|
{
|
|
GameManager.Singleton.ApplyOrigin();
|
|
|
|
if (!Global.IsGameHost)
|
|
{
|
|
GameManager.Singleton.RpcId(
|
|
1,
|
|
nameof(GameManager.Singleton.RpcSendNearbySectors),
|
|
CurrentSector.Coordinates,
|
|
NetworkManager.Singleton.LocalNetId
|
|
);
|
|
}
|
|
}
|
|
|
|
reassigning = false;
|
|
}
|
|
|
|
public bool IsMainPlayer()
|
|
{
|
|
return player == GameManager.Singleton.MainPlayer;
|
|
}
|
|
|
|
public Player InstantiatePlayer()
|
|
{
|
|
PackedScene prefab = ResourceLoader.Load<PackedScene>("res://prefabs/gameObjects/player.tscn");
|
|
Player instance = prefab.Instantiate<Player>();
|
|
|
|
instance.PlayerData = this;
|
|
player = instance;
|
|
|
|
return instance;
|
|
}
|
|
|
|
public override void UpdateNodePosition()
|
|
{
|
|
if (IsMainPlayer())
|
|
{
|
|
player.GlobalPosition = LocalCoordinates;
|
|
}
|
|
else
|
|
{
|
|
player.GlobalPosition = LocalCoordinates + SectorOffset;
|
|
}
|
|
}
|
|
}
|