Update shooter to 0.6.1

This commit is contained in:
rubenwardy 2020-03-14 21:51:24 +00:00 committed by GitHub
parent 85bf7b96d1
commit 63726848ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
85 changed files with 236 additions and 2022 deletions

View file

@ -17,16 +17,28 @@ function ctf_classes.register(cname, def)
if not def.properties.item_blacklist then
def.properties.item_blacklist = {}
for i=1, #def.properties.initial_stuff do
table.insert(def.properties.item_blacklist, def.properties.initial_stuff[i])
def.properties.item_blacklist[i] =
ItemStack(def.properties.initial_stuff[i]):get_name()
end
end
if def.properties.additional_item_blacklist then
for i=1, #def.properties.additional_item_blacklist do
table.insert(def.properties.item_blacklist, def.properties.additional_item_blacklist[i])
table.insert(def.properties.item_blacklist,
def.properties.additional_item_blacklist[i])
end
end
-- Validate items
for i=1, #def.properties.initial_stuff do
local item_name = ItemStack(def.properties.initial_stuff[i]):get_name()
assert(minetest.registered_items[item_name], "Item " .. item_name .. " not found")
end
for i=1, #def.properties.item_blacklist do
local item_name = def.properties.item_blacklist[i]
assert(minetest.registered_items[item_name], "Item " .. item_name .. " not found")
end
def.properties.speed = def.properties.speed or 1
def.properties.max_hp = def.properties.max_hp or 20
end

View file

@ -14,9 +14,9 @@ ctf_classes.register("knight", {
},
allowed_guns = {
"shooter:pistol",
"shooter:smg",
"shooter:shotgun",
"shooter_guns:pistol",
"shooter_guns:smg",
"shooter_guns:shotgun",
},
},
})
@ -30,25 +30,28 @@ ctf_classes.register("shooter", {
allow_grapples = true,
initial_stuff = {
"shooter:rifle",
"shooter:grapple_gun_loaded",
"shooter_guns:rifle_loaded",
"shooter_hook:grapple_gun_loaded",
},
additional_item_blacklist = {
"shooter:grapple_gun",
"shooter:grapple_hook",
"shooter_hook:grapple_gun",
"shooter_hook:grapple_hook",
"shooter_guns:rifle",
},
allowed_guns = {
"shooter:pistol",
"shooter:rifle",
"shooter:smg",
"shooter:shotgun",
"shooter_guns:pistol",
"shooter_guns:rifle",
"shooter_guns:smg",
"shooter_guns:shotgun",
},
shooter_multipliers = {
range = 1.5,
full_punch_interval = 0.8,
tool_caps = {
full_punch_interval = 0.8,
},
},
},
})
@ -66,9 +69,9 @@ ctf_classes.register("medic", {
},
allowed_guns = {
"shooter:pistol",
"shooter:smg",
"shooter:shotgun",
"shooter_guns:pistol",
"shooter_guns:smg",
"shooter_guns:shotgun",
},
},
})
@ -80,18 +83,18 @@ ctf_classes.register("rocketeer", {
color = "#fa0",
properties = {
initial_stuff = {
"shooter:rocket_gun_loaded",
"shooter:rocket 4",
"shooter_rocket:rocket_gun_loaded",
"shooter_rocket:rocket 4",
},
additional_item_blacklist = {
"shooter:rocket_gun",
"shooter_rocket:rocket_gun",
},
allowed_guns = {
"shooter:pistol",
"shooter:smg",
"shooter:shotgun",
"shooter_guns:pistol",
"shooter_guns:smg",
"shooter_guns:shotgun",
},
},
})

View file

@ -9,30 +9,46 @@ end
-- Returns true if the item shouldn't be allowed to be dropped etc
local function is_class_blacklisted(player, itemname)
local class = ctf_classes.get(player)
local items = stack_list_to_map(class.properties.item_blacklist or {})
local items = stack_list_to_map(class.properties.item_blacklist)
return items[itemname]
end
give_initial_stuff.register_stuff_provider(function(player)
local class = ctf_classes.get(player)
return class.properties.initial_stuff or {}
return class.properties.initial_stuff
end, 1)
local function remove_blacklist_in_list(list, blacklist_map)
local removed = false
for i=1, #list do
if blacklist_map[ItemStack(list[i]):get_name()] then
list[i] = ""
removed = true
end
end
return removed
end
ctf_classes.register_on_changed(function(player, old, new)
local inv = player:get_inventory()
if old then
local items = old.properties.item_blacklist or {}
for i = 1, #items do
inv:remove_item("main", ItemStack(items[i]))
local blacklist = old.properties.item_blacklist
if old and #blacklist > 0 then
local blacklist_map = stack_list_to_map(blacklist)
for listname, list in pairs(inv:get_lists()) do
if remove_blacklist_in_list(list, blacklist_map) then
inv:set_list(listname, list)
end
end
end
do
assert(new)
local items = new.properties.initial_stuff or {}
local items = new.properties.initial_stuff
for i = 1, #items do
inv:add_item("main", ItemStack(items[i]))
end

View file

@ -1,3 +1,3 @@
name = ctf_classes
depends = ctf, ctf_flag, ctf_colors, ctf_map_core, physics, shooter, hpregen, give_initial_stuff, dropondie
depends = ctf, ctf_flag, ctf_colors, ctf_map_core, ctf_bandages, physics, shooter, hpregen, give_initial_stuff, dropondie
description = Adds classes, including knight, shooter, and medic

View file

@ -1,30 +1,30 @@
local specs_cache = {}
local function recursive_multiply(source, multiplier)
for key, value in pairs(multiplier) do
assert(type(source[key]) == type(value))
if type(value) == "table" then
recursive_multiply(source[key], value)
else
source[key] = source[key] * value
end
end
end
local function get_shooter_specs(weapon_name, multiplier)
local spec = shooter.registered_weapons[weapon_name]
if not spec then
return nil
end
spec = spec.spec
-- this will convert the multipler to a table pointer
local idx = ("%s:%s"):format(multiplier or "nil", weapon_name)
spec = table.copy(spec.spec)
if specs_cache[idx] then
return specs_cache[idx]
end
spec = table.copy(spec)
specs_cache[idx] = spec
for key, value in pairs(multiplier) do
spec[key] = spec[key] * value
if multiplier then
recursive_multiply(spec, multiplier)
end
return spec
end
shooter.get_weapon_spec = function(_, user, weapon_name)
shooter.get_weapon_spec = function(user, weapon_name)
local class = ctf_classes.get(user)
if table.indexof(class.properties.allowed_guns or {}, weapon_name) == -1 then
@ -34,7 +34,9 @@ shooter.get_weapon_spec = function(_, user, weapon_name)
end
local spec = get_shooter_specs(weapon_name, class.properties.shooter_multipliers)
spec.name = user and user:get_player_name()
if not spec then
return nil
end
return spec
end
@ -64,6 +66,6 @@ local function check_grapple(itemname)
})
end
check_grapple("shooter:grapple_gun_loaded")
check_grapple("shooter:grapple_gun")
check_grapple("shooter:grapple_hook")
check_grapple("shooter_hook:grapple_gun_loaded")
check_grapple("shooter_hook:grapple_gun")
check_grapple("shooter_hook:grapple_hook")