void Robot::setHp(int hp) {
  	this->_health_points = hp;
	std_msgs::UInt8 hp_msg;
 	hp_msg.data = getHp();
  	this->hp_pub.publish(hp_msg);

	this->sendLogMsg( "Aggiornati i punti vita a ", getHp());
}
Exemple #2
0
string Tripulacao::getAsString() const
{
	ostringstream oss;
	if (getSala() == -1)
		oss << getId() << "-" << getNome() << "- PV: " << getHp(); //<< " Sala: Sem sala atribuida";
	else
		oss << getId() << "-" << getNome() << "- PV: " << getHp(); //<< " Sala: " << getSala() + 1;
	return oss.str();
}
void AbstractItem::addHp(int toAdd)
{
	if (toAdd < 0)
	{
		subHp(-toAdd);
		return;
	}
	setCurrentHp(getHp() + toAdd);

	if (getHp() > mDefaultFullHp)
	{
		setCurrentHp(mDefaultFullHp);
	}
}
Exemple #4
0
void Monster::lifeBar(Coordinates position){
    COORD pos;
    pos.X = position.x;
    pos.Y = position.y;

    SetConsoleCursorPosition(pConsole, pos);
    cout<<getName()<<" ["<<getLevel()<<"]"<<endl;
    cout<<setfill(' ');

    pos.Y++;
    SetConsoleCursorPosition(pConsole, pos);
    cout<<"HP:   ";
    barizise(getHp(),getMaxhp(),2);
    cout<<' '<<setw(4)<<getHp()<<endl;
}
Exemple #5
0
bool Mob::tick(std::vector<std::function<void ()> > &deferred)
{
	//tick effects etc
	Entity::tick(deferred);
	//tick skills
	for (auto it = skills.begin(); it != skills.end(); it++) {
		it->first.decCd();
	}

	if (getHp() > 0) {
		if (++regenTick >= TICKS) {
			regenTick = 0;
			int newhp = hp + (stats.getHp() * regen) / 100;
			hp = newhp > stats.getHp() ? stats.getHp() : newhp;
		}
		ai->runAI();
		return false;
	}

	Map *m = getMap();
	Entity *e = 0;
	if (lastAttacker && (e = m->getNearByOid(this, lastAttacker)))
		DataService::getService()->groupDistributeExp(exp, level, mobId, e);

	if (spawner)
		spawner->mobDied(this);

	dropItems(e);

	deferred.push_back([=]() {
		delete this;
	});

	return true;
}
Exemple #6
0
bool Enemy::willRestoreHP() {
    if (getHp() <= (RESTORE_HP_DMG_MULT * m_avgDmg)) {
        size_t len;
        if (!m_inventory.consumables().empty()) {
            len = m_inventory.consumables().size();
            for (size_t i = 0; i < len; ++i) {
                if (m_inventory.consumables()[i] -> getType() == CONSUMABLE_TYPE::HP) {
                    m_hpWithItem = true;
                    return true;
                }
            }
        }

        if (!m_hpRestoreSpells.empty()) {
            len = m_hpRestoreSpells.size();
            for (size_t i = 0; i < len; ++i) {
                if (m_hpRestoreSpells[i] -> getStat() == Statistics::HP) {
                    m_hpWithSpell = true;
                    return true;
                }
            }
        }
    }
    return false;
}
Exemple #7
0
void Hero::showStats()
{
    WindowSharedPtr w(m_statsPopup.expired() ?
                      WindowSharedPtr(new Window()) : m_statsPopup.lock());
    m_statsPopup = w;

    w->setHorizontalAlign(Window::HorizontalAlign::LEFT);
    w->setVerticalAlign(Window::VerticalAlign::TOP);

    w->setTitle("Battle window");
    w->clear();

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

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

    const int hpTotalBar = w->getWidth()-2;
    int hpBars = (int)((float)hpTotalBar * getHp() / getMaxHp());

    w->print(Colors::GREEN(), String(hpBars, '='));
    w->print(Colors::RED(), String(hpTotalBar-hpBars, 'x'));

    WindowManager::get().popup(w, 5);
}
//Åöײ¼ì²âº¯Êý
void BattleField::collisionDetection()
{
	
	
	if (bullets.empty() || preys.empty()) {
		return;
	}
	// 1 
	Vector<Prey*> preyNeedToDelete;
	Vector<Bullet*> bulletNeedToDelete;
	// 2
	for (int i = 0; i < bullets.size(); i++)
	{
		auto  bullet1 = bullets.at(i);
		/*auto  bulletRect = Rect(bullet->getPositionX() + bullet->getParent()->getPositionX() - bullet->getContentSize().width / 2,
			bullet->getPositionY() + bullet->getParent()->getPositionY() - bullet->getContentSize().height / 2,
			bullet->getContentSize().width,
			bullet->getContentSize().height);*/
		auto bulletRect = bullet1->getBoundingBox();

		
		for (int j = 0; j < preys.size(); j++)
		{
			auto enemy = preys.at(j);
			auto enemyRect = enemy->getBoundingBox();
			// 4
			if (bulletRect.intersectsRect(enemyRect))// Åöײ³É¹¦
			{
				bullet->setpower(2);
				auto power = bullet->getpower();
				auto hp = enemy->getHp();
				hp = hp - 2;
				enemy->setHp(hp);//¿ÛѪ
				bulletNeedToDelete.pushBack(bullet1);
				if(hp<=0)
				preyNeedToDelete.pushBack(enemy);
				
				// 5
				break;
			}
		}
		// ÒƳýËÀÁ˵Äprey
		for (Prey* preytemp:preyNeedToDelete)
		{
			
			preys.eraseObject(preytemp);
			preytemp->removeFromParentAndCleanup(true);
		}
		preyNeedToDelete.clear();
	}
	// ÒƳýËÀÁ˵Äbullet
	for (const auto& bulletTemp : bulletNeedToDelete)
	{
		bullets.eraseObject(bulletTemp);
		//bulletTemp->removeFromParent();
		bulletTemp->removeFromParentAndCleanup(true);
	}
	bulletNeedToDelete.clear();
}
Exemple #9
0
    //-----------------------------------------------------------------------------
    void CCharacter::setHpMpSp( Flt num, DamageType type, ATTACK_RESULT_TYPE resType )
    {
        //死亡
        if ( ATTACK_RESULT_TYPE_DEAD == resType )
        {    
            setHp(0);
        }
        //恢复
        if ( ATTACK_RESULT_TYPE_RECOVER == resType )
        {
            if ( type & DT_HP )
            {
                setHp(getHp()+num);
            }
            if ( type & DT_MP )
            {
                //mCAttributeSystem.addValue(ATTR_ID_Mp, num);
                setMp(getMp()+num);
            }
            if ( type & DT_SP )
            {
                //mCAttributeSystem.addValue(ATTR_ID_Sp, num);
                setSp(getSp()+num);
            }

        }
        //伤害
        if ( ATTACK_RESULT_TYPE_HURT == resType )
        {
            if ( type & DT_HP )
            {
                //mCAttributeSystem.addValue(ATTR_ID_Hp, -num);
                setHp(getHp()-num);
            }
            if ( type & DT_MP )
            {
                //mCAttributeSystem.addValue(ATTR_ID_Mp, -num);
                setMp(getMp()-num);
            }
            if ( type & DT_SP )
            {
                //mCAttributeSystem.addValue(ATTR_ID_Sp, -num);
                setSp(getSp()-num);
            }
        }
    }
void Robot::run() {

	ros::Rate loop_rate(1);
	while (ros::ok() && getHp() > 0) {
		ros::spinOnce();
		loop_rate.sleep();
	}
}
void AbstractItem::subHp(int toSub)				// 加血
{
	if (toSub < 0)
	{
		addHp(-toSub);
		return;
	}
	if (getHp() < toSub)
	{
		setCurrentHp(0);
		CCLog("Item Dead Clear All Buffs: %d",mAttachedBuffVec.size());
		mAttachedBuffVec.clear();
	}else
	{
		setCurrentHp(getHp() - toSub);
	}
}
Exemple #12
0
bool Player::hasSkill(const QString &skill_name, bool include_lose) const{
    if (!include_lose) {
        if (!hasEquipSkill(skill_name) && ((hasFlag("huoshui") && getHp() >= (getMaxHp() + 1) / 2)
                                           || getMark("Qingcheng" + skill_name) > 0))
            return false;
    }
    return skills.contains(skill_name)
           || acquired_skills.contains(skill_name);
}
Exemple #13
0
void Hero::handleStateInGame(bool pressed, int key)
{
    // only when alive
    if (!getHp() || !pressed)
    {
        return;
    }

    switch (key)
    {
    case (int)Key::UP:
        setDisplacement(0, -1);
        break;

    case (int)Key::DOWN:
        setDisplacement(0, 1);
        break;

    case (int)Key::LEFT:
        setDisplacement(-1, 0);
        break;

    case (int)Key::RIGHT:
        setDisplacement(1, 0);
        break;

    case 't':
    case 'T':
        takeAll();
        break;

    case 'a':
    case 'A':
        hit(Direction::LEFT);
        break;

    case 'd':
    case 'D':
        hit(Direction::RIGHT);
        break;

    case 's':
    case 'S':
        hit(Direction::DOWN);
        break;

    case 'w':
    case 'W':
        hit(Direction::UP);
        break;

    case ' ':
        m_state = State::Status;
        break;
    }
}
Exemple #14
0
 /*public*/ int Engine::getHpInteger() {
     //try {
 bool bok;
         return getHp().toInt();
         if(!bok)
         {
         log->warn(tr("Locomotive (%1) horsepower (%2) isn't a number").arg(toString()).arg(getHp()));
         return 0;
     }
 }
Exemple #15
0
void Building::updateHpProgress()
{
    if (getHPProcess() == nullptr)
    {
        createHPProcess();
    }
    auto cfg = BuildingConfig::getBuildingConfig(getType());
    float per = (float)getHp()/cfg->max_hp*100;
    getHPProcess()->setPercentage(per);
}
Exemple #16
0
 /**
  * Set the locomotive horsepower rating for this locomotive's model
  *
  * @param hp locomotive horsepower
  */
 /*public*/ void Engine::setHp(QString hp) {
     if (getModel()==(NONE)) {
         return;
     }
     QString old = getHp();
     engineModels->setModelHorsepower(getModel(), hp);
     if (old!=(hp)) {
         setDirtyAndFirePropertyChange("hp", old, hp); // NOI18N
     }
 }
Exemple #17
0
bool Player::hasSkill(const QString &skill_name, bool include_lose) const{
    if (!include_lose) {
        const Skill *skill = Sanguosha->getSkill(skill_name);
        if (!skill) {
            return false;
        }
        if ((!skill->inherits("WeaponSkill") && !skill->inherits("ArmorSkill"))
                && ((hasFlag("huoshui") && getHp() >= (getMaxHp() + 1) / 2) || getMark("Qingcheng" + skill_name) > 0))
            return false;
    }
    return skills.contains(skill_name)
           || acquired_skills.contains(skill_name);
}
// メンバーの回復
void GameLayer::healMember(int healing)
{
    for (int i = 0; i < _memberDatum.size(); i++)
    {
        // メンバーデータ取得
        auto memberData = _memberDatum.at(i);
        
        // HPが0の場合は、回復しない
        if (memberData->getHp() <= 0)
            continue;
        
        // メンバーを回復する
        float preHpPercentage = memberData->getHpPercentage();
        int afterHp = memberData->getHp() + healing;
        if (afterHp > memberData->getMaxHp()) afterHp = memberData->getMaxHp();
        memberData->setHp(afterHp);
        
        // メンバーHPアニメーション
        auto act = ProgressFromTo::create(0.5, preHpPercentage, memberData->getHpPercentage());
        _hpBarForMembers.at(i)->runAction(act);
    }
}
Exemple #19
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);
}
Exemple #20
0
int Player::distanceTo(const Player *other, int distance_fix) const
{
    if (this == other)
        return 0;

    if (hasSkill("zhuiji") && other->getHp() < getHp())
        return 1;

    if (fixed_distance.contains(other)) {
        QList<int> distance_list = fixed_distance.values(other);
        int min = 10000;
        foreach (int d, distance_list) {
            if (min > d)
                min = d;
        }

        return min;
    }
// ダメージの計算
void GameLayer::calculateDamage(int &chainNum, int &healing, int &damage, std::set<int> &attackers)
{
    auto removeIt = _removeNumbers.begin();
    while (removeIt != _removeNumbers.end())
    {
        auto ballIt = (*removeIt).begin();
        while(ballIt != (*removeIt).end())
        {
            if ((*ballIt).first == BallSprite::BallType::Pink)
            {
                // 回復
                healing += 5;
            }
            else
            {
                // アタッカー分のデータを繰り返す
                for (int i = 0; i < _memberDatum.size(); i++)
                {
                    // メンバー情報取得
                    auto memberData = _memberDatum.at(i);
                    
                    // メンバーのHPが0の場合は、以下の処理を行わない
                    if (memberData->getHp() <= 0)
                        continue;
                    
                    // 消されたボールとアタッカーの属性よりアタッカーの判定
                    if (isAttacker((*ballIt).first, memberData->getElement()))
                    {
                        // アタッカー情報の保持
                        attackers.insert(i);
                        
                        // ダメージ
                        damage += Character::getDamage((*ballIt).second, chainNum, memberData, _enemyData);
                    }
                }
            }
            
            chainNum++;
            ballIt++;
        }
        
        removeIt++;
    }
}
Exemple #22
0
void MonsterProperties::setWidgetValue()
{
	InternalOperation = true;
	if (targetSprite->isHasMonsterProperties()){
		auto sprite = dynamic_cast<EntityImageSprite*>(targetSprite);
		this->setVisible(true);
		hp->setText(QString::number(sprite->getHp()));
		mp->setText(QString::number(sprite->getMp()));
		attack->setText(QString::number(sprite->getAttack()));
		defense->setText(QString::number(sprite->getDefense()));
		magic_attack->setText(QString::number(sprite->getMagicAttack()));
		magic_defense->setText(QString::number(sprite->getMagicDefense()));
		speed->setText(QString::number(sprite->getSpeed()));
		hardFactor->setText(QString::number(sprite->getHardFactor()));
	}
	else{
		this->setVisible(false);
		setDefaultValue();
	}
	InternalOperation = false;
}
Exemple #23
0
int Player::distanceTo(const Player *other) const{
    if(this == other)
        return 0;

    if(fixed_distance.contains(other))
        return fixed_distance.value(other);

    int right = qAbs(seat - other->seat);
    int left = aliveCount() - right;
    int distance = qMin(left, right);

    // the shorten ways of distance
    if(getOffensiveHorse())
        distance --;

    if(hasSkill("mashu"))
        distance --;

    if(hasSkill("yicong") && getHp() > 2)
        distance --;

    // the lengthen ways of distance
    if(other->getDefensiveHorse())
        distance ++;

    if(other->hasSkill("feiying"))
        distance ++;

    if(other->hasSkill("yicong") && other->getHp() <= 2)
        distance ++;

    // keep the distance >=1
    if(distance < 1)
        distance = 1;

    return distance;
}
Exemple #24
0
/*
void Slime::BeginContact(GameObject* other, b2Contact* contact)
{
	if (other->getType() == TYPE_HERO)
	{
		Hero* hero = GameManager::getInstance()->hero;
		if (hero->isDie())
			return;
		hero->setHp(hero->getHp() - SD_INT("slime_int_atk"));
		//Ó¢ÐÛÎÞµÐ0.5Ãë
		hero->setUnbeatable(0.5);

		//»ñÈ¡Åöײºó²úÉúµÄºÏÁ¦·½Ïò
		float y = contact->GetManifold()->localNormal.y;
		if (y > 0)
		{
			b2Vec2 vec = hero->getBody()->GetLinearVelocity();
			vec.y = SD_FLOAT("slime_float_atk_jump");
			//ʹӢÐÛÌøÔ¾
			hero->getBody()->SetLinearVelocity(vec);
			//É˺¦Ê·À³Ä·
			this->setHp(getHp()-1);
		}
	}
}
*/
void Slime::PreSolve(GameObject* other, b2Contact* contact, const b2Manifold* oldManifold)
{
	if (other->getType() == TYPE_HERO)
	{
		Hero* hero = GameManager::getInstance()->hero;
		if (hero->isDie())
			return;
		hero->setHp(hero->getHp() - SD_INT("slime_int_atk"));
		//Ó¢ÐÛÎÞµÐ0.5Ãë
		hero->setUnbeatable(SD_FLOAT("slime_float_unbeatable"));

		//»ñÈ¡Åöײºó²úÉúµÄºÏÁ¦·½Ïò
		float y = contact->GetManifold()->localNormal.y;
		if (y > 0)
		{
			b2Vec2 vec = hero->getBody()->GetLinearVelocity();
			vec.y = SD_FLOAT("slime_float_atk_jump");
			//ʹӢÐÛÌøÔ¾
			hero->getBody()->SetLinearVelocity(vec);
			//É˺¦Ê·À³Ä·
			this->setHp(getHp()-1);
		}
	}
}
Exemple #25
0
 /**
  * Create an XML element to represent this Entry. This member has to remain
  * synchronized with the detailed DTD in operations-engines.dtd.
  *
  * @return Contents in a JDOM Element
  */
 /*public*/ QDomElement Engine::store(QDomDocument doc)
 {
  QDomElement e = doc.createElement(Xml::ENGINE);
//  QDomElement e = QDomElement();
//  e.setTagName(Xml::ENGINE);
  RollingStock::store(e);
  e.setAttribute(Xml::MODEL, getModel());
  e.setAttribute(Xml::HP, getHp());
  e.setAttribute(Xml::B_UNIT, (isBunit() ? Xml::_TRUE : Xml::_FALSE));
  if (getConsist() != NULL)
  {
   e.setAttribute(Xml::CONSIST, getConsistName());
   if (getConsist()->isLead(this))
   {
    e.setAttribute(Xml::LEAD_CONSIST, Xml::_TRUE);
    if (getConsist()->getConsistNumber() > 0)
    {
     e.setAttribute(Xml::CONSIST_NUM,
                    getConsist()->getConsistNumber());
    }
   }
  }
  return e;
 }
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);
}
// initialization
void className::onInit()
{
	baseClassName::onInit();

	//////////////// Most typical efect
	//////////////// uncomment if need
	//// graphics
	//addEfect(efModel = new EfectModel("model_.txt", nullptr, true, true) );
	//addEfect(efParticle = new EfectParticle( "particle_.txt", 1, 1, 1, 0, &efModel->model, nullptr) );
	//addEfect(efFollowCam = new EfectFollowCam( &efModel->model, -350) );
	//addEfect(efAnimation = new EfectAnimation("", "animation_.txt") );

	//// collision
	//addEfect(efCollidionResponse = new EfectCollisionResponse(5.5, 0.001, Vector2D() ) );
	//addEfect(efDamageOnCollision = new EfectDamageOnCollision(-0,-0) );
	//addEfect(efCheckForCollision = new EfectCheckForCollision(&world) );


	//// movement
	//addEfect(efTppMovement = new EfectTppMovement(4, 0.5) );
	//addEfect(efFollowAim = new EfectFollowAim(nullptr,0,0,1.f,Vector2D(),Vector2D(),false, false));

	//// debug
	//addEfect(efDebugCollider = new EfectDebugCollider(&efModel->model, sf::Keyboard::Z, Color(200, 200, 200, 100)));
	//addEfect(efDebugStat = new EfectDebugStat(Game::Event::hp, true, "object hp", Control::Input(sf::Keyboard::K)));

	//////////////// Collider
	//addCollider(CircleCollider(Vector2D(), 100.f));
	//////////////// Animation
	//addAnimation("", Animation("animation_.txt"));

	//////////////// Realms
	//// position
	getPos().position = Vector2D();
	getPos().velocity = Vector2D();
	getPos().force = Vector2D();
	getPos().inverseMass = 1;
	getPos().resetVelocity = 0.75;
	getPos().resetForce = 0;

	//// rotation
	getRot().position = 0;
	getRot().velocity = 0;
	getRot().force = 0;
	getRot().inverseMass = 1;
	getRot().resetVelocity = 0.75;
	getRot().resetForce = 0;

	//// hp
	getHp().position = 100;
	getHp().velocity = 0;
	getHp().force = 0;
	getHp().inverseMass = 1;
	getHp().resetVelocity = 0;
	getHp().resetForce = 0;

	//// vis
	getVis().position = 0;
	getVis().velocity = 0;
	getVis().force = 0;
	getVis().inverseMass = 1;
	getVis().resetVelocity = 0.75;
	getVis().resetForce = 0;
}