Enable null as CastSpell target and Add IsCasting

Closes https://github.com/ElunaLuaEngine/Eluna/issues/160
This commit is contained in:
Rochet2
2015-08-10 01:11:01 +03:00
parent 1bc22faa7f
commit b9bc5343b4
2 changed files with 23 additions and 7 deletions

View File

@@ -366,6 +366,7 @@ ElunaRegister<Unit> UnitMethods[] =
{ "IsRooted", &LuaUnit::IsRooted }, // :IsRooted()
{ "IsFullHealth", &LuaUnit::IsFullHealth }, // :IsFullHealth() - Returns if the unit is full health
{ "HasAura", &LuaUnit::HasAura }, // :HasAura(spellId) - Returns true if the unit has the aura from the spell
{ "IsCasting", &LuaUnit::IsCasting },
{ "IsStandState", &LuaUnit::IsStandState }, // :IsStandState() - Returns true if the unit is standing
#ifndef CLASSIC
{ "IsOnVehicle", &LuaUnit::IsOnVehicle }, // :IsOnVehicle() - Checks if the unit is on a vehicle

View File

@@ -539,7 +539,22 @@ namespace LuaUnit
Eluna::Push(L, unit->HasAura(spell));
return 1;
}
/**
* Returns true if the [Unit] is casting a spell
*
* @return bool isCasting
*/
int IsCasting(Eluna* /*E*/, lua_State* L, Unit* unit)
{
#ifndef TRINITY
Eluna::Push(L, unit->hasUnitState(UNIT_STATE_CASTING));
#else
Eluna::Push(L, unit->HasUnitState(UNIT_STATE_CASTING));
#endif
return 1;
}
/**
* Returns true if the [Unit] has the given unit state.
*
@@ -2072,7 +2087,7 @@ namespace LuaUnit
#endif
return 0;
}
/**
* Unmorphs the [Unit] setting it's display ID back to the native display ID.
*/
@@ -2081,17 +2096,17 @@ namespace LuaUnit
unit->DeMorph();
return 0;
}
/**
* Makes the [Unit] cast the spell on the target.
*
* @param [Unit] target : can be self or another unit
* @param [Unit] target = nil : can be self or another unit
* @param uint32 spell : entry of a spell
* @param bool triggered = false : if true the spell is instant and has no cost
*/
int CastSpell(Eluna* /*E*/, lua_State* L, Unit* unit)
{
Unit* target = Eluna::CHECKOBJ<Unit>(L, 2);
Unit* target = Eluna::CHECKOBJ<Unit>(L, 2, NULL);
uint32 spell = Eluna::CHECKVAL<uint32>(L, 3);
bool triggered = Eluna::CHECKVAL<bool>(L, 4, false);
SpellEntry const* spellEntry = sSpellStore.LookupEntry(spell);
@@ -2106,7 +2121,7 @@ namespace LuaUnit
* Casts the [Spell] at target [Unit] with custom basepoints or casters.
* See also [Unit:CastSpell].
*
* @param [Unit] target
* @param [Unit] target = nil
* @param uint32 spell
* @param bool triggered = false
* @param int32 bp0 = nil : custom basepoints for [Spell] effect 1. If nil, no change is made
@@ -2117,7 +2132,7 @@ namespace LuaUnit
*/
int CastCustomSpell(Eluna* /*E*/, lua_State* L, Unit* unit)
{
Unit* target = Eluna::CHECKOBJ<Unit>(L, 2);
Unit* target = Eluna::CHECKOBJ<Unit>(L, 2, NULL);
uint32 spell = Eluna::CHECKVAL<uint32>(L, 3);
bool triggered = Eluna::CHECKVAL<bool>(L, 4, false);
bool has_bp0 = !lua_isnoneornil(L, 5);