新增位移,数值相关组件

This commit is contained in:
2025-08-25 18:03:15 +08:00
parent e41fd7dd2d
commit a3768e4aa2
73 changed files with 1254 additions and 484 deletions

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 5432d229611d4f8e8fa72a637035bb40
timeCreated: 1756044768

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3313ff0be8cf4611891770497b258bcd
timeCreated: 1756115138

View File

@@ -0,0 +1,9 @@
using NBC.Entitas;
namespace NBF.Fishing2
{
public class MoveComponent : Entity
{
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 660d750ed1f74128a55bbb574d772af4
timeCreated: 1756115969

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2859b0361c964635b4ea58be3b903b6a
timeCreated: 1756115131

View File

@@ -0,0 +1,138 @@
using System.Collections.Generic;
using NBC;
using NBC.Entitas;
namespace NBF.Fishing2
{
/// <summary>
/// 数据组件
/// </summary>
public class NumericComponent : Entity
{
public Dictionary<int, long> NumericDic = new Dictionary<int, long>();
public long this[int numericType]
{
get { return this.GetByKey(numericType); }
set { this.Insert(numericType, value); }
}
}
public struct NumericChange
{
public Unit Unit;
public int NumericType;
public long Old;
public long New;
}
public static class NumericComponentSystem
{
public static float GetAsFloat(this NumericComponent self, int numericType)
{
return (float)self.GetByKey(numericType) / 10000;
}
public static int GetAsInt(this NumericComponent self, int numericType)
{
return (int)self.GetByKey(numericType);
}
public static long GetAsLong(this NumericComponent self, int numericType)
{
return self.GetByKey(numericType);
}
public static void Set(this NumericComponent self, int nt, float value)
{
self[nt] = (long)(value * 10000);
}
public static void Set(this NumericComponent self, int nt, int value)
{
self[nt] = value;
}
public static void Set(this NumericComponent self, int nt, long value)
{
self[nt] = value;
}
public static void Add(this NumericComponent self, int nt, float value)
{
self[nt] += (long)(value * 10000);
}
public static void Add(this NumericComponent self, int nt, int value)
{
self[nt] += value;
}
public static void Add(this NumericComponent self, int nt, long value)
{
self[nt] += value;
}
public static void SetNoEvent(this NumericComponent self, int numericType, long value)
{
self.Insert(numericType, value, false);
}
public static void Insert(this NumericComponent self, int numericType, long value, bool isPublicEvent = true)
{
long oldValue = self.GetByKey(numericType);
if (oldValue == value)
{
return;
}
self.NumericDic[numericType] = value;
if (numericType >= NumericType.Max)
{
self.Update(numericType, isPublicEvent);
return;
}
if (isPublicEvent)
{
App.Main.EventComponent.Publish(new NumericChange()
{ Unit = self.GetParent<Unit>(), New = value, Old = oldValue, NumericType = numericType });
}
}
public static long GetByKey(this NumericComponent self, int key)
{
long value = 0;
self.NumericDic.TryGetValue(key, out value);
return value;
}
public static void Update(this NumericComponent self, int numericType, bool isPublicEvent)
{
int final = numericType / 10;
int bas = final * 10 + 1;
int add = final * 10 + 2;
int pct = final * 10 + 3;
int finalAdd = final * 10 + 4;
int finalPct = final * 10 + 5;
// 一个数值可能会多种情况影响,比如速度,加个buff可能增加速度绝对值100也有些buff增加10%速度所以一个值可以由5个值进行控制其最终结果
// final = (((base + add) * (100 + pct) / 100) + finalAdd) * (100 + finalPct) / 100;
long result = (long)(((self.GetByKey(bas) + self.GetByKey(add)) * (100 + self.GetAsFloat(pct)) / 100f +
self.GetByKey(finalAdd)) *
(100 + self.GetAsFloat(finalPct)) / 100f);
self.Insert(final, result, isPublicEvent);
}
public static Dictionary<int, long> CopyDict(this NumericComponent self)
{
return new Dictionary<int, long>(self.NumericDic);
}
public static void Clear(this NumericComponent self)
{
self.NumericDic.Clear();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 737675ae567e412aa2ec234c3fa62ed5
timeCreated: 1756114955

View File

@@ -0,0 +1,8 @@
namespace NBF.Fishing2
{
public static class NumericType
{
public const int Max = 10000;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 257e38cf2fa2457087822886699e3276
timeCreated: 1756115154

View File

@@ -0,0 +1,9 @@
using NBC.Entitas;
namespace NBF.Fishing2
{
public class UnitBasic : Entity
{
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 19299372f58c4c1db612f36ce60ee238
timeCreated: 1756116063

View File

@@ -0,0 +1,15 @@
using NBC;
using NBC.Entitas;
namespace NBF.Fishing2
{
public static partial class UnitFactory
{
public static Unit Create(Map map, MapUnitInfo unitInfo, bool isMainPlayer = false)
{
var unit = Entity.Create<Unit>(map.Scene,true,true);
unit.SetUnitInfo(unitInfo);
return null;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d636bf7bc79a4d55b7f03a6e7a187b22
timeCreated: 1756106498

View File

@@ -1,7 +1,18 @@
namespace NBF.Fishing2
using NBC;
namespace NBF.Fishing2
{
public static class UnitSystem
{
public static void SetUnitInfo(this Unit self, MapUnitInfo unitInfo)
{
NumericComponent numericComponent = self.AddComponent<NumericComponent>();
foreach (var kv in unitInfo.KV)
{
numericComponent.Set(kv.Key, kv.Value);
}
}
public static UnitConfig Config(this Unit self)
{
return UnitConfig.Get(self.ConfigId);

View File

@@ -68,6 +68,26 @@ namespace NBC
public long Value { get; set; }
}
[ProtoContract]
public partial class KeyValueInt32 : AMessage, IProto
{
public static KeyValueInt32 Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<KeyValueInt32>();
}
public override void Dispose()
{
Key = default;
Value = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<KeyValueInt32>(this);
#endif
}
[ProtoMember(1)]
public int Key { get; set; }
[ProtoMember(2)]
public int Value { get; set; }
}
[ProtoContract]
public partial class KeyValueInt64 : AMessage, IProto
{
public static KeyValueInt64 Create(Scene scene)

View File

@@ -10,18 +10,18 @@ using NBC.Serialize;
namespace NBC
{
[ProtoContract]
public partial class RoleGearItemInfo : AMessage, IProto
public partial class UnitGearItemInfo : AMessage, IProto
{
public static RoleGearItemInfo Create(Scene scene)
public static UnitGearItemInfo Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<RoleGearItemInfo>();
return scene.MessagePoolComponent.Rent<UnitGearItemInfo>();
}
public override void Dispose()
{
Id = default;
ConfigId = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<RoleGearItemInfo>(this);
GetScene().MessagePoolComponent.Return<UnitGearItemInfo>(this);
#endif
}
[ProtoMember(1)]
@@ -30,11 +30,11 @@ namespace NBC
public int ConfigId { get; set; }
}
[ProtoContract]
public partial class RoleGearInfo : AMessage, IProto
public partial class UnitGearInfo : AMessage, IProto
{
public static RoleGearInfo Create(Scene scene)
public static UnitGearInfo Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<RoleGearInfo>();
return scene.MessagePoolComponent.Rent<UnitGearInfo>();
}
public override void Dispose()
{
@@ -49,29 +49,29 @@ namespace NBC
Leader = default;
Feeder = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<RoleGearInfo>(this);
GetScene().MessagePoolComponent.Return<UnitGearInfo>(this);
#endif
}
[ProtoMember(1)]
public RoleGearItemInfo Rod { get; set; }
public UnitGearItemInfo Rod { get; set; }
[ProtoMember(2)]
public RoleGearItemInfo Reel { get; set; }
public UnitGearItemInfo Reel { get; set; }
[ProtoMember(3)]
public RoleGearItemInfo Bobber { get; set; }
public UnitGearItemInfo Bobber { get; set; }
[ProtoMember(4)]
public RoleGearItemInfo Hook { get; set; }
public UnitGearItemInfo Hook { get; set; }
[ProtoMember(5)]
public RoleGearItemInfo Bait { get; set; }
public UnitGearItemInfo Bait { get; set; }
[ProtoMember(6)]
public RoleGearItemInfo Lure { get; set; }
public UnitGearItemInfo Lure { get; set; }
[ProtoMember(7)]
public RoleGearItemInfo Weight { get; set; }
public UnitGearItemInfo Weight { get; set; }
[ProtoMember(8)]
public RoleGearItemInfo Line { get; set; }
public UnitGearItemInfo Line { get; set; }
[ProtoMember(9)]
public RoleGearItemInfo Leader { get; set; }
public UnitGearItemInfo Leader { get; set; }
[ProtoMember(10)]
public RoleGearItemInfo Feeder { get; set; }
public UnitGearItemInfo Feeder { get; set; }
}
[ProtoContract]
public partial class Vector3Info : AMessage, IProto
@@ -123,11 +123,11 @@ namespace NBC
public float w { get; set; }
}
[ProtoContract]
public partial class RoleFishingInfo : AMessage, IProto
public partial class UnitFishingInfo : AMessage, IProto
{
public static RoleFishingInfo Create(Scene scene)
public static UnitFishingInfo Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<RoleFishingInfo>();
return scene.MessagePoolComponent.Rent<UnitFishingInfo>();
}
public override void Dispose()
{
@@ -136,7 +136,7 @@ namespace NBC
OpenLight = default;
RodSetting = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<RoleFishingInfo>(this);
GetScene().MessagePoolComponent.Return<UnitFishingInfo>(this);
#endif
}
[ProtoMember(1)]
@@ -149,18 +149,18 @@ namespace NBC
public int RodSetting { get; set; }
}
[ProtoContract]
public partial class RoleStateInfo : AMessage, IProto
public partial class UnitStateInfo : AMessage, IProto
{
public static RoleStateInfo Create(Scene scene)
public static UnitStateInfo Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<RoleStateInfo>();
return scene.MessagePoolComponent.Rent<UnitStateInfo>();
}
public override void Dispose()
{
State = default;
Args.Clear();
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<RoleStateInfo>(this);
GetScene().MessagePoolComponent.Return<UnitStateInfo>(this);
#endif
}
[ProtoMember(1)]
@@ -169,11 +169,11 @@ namespace NBC
public List<string> Args = new List<string>();
}
[ProtoContract]
public partial class MapRoleInfo : AMessage, IProto
public partial class MapUnitInfo : AMessage, IProto
{
public static MapRoleInfo Create(Scene scene)
public static MapUnitInfo Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<MapRoleInfo>();
return scene.MessagePoolComponent.Rent<MapUnitInfo>();
}
public override void Dispose()
{
@@ -183,8 +183,9 @@ namespace NBC
State = default;
Gears = default;
FishingInfo = default;
KV.Clear();
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<MapRoleInfo>(this);
GetScene().MessagePoolComponent.Return<MapUnitInfo>(this);
#endif
}
[ProtoMember(1)]
@@ -192,27 +193,29 @@ namespace NBC
[ProtoMember(2)]
public RoleSimpleInfo RoleInfo { get; set; }
[ProtoMember(3)]
public MapRolePositionInfo Location { get; set; }
public MapUnitPositionInfo Location { get; set; }
[ProtoMember(4)]
public RoleStateInfo State { get; set; }
public UnitStateInfo State { get; set; }
[ProtoMember(5)]
public RoleGearInfo Gears { get; set; }
public UnitGearInfo Gears { get; set; }
[ProtoMember(6)]
public RoleFishingInfo FishingInfo { get; set; }
public UnitFishingInfo FishingInfo { get; set; }
[ProtoMember(7)]
public List<KeyValueInt32> KV = new List<KeyValueInt32>();
}
[ProtoContract]
public partial class MapRolePositionInfo : AMessage, IProto
public partial class MapUnitPositionInfo : AMessage, IProto
{
public static MapRolePositionInfo Create(Scene scene)
public static MapUnitPositionInfo Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<MapRolePositionInfo>();
return scene.MessagePoolComponent.Rent<MapUnitPositionInfo>();
}
public override void Dispose()
{
Position = default;
Rotation = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<MapRolePositionInfo>(this);
GetScene().MessagePoolComponent.Return<MapUnitPositionInfo>(this);
#endif
}
[ProtoMember(1)]
@@ -230,14 +233,14 @@ namespace NBC
public override void Dispose()
{
ErrorCode = default;
Roles.Clear();
Units.Clear();
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<Map2C_CreateMapResponse>(this);
#endif
}
public uint OpCode() { return OuterOpcode.Map2C_CreateMapResponse; }
[ProtoMember(1)]
public List<MapRoleInfo> Roles = new List<MapRoleInfo>();
public List<MapUnitInfo> Units = new List<MapUnitInfo>();
[ProtoMember(2)]
public uint ErrorCode { get; set; }
}
@@ -276,14 +279,14 @@ namespace NBC
public override void Dispose()
{
ErrorCode = default;
Roles.Clear();
Units.Clear();
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<Map2C_EnterMapResponse>(this);
#endif
}
public uint OpCode() { return OuterOpcode.Map2C_EnterMapResponse; }
[ProtoMember(1)]
public List<MapRoleInfo> Roles = new List<MapRoleInfo>();
public List<MapUnitInfo> Units = new List<MapUnitInfo>();
[ProtoMember(2)]
public uint ErrorCode { get; set; }
}
@@ -306,7 +309,7 @@ namespace NBC
[ProtoIgnore]
public int RouteType => Fantasy.RouteType.MapRoute;
[ProtoMember(1)]
public MapRolePositionInfo Location { get; set; }
public MapUnitPositionInfo Location { get; set; }
[ProtoMember(2)]
public bool IsStop { get; set; }
}
@@ -331,7 +334,7 @@ namespace NBC
[ProtoIgnore]
public int RouteType => Fantasy.RouteType.MapRoute;
[ProtoMember(1)]
public MapRoleInfo Info { get; set; }
public MapUnitInfo Info { get; set; }
}
/// <summary>
/// 用户离开地图
@@ -380,7 +383,7 @@ namespace NBC
[ProtoMember(1)]
public long Id { get; set; }
[ProtoMember(2)]
public RoleStateInfo State { get; set; }
public UnitStateInfo State { get; set; }
}
/// <summary>
/// 玩家钓组状态变化
@@ -406,7 +409,7 @@ namespace NBC
[ProtoMember(1)]
public long Id { get; set; }
[ProtoMember(2)]
public RoleFishingInfo State { get; set; }
public UnitFishingInfo State { get; set; }
}
/// <summary>
/// 玩家钓组变化
@@ -432,7 +435,7 @@ namespace NBC
[ProtoMember(1)]
public long Id { get; set; }
[ProtoMember(2)]
public RoleGearInfo Gears { get; set; }
public UnitGearInfo Gears { get; set; }
}
/// <summary>
/// 玩家位置变化
@@ -455,6 +458,6 @@ namespace NBC
[ProtoMember(1)]
public long Id { get; set; }
[ProtoMember(2)]
public MapRolePositionInfo Location { get; set; }
public MapUnitPositionInfo Location { get; set; }
}
}

View File

@@ -141,10 +141,7 @@ namespace NBF
// //测试登录
// OnLoginButtonClick().Coroutine();
}
private void LoadData()
{
ConfigAssets.Init();