配置表接入和升级服务器框架到最新版
This commit is contained in:
@@ -122,7 +122,7 @@ public static class PlayerBasicCacheManageComponentSystem
|
||||
cache.Country = player.Country;
|
||||
cache.Head = player.Head;
|
||||
cache.Level = player.Level;
|
||||
cache.IsVip = player.IsVip;
|
||||
cache.Vip = player.Vip;
|
||||
cache.ExpirationTime = TimeHelper.Now + TimeHelper.OneDay; //更新则过期时间增加一天
|
||||
|
||||
return cache;
|
||||
|
||||
@@ -11,7 +11,7 @@ public class PlayerBasicCacheDestroySystem : DestroySystem<PlayerBasicCache>
|
||||
self.NickName = string.Empty;
|
||||
self.Head = string.Empty;
|
||||
self.Level = 0;
|
||||
self.IsVip = false;
|
||||
self.Vip = 0;
|
||||
self.ExpirationTime = 0;
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public static class PlayerBasicCacheSystem
|
||||
ret.Country = player.Country;
|
||||
ret.Head = player.Head;
|
||||
ret.Level = player.Level;
|
||||
ret.Vip = player.IsVip;
|
||||
ret.Vip = player.Vip;
|
||||
ret.RoleId = player.Id;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public static class ItemFactory
|
||||
/// <param name="configId"></param>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
public static Item Create(Scene scene, int configId, int count = 1)
|
||||
public static Item Create(Scene scene, uint configId, int count = 1)
|
||||
{
|
||||
var item = Entity.Create<Item>(scene, true, true);
|
||||
item.ConfigId = configId;
|
||||
|
||||
20
Hotfix/Game/Item/Helper/ItemHelper.cs
Normal file
20
Hotfix/Game/Item/Helper/ItemHelper.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
namespace NB.Game;
|
||||
|
||||
public static class ItemHelper
|
||||
{
|
||||
public static ItemBasicType GetType(uint id)
|
||||
{
|
||||
var type = (int)(id / 10000);
|
||||
if (type == 1)
|
||||
{
|
||||
return ItemBasicType.Currency;
|
||||
}
|
||||
|
||||
if (type == 21)
|
||||
{
|
||||
return ItemBasicType.Fish;
|
||||
}
|
||||
|
||||
return ItemBasicType.Item;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Entitas.Interface;
|
||||
|
||||
namespace NB.Game;
|
||||
|
||||
public sealed class ItemContainerDestroySystem : DestroySystem<PlayerItemContainer>
|
||||
public sealed class ItemContainerDestroySystem : DestroySystem<PlayerItemContainerComponent>
|
||||
{
|
||||
protected override void Destroy(PlayerItemContainer self)
|
||||
protected override void Destroy(PlayerItemContainerComponent self)
|
||||
{
|
||||
self.CellCountMax = 0;
|
||||
|
||||
@@ -20,8 +21,17 @@ public sealed class ItemContainerDestroySystem : DestroySystem<PlayerItemContain
|
||||
}
|
||||
}
|
||||
|
||||
public static class ItemContainerSystem
|
||||
public static class PlayerItemContainerComponentSystem
|
||||
{
|
||||
#region Save
|
||||
|
||||
public static async FTask Save(this PlayerItemContainerComponent self)
|
||||
{
|
||||
await self.Scene.World.DataBase.Save(self);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Get
|
||||
|
||||
/// <summary>
|
||||
@@ -31,7 +41,7 @@ public static class ItemContainerSystem
|
||||
/// <param name="id"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
public static bool GetItemById(this PlayerItemContainer self, long id, out Item? item)
|
||||
public static bool GetItemById(this PlayerItemContainerComponent self, long id, out Item? item)
|
||||
{
|
||||
return self.Items.TryGetValue(id, out item);
|
||||
}
|
||||
@@ -42,7 +52,7 @@ public static class ItemContainerSystem
|
||||
/// <param name="self"></param>
|
||||
/// <param name="configId"></param>
|
||||
/// <param name="item"></param>
|
||||
public static bool GetFistItemByConfigId(this PlayerItemContainer self, int configId, out Item? item)
|
||||
public static bool GetFistItemByConfigId(this PlayerItemContainerComponent self, int configId, out Item? item)
|
||||
{
|
||||
foreach (var (_, it) in self.Items)
|
||||
{
|
||||
@@ -100,17 +110,31 @@ public static class ItemContainerSystem
|
||||
|
||||
#region Add
|
||||
|
||||
public static void Add(this PlayerItemContainer self, int configId, int count)
|
||||
public static async FTask Add(this PlayerItemContainerComponent self, Dictionary<uint, int> items)
|
||||
{
|
||||
foreach (var (configId, count) in items)
|
||||
{
|
||||
await self.Add(configId, count, false);
|
||||
}
|
||||
|
||||
await self.Save();
|
||||
}
|
||||
|
||||
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);
|
||||
if (needSave)
|
||||
{
|
||||
await self.Save();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 结构转换
|
||||
|
||||
public static List<ItemInfo> GetItemInfos(this PlayerItemContainer self)
|
||||
public static List<ItemInfo> GetItemInfos(this PlayerItemContainerComponent self)
|
||||
{
|
||||
List<ItemInfo> ret = new List<ItemInfo>();
|
||||
foreach (var (_, item) in self.Items)
|
||||
@@ -121,7 +145,7 @@ public static class ItemContainerSystem
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static List<GearInfo> GetGearInfos(this PlayerItemContainer self)
|
||||
public static List<GearInfo> GetGearInfos(this PlayerItemContainerComponent self)
|
||||
{
|
||||
List<GearInfo> ret = new List<GearInfo>();
|
||||
|
||||
@@ -3,6 +3,7 @@ using Fantasy.Async;
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Entitas.Interface;
|
||||
using Fantasy.Helper;
|
||||
using NBF;
|
||||
|
||||
#pragma warning disable CS8603 // 可能返回 null 引用。
|
||||
|
||||
@@ -45,37 +46,28 @@ public static class PlayerManageComponentSystem
|
||||
{
|
||||
// 首先要先到数据库中查询是否有这个账号
|
||||
account = await PlayerHelper.LoadDataBase(self.Scene, accountId);
|
||||
bool needInit = false;
|
||||
// 如果有的话,就直接加入在缓存中就可以了
|
||||
if (account == null)
|
||||
{
|
||||
Log.Debug("检查到账号没有在数据库中,需要创建一个新的账号并且保存到数据库中");
|
||||
// 如果没有,就要创建一个新的并且保存到数据库。
|
||||
// 如果不存在,表示这是一个新的账号,需要创建一下这个账号。
|
||||
account = PlayerFactory.Create(self.Scene, accountId);
|
||||
|
||||
account.Level = 99;
|
||||
account.NickName = "王麻子";
|
||||
account.Country = "cn";
|
||||
account.Exp = 999;
|
||||
account.Head = "xxx.png";
|
||||
|
||||
// for (int i = 0; i < 500; i++)
|
||||
// {
|
||||
// var item = Entity.Create<Item>(scene, true, true);
|
||||
// account.ItemContainer.Add(item.Id, item);
|
||||
// }
|
||||
//
|
||||
// for (int i = 0; i < 500; i++)
|
||||
// {
|
||||
// var item = Entity.Create<Fish>(scene, true, true);
|
||||
// account.Fishes.Add(item.Id, item);
|
||||
// }
|
||||
needInit = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Debug("检查到账号在数据库中");
|
||||
}
|
||||
|
||||
await account.TryComponent<PlayerItemContainerComponent>();
|
||||
await account.TryComponent<PlayerWalletComponent>();
|
||||
await account.TryComponent<FishContainer>();
|
||||
|
||||
if (needInit)
|
||||
{
|
||||
await account.InitPlayer();
|
||||
}
|
||||
|
||||
Log.Debug("把当前账号添加到缓存中");
|
||||
// 把创建完成的Account放入到缓存中
|
||||
self.Add(account);
|
||||
@@ -152,6 +144,69 @@ public static class PlayerManageComponentSystem
|
||||
|
||||
#endregion
|
||||
|
||||
#region 初始化新号数据
|
||||
|
||||
public static async Task InitPlayer(this Player player)
|
||||
{
|
||||
//TODO: 处理基础信息
|
||||
player.Level = 99;
|
||||
player.NickName = "王麻子";
|
||||
player.Country = "cn";
|
||||
player.Exp = 999;
|
||||
player.Head = "xxx.png";
|
||||
|
||||
var list = InitConfig.GetList();
|
||||
|
||||
|
||||
Dictionary<ItemBasicType, Dictionary<uint, int>>
|
||||
addDic = new Dictionary<ItemBasicType, Dictionary<uint, int>>();
|
||||
foreach (var initConfig in list)
|
||||
{
|
||||
var itemType = ItemHelper.GetType(initConfig.ItemId);
|
||||
if (!addDic.TryGetValue(itemType, out var dic))
|
||||
{
|
||||
dic = new Dictionary<uint, int>();
|
||||
addDic.Add(itemType, dic);
|
||||
}
|
||||
|
||||
if (!dic.ContainsKey(initConfig.ItemId))
|
||||
{
|
||||
dic.Add(initConfig.ItemId, initConfig.Amount);
|
||||
}
|
||||
else
|
||||
{
|
||||
dic[initConfig.ItemId] += initConfig.Amount;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var (itemType, dictionary) in addDic)
|
||||
{
|
||||
if (itemType == ItemBasicType.Item)
|
||||
{
|
||||
var itemContainer = player.GetComponent<PlayerItemContainerComponent>();
|
||||
await itemContainer.Add(dictionary);
|
||||
}
|
||||
else if (itemType == ItemBasicType.Currency)
|
||||
{
|
||||
var playerWallet = player.GetComponent<PlayerWalletComponent>();
|
||||
foreach (var (key, value) in dictionary)
|
||||
{
|
||||
if (value > 0)
|
||||
{
|
||||
await playerWallet.Add(key, value);
|
||||
}
|
||||
else if (value < 0)
|
||||
{
|
||||
await playerWallet.Sub(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region 组件
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Net.Http.Headers;
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Entitas;
|
||||
@@ -35,55 +36,71 @@ public sealed class PlayerDestroySystem : DestroySystem<Player>
|
||||
|
||||
public static class PlayerSystem
|
||||
{
|
||||
#region 物品
|
||||
|
||||
/// <summary>
|
||||
/// 添加物品
|
||||
/// </summary>
|
||||
/// <param name="self"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="items"></param>
|
||||
public static async FTask AddItems(this Player self, Dictionary<uint, int> items)
|
||||
{
|
||||
|
||||
var itemContainer = self.GetComponent<PlayerItemContainerComponent>();
|
||||
HashSet<ItemBasicType> addType = new HashSet<ItemBasicType>();
|
||||
foreach (var (key, value) in items)
|
||||
{
|
||||
var itemType = ItemHelper.GetType(key);
|
||||
switch (itemType)
|
||||
{
|
||||
case ItemBasicType.Item:
|
||||
itemContainer.Add(key, value);
|
||||
addType.Add(ItemBasicType.Item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 测试数据
|
||||
|
||||
public static void SetTestData(this Player player)
|
||||
{
|
||||
List<int> addItemConfigs = new List<int>()
|
||||
{
|
||||
100001, 100002, 100003,
|
||||
200001,
|
||||
300001, 300002, 300003,
|
||||
400001,
|
||||
500001, 500002,
|
||||
600001, 600002, 600003, 600004,
|
||||
700001,
|
||||
800001
|
||||
};
|
||||
|
||||
Dictionary<int, List<int>> rigDic = new Dictionary<int, List<int>>()
|
||||
{
|
||||
{ 100001, [300001, 400001, 500002, 700001, 800001] },
|
||||
{ 100002, [200001, 300001, 400001, 500002, 700001, 800001] },
|
||||
{ 100003, [200001, 400001, 600001] }
|
||||
{ 30001, [50001, 60001, 70002, 90001, 100001] },
|
||||
{ 30002, [40001, 50001, 60001, 70002, 00001, 100001] },
|
||||
{ 30003, [40001, 60001, 80001] }
|
||||
};
|
||||
//添加测试数据
|
||||
if (player.ItemContainer != null && player.ItemContainer.Items.Count < 1)
|
||||
{
|
||||
foreach (var configId in addItemConfigs)
|
||||
{
|
||||
player.ItemContainer.Add(configId, 1);
|
||||
}
|
||||
|
||||
var itemContainer = player.GetComponent<PlayerItemContainerComponent>();
|
||||
|
||||
//添加测试数据
|
||||
if (itemContainer != null && itemContainer.FishingRig.Count < 1)
|
||||
{
|
||||
foreach (var (rod, list) in rigDic)
|
||||
{
|
||||
if (player.ItemContainer.GetFistItemByConfigId(rod, out var item) && item != null)
|
||||
if (itemContainer.GetFistItemByConfigId(rod, out var item) && item != null)
|
||||
{
|
||||
var childs = new List<long>();
|
||||
foreach (var i in list)
|
||||
{
|
||||
if (player.ItemContainer.GetFistItemByConfigId(i, out var itemChild) && itemChild != null)
|
||||
if (itemContainer.GetFistItemByConfigId(i, out var itemChild) && itemChild != null)
|
||||
{
|
||||
childs.Add(itemChild.Id);
|
||||
}
|
||||
}
|
||||
|
||||
player.ItemContainer.FishingRig[item.Id] = childs;
|
||||
|
||||
itemContainer.FishingRig[item.Id] = childs;
|
||||
}
|
||||
}
|
||||
|
||||
// player.ItemContainer.FishingRig
|
||||
itemContainer.Save();
|
||||
}
|
||||
// if(player.gr)
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -17,6 +17,7 @@ public static class PlayerFactory
|
||||
public static Player Create(Scene scene, long aId)
|
||||
{
|
||||
var player = Entity.Create<Player>(scene, aId, true, true);
|
||||
|
||||
return player;
|
||||
}
|
||||
}
|
||||
@@ -8,15 +8,14 @@ namespace NB.Game;
|
||||
|
||||
public static class PlayerHelper
|
||||
{
|
||||
#region MyRegion
|
||||
|
||||
#region 数据保存
|
||||
|
||||
public static async FTask Save(this Player self)
|
||||
{
|
||||
//先立马保存,后续做缓存
|
||||
await self.Scene.World.DataBase.Save(self);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 从数据库中读取GameAccount
|
||||
/// </summary>
|
||||
@@ -32,12 +31,6 @@ public static class PlayerHelper
|
||||
}
|
||||
|
||||
account.Deserialize(scene);
|
||||
account.ItemContainer.Deserialize(scene);
|
||||
foreach (var (_, item) in account.ItemContainer.Items)
|
||||
{
|
||||
item.Deserialize(scene);
|
||||
}
|
||||
|
||||
return account;
|
||||
}
|
||||
|
||||
@@ -50,6 +43,18 @@ public static class PlayerHelper
|
||||
{
|
||||
// 保存该账号信息到数据库中。
|
||||
await Save(self);
|
||||
var itemContainer = self.GetComponent<PlayerItemContainerComponent>();
|
||||
if (itemContainer != null)
|
||||
{
|
||||
await itemContainer.Save();
|
||||
}
|
||||
|
||||
var wallet = self.GetComponent<PlayerWalletComponent>();
|
||||
if (wallet != null)
|
||||
{
|
||||
await wallet.Save();
|
||||
}
|
||||
|
||||
// 在缓存中移除自己,并且执行自己的Dispose方法。
|
||||
self.Scene.GetComponent<PlayerManageComponent>().Remove(self.Id);
|
||||
}
|
||||
@@ -119,7 +124,7 @@ public static class PlayerHelper
|
||||
Head = self.Head,
|
||||
Country = self.Country,
|
||||
Level = self.Level,
|
||||
Vip = self.IsVip,
|
||||
Vip = self.Vip,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -127,7 +132,7 @@ public static class PlayerHelper
|
||||
{
|
||||
var info = new RoleInfo();
|
||||
info.BaseInfo = GetRoleBaseInfo(self);
|
||||
info.Items = self.ItemContainer.GetItemInfos();
|
||||
// info.Items = self.ItemContainer.GetItemInfos();
|
||||
info.RoleId = self.RouteId;
|
||||
return info;
|
||||
}
|
||||
@@ -142,11 +147,12 @@ public static class PlayerHelper
|
||||
Level = self.Level,
|
||||
Exp = self.Exp,
|
||||
};
|
||||
if (self.IsVip)
|
||||
if (self.Vip > 0)
|
||||
{
|
||||
ret.VipInfo = new VipInfo();
|
||||
// ret.VipInfo.OpenTime = self.Vip.GetTime;
|
||||
// ret.VipInfo.ExpirationTime = self.Vip.ExpirationTime;
|
||||
ret.VipInfo.Level = self.Vip;
|
||||
ret.VipInfo.OpenTime = self.VipGetTime;
|
||||
ret.VipInfo.ExpirationTime = self.VipExpirationTime;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
83
Hotfix/Game/Wallet/PlayerWalletComponentSystem.cs
Normal file
83
Hotfix/Game/Wallet/PlayerWalletComponentSystem.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
|
||||
namespace NB.Game;
|
||||
|
||||
public static class PlayerWalletComponentSystem
|
||||
{
|
||||
#region Save
|
||||
|
||||
public static async FTask Save(this PlayerWalletComponent self)
|
||||
{
|
||||
await self.Scene.World.DataBase.Save(self);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Add & Sub
|
||||
|
||||
/// <summary>
|
||||
/// 货币是否足够
|
||||
/// </summary>
|
||||
/// <param name="self"></param>
|
||||
/// <param name="configId"></param>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
public static bool Have(this PlayerWalletComponent self, uint configId, int count)
|
||||
{
|
||||
if (self.Currency.TryGetValue(configId, out var value))
|
||||
{
|
||||
if (value >= Math.Abs(count))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static async FTask Add(this PlayerWalletComponent self, uint configId, int count)
|
||||
{
|
||||
if (count < 1)
|
||||
{
|
||||
Log.Error("Wallet Add Count Error ");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!self.Currency.TryAdd(configId, count))
|
||||
{
|
||||
self.Currency[configId] += count;
|
||||
}
|
||||
|
||||
await self.Save();
|
||||
}
|
||||
|
||||
public static async FTask Sub(this PlayerWalletComponent self, uint configId, int count)
|
||||
{
|
||||
if (count > 0)
|
||||
{
|
||||
Log.Error("Wallet Sub Count Error ");
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.Currency.TryGetValue(configId, out var value))
|
||||
{
|
||||
if (value >= Math.Abs(count))
|
||||
{
|
||||
self.Currency[configId] += count;
|
||||
await self.Save();
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error("Wallet Sub Count Error Lower");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error("Wallet Sub Count Error Not");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Game\Helper\" />
|
||||
<Folder Include="Game\Item\Handler\" />
|
||||
<Folder Include="Game\Shop\Handler\" />
|
||||
<Folder Include="Social\Chat\" />
|
||||
<Folder Include="Social\Club\" />
|
||||
<Folder Include="Social\Mail\Handler\Inner\" />
|
||||
|
||||
@@ -7,6 +7,7 @@ using Fantasy.Helper;
|
||||
using Fantasy.Serialize;
|
||||
using NB.Game;
|
||||
using NB.Map;
|
||||
using NBF;
|
||||
using ProtoBuf;
|
||||
|
||||
namespace NB;
|
||||
@@ -86,6 +87,8 @@ public sealed class OnCreateSceneEvent : AsyncEventSystem<OnCreateScene>
|
||||
}
|
||||
case SceneType.Game:
|
||||
{
|
||||
var rod = RodConfig.Get(30001);
|
||||
Log.Info("rod config id="+rod.Id);
|
||||
// // Begins transaction
|
||||
// using (var session = mongoClient.StartSession())
|
||||
// {
|
||||
|
||||
Reference in New Issue
Block a user