public void PlaceMapMarker(MapLinkMessage maplinkMessage) { Log($"Viewing {maplinkMessage.Text}"); var map = DataManager.GetExcelSheet <TerritoryType>().GetRow(maplinkMessage.TerritoryId).Map; var maplink = new MapLinkPayload(maplinkMessage.TerritoryId, map.Row, maplinkMessage.X, maplinkMessage.Y); GameGui.OpenMapWithMapLink(maplink); }
public void TeleportToAetheryte(MapLinkMessage maplinkMessage) { if (!Config.Teleport) { return; } var aetheryteName = GetNearestAetheryte(maplinkMessage); if (aetheryteName != "") { Log($"Teleporting to {aetheryteName}"); CommandManager.ProcessCommand($"/tp {aetheryteName}"); } else { LogError($"Cannot find nearest aetheryte of {maplinkMessage.PlaceName}({maplinkMessage.X}, {maplinkMessage.Y})."); } }
public void GetTarget() { string messageText = ""; float coordX = 0; float coordY = 0; float scale = 100; var target = TargetManager.Target; var territoryType = ClientState.TerritoryType; var place = DataManager.GetExcelSheet <Map>(ClientState.ClientLanguage).FirstOrDefault(m => m.TerritoryType.Row == territoryType); var placeName = place.PlaceName.Row; scale = place.SizeFactor; var placeNameRow = DataManager.GetExcelSheet <PlaceName>(ClientState.ClientLanguage).GetRow(placeName).Name; if (target != null) { coordX = (float)ToMapCoordinate(target.Position.X, scale); coordY = (float)ToMapCoordinate(target.Position.Z, scale); messageText += placeNameRow; messageText += " X:" + coordX.ToString("#0.0"); messageText += " Y:" + coordY.ToString("#0.0"); var newMapLinkMessage = new MapLinkMessage( (ushort)XivChatType.Debug, target.Name.ToString(), messageText, coordX, coordY, scale, territoryType, placeNameRow, DateTime.Now ); Config.MapLinkMessageList.Add(newMapLinkMessage); if (Config.MapLinkMessageList.Count > Config.MaxRecordings) { var tempList = Config.MapLinkMessageList.OrderBy(e => e.RecordTime); Config.MapLinkMessageList.RemoveRange(0, Config.MapLinkMessageList.Count - Config.MaxRecordings); var infoMsg = $"There are too many records, truncated to the latest {Config.MaxRecordings} records"; PluginLog.Information(infoMsg); } } }
public string GetNearestAetheryte(MapLinkMessage maplinkMessage) { string aetheryteName = ""; double distance = 0; foreach (var data in Aetherytes) { if (!data.IsAetheryte) { continue; } if (data.Territory.Value == null) { continue; } if (data.PlaceName.Value == null) { continue; } var scale = maplinkMessage.Scale; if (data.Territory.Value.RowId == maplinkMessage.TerritoryId) { var mapMarker = AetherytesMap.FirstOrDefault(m => (m.DataType == 3 && m.DataKey == data.RowId)); if (mapMarker == null) { LogError($"Cannot find aetherytes position for {maplinkMessage.PlaceName}#{data.PlaceName.Value.Name}"); continue; } var AethersX = ConvertMapMarkerToMapCoordinate(mapMarker.X, scale); var AethersY = ConvertMapMarkerToMapCoordinate(mapMarker.Y, scale); Log($"Aetheryte: {data.PlaceName.Value.Name} ({AethersX} ,{AethersY})"); double temp_distance = Math.Pow(AethersX - maplinkMessage.X, 2) + Math.Pow(AethersY - maplinkMessage.Y, 2); if (aetheryteName == "" || temp_distance < distance) { distance = temp_distance; aetheryteName = data.PlaceName.Value.Name; } } } return(aetheryteName); }
private void Chat_OnChatMessage(XivChatType type, uint senderId, ref SeString sender, ref SeString message, ref bool isHandled) { if (!Config.Recording) { return; } bool hasMapLink = false; float coordX = 0; float coordY = 0; float scale = 100; MapLinkPayload maplinkPayload = null; foreach (var payload in message.Payloads) { if (payload is MapLinkPayload mapLinkload) { maplinkPayload = mapLinkload; hasMapLink = true; // float fudge = 0.05f; scale = mapLinkload.TerritoryType.Map.Value.SizeFactor; // coordX = ConvertRawPositionToMapCoordinate(mapLinkload.RawX, scale) - fudge; // coordY = ConvertRawPositionToMapCoordinate(mapLinkload.RawY, scale) - fudge; coordX = mapLinkload.XCoord; coordY = mapLinkload.YCoord; Log($"TerritoryId: {mapLinkload.TerritoryType.RowId} {mapLinkload.PlaceName} ({coordX} ,{coordY})"); } } string messageText = message.TextValue; if (hasMapLink) { var newMapLinkMessage = new MapLinkMessage( (ushort)type, sender.TextValue, messageText, coordX, coordY, scale, maplinkPayload.TerritoryType.RowId, maplinkPayload.PlaceName, DateTime.Now ); bool filteredOut = false; if (sender.TextValue.ToLower() == "sonar") { filteredOut = true; } bool alreadyInList = Config.MapLinkMessageList.Any(w => { bool sameText = w.Text == newMapLinkMessage.Text; var timeoutMin = new TimeSpan(0, Config.FilterDupTimeout, 0); if (newMapLinkMessage.RecordTime < w.RecordTime + timeoutMin) { bool sameX = (int)(w.X * 10) == (int)(newMapLinkMessage.X * 10); bool sameY = (int)(w.Y * 10) == (int)(newMapLinkMessage.Y * 10); bool sameTerritory = w.TerritoryId == newMapLinkMessage.TerritoryId; return(sameTerritory && sameX && sameY); } return(sameText); }); if (Config.FilterDuplicates && alreadyInList) { filteredOut = true; } if (!filteredOut && Config.FilteredChannels.IndexOf((ushort)type) != -1) { filteredOut = true; } if (!filteredOut) { Config.MapLinkMessageList.Add(newMapLinkMessage); if (Config.MapLinkMessageList.Count > Config.MaxRecordings) { var tempList = Config.MapLinkMessageList.OrderBy(e => e.RecordTime); Config.MapLinkMessageList.RemoveRange(0, Config.MapLinkMessageList.Count - Config.MaxRecordings); var infoMsg = $"There are too many records, truncated to the latest {Config.MaxRecordings} records"; PluginLog.Information(infoMsg); } Config.Save(); } } }
private void DrawMaplinks() { // sender, text, time, view, tp, del int columns = 5; if (Config.Teleport) { columns++; } if (ImGui.Button(_localizer.Localize("Clear"))) { Config.MapLinkMessageList.Clear(); Config.Save(); } // right alignment ? ImGui.SameLine(ImGui.GetCursorPosX() + ImGui.GetColumnWidth() - ImGui.CalcTextSize(_localizer.Localize("Target")).X - ImGui.GetScrollX() - ImGui.GetStyle().ItemSpacing.X); if (ImGui.Button(_localizer.Localize("Target"))) { Plugin.GetTarget(); Config.Save(); } ImGui.Columns(columns, "Maplinks", true); ImGui.Separator(); ImGui.Text(_localizer.Localize("Sender")); ImGui.NextColumn(); ImGui.Text(_localizer.Localize("Message")); ImGui.NextColumn(); ImGui.Text(_localizer.Localize("Time")); ImGui.NextColumn(); ImGui.Text(_localizer.Localize("Retrieve")); ImGui.NextColumn(); if (Config.Teleport) { ImGui.Text(_localizer.Localize("Teleport")); ImGui.NextColumn(); } ImGui.Text(_localizer.Localize("Delete")); ImGui.NextColumn(); ImGui.Separator(); MapLinkMessage toDelete = null; List <MapLinkMessage> listToDisplay = Config.MapLinkMessageList; if (Config.SortDesc) { listToDisplay = listToDisplay.OrderByDescending(mlm => mlm.RecordTime).ToList(); } else { listToDisplay = listToDisplay.OrderBy(mlm => mlm.RecordTime).ToList(); } for (int i = 0; i < listToDisplay.Count(); i++) { var maplinkMessage = listToDisplay[i]; ImGui.Text(maplinkMessage.Sender); ImGui.NextColumn(); ImGui.TextUnformatted(maplinkMessage.Text); ImGui.NextColumn(); ImGui.Text(maplinkMessage.RecordTime.ToString()); ImGui.NextColumn(); if (ImGui.Button(_localizer.Localize("View") + "##" + i.ToString())) { Plugin.PlaceMapMarker(maplinkMessage); } ImGui.NextColumn(); if (Config.Teleport) { if (ImGui.Button(_localizer.Localize("Tele") + "##" + i.ToString())) { Plugin.TeleportToAetheryte(maplinkMessage); } ImGui.NextColumn(); } if (ImGui.Button(_localizer.Localize("Del") + "##" + i.ToString())) { toDelete = maplinkMessage; } ImGui.NextColumn(); ImGui.Separator(); } if (null != toDelete) { Config.MapLinkMessageList.Remove(toDelete); Config.Save(); } }