XmdsPlayer.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using CommonAI.Zone.Instance;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using XmdsServerNode.Node.Interface;
  8. using Pomelo;
  9. using XmdsServerNode.Node;
  10. using CommonAI.Zone;
  11. using CommonLang.ByteOrder;
  12. using CommonLang.Property;
  13. using CommonLang.IO.Attribute;
  14. using CommonLang.Log;
  15. using CommonLang.Concurrent;
  16. using CommonLang;
  17. namespace XmdsServerEdgeJS.Zone
  18. {
  19. public class XmdsPlayer : IPlayer
  20. {
  21. private readonly Logger log = LoggerFactory.GetLogger("XmdsPlayer");
  22. private readonly string player_uuid;
  23. private readonly XmdsZoneNode node;
  24. private readonly ZoneService service;
  25. private readonly string instanceId;
  26. private readonly IFastSession connectServerId;
  27. private readonly string uid;
  28. private HashMap<string, object> attributes = new HashMap<string, object>(1);
  29. private AtomicReference<ServerZoneNode.ZoneNodePlayer> mBindingObject = new AtomicReference<ServerZoneNode.ZoneNodePlayer>(null);
  30. public XmdsPlayer(ZoneService svc, string uuid, string uid, IFastSession connectServerId, XmdsZoneNode node)
  31. {
  32. this.node = node;
  33. this.service = svc;
  34. this.player_uuid = uuid;
  35. this.instanceId = node.InstanceID;
  36. this.connectServerId = connectServerId;
  37. this.uid = uid;
  38. }
  39. public ServerZoneNode Node { get { return node.Node; } }
  40. public string PlayerUUID { get { return player_uuid; } }
  41. public string InstanceId { get { return instanceId; } }
  42. public IFastSession ConnectServerId { get { return connectServerId; } }
  43. public string Uid { get { return uid; } }
  44. /// <summary>
  45. /// 用于显示的名字
  46. /// </summary>
  47. public string DisplayName { get { return ""; } }
  48. /// <summary>
  49. /// 绑定数据
  50. /// </summary>
  51. public ServerZoneNode.ZoneNodePlayer BindingObject
  52. {
  53. get { return mBindingObject.Value; }
  54. set { mBindingObject.Value = value; }
  55. }
  56. /// <summary>
  57. /// 绑定的玩家
  58. /// </summary>
  59. public InstancePlayer BindingActor
  60. {
  61. get
  62. {
  63. var binding = BindingObject;
  64. if (binding != null) { return binding.BindingActor; }
  65. return null;
  66. }
  67. }
  68. /// <summary>
  69. /// 向此玩家发送战斗服事件
  70. /// </summary>
  71. /// <param name="msg"></param>
  72. public void SendToClient(ArraySegment<byte> msg)
  73. {
  74. //通过fastStream发送
  75. //try
  76. //{
  77. FastStream.instance().Send(connectServerId, uid, instanceId, msg);
  78. //}
  79. //catch (Exception err)
  80. //{
  81. // log.Error(err.Message, err);
  82. //}
  83. }
  84. /// <summary>
  85. /// 发送事件到游戏服
  86. /// </summary>
  87. /// <param name="msg"></param>
  88. public void SendToGameServer(object msg)
  89. {
  90. node.SendToGameServer(EventType.areaEvent.ToString(), msg);
  91. }
  92. public void ReceiveMsgR2B(object data)
  93. {
  94. node.Node.ReceiveMsgR2B(this, data);
  95. }
  96. public InstancePlayer getInstancePlayer()
  97. {
  98. return node.Node.GetPlayer(this.player_uuid);
  99. }
  100. public bool IsAttribute(string key)
  101. {
  102. return attributes.ContainsKey(key);
  103. }
  104. public void SetAttribute(string key, object value)
  105. {
  106. attributes.Put(key, value);
  107. }
  108. public object GetAttribute(string key)
  109. {
  110. return attributes.Get(key);
  111. }
  112. public void Dispose()
  113. {
  114. attributes.Clear();
  115. }
  116. }
  117. }