mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2025-01-11 18:40:25 +01:00
Added class shifting system
- Warrior shifting system implemented
This commit is contained in:
parent
34ae29e899
commit
0f562cd59e
@ -450,11 +450,13 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
player:get_inventory():set_stack(listname, index, stack)
|
player:get_inventory():set_stack(listname, index, stack)
|
||||||
armor:set_player_armor(player)
|
armor:set_player_armor(player)
|
||||||
armor:update_inventory(player)
|
armor:update_inventory(player)
|
||||||
|
pclasses.api.assign_class(player) -- //MFF (Mg|07/18/2015)
|
||||||
end,
|
end,
|
||||||
on_take = function(inv, listname, index, stack, player)
|
on_take = function(inv, listname, index, stack, player)
|
||||||
player:get_inventory():set_stack(listname, index, nil)
|
player:get_inventory():set_stack(listname, index, nil)
|
||||||
armor:set_player_armor(player)
|
armor:set_player_armor(player)
|
||||||
armor:update_inventory(player)
|
armor:update_inventory(player)
|
||||||
|
pclasses.api.assign_class(player) -- //MFF (Mg|07/18/2015)
|
||||||
end,
|
end,
|
||||||
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||||
local plaver_inv = player:get_inventory()
|
local plaver_inv = player:get_inventory()
|
||||||
@ -463,6 +465,7 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
player_inv:set_stack(from_list, from_index, nil)
|
player_inv:set_stack(from_list, from_index, nil)
|
||||||
armor:set_player_armor(player)
|
armor:set_player_armor(player)
|
||||||
armor:update_inventory(player)
|
armor:update_inventory(player)
|
||||||
|
pclasses.api.assign_class(player) -- //MFF (Mg|07/18/2015)
|
||||||
end,
|
end,
|
||||||
allow_put = function(inv, listname, index, stack, player)
|
allow_put = function(inv, listname, index, stack, player)
|
||||||
--DEBUT modif MFF (crabman/24/06/2015)
|
--DEBUT modif MFF (crabman/24/06/2015)
|
||||||
|
@ -19,7 +19,7 @@ function interact.get_player_language(plr)
|
|||||||
return interact.player_languages[plr]
|
return interact.player_languages[plr]
|
||||||
end
|
end
|
||||||
return interact.player_languages[plr:get_player_name()]
|
return interact.player_languages[plr:get_player_name()]
|
||||||
end
|
end
|
||||||
|
|
||||||
interact.forms = {
|
interact.forms = {
|
||||||
languageselect = function(player)
|
languageselect = function(player)
|
||||||
|
@ -94,7 +94,7 @@ function mobs:register_mob(name, def)
|
|||||||
self.attack.dist = dist
|
self.attack.dist = dist
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
set_velocity = function(self, v)
|
set_velocity = function(self, v)
|
||||||
v = (v or 0)
|
v = (v or 0)
|
||||||
if def.drawtype
|
if def.drawtype
|
||||||
@ -106,7 +106,7 @@ function mobs:register_mob(name, def)
|
|||||||
local z = math.cos(yaw) * v
|
local z = math.cos(yaw) * v
|
||||||
self.object:setvelocity({x = x, y = self.object:getvelocity().y, z = z})
|
self.object:setvelocity({x = x, y = self.object:getvelocity().y, z = z})
|
||||||
end,
|
end,
|
||||||
|
|
||||||
get_velocity = function(self)
|
get_velocity = function(self)
|
||||||
local v = self.object:getvelocity()
|
local v = self.object:getvelocity()
|
||||||
return (v.x ^ 2 + v.z ^ 2) ^ (0.5)
|
return (v.x ^ 2 + v.z ^ 2) ^ (0.5)
|
||||||
@ -122,9 +122,9 @@ function mobs:register_mob(name, def)
|
|||||||
local d = { x = vx / ds, z = vz / ds }
|
local d = { x = vx / ds, z = vz / ds }
|
||||||
local p = { x = pos.x / ps, z = pos.z / ps }
|
local p = { x = pos.x / ps, z = pos.z / ps }
|
||||||
local an = ( d.x * p.x ) + ( d.z * p.z )
|
local an = ( d.x * p.x ) + ( d.z * p.z )
|
||||||
|
|
||||||
a = math.deg( math.acos( an ) )
|
a = math.deg( math.acos( an ) )
|
||||||
|
|
||||||
if a > ( self.fov / 2 ) then
|
if a > ( self.fov / 2 ) then
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
@ -185,7 +185,7 @@ function mobs:register_mob(name, def)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_step = function(self, dtime)
|
on_step = function(self, dtime)
|
||||||
|
|
||||||
if self.type == "monster"
|
if self.type == "monster"
|
||||||
@ -268,7 +268,7 @@ function mobs:register_mob(name, def)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- knockback timer
|
-- knockback timer
|
||||||
if self.pause_timer > 0 then
|
if self.pause_timer > 0 then
|
||||||
self.pause_timer = self.pause_timer - dtime
|
self.pause_timer = self.pause_timer - dtime
|
||||||
@ -277,7 +277,7 @@ function mobs:register_mob(name, def)
|
|||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- attack timer
|
-- attack timer
|
||||||
self.timer = self.timer + dtime
|
self.timer = self.timer + dtime
|
||||||
if self.state ~= "attack" then
|
if self.state ~= "attack" then
|
||||||
@ -294,7 +294,7 @@ function mobs:register_mob(name, def)
|
|||||||
max_hear_distance = self.sounds.distance
|
max_hear_distance = self.sounds.distance
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
local do_env_damage = function(self)
|
local do_env_damage = function(self)
|
||||||
|
|
||||||
local pos = self.object:getpos()
|
local pos = self.object:getpos()
|
||||||
@ -334,7 +334,7 @@ function mobs:register_mob(name, def)
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local do_jump = function(self)
|
local do_jump = function(self)
|
||||||
if self.fly then
|
if self.fly then
|
||||||
return
|
return
|
||||||
@ -360,7 +360,7 @@ function mobs:register_mob(name, def)
|
|||||||
})
|
})
|
||||||
--print ("in front:", nod.name, pos.y)
|
--print ("in front:", nod.name, pos.y)
|
||||||
if nod and nod.name and
|
if nod and nod.name and
|
||||||
(nod.name ~= "air"
|
(nod.name ~= "air"
|
||||||
or self.walk_chance == 0) then
|
or self.walk_chance == 0) then
|
||||||
local def = minetest.registered_items[nod.name]
|
local def = minetest.registered_items[nod.name]
|
||||||
if (def
|
if (def
|
||||||
@ -385,7 +385,7 @@ function mobs:register_mob(name, def)
|
|||||||
self.jumptimer = 0
|
self.jumptimer = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- environmental damage timer
|
-- environmental damage timer
|
||||||
self.env_damage_timer = self.env_damage_timer + dtime
|
self.env_damage_timer = self.env_damage_timer + dtime
|
||||||
if self.state == "attack"
|
if self.state == "attack"
|
||||||
@ -395,7 +395,7 @@ function mobs:register_mob(name, def)
|
|||||||
elseif self.state ~= "attack" then
|
elseif self.state ~= "attack" then
|
||||||
do_env_damage(self)
|
do_env_damage(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- find someone to attack
|
-- find someone to attack
|
||||||
if self.type == "monster"
|
if self.type == "monster"
|
||||||
and damage_enabled
|
and damage_enabled
|
||||||
@ -421,7 +421,7 @@ function mobs:register_mob(name, def)
|
|||||||
type = obj.type
|
type = obj.type
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if type == "player"
|
if type == "player"
|
||||||
or type == "npc" then
|
or type == "npc" then
|
||||||
s = self.object:getpos()
|
s = self.object:getpos()
|
||||||
@ -446,7 +446,7 @@ function mobs:register_mob(name, def)
|
|||||||
self.do_attack(self, min_player, min_dist)
|
self.do_attack(self, min_player, min_dist)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- npc, find closest monster to attack
|
-- npc, find closest monster to attack
|
||||||
local min_dist = self.view_range + 1
|
local min_dist = self.view_range + 1
|
||||||
local min_player = nil
|
local min_player = nil
|
||||||
@ -658,7 +658,7 @@ function mobs:register_mob(name, def)
|
|||||||
|
|
||||||
if self.type == "npc" then
|
if self.type == "npc" then
|
||||||
local o = minetest.get_objects_inside_radius(self.object:getpos(), 3)
|
local o = minetest.get_objects_inside_radius(self.object:getpos(), 3)
|
||||||
|
|
||||||
local yaw = 0
|
local yaw = 0
|
||||||
for _,o in ipairs(o) do
|
for _,o in ipairs(o) do
|
||||||
if o:is_player() then
|
if o:is_player() then
|
||||||
@ -674,7 +674,7 @@ function mobs:register_mob(name, def)
|
|||||||
if lp.x > s.x then
|
if lp.x > s.x then
|
||||||
yaw = yaw + math.pi
|
yaw = yaw + math.pi
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
yaw = self.object:getyaw() + ((math.random(0, 360) - 180) / 180 * math.pi)
|
yaw = self.object:getyaw() + ((math.random(0, 360) - 180) / 180 * math.pi)
|
||||||
end
|
end
|
||||||
self.object:setyaw(yaw)
|
self.object:setyaw(yaw)
|
||||||
@ -751,7 +751,7 @@ end
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- exploding mobs
|
-- exploding mobs
|
||||||
elseif self.state == "attack" and self.attack_type == "explode" then
|
elseif self.state == "attack" and self.attack_type == "explode" then
|
||||||
if not self.attack.player
|
if not self.attack.player
|
||||||
or not self.attack.player:is_player() then
|
or not self.attack.player:is_player() then
|
||||||
self.state = "stand"
|
self.state = "stand"
|
||||||
@ -776,7 +776,7 @@ end
|
|||||||
self:set_animation("walk")
|
self:set_animation("walk")
|
||||||
self.attack.dist = dist
|
self.attack.dist = dist
|
||||||
end
|
end
|
||||||
|
|
||||||
local vec = {x = p.x - s.x, y = p.y - s.y, z = p.z - s.z}
|
local vec = {x = p.x - s.x, y = p.y - s.y, z = p.z - s.z}
|
||||||
yaw = math.atan(vec.z / vec.x) + math.pi / 2 + self.rotate -- local
|
yaw = math.atan(vec.z / vec.x) + math.pi / 2 + self.rotate -- local
|
||||||
if p.x > s.x then
|
if p.x > s.x then
|
||||||
@ -904,7 +904,7 @@ end
|
|||||||
else
|
else
|
||||||
self.attack.dist = dist
|
self.attack.dist = dist
|
||||||
end
|
end
|
||||||
|
|
||||||
local vec = {x = p.x - s.x, y = p.y - s.y, z = p.z - s.z}
|
local vec = {x = p.x - s.x, y = p.y - s.y, z = p.z - s.z}
|
||||||
yaw = (math.atan(vec.z / vec.x) + math.pi / 2) + self.rotate -- local
|
yaw = (math.atan(vec.z / vec.x) + math.pi / 2) + self.rotate -- local
|
||||||
if p.x > s.x then
|
if p.x > s.x then
|
||||||
@ -977,7 +977,7 @@ end
|
|||||||
else
|
else
|
||||||
self.attack.dist = dist
|
self.attack.dist = dist
|
||||||
end
|
end
|
||||||
|
|
||||||
local vec = {x = p.x - s.x, y = p.y - s.y, z = p.z - s.z}
|
local vec = {x = p.x - s.x, y = p.y - s.y, z = p.z - s.z}
|
||||||
yaw = (math.atan(vec.z/vec.x)+math.pi/2) + self.rotate
|
yaw = (math.atan(vec.z/vec.x)+math.pi/2) + self.rotate
|
||||||
if p.x > s.x then
|
if p.x > s.x then
|
||||||
@ -985,7 +985,7 @@ end
|
|||||||
end
|
end
|
||||||
self.object:setyaw(yaw)
|
self.object:setyaw(yaw)
|
||||||
self.set_velocity(self, 0)
|
self.set_velocity(self, 0)
|
||||||
|
|
||||||
if self.shoot_interval
|
if self.shoot_interval
|
||||||
and self.timer > self.shoot_interval
|
and self.timer > self.shoot_interval
|
||||||
and math.random(1, 100) <= 60 then
|
and math.random(1, 100) <= 60 then
|
||||||
@ -1206,7 +1206,7 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, inter
|
|||||||
action = function(pos, node, _, active_object_count_wider)
|
action = function(pos, node, _, active_object_count_wider)
|
||||||
-- do not spawn if too many active entities in area
|
-- do not spawn if too many active entities in area
|
||||||
if active_object_count_wider > active_object_count
|
if active_object_count_wider > active_object_count
|
||||||
or not mobs.spawning_mobs[name]
|
or not mobs.spawning_mobs[name]
|
||||||
or not pos then
|
or not pos then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -46,7 +46,7 @@ function pclasses.api.id_for_class(cname)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Register the class (basic registration)
|
-- Register the class (basic registration)
|
||||||
function pclasses.api.register_class(cname)
|
function pclasses.api.register_class(cname, assign_f)
|
||||||
if not cname then
|
if not cname then
|
||||||
minetest.log("error", "[PClasses] Error registering unamed class")
|
minetest.log("error", "[PClasses] Error registering unamed class")
|
||||||
return
|
return
|
||||||
@ -54,6 +54,9 @@ function pclasses.api.register_class(cname)
|
|||||||
|
|
||||||
local c_id = pclasses.api.create_class_id()
|
local c_id = pclasses.api.create_class_id()
|
||||||
pclasses.classes[c_id] = {name = cname}
|
pclasses.classes[c_id] = {name = cname}
|
||||||
|
if assign_f then
|
||||||
|
pclasses.classes[c_id].match_function = assign_f
|
||||||
|
end
|
||||||
return c_id
|
return c_id
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -129,6 +132,7 @@ minetest.register_globalstep(function(dtime)
|
|||||||
save_timer = 0
|
save_timer = 0
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
minetest.register_on_shutdown(save_datas)
|
||||||
|
|
||||||
-----------------------------
|
-----------------------------
|
||||||
-- Default class assignment
|
-- Default class assignment
|
||||||
@ -144,3 +148,40 @@ if pclasses.conf.default_class then
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
------------
|
||||||
|
-- Classes
|
||||||
|
--
|
||||||
|
|
||||||
|
pclasses.api.register_class("warrior", function(player)
|
||||||
|
local inv = minetest.get_inventory({type = "detached", name = player:get_player_name() .. "_armor"})
|
||||||
|
local shift_class = false
|
||||||
|
if not inv or inv:is_empty("armor") then
|
||||||
|
return shift_class
|
||||||
|
end
|
||||||
|
shift_class = true
|
||||||
|
for _,piece in pairs({"helmet", "leggings", "boots", "helmet"}) do
|
||||||
|
shift_class = shift_class and inv:contains_item("armor", "3d_armor:" .. piece .. "_warrior")
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
function pclasses.api.assign_class(player)
|
||||||
|
-- Look for every sign needed to deduct a player's class
|
||||||
|
-- Starting from the most important class to the less one
|
||||||
|
|
||||||
|
print(pclasses.classes[pclasses.api.id_for_class("warrior")].match_function(player))
|
||||||
|
if pclasses.classes[pclasses.api.id_for_class("warrior")].match_function(player)
|
||||||
|
and pclasses.api.get_player_class(player:get_player_name()) ~= "warrior" then
|
||||||
|
pclasses.api.set_player_class(player:get_player_name(), "warrior")
|
||||||
|
minetest.chat_send_player(player:get_player_name(), "You are now a warrior")
|
||||||
|
|
||||||
|
elseif pclasses.api.get_player_class(player:get_player_name()) ~= "adventurer" then
|
||||||
|
pclasses.api.set_player_class(player:get_player_name(), "adventurer")
|
||||||
|
minetest.chat_send_player(player:get_player_name(), "You are now an adventurer")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_on_respawnplayer(pclasses.api.assign_class)
|
||||||
|
minetest.register_on_joinplayer(pclasses.api.assign_class)
|
||||||
|
minetest.register_on_leaveplayer(pclasses.api.assign_class)
|
||||||
|
Loading…
Reference in New Issue
Block a user