2024-02-21 14:47:37 +00:00
|
|
|
|
using Core.Config;
|
|
|
|
|
using GameServer.Controllers.Attributes;
|
2024-02-21 21:14:56 +00:00
|
|
|
|
using GameServer.Extensions.Logic;
|
2024-02-21 14:47:37 +00:00
|
|
|
|
using GameServer.Models;
|
2024-02-09 22:15:05 +00:00
|
|
|
|
using GameServer.Network;
|
2024-02-21 14:47:37 +00:00
|
|
|
|
using GameServer.Systems.Entity;
|
|
|
|
|
using GameServer.Systems.Entity.Component;
|
|
|
|
|
using GameServer.Systems.Event;
|
2024-02-09 22:15:05 +00:00
|
|
|
|
using Protocol;
|
|
|
|
|
|
|
|
|
|
namespace GameServer.Controllers;
|
|
|
|
|
internal class InventoryController : Controller
|
|
|
|
|
{
|
|
|
|
|
public InventoryController(PlayerSession session) : base(session)
|
|
|
|
|
{
|
2024-02-10 11:51:20 +00:00
|
|
|
|
// InventoryController.
|
2024-02-09 22:15:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NetEvent(MessageId.NormalItemRequest)]
|
2024-02-20 19:39:08 +00:00
|
|
|
|
public RpcResult OnNormalItemRequest() => Response(MessageId.NormalItemResponse, new NormalItemResponse());
|
2024-02-09 22:15:05 +00:00
|
|
|
|
|
|
|
|
|
[NetEvent(MessageId.WeaponItemRequest)]
|
2024-02-21 14:47:37 +00:00
|
|
|
|
public RpcResult OnWeaponItemRequest(ModelManager modelManager) => Response(MessageId.WeaponItemResponse, new WeaponItemResponse
|
|
|
|
|
{
|
|
|
|
|
WeaponItemList =
|
|
|
|
|
{
|
|
|
|
|
modelManager.Inventory.WeaponList
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-02-09 22:15:05 +00:00
|
|
|
|
|
|
|
|
|
[NetEvent(MessageId.PhantomItemRequest)]
|
2024-02-20 19:39:08 +00:00
|
|
|
|
public RpcResult OnPhantomItemRequest() => Response(MessageId.PhantomItemResponse, new PhantomItemResponse());
|
2024-02-09 22:15:05 +00:00
|
|
|
|
|
|
|
|
|
[NetEvent(MessageId.ItemExchangeInfoRequest)]
|
2024-02-20 19:39:08 +00:00
|
|
|
|
public RpcResult OnItemExchangeInfoRequest() => Response(MessageId.ItemExchangeInfoResponse, new ItemExchangeInfoResponse());
|
2024-02-21 14:47:37 +00:00
|
|
|
|
|
|
|
|
|
[NetEvent(MessageId.EquipTakeOnRequest)]
|
2024-02-21 21:14:56 +00:00
|
|
|
|
public async Task<RpcResult> OnEquipTakeOnRequest(EquipTakeOnRequest request, ModelManager modelManager, CreatureController creatureController, ConfigManager configManager)
|
2024-02-21 14:47:37 +00:00
|
|
|
|
{
|
|
|
|
|
WeaponItem? weapon = modelManager.Inventory.GetWeaponById(request.Data.EquipIncId);
|
|
|
|
|
if (weapon == null) return Response(MessageId.EquipTakeOnResponse, new EquipTakeOnResponse
|
|
|
|
|
{
|
|
|
|
|
ErrorCode = (int)ErrorCode.ErrItemIdInvaild
|
|
|
|
|
});
|
|
|
|
|
|
2024-02-21 21:14:56 +00:00
|
|
|
|
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 }
|
|
|
|
|
});
|
|
|
|
|
|
2024-02-21 14:47:37 +00:00
|
|
|
|
PlayerEntity? entity = creatureController.GetPlayerEntityByRoleId(request.Data.RoleId);
|
2024-02-21 21:14:56 +00:00
|
|
|
|
if (entity != null)
|
2024-02-21 14:47:37 +00:00
|
|
|
|
{
|
2024-02-21 21:14:56 +00:00
|
|
|
|
// Update entity equipment
|
2024-02-21 14:47:37 +00:00
|
|
|
|
EntityEquipComponent equipComponent = entity.ComponentSystem.Get<EntityEquipComponent>();
|
|
|
|
|
equipComponent.WeaponId = weapon.Id;
|
|
|
|
|
|
|
|
|
|
await Session.Push(MessageId.EntityEquipChangeNotify, new EntityEquipChangeNotify
|
|
|
|
|
{
|
|
|
|
|
EntityId = entity.Id,
|
|
|
|
|
EquipComponent = equipComponent.Pb.EquipComponent
|
|
|
|
|
});
|
2024-02-21 21:14:56 +00:00
|
|
|
|
|
|
|
|
|
// 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 }
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-21 22:00:48 +00:00
|
|
|
|
// Response
|
|
|
|
|
EquipTakeOnResponse response = new()
|
2024-02-21 14:47:37 +00:00
|
|
|
|
{
|
|
|
|
|
DataList =
|
|
|
|
|
{
|
|
|
|
|
new RoleLoadEquipData
|
|
|
|
|
{
|
|
|
|
|
RoleId = request.Data.RoleId,
|
|
|
|
|
Pos = request.Data.Pos,
|
|
|
|
|
EquipIncId = request.Data.EquipIncId
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-21 22:00:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (prevWeapon != null)
|
|
|
|
|
{
|
|
|
|
|
response.DataList.Add(new RoleLoadEquipData
|
|
|
|
|
{
|
|
|
|
|
EquipIncId = prevWeapon.IncrId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Response(MessageId.EquipTakeOnResponse, response);
|
2024-02-21 14:47:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[GameEvent(GameEventType.EnterGame)]
|
|
|
|
|
public async Task OnEnterGame()
|
|
|
|
|
{
|
|
|
|
|
await Session.Push(MessageId.ItemPkgOpenNotify, new ItemPkgOpenNotify
|
|
|
|
|
{
|
|
|
|
|
OpenPkg = { 0, 2, 1, 3, 4, 5, 6, 7 }
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[GameEvent(GameEventType.DebugUnlockAllWeapons)]
|
|
|
|
|
public void DebugUnlockAllWeapons(ConfigManager configManager, ModelManager modelManager)
|
|
|
|
|
{
|
|
|
|
|
foreach (WeaponConfig weaponConf in configManager.Enumerate<WeaponConfig>())
|
|
|
|
|
{
|
|
|
|
|
modelManager.Inventory.AddNewWeapon(weaponConf.ItemId);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-09 22:15:05 +00:00
|
|
|
|
}
|