Module:AutoUpdateAgPrices
From MicrasWiki
Documentation for this module may be created at Module:AutoUpdateAgPrices/doc
local p = {}
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
if dayOfYear <= 61 then
month = "Atosiel"
elseif dayOfYear <= 122 then
month = "Thalassiel"
else
month = "Opsitheiel"
end
return string.format("%d, %s, %d PSSC", dayOfYear, month, psscYear), dayOfYear, month
end
local products = {
{"Rice", "Gladeseed Farmers' Union", 9.00},
{"Edible Algae", "Gladeseed Farmers' Union", 21.00},
{"Shrimp", "Gladeseed Farmers' Union", 15.00},
{"Anterran Spicy Onion", "Gladeseed Farmers' Union", 18.00},
{"Queen's Garlic", "Gladeseed Farmers' Union", 27.00},
{"Morovian Water Buffalo", "Atterian Cattle Drivers", 6.60},
{"Unprocessed Noctic-Rabrev Flower", "Noctic Fleet", 6.00},
{"Processed Noctic Rabrev Flower", "Noctic Fleet", 2.50},
{"Noctic-Rabrev Flower Concentrate", "Noctic Fleet", 3.00},
{"Unprocessed Noctic-Rabrev Leaf", "Noctic Fleet", 15.00},
{"Processed Noctic-Rabrev Leaf", "Noctic Fleet", 5.79},
{"Unprocessed Noctic-Rabrev Leaf Concentrate", "Noctic Fleet", 6.00},
{"Processed Noctic-Rabrev Leaf Concentrate", "Noctic Fleet", 3.00},
{"Manwine", "Jogiani Merchants of Manwine", 2.07},
{"Milkwine", "Jogiani Merchants of Manwine", 6.00},
{"Zoe Elm Resin (Unrefined)", "Keepers of the Grove of Zoe Elm", 0.03},
{"Zoe Elm Resin (Refined)", "Keepers of the Grove of Zoe Elm", 0.04},
{"Sea Elm Flavored Mead", "Sea-Elm Southern Meadery", 1.11},
{"Wheat", "Plains of Jogi", 0.30},
{"Oats", "Plains of Jogi", 0.23},
{"Cereal", "Plains of Jogi", 0.52},
{"Hay", "Plains of Jogi", 0.45},
{"Ale of the Night", "Ale of the Night Central Brewery", 2.43},
{"Camels", "Camel Herders of the Jangsong Province", 1.04},
{"Camel Meat", "Camel Herders of the Jangsong Province", 34.65},
{"Camel Milk", "Camel Herders of the Jangsong Province", 5.20},
{"Camel Hump Water", "Camel Herders of the Jangsong Province", 3.47},
{"Camel Hump Water Tea", "Camel Herders of the Jangsong Province", 0.86},
{"Pearls", "Anterran Imports and Services", 0.79},
{"Abalone", "Anterran Imports and Services", 2.64},
{"Opium", "Merchant Guild of the Poppy Goddess", 0.18},
{"Hash", "Merchant Guild of the Poppy Goddess", 0.17},
{"Mead", "Grand Cave Bee Meadery", 0.49},
{"Cinammon", "Cinammon Plains of Roue", 0.45},
{"Velvet Worm Meat", "The Velvet Company", 1.04},
{"Velvet Worm Eggs", "The Velvet Company", 0.35},
{"Silk", "Seamstresses of Rouge", 5.00},
{"Horehound Mead", "Salurian Temple of Sacred Horehound", 0.05},
{"Horehound Beer", "Salurian Temple of Sacred Horehound", 0.07},
{"Sea Cow Beef", "Bulhanu Ranchers' Association", 8.50},
{"Atterian Armored Pufferfish", "Suncliff Fisheries", 3.00},
{"Morovian Saucer Eyed Giant Eel", "Suncliff Fisheries", 7.50},
{"Amina Crab", "Suncliff Fisheries", 6.00},
{"Mugwort Oil", "Ministers of Mistress Mugwort", 0.35},
{"Ground Mugwort", "Ministers of Mistress Mugwort", 0.75},
{"Mugwort Tincture", "Ministers of Mistress Mugwort", 0.10},
{"Blood InfusedRed Wine", "Blood Vineyards of the Far North", 0.39},
{"Wisp Rice", "Norsolyrian Wisp Rice Farmers Association", 15.00},
{"Giid-Lisea-Eda", "Giid Lisea Ranching Import Company", 0.41},
{"Vaeringheim Turkey Meat", "Bird Keepers of Saluria", 1.07},
{"Salurian Swamp Quail Eggs", "Bird Keepers of Saluria", 12.00},
{"Giant Fanged Penguin Blubber", "Hunters of the Giant Fanged Penguin", 25.00},
{"Giant Fanged Penguin Blubber Oil Extract", "Hunters of the Giant Fanged Penguin", 5.00},
}
local events = {
["Atosiel,6"] = "Bayram al-Nur (Festival of Light) [Vaeringheim]",
["Atosiel,18"] = "Chag Or Hadash (Festival of New Light) [Luminaria]",
["Atosiel,30"] = "Symposion Eirinis (Symposium of Harmony) [Serena]",
["Atosiel,43"] = "Alev Günü (Day of Flame) [Pyralis]",
["Atosiel,48"] = "Day of Abandonment [Vaeringheim]",
["Atosiel,55"] = "Tikkun Tzel (Repair of Shadows) [Symphonara]",
["Thalassiel,6"] = "Panegyris Chrysou (Golden Gathering) [Aurelia]",
["Thalassiel,17"] = "Constitution Day [Luminaria]",
["Thalassiel,19"] = "Mehtap Dalgası (Moonlit Tide) [Vaeringheim]",
["Thalassiel,31"] = "Oneiro Foteino (Dream of Illumination) [Somniumpolis]",
["Thalassiel,39"] = "Anniversary of victory in the New South Jangsong Campaign [Nexa]",
["Thalassiel,44"] = "Erev Galgal (Eve of Cycles) [Nexa]",
["Thalassiel,45"] = "Bassaridia Festival [Somniumpolis]",
["Thalassiel,48"] = "Anniversary of victory in the Southern Lake Morovia Campaign [Somniumpolis]",
["Thalassiel,54"] = "Leilat al-Kamar (Night of the Moon) [Lunalis Sancta]",
["Thalassiel,61"] = "Taşrakah (Reverence of the Stone) [Luminaria]",
["Opsitheiel,6"] = "Chag Tvuah (Festival of Harvest) [Sylvapolis]",
["Opsitheiel,18"] = "Anagenesis Eirmos (Procession of Rebirth) [Acheron]",
["Opsitheiel,28"] = "Panagia Therizis (Holy Day of the Reaper) [Sylvapolis]",
["Opsitheiel,37"] = "Anniversary of victory in the Morovian Frontier Campaign [Acheron]",
["Opsitheiel,43"] = "Karnavali Thysias (Carnival of Celebration) [Erythros]",
["Opsitheiel,53"] = "Sefar Yashar (Straight Path Celebration) [Catonis Atrium]",
}
local function simulatePriceChange(basePrice, dayOfYear, month)
local dateKey = string.format("%s,%d", month, dayOfYear)
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 -- Boost price change for significant events
else
explanation = "General market fluctuations."
end
local newPrice = math.floor((basePrice * (1 + changeFactor)) * 100) / 100
return newPrice, changeFactor, explanation
end
function p.generateTable()
local date, dayOfYear, month = getCurrentDate()
local wikitable = "{| class=\"wikitable\"\n! Date !! Product !! Producing Company !! Base Price !! Tier III Price !! Tier II Price !! Tier I Price !! Explanation\n"
for _, product in ipairs(products) do
local name, company, basePrice = product[1], product[2], product[3]
local newPrice, changeFactor, explanation = simulatePriceChange(basePrice, dayOfYear, month)
-- Calculate Tier prices
local tierIIIPrice = math.floor((newPrice / 3) * 100) / 100
local tierIIPrice = math.floor((newPrice * 2 / 3) * 100) / 100
local tierIPrice = newPrice
wikitable = wikitable .. string.format("|-\n| %s || %s || %s || %.2f || %.2f || %.2f || %.2f || %s\n",
date, name, company, basePrice, tierIIIPrice, tierIIPrice, tierIPrice, explanation)
end
wikitable = wikitable .. "|}"
return wikitable
end
return p