private async void Handle(Player player, string text) { var rt = RTVar.Parse(text); var world = await Database.GetWorld(player.CurrentWorld); if (!rt.IsValid()) { return; } var instance = new TextEventHandler() { Player = player, World = world, Data = text, Rt = rt }; var method = instance.GetType() .GetMethods() .FirstOrDefault(x => { var attribute = x.GetCustomAttribute(typeof(TextPacketAttribute)); if (attribute == null) { return(false); } var type = attribute?.GetType(); var textProperty = type?.GetProperty("TextName"); var textValue = textProperty?.GetValue(attribute).ToString(); var lobbyProperty = type?.GetProperty("RequireLobby"); var lobbyValue = (bool)lobbyProperty?.GetValue(attribute); var defaultProperty = type?.GetProperty("DefaultLobby"); var defaultValue = (bool)defaultProperty?.GetValue(attribute); if (!defaultValue) { if (lobbyValue != player.InLobby) { return(false); } } return(textValue != null && text.StartsWith(textValue)); }); //instance.GetType().GetProperty("Rt").SetValue(instance, rt); //instance.GetType().GetProperty("World").SetValue(instance, world); //instance.GetType().GetProperty("Player").SetValue(instance, player); method?.Invoke(instance, null); }
public void OnDialogReturn() { if (Player.InDialog) { Player.InDialog = false; Data += "edr|1\n"; new DialogEvent(Player, World, RTVar.Parse(Data)); } else { Player.Disconnect(); } }
private void Handle(Player player, World world, RTVar rt) { if (rt.Size < 2) { return; } if (rt.Get(1).Key != "dialog_name") { return; } var name = ""; var instance = new DialogEventHandler() { Player = player, World = world, }; foreach (var pair in rt.Pairs) { if (pair.Key == "" || pair.Value == "") { return; } else if (pair.Key == "tilex") { if (int.TryParse(pair.Value, out var x)) { instance.DialogData.Pos.X = x; } } else if (pair.Key == "tiley") { if (int.TryParse(pair.Value, out var y)) { instance.DialogData.Pos.Y = y; } } else if (pair.Key == "dialog_name") { name = pair.Value; } if (name == "") { continue; } instance.Pair = pair; var method = instance.GetType() .GetMethods() .FirstOrDefault(x => { var attribute = x.GetCustomAttribute(typeof(DialogAttribute)); if (attribute == null) { return(false); } var type = attribute.GetType(); var property = type?.GetProperty("DialogName"); var value = property.GetValue(attribute); return(value.ToString() == name); }); var result = (bool)method?.Invoke(instance, null); if (!result) { return; } } }
public DialogEvent(Player player, World world, RTVar rt) { Handle(player, world, rt); }