Set entity equipment properly

This commit is contained in:
xeon 2024-02-22 01:00:48 +03:00
parent 3e7ec6f8ad
commit a46dc434d8
3 changed files with 19 additions and 32 deletions

View file

@ -254,11 +254,7 @@ internal class CreatureController : Controller
entity.ComponentSystem.Get<EntityAttributeComponent>().SetAll(_modelManager.Roles.GetRoleById(roleId)!.GetAttributeList()); entity.ComponentSystem.Get<EntityAttributeComponent>().SetAll(_modelManager.Roles.GetRoleById(roleId)!.GetAttributeList());
CreateConcomitants(entity); CreateConcomitants(entity);
entity.WeaponId = _modelManager.Inventory.GetEquippedWeapon(roleId)?.Id ?? 0;
// Give weapon to entity
RoleInfoConfig roleConfig = _configManager.GetConfig<RoleInfoConfig>(entity.ConfigId)!;
WeaponConfig weaponConfig = _configManager.GetConfig<WeaponConfig>(roleConfig.InitWeaponItemId)!;
entity.WeaponId = weaponConfig.ItemId;
if (i == 0) _modelManager.Creature.PlayerEntityId = entity.Id; if (i == 0) _modelManager.Creature.PlayerEntityId = entity.Id;
} }

View file

@ -91,32 +91,8 @@ internal class InventoryController : Controller
}); });
} }
// Notify to take off previous one // Response
{ EquipTakeOnResponse response = new()
EquipTakeOnNotify equipTakeOnNotify = new()
{
DataList =
{
new RoleLoadEquipData
{
EquipIncId = weapon.IncrId,
RoleId = role.RoleId
}
}
};
if (prevWeapon != null)
{
equipTakeOnNotify.DataList.Add(new RoleLoadEquipData
{
EquipIncId = prevWeapon.IncrId
});
}
await Session.Push(MessageId.EquipTakeOnNotify, equipTakeOnNotify);
}
return Response(MessageId.EquipTakeOnResponse, new EquipTakeOnResponse
{ {
DataList = DataList =
{ {
@ -127,7 +103,17 @@ internal class InventoryController : Controller
EquipIncId = request.Data.EquipIncId EquipIncId = request.Data.EquipIncId
} }
} }
}); };
if (prevWeapon != null)
{
response.DataList.Add(new RoleLoadEquipData
{
EquipIncId = prevWeapon.IncrId
});
}
return Response(MessageId.EquipTakeOnResponse, response);
} }
[GameEvent(GameEventType.EnterGame)] [GameEvent(GameEventType.EnterGame)]

View file

@ -8,6 +8,11 @@ internal class InventoryModel
public List<WeaponItem> WeaponList { get; } = []; public List<WeaponItem> WeaponList { get; } = [];
public WeaponItem? GetEquippedWeapon(int roleId)
{
return WeaponList.SingleOrDefault(weapon => weapon.RoleId == roleId);
}
public WeaponItem? GetWeaponById(int incrId) public WeaponItem? GetWeaponById(int incrId)
{ {
return WeaponList.SingleOrDefault(weapon => weapon.IncrId == incrId); return WeaponList.SingleOrDefault(weapon => weapon.IncrId == incrId);