Beispiel #1
0
void GameObj::damage(int amount, SoundManager &sm) {
	// Process incoming damage
	if(getArmor() > amount)
		return;				// armor negates all damage
	else amount -= getArmor();
	setHP(getHP() - amount);

	// SFX
	t_damaged.Calculate_Ellapsed_Time();
	if(t_damaged.TotalTime() >= TIMER_SOUND_DAMAGED) {
		SoundManager::Sounds soundID;
		switch(goSettings.getTypeID()) {
			case Settings::OBJ_ID_ARCHER: soundID = sm.SND_ARCHER_DAMAGED; break;
			case Settings::OBJ_ID_STONEWALL: soundID = sm.SND_STONEWALL_DAMAGED; break;
	//			case settings.OBJ_T_DOG: soundID = sm.SND_DOG_MELEE; break;
	//			case settings.OBJ_T_SPEARMAN: soundID = sm.SND_SPEARMAN_MELEE; break;
	//			case settings.OBJ_ID_ARCHER: soundID = sm.SND_ARCHER_MELEE; break;
			default: soundID = sm.SND_ARCHER_DAMAGED; break;
		}
		sm.playSound(soundSourceID, soundID, body->GetPosition());
		t_damaged.Reset(0.0);
	}

	// Special Behavior (defined in derived classes)
	damageSpecial(amount, sm);

	// Death sequence
	if(getHP() < 0) {
		death(sm);
	}
}
Beispiel #2
0
int PlayerSAO::punch(v3f dir,
	const ToolCapabilities *toolcap,
	ServerActiveObject *puncher,
	float time_from_last_punch)
{
	// It's best that attachments cannot be punched
	if (isAttached())
		return 0;

	if (!toolcap)
		return 0;

	// No effect if PvP disabled
	if (g_settings->getBool("enable_pvp") == false) {
		if (puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
			std::string str = gob_cmd_punched(0, getHP());
			// create message and add to list
			ActiveObjectMessage aom(getId(), true, str);
			m_messages_out.push(aom);
			return 0;
		}
	}

	HitParams hitparams = getHitParams(m_armor_groups, toolcap,
			time_from_last_punch);

	std::string punchername = "nil";

	if (puncher != 0)
		punchername = puncher->getDescription();

	PlayerSAO *playersao = m_player->getPlayerSAO();

	bool damage_handled = m_env->getScriptIface()->on_punchplayer(playersao,
				puncher, time_from_last_punch, toolcap, dir,
				hitparams.hp);

	if (!damage_handled) {
		setHP(getHP() - hitparams.hp);
	} else { // override client prediction
		if (puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
			std::string str = gob_cmd_punched(0, getHP());
			// create message and add to list
			ActiveObjectMessage aom(getId(), true, str);
			m_messages_out.push(aom);
		}
	}


	actionstream << "Player " << m_player->getName() << " punched by "
			<< punchername;
	if (!damage_handled) {
		actionstream << ", damage " << hitparams.hp << " HP";
	} else {
		actionstream << ", damage handled by lua";
	}
	actionstream << std::endl;

	return hitparams.wear;
}
Beispiel #3
0
std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
{
	std::ostringstream os(std::ios::binary);

	if(protocol_version >= 15)
	{
		writeU8(os, 1); // version
		os<<serializeString(m_player->getName()); // name
		writeU8(os, 1); // is_player
		writeS16(os, getId()); //id
		writeV3F1000(os, m_base_position + v3f(0,BS*1,0));
		writeF1000(os, m_yaw);
		writeS16(os, getHP());

		std::ostringstream msg_os(std::ios::binary);
		msg_os << serializeLongString(getPropertyPacket()); // message 1
		msg_os << serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
		msg_os << serializeLongString(gob_cmd_update_animation(
			m_animation_range, m_animation_speed, m_animation_blend, m_animation_loop)); // 3
		for (UNORDERED_MAP<std::string, core::vector2d<v3f> >::const_iterator
				ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) {
			msg_os << serializeLongString(gob_cmd_update_bone_position((*ii).first,
				(*ii).second.X, (*ii).second.Y)); // m_bone_position.size
		}
		msg_os << serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id,
			m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4
		msg_os << serializeLongString(gob_cmd_update_physics_override(m_physics_override_speed,
				m_physics_override_jump, m_physics_override_gravity, m_physics_override_sneak,
				m_physics_override_sneak_glitch)); // 5
		// (GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES) : Deprecated, for backwards compatibility only.
		msg_os << serializeLongString(gob_cmd_update_nametag_attributes(m_prop.nametag_color)); // 6
		int message_count = 6 + m_bone_position.size();
		for (UNORDERED_SET<int>::const_iterator ii = m_attachment_child_ids.begin();
				ii != m_attachment_child_ids.end(); ++ii) {
			if (ServerActiveObject *obj = m_env->getActiveObject(*ii)) {
				message_count++;
				msg_os << serializeLongString(gob_cmd_update_infant(*ii, obj->getSendType(),
					obj->getClientInitializationData(protocol_version)));
			}
		}

		writeU8(os, message_count);
		os.write(msg_os.str().c_str(), msg_os.str().size());
	}
	else
	{
		writeU8(os, 0); // version
		os<<serializeString(m_player->getName()); // name
		writeU8(os, 1); // is_player
		writeV3F1000(os, m_base_position + v3f(0,BS*1,0));
		writeF1000(os, m_yaw);
		writeS16(os, getHP());
		writeU8(os, 2); // number of messages stuffed in here
		os<<serializeLongString(getPropertyPacket()); // message 1
		os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
	}

	// return result
	return os.str();
}
Beispiel #4
0
void GameUILayer::_updateHpHandler(cocos2d::Ref *pSender)
{
    auto player = GameManager::getInstance()->getPlayer();
    int *hurt = (int*)static_cast<Node*>(pSender)->getUserData();
    auto progressTo = ProgressFromTo::create(1.0f, player->getHP()+*hurt, player->getHP());
    hpBar->runAction(progressTo);
}
Beispiel #5
0
int LuaEntitySAO::punch(v3f dir,
		const ToolCapabilities *toolcap,
		ServerActiveObject *puncher,
		float time_from_last_punch)
{
	if(!m_registered){
		// Delete unknown LuaEntities when punched
		m_removed = true;
		return 0;
	}

	// It's best that attachments cannot be punched 
	if(isAttached())
		return 0;
	
	ItemStack *punchitem = NULL;
	ItemStack punchitem_static;
	if(puncher){
		punchitem_static = puncher->getWieldedItem();
		punchitem = &punchitem_static;
	}

	PunchDamageResult result = getPunchDamage(
			m_armor_groups,
			toolcap,
			punchitem,
			time_from_last_punch);
	
	if(result.did_punch)
	{
		setHP(getHP() - result.damage);
		

		std::string punchername = "nil";

		if ( puncher != 0 )
			punchername = puncher->getDescription();

		actionstream<<getDescription()<<" punched by "
				<<punchername<<", damage "<<result.damage
				<<" hp, health now "<<getHP()<<" hp"<<std::endl;
		
		{
			std::string str = gob_cmd_punched(result.damage, getHP());
			// create message and add to list
			ActiveObjectMessage aom(getId(), true, str);
			m_messages_out.push_back(aom);
		}

		if(getHP() == 0)
			m_removed = true;
	}

	ENV_TO_SA(m_env)->luaentity_Punch(m_id, puncher,
			time_from_last_punch, toolcap, dir);

	return result.wear;
}
int LuaEntitySAO::punch(v3f dir,
		const ToolCapabilities *toolcap,
		ServerActiveObject *puncher,
		float time_from_last_punch)
{
	if (!m_registered) {
		// Delete unknown LuaEntities when punched
		m_pending_removal = true;
		return 0;
	}

	ItemStack *punchitem = NULL;
	ItemStack punchitem_static;
	if (puncher) {
		punchitem_static = puncher->getWieldedItem();
		punchitem = &punchitem_static;
	}

	PunchDamageResult result = getPunchDamage(
			m_armor_groups,
			toolcap,
			punchitem,
			time_from_last_punch);

	bool damage_handled = m_env->getScriptIface()->luaentity_Punch(m_id, puncher,
			time_from_last_punch, toolcap, dir, result.did_punch ? result.damage : 0);

	if (!damage_handled) {
		if (result.did_punch) {
			setHP(getHP() - result.damage,
				PlayerHPChangeReason(PlayerHPChangeReason::SET_HP));

			if (result.damage > 0) {
				std::string punchername = puncher ? puncher->getDescription() : "nil";

				actionstream << getDescription() << " punched by "
						<< punchername << ", damage " << result.damage
						<< " hp, health now " << getHP() << " hp" << std::endl;
			}

			std::string str = gob_cmd_punched(result.damage, getHP());
			// create message and add to list
			ActiveObjectMessage aom(getId(), true, str);
			m_messages_out.push(aom);
		}
	}

	if (getHP() == 0 && !isGone()) {
		m_pending_removal = true;
		clearParentAttachment();
		clearChildAttachments();
		m_env->getScriptIface()->luaentity_on_death(m_id, puncher);
	}

	return result.wear;
}
Beispiel #7
0
void Pokemon::setCurrentHP(double curHP)
{
	if (curHP < 0)
	{
		_curHP = 0;
		setIsAlive(false);
	}
	else if (curHP > getHP())
		_curHP = getHP();
	else
		_curHP = curHP;
}
void Server::handleCommand_Damage(NetworkPacket* pkt) {
	//const auto peer_id = pkt->getPeerId();
	auto & packet = *(pkt->packet);
	auto player = m_env->getPlayer(pkt->getPeerId());
	if (!player) {
		m_con.DisconnectPeer(pkt->getPeerId());
		return;
	}
	auto playersao = player->getPlayerSAO();
	if (!playersao) {
		m_con.DisconnectPeer(pkt->getPeerId());
		return;
	}
	u8 damage = packet[TOSERVER_DAMAGE_VALUE].as<u8>();

	if(g_settings->getBool("enable_damage")) {
		actionstream << player->getName() << " damaged by "
		             << (int)damage << " hp at " << PP(player->getPosition() / BS)
		             << std::endl;

		playersao->setHP(playersao->getHP() - damage);

		SendPlayerHPOrDie(playersao);

		stat.add("damage", player->getName(), damage);
	}
}
Beispiel #9
0
void Frog::update()
{
	if (getHP() < 0.f)
	{
		Drop(std::make_shared<DeathAnimation>(mPos, 0.8));
		kill();
	}
	sf::Vector2f move(0,0);
	if(closeToMyEnemy)
	{
		move.x -= directionToMyEnemy.x*2;
		move.y -= directionToMyEnemy.y*2;
	}

	if(move.x > 0 && move.x > move.y)
		mCurrentAnim = &mRigth;//
	else if(move.x < 0 && move.x < move.y)
		mCurrentAnim = &mLeft;
	if(move.y > 0 && move.x < move.y)
		mCurrentAnim = &mDown;//
	else if(move.y < 0 && move.x > move.y)
		mCurrentAnim = &mUp;

	mPos += move;
	mCollisionBox.left = mPos.x - mCollisionBox.width / 2;
	mCollisionBox.top = mPos.y - mCollisionBox.height / 2;

	mCurrentAnim->update();

	move = mMap.tryMove(mPos, move, mCollisionBox);
	mPos = move;
}
Beispiel #10
0
void PlayerSAO::setHP(s16 hp)
{
	s16 oldhp = m_player->hp;

	if(hp < 0)
		hp = 0;
	else if(hp > PLAYER_MAX_HP)
		hp = PLAYER_MAX_HP;

	if(hp < oldhp && g_settings->getBool("enable_damage") == false)
	{
		m_hp_not_sent = true; // fix wrong prediction on client
		return;
	}

	m_player->hp = hp;

	if(hp != oldhp)
		m_hp_not_sent = true;

	// On death or reincarnation send an active object message
	if((hp == 0) != (oldhp == 0))
	{
		// Will send new is_visible value based on (getHP()!=0)
		m_properties_sent = false;
		// Send new HP
		std::string str = gob_cmd_punched(0, getHP());
		ActiveObjectMessage aom(getId(), true, str);
		m_messages_out.push_back(aom);
	}
}
Beispiel #11
0
int Character::getX()
{
    if(getHP()<10){
        return this->x+30;
    }
    return this->x;
}
Beispiel #12
0
int PlayerSAO::punch(v3f dir,
	const ToolCapabilities *toolcap,
	ServerActiveObject *puncher,
	float time_from_last_punch)
{
	// It's best that attachments cannot be punched 
	if(isAttached())
		return 0;

	if(!toolcap)
		return 0;

	// No effect if PvP disabled
	if(g_settings->getBool("enable_pvp") == false){
		if(puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER){
			std::string str = gob_cmd_punched(0, getHP());
			// create message and add to list
			ActiveObjectMessage aom(getId(), true, str);
			m_messages_out.push_back(aom);
			return 0;
		}
	}

	HitParams hitparams = getHitParams(m_armor_groups, toolcap,
			time_from_last_punch);

	std::string punchername = "nil";

	if ( puncher != 0 )
		punchername = puncher->getDescription();

	actionstream<<"Player "<<m_player->getName()<<" punched by "
			<<punchername<<", damage "<<hitparams.hp
			<<" HP"<<std::endl;

	setHP(getHP() - hitparams.hp);

	if(hitparams.hp != 0)
	{
		std::string str = gob_cmd_punched(hitparams.hp, getHP());
		// create message and add to list
		ActiveObjectMessage aom(getId(), true, str);
		m_messages_out.push_back(aom);
	}

	return hitparams.wear;
}
Beispiel #13
0
bool EntityHP::update()
{
  if (getHP() <= 0.)
    {
      setDead(true);
    }
  return Entity::update();
}
Beispiel #14
0
void TeamFeedCell::onSliderChanged(Ref* sender, Slider::EventType event)
{
    if (event == Slider::EventType::ON_PERCENTAGE_CHANGED)
    {
        isLargest = false;
        
        auto pet = getCurrBag()->getPetByID(this->getUserID());
        int hp = _btnSlider->getPercent() * pet->getHpMax() / 100;      //---当前值hp的值
        
        if (hp < pet->getHP()) {           //------重置为原始状态
            hp = pet->getHP();
            _btnSlider->setPercent(pet->getHP() * 100 / pet->getHpMax());
        }
        
        if(getIsWater())
        {
            if(hp - pet->getHP() > getCurrNum())        //当前泉水数小于需要的泉水数
            {
                _btnSlider->setPercent(pet->getHP() * 100 / pet->getHpMax());
            }
        }
        else
        {
            if((hp - pet->getHP()) * pow(10, pet->getStarNum()) > getCurrNum())      //当前粮食数小于需要的粮食数
            {
                _btnSlider->setPercent(pet->getHP() * 100 / pet->getHpMax());
            }
        }
        
        if (_delegate != nullptr)
        {
            _delegate->onHpFeedNumChanged(this, hp - pet->getHP(), this->getIsLargest());
        }
    }
}
Beispiel #15
0
int characterShell::getHP(lua_State* pLua)
{
	auto pCharacter = worldShell::CWorldSingleton::instance()->getPlayer()->getCharacter();

	if(pCharacter != nullptr)
		lua_pushinteger(pLua, pCharacter->getHP());

	return 1;
}
Beispiel #16
0
std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
{
	std::ostringstream os(std::ios::binary);

	if(protocol_version >= 15)
	{
		writeU8(os, 1); // version
		os<<serializeString(m_player->getName()); // name
		writeU8(os, 1); // is_player
		writeS16(os, getId()); //id
		writeV3F1000(os, m_player->getPosition() + v3f(0,BS*1,0));
		writeF1000(os, m_player->getYaw());
		writeS16(os, getHP());

		writeU8(os, 6 + m_bone_position.size()); // number of messages stuffed in here
		os<<serializeLongString(getPropertyPacket()); // message 1
		os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
		os<<serializeLongString(gob_cmd_update_animation(
			m_animation_range, m_animation_speed, m_animation_blend, m_animation_loop)); // 3
		for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
			os<<serializeLongString(gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y)); // m_bone_position.size
		}
		os<<serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4
		os<<serializeLongString(gob_cmd_update_physics_override(m_physics_override_speed,
				m_physics_override_jump, m_physics_override_gravity, m_physics_override_sneak,
				m_physics_override_sneak_glitch)); // 5
		os << serializeLongString(gob_cmd_update_nametag_attributes(m_nametag_color)); // 6
	}
	else
	{
		writeU8(os, 0); // version
		os<<serializeString(m_player->getName()); // name
		writeU8(os, 1); // is_player
		writeV3F1000(os, m_player->getPosition() + v3f(0,BS*1,0));
		writeF1000(os, m_player->getYaw());
		writeS16(os, getHP());
		writeU8(os, 2); // number of messages stuffed in here
		os<<serializeLongString(getPropertyPacket()); // message 1
		os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
	}

	// return result
	return os.str();
}
Beispiel #17
0
//Return a reaction based on state
Enemy::Reaction Enemy::ruminate()
{
	//Update player presence
	player_ = getPlayer_();
	play_ = (player_ != nullptr);

	//Change states based on behaviour
	float hpf = (float)getHP() / (float)(startingHP_);
	
	//Distance to player, if she's there
	float between = FLT_MAX;
	if (play_) between = (getPosition() - player_->getPosition()).Length();

	//If the player's dead, hang ten
	if (!play_) stateOfMind_ = IDLE;

	//Flee if hurt
	else if (hpf < ouch_[brainStem_.pain_tolerance]) stateOfMind_ = FLEE;

	//Otherwise think about what we should do
	else switch (stateOfMind_)
	{
	//If we're running, check if we're healthy enough to stop
	case FLEE:
		if (hpf > ouch_[brainStem_.pain_tolerance]) stateOfMind_ = IDLE;
		
	//If we're chilling, check if the player is messing with the bull
	case IDLE:
		if (play_ && between < 128 && between <= chaseRange_[brainStem_.personal_space] || angry_ == angryMAX_) stateOfMind_ = CHASE;
	
	//If we're chasing, make sure we can still see him
	case CHASE:
			if (play_ && between > chaseRangeMAX_[brainStem_.perserverance]) stateOfMind_ = IDLE;
	}

	//Execute our current mood
	switch (stateOfMind_)
	{
	case IDLE:
		//std::cout << "idle" << std::endl;
		return idle();
		break;
	case CHASE:
		//std::cout << "chase" << std::endl;
		return chase();
		break;
	case FLEE:
		//std::cout << "flee" << std::endl;
		return flee();
		break;
	}

	return Reaction();
}
void HumanoidCombatComponent::takeDamage(GameObject& attacker, GameObject& target, float damage) {

	setHP(getHP() - damage);
	std::string attackerName = std::string(attacker.getSocial()->getName());
	std::string targetName = std::string(target.getSocial()->getName());
	
	if(&attacker == &target)
		targetName = "himself";

	std::cout << attackerName << " deals " << damage << " damage to " << targetName << ".\n";
	//std::printf("%s deals %.0f damage to %s.\n", attackerName.c_str(), damage, targetName.c_str());
	
	if(getHP() <= 0) {

		kill();
		std::printf("%s is killed by %s.\n", targetName.c_str(), attackerName.c_str());
		attacker.getInput()->setTargeting(false);

	}

}
Beispiel #19
0
void Pokemon::SetStatsForLevel()
{
	setHP(round(ceil(2 * getBaseHP() + 31) * getLevel() / 100 + getLevel() + 10));
   setAtt(round(ceil(2 * getBaseAtt() + 31) * getLevel() / 100 + 5));
   setDef(round(ceil(2 * getBaseDef() + 31) * getLevel() / 100 + 5));
   setSpeed(round(ceil(2 * getBaseSpeed() + 31) * getLevel() / 100 + 5));

	setCurrentHP(getHP());
	setCurrentAtt(getAtt());
	setCurrentDef(getDef());
	setCurrentSpeed(getSpeed());
}
Beispiel #20
0
void ch_att::getInfo()
{
	x=getX();
	y=getY();
	lev=getLevel();
	point=getPoint();
	exp=getExp();
	hp=getHP();
	maxhp=getMaxHP();
	att=getAtt();
	sp=getSp();
	getMap();
}
Beispiel #21
0
void ObjHero::actionStand(){
    assert(rootObj);
    if(getHP() <= 0){
        die();
        return;
    }
    rootObj->stopAllActions();
    setDesPoin(rootObj->getPosition());
    setState(EobjState::E_STAND);
    Animation* stand = createAnimateWithFileNames("Hero%d.png", 3);
    auto action = Animate::create(stand);
    rootObj->runAction(RepeatForever::create(action));
}
Beispiel #22
0
void ObjMonster::actionStand(){
    assert(rootObj);
    
    if(getHP() <= 0){
        die(NULL);
        return;
    }
    //if(getState() == EobjState::E_HURT) return;
    rootObj->stopAllActions();
    setState(EobjState::E_STAND);
    Animation* stand = createAnimateWithFileNames("Robot%d.png", 3);
    auto action = Animate::create(stand);
    rootObj->runAction(RepeatForever::create(action));
}
Beispiel #23
0
std::string PlayerSAO::getClientInitializationData()
{
	std::ostringstream os(std::ios::binary);
	writeU8(os, 0); // version
	os<<serializeString(m_player->getName()); // name
	writeU8(os, 1); // is_player
	writeV3F1000(os, m_player->getPosition() + v3f(0,BS*1,0));
	writeF1000(os, m_player->getYaw());
	writeS16(os, getHP());
	writeU8(os, 2); // number of messages stuffed in here
	os<<serializeLongString(getPropertyPacket()); // message 1
	os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
	return os.str();
}
Beispiel #24
0
void SkillNormalBombStep::update(float dt)
{
	if (!_start || !_stepData || _targetRoles.size()==0) return;

	if (_step == 0)
	{
		for(int i=0; i<_targetRoles.size(); i++)
		{
			auto role = _targetRoles.at(i);
			auto player = AnimiPlayer::create(_frames, _stepData->frameDt);
			player->setTag(1000+i);
			player->start(1);
			player->setUserObject(role);
			player->setStopEvent([&](AnimiPlayer* player)
			{
				auto effect = DamageEffect::create(_stepData->_hurtHP);
				effect->setPosition(Point(CCRANDOM_MINUS1_1()*10, CCRANDOM_MINUS1_1()*10+60));

				auto role = static_cast<BattleRole*>(player->getUserObject());
				role->getNode()->addChild(effect, 10);

				int hp = role->getHP() + _stepData->_hurtHP;
				role->setHP(hp);

				player->removeFromParent();
			});
			player->setPosition(GRID_CONVER_TO_PIXEL(role->getGridIndex().x, role->getGridIndex().y));
			BattleController::getInstance()->addChild(player, ZORDER_BATTLE_EFFECT);
		}
		_step ++;
	}
	else if (_step == 1)
	{
		bool over = true;
		for(int i=0; i<_targetRoles.size(); i++)
		{
			auto node = BattleController::getInstance()->getChildByTag(1000+i);
			if (node)
			{
				over = false;
			}
		}
		if (over)
		{
			setOver(over);
			_step++;
		}
	}
}
Beispiel #25
0
//Towards player, shoot if close, run if low hp
void Enemy::classicAI()
{
	Shape* player = getPlayer_();
	if (player)
	{
		b2Vec2 playerPos = player->getPosition();
		b2Vec2 ePos = getPosition();
		b2Vec2 between = playerPos - ePos;

		//In long distance, look
		if (between.Length() < 40 || between.Length() < 4.f)
		{
			orient(between);
		}

		//In med distance, move towards, shoot at
		if (between.Length() < 25 && (getHP() >= verticesMIN_ * hpScale_))
		{
			if (getArmed())
			{
				move(between);
				orient(between);
				if (getWeaponReady())
				{
					float rotation = atan2f(between.y, between.x);
					float adjust = randFloat(-0.4, 0.4);
					b2Vec2 newDir(cosf(rotation + adjust), sinf(rotation + adjust));
					trigger(between);
				}
				else release();
			}
		}

		else if (getArmed() && between.Length() < verticesMIN_ * hpScale_)
		{
			orient(-between);
			move(-between);
		}

		else if (!getArmed() && between.Length() < size_ * 1.5f)
		{
			orient(-between);
		}

		else move(b2Vec2_zero);
	}
}
Beispiel #26
0
void Enemy::hurt(int damage, float repelDist)
{
	mHealthPoint -= damage;

	if (mDirState == LEFT) {
		setPosition(ccpAdd(getPosition(), 
			ccp(repelDist, 0)));
	} else {
		setPosition(ccpAdd(getPosition(), 
			ccp(-repelDist, 0)));
	}
	//run action? -- collision rect??

	if (getHP() <= 0) {
		this->die();
	}
}
Beispiel #27
0
Enemy::Enemy(b2Body* body, const EnemyDef& def, std::function<void(SideDef&)>& callback, std::function<Shape*()> &player) :
	Shape(body, def, callback),
	getPlayer_(player),
	aistate(def.ai),
	brainStem_(def.brain),
	stateOfMind_(IDLE),
	panic_(false),
	chasing_(false),
	fired_(false)
{
	imprint(brainStem_);
	startingHP_ = getHP();
	body_->GetFixtureList()->SetUserData("enemy");
	shapeFixDef_.userData = "enemy";

	//Add to swarm
	swarm_.push_back(this);
}
void Character::adjustHP( int delta )
{
	std::string pointsAsText = "N/A";
	int x = getX(), y = getY();
	unsigned int color;

	if(delta < 0) {
		pointsAsText = toString(-delta);
		color = makecol(255, 20, 20);
	} else if( delta > 0) {
		pointsAsText = toString(delta);
		color = makecol(20, 255, 20);
	}

	myBattle->addEntity(new BouncyTextEntity(pointsAsText, x, y, color, this->getZOrder()));

	setHP(getHP() + delta);
}
QMap<QString, pokemonStruct> accessAllCaughtPokemon(QString trainerName)
{
    QMap<QString, pokemonStruct> data;
    QSqlQuery query(Dynamic);
    QString statement = "SELECT * FROM CaughtPokemon WHERE trainer='" + trainerName + "'";
    if( !query.exec(statement) )
    {
        qDebug() << query.lastError().databaseText();
        return data;
    }
    while( query.next() )
    {        
        pokemonStruct saved;
        saved.PID = query.record().field("PID").value().toInt();
        saved.attEV = query.record().field("AtEV").value().toInt();
        saved.CPID = query.record().field("CPID").value().toInt();
        saved.defEV = query.record().field("DefEV").value().toInt();
        saved.EXP = query.record().field("EXP").value().toInt();
        saved.HPEV = query.record().field("HPEV").value().toInt();
        saved.speedEV = query.record().field("speedEV").value().toInt();
        saved.HP = query.record().field("HP").value().toInt();
        saved.level = getLevel(saved.EXP);
        saved.name = getPokemonName(QString::number(saved.PID));
        saved.attack = getStat(saved.attEV, getBaseAtt(saved.name), saved.level);
        saved.defense = getStat(saved.defEV, getBaseDef(saved.name), saved.level);
        saved.speed = getStat(saved.speedEV, getBaseSpeed(saved.name), saved.level);
        saved.HP = getHP(saved.HPEV, getBaseHP(saved.name), saved.level);
        QString moves = query.record().field("Moves").value().toString();
        QStringList l = moves.split("|");
        for(int i = 0; i < l.size(); i++)
        {
            QStringList m = l[i].split(".");
            moveStruct move;
            move.name = m[0];
            move.pp = m[1].toInt();
            move.accuracy = getAccuracy(move.name);
            move.damage = getDamage(move.name);
            move.type = getMoveType(move.name);
            saved.moves.append(move);
        }
        data.insert(saved.name, saved);
    }
    return data;
}
Beispiel #30
0
PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
		const std::set<std::string> &privs, bool is_singleplayer):
	ServerActiveObject(env_, v3f(0,0,0)),
	m_player(player_),
	m_peer_id(peer_id_),
	m_inventory(NULL),
	m_last_good_position(0,0,0),
	m_last_good_position_age(0),
	m_time_from_last_punch(0),
	m_nocheat_dig_pos(32767, 32767, 32767),
	m_nocheat_dig_time(0),
	m_wield_index(0),
	m_position_not_sent(false),
	m_armor_groups_sent(false),
	m_properties_sent(true),
	m_privs(privs),
	m_is_singleplayer(is_singleplayer),
	// public
	m_teleported(false),
	m_inventory_not_sent(false),
	m_hp_not_sent(false),
	m_wielded_item_not_sent(false)
{
	assert(m_player);
	assert(m_peer_id != 0);
	setBasePosition(m_player->getPosition());
	m_inventory = &m_player->inventory;
	m_armor_groups["choppy"] = 2;
	m_armor_groups["fleshy"] = 3;

	m_prop.hp_max = PLAYER_MAX_HP;
	m_prop.physical = false;
	m_prop.weight = 75;
	m_prop.collisionbox = core::aabbox3d<f32>(-1/3.,-1.0,-1/3., 1/3.,1.0,1/3.);
	m_prop.visual = "upright_sprite";
	m_prop.visual_size = v2f(1, 2);
	m_prop.textures.clear();
	m_prop.textures.push_back("player.png");
	m_prop.textures.push_back("player_back.png");
	m_prop.spritediv = v2s16(1,1);
	m_prop.is_visible = (getHP() != 0);
	m_prop.makes_footstep_sound = true;
}