Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jichi authored and jichi committed Dec 3, 2023
1 parent 6b86637 commit 9688e3a
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 127 deletions.
18 changes: 16 additions & 2 deletions working_villagers/jobs/bone_collector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,24 @@ working_villages.register_job("working_villages:job_bonecollector", {
print("failure: no adjacent walkable found")
destination = target
end
self:go_to(destination)
--self:go_to(destination)
--local herb_data = bones.get_bone(minetest.get_node(target).name);
--bones.get_bone(minetest.get_node(target).name);
self:dig(target,true)
--self:dig(target,true)
self:set_displayed_action("collecting some bones")
local success, ret = self:go_to(destination)
if not success then
working_villages.failed_pos_record(target)
self:set_displayed_action("looking at the unreachable bones")
self:delay(100)
else
success, ret = self:dig(target,true)
if not success then
working_villages.failed_pos_record(target)
self:set_displayed_action("confused as to why collecting failed")
self:delay(100)
end
end
end
elseif self:timer_exceeded("bonecollector:change_dir",50) then
-- TODO I don't suppose a search pattern would be applicable
Expand Down
18 changes: 16 additions & 2 deletions working_villagers/jobs/brush_collector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,24 @@ working_villages.register_job("working_villages:job_brushcollector", {
print("failure: no adjacent walkable found")
destination = target
end
self:go_to(destination)
--self:go_to(destination)
--local herb_data = shrubs.get_shrub(minetest.get_node(target).name);
--shrubs.get_shrub(minetest.get_node(target).name);
self:dig(target,true)
--self:dig(target,true)
self:set_displayed_action("collecting some brush")
local success, ret = self:go_to(destination)
if not success then
working_villages.failed_pos_record(target)
self:set_displayed_action("looking at the unreachable brush")
self:delay(100)
else
success, ret = self:dig(target,true)
if not success then
working_villages.failed_pos_record(target)
self:set_displayed_action("confused as to why collecting failed")
self:delay(100)
end
end
end
elseif self:timer_exceeded("brushcollector:change_dir",50) then
self:change_direction_randomly()
Expand Down
18 changes: 16 additions & 2 deletions working_villagers/jobs/bug_collector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,24 @@ working_villages.register_job("working_villages:job_bugcollector", {
print("failure: no adjacent walkable found")
destination = target
end
self:go_to(destination)
--self:go_to(destination)
--local herb_data = bugs.get_bug(minetest.get_node(target).name);
--bugs.get_bug(minetest.get_node(target).name);
self:dig(target,true)
--self:dig(target,true)
self:set_displayed_action("collecting some bugs")
local success, ret = self:go_to(destination)
if not success then
working_villages.failed_pos_record(target)
self:set_displayed_action("looking at the unreachable bugs")
self:delay(100)
else
success, ret = self:dig(target,true)
if not success then
working_villages.failed_pos_record(target)
self:set_displayed_action("confused as to why collecting failed")
self:delay(100)
end
end
end
elseif self:timer_exceeded("bugcollector:change_dir",50) then
self:change_direction_randomly()
Expand Down
4 changes: 3 additions & 1 deletion working_villagers/jobs/farmer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ working_villages.register_job("working_villages:job_farmer", {
print("failure: no adjacent walkable found")
destination = target
end
local plant_name = minetest.get_node(target).name
self:set_displayed_action("farming some "..plant_name)
self:go_to(destination)
local plant_data = farming_plants.get_plant(minetest.get_node(target).name);
local plant_data = farming_plants.get_plant(plant_name);
self:dig(target,true)
if plant_data and plant_data.replant then
for index, value in ipairs(plant_data.replant) do
Expand Down
5 changes: 4 additions & 1 deletion working_villagers/jobs/gardener.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ working_villages.register_job("working_villages:job_gardener", {
destination = target
end
self:go_to(destination)
local plant_data = gardening_nodes.get_dirt(minetest.get_node(target).name);
local plant_name = minetest.get_node(target).name
self:set_displayed_action("tilling some "..plant_name)
local plant_data = gardening_nodes.get_dirt(plant_name)
--self:dig(target,true)
--if plant_data and plant_data.replant then
-- for index, value in ipairs(plant_data.replant) do
Expand All @@ -132,6 +134,7 @@ working_villages.register_job("working_villages:job_gardener", {
local user = self
local pointed_thing = {under=target, type="node",}
local new_stack = on_use(stack, user, pointed_thing)
-- TODO register position failure ?
self:set_wield_item_stack(new_stack)
for _=0,10 do coroutine.yield() end --wait 10 steps
end
Expand Down
20 changes: 17 additions & 3 deletions working_villagers/jobs/plant_collector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,24 @@ working_villages.register_job("working_villages:job_herbcollector", {
print("failure: no adjacent walkable found")
destination = target
end
self:go_to(destination)
--self:go_to(destination)
self:set_displayed_action("collecting some plants")
local success, ret = self:go_to(destination)
--local herb_data = herbs.get_herb(minetest.get_node(target).name);
herbs.get_herb(minetest.get_node(target).name);
self:dig(target,true)
--herbs.get_herb(minetest.get_node(target).name);
--self:dig(target,true)
if not success then
working_villages.failed_pos_record(target)
self:set_displayed_action("looking at the unreachable plant")
self:delay(100)
else
success, ret = self:dig(target,true)
if not success then
working_villages.failed_pos_record(target)
self:set_displayed_action("confused as to why collecting failed")
self:delay(100)
end
end
end
elseif self:timer_exceeded("herbcollector:change_dir",50) then
self:change_direction_randomly()
Expand Down
17 changes: 15 additions & 2 deletions working_villagers/jobs/snowclearer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,21 @@ I'm doing anyway, clearing the snow away.",
destination = target
end
self:set_displayed_action("clearing snow away")
self:go_to(destination)
self:dig(target,true)
--self:go_to(destination)
--self:dig(target,true)
local success, ret = self:go_to(destination)
if not success then
working_villages.failed_pos_record(target)
self:set_displayed_action("looking at the unreachable snow")
self:delay(100)
else
success, ret = self:dig(target,true)
if not success then
working_villages.failed_pos_record(target)
self:set_displayed_action("confused as to why clearing failed")
self:delay(100)
end
end
end
self:set_displayed_action("looking for work")
elseif self:timer_exceeded("snowclearer:change_dir",50) then
Expand Down
85 changes: 46 additions & 39 deletions working_villagers/jobs/watercarrier.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,46 +87,53 @@ working_villages.register_job("working_villages:job_watercarrier", {
print("failure: no adjacent walkable found")
destination = target
end
self:go_to(destination)
local plant_data = liquids.get_liquid(minetest.get_node(target).name);

-- TODO wield the bucket instead
-- first we need an empty bucket
self:set_displayed_action("checking for empty bucket")
local item_name = "bucket:bucket_empty"
local inv = self:get_inventory()
local itemstack = ItemStack(item_name)
itemstack:set_count(1)
--if (not inv:contains_item("wield_item", itemstack)) then
if (not inv:contains_item("main", itemstack)) then
-- need a bucket
self.job_data.manipulated_chest2 = false
return
--self:go_to(destination)
local success, ret = self:go_to(destination)
if not success then
working_villages.failed_pos_record(target)
self:set_displayed_action("looking at the unreachable snow")
self:delay(100)
else
local plant_data = liquids.get_liquid(minetest.get_node(target).name);

-- TODO wield the bucket instead
-- first we need an empty bucket
self:set_displayed_action("checking for empty bucket")
local item_name = "bucket:bucket_empty"
local inv = self:get_inventory()
local itemstack = ItemStack(item_name)
itemstack:set_count(1)
--if (not inv:contains_item("wield_item", itemstack)) then
if (not inv:contains_item("main", itemstack)) then
-- need a bucket
self.job_data.manipulated_chest2 = false
return
end

-- next we need the filled bucket
self:set_displayed_action("checking for room for filled bucket")
local plantstack = ItemStack(plant_data)
plantstack:set_count(1)
if not inv:room_for_item("main", plantstack) then
-- no room for new bucket
self.job_data.manipulated_chest2 = false
return
end

self:set_displayed_action("bucketing some liquid")
-- now we can do the action
--self:dig(target,true) -- bucketing is different than digging
minetest.remove_node(target)

--local taken = inv:remove_item("wield_item", itemstack)
local taken = inv:remove_item("main", itemstack)
assert(taken:get_count() == 1)

local leftover = inv:add_item("main", plantstack)
assert(leftover:get_count() == 0)

for _=0,10 do coroutine.yield() end --wait 10 steps
end

-- next we need the filled bucket
self:set_displayed_action("checking for room for filled bucket")
local plantstack = ItemStack(plant_data)
plantstack:set_count(1)
if not inv:room_for_item("main", plantstack) then
-- no room for new bucket
self.job_data.manipulated_chest2 = false
return
end

self:set_displayed_action("bucketing some liquid")
-- now we can do the action
--self:dig(target,true) -- bucketing is different than digging
minetest.remove_node(target)

--local taken = inv:remove_item("wield_item", itemstack)
local taken = inv:remove_item("main", itemstack)
assert(taken:get_count() == 1)

local leftover = inv:add_item("main", plantstack)
assert(leftover:get_count() == 0)

for _=0,10 do coroutine.yield() end --wait 10 steps
end
elseif self:timer_exceeded("watercarrier:change_dir",50) then
self:change_direction_randomly()
Expand Down
122 changes: 47 additions & 75 deletions working_villagers/jobs/wizard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,81 +104,53 @@ working_villages.register_job("working_villages:job_wizard", {
print("failure: no adjacent walkable found")
destination = target
end
self:go_to(destination)
-- local plant_data = spellbooks.get_book(minetest.get_node(target).name);

-- TODO wield the bucket instead
-- first we need an empty bucket
--self:set_displayed_action("checking for empty bucket")
-- local item_name = "iadiscordia:kallisti"
-- local inv = self:get_inventory()
-- local itemstack = ItemStack(item_name)
-- itemstack:set_count(1)
-- --if (not inv:contains_item("wield_item", itemstack)) then
-- if (not inv:contains_item("main", itemstack)) then
-- -- need a bucket
-- self.job_data.manipulated_chest2 = false
-- return
-- end
--
-- -- next we need the filled bucket
-- self:set_displayed_action("checking for room for filled bucket")
-- local plantstack = ItemStack(plant_data)
-- plantstack:set_count(1)
-- if not inv:room_for_item("main", plantstack) then
-- -- no room for new bucket
-- self.job_data.manipulated_chest2 = false
-- return
-- end
--
-- self:set_displayed_action("spellcasting some book")
-- -- now we can do the action
-- --self:dig(target,true) -- spellcasting is different than digging
-- minetest.remove_node(target)
--
-- --local taken = inv:remove_item("wield_item", itemstack)
-- local taken = inv:remove_item("main", itemstack)
-- assert(taken:get_count() == 1)
--
-- local leftover = inv:add_item("main", plantstack)
-- assert(leftover:get_count() == 0)
--
self:set_displayed_action("checking for spells in book")
-- -- TODO check HP+MP, and eat+sleep if necessary
local name = stack:get_name()
--local def = minetest.registered_items[name]
local def = stack:get_definition() -- minetest.registered_items[item_name]
local on_use = def.on_use
local user = self
--local playername = user.nametag
local playername = self:get_player_name()
assert(playername ~= nil)
print('player name: '..playername)
if mana.playerlist[playername] == nil then
mana.playerlist[playername] = {}
mana.playerlist[playername].mana = 0
mana.playerlist[playername].maxmana = mana.settings.default_max
mana.playerlist[playername].regen = mana.settings.default_regen
mana.playerlist[playername].remainder = 0
end
assert(mana.playerlist[playername] ~= nil)
--SkillsFramework.append_skills(playername, {
SkillsFramework.attach_skillset(playername, {
"iadiscordia:Chaos Magick",
})
-- TODO mana regen
if mana.playerlist[playername].mana < mana.playerlist[playername].maxmana then
self:set_displayed_action("insufficient mana: "..
mana.playerlist[playername].mana .. " < " ..
mana.playerlist[playername].maxmana)
return
end
self:set_displayed_action("attempting spell")
local pointed_thing = {under=target, type="node",}
local new_stack = on_use(stack, user, pointed_thing)
self:set_wield_item_stack(new_stack)
for _=0,10 do coroutine.yield() end --wait 10 steps
-- TODO record successes so he's useful
self:set_displayed_action("casting some spells")
--self:go_to(destination)
local success, ret = self:go_to(destination)
if not success then
working_villages.failed_pos_record(target)
self:set_displayed_action("looking at the unreachable snow")
self:delay(100)
else
self:set_displayed_action("checking for spells in book")
-- -- TODO check HP+MP, and eat+sleep if necessary
local name = stack:get_name()
--local def = minetest.registered_items[name]
local def = stack:get_definition() -- minetest.registered_items[item_name]
local on_use = def.on_use
local user = self
--local playername = user.nametag
local playername = self:get_player_name()
assert(playername ~= nil)
print('player name: '..playername)
-- TODO this belongs in api
if mana.playerlist[playername] == nil then
mana.playerlist[playername] = {}
mana.playerlist[playername].mana = 0
mana.playerlist[playername].maxmana = mana.settings.default_max
mana.playerlist[playername].regen = mana.settings.default_regen
mana.playerlist[playername].remainder = 0
end
assert(mana.playerlist[playername] ~= nil)
--SkillsFramework.append_skills(playername, {
-- TODO this needs to be done once and probably in api
SkillsFramework.attach_skillset(playername, {
"iadiscordia:Chaos Magick",
})
-- TODO mana regen
if mana.playerlist[playername].mana < mana.playerlist[playername].maxmana then
self:set_displayed_action("insufficient mana: "..
mana.playerlist[playername].mana .. " < " ..
mana.playerlist[playername].maxmana)
return
end
self:set_displayed_action("attempting spell")
local pointed_thing = {under=target, type="node",}
local new_stack = on_use(stack, user, pointed_thing)
self:set_wield_item_stack(new_stack)
for _=0,10 do coroutine.yield() end --wait 10 steps
-- TODO record successes so he's useful
end
end
elseif self:timer_exceeded("wizard:change_dir",50) then
self:change_direction_randomly()
Expand Down

0 comments on commit 9688e3a

Please sign in to comment.