Weapon stats + correct take on/off
This commit is contained in:
parent
1bd1931807
commit
3e7ec6f8ad
6 changed files with 124 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
|||
using Core.Config;
|
||||
using GameServer.Controllers.Attributes;
|
||||
using GameServer.Extensions.Logic;
|
||||
using GameServer.Models;
|
||||
using GameServer.Network;
|
||||
using GameServer.Network.Messages;
|
||||
|
@ -243,12 +244,14 @@ internal class CreatureController : Controller
|
|||
{
|
||||
for (int i = 0; i < _modelManager.Formation.RoleIds.Length; i++)
|
||||
{
|
||||
PlayerEntity entity = _entityFactory.CreatePlayer(_modelManager.Formation.RoleIds[i], _modelManager.Player.Id);
|
||||
int roleId = _modelManager.Formation.RoleIds[i];
|
||||
|
||||
PlayerEntity entity = _entityFactory.CreatePlayer(roleId, _modelManager.Player.Id);
|
||||
entity.Pos = _modelManager.Player.Position.Clone();
|
||||
entity.IsCurrentRole = i == 0;
|
||||
|
||||
_entitySystem.Create(entity);
|
||||
entity.InitProps(_configManager.GetConfig<BasePropertyConfig>(entity.ConfigId)!);
|
||||
entity.ComponentSystem.Get<EntityAttributeComponent>().SetAll(_modelManager.Roles.GetRoleById(roleId)!.GetAttributeList());
|
||||
|
||||
CreateConcomitants(entity);
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Core.Config;
|
||||
using GameServer.Controllers.Attributes;
|
||||
using GameServer.Extensions.Logic;
|
||||
using GameServer.Models;
|
||||
using GameServer.Network;
|
||||
using GameServer.Systems.Entity;
|
||||
|
@ -34,7 +35,7 @@ internal class InventoryController : Controller
|
|||
public RpcResult OnItemExchangeInfoRequest() => Response(MessageId.ItemExchangeInfoResponse, new ItemExchangeInfoResponse());
|
||||
|
||||
[NetEvent(MessageId.EquipTakeOnRequest)]
|
||||
public async Task<RpcResult> OnEquipTakeOnRequest(EquipTakeOnRequest request, ModelManager modelManager, CreatureController creatureController)
|
||||
public async Task<RpcResult> OnEquipTakeOnRequest(EquipTakeOnRequest request, ModelManager modelManager, CreatureController creatureController, ConfigManager configManager)
|
||||
{
|
||||
WeaponItem? weapon = modelManager.Inventory.GetWeaponById(request.Data.EquipIncId);
|
||||
if (weapon == null) return Response(MessageId.EquipTakeOnResponse, new EquipTakeOnResponse
|
||||
|
@ -42,9 +43,34 @@ internal class InventoryController : Controller
|
|||
ErrorCode = (int)ErrorCode.ErrItemIdInvaild
|
||||
});
|
||||
|
||||
WeaponConfig weaponConf = configManager.GetConfig<WeaponConfig>(weapon.Id)!;
|
||||
|
||||
roleInfo? role = modelManager.Roles.GetRoleById(request.Data.RoleId);
|
||||
if (role == null) return Response(MessageId.EquipTakeOnResponse, new EquipTakeOnResponse
|
||||
{
|
||||
ErrorCode = (int)ErrorCode.NotValidRole
|
||||
});
|
||||
|
||||
// Take off previous weapon
|
||||
WeaponItem? prevWeapon = modelManager.Inventory.WeaponList.SingleOrDefault(weapon => weapon.RoleId == role.RoleId);
|
||||
if (prevWeapon != null) prevWeapon.RoleId = 0;
|
||||
|
||||
// Set new weapon
|
||||
weapon.RoleId = role.RoleId;
|
||||
role.ApplyWeaponProperties(weaponConf);
|
||||
|
||||
// Update role prop data on client
|
||||
await Session.Push(MessageId.PbRolePropsNotify, new PbRolePropsNotify
|
||||
{
|
||||
RoleId = role.RoleId,
|
||||
BaseProp = { role.BaseProp },
|
||||
AddProp = { role.AddProp }
|
||||
});
|
||||
|
||||
PlayerEntity? entity = creatureController.GetPlayerEntityByRoleId(request.Data.RoleId);
|
||||
if (entity != null)
|
||||
{
|
||||
// Update entity equipment
|
||||
EntityEquipComponent equipComponent = entity.ComponentSystem.Get<EntityEquipComponent>();
|
||||
equipComponent.WeaponId = weapon.Id;
|
||||
|
||||
|
@ -53,6 +79,41 @@ internal class InventoryController : Controller
|
|||
EntityId = entity.Id,
|
||||
EquipComponent = equipComponent.Pb.EquipComponent
|
||||
});
|
||||
|
||||
// Update entity gameplay attributes
|
||||
EntityAttributeComponent attrComponent = entity.ComponentSystem.Get<EntityAttributeComponent>();
|
||||
attrComponent.SetAll(role.GetAttributeList());
|
||||
|
||||
await Session.Push(MessageId.AttributeChangedNotify, new AttributeChangedNotify
|
||||
{
|
||||
Id = entity.Id,
|
||||
Attributes = { attrComponent.Pb.AttributeComponent.GameAttributes }
|
||||
});
|
||||
}
|
||||
|
||||
// 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
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Core.Config;
|
||||
using GameServer.Controllers.Attributes;
|
||||
using GameServer.Extensions.Logic;
|
||||
using GameServer.Models;
|
||||
using GameServer.Network;
|
||||
using GameServer.Systems.Event;
|
||||
|
@ -23,6 +24,8 @@ internal class RoleController : Controller
|
|||
|
||||
WeaponItem weapon = modelManager.Inventory.AddNewWeapon(roleConfig.InitWeaponItemId);
|
||||
weapon.RoleId = role.RoleId;
|
||||
|
||||
role.ApplyWeaponProperties(configManager.GetConfig<WeaponConfig>(weapon.Id)!);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
39
GameServer/Extensions/Logic/RoleInfoExtensions.cs
Normal file
39
GameServer/Extensions/Logic/RoleInfoExtensions.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using Core.Config;
|
||||
using Protocol;
|
||||
|
||||
namespace GameServer.Extensions.Logic;
|
||||
internal static class RoleInfoExtensions
|
||||
{
|
||||
public static IEnumerable<GameplayAttributeData> GetAttributeList(this roleInfo role)
|
||||
{
|
||||
return role.BaseProp.Select(prop => new GameplayAttributeData
|
||||
{
|
||||
AttributeType = prop.Key,
|
||||
BaseValue = prop.Value,
|
||||
CurrentValue = prop.Value + ((role.AddProp.SingleOrDefault(p => p.Key == prop.Key)?.Value) ?? 0),
|
||||
});
|
||||
}
|
||||
|
||||
public static void ApplyWeaponProperties(this roleInfo role, WeaponConfig weaponConf)
|
||||
{
|
||||
role.AddProp.Clear();
|
||||
|
||||
if (weaponConf.FirstPropId != null)
|
||||
{
|
||||
role.AddProp.Add(new ArrayIntInt
|
||||
{
|
||||
Key = weaponConf.FirstPropId.Id,
|
||||
Value = (int)weaponConf.FirstPropId.Value
|
||||
});
|
||||
}
|
||||
|
||||
if (weaponConf.SecondPropId != null)
|
||||
{
|
||||
role.AddProp.Add(new ArrayIntInt
|
||||
{
|
||||
Key = weaponConf.SecondPropId.Id,
|
||||
Value = (int)weaponConf.SecondPropId.Value
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,6 +18,11 @@ internal class RoleModel
|
|||
return info;
|
||||
}
|
||||
|
||||
public roleInfo? GetRoleById(int roleId)
|
||||
{
|
||||
return Roles.SingleOrDefault(role => role.RoleId == roleId);
|
||||
}
|
||||
|
||||
private static List<ArrayIntInt> CreateBasePropList(BasePropertyConfig? config)
|
||||
{
|
||||
List<ArrayIntInt> baseProp = [];
|
||||
|
|
|
@ -12,6 +12,14 @@ internal class EntityAttributeComponent : EntityComponentBase
|
|||
_gameplayAttributes = [];
|
||||
}
|
||||
|
||||
public void SetAll(IEnumerable<GameplayAttributeData> attributes)
|
||||
{
|
||||
foreach (GameplayAttributeData attr in attributes)
|
||||
{
|
||||
SetAttribute((EAttributeType)attr.AttributeType, attr.CurrentValue, attr.BaseValue);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetAttribute(EAttributeType type, int currentValue, int baseValue)
|
||||
{
|
||||
if (!_gameplayAttributes.TryGetValue(type, out GameplayAttributeData? attribute))
|
||||
|
|
Loading…
Reference in a new issue