1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-20 10:53:51 +00:00
openmw-tes3mp/apps/openmw/mwmp/ActorList.cpp
Koncord 2d0840cb3a [General] Modernize Script API
This commit changes the style of tes3mp serverside scripting mods. Short list of changes:
* Break compatibility with old server mods
* OOP style lua API
* Basic dependency checker, allowing the installation of multiple server mods without changing configs
* Remove support for C++ plugins
* Change outdated LuaBridge to [sol2](https://github.com/ThePhD/sol2);
* Support GCC, Clang and MSVC compilers
* New environment variables: "TES3MP_SERVER_DIR" and "TES3MP_SERVER_USERDIR";
* New entity "Command controller" for registering new chat commands;
* New Event system
* Simplified Timer API
* All Lua mods now run in their own environments
* Add global namespace - Data that can be used for communicating between mods
* Player and Actor inherit base class NetActor
2017-08-28 00:15:56 +08:00

208 lines
5.2 KiB
C++

#include "ActorList.hpp"
#include "Main.hpp"
#include "Networking.hpp"
#include "LocalPlayer.hpp"
#include <components/openmw-mp/Log.hpp>
using namespace mwmp;
using namespace std;
ActorList::ActorList()
{
}
ActorList::~ActorList()
{
}
Networking *ActorList::getNetworking()
{
return mwmp::Main::get().getNetworking();
}
void ActorList::reset()
{
cell.blank();
baseActors.clear();
positionActors.clear();
animFlagsActors.clear();
animPlayActors.clear();
speechActors.clear();
statsDynamicActors.clear();
equipmentActors.clear();
attackActors.clear();
cellChangeActors.clear();
guid = mwmp::Main::get().getNetworking()->getLocalPlayer()->guid;
}
void ActorList::addActor(BaseActor *baseActor)
{
baseActors.emplace_back(baseActor);
}
void ActorList::addActor(LocalActor *localActor)
{
baseActors.emplace_back(localActor);
}
void ActorList::addPositionActor(LocalActor *localActor)
{
positionActors.emplace_back(localActor);
}
void ActorList::addAnimFlagsActor(LocalActor *localActor)
{
animFlagsActors.emplace_back(localActor);
}
void ActorList::addAnimPlayActor(LocalActor *localActor)
{
animPlayActors.emplace_back(localActor);
}
void ActorList::addSpeechActor(LocalActor *localActor)
{
speechActors.emplace_back(localActor);
}
void ActorList::addStatsDynamicActor(LocalActor *localActor)
{
statsDynamicActors.emplace_back(localActor);
}
void ActorList::addEquipmentActor(LocalActor *localActor)
{
equipmentActors.emplace_back(localActor);
}
void ActorList::addAttackActor(LocalActor *localActor)
{
attackActors.emplace_back(localActor);
}
void ActorList::addCellChangeActor(LocalActor *localActor)
{
cellChangeActors.emplace_back(localActor);
}
void ActorList::sendPositionActors()
{
if (positionActors.size() > 0)
{
baseActors = positionActors;
Main::get().getNetworking()->getActorPacket(ID_ACTOR_POSITION)->setActorList(this);
Main::get().getNetworking()->getActorPacket(ID_ACTOR_POSITION)->Send();
}
}
void ActorList::sendAnimFlagsActors()
{
if (animFlagsActors.size() > 0)
{
baseActors = animFlagsActors;
Main::get().getNetworking()->getActorPacket(ID_ACTOR_ANIM_FLAGS)->setActorList(this);
Main::get().getNetworking()->getActorPacket(ID_ACTOR_ANIM_FLAGS)->Send();
}
}
void ActorList::sendAnimPlayActors()
{
if (animPlayActors.size() > 0)
{
baseActors = animPlayActors;
Main::get().getNetworking()->getActorPacket(ID_ACTOR_ANIM_PLAY)->setActorList(this);
Main::get().getNetworking()->getActorPacket(ID_ACTOR_ANIM_PLAY)->Send();
}
}
void ActorList::sendSpeechActors()
{
if (speechActors.size() > 0)
{
baseActors = speechActors;
Main::get().getNetworking()->getActorPacket(ID_ACTOR_SPEECH)->setActorList(this);
Main::get().getNetworking()->getActorPacket(ID_ACTOR_SPEECH)->Send();
}
}
void ActorList::sendStatsDynamicActors()
{
if (statsDynamicActors.size() > 0)
{
baseActors = statsDynamicActors;
Main::get().getNetworking()->getActorPacket(ID_ACTOR_STATS_DYNAMIC)->setActorList(this);
Main::get().getNetworking()->getActorPacket(ID_ACTOR_STATS_DYNAMIC)->Send();
}
}
void ActorList::sendEquipmentActors()
{
if (equipmentActors.size() > 0)
{
baseActors = equipmentActors;
Main::get().getNetworking()->getActorPacket(ID_ACTOR_EQUIPMENT)->setActorList(this);
Main::get().getNetworking()->getActorPacket(ID_ACTOR_EQUIPMENT)->Send();
}
}
void ActorList::sendAttackActors()
{
if (attackActors.size() > 0)
{
baseActors = attackActors;
Main::get().getNetworking()->getActorPacket(ID_ACTOR_ATTACK)->setActorList(this);
Main::get().getNetworking()->getActorPacket(ID_ACTOR_ATTACK)->Send();
}
}
void ActorList::sendCellChangeActors()
{
if (cellChangeActors.size() > 0)
{
baseActors = cellChangeActors;
Main::get().getNetworking()->getActorPacket(ID_ACTOR_CELL_CHANGE)->setActorList(this);
Main::get().getNetworking()->getActorPacket(ID_ACTOR_CELL_CHANGE)->Send();
}
}
void ActorList::sendActorsInCell(MWWorld::CellStore* cellStore)
{
reset();
cell = *cellStore->getCell();
action = BaseActorList::SET;
auto createActor = [](const MWWorld::Ptr &ptr){
BaseActor *actor = new BaseActor;
actor->refId = ptr.getCellRef().getRefId();
actor->refNumIndex = ptr.getCellRef().getRefNum().mIndex;
actor->mpNum = ptr.getCellRef().getMpNum();
return actor;
};
for (auto &ref : cellStore->getNpcs()->mList)
{
MWWorld::Ptr ptr(&ref, 0);
// If this Ptr is lacking a unique index, ignore it
if (ptr.getCellRef().getRefNum().mIndex == 0 && ptr.getCellRef().getMpNum() == 0) continue;
addActor(createActor(ptr));
}
for (auto &ref : cellStore->getCreatures()->mList)
{
MWWorld::Ptr ptr(&ref, 0);
// If this Ptr is lacking a unique index, ignore it
if (ptr.getCellRef().getRefNum().mIndex == 0 && ptr.getCellRef().getMpNum() == 0) continue;
addActor(createActor(ptr));
}
mwmp::Main::get().getNetworking()->getActorPacket(ID_ACTOR_LIST)->setActorList(this);
mwmp::Main::get().getNetworking()->getActorPacket(ID_ACTOR_LIST)->Send();
}