Ejemplo n.º 1
0
void CShop::onScoreItemCallback(Ref* pSender)
{
	std::string num;
	Label* tRemain=(Label*)this->getChildByTag(101);
	Label* tScore = (Label*)this->getChildByTag(102);

	auto m_score = CScore::getInstance();

	log("Gold %d", m_score->getGold());

	if (m_score->getGold()>=100 && m_score->getMultScore()<100)
	{
		//点击

		if (AudioController::getInstance()->isMusicOpen())
		{
			AudioController::getInstance()->clickOk();
		}

		//金币数量减少
		m_score->useGold(100);
		m_score->storeGold();

		log("Gold use %d", m_score->getGold());

		num = String::createWithFormat("%d", CScore::getInstance()->getGold())->_string;
		tRemain->setString(num);

		//道具数量增加 
		m_score->addMultScore(1);
		m_score->storeMultScore();

		num = String::createWithFormat("%d", CScore::getInstance()->getMultScore())->_string;
		tScore->setString(num);
	}
	else
	{
		//非法点击
		if (AudioController::getInstance()->isMusicOpen())
		{
			AudioController::getInstance()->clickNo();
		}
	}
}
Ejemplo n.º 2
0
void Hero::showStatus()
{
    if (!m_menuWindow)
    {
        m_menuWindow = WindowSharedPtr(new Window());
        m_menuWindow->setPosition(2, 1, 0);
        m_menuWindow->setHorizontalAlign(Window::HorizontalAlign::LEFT);
        m_menuWindow->setVerticalAlign(Window::VerticalAlign::BOTTOM);
        m_menuWindow->setMaxWidth(50);
    }

    Window* w = m_menuWindow.get();

    w->setTitle("Status");
    w->clear();

    w->print(Colors::ORANGE(), "NAME:");
    w->print(Colors::WHITE(), getName());

    w->print(Colors::ORANGE(), " HP:");
    w->print(Colors::WHITE(), std::to_string(getHp()));

    w->print(Colors::ORANGE(), " GOLD:");
    w->print(Colors::WHITE(), std::to_string(getGold()));

    w->print(Colors::ORANGE(), "\n");

    w->print(Colors::ORANGE(), "LEVEL:");
    w->print(Colors::WHITE(), std::to_string(getLevel()));

    w->print(Colors::ORANGE(), " XP:");
    w->print(Colors::WHITE(), std::to_string(getXp()));

    w->print(Colors::ORANGE(), " NEXT:");
    w->print(Colors::WHITE(), std::to_string(getNextLevelXp()));

    w->print(Colors::ORANGE(), "\n");
    w->print(Colors::ORANGE(), "\n");

    w->print(Colors::ORANGE(), "e: ");
    w->print(Colors::ORANGE(), "equip");

    w->print(Colors::ORANGE(), " d: ");
    w->print(Colors::ORANGE(), "drop");

    WindowManager::get().popup(m_menuWindow, 0.1);
}
Ejemplo n.º 3
0
void player::addGold(int amount){
	this->setGold(getGold() + amount);
}
Ejemplo n.º 4
0
bool UserCharacter::handleMessage(const Telegram& msg)
{
	int damage = 0;
	//first see if the current goal accepts the message
	if (getBrain()->handleMessage(msg)) return true;

	//handle any messages not handles by the goals
	switch (msg.msg)
	{
	case MSG_GET_DAMAGED:

		if(isAlive())
		{
			damage = dereferenceToType<int>(msg.extra_info);

			//the extra info field of the telegram carries the amount of damage
		
			// 아직 유저가 죽는것 안함.
			reduceHealth(dereferenceToType<int>(msg.extra_info));

			AbstCharacter* attacker =
				(AbstCharacter*)EntityMgr.getEntityFromID(msg.sender);
			getSensoryMemory()->updateWithDamageSource(attacker, damage);

			//if this bot is now dead let the shooter know
			if (!isAlive())
			{
				int gold_worth = getGoldWorth();
				Dispatcher.dispatchMsg(
					SEND_MSG_IMMEDIATELY,
					getId(),
					msg.sender,
					MSG_GIVE_GOLD,
					(void*)&gold_worth);  // 내 가치를 죽인애한테 gold로 준다.

				Dispatcher.dispatchMsg(
					SEND_MSG_IMMEDIATELY,
					getId(),
					msg.sender,
					MSG_YOU_GOT_ME,
					NULL);  // 내 가치를 죽인애한테 gold로 준다.

				for (auto iter = std::begin(_game_world->getUserCharacters());
					iter != std::end(_game_world->getUserCharacters());
					iter++)
				{
					if (getTeam() != iter->second->getTeam())
					{
						//int damage = _owner_skill->getDamage() + _shooter->getMDamage();
						int exp = getExpWorth();
						//send a message to the bot to let it know it's been hit, and who the
						//shot came from.
						Dispatcher.dispatchMsg(
							SEND_MSG_IMMEDIATELY,
							getId(),
							iter->second->getId(),
							MSG_GIVE_EXP,
							(void*)&exp);
					}
				}
			}
			// hit animation
			float noise_x = util::genRand(0, 30) - 15;
			float noise_y = util::genRand(0, 30) - 15;
			_game_world->getAnimationQ()
				.push(std::make_tuple("damage", _pos.x + noise_x, _pos.y + noise_y));
		}

		return true;

	case MSG_GIVE_GOLD:

		setGold(getGold() + dereferenceToType<int>(msg.extra_info));

		return true;

	case MSG_GIVE_EXP:

		setExp(getExp() + dereferenceToType<int>(msg.extra_info));
		if (getExp() >= _level_up_need_exp)  // level up
		{
			setLevel(getLevel() + 1);
			setExp(getExp() - _level_up_need_exp);
			levelUp();
		}

		return true;

	case MSG_YOU_GOT_ME:  // 내가 누굴 죽였다고 메시지를 받음

		setScore(getScore() + 1);

		//the bot this bot has just killed should be removed as the target
		_target_system->clearTarget();

		return true;

	case MSG_GUN_SHOT_SOUND:

		//add the source of this sound to the bot's percepts
		getSensoryMemory()->updateWithSoundSource((AbstCharacter*)msg.extra_info);

		return true;

	case MSG_USER_HAS_REMOVED_BOT:
	{

		AbstCharacter* pRemovedBot = (AbstCharacter*)msg.extra_info;

		getSensoryMemory()->removeBotFromMemory(pRemovedBot);

		//if the removed bot is the target, make sure the target is cleared
		if (pRemovedBot == getTargetSys()->getTarget())
		{
			getTargetSys()->clearTarget();
		}

		return true;
	}
	case MSG_GAME_OVER:
		GameServerManager::getInstance().sendAll(
			PacketFactory::getInstance().createPacketGameOver(_client_name, _team));
		return true;


	default: return false;
	}
}
Ejemplo n.º 5
0
void FileUnit::saveModel()
{
	auto map = Detect::shareDetect()->saveModel();
	ValueMap labelMap;
	auto player = Detect::shareDetect()->getPlayer();
	std::string info = StringUtils::format("%s %d %d %d %d %d",player->getNickName().c_str(),player->getHp(),player->getStr(),player->getDef(),player->getGold(),player->getXp());
	labelMap["info"] = info;
	std::string date = getTimeStr();
	labelMap["date"] = date;
	map["label"] = labelMap;
	map["exist"] = true;
	FileUtils::getInstance()->writeToFile(map,_path);
}
Ejemplo n.º 6
0
void EnemyBase::givePlayerLoot()
{
	GamePlayMediator::getPtr()->givePlayerGold(getGold());
}