master
root 2021-03-02 10:57:33 +01:00
parent 84e8b8fd9e
commit 9f141caf1f
15 changed files with 488 additions and 26 deletions

View File

@ -292,7 +292,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
mobkit.clear_queue_low(pet)
petz.ownthing(pet)
elseif fields.btn_alight then
petz.alight(pet)
petz.alight(pet, 0, "stand")
elseif fields.btn_fly then
mobkit.clear_queue_low(pet)
mobkit.clear_queue_high(pet)

View File

@ -60,11 +60,11 @@ petz.follow = function(self, player)
end
end
petz.alight = function(self)
petz.alight = function(self, prty, end_status)
mobkit.clear_queue_low(self)
mobkit.clear_queue_high(self)
if not(petz.node_name_in(self, "below") == "air") then
mobkit.animate(self, "fly")
end
petz.hq_alight(self, 0)
petz.hq_alight(self, prty, end_status)
end

View File

@ -183,7 +183,7 @@ petz.init_lay_eggs = function(self)
if self.eggs_count > 0 then
return
end
petz.alight(self)
petz.alight(self, 0, "stand")
minetest.after(10.0, function()
if not(mobkit.is_alive(self)) then
return

View File

@ -68,7 +68,7 @@ petz.milk_refill = function(self)
end
petz.milk_milk = function(self, clicker)
if not self.is_male then
if self.is_male then
minetest.chat_send_player(clicker:get_player_name(), S("Milk only female animals!"))
return
end

View File

@ -59,4 +59,46 @@ if minetest.get_modpath("hunger_ng") ~= nil then
hunger_ng.add_hunger_data('petz:candy_cane', {
satiates = 6.0,
})
hunger_ng.add_hunger_data('petz:beef', {
satiates = 1.0,
})
hunger_ng.add_hunger_data('petz:roasted_ducky', {
satiates = 3.0,
})
hunger_ng.add_hunger_data('petz:roasted_rabbit', {
satiates = 3.0,
})
hunger_ng.add_hunger_data('petz:roasted_goat_meat', {
satiates = 4.0,
})
hunger_ng.add_hunger_data('petz:raw_rabbit', {
satiates = 1.0,
})
hunger_ng.add_hunger_data('petz:frog_leg', {
satiates = 1.0,
})
hunger_ng.add_hunger_data('petz:honey_bottle', {
satiates = 7.0,
})
hunger_ng.add_hunger_data('petz:mini_lamb_chop', {
satiates = 1.0,
})
hunger_ng.add_hunger_data('petz:raw_chicken', {
satiates = 1.0,
})
hunger_ng.add_hunger_data('petz:raw_ducky', {
satiates = 1.0,
})
hunger_ng.add_hunger_data('petz:raw_goat', {
satiates = 1.0,
})
hunger_ng.add_hunger_data('petz:raw_parrot', {
satiates = 1.0,
})
hunger_ng.add_hunger_data('petz:raw_porkchop', {
satiates = 1.0,
})
hunger_ng.add_hunger_data('petz:chicken_legs', {
satiates = 1.0,
})
end

View File

@ -169,7 +169,7 @@ end
-- Alight Behaviour ( 2 funtions: HQ & LQ)
--
function petz.hq_alight(self, prty)
function petz.hq_alight(self, prty, end_status)
local func = function()
local node_name = petz.node_name_in(self, "below")
if node_name == "air" then
@ -179,9 +179,9 @@ function petz.hq_alight(self, prty)
return true
else
--minetest.chat_send_player("singleplayer", "on ground")
mobkit.animate(self, "stand")
mobkit.animate(self, end_status)
mobkit.lq_idle(self, 2400)
self.status = "stand"
self.status = end_status
return true
end
end

213
petz/mobkit/br_birds.lua Normal file
View File

@ -0,0 +1,213 @@
-- 1. FLYING MOBS BRAIN
--
function petz.herbivore_brain(self)
local pos = self.object:get_pos()
local die = false
mobkit.vitals(self)
if self.hp <= 0 then
die = true
elseif not(petz.is_night()) and self.die_at_daylight then --it dies when sun rises up
if pos then
local node_light = minetest.get_node_light(pos, minetest.get_timeofday())
if node_light and self.max_daylight_level then
if node_light >= self.max_daylight_level then
die = true
end
end
end
end
if die then
petz.on_die(self)
return
end
--no gravity
self.object:set_acceleration({x=0, y=0, z=0})
petz.check_ground_suffocation(self, pos)
if mobkit.timer(self, 1) then
local prty = mobkit.get_queue_priority(self)
if prty < 30 then
petz.env_damage(self, pos, 30) --enviromental damage: lava, fire...
end
if prty < 25 then
if self.driver then
petz.hq_mountdriver(self, 25)
return
end
end
if prty < 20 then
if self.isinliquid and not self.can_swin then
petz.hq_liquid_recovery_flying(self, 20)
end
end
local player = mobkit.get_nearby_player(self)
--if player then petz.move_head(self, player:get_pos()) end
--Runaway from predator
if prty < 18 then
if petz.bh_runaway_from_predator(self, pos) then
return
end
end
--Follow Behaviour
if prty < 16 then
if petz.bh_start_follow(self, pos, player, 16) then
return
end
end
if prty == 16 then
if petz.bh_stop_follow(self, player) then
return
end
end
-- hunt a prey (another congener)
if prty < 12 and self.aggressive then
petz.bh_hunt(self, 12, true)
end
--Baby petz follow their parents
if prty < 10 then
if petz.settings.parent_search and self.parents then
if mobkit.timer(self, 5) then --each 5 seconds search for parents
petz.follow_parents(self, pos)
end
end
end
--if prty < 7 and self.type == "moth" and mobkit.is_queue_empty_high(self) then --search for a squareball
--local pos_torch_near = minetest.find_node_near(pos, self.view_range, "default:torch")
--if pos_torch_near then
--mobkit.hq_approach_torch(self, 7, pos_torch_near)
--return
--end
--end
if prty < 8 then
if (self.can_jump) and not(self.status) then
local random_number = math.random(1, self.jump_ratio)
if random_number == 1 then
--minetest.chat_send_player("singleplayer", "jump")
mobkit.clear_queue_high(self)
petz.hq_terrestial_jump(self, 8)
end
end
end
--Poop
if prty < 7 then
petz.poop(self, pos)
end
--Replace nodes by others
if prty < 6 then
petz.bh_replace(self)
end
if prty < 5 then
petz.bh_breed(self, pos)
end
--Herding
if prty < 4.5 and petz.settings.herding then
if mobkit.timer(self, petz.settings.herding_timing) then
if petz.bh_herding(self, pos, player) then
return
end
end
end
--search for a petz:pet_bowl or a bale
if prty < 4 and self.tamed then
local view_range = self.view_range
local nearby_nodes = minetest.find_nodes_in_area(
{x = pos.x - view_range, y = pos.y - 1, z = pos.z - view_range},
{x = pos.x + view_range, y = pos.y + 1, z = pos.z + view_range},
{"group:feeder"})
if #nearby_nodes >= 1 then
local tpos = nearby_nodes[1] --the first match
local distance = vector.distance(pos, tpos)
if distance > 3.0 then
mobkit.hq_goto(self, 4, tpos)
elseif distance <= 3.0 then
if petz.settings.tamagochi_mode and not(self.fed) then
petz.do_feed(self)
if self.eat_hay then
local node = minetest.get_node_or_nil(tpos)
if node and node.name == "bale:bale" then
minetest.remove_node(tpos)
mokapi.make_sound("pos", tpos, "petz_replace", 5 or mokapi.consts.DEFAULT_MAX_HEAR_DISTANCE)
end
end
end
end
end
end
--if prty < 5 and self.type == "puppy" and self.tamed == true and self.square_ball_attached == false then --search for a squareball
--local object_list = minetest.get_objects_inside_radius(self.object:get_pos(), 10)
--for i = 1,#object_list do
--local obj = object_list[i]
--local ent = obj:get_luaentity()
--if ent and ent.name == "__builtin:item" then
--minetest.chat_send_player("singleplayer", ent.itemstring)
--local spos = self.object:get_pos()
--local tpos = obj:get_pos()
--if vector.distance(spos, tpos) > 2 then
--if tpos then
--mobkit.hq_goto(self, 5, tpos)
--end
--else
--local meta = ent:get_meta()
--local shooter_name = meta:get_string("shooter_name")
--petz.attach_squareball(ent, self, self.object, nil)
--end
--end
--end
--end
--end
-- Default Random Sound
mokapi.make_misc_sound(self, petz.settings.misc_sound_chance, petz.settings.max_hear_distance)
if prty < 3 then
if self.is_arboreal then
if petz.bh_climb(self, pos, 3) then
return
end
end
end
if prty < 2 then --Sleep Behaviour
petz.bh_sleep(self, 2)
end
--Look_at Behaviour
if prty < 1 and player then
if petz.bh_look_at(self, player:get_pos(), 1) then
return
end
end
--Roam default
if mobkit.is_queue_empty_high(self) and not(self.status) then
petz.hq_wanderfly(self, 0)
end
end
end

213
petz/mobkit/br_flying.lua Normal file
View File

@ -0,0 +1,213 @@
-- 1. FLYING MOBS BRAIN
--
function petz.flying_brain(self)
local pos = self.object:get_pos()
local die = false
mobkit.vitals(self)
if self.hp <= 0 then
die = true
elseif not(petz.is_night()) and self.die_at_daylight then --it dies when sun rises up
if pos then
local node_light = minetest.get_node_light(pos, minetest.get_timeofday())
if node_light and self.max_daylight_level then
if node_light >= self.max_daylight_level then
die = true
end
end
end
end
if die then
petz.on_die(self)
return
end
--no gravity
self.object:set_acceleration({x=0, y=0, z=0})
petz.check_ground_suffocation(self, pos)
if mobkit.timer(self, 1) then
local prty = mobkit.get_queue_priority(self)
if prty < 30 then
petz.env_damage(self, pos, 30) --enviromental damage: lava, fire...
end
if prty < 25 then
if self.driver then
petz.hq_mountdriver(self, 25)
return
end
end
if prty < 20 then
if self.isinliquid and not self.can_swin then
petz.hq_liquid_recovery_flying(self, 20)
end
end
local player = mobkit.get_nearby_player(self)
--if player then petz.move_head(self, player:get_pos()) end
--Runaway from predator
if prty < 18 then
if petz.bh_runaway_from_predator(self, pos) then
return
end
end
--Follow Behaviour
if prty < 16 then
if petz.bh_start_follow(self, pos, player, 16) then
return
end
end
if prty == 16 then
if petz.bh_stop_follow(self, player) then
return
end
end
-- hunt a prey (another congener)
if prty < 12 and self.aggressive then
petz.bh_hunt(self, 12, true)
end
--Baby petz follow their parents
if prty < 10 then
if petz.settings.parent_search and self.parents then
if mobkit.timer(self, 5) then --each 5 seconds search for parents
petz.follow_parents(self, pos)
end
end
end
--if prty < 7 and self.type == "moth" and mobkit.is_queue_empty_high(self) then --search for a squareball
--local pos_torch_near = minetest.find_node_near(pos, self.view_range, "default:torch")
--if pos_torch_near then
--mobkit.hq_approach_torch(self, 7, pos_torch_near)
--return
--end
--end
if prty < 8 then
if (self.can_jump) and not(self.status) then
local random_number = math.random(1, self.jump_ratio)
if random_number == 1 then
--minetest.chat_send_player("singleplayer", "jump")
mobkit.clear_queue_high(self)
petz.hq_terrestial_jump(self, 8)
end
end
end
--Poop
if prty < 7 then
petz.poop(self, pos)
end
--Replace nodes by others
if prty < 6 then
petz.bh_replace(self)
end
if prty < 5 then
petz.bh_breed(self, pos)
end
--Herding
if prty < 4.5 and petz.settings.herding then
if mobkit.timer(self, petz.settings.herding_timing) then
if petz.bh_herding(self, pos, player) then
return
end
end
end
--search for a petz:pet_bowl or a bale
if prty < 4 and self.tamed then
local view_range = self.view_range
local nearby_nodes = minetest.find_nodes_in_area(
{x = pos.x - view_range, y = pos.y - 1, z = pos.z - view_range},
{x = pos.x + view_range, y = pos.y + 1, z = pos.z + view_range},
{"group:feeder"})
if #nearby_nodes >= 1 then
local tpos = nearby_nodes[1] --the first match
local distance = vector.distance(pos, tpos)
if distance > 3.0 then
mobkit.hq_goto(self, 4, tpos)
elseif distance <= 3.0 then
if petz.settings.tamagochi_mode and not(self.fed) then
petz.do_feed(self)
if self.eat_hay then
local node = minetest.get_node_or_nil(tpos)
if node and node.name == "bale:bale" then
minetest.remove_node(tpos)
mokapi.make_sound("pos", tpos, "petz_replace", 5 or mokapi.consts.DEFAULT_MAX_HEAR_DISTANCE)
end
end
end
end
end
end
--if prty < 5 and self.type == "puppy" and self.tamed == true and self.square_ball_attached == false then --search for a squareball
--local object_list = minetest.get_objects_inside_radius(self.object:get_pos(), 10)
--for i = 1,#object_list do
--local obj = object_list[i]
--local ent = obj:get_luaentity()
--if ent and ent.name == "__builtin:item" then
--minetest.chat_send_player("singleplayer", ent.itemstring)
--local spos = self.object:get_pos()
--local tpos = obj:get_pos()
--if vector.distance(spos, tpos) > 2 then
--if tpos then
--mobkit.hq_goto(self, 5, tpos)
--end
--else
--local meta = ent:get_meta()
--local shooter_name = meta:get_string("shooter_name")
--petz.attach_squareball(ent, self, self.object, nil)
--end
--end
--end
--end
--end
-- Default Random Sound
mokapi.make_misc_sound(self, petz.settings.misc_sound_chance, petz.settings.max_hear_distance)
if prty < 3 then
if self.is_arboreal then
if petz.bh_climb(self, pos, 3) then
return
end
end
end
if prty < 2 then --Sleep Behaviour
petz.bh_sleep(self, 2)
end
--Look_at Behaviour
if prty < 1 and player then
if petz.bh_look_at(self, player:get_pos(), 1) then
return
end
end
--Roam default
if mobkit.is_queue_empty_high(self) and not(self.status) then
petz.hq_wanderfly(self, 0)
end
end
end

View File

@ -1,4 +1,4 @@
-- 1. HERBIBORE/FLYING MOBS BRAIN
-- 1. HERBIBORE MOBS BRAIN
--
function petz.herbivore_brain(self)
@ -27,7 +27,8 @@ function petz.herbivore_brain(self)
return
end
if self.can_fly or self.status == "climb" then
--no gravity
if self.status == "climb" then
self.object:set_acceleration({x=0, y=0, z=0})
end
@ -50,11 +51,7 @@ function petz.herbivore_brain(self)
if prty < 20 then
if self.isinliquid then
if not self.can_fly then
mobkit.hq_liquid_recovery(self, 20)
else
petz.hq_liquid_recovery_flying(self, 20)
end
mobkit.hq_liquid_recovery(self, 20)
return
end
end
@ -85,7 +82,7 @@ function petz.herbivore_brain(self)
--Runaway from Player
if prty < 14 then
if not(self.can_fly) and not(self.tamed) then --if no tamed
if not(self.tamed) then --if no tamed
if player then
local player_pos = player:get_pos()
local wielded_item_name = player:get_wielded_item():get_name()
@ -226,11 +223,7 @@ function petz.herbivore_brain(self)
--Roam default
if mobkit.is_queue_empty_high(self) and not(self.status) then
if not(self.can_fly) then
mobkit.hq_roam(self, 0)
else
petz.hq_wanderfly(self, 0)
end
mobkit.hq_roam(self, 0)
end
end

View File

@ -25,3 +25,4 @@ assert(loadfile(modpath .. "/mobkit/br_predator.lua"))()
assert(loadfile(modpath .. "/mobkit/br_semiaquatic.lua"))()
assert(loadfile(modpath .. "/mobkit/helper_functions.lua"))()
assert(loadfile(modpath .. "/mobkit/bh_head.lua"))()
assert(loadfile(modpath .. "/mobkit/br_flying.lua"))()

View File

@ -54,7 +54,7 @@ minetest.register_entity("petz:"..pet_name,{
stand_fly={range={x=0, y=6}, speed=25, loop=true},
},
logic = petz.herbivore_brain,
logic = petz.flying_brain,
on_activate = function(self, staticdata, dtime_s) --on_activate, required
mobkit.actfunc(self, staticdata, dtime_s)

View File

@ -65,7 +65,7 @@ minetest.register_entity("petz:"..pet_name,{
moaning = "petz_moth_moaning",
},
logic = petz.herbivore_brain,
logic = petz.flying_brain,
on_activate = function(self, staticdata, dtime_s) --on_activate, required
mobkit.actfunc(self, staticdata, dtime_s)

View File

@ -65,7 +65,7 @@ minetest.register_entity("petz:"..pet_name,{
moaning = "petz_parrot_moaning",
},
logic = petz.herbivore_brain,
logic = petz.flying_brain,
on_activate = function(self, staticdata, dtime_s) --on_activate, required
mobkit.actfunc(self, staticdata, dtime_s)

View File

@ -65,7 +65,7 @@ minetest.register_entity("petz:"..pet_name,{
moaning = "petz_pigeon_moaning",
},
logic = petz.herbivore_brain,
logic = petz.flying_brain,
on_activate = function(self, staticdata, dtime_s) --on_activate, required
mobkit.actfunc(self, staticdata, dtime_s)

View File

@ -64,7 +64,7 @@ minetest.register_entity("petz:"..pet_name,{
moaning = "petz_toucan_moaning",
},
logic = petz.herbivore_brain,
logic = petz.flying_brain,
on_activate = function(self, staticdata, dtime_s) --on_activate, required
mobkit.actfunc(self, staticdata, dtime_s)