forked from teamnwah/openmw-tes3coop
[Server] Add Weather API
This commit is contained in:
parent
1ef6ad6215
commit
44dc153ebe
5 changed files with 169 additions and 1 deletions
|
@ -86,6 +86,7 @@ void Player::Init(LuaState &lua)
|
||||||
"getFactions", &Player::getFactions,
|
"getFactions", &Player::getFactions,
|
||||||
"getQuests", &Player::getQuests,
|
"getQuests", &Player::getQuests,
|
||||||
"getSpells", &Player::getSpells,
|
"getSpells", &Player::getSpells,
|
||||||
|
"getWeatherMgr", &Player::getWeatherMgr,
|
||||||
|
|
||||||
"getCellState", &Player::getCellState,
|
"getCellState", &Player::getCellState,
|
||||||
"cellStateSize", &Player::cellStateSize,
|
"cellStateSize", &Player::cellStateSize,
|
||||||
|
@ -104,7 +105,7 @@ void Player::Init(LuaState &lua)
|
||||||
|
|
||||||
Player::Player(RakNet::RakNetGUID guid) : BasePlayer(guid), NetActor(), changedMap(false), cClass(this),
|
Player::Player(RakNet::RakNetGUID guid) : BasePlayer(guid), NetActor(), changedMap(false), cClass(this),
|
||||||
settings(this), books(this), gui(this), dialogue(this), factions(this),
|
settings(this), books(this), gui(this), dialogue(this), factions(this),
|
||||||
quests(this), spells(this)
|
quests(this), spells(this), weatherMgr(this)
|
||||||
{
|
{
|
||||||
basePlayer = this;
|
basePlayer = this;
|
||||||
netCreature = this;
|
netCreature = this;
|
||||||
|
@ -228,6 +229,7 @@ void Player::update()
|
||||||
factions.update();
|
factions.update();
|
||||||
quests.update();
|
quests.update();
|
||||||
spells.update();
|
spells.update();
|
||||||
|
weatherMgr.update();
|
||||||
|
|
||||||
resetUpdateFlags();
|
resetUpdateFlags();
|
||||||
}
|
}
|
||||||
|
@ -732,6 +734,11 @@ Spells &Player::getSpells()
|
||||||
return spells;
|
return spells;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WeatherMgr &Player::getWeatherMgr()
|
||||||
|
{
|
||||||
|
return weatherMgr;
|
||||||
|
}
|
||||||
|
|
||||||
std::tuple<float, float, float> Player::getPreviousCellPos() const
|
std::tuple<float, float, float> Player::getPreviousCellPos() const
|
||||||
{
|
{
|
||||||
return make_tuple(previousCellPosition.pos[0], previousCellPosition.pos[1], previousCellPosition.pos[2]);
|
return make_tuple(previousCellPosition.pos[0], previousCellPosition.pos[1], previousCellPosition.pos[2]);
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include "Spells.hpp"
|
#include "Spells.hpp"
|
||||||
#include "NetActor.hpp"
|
#include "NetActor.hpp"
|
||||||
#include "CellState.hpp"
|
#include "CellState.hpp"
|
||||||
|
#include "Weather.hpp"
|
||||||
|
|
||||||
class Player : public mwmp::BasePlayer, public NetActor
|
class Player : public mwmp::BasePlayer, public NetActor
|
||||||
{
|
{
|
||||||
|
@ -183,6 +184,7 @@ public:
|
||||||
Factions &getFactions();
|
Factions &getFactions();
|
||||||
Quests &getQuests();
|
Quests &getQuests();
|
||||||
Spells &getSpells();
|
Spells &getSpells();
|
||||||
|
WeatherMgr &getWeatherMgr();
|
||||||
|
|
||||||
void setAuthority();
|
void setAuthority();
|
||||||
|
|
||||||
|
@ -201,6 +203,7 @@ private:
|
||||||
Factions factions;
|
Factions factions;
|
||||||
Quests quests;
|
Quests quests;
|
||||||
Spells spells;
|
Spells spells;
|
||||||
|
WeatherMgr weatherMgr;
|
||||||
sol::table customData;
|
sol::table customData;
|
||||||
bool markedForDeletion;
|
bool markedForDeletion;
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include "../Quests.hpp"
|
#include "../Quests.hpp"
|
||||||
#include "../Settings.hpp"
|
#include "../Settings.hpp"
|
||||||
#include "../Spells.hpp"
|
#include "../Spells.hpp"
|
||||||
|
#include "../Weather.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -91,6 +92,7 @@ LuaState::LuaState()
|
||||||
Effect::Init(*this);
|
Effect::Init(*this);
|
||||||
Spell::Init(*this);
|
Spell::Init(*this);
|
||||||
Spells::Init(*this);
|
Spells::Init(*this);
|
||||||
|
WeatherMgr::Init(*this);
|
||||||
|
|
||||||
Players::Init(*this);
|
Players::Init(*this);
|
||||||
|
|
||||||
|
|
111
apps/openmw-mp/Weather.cpp
Normal file
111
apps/openmw-mp/Weather.cpp
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
//
|
||||||
|
// Created by koncord on 30.11.17.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "Weather.hpp"
|
||||||
|
#include "Script/LuaState.hpp"
|
||||||
|
#include "Networking.hpp"
|
||||||
|
#include <Player.hpp>
|
||||||
|
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||||
|
#include <components/openmw-mp/Base/BasePlayer.hpp>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace mwmp;
|
||||||
|
|
||||||
|
void WeatherMgr::Init(LuaState &lua)
|
||||||
|
{
|
||||||
|
lua.getState()->new_usertype<WeatherMgr>("WeatherMgr",
|
||||||
|
"current", sol::property(&WeatherMgr::getCurrent, &WeatherMgr::setCurrent),
|
||||||
|
"next", sol::property(&WeatherMgr::getNext, &WeatherMgr::setNext),
|
||||||
|
"transitionFactor", sol::property(&WeatherMgr::getTransition, &WeatherMgr::setTransition),
|
||||||
|
"updateTime", sol::property(&WeatherMgr::getUpdate, &WeatherMgr::setUpdate),
|
||||||
|
"copy", &WeatherMgr::copy,
|
||||||
|
"setWeather", &WeatherMgr::setWeather,
|
||||||
|
"request", &WeatherMgr::requestWeather
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
WeatherMgr::WeatherMgr(Player *player) : player(player), changed(false)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void WeatherMgr::setWeather(int weather)
|
||||||
|
{
|
||||||
|
changed = true;
|
||||||
|
|
||||||
|
player->weather.nextWeather = weather;
|
||||||
|
player->weather.transitionFactor = 0.0f;
|
||||||
|
player->weather.updateTime = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WeatherMgr::update()
|
||||||
|
{
|
||||||
|
if (!changed)
|
||||||
|
return;
|
||||||
|
changed = false;
|
||||||
|
|
||||||
|
auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_WEATHER);
|
||||||
|
|
||||||
|
packet->setPlayer(player);
|
||||||
|
|
||||||
|
packet->Send(/*toOthers*/ false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WeatherMgr::setCurrent(int weather)
|
||||||
|
{
|
||||||
|
player->weather.currentWeather = weather;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int WeatherMgr::getCurrent() const
|
||||||
|
{
|
||||||
|
return player->weather.currentWeather;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WeatherMgr::setNext(int weather)
|
||||||
|
{
|
||||||
|
player->weather.nextWeather = weather;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int WeatherMgr::getNext() const
|
||||||
|
{
|
||||||
|
return player->weather.nextWeather;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WeatherMgr::setTransition(float time)
|
||||||
|
{
|
||||||
|
player->weather.transitionFactor = time;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
float WeatherMgr::getTransition() const
|
||||||
|
{
|
||||||
|
return player->weather.transitionFactor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WeatherMgr::setUpdate(float time)
|
||||||
|
{
|
||||||
|
player->weather.updateTime = time;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
float WeatherMgr::getUpdate() const
|
||||||
|
{
|
||||||
|
return player->weather.updateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WeatherMgr::requestWeather()
|
||||||
|
{
|
||||||
|
auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_WEATHER);
|
||||||
|
packet->RequestData(player->guid);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WeatherMgr::copy(const WeatherMgr &other)
|
||||||
|
{
|
||||||
|
if(other.player == player)
|
||||||
|
return;
|
||||||
|
player->weather = other.player->weather;
|
||||||
|
changed = true;
|
||||||
|
}
|
45
apps/openmw-mp/Weather.hpp
Normal file
45
apps/openmw-mp/Weather.hpp
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
//
|
||||||
|
// Created by koncord on 30.11.17.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <components/openmw-mp/Base/BasePlayer.hpp>
|
||||||
|
#include <apps/openmw-mp/Script/LuaState.hpp>
|
||||||
|
|
||||||
|
class Player;
|
||||||
|
|
||||||
|
class WeatherMgr
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void Init(LuaState &lua);
|
||||||
|
public:
|
||||||
|
explicit WeatherMgr(Player *player);
|
||||||
|
~WeatherMgr() = default;
|
||||||
|
|
||||||
|
void update();
|
||||||
|
|
||||||
|
void setWeather(int weather);
|
||||||
|
|
||||||
|
void setCurrent(int weather);
|
||||||
|
int getCurrent() const;
|
||||||
|
|
||||||
|
void setNext(int weather);
|
||||||
|
int getNext() const;
|
||||||
|
|
||||||
|
void setTransition(float time);
|
||||||
|
float getTransition() const;
|
||||||
|
|
||||||
|
void setUpdate(float time);
|
||||||
|
float getUpdate() const;
|
||||||
|
|
||||||
|
void requestWeather();
|
||||||
|
|
||||||
|
void copy(const WeatherMgr &other);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Player *player;
|
||||||
|
bool changed;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue