维护提醒

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

全站通知:

模块:Fish

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

local p = {}

function ParseEntry(entry) 
	local result = {}
    local parts = {}
    for part in string.gmatch(entry, "[^/]+") do
        table.insert(parts, part)
    end
    result.name = parts[1]
    if (parts[2] == 'trap') then
    	result.type = parts[2]
    	result.chance = parts[3]
    	result.min = parts[5]
    	result.max = parts[6]
    	return result
    end
    result.type = 'normal'
	result.dart = parts[2]
	result.random = parts[3]
	result.min = parts[4]
	result.max = parts[5]
	-- result.time = parts[6]
	local times = {}
	result.times = {}
    for time in string.gmatch(parts[6], "%S+") do
        table.insert(times, tonumber(time))
    end
    for i = 1, #times, 2 do
        local range = {min = times[i], max = times[i+1]}
        table.insert(result.times, range)
    end
	local seasons = {}
	-- result.season = parts[7]
	for part in string.gmatch(parts[7], "%S+") do
        table.insert(seasons, part)
	end
	result.seasons = seasons
	result.weather = parts[8]
	result.maxDepth = parts[10]
	result.multiplierSpawn = parts[11]
	result.multiplierDepth = parts[12]
	result.level = parts[13]
	result.tutorial = parts[14]
	return result
end

function ParseData(data)
    local fishes = {}
    for key, entry in pairs(data) do
        local parsedEntry = ParseEntry(entry)
        fishes[key] = parsedEntry
    end

    return fishes
end

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

-- =p.FieldByName{args={"Catfish","level"}}
function p.FieldByName(frame)
	item = frame.args[1]
	field = frame.args[2]
    local id = TestItem(frame)
    if id == nil then
        return ''
    end
	local processedData = ParseData(Data)
	if processedData[id] == nil then
		return ''
	end
	if processedData[id][field] ~= nil then
		return processedData[id][field]
	else
		return ''
	end
end

function p.debug()
    local processedData = ParseData(Data)
    mw.logObject(processedData)
end

return p