void cPlayer::FinishEating(void) { // Reset the timer: m_EatingFinishTick = -1; // Send the packets: m_ClientHandle->SendEntityStatus(*this, esPlayerEatingAccepted); m_World->BroadcastEntityAnimation(*this, 0); m_World->BroadcastEntityMetadata(*this); // consume the item: cItem Item(GetEquippedItem()); Item.m_ItemCount = 1; cItemHandler * ItemHandler = cItemHandler::GetItemHandler(Item.m_ItemType); if (!ItemHandler->EatItem(this, &Item)) { return; } ItemHandler->OnFoodEaten(m_World, this, &Item); GetInventory().RemoveOneEquippedItem(); //if the food is mushroom soup, return a bowl to the inventory if( Item.m_ItemType == E_ITEM_MUSHROOM_SOUP ) { cItem emptyBowl(E_ITEM_BOWL, 1, 0, ""); GetInventory().AddItem(emptyBowl, true, true); } }
void cPlayer::UseEquippedItem(int a_Amount) { if (IsGameModeCreative() || IsGameModeSpectator()) // No damage in creative or spectator { return; } // If the item has an unbreaking enchantment, give it a random chance of not breaking: cItem Item = GetEquippedItem(); int UnbreakingLevel = Item.m_Enchantments.GetLevel(cEnchantments::enchUnbreaking); if (UnbreakingLevel > 0) { int chance; if (ItemCategory::IsArmor(Item.m_ItemType)) { chance = 60 + (40 / (UnbreakingLevel + 1)); } else { chance = 100 / (UnbreakingLevel + 1); } cFastRandom Random; if (Random.NextInt(101) <= chance) { return; } } if (GetInventory().DamageEquippedItem(a_Amount)) { m_World->BroadcastSoundEffect("random.break", GetPosX(), GetPosY(), GetPosZ(), 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); } }
void cInventory::UpdateItems(void) { const cItem & Slot = GetEquippedItem(); if (!Slot.IsEmpty()) { ItemHandler(Slot.m_ItemType)->OnUpdate(m_Owner.GetWorld(), &m_Owner, Slot); } }
void cInventory::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) { // Send the neccessary updates to whoever needs them if (m_Owner.IsDestroyed()) { // Owner is not (yet) valid, skip for now return; } // Armor update needs broadcast to other players: cWorld * World = m_Owner.GetWorld(); if ((a_ItemGrid == &m_ArmorSlots) && (World != nullptr)) { World->BroadcastEntityEquipment( m_Owner, ArmorSlotNumToEntityEquipmentID(a_SlotNum), m_ArmorSlots.GetSlot(a_SlotNum), m_Owner.GetClientHandle() ); } // Broadcast the Equipped Item, if the Slot is changed. if ((a_ItemGrid == &m_HotbarSlots) && (m_EquippedSlotNum == a_SlotNum)) { m_Owner.GetWorld()->BroadcastEntityEquipment(m_Owner, 0, GetEquippedItem(), m_Owner.GetClientHandle()); } // Convert the grid-local a_SlotNum to our global SlotNum: int Base = 0; if (a_ItemGrid == &m_ArmorSlots) { Base = invArmorOffset; } else if (a_ItemGrid == &m_InventorySlots) { Base = invInventoryOffset; } else if (a_ItemGrid == &m_HotbarSlots) { Base = invHotbarOffset; } else { ASSERT(!"Unknown ItemGrid calling OnSlotChanged()"); return; } SendSlot(Base + a_SlotNum); }
void cPlayer::HandleFloater() { if (GetEquippedItem().m_ItemType == E_ITEM_FISHING_ROD) { return; } class cFloaterCallback : public cEntityCallback { public: virtual bool Item(cEntity * a_Entity) override { a_Entity->Destroy(true); return true; } } Callback; m_World->DoWithEntityByID(m_FloaterID, Callback); SetIsFishing(false); }
void cPlayer::FinishEating(void) { // Reset the timer: m_EatingFinishTick = -1; // Send the packets: m_ClientHandle->SendEntityStatus(*this, esPlayerEatingAccepted); m_World->BroadcastEntityMetadata(*this); // consume the item: cItem Item(GetEquippedItem()); Item.m_ItemCount = 1; cItemHandler * ItemHandler = cItemHandler::GetItemHandler(Item.m_ItemType); if (!ItemHandler->EatItem(this, &Item)) { return; } ItemHandler->OnFoodEaten(m_World, this, &Item); }
void cInventory::UpdateItems(void) { const cItem & Slot = GetEquippedItem(); if (Slot.IsEmpty()) { return; } switch (Slot.m_ItemType) { case E_ITEM_MAP: { ItemHandler(Slot.m_ItemType)->OnUpdate(m_Owner.GetWorld(), &m_Owner, Slot); break; } default: break; } }
RPG_InventoryItem* RPG_InventoryHandler::GetEquippedArmor(RPG_EquipmentSlot_e armorSlot) const { return GetEquippedItem(armorSlot); }
RPG_InventoryItem* RPG_InventoryHandler::GetEquippedWeapon() const { return GetEquippedItem(ES_Weapon); }