Initial fixes for ContainerSetSlotPacket and CraftItemPacket (#649)
This commit is contained in:
@@ -1093,6 +1093,10 @@ void PlayerConnection::handleContainerClose(shared_ptr<ContainerClosePacket> pac
|
||||
#ifndef _CONTENT_PACKAGE
|
||||
void PlayerConnection::handleContainerSetSlot(shared_ptr<ContainerSetSlotPacket> packet)
|
||||
{
|
||||
if(player->gameMode->isSurvival()){ // Still allow creative players to change slots manually with packets(?) -- might want this different.
|
||||
server->warn(L"Player " + player->getName() + L" just tried to set a slot in a container in survival mode");
|
||||
return;
|
||||
}
|
||||
if (packet->containerId == AbstractContainerMenu::CONTAINER_ID_CARRIED )
|
||||
{
|
||||
player->inventory->setCarried(packet->item);
|
||||
@@ -1589,6 +1593,10 @@ void PlayerConnection::handleCraftItem(shared_ptr<CraftItemPacket> packet)
|
||||
Recipy::INGREDIENTS_REQUIRED *pRecipeIngredientsRequired=Recipes::getInstance()->getRecipeIngredientsArray();
|
||||
shared_ptr<ItemInstance> pTempItemInst=pRecipeIngredientsRequired[iRecipe].pRecipy->assemble(nullptr);
|
||||
|
||||
size_t recipeCount = Recipes::getInstance()->getRecipies()->size();
|
||||
if (iRecipe < 0 || iRecipe >= (int)recipeCount)
|
||||
return;
|
||||
|
||||
if(app.DebugSettingsOn() && (player->GetDebugOptions()&(1L<<eDebugSetting_CraftAnything)))
|
||||
{
|
||||
pTempItemInst->onCraftedBy(player->level, dynamic_pointer_cast<Player>( player->shared_from_this() ), pTempItemInst->count );
|
||||
@@ -1607,9 +1615,21 @@ void PlayerConnection::handleCraftItem(shared_ptr<CraftItemPacket> packet)
|
||||
{
|
||||
|
||||
|
||||
// TODO 4J Stu - Assume at the moment that the client can work this out for us...
|
||||
//if(pRecipeIngredientsRequired[iRecipe].bCanMake)
|
||||
//{
|
||||
Recipy::INGREDIENTS_REQUIRED &req = pRecipeIngredientsRequired[iRecipe];
|
||||
if (req.iType == RECIPE_TYPE_3x3 && dynamic_cast<CraftingMenu *>(player->containerMenu) == NULL)
|
||||
{
|
||||
server->warn(L"Player " + player->getName() + L" tried to craft a 3x3 recipe without a crafting bench");
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < req.iIngC; i++){
|
||||
int need = req.iIngValA[i];
|
||||
int have = player->inventory->countResource(req.iIngIDA[i], req.iIngAuxValA[i]);
|
||||
if (have < need){
|
||||
server->warn(L"Player " + player->getName() + L" just tried to craft item " + to_wstring(pTempItemInst->id) + L" with insufficient ingredients");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
pTempItemInst->onCraftedBy(player->level, dynamic_pointer_cast<Player>( player->shared_from_this() ), pTempItemInst->count );
|
||||
|
||||
// and remove those resources from your inventory
|
||||
|
||||
@@ -343,6 +343,18 @@ bool Inventory::hasResource(int type)
|
||||
return true;
|
||||
}
|
||||
|
||||
int Inventory::countResource(int type, int auxVal)
|
||||
{
|
||||
int count = 0;
|
||||
for (unsigned int i = 0; i < items.length; i++)
|
||||
{
|
||||
if (items[i] != NULL && items[i]->id == type &&
|
||||
(auxVal == -1 || items[i]->getAuxValue() == auxVal))
|
||||
count += items[i]->count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void Inventory::swapSlots(int from, int to)
|
||||
{
|
||||
shared_ptr<ItemInstance> tmp = items[to];
|
||||
|
||||
@@ -68,6 +68,7 @@ public:
|
||||
shared_ptr<ItemInstance> getResourceItem(int type,int iAuxVal);
|
||||
|
||||
bool hasResource(int type);
|
||||
int countResource(int type, int auxVal);
|
||||
void swapSlots(int from, int to);
|
||||
bool add(shared_ptr<ItemInstance> item);
|
||||
shared_ptr<ItemInstance> removeItem(unsigned int slot, int count);
|
||||
|
||||
Reference in New Issue
Block a user