void cSlotAreaArmor::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) { if (ItemCategory::IsHelmet(a_ItemStack.m_ItemType) && GetSlot(0, a_Player)->IsEmpty()) { if (a_ShouldApply) { SetSlot(0, a_Player, a_ItemStack.CopyOne()); } a_ItemStack.m_ItemCount -= 1; } else if (ItemCategory::IsChestPlate(a_ItemStack.m_ItemType) && GetSlot(1, a_Player)->IsEmpty()) { if (a_ShouldApply) { SetSlot(1, a_Player, a_ItemStack.CopyOne()); } a_ItemStack.m_ItemCount -= 1; } else if (ItemCategory::IsLeggings(a_ItemStack.m_ItemType) && GetSlot(2, a_Player)->IsEmpty()) { if (a_ShouldApply) { SetSlot(2, a_Player, a_ItemStack.CopyOne()); } a_ItemStack.m_ItemCount -= 1; } else if (ItemCategory::IsBoots(a_ItemStack.m_ItemType) && GetSlot(3, a_Player)->IsEmpty()) { if (a_ShouldApply) { SetSlot(3, a_Player, a_ItemStack.CopyOne()); } a_ItemStack.m_ItemCount -= 1; } }
void Container::SwapItems(int8 SrcSlot, int8 DstSlot) { Item* temp; if (SrcSlot < 0 || SrcSlot >= (int8)m_itemProto->ContainerSlots) return; if (DstSlot < 0 || DstSlot >= (int8)m_itemProto->ContainerSlots) return; uint32 destMaxCount = (m_owner->ItemStackCheat) ? 0x7fffffff : ((m_Slot[DstSlot]) ? m_Slot[DstSlot]->GetProto()->MaxCount : 0); if (m_Slot[DstSlot] && m_Slot[SrcSlot] && m_Slot[DstSlot]->GetEntry() == m_Slot[SrcSlot]->GetEntry() && m_Slot[SrcSlot]->wrapped_item_id == 0 && m_Slot[DstSlot]->wrapped_item_id == 0 && destMaxCount > 1) { uint32 total = m_Slot[SrcSlot]->GetStackCount() + m_Slot[DstSlot]->GetStackCount(); m_Slot[DstSlot]->m_isDirty = m_Slot[SrcSlot]->m_isDirty = true; if (total <= destMaxCount) { m_Slot[DstSlot]->ModStackCount(m_Slot[SrcSlot]->GetStackCount()); SafeFullRemoveItemFromSlot(SrcSlot); return; } else { if (m_Slot[DstSlot]->GetStackCount() == destMaxCount) { } else { int32 delta = destMaxCount - m_Slot[DstSlot]->GetStackCount(); m_Slot[DstSlot]->SetStackCount(destMaxCount); m_Slot[SrcSlot]->ModStackCount(-delta); return; } } } temp = m_Slot[SrcSlot]; m_Slot[SrcSlot] = m_Slot[DstSlot]; m_Slot[DstSlot] = temp; if (m_Slot[DstSlot]) { SetSlot(DstSlot, m_Slot[DstSlot]->GetGUID()); m_Slot[DstSlot]->m_isDirty = true; } else { SetSlot(DstSlot, 0); } if (m_Slot[SrcSlot]) { SetSlot(SrcSlot, m_Slot[SrcSlot]->GetGUID()); m_Slot[SrcSlot]->m_isDirty = true; } else { SetSlot(SrcSlot, 0); } }
void cSlotAreaAnvil::OnTakeResult(cPlayer & a_Player) { if (!a_Player.IsGameModeCreative()) { a_Player.DeltaExperience(-cPlayer::XpForLevel(m_MaximumCost)); } SetSlot(0, a_Player, cItem()); if (m_StackSizeToBeUsedInRepair > 0) { const cItem * Item = GetSlot(1, a_Player); if (!Item->IsEmpty() && (Item->m_ItemCount > m_StackSizeToBeUsedInRepair)) { cItem NewSecondItem(*Item); NewSecondItem.m_ItemCount -= m_StackSizeToBeUsedInRepair; m_StackSizeToBeUsedInRepair = 0; SetSlot(1, a_Player, NewSecondItem); } else { SetSlot(1, a_Player, cItem()); } } else { SetSlot(1, a_Player, cItem()); } m_ParentWindow.SetProperty(0, m_MaximumCost, a_Player); m_MaximumCost = 0; ((cAnvilWindow*)&m_ParentWindow)->SetRepairedItemName("", NULL); int PosX, PosY, PosZ; ((cAnvilWindow*)&m_ParentWindow)->GetBlockPos(PosX, PosY, PosZ); BLOCKTYPE Block; NIBBLETYPE BlockMeta; a_Player.GetWorld()->GetBlockTypeMeta(PosX, PosY, PosZ, Block, BlockMeta); cFastRandom Random; if (!a_Player.IsGameModeCreative() && (Block == E_BLOCK_ANVIL) && (Random.NextFloat(1.0F) < 0.12F)) { NIBBLETYPE Orientation = BlockMeta & 0x3; NIBBLETYPE AnvilDamage = BlockMeta >> 2; ++AnvilDamage; if (AnvilDamage > 2) { // Anvil will break a_Player.GetWorld()->SetBlock(PosX, PosY, PosZ, E_BLOCK_AIR, (NIBBLETYPE)0); a_Player.GetWorld()->BroadcastSoundParticleEffect(1020, PosX, PosY, PosZ, 0); a_Player.CloseWindow(false); } else { a_Player.GetWorld()->SetBlockMeta(PosX, PosY, PosZ, Orientation | (AnvilDamage << 2)); a_Player.GetWorld()->BroadcastSoundParticleEffect(1021, PosX, PosY, PosZ, 0); } }
void cItemGrid::GenerateRandomLootWithBooks(const cLootProbab * a_LootProbabs, size_t a_CountLootProbabs, int a_NumSlots, int a_Seed) { // Calculate the total weight: int TotalProbab = 1; for (size_t i = 0; i < a_CountLootProbabs; i++) { TotalProbab += a_LootProbabs[i].m_Weight; } // Pick the loot items: cNoise Noise(a_Seed); for (int i = 0; i < a_NumSlots; i++) { int Rnd = (Noise.IntNoise1DInt(i) / 7); int LootRnd = Rnd % TotalProbab; Rnd >>= 8; cItem CurrentLoot = cItem(E_ITEM_BOOK, 1, 0); // TODO: enchantment for (size_t j = 0; j < a_CountLootProbabs; j++) { LootRnd -= a_LootProbabs[i].m_Weight; if (LootRnd < 0) { CurrentLoot = a_LootProbabs[i].m_Item; CurrentLoot.m_ItemCount = a_LootProbabs[i].m_MinAmount + (Rnd % (a_LootProbabs[i].m_MaxAmount - a_LootProbabs[i].m_MinAmount)); Rnd >>= 8; break; } } // for j - a_LootProbabs[] SetSlot(Rnd % m_NumSlots, CurrentLoot); } // for i - NumSlots
bool Container::AddItemToFreeSlot(Item* pItem, uint32* r_slot) { uint32 slot; for (slot = 0; slot < GetProto()->ContainerSlots; slot++) { if (!m_Slot[slot]) { m_Slot[slot] = pItem; pItem->m_isDirty = true; pItem->SetContainerGUID(GetGUID()); pItem->SetOwner(m_owner); SetSlot(uint16(slot), pItem->GetGUID()); if (m_owner->IsInWorld() && !pItem->IsInWorld()) { pItem->PushToWorld(m_owner->GetMapMgr()); ByteBuffer buf(2500); uint32 count = pItem->BuildCreateUpdateBlockForPlayer(&buf, m_owner); m_owner->PushCreationData(&buf, count); } if (r_slot) *r_slot = slot; #ifdef ENABLE_ACHIEVEMENTS m_owner->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_OWN_ITEM, pItem->GetProto()->ItemId, pItem->GetStackCount(), 0); #endif return true; } } return false; }
void cSlotAreaAnvil::ShiftClicked(cPlayer & a_Player, int a_SlotNum, const cItem & a_ClickedItem) { if (a_SlotNum != 2) { super::ShiftClicked(a_Player, a_SlotNum, a_ClickedItem); UpdateResult(a_Player); return; } // Make a copy of the slot, distribute it among the other areas, then update the slot to contain the leftover: cItem Slot(*GetSlot(a_SlotNum, a_Player)); if (Slot.IsEmpty() || !CanTakeResultItem(a_Player)) { return; } m_ParentWindow.DistributeStack(Slot, a_Player, this, true); if (Slot.IsEmpty()) { Slot.Empty(); OnTakeResult(a_Player); } SetSlot(a_SlotNum, a_Player, Slot); // Some clients try to guess our actions and not always right (armor slots in 1.2.5), so we fix them: m_ParentWindow.BroadcastWholeWindow(); }
bool cBeaconEntity::LoadFromJson(const Json::Value & a_Value) { m_PosX = a_Value.get("x", 0).asInt(); m_PosY = a_Value.get("y", 0).asInt(); m_PosZ = a_Value.get("z", 0).asInt(); Json::Value AllSlots = a_Value.get("Slots", 0); int SlotIdx = 0; for (Json::Value::iterator itr = AllSlots.begin(); itr != AllSlots.end(); ++itr) { cItem Item; Item.FromJson(*itr); SetSlot(SlotIdx, Item); SlotIdx++; } m_BeaconLevel = (char)a_Value.get("Level", 0).asInt(); int PrimaryEffect = a_Value.get("PrimaryEffect", 0).asInt(); int SecondaryEffect = a_Value.get("SecondaryEffect", 0).asInt(); if ((PrimaryEffect >= 0) && (PrimaryEffect <= (int)cEntityEffect::effSaturation)) { m_PrimaryEffect = (cEntityEffect::eType)PrimaryEffect; } if ((SecondaryEffect >= 0) && (SecondaryEffect <= (int)cEntityEffect::effSaturation)) { m_SecondaryEffect = (cEntityEffect::eType)SecondaryEffect; } return true; }
CWeaponPistol::CWeaponPistol(LPCSTR name) : CWeaponCustomPistol(name) { m_eSoundClose = ESoundTypes(SOUND_TYPE_WEAPON_RECHARGING /*| eSoundType*/); m_opened = false; m_bPending = false; SetSlot(PISTOL_SLOT); }
void cSlotAreaAnvil::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) { for (int i = 0; i < 2; i++) { const cItem * Slot = GetSlot(i, a_Player); if (!Slot->IsEqual(a_ItemStack) && (!Slot->IsEmpty() || a_KeepEmptySlots)) { // Different items continue; } int NumFit = ItemHandler(Slot->m_ItemType)->GetMaxStackSize() - Slot->m_ItemCount; if (NumFit <= 0) { // Full stack already continue; } if (NumFit > a_ItemStack.m_ItemCount) { NumFit = a_ItemStack.m_ItemCount; } if (a_ShouldApply) { cItem NewSlot(a_ItemStack); NewSlot.m_ItemCount = Slot->m_ItemCount + NumFit; SetSlot(i, a_Player, NewSlot); } a_ItemStack.m_ItemCount -= NumFit; if (a_ItemStack.IsEmpty()) { UpdateResult(a_Player); return; } } // for i - Slots UpdateResult(a_Player); }
Item* Container::SafeRemoveAndRetreiveItemFromSlot(int16 slot, bool destroy) { if (slot < 0 || (uint32)slot >= GetProto()->ContainerSlots) return NULL; Item* pItem = m_Slot[slot]; if (pItem == NULL || pItem == this) return NULL; m_Slot[slot] = NULL; if (pItem->GetOwner() == m_owner) { SetSlot(slot, 0); pItem->SetContainerGUID(0); if (destroy) { if (pItem->IsInWorld()) { pItem->RemoveFromWorld(); } pItem->DeleteFromDB(); } } else pItem = NULL; return pItem; }
int SimJointSetWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QWidget::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: UpdateODEJoint(); break; case 1: UpdateList(); break; case 2: SetSlot(); break; case 3: NameSlot((*reinterpret_cast< int(*)>(_a[1]))); break; case 4: PosXSlot((*reinterpret_cast< double(*)>(_a[1]))); break; case 5: PosYSlot((*reinterpret_cast< double(*)>(_a[1]))); break; case 6: PosZSlot((*reinterpret_cast< double(*)>(_a[1]))); break; case 7: ScaleXSlot((*reinterpret_cast< double(*)>(_a[1]))); break; case 8: ScaleYSlot((*reinterpret_cast< double(*)>(_a[1]))); break; case 9: ScaleZSlot((*reinterpret_cast< double(*)>(_a[1]))); break; case 10: RollSlot((*reinterpret_cast< double(*)>(_a[1]))); break; case 11: PitchSlot((*reinterpret_cast< double(*)>(_a[1]))); break; case 12: YawSlot((*reinterpret_cast< double(*)>(_a[1]))); break; case 13: OffsetXSlot((*reinterpret_cast< double(*)>(_a[1]))); break; case 14: OffsetYSlot((*reinterpret_cast< double(*)>(_a[1]))); break; case 15: OffsetZSlot((*reinterpret_cast< double(*)>(_a[1]))); break; case 16: VisibleSlot(); break; case 17: unVisibleSlot(); break; case 18: DestroySlot(); break; default: ; } _id -= 19; } return _id; }
bool cSlotArea::CollectItemsToHand(cItem & a_Dragging, cPlayer & a_Player, bool a_CollectFullStacks) { int NumSlots = GetNumSlots(); for (int i = 0; i < NumSlots; i++) { const cItem & SlotItem = *GetSlot(i, a_Player); if (!SlotItem.IsEqual(a_Dragging)) { continue; } int ToMove = a_Dragging.GetMaxStackSize() - a_Dragging.m_ItemCount; if (ToMove > SlotItem.m_ItemCount) { ToMove = SlotItem.m_ItemCount; } a_Dragging.m_ItemCount += ToMove; cItem NewSlot(SlotItem); NewSlot.m_ItemCount -= ToMove; SetSlot(i, a_Player, NewSlot); if (!NewSlot.IsEmpty()) { // There are leftovers in the slot, so a_Dragging must be full return true; } } // for i - Slots[] // a_Dragging may be full if there were exactly the number of items needed to fill it return a_Dragging.IsFullStack(); }
void cSlotArea::DblClicked(cPlayer & a_Player, int a_SlotNum) { cItem & Dragging = a_Player.GetDraggingItem(); if (Dragging.IsEmpty()) { // Move the item in the dblclicked slot into hand: Dragging = *GetSlot(a_SlotNum, a_Player); cItem EmptyItem; SetSlot(a_SlotNum, a_Player, EmptyItem); } if (Dragging.IsEmpty()) { LOGD("%s DblClicked with an empty hand over empty slot, ignoring", a_Player.GetName().c_str()); return; } // Add as many items from the surrounding area into hand as possible: // First skip full stacks, then if there's still space, process full stacks as well: if (!m_ParentWindow.CollectItemsToHand(Dragging, *this, a_Player, false)) { m_ParentWindow.CollectItemsToHand(Dragging, *this, a_Player, true); } m_ParentWindow.BroadcastWholeWindow(); // We need to broadcast, in case the window was a chest opened by multiple players }
void cSlotAreaCrafting::UpdateRecipe(cPlayer & a_Player) { cCraftingGrid Grid(GetPlayerSlots(a_Player) + 1, m_GridSize, m_GridSize); cCraftingRecipe & Recipe = GetRecipeForPlayer(a_Player); cRoot::Get()->GetCraftingRecipes()->GetRecipe(&a_Player, Grid, Recipe); SetSlot(0, a_Player, Recipe.GetResult()); m_ParentWindow.SendSlot(a_Player, this, 0); }
CWeaponKnife::CWeaponKnife() : CWeapon("KNIFE") { m_attackStart = false; SetState ( eHidden ); SetNextState ( eHidden ); knife_material_idx = (u16)-1; SetSlot (KNIFE_SLOT); }
Package::Package(Engine* eng, Type* pkgType, String* n, Package* superPkg) : Object(eng, pkgType), name(n), dotName(0), superPackage(superPkg) { SetName(n); SetSlot("__package", this, Slot::ATTR_internal | Slot::ATTR_forcewrite); }
StateLabel::StateLabel (bool aLoad) : SummerfaceLabel(Area(10, 85, 25, 6), ""), Slot(1), Load(aLoad) { MDFNI_SelectState(1); Slot = StateStatusInfo ? StateStatusInfo->recently_saved : Slot; Slot = (Slot < 1 || Slot > 9) ? 1 : Slot; SetSlot(Slot); }
void CInventoryItem::load(IReader &packet) { m_eItemPlace = (EItemPlace)packet.r_u8(); m_fCondition = packet.r_float(); SetSlot (packet.r_u8()); if (GetSlot() == 255) SetSlot (NO_ACTIVE_SLOT); u8 tmp = packet.r_u8(); if (!tmp) return; if (!object().PPhysicsShell()) { object().setup_physic_shell (); object().PPhysicsShell()->Disable(); } object().PHLoadState(packet); object().PPhysicsShell()->Disable(); }
void cSlotAreaInventoryBase::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) { if ((a_Player.GetGameMode() == eGameMode_Creative) && (m_ParentWindow.GetWindowType() == cWindow::Inventory)) { // Creative inventory must treat a_ClickedItem as a DraggedItem instead, replacing the inventory slot with it SetSlot(a_SlotNum, a_Player, a_ClickedItem); return; } // Survival inventory and all other windows' inventory has the same handling as normal slot areas super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem); return; }
void StyleSet::Set(const StyleAttrib& attrib, Pool* pool) { int32_t slot = GetSlot(attrib.GetCategory()); if (slot != 0) { Attribs[slot - 1] = attrib; return; } if (Count >= Capacity) Grow(pool); Attribs[Count] = attrib; SetSlot(attrib.GetCategory(), Count + SlotOffset); Count++; //DebugCheckSanity(); }
void cItemGrid::GenerateRandomLootWithBooks(const cLootProbab * a_LootProbabs, size_t a_CountLootProbabs, int a_NumSlots, int a_Seed) { // Calculate the total weight: int TotalProbab = 1; for (size_t i = 0; i < a_CountLootProbabs; i++) { TotalProbab += a_LootProbabs[i].m_Weight; } // Pick the loot items: cNoise Noise(a_Seed); for (int i = 0; i < a_NumSlots; i++) { int Rnd = (Noise.IntNoise1DInt(i) / 7); int LootRnd = Rnd % TotalProbab; Rnd >>= 8; cItem CurrentLoot = cItem(E_ITEM_ENCHANTED_BOOK, 1, 0); // Choose the enchantments cWeightedEnchantments Enchantments; cEnchantments::AddItemEnchantmentWeights(Enchantments, E_ITEM_BOOK, 24 + Noise.IntNoise2DInt(a_Seed, TotalProbab) % 7); int NumEnchantments = Noise.IntNoise3DInt(TotalProbab, Rnd, a_Seed) % 5; // The number of enchantments this book wil get. for (int j = 0; j <= NumEnchantments; j++) { cEnchantments Enchantment = cEnchantments::SelectEnchantmentFromVector(Enchantments, Noise.IntNoise2DInt(NumEnchantments, i)); CurrentLoot.m_Enchantments.Add(Enchantment); cEnchantments::RemoveEnchantmentWeightFromVector(Enchantments, Enchantment); cEnchantments::CheckEnchantmentConflictsFromVector(Enchantments, Enchantment); } for (size_t j = 0; j < a_CountLootProbabs; j++) { LootRnd -= a_LootProbabs[j].m_Weight; if (LootRnd < 0) { CurrentLoot = a_LootProbabs[j].m_Item; if ((a_LootProbabs[j].m_MaxAmount - a_LootProbabs[j].m_MinAmount) > 0) { CurrentLoot.m_ItemCount = static_cast<char>(a_LootProbabs[j].m_MinAmount + (Rnd % (a_LootProbabs[j].m_MaxAmount - a_LootProbabs[j].m_MinAmount))); } else { CurrentLoot.m_ItemCount = static_cast<char>(a_LootProbabs[j].m_MinAmount); } Rnd >>= 8; break; } } // for j - a_LootProbabs[] SetSlot(Rnd % m_NumSlots, CurrentLoot); } // for i - NumSlots
void cSlotArea::ShiftClicked(cPlayer & a_Player, int a_SlotNum, const cItem & a_ClickedItem) { // Make a copy of the slot, distribute it among the other areas, then update the slot to contain the leftover: cItem Slot(*GetSlot(a_SlotNum, a_Player)); m_ParentWindow.DistributeStack(Slot, a_Player, this, true); if (Slot.IsEmpty()) { // Empty the slot completely, the cilent doesn't like left-over ItemType with zero count Slot.Empty(); } SetSlot(a_SlotNum, a_Player, Slot); // Some clients try to guess our actions and not always right (armor slots in 1.2.5), so we fix them: m_ParentWindow.BroadcastWholeWindow(); }
bool Container::AddItem(int16 slot, Item* item) { if (slot < 0 || (uint32)slot >= GetProto()->ContainerSlots) return false; //ARCEMU_ASSERT( m_Slot[slot] == NULL); if (m_Slot[slot] != NULL) { //sLog.outString("Bad container item %u slot %d", item->GetGUID(), slot); return false; } if (!m_owner) return false; m_Slot[slot] = item; item->m_isDirty = true; item->SetContainerGUID(GetGUID()); item->SetOwner(m_owner); if (item->GetProto()->Bonding == ITEM_BIND_ON_PICKUP) { if (item->GetProto()->Flags & ITEM_FLAG_ACCOUNTBOUND) // don't "Soulbind" account-bound items item->AccountBind(); else item->SoulBind(); } SetSlot(slot, item->GetGUID()); //new version to fix bag issues if (m_owner->IsInWorld() && !item->IsInWorld()) { //item->AddToWorld(); item->PushToWorld(m_owner->GetMapMgr()); ByteBuffer buf(3000); uint32 count = item->BuildCreateUpdateBlockForPlayer(&buf, m_owner); m_owner->PushCreationData(&buf, count); } #ifdef ENABLE_ACHIEVEMENTS m_owner->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_OWN_ITEM, item->GetProto()->ItemId, item->GetStackCount(), 0); #endif return true; }
bool cChestEntity::LoadFromJson(const Json::Value & a_Value) { m_PosX = a_Value.get("x", 0).asInt(); m_PosY = a_Value.get("y", 0).asInt(); m_PosZ = a_Value.get("z", 0).asInt(); Json::Value AllSlots = a_Value.get("Slots", 0); int SlotIdx = 0; for (Json::Value::iterator itr = AllSlots.begin(); itr != AllSlots.end(); ++itr) { cItem Item; Item.FromJson(*itr); SetSlot(SlotIdx, Item); SlotIdx++; } return true; }
void Package::AddNative(RegisterFunction* fns, size_t count) { GCPAUSE_NORUN(engine); for (size_t i = 0; i < count; ++i) { String* funname = engine->AllocString(fns[i].name); Def* fn = Def::CreateWith(engine, funname, fns[i].code, fns[i].argc, fns[i].flags, 0, fns[i].__doc); Value vname(funname); Value vfn(fn); Function* closure = Function::Create(engine, fn, this); Value vframe; vframe.Set(closure); SetSlot(vname, vframe); } }
void cSlotArea::NumberClicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction) { if ((a_ClickAction < caNumber1) || (a_ClickAction > caNumber9)) { return; } int HotbarSlot = (int)a_ClickAction - (int)caNumber1; cItem ItemInHotbar(a_Player.GetInventory().GetHotbarSlot(HotbarSlot)); cItem ItemInSlot(*GetSlot(a_SlotNum, a_Player)); // The items are equal. Do nothing. if (ItemInHotbar.IsEqual(ItemInSlot)) { return; } a_Player.GetInventory().SetHotbarSlot(HotbarSlot, ItemInSlot); SetSlot(a_SlotNum, a_Player, ItemInHotbar); }
void cSlotAreaEnchanting::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_Apply, bool a_KeepEmptySlots) { const cItem * Slot = GetSlot(0, a_Player); if (!Slot->IsEmpty()) { return; } if (a_Apply) { SetSlot(0, a_Player, a_ItemStack.CopyOne()); } a_ItemStack.m_ItemCount -= 1; if (a_ItemStack.m_ItemCount <= 0) { a_ItemStack.Empty(); } UpdateResult(a_Player); }
bool Container::SafeFullRemoveItemFromSlot(int16 slot) { if (slot < 0 || (uint32)slot >= GetProto()->ContainerSlots) return false; Item* pItem = m_Slot[slot]; if (pItem == NULL || pItem == this) return false; m_Slot[slot] = NULL; SetSlot(slot, 0); pItem->SetContainerGUID(0); if (pItem->IsInWorld()) { pItem->RemoveFromWorld(); } pItem->DeleteFromDB(); pItem->DeleteMe(); return true; }
bool cFurnaceEntity::LoadFromJson(const Json::Value & a_Value) { m_PosX = a_Value.get("x", 0).asInt(); m_PosY = a_Value.get("y", 0).asInt(); m_PosZ = a_Value.get("z", 0).asInt(); Json::Value AllSlots = a_Value.get("Slots", 0); int SlotIdx = 0; for (Json::Value::iterator itr = AllSlots.begin(); itr != AllSlots.end(); ++itr) { cItem Item; Item.FromJson(*itr); SetSlot(SlotIdx, Item); SlotIdx++; } m_NeedCookTime = (int)(a_Value.get("CookTime", 0).asDouble() / 50); m_TimeCooked = (int)(a_Value.get("TimeCooked", 0).asDouble() / 50); m_FuelBurnTime = (int)(a_Value.get("BurnTime", 0).asDouble() / 50); m_TimeBurned = (int)(a_Value.get("TimeBurned", 0).asDouble() / 50); return true; }
void cSlotArea::DropClicked(cPlayer & a_Player, int a_SlotNum, bool a_DropStack) { cItem Slot(*GetSlot(a_SlotNum, a_Player)); if (Slot.IsEmpty()) { return; } cItem ItemToDrop = Slot.CopyOne(); if (a_DropStack) { ItemToDrop.m_ItemCount = Slot.m_ItemCount; } Slot.m_ItemCount -= ItemToDrop.m_ItemCount; if (Slot.m_ItemCount <= 0) { Slot.Empty(); } SetSlot(a_SlotNum, a_Player, Slot); a_Player.TossPickup(ItemToDrop); }