完成配件安装和拆卸
This commit is contained in:
75
Hotfix/Game/Handler/C2Game_RigChangeRequestHandler.cs
Normal file
75
Hotfix/Game/Handler/C2Game_RigChangeRequestHandler.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace NB.Game;
|
||||
|
||||
public class C2Game_RigChangeRequestHandler : RouteRPC<Player, C2Game_RigChangeRequest, Game2C_RigChangeResponse>
|
||||
{
|
||||
protected override async FTask Run(Player entity, C2Game_RigChangeRequest request,
|
||||
Game2C_RigChangeResponse response, Action reply)
|
||||
{
|
||||
var itemContainer = entity.GetComponent<PlayerItemContainerComponent>();
|
||||
if (itemContainer == null)
|
||||
{
|
||||
response.ErrorCode = ErrorCode.ErrArgs;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!itemContainer.Items.TryGetValue(request.ItemId, out var item))
|
||||
{
|
||||
response.ErrorCode = ErrorCode.ErrArgs;
|
||||
return;
|
||||
}
|
||||
|
||||
if (request.IsAdd)
|
||||
{
|
||||
//安装配件需要检查配件是否已被使用
|
||||
var usable = true;
|
||||
|
||||
foreach (var bindInfo in itemContainer.Binding)
|
||||
{
|
||||
if (bindInfo.Value.Any(useId => useId == request.RigId))
|
||||
{
|
||||
usable = false;
|
||||
}
|
||||
|
||||
if (!usable) break;
|
||||
}
|
||||
|
||||
if (!usable)
|
||||
{
|
||||
response.ErrorCode = ErrorCode.ErrArgs;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//检查是否可用配件
|
||||
if (!itemContainer.Binding.TryGetValue(item.Id, out var list))
|
||||
{
|
||||
list = new List<long>();
|
||||
itemContainer.Binding[item.Id] = list;
|
||||
}
|
||||
|
||||
if (request.IsAdd)
|
||||
{
|
||||
if (request.OldRigId > 0)
|
||||
{
|
||||
if (list.Contains(request.OldRigId))
|
||||
{
|
||||
list.Remove(request.OldRigId);
|
||||
}
|
||||
}
|
||||
|
||||
list.Add(request.RigId);
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Remove(request.RigId);
|
||||
}
|
||||
|
||||
await itemContainer.Save();
|
||||
response.Rigs = itemContainer.GetRigInfo(request.ItemId);
|
||||
}
|
||||
}
|
||||
@@ -120,7 +120,8 @@ public static class PlayerItemContainerComponentSystem
|
||||
await self.Save();
|
||||
}
|
||||
|
||||
public static async FTask Add(this PlayerItemContainerComponent self, uint configId, int count, bool needSave = true)
|
||||
public static async FTask Add(this PlayerItemContainerComponent self, uint configId, int count,
|
||||
bool needSave = true)
|
||||
{
|
||||
var item = ItemFactory.Create(self.Scene, configId, count);
|
||||
self.Items.Add(item.Id, item);
|
||||
@@ -159,11 +160,29 @@ public static class PlayerItemContainerComponentSystem
|
||||
//
|
||||
// return ret;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
public static ItemBindInfo GetRigInfo(this PlayerItemContainerComponent self, long id)
|
||||
{
|
||||
if (self.Binding.TryGetValue(id, out var info))
|
||||
{
|
||||
ItemBindInfo gearInfo = new ItemBindInfo();
|
||||
gearInfo.Item = id;
|
||||
if (info != null)
|
||||
{
|
||||
gearInfo.BindItems.AddRange(info);
|
||||
}
|
||||
|
||||
return gearInfo;
|
||||
}
|
||||
|
||||
return new ItemBindInfo() { Item = id };
|
||||
}
|
||||
|
||||
public static List<ItemBindInfo> GetRigInfos(this PlayerItemContainerComponent self)
|
||||
{
|
||||
List<ItemBindInfo> ret = new List<ItemBindInfo>(self.FishingRig.Count);
|
||||
foreach (var (rod, rigs) in self.FishingRig)
|
||||
List<ItemBindInfo> ret = new List<ItemBindInfo>(self.Binding.Count);
|
||||
foreach (var (rod, rigs) in self.Binding)
|
||||
{
|
||||
ItemBindInfo gearInfo = new ItemBindInfo();
|
||||
gearInfo.Item = rod;
|
||||
@@ -174,6 +193,5 @@ public static class PlayerItemContainerComponentSystem
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -90,7 +90,7 @@ public static class PlayerManageComponentSystem
|
||||
}
|
||||
|
||||
// account.Statistics.LoginTime = TimeHelper.Now;
|
||||
account.SetTestData();
|
||||
// account.SetTestData();
|
||||
|
||||
await account.Save();
|
||||
|
||||
|
||||
@@ -69,37 +69,37 @@ public static class PlayerSystem
|
||||
public static void SetTestData(this Player player)
|
||||
{
|
||||
|
||||
Dictionary<int, List<int>> rigDic = new Dictionary<int, List<int>>()
|
||||
{
|
||||
{ 30001, [50001, 60001, 70002, 90001, 100001] },
|
||||
{ 30002, [40001, 50001, 60001, 70002, 00001, 100001] },
|
||||
{ 30003, [40001, 60001, 80001] }
|
||||
};
|
||||
|
||||
var itemContainer = player.GetComponent<PlayerItemContainerComponent>();
|
||||
|
||||
//添加测试数据
|
||||
if (itemContainer != null && itemContainer.FishingRig.Count < 1)
|
||||
{
|
||||
foreach (var (rod, list) in rigDic)
|
||||
{
|
||||
if (itemContainer.GetFistItemByConfigId(rod, out var item) && item != null)
|
||||
{
|
||||
var childs = new List<long>();
|
||||
foreach (var i in list)
|
||||
{
|
||||
if (itemContainer.GetFistItemByConfigId(i, out var itemChild) && itemChild != null)
|
||||
{
|
||||
childs.Add(itemChild.Id);
|
||||
}
|
||||
}
|
||||
|
||||
itemContainer.FishingRig[item.Id] = childs;
|
||||
}
|
||||
}
|
||||
|
||||
itemContainer.Save();
|
||||
}
|
||||
// Dictionary<int, List<int>> rigDic = new Dictionary<int, List<int>>()
|
||||
// {
|
||||
// { 30001, [50001, 60001, 70002, 90001, 100001] },
|
||||
// { 30002, [40001, 50001, 60001, 70002, 00001, 100001] },
|
||||
// { 30003, [40001, 60001, 80001] }
|
||||
// };
|
||||
//
|
||||
// var itemContainer = player.GetComponent<PlayerItemContainerComponent>();
|
||||
//
|
||||
// //添加测试数据
|
||||
// if (itemContainer != null && itemContainer.FishingRig.Count < 1)
|
||||
// {
|
||||
// foreach (var (rod, list) in rigDic)
|
||||
// {
|
||||
// if (itemContainer.GetFistItemByConfigId(rod, out var item) && item != null)
|
||||
// {
|
||||
// var childs = new List<long>();
|
||||
// foreach (var i in list)
|
||||
// {
|
||||
// if (itemContainer.GetFistItemByConfigId(i, out var itemChild) && itemChild != null)
|
||||
// {
|
||||
// childs.Add(itemChild.Id);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// itemContainer.FishingRig[item.Id] = childs;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// itemContainer.Save();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user