76 lines
2.7 KiB
C#
76 lines
2.7 KiB
C#
using DataServer.Data.Entities;
|
|
using DataServer.Data.Enums;
|
|
|
|
namespace GameServer.Dungeon;
|
|
|
|
public class NpcInstance
|
|
{
|
|
public int Id { get; set; }
|
|
public int DefinitionId { get; set; }
|
|
public string Name { get; set; } = "";
|
|
|
|
public float X { get; set; }
|
|
public float Y { get; set; }
|
|
public float SpawnX { get; set; }
|
|
public float SpawnY { get; set; }
|
|
public float Rotation { get; set; }
|
|
|
|
public int Level { get; set; } = 1;
|
|
public int Health { get; set; } = 100;
|
|
public int MaxHealth { get; set; } = 100;
|
|
public bool IsAlive { get; set; } = true;
|
|
public bool IsKillable { get; set; } = true;
|
|
public bool CanShop { get; set; } = false;
|
|
public bool HasDialog { get; set; } = false;
|
|
public bool CanWander { get; set; } = true;
|
|
|
|
public NpcBehaviorMode BehaviorMode { get; set; } = NpcBehaviorMode.Wander;
|
|
public NpcOnAttackBehavior OnAttackBehavior { get; set; } = NpcOnAttackBehavior.FightBack;
|
|
|
|
public float WanderRadiusPx { get; set; } = 96f;
|
|
public float WanderIntervalSeconds { get; set; } = 2.5f;
|
|
public float NextWanderIn { get; set; } = 2.5f;
|
|
|
|
public int? LootTableId { get; set; }
|
|
public int? ShopId { get; set; }
|
|
public int? DialogTreeId { get; set; }
|
|
|
|
public string CurrentAnimation { get; set; } = "idle_down";
|
|
public string? SpriteConfigJson { get; set; }
|
|
public string TintColor { get; set; } = "#ffffff";
|
|
public float Scale { get; set; } = 1f;
|
|
|
|
public static NpcInstance FromDefinition(DungeonNpcDefinition def, int id, float x, float y)
|
|
{
|
|
return new NpcInstance
|
|
{
|
|
Id = id,
|
|
DefinitionId = def.Id,
|
|
Name = def.Name,
|
|
X = x,
|
|
Y = y,
|
|
SpawnX = x,
|
|
SpawnY = y,
|
|
Level = Math.Max(1, def.Level),
|
|
Health = Math.Max(1, def.MaxHealth),
|
|
MaxHealth = Math.Max(1, def.MaxHealth),
|
|
IsKillable = def.IsKillable,
|
|
CanShop = def.CanShop,
|
|
HasDialog = def.HasDialog,
|
|
CanWander = def.CanWander,
|
|
BehaviorMode = def.BehaviorMode,
|
|
OnAttackBehavior = def.OnAttackBehavior,
|
|
WanderRadiusPx = Math.Max(0f, def.WanderRadiusPx),
|
|
WanderIntervalSeconds = Math.Max(0.25f, def.WanderIntervalSeconds),
|
|
NextWanderIn = Math.Max(0.25f, def.WanderIntervalSeconds),
|
|
LootTableId = def.LootTableId,
|
|
ShopId = def.ShopId,
|
|
DialogTreeId = def.DialogTreeId,
|
|
SpriteConfigJson = def.SpriteConfigJson,
|
|
TintColor = string.IsNullOrWhiteSpace(def.TintColor) ? "#ffffff" : def.TintColor,
|
|
Scale = Math.Max(0.1f, def.Scale)
|
|
};
|
|
}
|
|
}
|
|
|