Module:AutoUpdateServPrices: Difference between revisions
From MicrasWiki
Jump to navigationJump to search
NewZimiaGov (talk | contribs) No edit summary |
NewZimiaGov (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
--------------------------------------------------------- | |||
-- Module:DailyPriceTable | |||
-- Generates a daily-updated table where each cell | |||
-- refreshes once per day, with random fluctuations | |||
-- stable for that day but new on subsequent days. | |||
--------------------------------------------------------- | |||
local p = {} | local p = {} | ||
--------------------------------------------------------- | |||
-- getCurrentDate | |||
-- Returns today's date in PSSC format, | |||
-- along with dayOfMonth and month for daily logic. | |||
--------------------------------------------------------- | |||
local function getCurrentDate() | local function getCurrentDate() | ||
local startDate = os.time({year = 1999, month = 8, day = 6}) | local startDate = os.time({year = 1999, month = 8, day = 6}) | ||
Line 28: | Line 39: | ||
end | end | ||
--------------------------------------------------------- | |||
-- Product data remains the same | |||
--------------------------------------------------------- | |||
local products = { | local products = { | ||
{"Currency", "Lake Morovia Blockade Fund", 4.05, "stacks"}, | {"Currency", "Lake Morovia Blockade Fund", 4.05, "stacks"}, | ||
Line 68: | Line 82: | ||
} | } | ||
--------------------------------------------------------- | |||
-- Special Date Events | |||
--------------------------------------------------------- | |||
local events = { | local events = { | ||
["1,6"] = "Bayram al-Nur (Festival of Light) [Vaeringheim]", | ["1,6"] = "Bayram al-Nur (Festival of Light) [Vaeringheim]", | ||
["1,18"] = "Chag Or Hadash (Festival of New Light) [Luminaria]", | ["1,18"] = "Chag Or Hadash (Festival of New Light) [Luminaria]", | ||
["1,30"] = "Symposion Eirinis (Symposium of Harmony) [Serena]", | ["1,30"] = "Symposion Eirinis (Symposium of Harmony) [Serena]", | ||
Line 75: | Line 92: | ||
["1,48"] = "Day of Abandonment [Vaeringheim]", | ["1,48"] = "Day of Abandonment [Vaeringheim]", | ||
["1,55"] = "Tikkun Tzel (Repair of Shadows) [Symphonara]", | ["1,55"] = "Tikkun Tzel (Repair of Shadows) [Symphonara]", | ||
["2,6"] = "Panegyris Chrysou (Golden Gathering) [Aurelia]", | ["2,6"] = "Panegyris Chrysou (Golden Gathering) [Aurelia]", | ||
["2,17"] = "Constitution Day [Luminaria]", | ["2,17"] = "Constitution Day [Luminaria]", | ||
["2,19"] = "Mehtap Dalgası (Moonlit Tide) [Vaeringheim]", | ["2,19"] = "Mehtap Dalgası (Moonlit Tide) [Vaeringheim]", | ||
Line 85: | Line 102: | ||
["2,54"] = "Leilat al-Kamar (Night of the Moon) [Lunalis Sancta]", | ["2,54"] = "Leilat al-Kamar (Night of the Moon) [Lunalis Sancta]", | ||
["2,61"] = "Taşrakah (Reverence of the Stone) [Luminaria]", | ["2,61"] = "Taşrakah (Reverence of the Stone) [Luminaria]", | ||
["3,6"] = "Chag Tvuah (Festival of Harvest) [Sylvapolis]", | ["3,6"] = "Chag Tvuah (Festival of Harvest) [Sylvapolis]", | ||
["3,18"] = "Anagenesis Eirmos (Procession of Rebirth) [Acheron]", | ["3,18"] = "Anagenesis Eirmos (Procession of Rebirth) [Acheron]", | ||
["3,28"] = "Panagia Therizis (Holy Day of the Reaper) [Sylvapolis]", | ["3,28"] = "Panagia Therizis (Holy Day of the Reaper) [Sylvapolis]", | ||
["3,37"] = "Anniversary of victory in the Morovian Frontier Campaign [Acheron]", | ["3,37"] = "Anniversary of victory in the Morovian Frontier Campaign [Acheron]", | ||
["3,43"] = "Karnavali Thysias (Carnival of Celebration) [Erythros]", | ["3,43"] = "Karnavali Thysias (Carnival of Celebration) [Erythros]", | ||
["3,53"] = "Sefar Yashar (Straight Path Celebration) [Catonis Atrium]" | ["3,53"] = "Sefar Yashar (Straight Path Celebration) [Catonis Atrium]" | ||
} | } | ||
--------------------------------------------------------- | |||
-- simulatePriceChange | |||
-- Applies a daily random factor; special date events | |||
-- add a small positive boost to the final price. | |||
--------------------------------------------------------- | |||
local function simulatePriceChange(basePrice, dayOfMonth, month) | local function simulatePriceChange(basePrice, dayOfMonth, month) | ||
local dateKey = string.format("%d,%d", month, dayOfMonth) | local dateKey = string.format("%d,%d", month, dayOfMonth) | ||
local changeFactor = math.random(-20, 20) / 100 | local changeFactor = math.random(-20, 20) / 100 | ||
local explanation | local explanation | ||
if events[dateKey] then | if events[dateKey] then | ||
explanation = events[dateKey] .. ": Prices influenced by event dynamics." | explanation = events[dateKey] .. ": Prices influenced by event dynamics." | ||
changeFactor = changeFactor + 0.05 -- | changeFactor = changeFactor + 0.05 -- small event-based boost | ||
else | else | ||
explanation = "General market fluctuations." | explanation = "General market fluctuations." | ||
Line 109: | Line 131: | ||
end | end | ||
--------------------------------------------------------- | |||
-- determinePriceLevel | |||
-- If adjustedPrice < basePrice => "High", else "Low" | |||
--------------------------------------------------------- | |||
local function determinePriceLevel(basePrice, adjustedPrice) | local function determinePriceLevel(basePrice, adjustedPrice) | ||
if adjustedPrice < basePrice then | if adjustedPrice < basePrice then | ||
Line 117: | Line 143: | ||
end | end | ||
--------------------------------------------------------- | |||
-- Main function: generateTable | |||
-- Seeds random daily, then builds table | |||
--------------------------------------------------------- | |||
function p.generateTable() | function p.generateTable() | ||
local date | -- (A) Create a daily seed based on current local date | ||
local | local localTime = os.date("*t") | ||
local dailySeed = localTime.year * 1000 + localTime.yday | |||
math.randomseed(dailySeed) | |||
-- (B) Retrieve date for display and logic | |||
local dateString, dayOfMonth, month = getCurrentDate() | |||
-- (C) Table header | |||
local wikitable = | |||
"{| class=\"wikitable\"\n" .. | |||
"! Date (Day/Month/Year [[PSSC]]) !! Product !! Producing Company !! Base Price !! Price Level !! Tier III Price !! Tier II Price !! Tier I Price !! Units !! Explanation\n" | |||
-- (D) Iterate over all products, randomize daily | |||
for _, product in ipairs(products) do | for _, product in ipairs(products) do | ||
local name | local name = product[1] | ||
local company = product[2] | |||
local basePrice= product[3] | |||
local units = product[4] | |||
local newPrice, changeFactor, explanation = simulatePriceChange(basePrice, dayOfMonth, month) | local newPrice, changeFactor, explanation = simulatePriceChange(basePrice, dayOfMonth, month) | ||
local priceLevel = determinePriceLevel(basePrice, newPrice) | local priceLevel = determinePriceLevel(basePrice, newPrice) | ||
-- | -- Tiers | ||
local tierIIIPrice = math.floor((newPrice / 3) * 100) / 100 | local tierIIIPrice = math.floor((newPrice / 3) * 100) / 100 | ||
local tierIIPrice = math.floor((newPrice * 2 / 3) * 100) / 100 | local tierIIPrice = math.floor((newPrice * 2 / 3) * 100) / 100 | ||
local tierIPrice = newPrice | local tierIPrice = newPrice -- final adjusted | ||
wikitable = wikitable .. string.format("|-\n| %s || %s || %s || %.2f || %s || %.2f || %.2f || %.2f || %s || %s\n", | wikitable = wikitable .. string.format( | ||
"|-\n| %s || %s || %s || %.2f || %s || %.2f || %.2f || %.2f || %s || %s\n", | |||
dateString, name, company, basePrice, priceLevel, | |||
tierIIIPrice, tierIIPrice, tierIPrice, units, explanation | |||
) | |||
end | end | ||
Revision as of 21:38, 26 December 2024
Documentation for this module may be created at Module:AutoUpdateServPrices/doc
--------------------------------------------------------- -- Module:DailyPriceTable -- Generates a daily-updated table where each cell -- refreshes once per day, with random fluctuations -- stable for that day but new on subsequent days. --------------------------------------------------------- local p = {} --------------------------------------------------------- -- getCurrentDate -- Returns today's date in PSSC format, -- along with dayOfMonth and month for daily logic. --------------------------------------------------------- local function getCurrentDate() local startDate = os.time({year = 1999, month = 8, day = 6}) local secondsInDay = 86400 local daysPerYear = 183 local currentDate = os.time() local totalDaysElapsed = math.floor((currentDate - startDate) / secondsInDay) local yearFraction = totalDaysElapsed / daysPerYear local psscYear = math.floor(yearFraction) local dayOfYear = math.floor((yearFraction - psscYear) * daysPerYear) + 1 local month, dayOfMonth if dayOfYear <= 61 then month = 1 dayOfMonth = dayOfYear elseif dayOfYear <= 122 then month = 2 dayOfMonth = dayOfYear - 61 else month = 3 dayOfMonth = dayOfYear - 122 end return string.format("%d/%d/%d [[PSSC]]", dayOfMonth, month, psscYear), dayOfMonth, month end --------------------------------------------------------- -- Product data remains the same --------------------------------------------------------- local products = { {"Currency", "Lake Morovia Blockade Fund", 4.05, "stacks"}, {"Plunder", "Lake Morovia Blockade Fund", 3.30, "chests"}, {"Prostitutes", "Court of the Dark Harpy", 0.15, "contracts"}, {"Lievs", "Hatch Ministry", 0.32, "units"}, {"Prisoners", "Hatch Ministry", 0.04, "cells"}, {"Faces", "Maritime Guild of the Cult of Maskmakers", 0.03, "masks"}, {"Spies", "Ergonian Spy Agency", 0.01, "assignments"}, {"Missionaries of the Order Aurora Mystica", "Temple Bank of the Reformed Stripping Path", 0.05, "teams"}, {"Missionaries of Harmony Sanctum", "Temple Bank of the Reformed Stripping Path", 0.09, "teams"}, {"Missionaries of Ignis Aeternum", "Temple Bank of the Reformed Stripping Path", 0.09, "teams"}, {"Missionaries of Celestial Harmony Sect", "Temple Bank of the Reformed Stripping Path", 0.08, "teams"}, {"Missionaries of the Guild of Golden Shadows", "Temple Bank of the Reformed Stripping Path", 0.05, "teams"}, {"Missionaries of the Azure Sentinel Sect", "Temple Bank of the Reformed Stripping Path", 0.01, "teams"}, {"Missionaries of Reverie Nebulous", "Temple Bank of the Reformed Stripping Path", 0.10, "teams"}, {"Missionaries of the Eon Fellowship", "Temple Bank of the Reformed Stripping Path", 0.09, "teams"}, {"Missionaries of the Order of the Umbral Oracle", "Temple Bank of the Reformed Stripping Path", 0.07, "teams"}, {"Missionaries of the Mystery of the Verdant Embrace", "Temple Bank of the Reformed Stripping Path", 0.10, "teams"}, {"Missionaries of Conclace Illuminara", "Temple Bank of the Reformed Stripping Path", 0.02, "teams"}, {"Missionaries of Sanctum Vitalis", "Temple Bank of the Reformed Stripping Path", 0.06, "teams"}, {"Missionaries of Temple Alabaster", "Temple Bank of the Reformed Stripping Path", 0.09, "teams"}, {"Missionaries of the Court of the Ironclad", "Temple Bank of the Reformed Stripping Path", 0.06, "teams"}, {"Missionaries of Concord Accordia", "Temple Bank of the Reformed Stripping Path", 0.02, "teams"}, {"Missionaries of the Mystery of the Stygian Veil", "Temple Bank of the Reformed Stripping Path", 0.03, "teams"}, {"Missionaries of the Sylvan Fellowship", "Temple Bank of the Reformed Stripping Path", 0.09, "teams"}, {"Missionaries of the Mystery of Red Mirth", "Temple Bank of the Reformed Stripping Path", 0.06, "teams"}, {"Missionaries of Rex Catonis", "Temple Bank of the Reformed Stripping Path", 0.07, "teams"}, {"Missionaries of Sanctum Delphica", "Temple Bank of the Reformed Stripping Path", 0.09, "teams"}, {"Missionaries of Ordo Amictia", "Temple Bank of the Reformed Stripping Path", 0.06, "teams"}, {"Missionaries of Temple Illuminata", "Temple Bank of the Reformed Stripping Path", 0.05, "teams"}, {"Couriers", "Couriers of the Lizard Queen", 0.04, "dispatches"}, {"Wisp Ward Talismans", "Couriers of the Lizard Queen", 0.10, "amulets"}, {"Credit Hours", "Temple University of Delphica", 3.00, "credits"}, {"Circuses", "La Sái Ebile", 0.24, "venues"}, {"Performances", "La Sái Ebile", 0.11, "acts"}, {"Hellhound (scout)", "Hellhound Breeders of Dragevik", 0.03, "hounds"}, {"Hellhound (soldier)", "Hellhound Breeders of Dragevik", 0.05, "hounds"}, {"Hellhound (spy)", "Hellhound Breeders of Dragevik", 0.15, "hounds"}, } --------------------------------------------------------- -- Special Date Events --------------------------------------------------------- local events = { ["1,6"] = "Bayram al-Nur (Festival of Light) [Vaeringheim]", ["1,18"] = "Chag Or Hadash (Festival of New Light) [Luminaria]", ["1,30"] = "Symposion Eirinis (Symposium of Harmony) [Serena]", ["1,43"] = "Alev Günü (Day of Flame) [Pyralis]", ["1,48"] = "Day of Abandonment [Vaeringheim]", ["1,55"] = "Tikkun Tzel (Repair of Shadows) [Symphonara]", ["2,6"] = "Panegyris Chrysou (Golden Gathering) [Aurelia]", ["2,17"] = "Constitution Day [Luminaria]", ["2,19"] = "Mehtap Dalgası (Moonlit Tide) [Vaeringheim]", ["2,31"] = "Oneiro Foteino (Dream of Illumination) [Somniumpolis]", ["2,39"] = "Anniversary of victory in the New South Jangsong Campaign [Nexa]", ["2,44"] = "Erev Galgal (Eve of Cycles) [Nexa]", ["2,45"] = "Bassaridia Festival [Somniumpolis]", ["2,48"] = "Anniversary of victory in the Southern Lake Morovia Campaign [Somniumpolis]", ["2,54"] = "Leilat al-Kamar (Night of the Moon) [Lunalis Sancta]", ["2,61"] = "Taşrakah (Reverence of the Stone) [Luminaria]", ["3,6"] = "Chag Tvuah (Festival of Harvest) [Sylvapolis]", ["3,18"] = "Anagenesis Eirmos (Procession of Rebirth) [Acheron]", ["3,28"] = "Panagia Therizis (Holy Day of the Reaper) [Sylvapolis]", ["3,37"] = "Anniversary of victory in the Morovian Frontier Campaign [Acheron]", ["3,43"] = "Karnavali Thysias (Carnival of Celebration) [Erythros]", ["3,53"] = "Sefar Yashar (Straight Path Celebration) [Catonis Atrium]" } --------------------------------------------------------- -- simulatePriceChange -- Applies a daily random factor; special date events -- add a small positive boost to the final price. --------------------------------------------------------- local function simulatePriceChange(basePrice, dayOfMonth, month) local dateKey = string.format("%d,%d", month, dayOfMonth) local changeFactor = math.random(-20, 20) / 100 local explanation if events[dateKey] then explanation = events[dateKey] .. ": Prices influenced by event dynamics." changeFactor = changeFactor + 0.05 -- small event-based boost else explanation = "General market fluctuations." end local newPrice = math.floor((basePrice * (1 + changeFactor)) * 100) / 100 return newPrice, changeFactor, explanation end --------------------------------------------------------- -- determinePriceLevel -- If adjustedPrice < basePrice => "High", else "Low" --------------------------------------------------------- local function determinePriceLevel(basePrice, adjustedPrice) if adjustedPrice < basePrice then return "High" else return "Low" end end --------------------------------------------------------- -- Main function: generateTable -- Seeds random daily, then builds table --------------------------------------------------------- function p.generateTable() -- (A) Create a daily seed based on current local date local localTime = os.date("*t") local dailySeed = localTime.year * 1000 + localTime.yday math.randomseed(dailySeed) -- (B) Retrieve date for display and logic local dateString, dayOfMonth, month = getCurrentDate() -- (C) Table header local wikitable = "{| class=\"wikitable\"\n" .. "! Date (Day/Month/Year [[PSSC]]) !! Product !! Producing Company !! Base Price !! Price Level !! Tier III Price !! Tier II Price !! Tier I Price !! Units !! Explanation\n" -- (D) Iterate over all products, randomize daily for _, product in ipairs(products) do local name = product[1] local company = product[2] local basePrice= product[3] local units = product[4] local newPrice, changeFactor, explanation = simulatePriceChange(basePrice, dayOfMonth, month) local priceLevel = determinePriceLevel(basePrice, newPrice) -- Tiers local tierIIIPrice = math.floor((newPrice / 3) * 100) / 100 local tierIIPrice = math.floor((newPrice * 2 / 3) * 100) / 100 local tierIPrice = newPrice -- final adjusted wikitable = wikitable .. string.format( "|-\n| %s || %s || %s || %.2f || %s || %.2f || %.2f || %.2f || %s || %s\n", dateString, name, company, basePrice, priceLevel, tierIIIPrice, tierIIPrice, tierIPrice, units, explanation ) end wikitable = wikitable .. "|}" return wikitable end return p