using System; using System.Threading; namespace ET { public class ConsoleComponentAwakeSystem : StartSystem { public override void Start(ConsoleComponent self) { self.Start().Coroutine(); } } public static class ConsoleMode { public const string None = ""; public const string Repl = "repl"; } public class ConsoleComponent : Entity { public CancellationTokenSource CancellationTokenSource; public string Mode = ""; public async ETVoid Start() { this.CancellationTokenSource = new CancellationTokenSource(); while (true) { try { string line = await System.Threading.Tasks.Task.Factory.StartNew(() => { Console.Write($"{this.Mode}> "); return Console.In.ReadLine(); }, this.CancellationTokenSource.Token); line = line.Trim(); if (this.Mode != "") { bool isExited = true; switch (this.Mode) { case ConsoleMode.Repl: { ReplComponent replComponent = this.GetComponent(); if (replComponent == null) { Console.WriteLine($"no command: {line}!"); break; } //string name=null; //if(line.StartsWith('_')) //{ // name = line.Substring(1); // while (true) // { // string str = Console.ReadLine(); // if (str.Equals("data")) // { // line = $"foreach (var item in ET.UnitComponent.Instance.GetAll()){{if(item.GetComponent().NickName=={name}){{" + // $"var data = item.GetComponent();" + // $"foreach(var value in data.GoodsCapacityDic.Values){{ET.Log.Info(\"CapacityDic:\"+value.ToString());}}" + // $"ET.Log.Info(\"BattleExpSpeed:\"+data.BattleExpSpeed.ToString());" + // $"ET.Log.Info(\"IdleExpSpeed:\"+data.IdleExpSpeed.ToString());" + // $"ET.Log.Info(\"MainStoryRecordId:\"+data.MainStoryRecordId.ToString());" + // $"}}}}"; // } // if (str.Equals("character")) // { // line = $@"foreach (var item in ET.UnitComponent.Instance.GetAll()){{if(item.GetComponent().NickName=={name}){{ // var character = item.GetComponent(); // ET.Log.Info(""Hp:""+ character.GetAsInt(ET.NumericType.Hp).ToString()); // ET.Log.Info(""MaxHp:""+ character.GetAsInt(ET.NumericType.MaxHp).ToString()); // ET.Log.Info(""Mp:""+ character.GetAsInt(ET.NumericType.Mp).ToString()); // ET.Log.Info(""MaxMp:""+ character.GetAsInt(ET.NumericType.MaxMp).ToString()); // }}}}"; // } // if (str.Equals("exit")) // { // line = $"exit"; // } // try // { // isExited = await replComponent.Run(line, this.CancellationTokenSource.Token); // if (isExited) break; // } // catch (Exception e) // { // Console.WriteLine(e); // } // } //} break; } } if (isExited) { this.Mode = ""; } continue; } switch (line) { case "close": try { await Game.EventSystem.Publish(new EventType.CloseServer()); } catch (Exception e) { Console.WriteLine(e); } break; case "reload": try { Game.EventSystem.Add(DllHelper.GetHotfixAssembly()); Console.WriteLine($"@热更完成了"); } catch (Exception e) { Console.WriteLine(e); } break; case "repl": try { this.Mode = ConsoleMode.Repl; this.AddComponent(); } catch (Exception e) { Console.WriteLine(e); } break; default: Console.WriteLine($"no such command: {line}"); break; } } catch (Exception e) { Console.WriteLine(e); } } } } }