Advertisement
Guest User

Untitled

a guest
May 4th, 2023
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.79 KB | None | 0 0
  1. local function AvailableCustomPins()
  2. local count = 0
  3. for _, b in pairs(FyrMM.CustomPinList) do
  4. count = count + #b
  5. end
  6. return count
  7. end
  8.  
  9. local function IsCustomPinsLoading()
  10. for _, b in pairs(FyrMM.LoadingCustomPins) do
  11. if b then
  12. return b
  13. end
  14. end
  15. return false
  16. end
  17.  
  18. local function GetQuestFreePinIndex()
  19. local index = LastQuestPinIndex
  20. if not tableIsEmpty(FreeQuestPinIndex) then
  21. index = table.remove(FreeQuestPinIndex)
  22. return index
  23. end
  24. index = index + 1
  25. LastQuestPinIndex = index
  26. return index
  27. end
  28.  
  29. function RequestJournalQuestConditionAssistance(questIndex, stepIndex, conditionIndex, assisted)
  30. local taskId = FyrMM.RequestJournalQuestConditionAssistance(questIndex, stepIndex, conditionIndex, assisted)
  31. local tag = ZO_MapPin.CreateQuestPinTag(questIndex, stepIndex, conditionIndex)
  32. local currentTime = GetGameTimeMilliseconds()
  33. if currentTime - FyrMM.LastQuestPinRequest > FYRMM_QUEST_PIN_REQUEST_MINIMUM_DELAY then
  34. FyrMM.questPinCount = GetQuestPinCount()
  35. QuestPinsUpdating = true
  36. end
  37. if taskId ~= nil and not FyrMM.Halted then
  38. FyrMM.LastQuestPinRequest = currentTime
  39. local currentTask = {}
  40. currentTask = tag
  41. currentTask.RequestTimeStamp = FyrMM.LastQuestPinRequest
  42. currentTask.MapId = CurrentMap.MapId
  43. currentTask.Fetched = true
  44. currentTask.ZO_MapVisible = ZO_WorldMap:IsHidden()
  45. CurrentTasks[taskId] = currentTask
  46. end
  47. return taskId
  48. end
  49.  
  50. function CancelRequestJournalQuestConditionAssistance(taskId)
  51. if taskId ~= nil and CurrentTasks[taskId] and CurrentTasks[taskId].Fetched then
  52. CurrentTasks[taskId] = nil
  53. FyrMM.CancelRequestJournalQuestConditionAssistance(taskId)
  54. end
  55. end
  56.  
  57. function tableIsEmpty(tbl)
  58. return next(tbl) == nil
  59. end
  60.  
  61. local function CancelUpdates()
  62. EVENT_MANAGER:UnregisterForUpdate("FyrMiniMapDelayedRegister")
  63. -- EVENT_MANAGER:UnregisterForUpdate("FyrMiniMapZoneCheck")
  64. EVENT_MANAGER:UnregisterForUpdate("FyrMiniMapPOIPins")
  65. EVENT_MANAGER:UnregisterForUpdate("FyrMiniMapLocationsPins")
  66. EVENT_MANAGER:UnregisterForUpdate("FyrMiniMapWayshrinesPins")
  67. EVENT_MANAGER:UnregisterForUpdate("FyrMiniMapCustomPins")
  68. -- EVENT_MANAGER:UnregisterForUpdate("FyrMiniMapPOIPinsD")
  69. -- EVENT_MANAGER:UnregisterForUpdate("OnFyrMiniMapInitialPreload")
  70. EVENT_MANAGER:UnregisterForUpdate("OnFyrMiniMapCustomPinGroupAll")
  71. FyrMM.UpdatingCustomPins = {}
  72. FyrMM.LoadingCustomPins = {}
  73. if PinRef then
  74. for i, n in pairs(PRCustomPins) do
  75. if i > MAP_PIN_TYPE_INVALID then
  76. EVENT_MANAGER:UnregisterForUpdate("OnFyrMiniMapCustomPinGroup" .. tostring(i))
  77. end
  78. end
  79. end
  80. end
  81. local function IsCurrentLocation(pin)
  82. if not pin then
  83. return
  84. end
  85.  
  86. local x, y = CurrentMap.PlayerNX, CurrentMap.PlayerNY
  87. local nX = pin.nX or pin.normalizedX
  88. local nY = pin.nY or pin.normalizedY
  89.  
  90. if not (nX and nY and CurrentMap.TrueMapSize) then
  91. return false
  92. end
  93.  
  94. local distance = zo_round(CurrentMap.TrueMapSize * math.sqrt((x - nX) ^ 2 + (y - nY) ^ 2) * 7.55) / 10 -- assumed size is 1.325 times larger than approximate effective skill distance in meters.
  95. local message = zo_strformat(SI_MM_STRING_DISTANCE, distance) .. " m"
  96. if not InformationTooltip:IsHidden() then
  97. InformationTooltip:AddLine(message, "", ZO_HIGHLIGHT_TEXT:UnpackRGB())
  98. end
  99. if not ZO_MapLocationTooltip:IsHidden() then
  100. ZO_MapLocationTooltip:AddLine(message, "", ZO_HIGHLIGHT_TEXT:UnpackRGB())
  101. end
  102.  
  103. return CurrentMap.TrueMapSize * math.sqrt((x - nX) ^ 2 + (y - nY) ^ 2) < 14 -- Approximate distance to use a wayshrine
  104. end
  105.  
  106. local function IsCraftingService(pin)
  107. if not pin then
  108. return false
  109. end
  110.  
  111. local tooltipIndex = pin.locationIndex
  112. if not tooltipIndex then
  113. return false
  114. end
  115.  
  116. for _, v in pairs(FyrMM.CSProviders) do
  117. if v then
  118. for j = 1, GetNumMapLocationTooltipLines(tooltipIndex) do
  119. local _, tooltipLineText = GetMapLocationTooltipLineInfo(tooltipIndex, j)
  120. if tooltipLineText:find(v) then
  121. return true
  122. end
  123. end
  124. end
  125. end
  126.  
  127. return false
  128. end
  129.  
  130. local function SetTooltipMessage(pin)
  131. if not pin then
  132. return
  133. end
  134. if pin:IsFastTravelWayShrine() then
  135. local nodeIndex = pin:GetFastTravelNodeIndex()
  136. local known, name = GetFastTravelNodeInfo(nodeIndex)
  137. if not known then
  138. name = name .. " (undiscovered)"
  139. end
  140. InformationTooltip:AddLine(zo_strformat(SI_WORLD_MAP_LOCATION_NAME, name), "",
  141. ZO_TOOLTIP_DEFAULT_COLOR:UnpackRGB()) -- Wayshrine name
  142. if IsCurrentLocation(pin) then
  143. InformationTooltip:AddLine(GetString(SI_TOOLTIP_WAYSHRINE_CURRENT_LOC), "", ZO_HIGHLIGHT_TEXT:UnpackRGB()) -- Player is near wayshrine
  144. else
  145. if IsInAvAZone() then
  146. InformationTooltip:AddLine(GetString(SI_TOOLTIP_WAYSHRINE_CANT_RECALL_AVA), "",
  147. ZO_ERROR_COLOR:UnpackRGB()) -- Can't travel to a wayshrine in Cyrodiil
  148. else
  149. local _, premiumTimeLeft = GetRecallCooldown()
  150. if premiumTimeLeft == 0 then
  151. InformationTooltip:AddLine(GetString(SI_TOOLTIP_WAYSHRINE_CLICK_TO_RECALL), "",
  152. ZO_HIGHLIGHT_TEXT:UnpackRGB()) -- Recall text line
  153. local cost = GetRecallCost()
  154. if cost > 0 then
  155. if cost <= GetCurrentMoney() then
  156. ZO_ItemTooltip_AddMoney(InformationTooltip, cost, SI_TOOLTIP_RECALL_COST,
  157. CURRENCY_HAS_ENOUGH)
  158. else
  159. ZO_ItemTooltip_AddMoney(InformationTooltip, cost, SI_TOOLTIP_RECALL_COST,
  160. CURRENCY_NOT_ENOUGH)
  161. end
  162. end
  163. else
  164. local cooldownText = zo_strformat(SI_TOOLTIP_WAYSHRINE_RECALL_COOLDOWN, ZO_FormatTimeMilliseconds(
  165. premiumTimeLeft, TIME_FORMAT_STYLE_DESCRIPTIVE, TIME_FORMAT_PRECISION_SECONDS))
  166. InformationTooltip:AddLine(cooldownText, "", ZO_HIGHLIGHT_TEXT:UnpackRGB())
  167. end
  168. end
  169. end
  170. else
  171. local poiIndex = pin:GetPOIIndex()
  172. local zoneIndex = pin:GetPOIZoneIndex()
  173. local poiName, _, poiStartDesc, poiFinishedDesc = GetPOIInfo(zoneIndex, poiIndex)
  174. InformationTooltip:AddLine(zo_strformat(SI_WORLD_MAP_LOCATION_NAME, poiName), "",
  175. ZO_TOOLTIP_DEFAULT_COLOR:UnpackRGB())
  176. local pinType = select(3, MM_GetPOIMapInfo(zoneIndex, poiIndex))
  177. if not (ZO_MapPin.POI_PIN_TYPES[pinType]) then
  178. InformationTooltip:AddLine("(undiscovered)", "", ZO_HIGHLIGHT_TEXT:UnpackRGB())
  179. end
  180. if pinType == MAP_PIN_TYPE_POI_COMPLETE then
  181. if poiFinishedDesc ~= "" then
  182. InformationTooltip:AddLine(poiFinishedDesc, "", ZO_HIGHLIGHT_TEXT:UnpackRGB())
  183. end
  184. else
  185. if poiStartDesc ~= "" then
  186. InformationTooltip:AddLine(poiStartDesc, "", ZO_HIGHLIGHT_TEXT:UnpackRGB())
  187. end
  188. end
  189. end
  190. end
  191. function GetCurrentMapTextureFileInfo()
  192. local tileTexture = (GetMapTileTexture()):lower()
  193. if tileTexture == nil or tileTexture == "" then
  194. return "tamriel_0", "tamriel_", "art/maps/tamriel/"
  195. end
  196. local pos = select(2, tileTexture:find("maps/([%w%-]+)/"))
  197. if pos == nil then
  198. return "tamriel_0", "tamriel_", "art/maps/tamriel/"
  199. end
  200. pos = pos + 1
  201. return string.gsub(string.sub(tileTexture, pos), ".dds", ""),
  202. string.gsub(string.sub(tileTexture, pos), "0.dds", ""), tileTexture:sub(1, pos - 1)
  203. end
  204.  
  205. local function GetTrueMapSize()
  206. local currentMapId = CurrentMap.MapId
  207. local size = FyrMM.MapSizes[currentMapId] or 1
  208. return currentMapId, size
  209. end
  210.  
  211. local function GetMapTextureFileInfo(mapId)
  212. local tileTexture = GetMapTileTextureForMapId(mapId, 1)
  213. if tileTexture == nil or tileTexture == "" then
  214. return "tamriel_0", "tamriel_", "art/maps/tamriel/"
  215. end
  216. local _, pos = tileTexture:find("maps/([%w%-]+)/")
  217. if not pos then
  218. return "tamriel_0", "tamriel_", "art/maps/tamriel/"
  219. end
  220. return string.gsub(string.sub(tileTexture, pos + 1), ".dds", "")
  221. end
  222.  
  223. function FyrMM.MapHalfDiagonal()
  224. FyrMM.DiagonalND = math.sqrt((Fyr_MM_Player:GetRight() - Fyr_MM:GetRight()) ^ 2 +
  225. (Fyr_MM_Player:GetTop() - Fyr_MM:GetTop()) ^ 2)
  226. return FyrMM.DiagonalND
  227. end
  228.  
  229. local function IsAssisted(pinType)
  230. if pinType then
  231. return ASSISTED_PIN_TYPES[pinType] ~= nil -- non-existent key = nil
  232. end
  233. return false
  234. end
  235.  
  236. local function IsQuestType(pinType)
  237. return QUEST_PIN_TYPES[pinType] ~= nil -- non-existent key = nil
  238. end
  239.  
  240. local function valueExists(i, x)
  241. for j = 1, #x do -- instead of ipairs to avoid overhead
  242. if x[j] == i then
  243. return true
  244. end
  245. end
  246. return false
  247. end
  248.  
  249. local function questpinDataExists(pinData, array)
  250. -- Avoid continuous table lookups localize the values instead
  251. local questIndex, questName, conditionText, conditionIndex, normX, normY, radius, stepIndex = pinData.questIndex,
  252. pinData.questName, pinData.conditionText, pinData.conditionIndex, pinData.normalizedX, pinData.normalizedY,
  253. pinData.radius, pinData.stepIndex
  254.  
  255. for i, v in pairs(array) do
  256. if v.questIndex == questIndex and v.questName == questName and v.conditionText == conditionText and
  257. v.conditionIndex == conditionIndex and v.normalizedX == normX and v.normalizedY == normY and v.radius ==
  258. radius and v.stepIndex == stepIndex then
  259. return i
  260. end
  261. end
  262. return nil
  263. end
  264.  
  265. function FyrMM.SetTargetScale(pin, targetScale)
  266. if not (pin or targetScale) or (pin.targetScal == targetScale and targetScale == pin:GetScale()) then
  267. return
  268. end
  269. pin.targetScale = targetScale
  270. local primaryPin, secondaryPin, tertiaryPin = pin.primaryPin, pin.secondaryPin, pin.tertiaryPin
  271. local newScale
  272.  
  273. for i = 1, 10 do
  274. newScale = zo_deltaNormalizedLerp(pin:GetScale(), pin.targetScale, 0.1 * i)
  275. zo_callLater(function()
  276. pin:SetScale(newScale)
  277. if primaryPin then
  278. primaryPin:SetScale(newScale)
  279. end
  280. if secondaryPin then
  281. secondaryPin:SetScale(newScale)
  282. end
  283. if tertiaryPin then
  284. tertiaryPin:SetScale(newScale)
  285. end
  286. end, i * 50)
  287. end
  288.  
  289. zo_callLater(function()
  290. pin:SetScale(pin.targetScale)
  291. if primaryPin then
  292. primaryPin:SetScale(pin.targetScale)
  293. end
  294. if secondaryPin then
  295. secondaryPin:SetScale(pin.targetScale)
  296. end
  297. if tertiaryPin then
  298. tertiaryPin:SetScale(pin.targetScale)
  299. end
  300. pin.targetScale = nil
  301. end, 550)
  302. end
  303.  
  304. local function WayshrineDistances(nDistance)
  305. if not (FyrMM.SV.BorderPins and FyrMM.SV.BorderWayshrine) or FyrMM.currentWayshrineCount == 0 then
  306. return
  307. end
  308.  
  309. if CurrentMap.movedTimeStamp == WayshrineDistancesTimeStamp and WayshrineDistancesTimeStamp ~= 0 then
  310. return
  311. end
  312.  
  313. WayshrineDistancesTimeStamp = CurrentMap.movedTimeStamp
  314.  
  315. local gameTime = GetGameTimeMilliseconds()
  316. local wDi, wDmi, minWD, owDmi = 1, 1, 1, 1
  317.  
  318. if FyrMM.DebugMode then
  319. CALLBACK_MANAGER:FireCallbacks("FyrMMDebug",
  320. "WayshrineDistances Start:" .. tostring(FyrMM.currentWayshrineCount))
  321. end
  322.  
  323. if FyrMM.currentWayshrineCount == 1 then
  324. Wayshrines[1].Closest = Wayshrines[1].isRealWayshrine
  325. return
  326. end
  327.  
  328. EVENT_MANAGER:RegisterForUpdate("OnFyrMiniMapDistances", 100, -- 150 ~8s 50 ~6s -- 100 ~ loads about the same as 50 on initial load.
  329. function()
  330. local playerX, playerY = CurrentMap.PlayerNX, CurrentMap.PlayerNY
  331.  
  332. if Wayshrines[wDi] and Wayshrines[wDi].isRealWayshrine then
  333. Wayshrines[wDi].nDistance =
  334. math.sqrt((playerX - Wayshrines[wDi].nX) ^ 2 + (playerY - Wayshrines[wDi].nY) ^ 2)
  335. if Wayshrines[wDi].nDistance < minWD then
  336. minWD = Wayshrines[wDi].nDistance
  337. wDmi = wDi
  338. end
  339. end
  340.  
  341. if wDi <= FyrMM.currentWayshrineCount then
  342. wDi = wDi + 1
  343. return
  344. end
  345.  
  346. for i, p in pairs(Wayshrines) do
  347. Wayshrines[i].Closest = (i == wDmi)
  348. Wayshrines[i].pin.Closest = (i == wDmi)
  349. end
  350.  
  351. if FyrMM.DebugMode then
  352. CALLBACK_MANAGER:FireCallbacks("FyrMMDebug", "WayshrineDistances Done. (" .. tostring(wDmi) .. ") " ..
  353. tostring(GetGameTimeMilliseconds() - gameTime))
  354. end
  355.  
  356. EVENT_MANAGER:UnregisterForUpdate("OnFyrMiniMapDistances")
  357. end)
  358.  
  359. end
  360.  
  361. local function sort(a, b)
  362. local typeA, typeB = type(a.index), type(b.index) -- avoid repeated calls to the type function
  363.  
  364. if typeA == "number" and typeB == "number" then
  365. return a.index < b.index
  366. end
  367. if typeA == "number" and typeB ~= "number" then
  368. return true
  369. end
  370. if typeA ~= "number" and typeB == "number" then
  371. return false
  372. end
  373.  
  374. return a.index and b.index and tostring(a.index) < tostring(b.index)
  375. end
  376.  
  377. local function FirstKey(Table, offset)
  378. if tableIsEmpty(Table) then
  379. return nil
  380. end
  381. if offset == nil then
  382. offset = 0
  383. end
  384. local key = next(Table, offset)
  385. while key ~= nil do
  386. if Table[key] ~= nil then
  387. return key
  388. end
  389. key = next(Table, key)
  390. end
  391. return nil
  392. end
  393.  
  394. local function QuestGiverDistances()
  395. if not (FyrMM.SV.BorderPins and FyrMM.SV.BorderQuestGivers) or #FyrMM.AvailableQuestGivers == 0 then
  396. return
  397. end
  398.  
  399. local gameTime = GetGameTimeMilliseconds()
  400. local x, y = CurrentMap.PlayerNX, CurrentMap.PlayerNY
  401. local AQGListFull = {}
  402. local multiplier = Fyr_MM:GetWidth()
  403.  
  404. for _, v in ipairs(FyrMM.AvailableQuestGivers) do
  405. if v.nX == nil and v.mpin.normalizedX ~= nil then -- workaround just in case
  406. v.nX = v.mpin.normalizedX
  407. v.nY = v.mpin.normalizedY
  408. end
  409.  
  410. if v.nX and v.nY then
  411. v.nDistance = math.sqrt((x - v.nX) * (x - v.nX) + (y - v.nY) * (y - v.nY))
  412. AQGListFull[#AQGListFull + 1] = {
  413. index = math.floor(multiplier * v.nDistance),
  414. data = v
  415. }
  416. end
  417. end
  418.  
  419. table.sort(AQGListFull, sort)
  420.  
  421. local AQGList = {}
  422. if FyrMM.ZoneStoryPin then
  423. AQGList[#AQGList + 1] = FyrMM.ZoneStoryPin
  424. end
  425.  
  426. for i, n in ipairs(AQGListFull) do
  427. if i > 5 then
  428. break
  429. end
  430. AQGList[#AQGList + 1] = n.data
  431. end
  432.  
  433. if FyrMM.DebugMode then
  434. CALLBACK_MANAGER:FireCallbacks("FyrMMDebug",
  435. "QuestGiverDistances " .. tostring(GetGameTimeMilliseconds() - gameTime))
  436. end
  437. end
  438.  
  439. function FyrMM.MenuTooltip(button, message)
  440. -- Fyr_MM_Menu:SetAlpha(1)
  441. FyrMM.OverMenu = true
  442. Fyr_MM_Close:SetAlpha(1)
  443. if not message or not button then
  444. return
  445. end
  446. InitializeTooltip(InformationTooltip, Fyr_MM, TOPLEFT, 38, button:GetTop())
  447. InformationTooltip:AddLine(message, "", ZO_TOOLTIP_DEFAULT_COLOR:UnpackRGB())
  448. end
  449.  
  450. function GetCurrentMapSize()
  451. return CurrentMap and CurrentMap.TrueMapSize or nil -- Returns assumed calculated map size in feet, returns nil no calculated size or not possible to do so
  452. end
  453.  
  454. local function GetRotatedPosition(x, y) -- Inspired by DeathAngel's RadarMiniMap
  455. if not CurrentMap.Heading then
  456. return
  457. end
  458. if not (x or CurrentMap.PlayerX) then
  459. return x, y
  460. end
  461. local mWidth, mHeight = Fyr_MM_Scroll_Map:GetDimensions()
  462. local ix, iy = (x * mWidth) - CurrentMap.PlayerX, (y * mHeight) - CurrentMap.PlayerY
  463. local rx = math.cos(-CurrentMap.Heading) * ix - math.sin(-CurrentMap.Heading) * iy
  464. local ry = math.sin(-CurrentMap.Heading) * ix + math.cos(-CurrentMap.Heading) * iy
  465. return zo_round(rx), zo_round(ry)
  466. end
  467.  
  468. local function GetNorthFacingPosition(x, y)
  469. local mWidth, mHeight = Fyr_MM_Scroll_Map:GetDimensions()
  470. if x and y then
  471. return math.floor(mWidth * x), math.floor(mHeight * y) -- math.floor is faster than zo_round
  472. end
  473. return x, y
  474. end
  475.  
  476. local function CleanUpPins()
  477. -- faster ways for cleaning up pins result in occasional pins not removing
  478. if not tableIsEmpty(PinsList) then
  479. local cui = 0
  480. local chunk = FyrMM.SV.ChunkSize or 50
  481. local delay = FyrMM.SV.ChunkDelay or 50
  482.  
  483. if FyrMM.DebugMode then
  484. CALLBACK_MANAGER:FireCallbacks("FyrMMDebug",
  485. "CleanUpPins Start:" .. tostring(chunk) .. "..." .. tostring(delay))
  486. end
  487.  
  488. EVENT_MANAGER:RegisterForUpdate("FyrMiniMapCleanupPinsTask", delay, function()
  489. local c = 0
  490. local k = false
  491. cui = cui + 1
  492. local t = GetGameTimeMilliseconds()
  493. for i, l in pairs(PinsList) do
  494. c = c + 1
  495. if c >= chunk then
  496. if FyrMM.DebugMode then
  497. CALLBACK_MANAGER:FireCallbacks("FyrMMDebug", "CleanUpPins " .. tostring(cui) .. " " ..
  498. tostring(GetGameTimeMilliseconds() - t))
  499. end
  500. return
  501. end
  502. if l ~= nil then
  503. if l.m_PinType ~= nil and l.m_PinType >= MAP_PIN_TYPE_INVALID then -- is custom pin
  504. RemoveCustomPin(l)
  505. k = true
  506. end
  507. if not k then -- is regular pin
  508. if l.BorderPin then
  509. RemoveBorderPin(l.BorderPin)
  510. end
  511. l:ClearAnchors()
  512. l:SetHidden(true)
  513. l:SetMouseEnabled(false)
  514. l.nX = nil
  515. l.nY = nil
  516. l:ClearAnchors()
  517. l:SetHidden(true)
  518. l:SetMouseEnabled(false)
  519. -- l:SetTexture(nil)
  520. l:SetDimensions(0, 0)
  521. l.m_PinTag = nil
  522. l.m_PinType = nil
  523. l.m_Pin = nil
  524. l.IsAvailableQuest = nil
  525. l.normalizedX = nil
  526. l.normalizedY = nil
  527. l.radius = nil
  528. l.MapId = nil
  529. l.Index = nil
  530. l.questName = nil
  531. l.PinToolTipText = nil
  532. l.primaryPin = nil
  533. l.secondaryPin = nil
  534. l.tertiaryPin = nil
  535. l.MM_Tag = nil
  536. l.pinAge = nil
  537. l.IsTreasure = nil
  538. l.isDps = nil
  539. l.isHeal = nil
  540. l.isTank = nil
  541. l.ClassId = nil
  542. l.isLeader = nil
  543. PinsList[i] = nil
  544. end
  545.  
  546. end
  547. end
  548. if tableIsEmpty(PinsList) then
  549. if FyrMM.DebugMode then
  550. CALLBACK_MANAGER:FireCallbacks("FyrMMDebug",
  551. "CleanUpPins Done. " .. tostring(GetGameTimeMilliseconds() - t))
  552. end
  553. EVENT_MANAGER:UnregisterForUpdate("FyrMiniMapCleanupPinsTask")
  554. CleanUpMisc()
  555. return
  556. end
  557. end)
  558.  
  559. else
  560. FyrMM.Reloading = false
  561. end
  562. end
  563.  
  564. function FyrMM.playerMoved()
  565. FyrMM.newPos = {CurrentMap.PlayerNX, CurrentMap.PlayerNY} -- GetMapPlayerPosition("player")
  566. if rawequal(FyrMM.newPos, FyrMM.oldPos) then
  567. return false
  568. end
  569. FyrMM.oldPos = FyrMM.newPos
  570. return true
  571. end
  572.  
  573. local function SpeedMeasure()
  574. local PositionLog3D = PositionLog3D -- cache global table
  575. FyrMM.WaypointPins()
  576. local multiplier = FyrMM.GetMapMeasureMultiplier()
  577.  
  578. if tableIsEmpty(PositionLog3D) then
  579. return
  580. end
  581. local x13d, y13d, z13d, t1, x12d, y12d = unpack(PositionLog3D[1], 2, 7)
  582. local x23d, y23d, z23d, t2, x22d, y22d
  583. local d3d, d2d, v13d, va3d = 0, 0, 0, 0
  584. local size = FyrMM.MapSizes[CurrentMap.MapId] or FyrMM.currentMap.TrueMapSize
  585.  
  586. if IsPlayerMoving() then
  587. local i = 2
  588. local PositionLogCounter = PositionLogCounter -- cache global variable
  589. while i <= PositionLogCounter do
  590. x23d, y23d, z23d, t2, x22d, y22d = unpack(PositionLog3D[i], 2, 7)
  591. d3d = math.sqrt((x23d - x13d) ^ 2 + (y23d - y13d) ^ 2 + (z23d - z13d) ^ 2)
  592. v13d = 0.1487 * d3d / math.abs((t2 - t1) / 1000)
  593. x13d, y13d, z13d, t1, x12d, y12d = x23d, y23d, z23d, t2, x22d, y22d
  594. va3d = va3d + v13d
  595. i = i + 1
  596. end
  597.  
  598. if PositionLogCounter == 0 then
  599. return
  600. end
  601.  
  602. local nsize = 0.0143 * math.sqrt((x23d - x13d) ^ 2 + (y23d - y13d) ^ 2) /
  603. math.sqrt((x22d - x12d) ^ 2 + (y22d - y12d) ^ 2)
  604. if nsize and size and nsize ~= math.huge and size < nsize then
  605. FyrMM.currentMap.TrueMapSize = nsize
  606. end
  607. va3d = va3d / (PositionLogCounter - 1) * multiplier
  608. end
  609.  
  610. local MovementSpeedPrevious = FyrMM.MovementSpeedPrevious -- cache global variable
  611. if MovementSpeedPrevious ~= nil then
  612. FyrMM.MovementSpeed = (va3d + MovementSpeedPrevious) / 2
  613. else
  614. FyrMM.MovementSpeed = va3d
  615. end
  616.  
  617. if MovementSpeedPrevious ~= FyrMM.MovementSpeed then
  618. CALLBACK_MANAGER:FireCallbacks("MovementSpeedChanged", va3d)
  619. FyrMM.MovementSpeedPrevious = FyrMM.MovementSpeed
  620. end
  621.  
  622. if va3d > FyrMM.MovementSpeedMax then
  623. FyrMM.MovementSpeedMax = va3d
  624. end
  625.  
  626. if FyrMM.SV.ShowSpeed then
  627. SetSpeedLabel(va3d)
  628. end
  629. end
  630.  
  631. function FyrMM.PositionUpdate()
  632. if not FyrMM.Visible or Fyr_MM:IsHidden() or FyrMM.worldMapShowing or not FyrMM.Initialized or
  633. not Fyr_MM_Scroll_Map_0 or not CurrentMap.Dx then
  634. return
  635. end
  636.  
  637. if FyrMM.GetMapId() ~= CurrentMap.MapId and not FyrMM.CheckingZone then
  638. FyrMM.ZoneCheck()
  639. end
  640.  
  641. local a = GetGameTimeMilliseconds()
  642. local x = CurrentMap.PlayerNX
  643. local y = CurrentMap.PlayerNY
  644. local pheading = CurrentMap.PlayerHeading
  645. if x == nil or pheading == nil then
  646. x, y, pheading = GetMapPlayerPosition("player")
  647. end
  648.  
  649. local moved = CurrentMap.PlayerMoved
  650. CurrentMap.CameraHeading = CurrentMap.CameraHeading or GetPlayerCameraHeading()
  651.  
  652. local cpheading = FyrMM.SV.RotateMap and math.abs(pheading - pi * 2) + CurrentMap.CameraHeading or
  653. CurrentMap.CameraHeading
  654. Fyr_MM_Camera:SetTextureRotation(cpheading)
  655.  
  656. local hpos = (x * (Fyr_MM_Scroll_Map_0:GetWidth() * CurrentMap.Dx)) - (Fyr_MM_Scroll:GetWidth() / 2)
  657. local vpos = (y * (Fyr_MM_Scroll_Map_0:GetHeight() * CurrentMap.Dx)) - (Fyr_MM_Scroll:GetHeight() / 2)
  658.  
  659. local heading = pheading
  660. if FyrMM.SV.PPStyle ~= GetString(SI_MM_STRING_PLAYERANDCAMERA) then
  661. if FyrMM.SV.Heading == "CAMERA" then
  662. heading = CurrentMap.CameraHeading
  663. end
  664. if not moved and FyrMM.SV.Heading == "MIXED" then
  665. heading = CurrentMap.CameraHeading
  666. end
  667. end
  668.  
  669. if moved and FyrMM.SV.ViewRangeFiltering then
  670. UpdateCustomPinPositions()
  671. end
  672.  
  673. if ((x < 1.2 and x > -0.2) and (y < 1.2 and y > -0.2)) then -- Can't let the scroll go too far outside view (Black map issue)
  674. if not Fyr_MM:IsHidden() and moved then
  675. FyrMM.SetMapToPlayerLocation()
  676. end
  677. CurrentMap.hpos = hpos
  678. CurrentMap.vpos = vpos
  679.  
  680. if FyrMM.SV.RotateMap then
  681. Fyr_MM_Scroll:SetHorizontalScroll(0)
  682. Fyr_MM_Scroll:SetVerticalScroll(0)
  683. else
  684. Fyr_MM_Scroll:SetHorizontalScroll(hpos)
  685. Fyr_MM_Scroll:SetVerticalScroll(vpos)
  686. end
  687.  
  688. if FyrMM.SV.WheelMap then
  689. FyrMM.WheelScroll(CurrentMap.hpos, CurrentMap.vpos)
  690. end
  691. else
  692. CurrentMap.hpos = hpos
  693. CurrentMap.vpos = vpos
  694.  
  695. if FyrMM.SV.RotateMap then
  696. Fyr_MM_Scroll:SetHorizontalScroll(0)
  697. Fyr_MM_Scroll:SetVerticalScroll(0)
  698. else
  699. Fyr_MM_Scroll:SetHorizontalScroll(CurrentMap.hpos)
  700. Fyr_MM_Scroll:SetVerticalScroll(CurrentMap.vpos)
  701. end
  702.  
  703. if FyrMM.SV.WheelMap then
  704. FyrMM.WheelScroll(CurrentMap.hpos, CurrentMap.vpos)
  705. end
  706. end
  707.  
  708. FyrMM.UpdateMapTiles(moved) -- can cause tiles not updating but should be fixed by now
  709. CurrentMap.needRescale = true -- REMOVING THIS CAUSES OCCASIONAL PINS DEPHASING ON ROTATING MAPS
  710.  
  711. if FyrMM.SV.RotateMap then
  712. Fyr_MM_Player:SetTextureRotation(0)
  713. FyrMM.AxisPins()
  714. else
  715. Fyr_MM_Player:SetTextureRotation(heading)
  716. end
  717.  
  718. a = GetGameTimeMilliseconds() - a
  719. if FyrMM.DebugMode and a > 0 then
  720. CALLBACK_MANAGER:FireCallbacks("FyrMMDebug", "FyrMM.PositionUpdate " .. tostring(a))
  721. end
  722. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement