123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- using CommonAI.Zone;
- using CommonAI.ZoneClient;
- using CommonAIClient.Client;
- using CommonLang;
- using CommonLang.Protocol;
- using RoomService.Net.BsServer;
- using System;
- using CommonLang.Log;
- namespace Pomelo.DotNetClient.NetClient
- {
-
-
-
- public class BaseBattleClient : AbstractBattle, IDisposable
- {
- protected bool BattleOk = false;
- protected readonly Logger log;
- protected readonly INetClient mClient;
- private Ping send_ping = new Ping();
- private TimeInterval<int> ping_task = new TimeInterval<int>(2000);
-
- private long mRecvPak = 0;
- private long mSentPak = 0;
-
- public override bool IsNet { get { return true; } }
- public override KickedByServerNotifyB2C KickMessage { get { return null; } }
- public override int CurrentPing { get { return Layer.CurrentPing; } }
- public override long RecvPackages { get { return mRecvPak; } }
- public override long SendPackages { get { return mSentPak; } }
- public int PingIntervalMS
- {
- get
- {
- return ping_task.IntervalTimeMS;
- }
- set
- {
- ping_task = new TimeInterval<int>(Math.Max(1000, value));
- }
- }
-
- public BaseBattleClient(INetClient client)
- : base(client.DataRoot)
- {
- this.log = LoggerFactory.GetLogger(GetType().Name);
- this.mClient = client;
- this.Layer.ActorSyncMode = SyncMode.MoveByClient_PreSkillByClient;
- }
- protected override void Disposing()
- {
- mHandleMessage = null;
- base.Disposing();
- }
-
- #region _PomeloNetwork_
-
-
-
-
- public override void SendAction(CommonAI.Zone.Action action)
- {
- if(BattleOk)
- {
- this.mClient.SendBattleMessage(action);
- this.mSentPak++;
- }
-
- }
- public override void BattleReady(bool bok)
- {
- BattleOk = bok;
- base.BattleReady(bok);
- }
- public virtual void OnReceivedBattleMessage(IMessage data)
- {
- this.Layer.ProcessMessage(data);
- this.mRecvPak++;
-
-
-
-
-
-
-
- if (this.mHandleMessage != null)
- {
- this.mHandleMessage.Invoke(this, data);
- }
- }
- #endregion
-
- #region _MainThread_
- public override void BeginUpdate(int intervalMS)
- {
- base.BeginUpdate(intervalMS);
- if (ping_task.Update(Layer.CurrentIntervalMS))
- {
- send_ping.Begin();
- Layer.SendAction(send_ping);
- }
- }
- public override void Update()
- {
- base.Update();
- }
- #endregion
-
- #region _Delegate_
- public delegate void OnHandleMessage(BaseBattleClient bc, IMessage msg);
- private OnHandleMessage mHandleMessage;
- public event OnHandleMessage HandleMessage { add { mHandleMessage += value; } remove { mHandleMessage -= value; } }
- #endregion
-
- }
- }
|