Module:AutoUpdateAgPrices: Difference between revisions
From MicrasWiki
Jump to navigationJump to search
NewZimiaGov (talk | contribs) Created page with "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 lo..." |
NewZimiaGov (talk | contribs) No edit summary |
||
| Line 13: | Line 13: | ||
local dayOfYear = math.floor((yearFraction - psscYear) * daysPerYear) + 1 | local dayOfYear = math.floor((yearFraction - psscYear) * daysPerYear) + 1 | ||
local month | local month, dayOfMonth | ||
if dayOfYear <= 61 then | if dayOfYear <= 61 then | ||
month = | month = 1 | ||
dayOfMonth = dayOfYear | |||
elseif dayOfYear <= 122 then | elseif dayOfYear <= 122 then | ||
month = | month = 2 | ||
dayOfMonth = dayOfYear - 61 | |||
else | else | ||
month = | month = 3 | ||
dayOfMonth = dayOfYear - 122 | |||
end | end | ||
return string.format("%d | return string.format("%d/%d/%d", dayOfMonth, month, psscYear), dayOfMonth, month | ||
end | end | ||
| Line 82: | Line 85: | ||
local 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]", | ||
} | } | ||
local function simulatePriceChange(basePrice, | local function simulatePriceChange(basePrice, dayOfMonth, month) | ||
local dateKey = string.format("% | 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 = "" | ||
| Line 123: | Line 126: | ||
function p.generateTable() | function p.generateTable() | ||
local date, | local date, dayOfMonth, month = getCurrentDate() | ||
local wikitable = "{| class=\"wikitable\"\n! Date !! Product !! Producing Company !! Base Price !! Tier III Price !! Tier II Price !! Tier I Price !! Explanation\n" | local wikitable = "{| class=\"wikitable\"\n! Date (Day/Month/Year) !! Product !! Producing Company !! Base Price !! Tier III Price !! Tier II Price !! Tier I Price !! Explanation\n" | ||
for _, product in ipairs(products) do | for _, product in ipairs(products) do | ||
local name, company, basePrice = product[1], product[2], product[3] | local name, company, basePrice = product[1], product[2], product[3] | ||
local newPrice, changeFactor, explanation = simulatePriceChange(basePrice, | local newPrice, changeFactor, explanation = simulatePriceChange(basePrice, dayOfMonth, month) | ||
-- Calculate Tier prices | -- Calculate Tier prices | ||
Revision as of 17:21, 24 December 2024
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, 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", dayOfMonth, month, psscYear), dayOfMonth, 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 = {
["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]",
}
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 -- 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, dayOfMonth, month = getCurrentDate()
local wikitable = "{| class=\"wikitable\"\n! Date (Day/Month/Year) !! 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, dayOfMonth, 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