Use player_monoids

This commit is contained in:
raymoo 2016-08-05 13:45:03 -07:00
parent e67d3b7a75
commit 92b243ad27
4 changed files with 24 additions and 39 deletions

View File

@ -1,23 +1,21 @@
#The Armor Monoid
This mod provides a monoidal_effects monoid for handling armor groups. It
provides the ```"armor"``` monoid, and a way to register new damage types
This mod provides a player_monoids monoid for handling armor groups. It
provides a monoid for damage resistance, and a way to register new damage types
for players. It is also compatible with 3d_armor.
Using the monoid
================
The values in the monoid are tables mapping armor group names to damage
multipliers. For example, if I wanted to register an effect granting arcane
multipliers. For example, if I wanted to apply an effect granting arcane
damage resistance but fleshy damage vulnerability, I could do <br/>
```
monoidal_effects.register_effect_type("magic_barrier", {
disp_name = "Magic Barrier",
tags = { magical = 1 },
monoids = { armor = true },
cancel_on_death = true,
values = { armor = { fleshy = 1.5, arcane = 0.3 } },
icon = "magic_barrier.png",
})
local tab = {
arcane = 50,
fleshy = 150,
}
armor_monoid.monoid:add_change(player, tab, "mymod:arcane_boost")
```
Registering damage types

View File

@ -1,2 +1,2 @@
monoidal_effects
player_monoids
3d_armor?

View File

@ -1 +1 @@
A monoidal_effects monoid for armor
A player_monoids monoid for armor

View File

@ -22,7 +22,7 @@ end
-- For example { fleshy = 0.5, fire = 1.2 } would mean that a player takes
-- half fleshy damage and 120% fire damage. Nil values are the same as putting
-- 1. The final multipliers are multiplied to the base damage for the group.
monoidal_effects.register_monoid("armor", {
armor_monoid.monoid = player_monoids.make_monoid({
combine = function(tab1, tab2)
local res = {}
@ -101,25 +101,6 @@ end
if not minetest.global_exists("armor") then return end
monoidal_effects.register_type("armor_monoid:compat_armor", {
disp_name = "3D Armor Compatibility",
dynamic = true,
monoids = { armor = true },
hidden = true,
cancel_on_death = false,
values = { armor = {} },
})
monoidal_effects.register_type("armor_monoid:compat_phys", {
disp_name = "3D Armor Physics Compatibility",
dynamic = true,
monoids = { speed = true, jump = true, gravity = true },
hidden = true,
cancel_on_death = false,
values = { speed = 1, jump = 1, gravity = 1 },
})
-- Armor override
armor.set_player_armor = function(self, player)
local name, player_inv = armor:get_valid_player(player, "[set_player_armor]")
@ -196,13 +177,19 @@ armor.set_player_armor = function(self, player)
armor_groups.fleshy = 100 - armor_level
end
monoidal_effects.cancel_effect_type("armor_monoid:compat_armor", name)
monoidal_effects.cancel_effect_type("armor_monoid:compat_phys", name)
armor_monoid.monoid:del_change(player, "armor_monoid:compat")
player_monoids.speed:del_change(player, "armor_monoid:compat")
player_monoids.jump:del_change(player, "armor_monoid:compat")
player_monoids.gravity:del_change(player, "armor_monoid:compat")
monoidal_effects.apply_effect("armor_monoid:compat_armor", "perm", name, {
armor = { fleshy = armor_groups.fleshy / 100 },
})
monoidal_effects.apply_effect("armor_monoid:compat_phys", "perm", name, physics_o)
armor_monoid.add_change(player, { fleshy = armor_groups.fleshy / 100 },
"armor_monoid:compat")
player_monoids.speed:add_change(player, physics_o.speed,
"armor_monoid:compat")
player_monoids.jump:add_change(player, physics_o.jump,
"armor_monoid:compat")
player_monoids.gravity:add_change(player, physics_o.gravity,
"armor_monoid:compat")
self.textures[name].armor = armor_texture
self.textures[name].preview = preview