Ejemplo n.º 1
0
bool cInventory::DamageItem(int a_SlotNum, short a_Amount)
{
	if ((a_SlotNum < 0) || (a_SlotNum >= invNumSlots))
	{
		LOGWARNING("%s: requesting an invalid slot index: %d out of %d", __FUNCTION__, a_SlotNum, invNumSlots - 1);
		return false;
	}
	if (a_Amount <= 0)
	{
		return false;
	}
	
	int GridSlotNum = 0;
	cItemGrid * Grid = GetGridForSlotNum(a_SlotNum, GridSlotNum);
	if (Grid == nullptr)
	{
		LOGWARNING("%s(%d, %d): requesting an invalid grid, ignoring.", __FUNCTION__, a_SlotNum, a_Amount);
		return false;
	}
	if (!Grid->DamageItem(GridSlotNum, a_Amount))
	{
		// The item has been damaged, but did not break yet
		SendSlot(a_SlotNum);
		return false;
	}
	
	// The item has broken, remove it:
	Grid->EmptySlot(GridSlotNum);
	return true;
}
Ejemplo n.º 2
0
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);
}
Ejemplo n.º 3
0
int Transmit::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QGroupBox::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: TransTableClear(); break;
        case 1: SendSlot((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2])),(*reinterpret_cast< QString(*)>(_a[3])),(*reinterpret_cast< QTime(*)>(_a[4]))); break;
        case 2: TransTableSave(); break;
        default: ;
        }
        _id -= 3;
    }
    return _id;
}
Ejemplo n.º 4
0
void cInventory::SendEquippedSlot()
{
	int EquippedSlotNum = cInventory::invArmorCount + cInventory::invInventoryCount + GetEquippedSlotNum();
	SendSlot(EquippedSlotNum);
}