public BotListViewItem(string name, int index, AddBotConfig add, BotConfig cfg) : base(name) { lock (this) { var bot = BotFactory.Instance.CreateBotRunner(cfg, add, name); this.Client = bot.Client; this.Runner = bot; this.Events = new StringBuilder(); this.Runner.Client.IsAutoUpdateBattle = true; if (cfg.NoBattleView == false) { this.BattleView = new BotGamePanelContainer(bot); this.BattleView.AutoUpdateBattleClient = false; this.BattleView.Init(this.Client); this.BattleView.Dock = DockStyle.Fill; } this.Tag = bot; var colums = bot.Columns; for (int i = 1; i < colums.Length; i++) { this.SubItems.Add(colums[i]); } } }
public virtual BotRunner CreateBotRunner(BotConfig cfg, AddBotConfig add, string account) { var c = new RPGClient(this.DataFactory.MessageCodec, new ClientInfo() { sdkName = "OneGame" }); return(new BotRunner(c, cfg, add, account)); }
public static void TrySaveAddConfig(AddBotConfig add) { if (BotLauncher.IsAuto == false) { var save = XmlUtil.ObjectToXml(add); XmlUtil.SaveXML(Application.StartupPath + "/bot_add.save", save); foreach (object mt_config in add.ModuleConfigs) { var type = mt_config.GetType(); SaveModule(type.DeclaringType.Name, type); } } }
//------------------------------------------------------------------------------------------------------------- #region OP private void StartBots(string name_prefix = null, int count = 1, bool keep = false) { var add = AddBotConfig.TryLoadAddConfig(); if (name_prefix != null) { add.name_format = name_prefix; add.count = count; add.index = lastIndex; } else { var servers = RPGClientTemplateManager.Instance.GetAllServers(); var servers_optionals = new DeepEditor.Common.G2D.DataGrid.OptionalList(); servers_optionals.AddRange(servers); servers_optionals.Converter = new Func <System.Reflection.MemberInfo, object, object>((field, value) => { if (value is Data.ServerInfo server) { return(server.id); } return(value); }); add.index = lastIndex; if (keep == false) { var dialog = new G2DPropertyDialog <AddBotConfig>(add); { dialog.Text = "1"; dialog.PropertyGrid.SelectedDescriptorObject.AppendOptionals(nameof(AddBotConfig.serverID), servers_optionals); var res = dialog.ShowDialog(); if (res == System.Windows.Forms.DialogResult.OK) { add = dialog.SelectedObject; } else { return; } } } else { add.count = count; } // add = G2DPropertyDialog<AddBotConfig>.Show("1", add); } if (add != null) { try { if (add.name_format.Contains("{0}") && !string.IsNullOrEmpty(add.digit_format)) { var starting = new List <BotListViewItem>(); for (int i = 0; i < add.count; i++) { var id = add.index + i; var name = string.Format(add.name_format, id.ToString(add.digit_format)); var item = new BotListViewItem(name, id, add, config); list_Bots.Items.Add(item); starting.Add(item); } Task.Run(async() => { foreach (var e in starting) { if (config.AddBotIntervalMS > 0) { await Task.Delay(config.AddBotIntervalMS); } this.Invoke(new Action(() => { e.Runner.Start(); })); } }).ConfigureAwait(true); } else { var name = add.name_format; var item = new BotListViewItem(name, lastIndex, add, config); list_Bots.Items.Add(item); item.Runner.Start(); } } catch (Exception err) { MessageBox.Show(err.Message); } this.started = true; this.lastIndex = add.index + add.count; if (keep == false) { AddBotConfig.TrySaveAddConfig(add); } } }
public virtual AddBotConfig CreateAddBotConfig() { var ret = new AddBotConfig(); return(ret); }