diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-05-08 00:06:32 +0200 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-08-26 22:56:46 +0200 |
commit | 68481094c0d02ba127bcab6c692801b01a27f21b (patch) | |
tree | aad235cc104f2a2445bab9f8e0d274ad89969cf4 /example | |
parent | f31277b327df701361391b1d4b8bd6f89f4e3109 (diff) | |
download | manaserv-68481094c0d02ba127bcab6c692801b01a27f21b.tar.gz manaserv-68481094c0d02ba127bcab6c692801b01a27f21b.tar.bz2 manaserv-68481094c0d02ba127bcab6c692801b01a27f21b.tar.xz manaserv-68481094c0d02ba127bcab6c692801b01a27f21b.zip |
[Abilities] Added abilities to monsters
Monsters can now either receive abilities at lifetime via scripts, or
via the <ability> node in the monsters node.
Diffstat (limited to 'example')
-rw-r--r-- | example/scripts/monster/basic_ai.lua | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/example/scripts/monster/basic_ai.lua b/example/scripts/monster/basic_ai.lua new file mode 100644 index 00000000..9c35f42c --- /dev/null +++ b/example/scripts/monster/basic_ai.lua @@ -0,0 +1,97 @@ +--[[ + + Basic stroll ai + +--]] + +local STROLL_TIMEOUT = 20 +local STROLL_TIMEOUT_RANDOMNESS = 10 + +-- Wrapping the monster update callback in order to do the stroll ai here +local old_on_update = MonsterClass.on_update +local update_functions = {} +function MonsterClass:on_update(callback) + update_functions[self] = callback +end + +local stroll_timer = {} +local angerlist = {} + +local mob_config = require "scripts/monster/settings" + +local function find_target(mob, config) + local target + local target_priority + local attack_x, attack_y + + for _, being in ipairs(get_beings_in_circle(mob, config.trackrange)) do + if being:type() == OBJECT_CHARACTER + and being:action() ~= ACTION_DEAD + then + local anger = angerlist[being] or 0 + if anger == 0 and config.aggressive then + anger = 1 + end + + local possible_attack_positions = { + { + x = being:x() - config.attack_distance or TILESIZE, + y = being:y() + }, + { + + x = being:x() + y = being:y() - config.attack_distance or TILESIZE, + }, + { + + x = being:x() + config.attack_distance or TILESIZE, + y = being:y(), + }, + { + + x = being:x() + y = being:y() + config.attack_distance or TILESIZE, + }, + } + for _, point in ipairs(possible_attack_positions) do + local priority = calculate_position_priority(mob:position(), point.x, point.y) + end + + + + end + end +end + +local function stroll_update(mob, tick) + local stroll_tick = stroll_timer[mob] + local mobconfig = mob_config[mob:name()] + + + local trackrange = mobconfig and mobconfig.trackrange or nil + + + local strollrange = mobconfig and mobconfig.strollrange or nil + if (not stroll_tick or stroll_tick <= tick) and strollrange then + local x, y = mob:position() + local destination_x = math.random(x - strollrange, x + strollrange) + local destination_y = math.random(y - strollrange, y + strollrange) + if is_walkable(destination_x, destination_y) then + mob:walk(destination_x, destination_y) + end + stroll_timer[mob] = tick + STROLL_TIMEOUT + + math.random(STROLL_TIMEOUT_RANDOMNESS) + end + + local monsterclass = get_monster_class(mob:monster_id()) + local update_function = update_functions[monsterclass] + if update_function then + return update_function(mob, tick) + end +end + +-- Register all update functions for strolling +for _, monsterclass in ipairs(get_monster_classes()) do + old_on_update(monsterclass, stroll_update) +end |