using CommonAI.Zone.Instance; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using XmdsServerNode.Node.Interface; using Pomelo; using XmdsServerNode.Node; using CommonAI.Zone; using CommonLang.ByteOrder; using CommonLang.Property; using CommonLang.IO.Attribute; using CommonLang.Log; using CommonLang.Concurrent; using CommonLang; using static Pomelo.FuckFastStream; namespace XmdsServerEdgeJS.Zone { public class XmdsPlayer : IPlayer { private readonly Logger log = LoggerFactory.GetLogger("XmdsPlayer"); private readonly string player_uuid; private readonly XmdsZoneNode node; private readonly ZoneService service; private readonly string instanceId; private IFastSession connectServerId; private readonly string uid; private HashMap attributes = new HashMap(1); private AtomicReference mBindingObject = new AtomicReference(null); public XmdsPlayer(ZoneService svc, string uuid, string uid, IFastSession connectServerId, XmdsZoneNode node) { this.node = node; this.service = svc; this.player_uuid = uuid; this.instanceId = node.InstanceID; this.connectServerId = connectServerId; this.uid = uid; } public ServerZoneNode Node { get { return node.Node; } } public string PlayerUUID { get { return player_uuid; } } public string InstanceId { get { return instanceId; } } public IFastSession ConnectServerId { get { return connectServerId; } } public string Uid { get { return uid; } } public void OnNetReconnect(string connetorId, IFastSession session) { if(this.connectServerId != null && this.connectServerId.ConnectorId != null && connetorId != null && this.connectServerId.ConnectorId.Equals(connetorId)) { this.connectServerId = session; } } /// /// 用于显示的名字 /// public string DisplayName { get { return ""; } } /// /// 绑定数据 /// public ServerZoneNode.ZoneNodePlayer BindingObject { get { return mBindingObject.Value; } set { mBindingObject.Value = value; } } /// /// 绑定的玩家 /// public InstancePlayer BindingActor { get { var binding = BindingObject; if (binding != null) { return binding.BindingActor; } return null; } } /// /// 向此玩家发送战斗服事件 /// /// public void SendToClient(ArraySegment msg) { //通过fastStream发送 //try //{ FastStream.instance().Send(connectServerId, uid, instanceId, msg); //} //catch (Exception err) //{ // log.Error(err.Message, err); //} } /// /// 发送事件到游戏服 /// /// public void SendToGameServer(object msg) { node.SendToGameServer(EventType.areaEvent.ToString(), msg); } public void ReceiveMsgR2B(object data) { node.Node.ReceiveMsgR2B(this, data); } public InstancePlayer getInstancePlayer() { return node.Node.GetPlayer(this.player_uuid); } public bool IsAttribute(string key) { return attributes.ContainsKey(key); } public void SetAttribute(string key, object value) { attributes.Put(key, value); } public object GetAttribute(string key) { return attributes.Get(key); } public void Dispose() { attributes.Clear(); } } }