attempt to fix some misunderstanding
This commit is contained in:
parent
a639dd362e
commit
bace34bf50
4 changed files with 41 additions and 20 deletions
|
@ -15,7 +15,6 @@ namespace ZoFo.GameCore.GameObjects
|
|||
public class ExitZone : Entity
|
||||
{
|
||||
|
||||
|
||||
public override GraphicsComponent graphicsComponent { get; } = new StaticGraphicsComponent("Content/Textures/icons/ExitZone");
|
||||
public ExitZone(Vector2 position) : base(position)
|
||||
{
|
|
@ -13,6 +13,11 @@ namespace ZoFo.GameCore.GameObjects
|
|||
{
|
||||
public class Particle : GameObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Партиклы не хранятся на сервере
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override bool ShouldObjectBeStoredOnServer() => false;
|
||||
public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List<string> { "explosion_1" }, "explosion_1");
|
||||
|
||||
public Particle(Vector2 position) : base(position)
|
||||
|
@ -42,7 +47,7 @@ namespace ZoFo.GameCore.GameObjects
|
|||
/// <summary>
|
||||
/// TODO: change from particle to throwable, it is not a particle anymore
|
||||
/// </summary>
|
||||
public class Granade : GameObject
|
||||
public class Granade : Entity
|
||||
{
|
||||
public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List<string> { "explosion_1" }, "explosion_1");
|
||||
|
||||
|
|
|
@ -15,6 +15,9 @@ public abstract class GameObject
|
|||
public Vector2 rotation; //вектор направления объекта
|
||||
public virtual GraphicsComponent graphicsComponent { get; }
|
||||
|
||||
public virtual bool ShouldObjectBeStoredOnServer() => true;
|
||||
public virtual bool ShouldObjectBeStoredOnClient() => true;
|
||||
|
||||
#region ServerSide
|
||||
public GameObject(Vector2 position)
|
||||
{
|
||||
|
@ -54,7 +57,10 @@ public abstract class GameObject
|
|||
|
||||
#region Client Side
|
||||
|
||||
public void Start_OnClinet()
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// вызывается для создания объектов на клиенте,
|
||||
/// соответственно используется по большей часте для создания эффектов
|
||||
|
|
|
@ -189,8 +189,28 @@ namespace ZoFo.GameCore
|
|||
public void RegisterGameObject(GameObject gameObject)
|
||||
{
|
||||
|
||||
gameObjects.Add(gameObject);
|
||||
|
||||
//Частицы живут только на клиенте, значит тут только отправить на клиент
|
||||
if (gameObject is Particle)
|
||||
{
|
||||
|
||||
AddData(new UpdateGameObjectWithoutIdCreated()
|
||||
{
|
||||
GameObjectClassName = gameObject.GetType().Name,
|
||||
position = gameObject.position.Serialize()
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
//обраюотка всех объектов, которые живут на сервере долго. На сервере их надо будет удалять.
|
||||
if (gameObject.ShouldObjectBeStoredOnServer())
|
||||
gameObjects.Add(gameObject);
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//Карта грузится по отдельной логике, поэтому вынесено тут
|
||||
#region Map
|
||||
if (gameObject is StopObject)
|
||||
{
|
||||
AddData(new UpdateStopObjectCreated()
|
||||
|
@ -219,17 +239,10 @@ namespace ZoFo.GameCore
|
|||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (gameObject is Particle)
|
||||
{
|
||||
#endregion
|
||||
|
||||
AddData(new UpdateGameObjectWithoutIdCreated()
|
||||
{
|
||||
GameObjectClassName = gameObject.GetType().Name,
|
||||
position = gameObject.position.Serialize()
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
//Entity живут и на сервере и на клиенте, поэтому есть айдишник у них + у них есть коллизии
|
||||
if (gameObject is Entity entity)
|
||||
{
|
||||
AddData(new UpdateGameObjectCreated()
|
||||
|
@ -238,8 +251,10 @@ namespace ZoFo.GameCore
|
|||
IdEntity = entity.Id,
|
||||
position = gameObject.position.Serialize()
|
||||
});
|
||||
collisionManager.Register(entity.collisionComponent);
|
||||
entities.Add(entity);
|
||||
|
||||
|
||||
collisionManager.Register(entity.collisionComponent);
|
||||
}
|
||||
else
|
||||
AddData(new UpdateGameObjectCreated()
|
||||
|
@ -251,11 +266,6 @@ namespace ZoFo.GameCore
|
|||
|
||||
if (gameObject is Player)
|
||||
players.Add(gameObject as Player);
|
||||
////var elems = gameObject.GetType().GetProperties(System.Reflection.BindingFlags.Public);
|
||||
////if (elems.Count()>0) TODO
|
||||
////{
|
||||
//// AppManager.Instance.server.collisionManager.Register((elems.First().GetValue(gameObject) as CollisionComponent));
|
||||
////}
|
||||
|
||||
}
|
||||
|
||||
|
@ -265,6 +275,7 @@ namespace ZoFo.GameCore
|
|||
/// <param name="gameObject"></param>
|
||||
public void DeleteObject(Entity entity)
|
||||
{
|
||||
|
||||
if (gameObjects.Contains(entity))
|
||||
gameObjects.Remove(entity);
|
||||
if (entities.Contains(entity))
|
||||
|
|
Loading…
Add table
Reference in a new issue