Ejemplo n.º 1
0
BOOL SFFreeForAll::OnPlayerHealth(SFPlayer* pPlayer, BasePacket* pPacket)
{
	SFRoom* pRoom = GetOwner()->GetOwner();

	SFProtobufPacket<SFPacketStore::MSG_PLAYER_HEALTH>* pHealth = (SFProtobufPacket<SFPacketStore::MSG_PLAYER_HEALTH>*)pPacket;
	
	PlayerHealthMsg msg;

	SF_GETPACKET_ARG(&msg, pHealth->GetData().playerhealth(), PlayerHealthMsg);

	SFPlayer* pHurtPlayer = NULL;
	SFRoom::RoomMemberMap MemberMap = pRoom->GetRoomMemberMap();
	SFRoom::RoomMemberMap::iterator iter = MemberMap.begin();

	for(; iter != MemberMap.end();iter++)
	{
		if(iter->second->GetSerial() == msg.PlayerID)
		{
			pHurtPlayer = iter->second;
			break;
		}
	}

	if(pHurtPlayer == NULL)
		return FALSE;

	_CharacterInfo* pInfo = pHurtPlayer->GetCharacterInfo();
	
	pInfo->health = msg.health;

	if(pInfo->health == 0)
	{
		pInfo->IsAlive = false;
		pInfo->DeathTime = GetTickCount();
	}
	
	iter = MemberMap.begin();

	for(; iter != MemberMap.end();iter++)
	{
		SFPlayer* pTarget = iter->second;
		SendPlayerHealth(pTarget, pHurtPlayer);
	}

	return TRUE;
}
Ejemplo n.º 2
0
int Zombie_Attack(GameObject* zombie, Scene* scene)
{
    zombie->ai.atkTimer--;
    for(int i = 0; i < scene->objCount; i++)
    {
        if(scene->objects[i].type == OBJECT_PLAYER)
        {
            int distance = GetDistance(zombie->rect, scene->objects[i].rect);
            if(scene->objects[i].playerInfo.alive==true){
            if(distance < zombie->ai.attackRange && zombie->ai.atkTimer <= 0)
            {
                scene->objects[i].playerInfo.health -= zombie->ai.damage;
                zombie->ai.atkTimer = zombie->ai.atkCd;
                printf("Player was damaged by Zombie.\n");
                printf("New health is: %d\n", scene->objects[i].playerInfo.health);
                SendPlayerHealth(scene->objects[i].obj_id, scene->objects[i].playerInfo.health);
            }
            break;
            }}
    }
    return EXIT_SUCCESS;
}