void NowPlaying::init() { switch (formFactor()) { case Plasma::Horizontal: layoutHorizontal(); break; case Plasma::Vertical: layoutHorizontal(); // FIXME break; default: layoutPlanar(); break; } Plasma::DataEngine* nowPlayingEngine = dataEngine("nowplaying"); if (nowPlayingEngine) { connect(nowPlayingEngine, SIGNAL(sourceAdded(QString)), SLOT(playerAdded(QString))); connect(nowPlayingEngine, SIGNAL(sourceRemoved(QString)), SLOT(playerRemoved(QString))); findPlayer(); } else { kDebug() << "Now Playing engine not found"; } }
void NowPlaying::playerRemoved(const QString &name) { kDebug() << "Player" << name << "removed"; if (m_watchingPlayer == name) { findPlayer(); } }
void Stalfos::update(std::vector<std::shared_ptr<GameObject>>* worldMap) { if (isCollidingWithPlayer(worldMap)){ Player* temp = (Player*)findPlayer(worldMap).get(); temp->takeDamage(worldMap, this); } checkParalyzeStatus(); if (isCollidingWithBoomerang(worldMap)){ Sound::playSound(GameSound::EnemyHit); isParalyzed = true; ThrownBoomrang* boom = (ThrownBoomrang*)findBoomerang(worldMap).get(); if (!boom->isReturning) boom->isReturning = true; } if (pushbackStep == 0 && !isParalyzed){ movement(worldMap); tryToChangeDirection(); } else if(pushbackStep!=0 && !isParalyzed) pushbackUpdate(); for (int i = 0; i < 3; i++) walkingAnimation[i]->updateAnimationFrame(position); if (healthPoint <= 0) processDeath(worldMap); else checkInvincibility(); updateMasks(); }
void Spawn::checkSpawn() { checkSpawnEvent = 0; cleanup(); uint32_t spawnCount = 0; for (auto& it : spawnMap) { uint32_t spawnId = it.first; if (spawnedMap.find(spawnId) != spawnedMap.end()) { continue; } spawnBlock_t& sb = it.second; if (OTSYS_TIME() >= sb.lastSpawn + sb.interval) { if (findPlayer(sb.pos)) { sb.lastSpawn = OTSYS_TIME(); continue; } spawnMonster(spawnId, sb.mType, sb.pos, sb.direction); if (++spawnCount >= static_cast<uint32_t>(g_config.getNumber(ConfigManager::RATE_SPAWN))) { break; } } } if (spawnedMap.size() < spawnMap.size()) { checkSpawnEvent = g_scheduler.addEvent(createSchedulerTask(getInterval(), std::bind(&Spawn::checkSpawn, this))); } }
void Trap::update(std::vector<std::shared_ptr<GameObject>>* worldMap) { if (isActive) TrapMovement(); Player* temp = (Player*)findPlayer(worldMap).get(); if (isCollidingWithPlayer(worldMap)) temp->takeDamage(worldMap, this); float xDiff = std::abs(position.x - temp->position.x); float yDiff = std::abs(position.y - temp->position.y); if (xDiff <= Global::TileWidth && temp->position.y < position.y && !isActive){ dir = Direction::Up; isActive = true; moveSpeed = 4; } else if (xDiff <= Global::TileWidth && temp->position.y > position.y && !isActive){ dir = Direction::Down; isActive = true; moveSpeed = 4; } else if (yDiff <= Global::TileWidth && temp->position.x < position.x && !isActive){ dir = Direction::Left; isActive = true; moveSpeed = 4; } else if (yDiff <= Global::TileWidth && temp->position.x > position.x && !isActive){ dir = Direction::Right; isActive = true; moveSpeed = 4; } }
void Spawn::checkSpawn() { checkSpawnEvent = 0; cleanup(); uint32_t spawnCount = 0; uint32_t spawnId; for (SpawnMap::iterator it = spawnMap.begin(); it != spawnMap.end(); ++it) { spawnId = it->first; spawnBlock_t& sb = it->second; if (spawnedMap.find(spawnId) == spawnedMap.end()) { if (OTSYS_TIME() >= sb.lastSpawn + sb.interval) { if (findPlayer(sb.pos)) { sb.lastSpawn = OTSYS_TIME(); continue; } spawnMonster(spawnId, sb.mType, sb.pos, sb.direction); ++spawnCount; if (spawnCount >= (uint32_t)g_config.getNumber(ConfigManager::RATE_SPAWN)) { break; } } } } if (spawnedMap.size() < spawnMap.size()) { checkSpawnEvent = g_scheduler.addEvent(createSchedulerTask(getInterval(), boost::bind(&Spawn::checkSpawn, this))); } }
void Spawn::checkSpawn() { #ifdef __DEBUG_SPAWN__ std::clog << "[Notice] Spawn::checkSpawn " << this << std::endl; #endif Monster* monster; uint32_t spawnId; checkSpawnEvent = 0; for(SpawnedMap::iterator it = spawnedMap.begin(); it != spawnedMap.end();) { spawnId = it->first; monster = it->second; if(monster->isRemoved()) { if(spawnId) spawnMap[spawnId].lastSpawn = OTSYS_TIME(); monster->unRef(); spawnedMap.erase(it++); } else { /*if(spawnId && !isInSpawnZone(monster->getPosition()) && monster->getIdleStatus()) g_game.internalTeleport(monster, monster->getMasterPosition(), true); */++it; } } uint32_t spawnCount = 0; for(SpawnMap::iterator it = spawnMap.begin(); it != spawnMap.end(); ++it) { spawnId = it->first; spawnBlock_t& sb = it->second; if(spawnedMap.count(spawnId)) continue; if(OTSYS_TIME() < sb.lastSpawn + sb.interval) continue; if(findPlayer(sb.pos)) { sb.lastSpawn = OTSYS_TIME(); continue; } spawnMonster(spawnId, sb.mType, sb.pos, sb.direction); ++spawnCount; if(spawnCount >= (uint32_t)g_config.getNumber(ConfigManager::RATE_SPAWN)) break; } if(spawnedMap.size() < spawnMap.size()) checkSpawnEvent = Scheduler::getInstance().addEvent(createSchedulerTask(getInterval(), boost::bind(&Spawn::checkSpawn, this))); #ifdef __DEBUG_SPAWN__ else std::clog << "[Notice] Spawn::checkSpawn stopped " << this << std::endl; #endif }
void Room::onReqJoinGame(ServiceConnection* conn, MSG_HEAD_BACK* head, char* body) { Player* player = findPlayer(head->pid); err_t err = tryEnterTable(head->tid, player); if (err) enterGameFailed(conn, player, err); else enterGameSuccess(conn, player, err); }
void Triforce::update(std::vector<std::shared_ptr<GameObject>>* Worldmap) { sprite.setPosition(position.x, position.y); if (isCollidingWithPlayer(Worldmap) && !isObtained) { Player* tmp = ((Player*)findPlayer(Worldmap).get()); position.y = tmp->position.y - Global::TileHeight; position.x = tmp->position.x; tmp->isObtainingItem = true; tmp->sprite.setPosition(tmp->position.x, tmp->position.y); Sound::stopSound(GameSound::Underworld); Sound::playSound(GameSound::NewInventoryItem); Sound::playSound(GameSound::Triforce); tmp->inventory->playerBar->healPlayerToFull(); if (tmp->inventory->playerBar->currentDungeon == DungeonLevel::ONE) tmp->inventory->hasDungeon1Triforce = true; isObtained = true; } if (isObtained){ currentFrame++; if (currentFrame > maxFrame){ Player* temp = ((Player*)findPlayer(Worldmap).get()); temp->isObtainingItem = false; Sound::playSound(GameSound::OverWorld); //previousWorld must be same as current room when moving to overworld layer otherwise the player //wont be moved to the correct vector and game will crash when looking for player in the new layer. temp->prevWorldX = temp->position.y / Global::roomHeight; temp->prevWorldY = temp->position.x / Global::roomWidth; temp->currentLayer = Layer::OverWorld; temp->prevLayer = Layer::Dungeon; temp->position = getReturnPointForPlayerLeavingDungeon(temp->inventory->playerBar->currentDungeon); temp->worldX = temp->position.y / Global::roomHeight; temp->worldY = temp->position.x / Global::roomWidth; float inventoryNewX = temp->worldY*Global::roomHeight; float inventoryNewY = temp->worldX*Global::roomWidth; temp->inventory->playerBar->currentDungeon = DungeonLevel::NONE; temp->inventory->setInventoryPosition(Point(inventoryNewX, inventoryNewY)); temp->inventory->playerBar->setPlayerBar(Point(inventoryNewX, inventoryNewY)); for (int i = 0; i < temp->walkingAnimation.size(); i++) { temp->walkingAnimation[i]->sprite.setPosition(temp->position.x, temp->position.y); temp->attackAnimation[i]->sprite.setPosition(temp->position.x, temp->position.y); temp->movePlayerToNewVector = true; } Global::gameView.setCenter(temp->worldY*Global::roomWidth + Global::SCREEN_WIDTH / 2, temp->worldX*Global::roomHeight + Global::SCREEN_HEIGHT / 2); destroyGameObject(Worldmap); } } }
void QBSoundWin::stopEffect(unsigned int nSoundId) { QBSoundLocker locker(&mMutex,"stopEffect"); PlayerList::iterator p = streamTrack.find(nSoundId); if (p != streamTrack.end()) { findPlayer(nSoundId)->stop(); } }
void ThrownArrow::update(std::vector<std::shared_ptr<GameObject>>* worldMap) { arrowMovement(); if(isCollidingWithMonster(worldMap)){ if(!((Monster*)collidingMonster.get())->isInvincible) destroyGameObject(worldMap); ((Monster*)collidingMonster.get())->takeDamage(arrowStrength, worldMap,arrowDir); std::shared_ptr<GameObject> temp = findPlayer(worldMap); Player* player = (Player*)temp.get(); player->arrowIsActive = false; } else if(isOutsideRoomBound(position)){ destroyGameObject(worldMap); std::shared_ptr<GameObject> temp = findPlayer(worldMap); Player* player = (Player*)temp.get(); player->arrowIsActive = false; } }
void Candle::onUse(Point pos, std::vector<std::shared_ptr<GameObject>>* worldMap, Direction dir) { Player* tmp = (Player*)findPlayer(worldMap).get(); std::cout << "Candle Used"; Sound::playSound(GameSound::CandleFire); destroyOtherFlame(worldMap); std::shared_ptr<CandleFlame> fire = std::make_shared<CandleFlame>(tmp->position,dir); Static::toAdd.push_back(fire); }
bool GameObject::isCollidingWithPlayer(std::vector<std::shared_ptr<GameObject>>* worldMap) { bool isColliding = false; Point offset(0, 0); Player* player =(Player*)findPlayer(worldMap).get(); if(intersect(player->fullMask, mask, offset)) isColliding = true; return isColliding; }
void DungeonMap::update(std::vector<std::shared_ptr<GameObject>>* Worldmap) { if (isCollidingWithPlayer(Worldmap)){ Player* player = (Player*)findPlayer(Worldmap).get(); Sound::playSound(GameSound::NewInventoryItem); player->inventory->playerBar->hasDungeonMap = true; destroyGameObject(Worldmap); } }
bool QBSoundWin::streamIsPlaying(int track) { QBSoundLocker locker(&mMutex,"streamStop"); PlayerList::iterator p = streamTrack.find(track); if (p == streamTrack.end()) { return false; } return findPlayer(track)->isPlaying(); }
bool CLounge::cancelQueuePlayerLogic(int queueNumber, const char* username) { CPlayer* player = findPlayer(username); CWaitingList* wlist = findWaitingList(queueNumber); if (!wlist || !player) return false; else return cancelQueuePlayerLogic(wlist, player); }
bool PlayerDatabase::validatePlayer(std::string name, std::string password) { Player* player = findPlayer(name); if (!player || player->mNetID != -1 || player->mPassword != password) return false; return true; }
void PlayerDatabase::logoutPlayer(int netID) { Player* player = findPlayer(netID); if (!player) return; mEngine->getScene()->removeEntity(player->mEntity); player->mNetID = -1; }
bool Goblin::update( int key ) { int newx=x,newy=y; int tx=rand()%10+x-5,ty=rand()%10-5+y; checked.clear(); findPlayer(tx,ty,currentRoom,player->x,player->y); start: newx=x; newy=y; if(tx!=x && ty==y) goto mx; if(ty!=y && tx==x) goto my; if(ty!=y && tx!=x) if(rand()%2==0) goto mx; else goto my; goto end; mx: newx=x-sign(x-tx); if(moveTo(newx,newy)) return 0; if((newx!=x || newy!=y) && ty!=y) { newx=x; tx=x; goto my; } goto end; my: newy=y-sign(y-ty); if(moveTo(newx,newy)) return 0; if((newx!=x || newy!=y) && tx!=x) { newy=y; ty=y; goto mx; } goto end; end: if(newx!=x) { ty+=rand()%3-1; goto start; } if(newy!=y) { tx+=rand()%3-1; goto start; } return 0; }
void DixitGame::describe(DixitGame::UniqueId uid, const QString &desc) { Player *pp = findPlayer(uid); if (pp == nullptr) return; if (pp->getActive() == false) return; if (description() == desc) return; setDescription(desc); message(QString("玩家%1的描述是\n %2").arg(pp->getId()).arg(desc)); setMessage(); }
void WoodSwordPickUp::update(std::vector<std::shared_ptr<GameObject>>* Worldmap) { sprite.setPosition(position.x, position.y); if(isCollidingWithPlayer(Worldmap) && !isObtained) { Player* tmp = ((Player*)findPlayer(Worldmap).get()); position.y = tmp->position.y-Global::TileHeight; position.x = tmp->position.x; tmp->inventory->playerBar->mySword = SwordType::WoodSword; tmp->isObtainingItem = true; tmp->sprite.setPosition(tmp->position.x, tmp->position.y); Sound::playSound(GameSound::NewItem); Sound::playSound(GameSound::NewInventoryItem); isObtained = true; } if(isObtained){ currentFrame++; if(currentFrame > maxFrame){ Player* tmp = ((Player*)findPlayer(Worldmap).get()); tmp->isObtainingItem = false; deleteNpcFromCurrentRoom(Worldmap); destroyGameObject(Worldmap); } } }
bool PlayerDatabase::loginPlayer(std::string name, int netID) { Player* player = findPlayer(name); if (!player || player->mNetID != -1) return false; mEngine->getScene()->addEntity(player->mEntity); player->mNetID = netID; reinterpret_cast<IntentComponent*>(player->mEntity->getComponent(IntentComponent::Type))->setNetID(netID); return true; }
void CTable::reseatPlayer(const char* username, u_int32_t addr, u_int16_t port) { SingleLock l(&tableMutex_); if (l.lock()) { CPlayer* player = findPlayer(username); if (player && player->getChips() > 0) { CpduClientReseat pdu; pdu.sendReseat(player->getConnfd(), addr, port); } } }
unsigned int QBSoundWin::playEffect(const char* filename,bool bLoop,float pitch, float pan, float gain) { QBSoundLocker locker(&mMutex,"playEffect"); if (filename) { unsigned int nRet = _Hash(filename); do { if (filename==NULL) break; unsigned int nRet = _Hash(filename); if (sharedList().end() != sharedList().find(nRet)) break; sharedList().insert(make_pair(nRet,new EffectBuffer())); EffectBuffer* buffer = sharedList()[nRet]; if (buffer->load(filename)!=0) { sharedList().erase(nRet); } } while (0); EffectList::iterator p = sharedList().find(nRet); if (p != sharedList().end()) { EffectBuffer* effect = p->second; findPlayer(soundID)->setVolume(gain); findPlayer(soundID)->play((unsigned char*)effect->pcmbuffer,effect->pcmsize); soundID ++; if (soundID > 9999) soundID = 1; } return soundID; } return 0; }
void Match::dodge(Player *p) { int randRating = Player::maxRating + 1; //cout << " Jumps"; int team = p->getTeam(), oppTeam; Player *opp; if(team == 1) { oppTeam = 2; opp = teamTwo->getPlayer(checkSquare(p, 1)); } else if(team == 2) { oppTeam = 1; opp = teamOne->getPlayer(checkSquare(p, 2)); } int attackRoll = (rand()%randRating) + opp->getAttack(); int dodgeRoll = (rand()%randRating) + p->getJump(); if(attackRoll > dodgeRoll) { //cout << " but is killed by Kills " << opp->getName() << endl; p->kill(); playersToMove.erase(playersToMove.begin()+ findPlayer(p)); ball->drop(); screen->updateKill(opp, p); screen->updateKillFeed(opp, p); } else { screen->updateDodge(opp, p); //cout << " and gets past" << opp->getName() << endl; if(team == 1) { p->setPosX(p->getPosX() + 1); } else if(team == 2) { p->setPosX(p->getPosX() - 1); } if(p->getNumber() == ball->getPlayer()) { updateBall(p); } } }
void DixitGame::select(DixitGame::UniqueId uid, int card) { Player *pp = findPlayer(uid); if (pp == nullptr) return; if (pp->getActive()) return; if (pp->getSelected()) return; pp->setSelected(card); if (notYetSelected() > 0) setMessage(QString("还有%1位玩家未选择。").arg(notYetSelected())); else { setMessage(); emit allSelected(); } }
void DixitGame::play(DixitGame::UniqueId uid, int card) { Player *pp = findPlayer(uid); if (pp == nullptr) return; if (pp->getPlayed()) return; pp->setPlayed(); pp->getHandCards().removeAll(card); addToTable(card); if (notYetPlayed() > 0) setMessage(QString("还有%1位玩家未出牌。").arg(notYetPlayed())); else { setMessage(); emit allPlayed(); } }
void DixitGame::ready(DixitGame::UniqueId uid) { Player *pp = findPlayer(uid); if (pp == nullptr) return; if (pp->getReady()) return; pp->setReady(); emit playerChanged(pp); message(QString("玩家%1准备就绪。").arg(pp->getId())); if (notYetReady() > 0) setMessage(QString("还有%1位玩家没有准备。").arg(notYetReady())); else { setMessage(); emit gameBegin(); } }
void Match::attack(Player *p) { int randRating = Player::maxRating + 1; //cout << " Attacks"; int n = p->getTeam(), oppTeam; Player *opp; if(n == 1) { oppTeam = 2; opp = teamTwo->getPlayer(checkSquare(p, n)); } else if(n == 2) { oppTeam = 1; opp = teamOne->getPlayer(checkSquare(p, n)); } int attackRoll = (rand()%randRating) + p->getAttack(); int dodgeRoll = (rand()%randRating) + opp->getJump(); if(attackRoll > dodgeRoll) { //cout << " and Kills " << opp->getName() << endl; opp->kill(); playersToMove.erase(playersToMove.begin()+ findPlayer(opp)); screen->updateKillFeed(p, opp); if(ball->getPlayer() == opp->getNumber()) { screen->updateKill(p, opp); ball->drop(); } } else { if(ball->getPlayer() == opp->getNumber()) { screen->updateDodge(p, opp); ball->drop(); } //cout << " but misses " << opp->getName() << endl; } }
void ThrownBoomrang::setDiagonalSpeed(std::vector<std::shared_ptr<GameObject>>* worldMap) { Player* temp = ((Player*)findPlayer(worldMap).get()); Point playerPos = temp->position; float ratio,factor; stepsYToPlayer = std::abs(position.y - playerPos.y); stepsXToPlayer = std::abs(position.x - playerPos.x); if(stepsXToPlayer > stepsYToPlayer && stepsYToPlayer!=0){ ratio = stepsXToPlayer / stepsYToPlayer; diagonalXspeed = boomrangSpeed; factor = boomrangSpeed / ratio; diagonalYspeed = 1 * factor; } else if(stepsXToPlayer < stepsYToPlayer && stepsXToPlayer != 0) { ratio = stepsYToPlayer / stepsXToPlayer; factor = boomrangSpeed / ratio; diagonalYspeed = boomrangSpeed; diagonalXspeed = 1 * factor; } }