1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-29 22:45:34 +00:00

[General] Use PlayerItemUse packets when using items through quick keys

This commit is contained in:
David Cernat 2019-08-16 05:50:07 +03:00
parent ae5200cbb2
commit ab93b5ddc5
6 changed files with 60 additions and 6 deletions

View file

@ -463,6 +463,14 @@ namespace MWGui
return;
}
/*
Start of tes3mp change (major)
Instead of unilaterally using an item, send an ID_PLAYER_ITEM_USE packet and let the server
decide if the item actually gets used
*/
/*
MWBase::Environment::get().getWindowManager()->useItem(item);
MWWorld::ConstContainerStoreIterator rightHand = store.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
// change draw state only if the item is in player's right hand
@ -470,21 +478,43 @@ namespace MWGui
{
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState_Weapon);
}
*/
bool shouldDraw = isWeapon || isTool;
mwmp::Main::get().getLocalPlayer()->sendItemUse(item, false, shouldDraw ? MWMechanics::DrawState_Weapon : MWMechanics::DrawState_Nothing);
/*
End of tes3mp change (major)
*/
}
else if (key->type == Type_MagicItem)
{
// equip, if it can be equipped
/*
Start of tes3mp change (major)
Instead of unilaterally using an item, send an ID_PLAYER_ITEM_USE packet and let the server
decide if the item actually gets used
*/
if (!item.getClass().getEquipmentSlots(item).first.empty())
{
/*
MWBase::Environment::get().getWindowManager()->useItem(item);
// make sure that item was successfully equipped
if (!store.isEquipped(item))
return;
}
*/
store.setSelectedEnchantItem(it);
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState_Spell);
mwmp::Main::get().getLocalPlayer()->sendItemUse(item, true, MWMechanics::DrawState_Spell);
}
//store.setSelectedEnchantItem(it);
//MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState_Spell);
/*
End of tes3mp change (major)
*/
}
}
else if (key->type == Type_Magic)

View file

@ -1675,7 +1675,7 @@ void LocalPlayer::sendSelectedSpell(const std::string& newSelectedSpellId)
getNetworking()->getPlayerPacket(ID_PLAYER_MISCELLANEOUS)->Send();
}
void LocalPlayer::sendItemUse(const MWWorld::Ptr& itemPtr)
void LocalPlayer::sendItemUse(const MWWorld::Ptr& itemPtr, bool itemMagicState, char drawState)
{
usedItem.refId = itemPtr.getCellRef().getRefId();
usedItem.count = itemPtr.getRefData().getCount();
@ -1683,6 +1683,9 @@ void LocalPlayer::sendItemUse(const MWWorld::Ptr& itemPtr)
usedItem.enchantmentCharge = itemPtr.getCellRef().getEnchantmentCharge();
usedItem.soul = itemPtr.getCellRef().getSoul();
usingItemMagic = itemMagicState;
itemUseDrawState = drawState;
getNetworking()->getPlayerPacket(ID_PLAYER_ITEM_USE)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_ITEM_USE)->Send();
}

View file

@ -95,7 +95,7 @@ namespace mwmp
void sendWerewolfState(bool isWerewolf);
void sendMarkLocation(const ESM::Cell& newMarkCell, const ESM::Position& newMarkPosition);
void sendSelectedSpell(const std::string& newSelectedSpellId);
void sendItemUse(const MWWorld::Ptr& itemPtr);
void sendItemUse(const MWWorld::Ptr& itemPtr, bool usingItemMagic = false, char itemUseDrawState = 0);
void sendCellStates();
void clearCellStates();

View file

@ -38,7 +38,24 @@ namespace mwmp
MWWorld::Ptr itemPtr = MechanicsHelper::getItemPtrFromStore(player->usedItem, inventoryStore);
if (itemPtr)
{
MWBase::Environment::get().getWindowManager()->getInventoryWindow()->useItem(itemPtr);
if (player->usingItemMagic)
{
MWWorld::ContainerStoreIterator storeIterator = inventoryStore.begin();
for (; storeIterator != inventoryStore.end(); ++storeIterator)
{
if (*storeIterator == itemPtr)
break;
}
inventoryStore.setSelectedEnchantItem(storeIterator);
}
if (player->itemUseDrawState != MWMechanics::DrawState_Nothing)
playerPtr.getClass().getNpcStats(playerPtr).setDrawState(static_cast<MWMechanics::DrawState_>(player->itemUseDrawState));
}
else
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Cannot use non-existent item %s", player->usedItem.refId.c_str());
}

View file

@ -326,6 +326,8 @@ namespace mwmp
std::string selectedSpellId;
mwmp::Item usedItem;
bool usingItemMagic;
char itemUseDrawState;
};
}

View file

@ -12,10 +12,12 @@ void PacketPlayerItemUse::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
RW(player->usedItem.refId, send, true);
RW(player->usedItem.count, send);
RW(player->usedItem.charge, send);
RW(player->usedItem.enchantmentCharge, send);
RW(player->usedItem.soul, send, true);
RW(player->usingItemMagic, send);
RW(player->itemUseDrawState, send);
}