123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- using CommonLang.Log;
- using pomelo.area;
- using pomelo.connector;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using XmdsBattleClient.Client;
- using XmdsBattleClientBot.Bot;
- using XmdsBattleClientWin32.Func;
- namespace XmdsBattleClientWin32.WinForm
- {
- public partial class FormBot : Form
- {
- public readonly static Logger log = new ConsoleLogger();
- private readonly BotClient bot;
- private long last_update_time;
- private Battle.BattlePanelContainer battle_view;
- public BotClient Bot { get { return bot; } }
- public FormBot()
- {
- InitializeComponent();
- this.bot = new BotClient("bottest", "123456", FormLauncher.LastConfig, null);
- this.bot.Client.GameSocket.IsSaveResponse = true;
- // this.bot.Client.GateSocket.OnError += on_error;
- // this.bot.Client.GameSocket.OnError += on_error;
- this.bot.Client.OnBeginEnterScene += on_gs_begin_enter_scene;
- this.battle_view = new Battle.BattlePanelContainer(bot);
- this.battle_view.Dock = DockStyle.Fill;
- this.Controls.Add(battle_view);
- }
- private void FormBot_Load(object sender, EventArgs e)
- {
- bot.Start();
- }
- private void FormBot_Shown(object sender, EventArgs e)
- {
- relogin();
- }
- private void timer_Update_Tick(object sender, EventArgs e)
- {
- long curTime = CommonLang.CUtils.CurrentTimeMS;
- if (last_update_time == 0)
- {
- last_update_time = curTime;
- }
- int intervalMS = (int)(curTime - last_update_time);
- last_update_time = curTime;
- try
- {
- bot.Update(intervalMS);
- if (battle_view != null)
- {
- battle_view.UpdateBattle(intervalMS);
- }
- }
- catch (Exception err)
- {
- MessageBox.Show(err.Message);
- }
- }
- //-------------------------------------------------------------------------------------------------
- #region Runner
- public static void on_error(Exception err)
- {
- MessageBox.Show(err.Message);
- }
- private void relogin()
- {
- var login = new FormLogin(bot);
- login.OnLogin += on_login;
- login.ShowDialog(this);
- }
- private void select_role()
- {
- var r = new FormCreateRole(bot);
- r.ShowDialog(this);
- }
- private void on_login()
- {
- FormBot.log.Info("on_login...");
- bot.QueueTask(() =>
- {
- start_enter_server();
- });
- }
- private void start_enter_server()
- {
- bot.gate_EnterServer(on_gate_enter_server, (err) =>
- {
- on_error(err);
- relogin();
- });
- }
- protected virtual void on_gate_enter_server(EntryResponse e)
- {
- this.Text = string.Format("帐号:{0} 服务器:{1}", bot.Account, bot.ServerName);
- FormBot.log.Info("on_gate_enter_server : " + this.Text);
- bot.QueueTask(() =>
- {
- if (e.s2c_players.Count > 0 && Program.AUTO_LOGIN)
- {
- log.Info("auto bind player ");
- bot.gate_BindPlayer(e.s2c_players[0].id,
- (rsp) => { log.Info("auto bind player done "); },
- (err) =>
- {
- on_error(err);
- select_role();
- });
- }
- else
- {
- select_role();
- }
- });
- }
- protected virtual void on_gs_begin_enter_scene(XmdsBattleClient.Battle.XmdsBattleClient obj)
- {
- FormBot.log.Info("on_gs_begin_enter_scene : ");
- bot.gs_EnterScene(on_gs_enter_scene, (err) => { on_error(err); relogin(); });
- }
- protected virtual void on_gs_enter_scene(EnterSceneResponse response)
- {
- FormBot.log.Info("on_gs_enter_scene : ");
- if (Program.ARG_TC)
- {
- FormTC form = new FormTC(bot);
- form.Show();
- }
- }
- #endregion
- }
- }
|