sol2-server-rewrite
David Cernat 7 years ago
commit 5cf71a4e67

@ -14,7 +14,6 @@ void Factions::Init(LuaState &lua)
{ {
lua.getState()->new_usertype<Factions>("Factions", lua.getState()->new_usertype<Factions>("Factions",
"addFaction", &Factions::addFaction, "addFaction", &Factions::addFaction,
"changesAction", sol::property(&Factions::getFactionChangesAction, &Factions::setFactionChangesAction),
"getFaction", &Factions::getFaction, "getFaction", &Factions::getFaction,
"setFaction", &Factions::setFaction, "setFaction", &Factions::setFaction,
"clear", &Factions::clear, "clear", &Factions::clear,
@ -40,20 +39,9 @@ void Factions::processUpdate()
clear(); clear();
} }
mwmp::FactionChanges::Type Factions::getFactionChangesAction() const void Factions::addFaction(const Faction &faction)
{ {
return player->factionChanges.action; player->factionChanges.factions.emplace_back(faction.faction);
}
void Factions::setFactionChangesAction(mwmp::FactionChanges::Type action)
{
player->factionChanges.action = action;
setChanged();
}
void Factions::addFaction(Faction faction)
{
player->factionChanges.factions.push_back(faction.faction);
setChanged(); setChanged();
} }
@ -63,7 +51,7 @@ Faction Factions::getFaction(int id) const
return Faction(player->factionChanges.factions.at(id)); return Faction(player->factionChanges.factions.at(id));
} }
void Factions::setFaction(int id, Faction faction) void Factions::setFaction(int id, const Faction &faction)
{ {
player->factionChanges.factions.at(id) = faction.faction; player->factionChanges.factions.at(id) = faction.faction;
setChanged(); setChanged();
@ -112,6 +100,7 @@ int Faction::getFactionRank() const
void Faction::setFactionRank(unsigned int rank) void Faction::setFactionRank(unsigned int rank)
{ {
faction.rankChanged();
faction.rank = rank; faction.rank = rank;
} }
@ -122,6 +111,7 @@ bool Faction::getFactionExpulsionState() const
void Faction::setFactionExpulsionState(bool expulsionState) void Faction::setFactionExpulsionState(bool expulsionState)
{ {
faction.expulsionChanged();
faction.isExpelled = expulsionState; faction.isExpelled = expulsionState;
} }
@ -132,5 +122,6 @@ int Faction::getFactionReputation() const
void Faction::setFactionReputation(int reputation) void Faction::setFactionReputation(int reputation)
{ {
faction.reputationChanged();
faction.reputation = reputation; faction.reputation = reputation;
} }

@ -42,13 +42,9 @@ public:
explicit Factions(Player *player); explicit Factions(Player *player);
~Factions(); ~Factions();
void addFaction(const Faction &faction);
mwmp::FactionChanges::Type getFactionChangesAction() const;
void setFactionChangesAction(mwmp::FactionChanges::Type action);
void addFaction(Faction faction);
Faction getFaction(int id) const; Faction getFaction(int id) const;
void setFaction(int id, Faction faction); void setFaction(int id, const Faction &faction);
size_t size() const; size_t size() const;
void clear(); void clear();

@ -33,7 +33,7 @@ void Inventory::Init(LuaState &lua)
); );
} }
Inventory::Inventory(NetActor *actor) : netActor(actor), equipmentChanged(false), inventoryChanged(mwmp::InventoryChanges::Type::None) Inventory::Inventory(NetActor *actor) : netActor(actor), equipmentChanged(false), inventoryChanged(false)
{ {
printf("Inventory::Inventory()\n"); printf("Inventory::Inventory()\n");
} }
@ -85,19 +85,12 @@ void Inventory::update()
inventoryChanged = 0;*/ inventoryChanged = 0;*/
} }
void Inventory::InitializeInventoryChanges()
{
netActor->getNetCreature()->inventoryChanges.items.clear();
netActor->getNetCreature()->inventoryChanges.action = mwmp::InventoryChanges::Type::Set;
}
int Inventory::getChangesSize() const int Inventory::getChangesSize() const
{ {
return netActor->getNetCreature()->inventoryChanges.items.size(); return netActor->getNetCreature()->inventoryChanges.items.size();
} }
void Inventory::equipItem(unsigned short slot, const std::string& refId, unsigned int count, int charge, double enchantmentCharge) void Inventory::equipItem(unsigned short slot, const std::string& refId, unsigned int count, int charge, float enchantmentCharge)
{ {
netActor->getNetCreature()->equipmentItems[slot].refId = refId; netActor->getNetCreature()->equipmentItems[slot].refId = refId;
netActor->getNetCreature()->equipmentItems[slot].count = count; netActor->getNetCreature()->equipmentItems[slot].count = count;
@ -119,12 +112,10 @@ void Inventory::unequipItem( unsigned short slot)
} }
void Inventory::addItem(const std::string &refId, unsigned int count, int charge, double enchantmentCharge) void Inventory::addItem(const std::string &refId, unsigned int count, int charge, float enchantmentCharge)
{ {
if (inventoryChanged == mwmp::InventoryChanges::Type::Remove) if(!inventoryChanged)
return; resetInventoryFlag();
if (inventoryChanged == mwmp::InventoryChanges::Type::None)
InitializeInventoryChanges();
mwmp::Item item; mwmp::Item item;
item.refId = refId; item.refId = refId;
@ -132,29 +123,24 @@ void Inventory::addItem(const std::string &refId, unsigned int count, int charge
item.charge = charge; item.charge = charge;
item.enchantmentCharge = enchantmentCharge; item.enchantmentCharge = enchantmentCharge;
netActor->getNetCreature()->inventoryChanges.items.push_back(item); netActor->getNetCreature()->inventoryChanges.items.emplace_back(item, mwmp::InventoryChanges::Action::Add);
netActor->getNetCreature()->inventoryChanges.action = mwmp::InventoryChanges::Type::Add; if (netActor->isPlayer())
if (inventoryChanged == mwmp::InventoryChanges::Type::None && netActor->isPlayer())
netActor->toPlayer()->addToUpdateQueue(); netActor->toPlayer()->addToUpdateQueue();
inventoryChanged = netActor->getNetCreature()->inventoryChanges.action; inventoryChanged = true;
} }
void Inventory::removeItem(const std::string &refId, unsigned short count) void Inventory::removeItem(const std::string &refId, unsigned short count)
{ {
if (inventoryChanged == mwmp::InventoryChanges::Type::Add) if(!inventoryChanged)
return; resetInventoryFlag();
if (inventoryChanged == mwmp::InventoryChanges::Type::None)
InitializeInventoryChanges();
mwmp::Item item; mwmp::Item item;
item.refId = refId; item.refId = refId;
item.count = count; item.count = count;
netActor->getNetCreature()->inventoryChanges.items.push_back(item); netActor->getNetCreature()->inventoryChanges.items.emplace_back(item, mwmp::InventoryChanges::Action::Remove);
netActor->getNetCreature()->inventoryChanges.action = mwmp::InventoryChanges::Type::Remove; if (netActor->isPlayer())
if (inventoryChanged == mwmp::InventoryChanges::Type::None && netActor->isPlayer())
netActor->toPlayer()->addToUpdateQueue(); netActor->toPlayer()->addToUpdateQueue();
inventoryChanged = netActor->getNetCreature()->inventoryChanges.action; inventoryChanged = true;
} }
bool Inventory::hasItemEquipped(const std::string &refId) const bool Inventory::hasItemEquipped(const std::string &refId) const
@ -173,7 +159,7 @@ std::tuple<std::string, int, int, double> Inventory::getEquipmentItem(unsigned s
std::tuple<std::string, int, int, double> Inventory::getInventoryItem(unsigned int slot) const std::tuple<std::string, int, int, double> Inventory::getInventoryItem(unsigned int slot) const
{ {
const auto &item = netActor->getNetCreature()->inventoryChanges.items.at(slot); const auto &item = netActor->getNetCreature()->inventoryChanges.items.at(slot).first;
return make_tuple(item.refId, item.count, item.charge, item.enchantmentCharge); return make_tuple(item.refId, item.count, item.charge, item.enchantmentCharge);
} }
@ -189,15 +175,14 @@ bool Inventory::isEquipmentChanged()
return equipmentChanged; return equipmentChanged;
} }
void Inventory::resetInventoryFlag() bool Inventory::isInventoryChanged()
{
inventoryChanged = mwmp::InventoryChanges::Type::None;
}
mwmp::InventoryChanges::Type Inventory::inventoryChangeType()
{ {
return inventoryChanged; return inventoryChanged;
} }
void Inventory::resetInventoryFlag()
{
inventoryChanged = false;
netActor->getNetCreature()->inventoryChanges.items.clear();
}

@ -16,7 +16,7 @@ public:
static void Init(LuaState &lua); static void Init(LuaState &lua);
bool isEquipmentChanged(); bool isEquipmentChanged();
void resetEquipmentFlag(); void resetEquipmentFlag();
mwmp::InventoryChanges::Type inventoryChangeType(); bool isInventoryChanged();
void resetInventoryFlag(); void resetInventoryFlag();
public: public:
explicit Inventory(NetActor *netActor); explicit Inventory(NetActor *netActor);
@ -25,7 +25,7 @@ public:
//inventory //inventory
int getChangesSize() const; int getChangesSize() const;
void addItem(const std::string& refId, unsigned int count, int charge, double enchantmentCharge); void addItem(const std::string& refId, unsigned int count, int charge, float enchantmentCharge);
void removeItem(const std::string& refId, unsigned short count); void removeItem(const std::string& refId, unsigned short count);
/** /**
@ -37,7 +37,7 @@ public:
// equipment // equipment
void equipItem(unsigned short slot, const std::string& refId, unsigned int count, int charge, double enchantmentCharge); void equipItem(unsigned short slot, const std::string& refId, unsigned int count, int charge, float enchantmentCharge);
void unequipItem(unsigned short slot); void unequipItem(unsigned short slot);
bool hasItemEquipped(const std::string& refId) const; bool hasItemEquipped(const std::string& refId) const;
@ -49,15 +49,11 @@ public:
*/ */
std::tuple<std::string,int, int, double> getEquipmentItem(unsigned short slot) const; std::tuple<std::string,int, int, double> getEquipmentItem(unsigned short slot) const;
private:
void InitializeInventoryChanges();
private: private:
// not controlled pointer // not controlled pointer
NetActor *netActor; NetActor *netActor;
bool equipmentChanged; bool equipmentChanged;
mwmp::InventoryChanges::Type inventoryChanged; bool inventoryChanged;
}; };

@ -147,12 +147,12 @@ void Object::setCharge(int charge)
} }
double Object::getEnchantmentCharge() const float Object::getEnchantmentCharge() const
{ {
return object.enchantmentCharge; return object.enchantmentCharge;
} }
void Object::setEnchantmentCharge(double enchantmentCharge) void Object::setEnchantmentCharge(float enchantmentCharge)
{ {
changedObjectPlace = true; changedObjectPlace = true;
object.enchantmentCharge = enchantmentCharge; object.enchantmentCharge = enchantmentCharge;
@ -251,7 +251,7 @@ tuple<string, int, int, double> Container::getItem(int i) const
return make_tuple(item.refId, item.count, item.charge, item.enchantmentCharge); return make_tuple(item.refId, item.count, item.charge, item.enchantmentCharge);
} }
void Container::setItem(int i, const string &refId, int count, int charge, double enchantmentCharge) void Container::setItem(int i, const string &refId, int count, int charge, float enchantmentCharge)
{ {
auto &item = object.containerItems.at(i); auto &item = object.containerItems.at(i);
item.refId = refId; item.refId = refId;
@ -261,7 +261,7 @@ void Container::setItem(int i, const string &refId, int count, int charge, doubl
changed = true; changed = true;
} }
void Container::addItem(const string &refId, int count, int charge, double enchantmentCharge) void Container::addItem(const string &refId, int count, int charge, float enchantmentCharge)
{ {
mwmp::ContainerItem item; mwmp::ContainerItem item;
item.refId = refId; item.refId = refId;
@ -296,6 +296,12 @@ void ObjectController::Init(LuaState &lua)
return lua.getObjectCtrl().sendContainers(player, objects, Utils::getCellFromDescription(cellDescription)); return lua.getObjectCtrl().sendContainers(player, objects, Utils::getCellFromDescription(cellDescription));
}); });
objectCtrl.set_function("sendConsoleCommand", [&lua](shared_ptr<Player> player, shared_ptr<vector<shared_ptr<Object>>> objects,
const std::string &cellDescription, const std::string &command,
bool broadcast) {
return lua.getObjectCtrl().sendConsoleCommand(player, objects, Utils::getCellFromDescription(cellDescription),
command, broadcast);
});
objectCtrl.set_function("requestContainers", [&lua](shared_ptr<Player> player) { objectCtrl.set_function("requestContainers", [&lua](shared_ptr<Player> player) {
lua.getObjectCtrl().requestContainers(player); lua.getObjectCtrl().requestContainers(player);
}); });

@ -66,8 +66,8 @@ public:
int getCharge() const; int getCharge() const;
void setCharge(int charge); void setCharge(int charge);
double getEnchantmentCharge() const; float getEnchantmentCharge() const;
void setEnchantmentCharge(double enchantmentCharge); void setEnchantmentCharge(float enchantmentCharge);
int getGoldValue() const; int getGoldValue() const;
void setGoldValue(int gold); void setGoldValue(int gold);
@ -99,9 +99,9 @@ public:
Container(); Container();
std::tuple<std::string, int, int, double> getItem(int i) const; std::tuple<std::string, int, int, double> getItem(int i) const;
void addItem(const std::string &refId, int count, int charge, double enchantmentCharge); void addItem(const std::string &refId, int count, int charge, float enchantmentCharge);
void setItem(int i, const std::string &refId, int count, int charge, double enchantmentCharge); void setItem(int i, const std::string &refId, int count, int charge, float enchantmentCharge);
int getActionCount(int i) const; int getActionCount(int i) const;
size_t size() const; size_t size() const;

@ -124,6 +124,7 @@ Player::Player(RakNet::RakNetGUID guid) : BasePlayer(guid), NetActor(), changedM
storedData = mwmp::Networking::get().getState().getState()->create_table(); storedData = mwmp::Networking::get().getState().getState()->create_table();
customData = mwmp::Networking::get().getState().getState()->create_table(); customData = mwmp::Networking::get().getState().getState()->create_table();
isActorPlayer = true; isActorPlayer = true;
inUpdateQueue = false;
} }
Player::~Player() Player::~Player()
@ -218,7 +219,7 @@ void Player::update()
inventory.resetEquipmentFlag(); inventory.resetEquipmentFlag();
} }
if (inventory.inventoryChangeType() != mwmp::InventoryChanges::Type::None) if (inventory.isInventoryChanged())
{ {
auto packet = plPCtrl->GetPacket(ID_PLAYER_INVENTORY); auto packet = plPCtrl->GetPacket(ID_PLAYER_INVENTORY);
packet->setPlayer(this); packet->setPlayer(this);

@ -15,7 +15,7 @@ void GameSettings::Init(LuaState &lua)
lua.getState()->new_usertype<GameSettings>("Settings", lua.getState()->new_usertype<GameSettings>("Settings",
"setDifficulty", &GameSettings::setDifficulty, "setDifficulty", &GameSettings::setDifficulty,
"setConsoleAllowed", &GameSettings::setConsoleAllowed, "setConsoleAllowed", &GameSettings::setConsoleAllowed,
"setBedRestAllowed", &GameSettings::setConsoleAllowed, "setBedRestAllowed", &GameSettings::setBedRestAllowed,
"setWildernessRestAllowed", &GameSettings::setWildernessRestAllowed, "setWildernessRestAllowed", &GameSettings::setWildernessRestAllowed,
"setWaitAllowed", &GameSettings::setWaitAllowed "setWaitAllowed", &GameSettings::setWaitAllowed
); );

@ -27,11 +27,6 @@ mwmp::Cell::Cell(MWWorld::CellStore* cellStore)
updateTimer = 0; updateTimer = 0;
} }
Cell::~Cell()
{
}
void Cell::updateLocal(bool forceUpdate) void Cell::updateLocal(bool forceUpdate)
{ {
if (localActors.empty()) if (localActors.empty())
@ -284,7 +279,7 @@ void Cell::readCellChange(ActorList& actorList)
std::string mapIndex = Main::get().getCellController()->generateMapIndex(baseActor); std::string mapIndex = Main::get().getCellController()->generateMapIndex(baseActor);
// Is a packet mistakenly moving the actor to the cell it's already in? If so, ignore it // Is a packet mistakenly moving the actor to the cell it's already in? If so, ignore it
if (Misc::StringUtils::ciEqual(getDescription(), baseActor.cell.getDescription())) if (Misc::StringUtils::ciEqual(getDescription(), baseActor->cell.getDescription()))
{ {
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Server says DedicatedActor %s moved to %s, but it was already there", LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Server says DedicatedActor %s moved to %s, but it was already there",
mapIndex.c_str(), getDescription().c_str()); mapIndex.c_str(), getDescription().c_str());
@ -434,12 +429,12 @@ void Cell::uninitializeDedicatedActors()
dedicatedActors.clear(); dedicatedActors.clear();
} }
LocalActor *Cell::getLocalActor(std::string actorIndex) LocalActor *Cell::getLocalActor(const std::string &actorIndex)
{ {
return localActors.at(actorIndex); return localActors.at(actorIndex);
} }
DedicatedActor *Cell::getDedicatedActor(std::string actorIndex) DedicatedActor *Cell::getDedicatedActor(const std::string &actorIndex)
{ {
return dedicatedActors.at(actorIndex); return dedicatedActors.at(actorIndex);
} }

@ -12,8 +12,8 @@ namespace mwmp
{ {
public: public:
Cell(MWWorld::CellStore* cellStore); explicit Cell(MWWorld::CellStore* cellStore);
virtual ~Cell(); ~Cell() = default;
void updateLocal(bool forceUpdate); void updateLocal(bool forceUpdate);
void updateDedicated(float dt); void updateDedicated(float dt);
@ -36,8 +36,8 @@ namespace mwmp
void uninitializeLocalActors(); void uninitializeLocalActors();
void uninitializeDedicatedActors(); void uninitializeDedicatedActors();
virtual LocalActor *getLocalActor(std::string actorIndex); LocalActor *getLocalActor(const std::string &actorIndex);
virtual DedicatedActor *getDedicatedActor(std::string actorIndex); DedicatedActor *getDedicatedActor(const std::string &actorIndex);
bool hasLocalAuthority(); bool hasLocalAuthority();
void setAuthority(const RakNet::RakNetGUID& guid); void setAuthority(const RakNet::RakNetGUID& guid);

@ -177,15 +177,18 @@ void DedicatedActor::setEquipment()
const string &packetRefId = equipmentItems[slot].refId; const string &packetRefId = equipmentItems[slot].refId;
int packetCharge = equipmentItems[slot].charge; int packetCharge = equipmentItems[slot].charge;
std::string storeRefId = "";
bool equal = false; bool equal = false;
if (it != invStore.end()) if (it != invStore.end())
{ {
storeRefId = it->getCellRef().getRefId(); std::string storeRefId = it->getCellRef().getRefId();
int count = invStore.count(storeRefId);
if (!Misc::StringUtils::ciEqual(storeRefId, packetRefId)) // if other item equiped if (!Misc::StringUtils::ciEqual(storeRefId, packetRefId)) // if other item equipped
{
invStore.unequipSlot(slot, ptr); invStore.unequipSlot(slot, ptr);
ptr.getClass().getContainerStore(ptr).remove(storeRefId, count, ptr);
}
else else
equal = true; equal = true;
} }

@ -170,11 +170,10 @@ void DedicatedPlayer::setEquipment()
MWWorld::ContainerStoreIterator it = invStore.getSlot(slot); MWWorld::ContainerStoreIterator it = invStore.getSlot(slot);
const string &dedicItem = equipmentItems[slot].refId; const string &dedicItem = equipmentItems[slot].refId;
std::string item = "";
bool equal = false; bool equal = false;
if (it != invStore.end()) if (it != invStore.end())
{ {
item = it->getCellRef().getRefId(); const std::string &item = it->getCellRef().getRefId();
if (!Misc::StringUtils::ciEqual(item, dedicItem)) // if other item equiped if (!Misc::StringUtils::ciEqual(item, dedicItem)) // if other item equiped
{ {
MWWorld::ContainerStore &store = ptr.getClass().getContainerStore(ptr); MWWorld::ContainerStore &store = ptr.getClass().getContainerStore(ptr);

@ -457,11 +457,11 @@ void LocalPlayer::updateEquipment(bool forceUpdate)
item.refId = ""; item.refId = "";
item.count = 0; item.count = 0;
item.charge = -1; item.charge = -1;
item.enchantmentCharge = -1; item.enchantmentCharge = -1.0f;
} }
} }
if (equipmentIndexChanges.size() > 0) if (!equipmentIndexChanges.empty())
{ {
getNetworking()->getPlayerPacket(ID_PLAYER_EQUIPMENT)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_EQUIPMENT)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_EQUIPMENT)->Send(); getNetworking()->getPlayerPacket(ID_PLAYER_EQUIPMENT)->Send();
@ -500,7 +500,7 @@ void LocalPlayer::updateInventory(bool forceUpdate)
if (setItem(item, *result)) if (setItem(item, *result))
continue; continue;
if (item == itemOld) if (item == itemOld.first)
break; break;
} }
if (result == ptrInventory.end()) if (result == ptrInventory.end())
@ -520,7 +520,9 @@ void LocalPlayer::updateInventory(bool forceUpdate)
auto items = inventoryChanges.items; auto items = inventoryChanges.items;
if (find(items.begin(), items.end(), item) == items.end()) if (find_if(items.begin(), items.end(), [&item](const std::pair<Item, InventoryChanges::Action> &a) {
return item == a.first;
}) == items.end())
{ {
invChanged = true; invChanged = true;
break; break;
@ -650,27 +652,25 @@ void LocalPlayer::updateAnimFlags(bool forceUpdate)
} }
} }
void LocalPlayer::addItems() void LocalPlayer::addItem(const Item &item)
{ {
MWWorld::Ptr ptrPlayer = getPlayerPtr(); MWWorld::Ptr ptrPlayer = getPlayerPtr();
MWWorld::ContainerStore &ptrStore = ptrPlayer.getClass().getContainerStore(ptrPlayer); MWWorld::ContainerStore &ptrStore = ptrPlayer.getClass().getContainerStore(ptrPlayer);
for (const auto &item : inventoryChanges.items)
{
try try
{ {
MWWorld::Ptr itemPtr = *ptrStore.add(item.refId, item.count, ptrPlayer); MWWorld::Ptr itemPtr = *ptrStore.add(item.refId, item.count, ptrPlayer);
if (item.charge != -1) if (item.charge != -1)
itemPtr.getCellRef().setCharge(item.charge); itemPtr.getCellRef().setCharge(item.charge);
if (item.enchantmentCharge != -1) if (item.enchantmentCharge != -1.0f)
itemPtr.getCellRef().setEnchantmentCharge(item.enchantmentCharge); itemPtr.getCellRef().setEnchantmentCharge(item.enchantmentCharge);
} }
catch (std::exception&) catch (std::exception&)
{ {
LOG_APPEND(Log::LOG_INFO, "- Ignored addition of invalid inventory item %s", item.refId.c_str()); LOG_APPEND(Log::LOG_INFO, "- Ignored addition of invalid inventory item %s", item.refId.c_str());
} }
}
} }
void LocalPlayer::addSpells() void LocalPlayer::addSpells()
@ -732,12 +732,11 @@ void LocalPlayer::addTopics()
} }
} }
void LocalPlayer::removeItems() void LocalPlayer::removeItem(const Item &item)
{ {
MWWorld::Ptr ptrPlayer = getPlayerPtr(); MWWorld::Ptr ptrPlayer = getPlayerPtr();
MWWorld::ContainerStore &ptrStore = ptrPlayer.getClass().getContainerStore(ptrPlayer); MWWorld::ContainerStore &ptrStore = ptrPlayer.getClass().getContainerStore(ptrPlayer);
for (const auto &item : inventoryChanges.items)
ptrStore.remove(item.refId, item.count, ptrPlayer); ptrStore.remove(item.refId, item.count, ptrPlayer);
} }
@ -1067,7 +1066,11 @@ void LocalPlayer::setInventory()
ptrStore.clear(); ptrStore.clear();
// Proceed by adding items // Proceed by adding items
addItems(); for(const auto &item : inventoryChanges.items)
{
if(item.second == InventoryChanges::Action::Set)
addItem(item.first);
}
// Don't automatically setEquipment() here, or the player could end // Don't automatically setEquipment() here, or the player could end
// up getting a new set of their starting clothes, or other items // up getting a new set of their starting clothes, or other items
@ -1172,7 +1175,7 @@ void LocalPlayer::setFactions()
if (!ptrNpcStats.isInFaction(faction.factionId)) if (!ptrNpcStats.isInFaction(faction.factionId))
ptrNpcStats.joinFaction(faction.factionId); ptrNpcStats.joinFaction(faction.factionId);
if (factionChanges.action == mwmp::FactionChanges::Type::Rank) if (faction.isRankChanged())
{ {
// While the faction rank is different in the packet than in the NpcStats, // While the faction rank is different in the packet than in the NpcStats,
// adjust the NpcStats accordingly // adjust the NpcStats accordingly
@ -1184,7 +1187,8 @@ void LocalPlayer::setFactions()
ptrNpcStats.lowerRank(faction.factionId); ptrNpcStats.lowerRank(faction.factionId);
} }
} }
else if (factionChanges.action == mwmp::FactionChanges::Type::Expulsion)
if (faction.isExpulsionChanged())
{ {
// If the expelled state is different in the packet than in the NpcStats, // If the expelled state is different in the packet than in the NpcStats,
// adjust the NpcStats accordingly // adjust the NpcStats accordingly
@ -1197,7 +1201,7 @@ void LocalPlayer::setFactions()
} }
} }
else if (factionChanges.action == mwmp::FactionChanges::Type::Reputation) if (faction.isReputationChanged())
ptrNpcStats.setFactionReputation(faction.factionId, faction.reputation); ptrNpcStats.setFactionReputation(faction.factionId, faction.reputation);
} }
} }
@ -1272,10 +1276,9 @@ void LocalPlayer::sendInventory()
item.charge = iter.getCellRef().getCharge(); item.charge = iter.getCellRef().getCharge();
item.enchantmentCharge = iter.getCellRef().getEnchantmentCharge(); item.enchantmentCharge = iter.getCellRef().getEnchantmentCharge();
inventoryChanges.items.push_back(item); inventoryChanges.items.emplace_back(item, InventoryChanges::Action::Set);
} }
inventoryChanges.action = InventoryChanges::Type::Set;
getNetworking()->getPlayerPacket(ID_PLAYER_INVENTORY)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_INVENTORY)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_INVENTORY)->Send(); getNetworking()->getPlayerPacket(ID_PLAYER_INVENTORY)->Send();
} }
@ -1416,11 +1419,11 @@ void LocalPlayer::sendJournalIndex(const std::string& quest, int index)
void LocalPlayer::sendFactionRank(const std::string& factionId, int rank) void LocalPlayer::sendFactionRank(const std::string& factionId, int rank)
{ {
factionChanges.factions.clear(); factionChanges.factions.clear();
factionChanges.action = FactionChanges::Type::Rank;
mwmp::Faction faction; mwmp::Faction faction;
faction.factionId = factionId; faction.factionId = factionId;
faction.rank = rank; faction.rank = rank;
faction.rankChanged();
factionChanges.factions.push_back(faction); factionChanges.factions.push_back(faction);
@ -1431,11 +1434,11 @@ void LocalPlayer::sendFactionRank(const std::string& factionId, int rank)
void LocalPlayer::sendFactionExpulsionState(const std::string& factionId, bool isExpelled) void LocalPlayer::sendFactionExpulsionState(const std::string& factionId, bool isExpelled)
{ {
factionChanges.factions.clear(); factionChanges.factions.clear();
factionChanges.action = FactionChanges::Type::Expulsion;
mwmp::Faction faction; mwmp::Faction faction;
faction.factionId = factionId; faction.factionId = factionId;
faction.isExpelled = isExpelled; faction.isExpelled = isExpelled;
faction.expulsionChanged();
factionChanges.factions.push_back(faction); factionChanges.factions.push_back(faction);
@ -1446,11 +1449,11 @@ void LocalPlayer::sendFactionExpulsionState(const std::string& factionId, bool i
void LocalPlayer::sendFactionReputation(const std::string& factionId, int reputation) void LocalPlayer::sendFactionReputation(const std::string& factionId, int reputation)
{ {
factionChanges.factions.clear(); factionChanges.factions.clear();
factionChanges.action = FactionChanges::Type::Reputation;
mwmp::Faction faction; mwmp::Faction faction;
faction.factionId = factionId; faction.factionId = factionId;
faction.reputation = reputation; faction.reputation = reputation;
faction.reputationChanged();
factionChanges.factions.push_back(faction); factionChanges.factions.push_back(faction);

@ -38,12 +38,12 @@ namespace mwmp
void updateDeadState(bool forceUpdate = false); void updateDeadState(bool forceUpdate = false);
void updateAnimFlags(bool forceUpdate = false); void updateAnimFlags(bool forceUpdate = false);
void addItems(); void addItem(const Item &item);
void addSpells(); void addSpells();
void addJournalItems(); void addJournalItems();
void addTopics(); void addTopics();
void removeItems(); void removeItem(const Item &item);
void removeSpells(); void removeSpells();
void resurrect(); void resurrect();

@ -90,7 +90,7 @@ void WorldEvent::editContainers(MWWorld::CellStore* cellStore)
if (containerItem.charge > -1) if (containerItem.charge > -1)
newPtr.getCellRef().setCharge(containerItem.charge); newPtr.getCellRef().setCharge(containerItem.charge);
if (containerItem.enchantmentCharge > -1) if (containerItem.enchantmentCharge > -1.0f)
newPtr.getCellRef().setEnchantmentCharge(containerItem.enchantmentCharge); newPtr.getCellRef().setEnchantmentCharge(containerItem.enchantmentCharge);
containerStore.add(newPtr, containerItem.count, ownerPtr, true); containerStore.add(newPtr, containerItem.count, ownerPtr, true);
@ -173,7 +173,7 @@ void WorldEvent::placeObjects(MWWorld::CellStore* cellStore)
if (worldObject.charge > -1) if (worldObject.charge > -1)
newPtr.getCellRef().setCharge(worldObject.charge); newPtr.getCellRef().setCharge(worldObject.charge);
if (worldObject.enchantmentCharge > -1) if (worldObject.enchantmentCharge > -1.0f)
newPtr.getCellRef().setEnchantmentCharge(worldObject.enchantmentCharge); newPtr.getCellRef().setEnchantmentCharge(worldObject.enchantmentCharge);
newPtr.getCellRef().setGoldValue(worldObject.goldValue); newPtr.getCellRef().setGoldValue(worldObject.goldValue);

@ -29,12 +29,19 @@ namespace mwmp
{ {
LocalPlayer &localPlayer = static_cast<LocalPlayer&>(*player); LocalPlayer &localPlayer = static_cast<LocalPlayer&>(*player);
if (localPlayer.inventoryChanges.action == InventoryChanges::Type::Add) for (const auto &item : localPlayer.inventoryChanges.items)
localPlayer.addItems(); {
else if (localPlayer.inventoryChanges.action == InventoryChanges::Type::Remove) if (item.second == InventoryChanges::Action::Add)
localPlayer.removeItems(); localPlayer.addItem(item.first);
else if (item.second == InventoryChanges::Action::Remove)
localPlayer.removeItem(item.first);
else // InventoryChanges::SET else // InventoryChanges::SET
{
// found set flag, clear and reset inventory
localPlayer.setInventory(); localPlayer.setInventory();
break;
}
}
} }
} }
}; };

@ -50,7 +50,7 @@ namespace mwmp
{ {
Set = 0, Set = 0,
Add, Add,
Remsove, Remove,
Request Request
}; };

@ -12,7 +12,7 @@ namespace mwmp
std::string refId; std::string refId;
int count; int count;
int charge; int charge;
double enchantmentCharge; float enchantmentCharge;
int actionCount; int actionCount;
@ -29,7 +29,7 @@ namespace mwmp
unsigned mpNum; unsigned mpNum;
int count; int count;
int charge; int charge;
double enchantmentCharge; float enchantmentCharge;
int goldValue; int goldValue;
ESM::Position position; ESM::Position position;

@ -59,10 +59,26 @@ namespace mwmp
struct Faction struct Faction
{ {
enum ChangesMask
{
Rank = 1,
Expulsion = 2,
Reputation = 4
};
inline bool isRankChanged() const { return (changes & ChangesMask::Rank) > 0; }
inline bool isExpulsionChanged() const { return (changes & ChangesMask::Expulsion) > 0; }
inline bool isReputationChanged() const { return (changes & ChangesMask::Reputation) > 0; }
inline void rankChanged() { changes |= ChangesMask::Rank; };
inline void expulsionChanged() { changes |= ChangesMask::Expulsion; };
inline void reputationChanged() { changes |= ChangesMask::Reputation; };
std::string factionId; std::string factionId;
int rank; int rank;
int reputation; int reputation;
bool isExpelled; bool isExpelled;
uint8_t changes = 0;
}; };
struct Topic struct Topic
@ -118,15 +134,6 @@ namespace mwmp
struct FactionChanges struct FactionChanges
{ {
std::vector<Faction> factions; std::vector<Faction> factions;
enum class Type: uint8_t
{
Rank = 0,
Expulsion,
Reputation
};
Type action;
}; };
struct TopicChanges struct TopicChanges
@ -240,7 +247,6 @@ namespace mwmp
BasePlayer(RakNet::RakNetGUID guid) : guid(guid) BasePlayer(RakNet::RakNetGUID guid) : guid(guid)
{ {
inventoryChanges.action = InventoryChanges::Type::None;
spellbookChanges.action = SpellbookChanges::Type::None; spellbookChanges.action = SpellbookChanges::Type::None;
useCreatureName = false; useCreatureName = false;
isWerewolf = false; isWerewolf = false;

@ -12,7 +12,7 @@ namespace mwmp
std::string refId; std::string refId;
int count; int count;
int charge; int charge;
double enchantmentCharge; float enchantmentCharge;
inline bool operator==(const Item& rhs) inline bool operator==(const Item& rhs)
{ {
@ -22,15 +22,14 @@ namespace mwmp
struct InventoryChanges struct InventoryChanges
{ {
std::vector<Item> items; enum class Action: int8_t
enum class Type: int8_t
{ {
None = -1, None = -1,
Set = 0, Set = 0,
Add, Add,
Remove Remove
}; };
Type action; // 0 - Clear and set in entirety, 1 - Add item, 2 - Remove item std::vector<std::pair<Item, Action>> items;
}; };
struct Target struct Target

@ -20,7 +20,8 @@ inline void AddPacket(mwmp::ActorPacketController::packets_t *packets, RakNet::R
{ {
T *packet = new T(peer); T *packet = new T(peer);
typedef mwmp::ActorPacketController::packets_t::value_type value_t; typedef mwmp::ActorPacketController::packets_t::value_type value_t;
packets->insert(value_t(packet->GetPacketID(), value_t::second_type(std::move(packet)))); unsigned char packetId = packet->GetPacketID();
packets->insert(value_t(packetId, value_t::second_type(std::move(packet))));
} }
mwmp::ActorPacketController::ActorPacketController(RakNet::RakPeerInterface *peer) mwmp::ActorPacketController::ActorPacketController(RakNet::RakPeerInterface *peer)

@ -47,7 +47,8 @@ inline void AddPacket(mwmp::PlayerPacketController::packets_t *packets, RakNet::
{ {
T *packet = new T(peer); T *packet = new T(peer);
typedef mwmp::PlayerPacketController::packets_t::value_type value_t; typedef mwmp::PlayerPacketController::packets_t::value_type value_t;
packets->insert(value_t(packet->GetPacketID(), value_t::second_type(std::move(packet)))); unsigned char packetId = packet->GetPacketID();
packets->insert(value_t(packetId, value_t::second_type(std::move(packet))));
} }
mwmp::PlayerPacketController::PlayerPacketController(RakNet::RakPeerInterface *peer) mwmp::PlayerPacketController::PlayerPacketController(RakNet::RakPeerInterface *peer)

@ -27,7 +27,8 @@ inline void AddPacket(mwmp::WorldPacketController::packets_t *packets, RakNet::R
{ {
T *packet = new T(peer); T *packet = new T(peer);
typedef mwmp::WorldPacketController::packets_t::value_type value_t; typedef mwmp::WorldPacketController::packets_t::value_type value_t;
packets->insert(value_t(packet->GetPacketID(), value_t::second_type(std::move(packet)))); unsigned char packetId = packet->GetPacketID();
packets->insert(value_t(packetId, value_t::second_type(std::move(packet))));
} }
mwmp::WorldPacketController::WorldPacketController(RakNet::RakPeerInterface *peer) mwmp::WorldPacketController::WorldPacketController(RakNet::RakPeerInterface *peer)

@ -12,9 +12,6 @@ PacketPlayerFaction::PacketPlayerFaction(RakNet::RakPeerInterface *peer) : Playe
void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send) void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send)
{ {
PlayerPacket::Packet(bs, send); PlayerPacket::Packet(bs, send);
RW(player->factionChanges.action, send);
uint32_t count; uint32_t count;
if (send) if (send)
@ -30,15 +27,17 @@ void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send)
for (auto &&faction : player->factionChanges.factions) for (auto &&faction : player->factionChanges.factions)
{ {
RW(faction.changes, send, true);
RW(faction.factionId, send, true); RW(faction.factionId, send, true);
if (player->factionChanges.action == FactionChanges::Type::Rank) if (faction.isRankChanged())
RW(faction.rank, send); RW(faction.rank, send);
if (player->factionChanges.action == FactionChanges::Type::Expulsion) if (faction.isExpulsionChanged())
RW(faction.isExpelled, send); RW(faction.isExpelled, send);
if (player->factionChanges.action == FactionChanges::Type::Reputation) if (faction.isReputationChanged())
RW(faction.reputation, send); RW(faction.reputation, send);
} }
} }

@ -17,8 +17,6 @@ void PacketPlayerInventory::Packet(RakNet::BitStream *bs, bool send)
{ {
PlayerPacket::Packet(bs, send); PlayerPacket::Packet(bs, send);
RW(player->inventoryChanges.action, send);
uint32_t count; uint32_t count;
if (send) if (send)
@ -34,9 +32,10 @@ void PacketPlayerInventory::Packet(RakNet::BitStream *bs, bool send)
for (auto &&item : player->inventoryChanges.items) for (auto &&item : player->inventoryChanges.items)
{ {
RW(item.refId, send, true); RW(item.first.refId, send, true);
RW(item.count, send); RW(item.first.count, send);
RW(item.charge, send); RW(item.first.charge, send);
RW(item.enchantmentCharge, send); RW(item.first.enchantmentCharge, send);
RW(item.second, send, true); // compress byte to bits
} }
} }

@ -12,7 +12,6 @@ PacketPlayerPosition::PacketPlayerPosition(RakNet::RakPeerInterface *peer) : Pla
{ {
packetID = ID_PLAYER_POSITION; packetID = ID_PLAYER_POSITION;
priority = MEDIUM_PRIORITY; priority = MEDIUM_PRIORITY;
//reliability = UNRELIABLE_SEQUENCED;
} }
void PacketPlayerPosition::Packet(RakNet::BitStream *bs, bool send) void PacketPlayerPosition::Packet(RakNet::BitStream *bs, bool send)
@ -23,6 +22,11 @@ void PacketPlayerPosition::Packet(RakNet::BitStream *bs, bool send)
unsigned char dir; unsigned char dir;
if (send) if (send)
{ {
if((player->movementFlags & /*Flag_ForceJump*/16) != 0)
reliability = RELIABLE_ORDERED;
else
reliability = UNRELIABLE_SEQUENCED;
rot[0] = player->position.rot[0] * 0.1f; rot[0] = player->position.rot[0] * 0.1f;
rot[1] = player->position.rot[2] * 0.1f; rot[1] = player->position.rot[2] * 0.1f;

Loading…
Cancel
Save