summaryrefslogtreecommitdiff
path: root/example/scripts/attributes.lua
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2013-02-20 15:34:28 +0100
committerErik Schilling <ablu.erikschilling@googlemail.com>2013-02-20 15:34:28 +0100
commitc70c6d19c1cabf46b595591802bceab63d371788 (patch)
tree1c153d2bfe560171bad5889d528dc5cf110e8533 /example/scripts/attributes.lua
parentd707495540581f8c1b9ab3d5007c9c4d1ab83b53 (diff)
parent587b7682e6bf7dd9e616c1d4789a5ed9aa986e6d (diff)
downloadmanaserv-c70c6d19c1cabf46b595591802bceab63d371788.tar.gz
manaserv-c70c6d19c1cabf46b595591802bceab63d371788.tar.bz2
manaserv-c70c6d19c1cabf46b595591802bceab63d371788.tar.xz
manaserv-c70c6d19c1cabf46b595591802bceab63d371788.zip
Merge branch 'master' into lpc2012
Conflicts: gameserver.cbp src/account-server/accounthandler.cpp src/game-server/attack.cpp src/game-server/attack.h src/game-server/being.cpp src/game-server/being.h src/game-server/character.cpp src/game-server/character.h src/game-server/inventory.cpp src/game-server/item.h src/game-server/monster.cpp src/game-server/monster.h
Diffstat (limited to 'example/scripts/attributes.lua')
-rw-r--r--example/scripts/attributes.lua74
1 files changed, 74 insertions, 0 deletions
diff --git a/example/scripts/attributes.lua b/example/scripts/attributes.lua
new file mode 100644
index 00000000..469cdf4e
--- /dev/null
+++ b/example/scripts/attributes.lua
@@ -0,0 +1,74 @@
+--[[
+
+ This file demonstrates how attributes are getting calculated and how they can
+ be linked to each other.
+
+ See http://doc.manasource.org/attributes.xml for more info.
+
+--]]
+
+local function recalculate_base_attribute(being, attribute)
+ local old_base = being_get_base_attribute(being, attribute)
+ local new_base = old_base
+ if attribute == ATTR_ACCURACY then
+ -- Provisional
+ new_base = being_get_modified_attribute(being, ATTR_DEX)
+ elseif attribute == ATTR_DEFENSE then
+ new_base = 0.3 * being_get_modified_attribute(being, ATTR_VIT)
+ elseif attribute == ATTR_DODGE then
+ -- Provisional
+ new_base = being_get_modified_attribute(being, ATTR_AGI)
+ elseif attribute == ATTR_MAGIC_DODGE then
+ -- TODO
+ new_base = 1
+ elseif attribute == ATTR_MAGIC_DEFENSE then
+ -- TODO
+ new_base = 0
+ elseif attribute == ATTR_BONUS_ASPD then
+ -- TODO
+ new_base = 0
+ elseif attribute == ATTR_HP_REGEN then
+ local hp_per_sec = being_get_modified_attribute(being, ATTR_VIT) * 0.05
+ new_base = hp_per_sec * TICKS_PER_HP_REGENERATION / 10
+ elseif attribute == ATTR_HP then
+ local hp = being_get_modified_attribute(being, ATTR_HP)
+ local max_hp = being_get_modified_attribute(being, ATTR_MAX_HP)
+
+ if hp > max_hp then
+ new_base = new_base - hp - max_hp
+ end
+ elseif attribute == ATTR_MAX_HP then
+ local vit = being_get_modified_attribute(being, ATTR_VIT)
+ new_base = (vit + 3) * (vit + 20) * 0.125
+ elseif attribute == ATTR_MOVE_SPEED_TPS then
+ -- Provisional
+ new_base = 3.0 + being_get_modified_attribute(being, ATTR_AGI) * 0.08
+ elseif attribute == ATTR_INV_CAPACITY then
+ -- Provisional
+ new_base = 2000 + being_get_modified_attribute(being, ATTR_STR) * 180
+ end
+
+ if new_base ~= old_base then
+ being_set_base_attribute(being, attribute, new_base)
+ end
+
+end
+
+local function update_derived_attributes(being, attribute)
+ if attribute == ATTR_STR then
+ recalculate_base_attribute(being, ATTR_INV_CAPACITY)
+ elseif attribute == ATTR_AGI then
+ recalculate_base_attribute(being, ATTR_DODGE)
+ elseif attribute == ATTR_VIT then
+ recalculate_base_attribute(being, ATTR_MAX_HP)
+ recalculate_base_attribute(being, ATTR_HP_REGEN)
+ recalculate_base_attribute(being, ATTR_DEFENSE)
+ elseif attribute == ATTR_INT then
+ -- unimplemented
+ elseif attribute == ATTR_WIL then
+ -- unimplemented
+ end
+end
+
+on_recalculate_base_attribute(recalculate_base_attribute)
+on_update_derived_attribute(update_derived_attributes)