diff --git a/GlobalMethods.h b/GlobalMethods.h index 8812f96..912c37e 100644 --- a/GlobalMethods.h +++ b/GlobalMethods.h @@ -2051,76 +2051,6 @@ namespace LuaGlobalFunctions return 0; } - /** - * Gets the [Weather] for a zone. - * - * @param uint32 zoneId : zone Id to check for [Weather] - * @return [Weather] weather - */ - int FindWeather(Eluna* /*E*/, lua_State* L) - { - uint32 zoneId = Eluna::CHECKVAL(L, 1); -#ifndef TRINITY - Weather* weather = eWorld->FindWeather(zoneId); -#else - Weather* weather = WeatherMgr::FindWeather(zoneId); -#endif - Eluna::Push(L, weather); - return 1; - } - - /** - * Adds weather to a zone and returns the new [Weather] object. - * - * @param uint32 zoneId : zone Id to add [Weather] - * @return [Weather] weather - */ - int AddWeather(Eluna* /*E*/, lua_State* L) - { - uint32 zoneId = Eluna::CHECKVAL(L, 1); -#ifndef TRINITY - Weather* weather = eWorld->AddWeather(zoneId); -#else - Weather* weather = WeatherMgr::AddWeather(zoneId); -#endif - Eluna::Push(L, weather); - return 1; - } - - /** - * Removes [Weather] from a zone. - * - * @param uint32 zoneId : zone Id to remove [Weather] - */ - int RemoveWeather(Eluna* /*E*/, lua_State* L) - { - uint32 zoneId = Eluna::CHECKVAL(L, 1); -#ifndef TRINITY - eWorld->RemoveWeather(zoneId); -#else - WeatherMgr::RemoveWeather(zoneId); -#endif - return 0; - } - - /** - * Sends a clear weather packet to a [Player]. - * - * Does not affect other [Player]s in the same zone, or affect the zone. - * - * @param [Player] player : [Player] to send the normal weather to - */ - int SendFineWeatherToPlayer(Eluna* /*E*/, lua_State* L) - { - Player* player = Eluna::CHECKOBJ(L, 1); -#ifndef TRINITY - Weather::SendFineWeatherUpdateToPlayer(player); -#else - WeatherMgr::SendFineWeatherUpdateToPlayer(player); -#endif - return 0; - } - /** * Returns `true` if the bag and slot is a valid inventory position, otherwise `false`. * diff --git a/HookMgr.cpp b/HookMgr.cpp index ad727cb..6941726 100644 --- a/HookMgr.cpp +++ b/HookMgr.cpp @@ -273,13 +273,13 @@ bool Eluna::OnAreaTrigger(Player* pPlayer, AreaTriggerEntry const* pTrigger) return CallAllFunctionsBool(ServerEventBindings, TRIGGER_EVENT_ON_TRIGGER); } // weather -void Eluna::OnChange(Weather* weather, WeatherState state, float grade) +void Eluna::OnChange(Weather* weather, uint32 zone, WeatherState state, float grade) { if (!ServerEventBindings->HasEvents(WEATHER_EVENT_ON_CHANGE)) return; LOCK_ELUNA; - Push(weather->GetZone()); + Push(zone); Push(state); Push(grade); CallAllFunctions(ServerEventBindings, WEATHER_EVENT_ON_CHANGE); diff --git a/HookMgr.h b/HookMgr.h index e7e4965..2e2ef9d 100644 --- a/HookMgr.h +++ b/HookMgr.h @@ -76,7 +76,7 @@ namespace HookMgr TRIGGER_EVENT_ON_TRIGGER = 24, // (event, player, triggerId) - Can return true // Weather - WEATHER_EVENT_ON_CHANGE = 25, // (event, weather, state, grade) + WEATHER_EVENT_ON_CHANGE = 25, // (event, zoneId, state, grade) // Auction house AUCTION_EVENT_ON_ADD = 26, // (event, AHObject) diff --git a/LuaEngine.h b/LuaEngine.h index 2b3ef7f..1b24eb7 100644 --- a/LuaEngine.h +++ b/LuaEngine.h @@ -396,7 +396,7 @@ public: bool OnAreaTrigger(Player* pPlayer, AreaTriggerEntry const* pTrigger); /* Weather */ - void OnChange(Weather* weather, WeatherState state, float grade); + void OnChange(Weather* weather, uint32 zone, WeatherState state, float grade); /* Auction House */ void OnAdd(AuctionHouseObject* auctionHouse); diff --git a/LuaFunctions.cpp b/LuaFunctions.cpp index 9278262..1c2db24 100644 --- a/LuaFunctions.cpp +++ b/LuaFunctions.cpp @@ -34,7 +34,6 @@ extern "C" #include "QuestMethods.h" #include "MapMethods.h" #include "CorpseMethods.h" -#include "WeatherMethods.h" #include "VehicleMethods.h" #include "BattleGroundMethods.h" @@ -137,10 +136,6 @@ ElunaGlobal::ElunaRegister GlobalMethods[] = { "RemoveCorpse", &LuaGlobalFunctions::RemoveCorpse }, { "ConvertCorpseForPlayer", &LuaGlobalFunctions::ConvertCorpseForPlayer }, { "RemoveOldCorpses", &LuaGlobalFunctions::RemoveOldCorpses }, - { "FindWeather", &LuaGlobalFunctions::FindWeather }, - { "AddWeather", &LuaGlobalFunctions::AddWeather }, - { "RemoveWeather", &LuaGlobalFunctions::RemoveWeather }, - { "SendFineWeatherToPlayer", &LuaGlobalFunctions::SendFineWeatherToPlayer }, { "CreateInt64", &LuaGlobalFunctions::CreateLongLong }, { "CreateUint64", &LuaGlobalFunctions::CreateULongLong }, @@ -1190,6 +1185,9 @@ ElunaRegister MapMethods[] = { "GetHeight", &LuaMap::GetHeight }, // :GetHeight(x, y[, phasemask]) - Returns ground Z coordinate. UNDOCUMENTED { "GetWorldObject", &LuaMap::GetWorldObject }, // :GetWorldObject(guid) - Returns a worldobject (player, creature, gameobject..) from the map by it's guid + // Setters + { "SetWeather", &LuaMap::SetWeather }, + // Booleans #ifndef CLASSIC { "IsArena", &LuaMap::IsArena }, // :IsArena() - Returns the true if the map is an arena, else false UNDOCUMENTED @@ -1217,24 +1215,6 @@ ElunaRegister CorpseMethods[] = { NULL, NULL } }; -ElunaRegister WeatherMethods[] = -{ - // Getters - { "GetZoneId", &LuaWeather::GetZoneId }, - - // Setters - { "SetWeather", &LuaWeather::SetWeather }, - - // Boolean - { "Regenerate", &LuaWeather::Regenerate }, - { "UpdateWeather", &LuaWeather::UpdateWeather }, - - // Other - { "SendWeatherUpdateToPlayer", &LuaWeather::SendWeatherUpdateToPlayer }, - - { NULL, NULL } -}; - ElunaRegister AuctionMethods[] = { { NULL, NULL } @@ -1397,9 +1377,6 @@ void RegisterFunctions(Eluna* E) ElunaTemplate::Register(E, "Map"); ElunaTemplate::SetMethods(E, MapMethods); - ElunaTemplate::Register(E, "Weather"); - ElunaTemplate::SetMethods(E, WeatherMethods); - ElunaTemplate::Register(E, "AuctionHouseObject"); ElunaTemplate::SetMethods(E, AuctionMethods); diff --git a/MapMethods.h b/MapMethods.h index 2f0d48d..b0a1e83 100644 --- a/MapMethods.h +++ b/MapMethods.h @@ -235,5 +235,47 @@ namespace LuaMap #endif return 1; } + + /** + * Sets the [Weather] type based on [WeatherType] and grade supplied. + * + * enum WeatherType + * { + * WEATHER_TYPE_FINE = 0, + * WEATHER_TYPE_RAIN = 1, + * WEATHER_TYPE_SNOW = 2, + * WEATHER_TYPE_STORM = 3, + * WEATHER_TYPE_THUNDERS = 86, + * WEATHER_TYPE_BLACKRAIN = 90 + * }; + * + * @param uint32 zone : id of the zone to set the weather for + * @param [WeatherType] type : the [WeatherType], see above available weather types + * @param float grade : the intensity/grade of the [Weather], ranges from 0 to 1 + */ + int SetWeather(Eluna* /*E*/, lua_State* L, Map* map) + { + uint32 zoneId = Eluna::CHECKVAL(L, 2); + uint32 weatherType = Eluna::CHECKVAL(L, 3); + float grade = Eluna::CHECKVAL(L, 4); + +#if (defined(CMANGOS) && defined(WOTLK)) + if (Weather::IsValidWeatherType(weatherType)) + map->SetWeather(zoneId, (WeatherType)weatherType, grade, false); +#else +#ifdef TRINITY + Weather* weather = WeatherMgr::FindWeather(zoneId); + if (!weather) + weather = WeatherMgr::AddWeather(zoneId); +#else + Weather* weather = eWorld->FindWeather(zoneId); + if (!weather) + weather = eWorld->AddWeather(zoneId); +#endif + if (weather) + weather->SetWeather((WeatherType)weatherType, grade); +#endif + return 0; + } }; #endif diff --git a/WeatherMethods.h b/WeatherMethods.h deleted file mode 100644 index f6aedb4..0000000 --- a/WeatherMethods.h +++ /dev/null @@ -1,91 +0,0 @@ -/* -* Copyright (C) 2010 - 2015 Eluna Lua Engine -* This program is free software licensed under GPL version 3 -* Please see the included DOCS/LICENSE.md for more information -*/ - -#ifndef WEATHERMETHODS_H -#define WEATHERMETHODS_H - -namespace LuaWeather -{ - /** - * Returns the zone id of the [Weather] - * - * @return uint32 zoneId - */ - int GetZoneId(Eluna* /*E*/, lua_State* L, Weather* weather) - { - Eluna::Push(L, weather->GetZone()); - return 1; - } - - /** - * Sets the [Weather] type based on [WeatherType] and grade supplied. - * - *
-     * enum WeatherType
-     * {
-     *     WEATHER_TYPE_FINE       = 0,
-     *     WEATHER_TYPE_RAIN       = 1,
-     *     WEATHER_TYPE_SNOW       = 2,
-     *     WEATHER_TYPE_STORM      = 3,
-     *     WEATHER_TYPE_THUNDERS   = 86,
-     *     WEATHER_TYPE_BLACKRAIN  = 90
-     * };
-     * 
- * - * @param WeatherType type : the [WeatherType], see above available weather types - * @param float grade : the intensity/grade of the [Weather], ranges from 0 to 1 - */ - int SetWeather(Eluna* /*E*/, lua_State* L, Weather* weather) - { - uint32 weatherType = Eluna::CHECKVAL(L, 2); - float grade = Eluna::CHECKVAL(L, 3); - - weather->SetWeather((WeatherType)weatherType, grade); - return 0; - } - - /** - * Sends a [Weather] update to the [Player] supplied. - * - * @param [Player] player - */ - int SendWeatherUpdateToPlayer(Eluna* /*E*/, lua_State* L, Weather* weather) - { - Player* player = Eluna::CHECKOBJ(L, 2); - - weather->SendWeatherUpdateToPlayer(player); - return 0; - } - - /** - * Regenerates the [Weather], causing it to change based on the below statistics. - * - * * 30% chance of no change - * * 30% chance of [Weather] getting better (if not fine) or changing [Weather] type - * * 30% chance of [Weather] getting worse (if not fine) - * * 10% chance of radical change (if not fine) - * - * @return bool changed : returns 'true' if [Weather] changed - */ - int Regenerate(Eluna* /*E*/, lua_State* L, Weather* weather) - { - Eluna::Push(L, weather->ReGenerate()); - return 1; - } - - /** - * Sends a [Weather] update to the all [Player] in the zone. - * - * @param bool changed : returns 'true' if weather changed for any [Player] in the zone, 'false' if no [Player] is within the zone - */ - int UpdateWeather(Eluna* /*E*/, lua_State* L, Weather* weather) - { - Eluna::Push(L, weather->UpdateWeather()); - return 1; - } -}; - -#endif