Files
Fishing2Server/Hotfix/Game/Player/Entity/PlayerSystem.cs
2026-03-19 16:14:33 +08:00

101 lines
2.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections.Generic;
using System.Net.Http.Headers;
using Fantasy;
using Fantasy.Async;
using Fantasy.Entitas;
using Fantasy.Entitas.Interface;
using Fantasy.Helper;
using NB.Chat;
#pragma warning disable CS8625 // 无法将 null 字面量转换为非 null 的引用类型。
namespace NB.Game;
public sealed class PlayerDestroySystem : DestroySystem<Player>
{
protected override void Destroy(Player self)
{
self.NickName = string.Empty;
self.Level = 0;
self.Exp = 0;
self.Country = string.Empty;
self.Head = string.Empty;
// self.ItemContainer.Dispose();
// self.ItemContainer = null;
// self.FishContainer.Dispose();
// self.FishContainer = null;
// self.Wallet.Dispose();
// self.Wallet = null;
// self.Vip.Dispose();
// self.Vip = null;
// self.Statistics.Dispose();
// self.Statistics = null;
// 退出当前ChatUnit拥有的所有频道
foreach (var (_, chatChannelComponent) in self.Channels)
{
chatChannelComponent.ExitChannel(self.Id, false);
}
// 理论情况下这个self.Channels不会存在因为数据的因为上面已经给清空掉了。
// 但是self.Channels.Clear();还是加上吧,防止以后忘记了。
self.Channels.Clear();
self.SessionRunTimeId = 0;
}
}
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<int, 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
public static MapUnitInfo ToMapUnitInfo(this Player self)
{
var ret = new MapUnitInfo()
{
Id = self.Id,
Position = Vector3Info.Create(),
Rotation = Vector3Info.Create(),
};
var mapUnit = self.GetComponent<MapUnitComponent>();
ret.Position.x = mapUnit.Position.x;
ret.Position.y = mapUnit.Position.y;
ret.Position.z = mapUnit.Position.z;
ret.Rotation.x = mapUnit.Rotation.x;
ret.Rotation.y = mapUnit.Rotation.y;
ret.Rotation.z = mapUnit.Rotation.z;
// ret.Gears
return ret;
}
}