From 30e5c418bad7b3ea1f0927248d4a6cb98476b21f Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Sat, 9 Aug 2014 01:26:14 +0300 Subject: [PATCH] Eluna fix doc style and prepare merge a PR --- AuraMethods.h | 60 +++++++++++++------------- GlobalMethods.h | 4 +- HookMgr.cpp | 100 ++++++++++++++++++++++--------------------- LuaFunctions.cpp | 3 +- UnitMethods.h | 65 ++++++++++++++++++++++------ WorldObjectMethods.h | 20 +++++++++ 6 files changed, 158 insertions(+), 94 deletions(-) diff --git a/AuraMethods.h b/AuraMethods.h index 356b5e0..a183e93 100644 --- a/AuraMethods.h +++ b/AuraMethods.h @@ -10,9 +10,9 @@ namespace LuaAura { /** - * Returns the `Unit` that casted the `Spell` that caused this Aura to be applied. + * Returns the &Unit that casted the &Spell that caused this &Aura to be applied. * - * @return :Unit the `Unit` that casted this Aura + * @return &Unit : the &Unit that casted this &Aura */ int GetCaster(lua_State* L, Aura* aura) { @@ -21,9 +21,9 @@ namespace LuaAura } /** - * Returns the GUID of the `Unit` that casted the `Spell` that caused this Aura to be applied. + * Returns the GUID of the &Unit that casted the &Spell that caused this &Aura to be applied. * - * @return :string the GUID of the `Unit` as a decimal string + * @return uint64 : the GUID of the &Unit as a string */ int GetCasterGUID(lua_State* L, Aura* aura) { @@ -36,9 +36,9 @@ namespace LuaAura } /** - * Returns the level of the `Unit` that casted the `Spell` that caused this Aura to be applied. + * Returns the level of the &Unit that casted the &Spell that caused this &Aura to be applied. * - * @return :number the level of the `Unit` + * @return uint8 : the level of the &Unit */ int GetCasterLevel(lua_State* L, Aura* aura) { @@ -47,9 +47,9 @@ namespace LuaAura } /** - * Returns the amount of time left until the Aura expires. + * Returns the amount of time left until the &Aura expires. * - * @return :number amount of time left in milliseconds + * @return int32 : amount of time left in milliseconds */ int GetDuration(lua_State* L, Aura* aura) { @@ -62,9 +62,9 @@ namespace LuaAura } /** - * Returns the ID of the `Spell` that caused this Aura to be applied. + * Returns the ID of the &Spell that caused this &Aura to be applied. * - * @return :number the `Spell` ID + * @return uint32 : the spellid */ int GetAuraId(lua_State* L, Aura* aura) { @@ -73,12 +73,12 @@ namespace LuaAura } /** - * Returns the amount of time this Aura lasts when applied. + * Returns the amount of time this &Aura lasts when applied. * - * To determine how much time has passed since this Aura was applied, + * To determine how much time has passed since this &Aura was applied, * subtract the result of `GetDuration` from the result of this method. * - * @return :number the maximum duration of the Aura, in milliseconds + * @return int32 : the maximum duration of the &Aura, in milliseconds */ int GetMaxDuration(lua_State* L, Aura* aura) { @@ -91,11 +91,11 @@ namespace LuaAura } /** - * Returns the number of times the Aura has "stacked". + * Returns the number of times the &Aura has "stacked". * - * This is the same as the number displayed on the Aura's icon in-game. + * This is the same as the number displayed on the &Aura's icon in-game. * - * @return :number how many times the Aura has stacked + * @return uint8 : how many times the &Aura has stacked */ int GetStackAmount(lua_State* L, Aura* aura) { @@ -104,9 +104,9 @@ namespace LuaAura } /** - * Returns the `Unit` that the Aura has been applied to. + * Returns the &Unit that the &Aura has been applied to. * - * @return :Unit who the Aura has been applied to + * @return &Unit : &Unit who the &Aura has been applied to */ int GetOwner(lua_State* L, Aura* aura) { @@ -119,13 +119,13 @@ namespace LuaAura } /** - * Change the amount of time before the Aura expires. + * Change the amount of time before the &Aura expires. * - * @param duration :number the new duration of the Aura, in milliseconds + * @param int32 duration : the new duration of the &Aura, in milliseconds */ int SetDuration(lua_State* L, Aura* aura) { - int duration = Eluna::CHECKVAL(L, 2); + int32 duration = Eluna::CHECKVAL(L, 2); #ifndef TRINITY aura->GetHolder()->SetAuraDuration(duration); #else @@ -135,16 +135,16 @@ namespace LuaAura } /** - * Change the maximum amount of time before the Aura expires. + * Change the maximum amount of time before the &Aura expires. * - * This does not affect the current duration of the Aura, but if the Aura + * This does not affect the current duration of the &Aura, but if the &Aura * is reset to the maximum duration, it will instead change to `duration`. * - * @param duration :number the new maximum duration of the Aura, in milliseconds + * @param int32 duration : the new maximum duration of the &Aura, in milliseconds */ int SetMaxDuration(lua_State* L, Aura* aura) { - int duration = Eluna::CHECKVAL(L, 2); + int32 duration = Eluna::CHECKVAL(L, 2); #ifndef TRINITY aura->GetHolder()->SetAuraMaxDuration(duration); #else @@ -154,16 +154,16 @@ namespace LuaAura } /** - * Change the amount of times the Aura has "stacked" on the `Unit`. + * Change the amount of times the &Aura has "stacked" on the &Unit. * * If `amount` is greater than or equal to the current number of stacks, - * then the Aura has its duration reset to the maximum duration. + * then the &Aura has its duration reset to the maximum duration. * - * @param amount :number the new stack amount for the Aura + * @param uint8 amount : the new stack amount for the &Aura */ int SetStackAmount(lua_State* L, Aura* aura) { - int amount = Eluna::CHECKVAL(L, 2); + uint8 amount = Eluna::CHECKVAL(L, 2); #ifndef TRINITY aura->GetHolder()->SetStackAmount(amount); #else @@ -173,7 +173,7 @@ namespace LuaAura } /** - * Remove this Aura from the `Unit` it is applied to. + * Remove this &Aura from the &Unit it is applied to. */ int Remove(lua_State* /*L*/, Aura* aura) { diff --git a/GlobalMethods.h b/GlobalMethods.h index ffebcfa..2ca04ff 100644 --- a/GlobalMethods.h +++ b/GlobalMethods.h @@ -950,8 +950,8 @@ namespace LuaGlobalFunctions int banMode = Eluna::CHECKVAL(L, 1); std::string nameOrIP = Eluna::CHECKVAL(L, 2); uint32 duration = Eluna::CHECKVAL(L, 3); - const char* reason = Eluna::CHECKVAL(L, 4); - const char* whoBanned = Eluna::CHECKOBJ(L, 5); + const char* reason = Eluna::CHECKVAL(L, 4, ""); + const char* whoBanned = Eluna::CHECKVAL(L, 5, ""); switch (banMode) { diff --git a/HookMgr.cpp b/HookMgr.cpp index 6360b6a..a4df953 100644 --- a/HookMgr.cpp +++ b/HookMgr.cpp @@ -190,9 +190,10 @@ void Eluna::OnPacketSendAny(Player* player, WorldPacket& packet, bool& result) { if (lua_isnoneornil(L, i)) continue; - if (WorldPacket* data = CHECKOBJ(L, i, false)) - packet = *data; - if (!CHECKVAL(L, i, true)) + if (lua_isuserdata(L, i)) + if (WorldPacket* data = CHECKOBJ(L, i, false)) + packet = *data; + if (lua_isboolean(L, i) && !CHECKVAL(L, i, true)) { result = false; break; @@ -210,9 +211,10 @@ void Eluna::OnPacketSendOne(Player* player, WorldPacket& packet, bool& result) { if (lua_isnoneornil(L, i)) continue; - if (WorldPacket* data = CHECKOBJ(L, i, false)) - packet = *data; - if (!CHECKVAL(L, i, true)) + if (lua_isuserdata(L, i)) + if (WorldPacket* data = CHECKOBJ(L, i, false)) + packet = *data; + if (lua_isboolean(L, i) && !CHECKVAL(L, i, true)) { result = false; break; @@ -241,9 +243,10 @@ void Eluna::OnPacketReceiveAny(Player* player, WorldPacket& packet, bool& result { if (lua_isnoneornil(L, i)) continue; - if (WorldPacket* data = CHECKOBJ(L, i, false)) - packet = *data; - if (!CHECKVAL(L, i, true)) + if (lua_isuserdata(L, i)) + if (WorldPacket* data = CHECKOBJ(L, i, false)) + packet = *data; + if (lua_isboolean(L, i) && !CHECKVAL(L, i, true)) { result = false; break; @@ -261,9 +264,10 @@ void Eluna::OnPacketReceiveOne(Player* player, WorldPacket& packet, bool& result { if (lua_isnoneornil(L, i)) continue; - if (WorldPacket* data = CHECKOBJ(L, i, false)) - packet = *data; - if (!CHECKVAL(L, i, true)) + if (lua_isuserdata(L, i)) + if (WorldPacket* data = CHECKOBJ(L, i, false)) + packet = *data; + if (lua_isboolean(L, i) && !CHECKVAL(L, i, true)) { result = false; break; @@ -477,9 +481,8 @@ bool Eluna::OnItemUse(Player* pPlayer, Item* pItem, SpellCastTargets const& targ ENTRY_EXECUTE(1); FOR_RETS(i) { - if (lua_isnoneornil(L, i)) - continue; - result = CHECKVAL(L, i, result); + if (lua_isboolean(L, i)) + result = CHECKVAL(L, i, result); } ENDCALL(); return result; @@ -495,9 +498,8 @@ bool Eluna::OnItemGossip(Player* pPlayer, Item* pItem, SpellCastTargets const& / ENTRY_EXECUTE(1); FOR_RETS(i) { - if (lua_isnoneornil(L, i)) - continue; - result = CHECKVAL(L, i, result); + if (lua_isboolean(L, i)) + result = CHECKVAL(L, i, result); } ENDCALL(); return result; @@ -556,9 +558,8 @@ bool Eluna::OnCommand(Player* player, const char* text) EVENT_EXECUTE(1); FOR_RETS(i) { - if (lua_isnoneornil(L, i)) - continue; - result = CHECKVAL(L, i, result); + if (lua_isboolean(L, i)) + result = CHECKVAL(L, i, result); } ENDCALL(); return result; @@ -637,7 +638,7 @@ InventoryResult Eluna::OnCanUseItem(const Player* pPlayer, uint32 itemEntry) EVENT_EXECUTE(1); FOR_RETS(i) { - if (lua_isnoneornil(L, i)) + if (!lua_isnumber(L, i)) continue; uint32 res = CHECKVAL(L, i, EQUIP_ERR_OK); if (res != EQUIP_ERR_OK) @@ -735,9 +736,8 @@ void Eluna::OnGiveXP(Player* pPlayer, uint32& amount, Unit* pVictim) EVENT_EXECUTE(1); FOR_RETS(i) { - if (lua_isnoneornil(L, i)) - continue; - amount = CHECKVAL(L, i, amount); + if (lua_isnumber(L, i)) + amount = CHECKVAL(L, i, amount); } ENDCALL(); } @@ -752,9 +752,8 @@ void Eluna::OnReputationChange(Player* pPlayer, uint32 factionID, int32& standin EVENT_EXECUTE(1); FOR_RETS(i) { - if (lua_isnoneornil(L, i)) - continue; - standing = CHECKVAL(L, i, standing); + if (lua_isnumber(L, i)) + standing = CHECKVAL(L, i, standing); } ENDCALL(); } @@ -901,9 +900,10 @@ bool Eluna::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg) { if (lua_isnoneornil(L, i)) continue; - if (const char* c_str = CHECKVAL(L, i, NULL)) - msg = std::string(c_str); - else if (!CHECKVAL(L, i, true)) + if (lua_isstring(L, i)) + if (const char* c_str = CHECKVAL(L, i, NULL)) + msg = std::string(c_str); + else if (lua_isboolean(L, i) && !CHECKVAL(L, i, true)) { result = false; break; @@ -929,9 +929,10 @@ bool Eluna::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, { if (lua_isnoneornil(L, i)) continue; - if (const char* c_str = CHECKVAL(L, i, NULL)) - msg = std::string(c_str); - else if (!CHECKVAL(L, i, true)) + if (lua_isstring(L, i)) + if (const char* c_str = CHECKVAL(L, i, NULL)) + msg = std::string(c_str); + else if (lua_isboolean(L, i) && !CHECKVAL(L, i, true)) { result = false; break; @@ -957,9 +958,10 @@ bool Eluna::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, { if (lua_isnoneornil(L, i)) continue; - if (const char* c_str = CHECKVAL(L, i, NULL)) - msg = std::string(c_str); - else if (!CHECKVAL(L, i, true)) + if (lua_isstring(L, i)) + if (const char* c_str = CHECKVAL(L, i, NULL)) + msg = std::string(c_str); + else if (lua_isboolean(L, i) && !CHECKVAL(L, i, true)) { result = false; break; @@ -985,9 +987,10 @@ bool Eluna::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, { if (lua_isnoneornil(L, i)) continue; - if (const char* c_str = CHECKVAL(L, i, NULL)) - msg = std::string(c_str); - else if (!CHECKVAL(L, i, true)) + if (lua_isstring(L, i)) + if (const char* c_str = CHECKVAL(L, i, NULL)) + msg = std::string(c_str); + else if (lua_isboolean(L, i) && !CHECKVAL(L, i, true)) { result = false; break; @@ -1013,9 +1016,10 @@ bool Eluna::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, { if (lua_isnoneornil(L, i)) continue; - if (const char* c_str = CHECKVAL(L, i, NULL)) - msg = std::string(c_str); - else if (!CHECKVAL(L, i, true)) + if (lua_isstring(L, i)) + if (const char* c_str = CHECKVAL(L, i, NULL)) + msg = std::string(c_str); + else if (lua_isboolean(L, i) && !CHECKVAL(L, i, true)) { result = false; break; @@ -1479,9 +1483,8 @@ struct ElunaCreatureAI : ScriptedAI ENTRY_EXECUTE(1); FOR_RETS(i) { - if (lua_isnoneornil(L, i)) - continue; - damage = Eluna::CHECKVAL(L, i, damage); + if (lua_isnumber(L, i)) + damage = Eluna::CHECKVAL(L, i, damage); } ENDCALL(); } @@ -1619,9 +1622,8 @@ struct ElunaCreatureAI : ScriptedAI ENTRY_EXECUTE(1); FOR_RETS(i) { - if (lua_isnoneornil(L, i)) - continue; - respawnDelay = Eluna::CHECKVAL(L, i, respawnDelay); + if (lua_isnumber(L, i)) + respawnDelay = Eluna::CHECKVAL(L, i, respawnDelay); } ENDCALL(); } diff --git a/LuaFunctions.cpp b/LuaFunctions.cpp index 6f9997a..6674d44 100644 --- a/LuaFunctions.cpp +++ b/LuaFunctions.cpp @@ -102,7 +102,7 @@ void RegisterGlobals(lua_State* L) lua_register(L, "VendorRemoveItem", &LuaGlobalFunctions::VendorRemoveItem); // VendorRemoveItem(entry, item) - Removes an item from vendor entry lua_register(L, "VendorRemoveAllItems", &LuaGlobalFunctions::VendorRemoveAllItems); // VendorRemoveAllItems(entry) - Removes all items from vendor entry lua_register(L, "Kick", &LuaGlobalFunctions::Kick); // Kick(player) - Kicks given player - lua_register(L, "Ban", &LuaGlobalFunctions::Ban); // Ban(banMode(integer), nameOrIP(string), duration(string), reason(string), whoBanned(string)) - Banmode: 0 account, 1 character, 2 IP + lua_register(L, "Ban", &LuaGlobalFunctions::Ban); // Ban(banMode(integer), nameOrIP(string), duration(string), [reason(string), whoBanned(string)]) - Banmode: 0 account, 1 character, 2 IP lua_register(L, "SaveAllPlayers", &LuaGlobalFunctions::SaveAllPlayers); // SaveAllPlayers() - Saves all players lua_register(L, "SendMail", &LuaGlobalFunctions::SendMail); // SendMail(subject, text, receiverLowGUID[, senderLowGUID, stationary, delay, itemEntry, itemAmount, itemEntry2, itemAmount2...]) - Sends a mail to player with lowguid. use nil to use default values on optional arguments. UNDOCUMENTED lua_register(L, "AddTaxiPath", &LuaGlobalFunctions::AddTaxiPath); // AddTaxiPath(pathTable, mountA, mountH[, price, pathId]) - Adds a new taxi path. Returns the path's ID. Will replace an existing path if pathId provided and already used. mountIDs are NPC entries. path table structure: T = {{map, x, y, z[, actionFlag, delay, arrivalEvId, departEvId]}, {...}, ...} @@ -381,6 +381,7 @@ ElunaRegister UnitMethods[] = { "MoveClear", &LuaUnit::MoveClear }, // :MoveClear([reset]) { "DealDamage", &LuaUnit::DealDamage }, // :DealDamage(target, amount[, durabilityloss]) - Deals damage to target, durabilityloss is true by default { "DealHeal", &LuaUnit::DealHeal }, // :DealDamage(target, amount, spell[, critical]) - Heals target by given amount. This will be logged as being healed by spell as critical if true. + { "AddThreat", &LuaUnit::AddThreat }, { NULL, NULL }, }; diff --git a/UnitMethods.h b/UnitMethods.h index 6a84495..618f653 100644 --- a/UnitMethods.h +++ b/UnitMethods.h @@ -1361,18 +1361,17 @@ namespace LuaUnit } /** - Casts the spell at target. - pb0, 1 and 2 are modifiers for the base points of the spell. - - @param &Unit target - @param uint32 spell - @param bool triggered = false - @param int32 bp0 = nil - @param int32 bp1 = nil - @param int32 bp2 = nil - @param &Item castItem = nil - @param uint64 originalCaster = 0 - */ + * Casts the spell at target with modified basepoints or casters. + * + * @param &Unit target + * @param uint32 spell + * @param bool triggered = false + * @param int32 bp0 = nil : modifier for the base points of the spell. + * @param int32 bp1 = nil : modifier for the base points of the spell. + * @param int32 bp2 = nil : modifier for the base points of the spell. + * @param &Item castItem = nil + * @param uint64 originalCaster = 0 + */ int CastCustomSpell(lua_State* L, Unit* unit) { Unit* target = Eluna::CHECKOBJ(L, 2); @@ -1618,6 +1617,48 @@ namespace LuaUnit return 0; } + /** + * Adds threat to the &Unit from the victim. + * + *
+     * enum SpellSchoolMask
+     * {
+     *     SPELL_SCHOOL_MASK_NONE    = 0,
+     *     SPELL_SCHOOL_MASK_NORMAL  = 1,
+     *     SPELL_SCHOOL_MASK_HOLY    = 2,
+     *     SPELL_SCHOOL_MASK_FIRE    = 4,
+     *     SPELL_SCHOOL_MASK_NATURE  = 8,
+     *     SPELL_SCHOOL_MASK_FROST   = 16,
+     *     SPELL_SCHOOL_MASK_SHADOW  = 32,
+     *     SPELL_SCHOOL_MASK_ARCANE  = 64,
+     * }
+     * 
+ * + * @param &Unit victim : &Unit that caused the threat + * @param float threat : threat amount + * @param uint32 SpellSchoolMask = 0 : school mask of the threat causer + * @param uint32 spell = 0 : spell entry used for threat + */ + int AddThreat(lua_State* L, Unit* unit) + { + Unit* victim = Eluna::CHECKOBJ(L, 2); + float threat = Eluna::CHECKVAL(L, 3, true); + uint32 schoolMask = Eluna::CHECKVAL(L, 3, 0); + uint32 spell = Eluna::CHECKVAL(L, 3, 0); + + if (schoolMask > SPELL_SCHOOL_MASK_ALL) + { + return luaL_argerror(L, 3, "valid SpellSchoolMask expected"); + } + +#ifdef TRINITY + unit->AddThreat(victim, threat, (SpellSchoolMask)schoolMask, spell ? sSpellMgr->GetSpellInfo(spell) : NULL); +#else + unit->AddThreat(victim, threat, false, (SpellSchoolMask)schoolMask, spell ? sSpellStore.LookupEntry(spell) : NULL); +#endif + return 0; + } + /*int RestoreDisplayId(lua_State* L, Unit* unit) { unit->RestoreDisplayId(); diff --git a/WorldObjectMethods.h b/WorldObjectMethods.h index b7dad84..402c46e 100644 --- a/WorldObjectMethods.h +++ b/WorldObjectMethods.h @@ -78,6 +78,14 @@ namespace LuaWorldObject return 1; } + /** + * Returns the coordinates and orientation of the &WorldObject + * + * @return float x + * @return float y + * @return float z + * @return float o + */ int GetLocation(lua_State* L, WorldObject* obj) { Eluna::Push(L, obj->GetPositionX()); @@ -386,6 +394,18 @@ namespace LuaWorldObject return 1; } + /** + * Spawns the creature at specified location. + * + * @param uint32 entry : creature entry + * @param float x + * @param float y + * @param float z + * @param float o + * @param TempSummonType spawnType : defines how and when the creature despawns + * @param uint32 despawnTimer : despawn time in seconds + * @return &Creature + */ int SpawnCreature(lua_State* L, WorldObject* obj) { uint32 entry = Eluna::CHECKVAL(L, 2);