维护提醒

BWIKI 全站将于 9 月 3 日(全天)进行维护,期间无法编辑任何页面或发布新的评论。

全站通知:

模块:Crops

来自星露谷物语维基
跳到导航 跳到搜索
[ 创建 | 刷新 ]文档页面
当前模块文档缺失,需要扩充。
local Helper = require("Module:Helper")
local ID = require("Module:ID")
local Object = require("Module:Object")
local CropsData = Helper.LazyLoad("Module:Crops/data")
local ShopsData = Helper.LazyLoad("Module:Shops/data")
local p = {}

local Stores = {
    ['Joja'] = '[[Joja超市]]',
    ['Raccoon'] = '[[大树桩(地点)|浣熊]]',
    ['Sandy'] = '[[绿洲]]',
    ['SeedShop'] = '[[皮埃尔的杂货店]]',
    ['Traveler'] = '[[旅行商人]]'
}
local StoresRaw = {
    ['Joja'] = '超市',
    ['Raccoon'] = '浣熊',
    ['Sandy'] = '绿洲',
    ['SeedShop'] = '杂货店',
    ['Traveler'] = '旅行'
}

function TestItem(frame)
	local id = ID.id {args = { frame.args[1] }}
	if id:sub(1, 3) == "(O)" then
        id = id:sub(4)
        return id
    else
        return nil
	end
end

function TestData(id)
	for key, entry in pairs(CropsData) do
		if entry['HarvestItemId'] == id then
			return entry
		end
	end
	return nil
end

function TestDataKey(id)
	for key, entry in pairs(CropsData) do
		if entry['HarvestItemId'] == id then
			return key
		end
	end
	return nil
end

function TestDataField(id, field)
	for key, entry in pairs(CropsData) do
		if entry['HarvestItemId'] == id then
			return entry[field]
		end
	end
	return nil
end

-- =p.CanRegrow{args={"Carrot"}}
function p.CanRegrow(frame)
	local id = TestItem(frame)
	if id == nil then
        return ''
	end
	local regrow = TestDataField(id, 'RegrowDays')
	if regrow == nil then
		return ''
	end
	if regrow == -1 then
		return '否'
	else
		return '是'
	end
end

-- =p.RegrowDays{args={"Carrot"}}
function p.RegrowDays(frame)
	local id = TestItem(frame)
	if id == nil then
        return ''
	end
	local regrow = TestDataField(id, 'RegrowDays')
	if regrow == nil then
		return ''
	end
	if regrow == -1 then
		return '否'
	else
		if regrow == 1 then
			return '是(每天)'
		end
		return '是(每 ' .. regrow .. ' 天)'
	end
	return regrow
end

-- =p.IsRaised{args={"Carrot"}}
-- 判定是否为棚架作物
function p.IsRaised(frame)
	local id = TestItem(frame)
	if id == nil then
        return ''
	end
	local raised = TestDataField(id, 'IsRaised')
	if raised == nil then
		return ''
	end
	if raised == true then
		return '是'
	else
		return '否'
	end
	return raised
end

-- =p.DaysInPhase{args={"Carrot"}}
function p.DaysInPhase(frame)
	local id = TestItem(frame)
	if id == nil then
        return ''
	end
	local phase = TestDataField(id, 'DaysInPhase')
	if phase == nil then
		return ''
	end
	local str = ''
	local total = 0
	for _, value in ipairs(phase) do
		if str == '' then
			str = value
		else
			str = str .. ' + ' .. value
		end
		total = total + value
	end
	str = str .. ' = ' .. total
	return str
end

local function contains(text, substring)
    return string.find(text, substring, 1, true) ~= nil
end

-- =p.TryPrice{args={"胡萝卜"}}
function p.TryPrice(frame)
	local id = TestItem(frame)
	id = TestDataKey(id)
	local CanPurchase = false
	local SpecialStore = false
	local NormalStore = false
	local Store = ''
	local Price = -1
	for key, entry in pairs(ShopsData) do
		if entry['Currency'] == 0 then
			for _, item in ipairs(entry['Items']) do
				if item['ItemId'] == '(O)' .. id then
					CanPurchase = true
					if key ~= 'Joja' and not contains(key, 'Festival') and not contains(key, 'IslandTrade') then
						Store = key
					end
					if item['TradeItemId'] ~= nil then
						SpecialStore = true
					else
						NormalStore = true
					end
					if item['Price'] ~= -1 then
						Price = item['Price']
					end
				end
			end
		end
	end
	if Store == '' then
		return '特殊'
	end
	
	if CanPurchase == true and NormalStore == true then
		if Price == -1 then
			Price = Object.getPriceById {args = { id }} * 2
		end
		return Helper.ExpandTemplate("模板:Price",{Price}) .. '(' .. Stores[Store] .. ')'
	end
	
	return '特殊(' .. Stores[Store] .. ')'
end

-- =p.TryStore{args={"胡萝卜"}}
function p.TryStore(frame)
	local id = TestItem(frame)
	id = TestDataKey(id)
	local Store = ''
	for key, entry in pairs(ShopsData) do
		if entry['Currency'] == 0 then
			for _, item in ipairs(entry['Items']) do
				if item['ItemId'] == '(O)' .. id then
					if key ~= 'Joja' and not contains(key, 'Festival') and not contains(key, 'IslandTrade') then
						Store = key
					end
				end
			end
		end
	end
	return StoresRaw[Store]
end

return p