94 lines
2.2 KiB
C#
94 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Fantasy;
|
|
using NBC;
|
|
using Fantasy.Entitas;
|
|
using Fantasy.Entitas.Interface;
|
|
|
|
namespace NBF.Fishing2
|
|
{
|
|
public class Map : Entity
|
|
{
|
|
public int MapId;
|
|
|
|
public string RoomCode;
|
|
|
|
/// <summary>
|
|
/// 自己的实体id
|
|
/// </summary>
|
|
public long SelfId;
|
|
|
|
/// <summary>
|
|
/// 好友房地图
|
|
/// </summary>
|
|
public bool IsRoomMap => !string.IsNullOrEmpty(RoomCode);
|
|
|
|
/// <summary>
|
|
/// 地图中的单位
|
|
/// </summary>
|
|
public Dictionary<long, MapUnit> Units = new Dictionary<long, MapUnit>();
|
|
|
|
/// <summary>
|
|
/// 自己的实体
|
|
/// </summary>
|
|
public MapUnit SelfMapUnit => GetUnit(SelfId);
|
|
|
|
|
|
#region System
|
|
|
|
public class MapDestroySystem : DestroySystem<Map>
|
|
{
|
|
protected override void Destroy(Map self)
|
|
{
|
|
self.MapId = 0;
|
|
self.SelfId = 0;
|
|
self.RoomCode = string.Empty;
|
|
self.Units.Clear();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
public MapUnit CreateMapUnit(MapUnitInfo unitInfo)
|
|
{
|
|
var mapUnit = Create<MapUnit>(Scene, unitInfo.Id, true, true);
|
|
mapUnit.SetUnitInfo(unitInfo);
|
|
Add(mapUnit);
|
|
return mapUnit;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取一个单位
|
|
/// </summary>
|
|
/// <param name="self"></param>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public MapUnit GetUnit(long id)
|
|
{
|
|
return Units.GetValueOrDefault(id);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 进入地图
|
|
/// </summary>
|
|
/// <param name="map"></param>
|
|
/// <param name="unit"></param>
|
|
/// <returns></returns>
|
|
public bool Add(MapUnit unit)
|
|
{
|
|
Units.Add(unit.Id, unit);
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 离开地图
|
|
/// </summary>
|
|
/// <param name="self"></param>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public bool Remove(long id)
|
|
{
|
|
return Units.Remove(id);
|
|
}
|
|
}
|
|
} |