Changed objectives and their values

master
Austin Shenk 2013-01-25 23:50:35 -05:00
parent fafd5a363f
commit 5313957f39
1 changed files with 18 additions and 9 deletions

View File

@ -1,11 +1,11 @@
local function subdivideObjective(str, desc)
local subdata = str:split(" ")
if subdata[1] == "Return" then
return {type=subdata[1], description=desc, count=subdata[2],content=subdata[3]}
return {command=subdata[1], description=desc, total=subdata[2],content=subdata[3], completed=false, count=0}
elseif subdata[1] == "Collect" then
return {type=subdata[1], description=desc, count=subdata[2],content=subdata[3]}
return {command=subdata[1], description=desc, total=subdata[2],content=subdata[3], completed=false, count=0}
elseif subdata[1] == "Kill" then
return {type=subdata[1], description=desc, count=subdata[2],content=subdata[3]}
return {command=subdata[1], description=desc, total=subdata[2],content=subdata[3], completed=false, count=0}
end
end
local function convertObjectiveString(str, desc)
@ -26,19 +26,18 @@ end
function adventures.storeQuestData(data)
local pos = {x=data[2],y=data[3],z=data[4]}
local meta = minetest.env:get_meta(pos)
local objs = convertObjectiveString(meta:get_string("objective"), meta:get_string("description"))
local objs = convertObjectiveString(meta:get_string("name"), meta:get_string("objective"), meta:get_string("description"))
local y = 3+table.getn(objs)
local str = "label[0,0;"..meta:get_string("name").."]"..
"list[context;reward;4,"..(y-3)..";2,2;]"..
"list[context;items;0,"..(y-3)..";2,2;]"..
"button[1.5,"..(y-1)..";1.5,0.75;accept;Accept]"..
"button_exit[3,"..(y-1)..";1.5,0.75;decline;Decline]"
"button[2.25,"..(y-1)..";1.5,0.75;accept;Accept]"
for i,obj in pairs(objs) do
str = str.."label[0.125,"..(i/2)..";"..obj.description.."]"
end
str = "size[6,"..y.."]"..str
meta:set_string("formspec", str)
adventures.quests[meta:get_string("name")] = {objectives = objs, id = meta:get_int("id")}
adventures.quests[meta:get_string("name")] = {source=pos, objectives = objs, completed=false, active=false}
end
minetest.register_node("adventures:quest", {
@ -49,8 +48,18 @@ minetest.register_node("adventures:quest", {
on_receive_fields = function(pos, formname, fields, sender)
if fields.accept then
local meta = minetest.env:get_meta(pos)
local quests = adventures.playerQuests[sender]
quests[meta:get_string("name")] = adventures.quests[meta:get_string("name")]
adventures.currentQuests[meta:get_string("name")] = adventures.quests[meta:get_string("name")]
local objs = adventures.currentQuests[meta:get_string("name")].objectives
for _,obj in pairs(objs) do
if obj.command == "Return" then
table.insert(adventures.currentObjectives["Return"], {quest=name, index=i})
elseif obj.command == "Collect" then
print("Storing Collect Objective")
table.insert(adventures.currentObjectives["Collect"], {quest=name, index=i})
elseif obj.command == "Kill" then
table.insert(adventures.currentObjectives["Kill"], {quest=name, index=i})
end
end
end
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)