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());
CreateConcomitants(entity);
// Give weapon to entity
RoleInfoConfig roleConfig = _configManager.GetConfig<RoleInfoConfig>(entity.ConfigId)!;
WeaponConfig weaponConfig = _configManager.GetConfig<WeaponConfig>(roleConfig.InitWeaponItemId)!;
entity.WeaponId = weaponConfig.ItemId;
entity.WeaponId = _modelManager.Inventory.GetEquippedWeapon(roleId)?.Id ?? 0;
if (i == 0) _modelManager.Creature.PlayerEntityId = entity.Id;
}

View file

@ -91,32 +91,8 @@ internal class InventoryController : Controller
});
}
// Notify to take off previous one
{
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
// Response
EquipTakeOnResponse response = new()
{
DataList =
{
@ -127,7 +103,17 @@ internal class InventoryController : Controller
EquipIncId = request.Data.EquipIncId
}
}
});
};
if (prevWeapon != null)
{
response.DataList.Add(new RoleLoadEquipData
{
EquipIncId = prevWeapon.IncrId
});
}
return Response(MessageId.EquipTakeOnResponse, response);
}
[GameEvent(GameEventType.EnterGame)]

View file

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