forked from teamnwah/openmw-tes3coop
[Server] Add script functions for factions
This commit is contained in:
parent
e6983993c2
commit
a2e2ca7cab
5 changed files with 106 additions and 4 deletions
|
@ -77,10 +77,10 @@ set(SERVER
|
||||||
|
|
||||||
Script/Functions/Actors.cpp Script/Functions/World.cpp Script/Functions/Miscellaneous.cpp
|
Script/Functions/Actors.cpp Script/Functions/World.cpp Script/Functions/Miscellaneous.cpp
|
||||||
|
|
||||||
Script/Functions/CharClass.cpp Script/Functions/Chat.cpp Script/Functions/GUI.cpp
|
Script/Functions/Cells.cpp Script/Functions/CharClass.cpp Script/Functions/Chat.cpp
|
||||||
Script/Functions/Items.cpp Script/Functions/Quests.cpp Script/Functions/Stats.cpp
|
Script/Functions/Factions.cpp Script/Functions/GUI.cpp Script/Functions/Items.cpp
|
||||||
Script/Functions/Spells.cpp Script/Functions/Timer.cpp Script/Functions/Positions.cpp
|
Script/Functions/Positions.cpp Script/Functions/Quests.cpp Script/Functions/Spells.cpp
|
||||||
Script/Functions/Cells.cpp
|
Script/Functions/Stats.cpp Script/Functions/Timer.cpp
|
||||||
|
|
||||||
ProcessorInitializer.cpp PlayerProcessor.cpp ActorProcessor.cpp WorldProcessor.cpp
|
ProcessorInitializer.cpp PlayerProcessor.cpp ActorProcessor.cpp WorldProcessor.cpp
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,7 @@ public:
|
||||||
mwmp::InventoryChanges inventoryChangesBuffer;
|
mwmp::InventoryChanges inventoryChangesBuffer;
|
||||||
mwmp::SpellbookChanges spellbookChangesBuffer;
|
mwmp::SpellbookChanges spellbookChangesBuffer;
|
||||||
mwmp::JournalChanges journalChangesBuffer;
|
mwmp::JournalChanges journalChangesBuffer;
|
||||||
|
mwmp::FactionChanges factionChangesBuffer;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CellController::TContainer cells;
|
CellController::TContainer cells;
|
||||||
|
|
67
apps/openmw-mp/Script/Functions/Factions.cpp
Normal file
67
apps/openmw-mp/Script/Functions/Factions.cpp
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
#include "Factions.hpp"
|
||||||
|
#include <apps/openmw-mp/Script/ScriptFunctions.hpp>
|
||||||
|
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||||
|
#include <apps/openmw-mp/Networking.hpp>
|
||||||
|
#include <components/misc/stringops.hpp>
|
||||||
|
|
||||||
|
using namespace mwmp;
|
||||||
|
|
||||||
|
unsigned int FactionFunctions::GetFactionChangesSize(unsigned short pid) noexcept
|
||||||
|
{
|
||||||
|
Player *player;
|
||||||
|
GET_PLAYER(pid, player, 0);
|
||||||
|
|
||||||
|
return player->factionChanges.count;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FactionFunctions::AddFaction(unsigned short pid, const char* factionId, unsigned int rank, bool isExpelled) noexcept
|
||||||
|
{
|
||||||
|
Player *player;
|
||||||
|
GET_PLAYER(pid, player, );
|
||||||
|
|
||||||
|
mwmp::Faction faction;
|
||||||
|
faction.factionId = factionId;
|
||||||
|
faction.rank = rank;
|
||||||
|
faction.isExpelled = isExpelled;
|
||||||
|
|
||||||
|
player->factionChangesBuffer.factions.push_back(faction);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *FactionFunctions::GetFactionId(unsigned short pid, unsigned int i) noexcept
|
||||||
|
{
|
||||||
|
Player *player;
|
||||||
|
GET_PLAYER(pid, player, "");
|
||||||
|
|
||||||
|
if (i >= player->factionChanges.count)
|
||||||
|
return "invalid";
|
||||||
|
|
||||||
|
return player->factionChanges.factions.at(i).factionId.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
int FactionFunctions::GetFactionRank(unsigned short pid, unsigned int i) noexcept
|
||||||
|
{
|
||||||
|
Player *player;
|
||||||
|
GET_PLAYER(pid, player, 0);
|
||||||
|
|
||||||
|
return player->factionChanges.factions.at(i).rank;
|
||||||
|
}
|
||||||
|
|
||||||
|
int FactionFunctions::GetFactionExpelledState(unsigned short pid, unsigned int i) noexcept
|
||||||
|
{
|
||||||
|
Player *player;
|
||||||
|
GET_PLAYER(pid, player, 0);
|
||||||
|
|
||||||
|
return player->factionChanges.factions.at(i).isExpelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FactionFunctions::SendFactionChanges(unsigned short pid) noexcept
|
||||||
|
{
|
||||||
|
Player *player;
|
||||||
|
GET_PLAYER(pid, player, );
|
||||||
|
|
||||||
|
std::swap(player->factionChanges, player->factionChangesBuffer);
|
||||||
|
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_FACTION)->setPlayer(player);
|
||||||
|
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_FACTION)->Send(false);
|
||||||
|
player->factionChanges = std::move(player->factionChangesBuffer);
|
||||||
|
player->factionChangesBuffer.factions.clear();
|
||||||
|
}
|
32
apps/openmw-mp/Script/Functions/Factions.hpp
Normal file
32
apps/openmw-mp/Script/Functions/Factions.hpp
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#ifndef OPENMW_FACTIONAPI_HPP
|
||||||
|
#define OPENMW_FACTIONAPI_HPP
|
||||||
|
|
||||||
|
#define FACTIONAPI \
|
||||||
|
{"GetFactionChangesSize", FactionFunctions::GetFactionChangesSize},\
|
||||||
|
\
|
||||||
|
{"AddFaction", FactionFunctions::AddFaction},\
|
||||||
|
\
|
||||||
|
{"GetFactionId", FactionFunctions::GetFactionId},\
|
||||||
|
{"GetFactionRank", FactionFunctions::GetFactionRank},\
|
||||||
|
{"GetFactionExpelledState", FactionFunctions::GetFactionExpelledState},\
|
||||||
|
\
|
||||||
|
{"SendFactionChanges", FactionFunctions::SendFactionChanges}
|
||||||
|
|
||||||
|
class FactionFunctions
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
static unsigned int GetFactionChangesSize(unsigned short pid) noexcept;
|
||||||
|
|
||||||
|
static void AddFaction(unsigned short pid, const char* factionId, unsigned int rank, bool isExpelled) noexcept;
|
||||||
|
|
||||||
|
static const char *GetFactionId(unsigned short pid, unsigned int i) noexcept;
|
||||||
|
static int GetFactionRank(unsigned short pid, unsigned int i) noexcept;
|
||||||
|
static int GetFactionExpelledState(unsigned short pid, unsigned int i) noexcept;
|
||||||
|
|
||||||
|
static void SendFactionChanges(unsigned short pid) noexcept;
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //OPENMW_FACTIONAPI_HPP
|
|
@ -12,6 +12,7 @@
|
||||||
#include <Script/Functions/Stats.hpp>
|
#include <Script/Functions/Stats.hpp>
|
||||||
#include <Script/Functions/Items.hpp>
|
#include <Script/Functions/Items.hpp>
|
||||||
#include <Script/Functions/Quests.hpp>
|
#include <Script/Functions/Quests.hpp>
|
||||||
|
#include <Script/Functions/Factions.hpp>
|
||||||
#include <Script/Functions/Spells.hpp>
|
#include <Script/Functions/Spells.hpp>
|
||||||
#include <Script/Functions/Actors.hpp>
|
#include <Script/Functions/Actors.hpp>
|
||||||
#include <Script/Functions/World.hpp>
|
#include <Script/Functions/World.hpp>
|
||||||
|
@ -102,6 +103,7 @@ public:
|
||||||
STATAPI,
|
STATAPI,
|
||||||
ITEMAPI,
|
ITEMAPI,
|
||||||
QUESTAPI,
|
QUESTAPI,
|
||||||
|
FACTIONAPI,
|
||||||
SPELLAPI,
|
SPELLAPI,
|
||||||
GUIAPI,
|
GUIAPI,
|
||||||
CHARCLASSAPI,
|
CHARCLASSAPI,
|
||||||
|
|
Loading…
Reference in a new issue