예제 #1
0
int cItemGrid::ChangeSlotCount(int a_SlotNum, int a_AddToCount)
{
	if ((a_SlotNum < 0) || (a_SlotNum >= m_NumSlots))
	{
		LOGWARNING("%s: Invalid slot number %d out of %d slots, ignoring the call, returning -1",
			__FUNCTION__, a_SlotNum, m_NumSlots
		);
		return -1;
	}

	if (m_Slots[a_SlotNum].IsEmpty())
	{
		// The item is empty, it's not gonna change
		return 0;
	}
	
	if (m_Slots[a_SlotNum].m_ItemCount <= -a_AddToCount)
	{
		// Trying to remove more items than there already are, make the item empty
		m_Slots[a_SlotNum].Empty();
		TriggerListeners(a_SlotNum);
		return 0;
	}
	
	m_Slots[a_SlotNum].m_ItemCount += a_AddToCount;
	TriggerListeners(a_SlotNum);
	return m_Slots[a_SlotNum].m_ItemCount;
}
예제 #2
0
cItem cItemGrid::RemoveOneItem(int a_SlotNum)
{
	if ((a_SlotNum < 0) || (a_SlotNum >= m_NumSlots))
	{
		LOGWARNING("%s: Invalid slot number %d out of %d slots, ignoring the call, returning empty item",
			__FUNCTION__, a_SlotNum, m_NumSlots
		);
		return cItem();
	}
	
	// If the slot is empty, return an empty item
	if (m_Slots[a_SlotNum].IsEmpty())
	{
		return cItem();
	}
	
	// Make a copy of the item in slot, set count to 1 and remove one from the slot
	cItem res = m_Slots[a_SlotNum];
	res.m_ItemCount = 1;
	m_Slots[a_SlotNum].m_ItemCount -= 1;
	
	// Emptying the slot correctly if appropriate
	if (m_Slots[a_SlotNum].m_ItemCount == 0)
	{
		m_Slots[a_SlotNum].Empty();
	}
	
	// Notify everyone of the change
	TriggerListeners(a_SlotNum);
	
	// Return the stored one item
	return res;
}
예제 #3
0
int cItemGrid::RemoveItem(const cItem & a_ItemStack)
{
	int NumLeft = a_ItemStack.m_ItemCount;

	for (int i = 0; i < m_NumSlots; i++)
	{
		if (NumLeft <= 0)
		{
			break;
		}

		if (m_Slots[i].IsEqual(a_ItemStack))
		{
			int NumToRemove = std::min(NumLeft, static_cast<int>(m_Slots[i].m_ItemCount));
			NumLeft -= NumToRemove;
			m_Slots[i].m_ItemCount -= NumToRemove;

			if (m_Slots[i].m_ItemCount <= 0)
			{
				m_Slots[i].Empty();
			}

			TriggerListeners(i);
		}
	}

	return (a_ItemStack.m_ItemCount - NumLeft);
}
예제 #4
0
void cItemGrid::Clear(void)
{
	for (int i = 0; i < m_NumSlots; i++)
	{
		m_Slots[i].Empty();
		TriggerListeners(i);
	}
}
예제 #5
0
void cItemGrid::SetSlot(int a_SlotNum, const cItem & a_Item)
{
	if ((a_SlotNum < 0) || (a_SlotNum >= m_NumSlots))
	{
		LOGWARNING("%s: Invalid slot number %d out of %d slots",
			__FUNCTION__, a_SlotNum, m_NumSlots
		);
		return;
	}
	m_Slots[a_SlotNum] = a_Item;
	TriggerListeners(a_SlotNum);
}
예제 #6
0
int cItemGrid::AddItemToSlot(const cItem & a_ItemStack, int a_Slot, int a_Num, int a_MaxStack)
{
	int PrevCount = 0;
	if (m_Slots[a_Slot].IsEmpty())
	{
		m_Slots[a_Slot] = a_ItemStack;
		PrevCount = 0;
	}
	else
	{
		PrevCount = m_Slots[a_Slot].m_ItemCount;
	}
	m_Slots[a_Slot].m_ItemCount = std::min(a_MaxStack, PrevCount + a_Num);
	int toReturn = m_Slots[a_Slot].m_ItemCount - PrevCount;
	TriggerListeners(a_Slot);
	return toReturn;
}
void ClientSongManager::StopMainPlayerSong(bool notifyServer)
{
    // sending message
    if(notifyServer)
    {
        psStopSongMessage stopMessage;
        stopMessage.SendMessage();
    }

    // stopping song
    StopSong(mainSongID);
    mainSongID = NO_SONG;
    sheet.Empty();

    // updating listeners
    TriggerListeners();
}
예제 #8
0
void cItemGrid::EmptySlot(int a_SlotNum)
{
	if ((a_SlotNum < 0) || (a_SlotNum >= m_NumSlots))
	{
		LOGWARNING("%s: Invalid slot number %d out of %d slots",
			__FUNCTION__, a_SlotNum, m_NumSlots
		);
		return;
	}
	
	// Check if already empty:
	if (m_Slots[a_SlotNum].IsEmpty())
	{
		return;
	}
	
	// Empty and notify
	m_Slots[a_SlotNum].Empty();
	TriggerListeners(a_SlotNum);
}
void ClientSongManager::HandleMessage(MsgEntry* message)
{
    uint8_t msgType = message->GetType();

    // Playing
    if(msgType == MSGTYPE_PLAY_SONG)
    {
        uint songHandleID;
        csVector3 playerPos;
        iSoundManager* sndMngr;

        psPlaySongMessage playMsg(message);

        // getting player's position
        playerPos = psengine->GetCelClient()->FindObject(playMsg.songID)->GetMesh()->GetMovable()->GetFullPosition();

        // if sounds are not active the song will still be heard by players around
        sndMngr = psengine->GetSoundManager();
        if(sndMngr->IsSoundActive(iSoundManager::INSTRUMENT_SNDCTRL))
        {
            // playing
            if(playMsg.toPlayer)
            {
                songHandleID = PlaySong(sheet, playMsg.instrName, playerPos);
            }
            else
            {
                // decompressing score
                csString uncompressedScore;
                psMusic::ZDecompressSong(playMsg.musicalScore, uncompressedScore);

                songHandleID = PlaySong(uncompressedScore, playMsg.instrName, playerPos);
            }

            // handling instrument not defined
            if(songHandleID == 0)
            {
                // stopping song, informing server and player
                if(playMsg.toPlayer)
                {
                    // noticing server
                    StopMainPlayerSong(true);

                    // noticing user
                    psSystemMessage msg(0, MSG_ERROR, PawsManager::GetSingleton().Translate("You cannot play this song!"));
                    msg.FireEvent();
                }

                return;
            }

            // saving song ID
            if(playMsg.toPlayer)
            {
                mainSongID = songHandleID;
            }
            else
            {
                songMap.Put(playMsg.songID, songHandleID);
            }
        }
        else
        {
            mainSongID = NO_SONG;
        }
    }

    // Stopping
    else if(msgType == MSGTYPE_STOP_SONG)
    {
        psStopSongMessage stopMsg(message);

        if(stopMsg.toPlayer)
        {
            csString errorStr;

            if(mainSongID == (uint)PENDING) // no instrument equipped, invalid MusicXML or low skill
            {
                // updating mainSongId
                mainSongID = NO_SONG;

                // updating listeners
                TriggerListeners();
            }
            else if(mainSongID == NO_SONG) // sound are deactivated or song has ended
            {
                TriggerListeners();
            }
            else // player's mode has changed
            {
                StopMainPlayerSong(false);
            }

            // noticing user
            switch(stopMsg.errorCode)
            {
            case psStopSongMessage::ILLEGAL_SCORE:
                errorStr = "Illegal musical score!";
                break;
            case psStopSongMessage::NO_INSTRUMENT:
                errorStr = "You do not have an equipped musical instrument!";
                break;
            }

            if(!errorStr.IsEmpty())
            {
                psSystemMessage msg(0, MSG_ERROR, PawsManager::GetSingleton().Translate(errorStr));
                msg.FireEvent();
            }
        }
        else if(songMap.Contains(stopMsg.songID))
        {
            StopSong(songMap.Get(stopMsg.songID, 0));
            songMap.DeleteAll(stopMsg.songID);
        }
    }
}