Module:AutoUpdateAgPrices: Difference between revisions
From MicrasWiki
Jump to navigationJump to search
NewZimiaGov (talk | contribs) No edit summary |
NewZimiaGov (talk | contribs) No edit summary |
||
| Line 123: | Line 123: | ||
local newPrice = math.floor((basePrice * (1 + changeFactor)) * 100) / 100 | local newPrice = math.floor((basePrice * (1 + changeFactor)) * 100) / 100 | ||
return newPrice, changeFactor, explanation | return newPrice, changeFactor, explanation | ||
end | |||
local function determinePriceLevel(basePrice, adjustedPrice) | |||
if adjustedPrice < basePrice then | |||
return "High" | |||
else | |||
return "Low" | |||
end | |||
end | end | ||
function p.generateTable() | function p.generateTable() | ||
local date, dayOfMonth, month = getCurrentDate() | local date, dayOfMonth, month = getCurrentDate() | ||
local wikitable = "{| class=\"wikitable\"\n! Date (Day/Month/Year [[PSSC]]) !! Product !! Producing Company !! Base Price !! Tier III Price !! Tier II Price !! Tier I Price !! Units !! Explanation\n" | 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" | ||
for _, product in ipairs(products) do | for _, product in ipairs(products) do | ||
local name, company, basePrice, unit = product[1], product[2], product[3], product[4] | local name, company, basePrice, unit = product[1], product[2], product[3], product[4] | ||
local newPrice, changeFactor, explanation = simulatePriceChange(basePrice, dayOfMonth, month) | local newPrice, changeFactor, explanation = simulatePriceChange(basePrice, dayOfMonth, month) | ||
local priceLevel = determinePriceLevel(basePrice, newPrice) | |||
-- Calculate Tier prices | -- Calculate Tier prices | ||
local tierIIIPrice = math.floor((newPrice / 3) * 100) / 100 | local tierIIIPrice = math.floor((newPrice / 3) * 100) / 100 | ||
| Line 138: | Line 147: | ||
local tierIPrice = newPrice | local tierIPrice = newPrice | ||
wikitable = wikitable .. string.format("|-\n| %s || %s || %s || %.2f || %.2f || %.2f || %.2f || %s || %s\n", | wikitable = wikitable .. string.format("|-\n| %s || %s || %s || %.2f || %s || %.2f || %.2f || %.2f || %s || %s\n", | ||
date, name, company, basePrice, tierIIIPrice, tierIIPrice, tierIPrice, unit, explanation) | date, name, company, basePrice, priceLevel, tierIIIPrice, tierIIPrice, tierIPrice, unit, explanation) | ||
end | end | ||
Revision as of 07:00, 25 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 [[PSSC]]", dayOfMonth, month, psscYear), dayOfMonth, month
end
local products = {
{"Rice", "Gladeseed Farmers' Union", 9.00, "tons"},
{"Edible Algae", "Gladeseed Farmers' Union", 21.00, "tons"},
{"Shrimp", "Gladeseed Farmers' Union", 15.00, "tons"},
{"Anterran Spicy Onion", "Gladeseed Farmers' Union", 18.00, "tons"},
{"Queen's Garlic", "Gladeseed Farmers' Union", 27.00, "tons"},
{"Morovian Water Buffalo", "Atterian Cattle Drivers", 6.60, "herds"},
{"Unprocessed Noctic-Rabrev Flower", "Noctic Fleet", 6.00, "bales"},
{"Processed Noctic Rabrev Flower", "Noctic Fleet", 2.50, "crates"},
{"Noctic-Rabrev Flower Concentrate", "Noctic Fleet", 3.00, "barrels"},
{"Unprocessed Noctic-Rabrev Leaf", "Noctic Fleet", 15.00, "bales"},
{"Processed Noctic-Rabrev Leaf", "Noctic Fleet", 5.79, "crates"},
{"Unprocessed Noctic-Rabrev Leaf Concentrate", "Noctic Fleet", 6.00, "barrels"},
{"Processed Noctic-Rabrev Leaf Concentrate", "Noctic Fleet", 3.00, "barrels"},
{"Manwine", "Jogiani Merchants of Manwine", 2.07, "barrels"},
{"Milkwine", "Jogiani Merchants of Manwine", 6.00, "barrels"},
{"Zoe Elm Resin (Unrefined)", "Keepers of the Grove of Zoe Elm", 0.03, "barrels"},
{"Zoe Elm Resin (Refined)", "Keepers of the Grove of Zoe Elm", 0.04, "barrels"},
{"Sea Elm Flavored Mead", "Sea-Elm Southern Meadery", 1.11, "barrels"},
{"Wheat", "Plains of Jogi", 0.30, "tons"},
{"Oats", "Plains of Jogi", 0.23, "tons"},
{"Cereal", "Plains of Jogi", 0.52, "pallets"},
{"Hay", "Plains of Jogi", 0.45, "bales"},
{"Ale of the Night", "Ale of the Night Central Brewery", 2.43, "barrels"},
{"Camels", "Camel Herders of the Jangsong Province", 1.04, "herds"},
{"Camel Meat", "Camel Herders of the Jangsong Province", 34.65, "tons"},
{"Camel Milk", "Camel Herders of the Jangsong Province", 5.20, "barrels"},
{"Camel Hump Water", "Camel Herders of the Jangsong Province", 3.47, "barrels"},
{"Camel Hump Water Tea", "Camel Herders of the Jangsong Province", 0.86, "barrels"},
{"Pearls", "Anterran Imports and Services", 0.79, "sacks"},
{"Abalone", "Anterran Imports and Services", 2.64, "crates"},
{"Opium", "Merchant Guild of the Poppy Goddess", 0.18, "sacks"},
{"Hash", "Merchant Guild of the Poppy Goddess", 0.17, "sacks"},
{"Mead", "Grand Cave Bee Meadery", 0.49, "barrels"},
{"Cinammon", "Cinammon Plains of Roue", 0.45, "tons"},
{"Velvet Worm Meat", "The Velvet Company", 1.04, "tons"},
{"Velvet Worm Eggs", "The Velvet Company", 0.35, "crates"},
{"Silk", "Seamstresses of Rouge", 5.00, "rolls"},
{"Horehound Mead", "Salurian Temple of Sacred Horehound", 0.05, "barrels"},
{"Horehound Beer", "Salurian Temple of Sacred Horehound", 0.07, "barrels"},
{"Sea Cow Beef", "Bulhanu Ranchers' Association", 8.50, "tons"},
{"Atterian Armored Pufferfish", "Suncliff Fisheries", 3.00, "tons"},
{"Morovian Saucer Eyed Giant Eel", "Suncliff Fisheries", 7.50, "tons"},
{"Amina Crab", "Suncliff Fisheries", 6.00, "tons"},
{"Mugwort Oil", "Ministers of Mistress Mugwort", 0.35, "barrels"},
{"Ground Mugwort", "Ministers of Mistress Mugwort", 0.75, "sacks"},
{"Mugwort Tincture", "Ministers of Mistress Mugwort", 0.10, "barrels"},
{"Blood InfusedRed Wine", "Blood Vineyards of the Far North", 0.39, "barrels"},
{"Wisp Rice", "Norsolyrian Wisp Rice Farmers Association", 15.00, "tons"},
{"Giid-Lisea-Eda", "Giid Lisea Ranching Import Company", 0.41, "shipments"},
{"Vaeringheim Turkey Meat", "Bird Keepers of Saluria", 1.07, "tons"},
{"Salurian Swamp Quail Eggs", "Bird Keepers of Saluria", 12.00, "crates"},
{"Giant Fanged Penguin Blubber", "Hunters of the Giant Fanged Penguin", 25.00, "tons"},
{"Giant Fanged Penguin Blubber Oil Extract", "Hunters of the Giant Fanged Penguin", 5.00, "barrels"},
}
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
local function determinePriceLevel(basePrice, adjustedPrice)
if adjustedPrice < basePrice then
return "High"
else
return "Low"
end
end
function p.generateTable()
local date, dayOfMonth, month = getCurrentDate()
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"
for _, product in ipairs(products) do
local name, company, basePrice, unit = product[1], product[2], product[3], product[4]
local newPrice, changeFactor, explanation = simulatePriceChange(basePrice, dayOfMonth, month)
local priceLevel = determinePriceLevel(basePrice, newPrice)
-- 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 || %s || %.2f || %.2f || %.2f || %s || %s\n",
date, name, company, basePrice, priceLevel, tierIIIPrice, tierIIPrice, tierIPrice, unit, explanation)
end
wikitable = wikitable .. "|}"
return wikitable
end
return p