yuanshen/Yuanshen.Gameserver/Game/GameMonster.cs
wisedev fc2ac1050f First working version of the server
KCP gameserver with packet dispatch, scene streaming, combat, gacha and the
shop, plus a small HTTP server for the login flow and the wish history page.

Game data under assets is pulled out of the client instead of being typed by
hand. The excel tables come from the packed bin container and the spawn points
from the compiled scene scripts.
2026-09-04 02:10:50 +03:00

95 lines
3.5 KiB
C#

using Yuanshen.Protocol;
namespace Yuanshen.Gameserver.Game;
internal sealed class GameMonster
{
public uint MonsterId { get; }
public uint EntityId { get; }
public uint NodeId { get; set; }
public uint ConfigId { get; set; }
public uint GroupId { get; set; }
public bool IsWildlife => MonsterId is >= 28000000 and < 29000000;
public Vector Pos { get; }
public uint Level { get; }
public float MaxHp { get; }
public float CurrentHp { get; private set; }
public int LevelSyncCount { get; set; }
public bool IsAlive => CurrentHp > 0;
private readonly float _attack;
private readonly float _defense;
public GameMonster(uint monsterId, uint entityId, Vector pos, uint level, float maxHp, float attack, float defense)
{
MonsterId = monsterId;
EntityId = entityId;
Pos = pos;
Level = level;
MaxHp = Math.Max(maxHp, 1f);
CurrentHp = MaxHp;
_attack = attack;
_defense = defense;
}
public float ApplyDamage(float damage)
{
CurrentHp = Math.Max(0f, CurrentHp - damage);
return CurrentHp;
}
public SceneEntityInfo AsSceneEntity()
{
SceneEntityInfo entity = new()
{
EntityType = ProtEntityType.ProtEntityMonster,
EntityId = EntityId,
LifeState = 1,
MotionInfo = new MotionInfo
{
Pos = Pos,
Rot = new Vector(),
Speed = new Vector(),
State = MotionState.MotionStandby
},
EntityClientData = new EntityClientData(),
EntityAuthorityInfo = new EntityAuthorityInfo
{
AbilityInfo = new AbilitySyncStateInfo { IsInited = true },
RendererChangedInfo = new EntityRendererChangedInfo(),
AiInfo = new SceneEntityAiInfo { IsAiOpen = true, BornPos = Pos },
BornPos = Pos
},
Monster = new SceneMonsterInfo
{
MonsterId = MonsterId,
AuthorityPeerId = Player.PeerId,
BornType = MonsterBornType.MonsterBornDefault,
GroupId = GroupId,
ConfigId = ConfigId != 0 ? ConfigId : EntityId
}
};
entity.PropList.Add(new PropPair
{
Type = 4001,
PropValue = new PropValue { Type = 4001, Ival = Level, Val = Level }
});
entity.FightPropList.Add(new FightPropPair { Type = 1, PropValue = MaxHp });
entity.FightPropList.Add(new FightPropPair { Type = 1010, PropValue = CurrentHp });
entity.FightPropList.Add(new FightPropPair { Type = 2000, PropValue = MaxHp });
entity.FightPropList.Add(new FightPropPair { Type = 4, PropValue = _attack });
entity.FightPropList.Add(new FightPropPair { Type = 2001, PropValue = _attack });
entity.FightPropList.Add(new FightPropPair { Type = 7, PropValue = _defense });
entity.FightPropList.Add(new FightPropPair { Type = 2002, PropValue = _defense });
entity.FightPropList.Add(new FightPropPair { Type = 5, PropValue = _attack });
entity.FightPropList.Add(new FightPropPair { Type = 8, PropValue = _defense });
entity.FightPropList.Add(new FightPropPair { Type = 29, PropValue = 0f });
for (uint resist = 50; resist <= 56; resist++)
entity.FightPropList.Add(new FightPropPair { Type = resist, PropValue = 0f });
return entity;
}
}