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 /src/scripting | |
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 'src/scripting')
-rw-r--r-- | src/scripting/lua.cpp | 55 |
1 files changed, 45 insertions, 10 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 87568087..0c27788c 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -2241,18 +2241,18 @@ static int entity_show_text_particle(lua_State *s) /** LUA entity:give_ability (being) * entity:give_ability(int ability) ** - * Valid only for character entities. + * Valid only for character and monster entities. * * Enables a ability for a character. */ static int entity_give_ability(lua_State *s) { // cost_type is ignored until we have more than one cost type - Entity *c = checkCharacter(s, 1); + Entity *b = checkBeing(s, 1); auto *abilityInfo = checkAbility(s, 2); const int currentMana = luaL_optint(s, 3, 0); - c->getComponent<AbilityComponent>()->giveAbility(abilityInfo->id, + b->getComponent<AbilityComponent>()->giveAbility(abilityInfo->id, currentMana); return 0; } @@ -2260,40 +2260,74 @@ static int entity_give_ability(lua_State *s) /** LUA entity:has_ability (being) * entity:has_ability(int ability) ** - * Valid only for character entities. + * Valid only for character and monster entities. * * **Return value:** True if the character has the ability, false otherwise. */ static int entity_has_ability(lua_State *s) { - Entity *c = checkCharacter(s, 1); + Entity *b = checkBeing(s, 1); const int ability = luaL_checkint(s, 2); - lua_pushboolean(s, c->getComponent<AbilityComponent>()->hasAbility(ability)); + lua_pushboolean(s, b->getComponent<AbilityComponent>()->hasAbility(ability)); return 1; } /** LUA entity:take_ability (being) * entity:take_ability(int ability) ** - * Valid only for character entities. + * Valid only for character and monster entities. * - * Removes a ability from a character. + * Removes a ability from a entity. * * **Return value:** True if removal was successful, false otherwise (in case * the character did not have the ability). */ static int entity_take_ability(lua_State *s) { - Entity *c = checkCharacter(s, 1); + Entity *b = checkBeing(s, 1); const int ability = luaL_checkint(s, 2); - auto *abilityComponent = c->getComponent<AbilityComponent>(); + auto *abilityComponent = b->getComponent<AbilityComponent>(); lua_pushboolean(s, abilityComponent->hasAbility(ability)); abilityComponent->takeAbility(ability); return 1; } +/** LUA entity:use_ability (being) + * entity:use_ability(int ability) + ** + * Valid only for character and monster entities. + * + * Makes the entity using the given ability if it is available and recharged. + * + * **Return value:** True if the ability was used successfully. False otherwise + * (if the ability is not available for the entity or was not recharged). + */ +static int entity_use_ability(lua_State *s) +{ + Entity *b = checkBeing(s, 1); + const int ability = luaL_checkint(s, 2); + bool targetIsBeing = lua_gettop(s) == 3; + + auto *abilityComponent = b->getComponent<AbilityComponent>(); + if (targetIsBeing) + { + Entity *target = checkBeing(s, 3); + lua_pushboolean(s, abilityComponent->useAbilityOnBeing(*b, ability, + target)); + } + else + { + const int x = luaL_checkint(s, 3); + const int y = luaL_checkint(s, 4); + lua_pushboolean(s, abilityComponent->useAbilityOnPoint(*b, ability, + x, y)); + } + + return 1; +} + /** LUA_CATEGORY Monster (monster) */ @@ -3332,6 +3366,7 @@ LuaScript::LuaScript(): { "give_ability", entity_give_ability }, { "has_ability", entity_has_ability }, { "take_ability", entity_take_ability }, + { "use_ability", entity_use_ability }, { "monster_id", entity_get_monster_id }, { "apply_status", entity_apply_status }, { "remove_status", entity_remove_status }, |