void ChainStrikeClientSkillEffect::update(float _dt)
{
	m_lifetime += _dt;

	m_eTarget = ClientEntityHandler::getEntity(m_target);
	
	FLOAT3 myVec = FLOAT3(0, 0, 0);
	if(m_eTarget)
		myVec = m_eTarget->m_model->getPosition() - FLOAT3(m_orig.x, m_orig.y, m_orig.z);

	D3DXVECTOR3 distanceToTarget(myVec.x, myVec.y, myVec.z);

	float onePercent = 1.0f/(ChainStrikeEffect::TIME_BETWEEN_JUMPS);
	m_percentToTarget += onePercent * _dt;

	D3DXVECTOR3 incY(0, 0.5f, 0);
	if(m_eOrig)
		//m_chainEffect->setOrig(D3DXVECTOR3(m_eOrig->m_model->getPosition().x, m_eOrig->m_model->getPosition().y, m_eOrig->m_model->getPosition().z));
		//m_chainEffect->setOrig(D3DXVECTOR3(m_superPos.x, m_superPos.y + 0.2f,m_superPos.z));
		pe[0]->setPosition(m_orig + (distanceToTarget*m_percentToTarget) + incY);
		pe[1]->setPosition(m_orig + (distanceToTarget*m_percentToTarget) + incY);
		pe[2]->setPosition(m_orig + (distanceToTarget*m_percentToTarget) + incY);
	//else
		//m_lifetime = ChainStrikeEffect::TIME_BETWEEN_JUMPS;
	//if(m_eTarget)
		//m_chainEffect->setTarget(D3DXVECTOR3(m_eTarget->m_model->getPosition().x, m_eTarget->m_model->getPosition().y + 0.2f, m_eTarget->m_model->getPosition().z));
		//m_chainEffect->setTarget(D3DXVECTOR3(m_superPos.x, m_superPos.y, m_superPos.z));
		//pe[1]->setPosition(D3DXVECTOR3(m_superPos.x, m_superPos.y, m_superPos.z));


	

	//m_chainEffect->setCamPos(g_graphicsEngine->getCamera()->getPos());
	//m_chainEffect->setViewProj(g_graphicsEngine->getCamera()->getViewProjectionMatrix());
}
Exemplo n.º 2
0
bool MonsterFSM::States( StateMachineEvent event, Message_s * msg, int state )
{
	ASSERT(m_Owner!=0, "Owner was NULL");

// Do the state machine:
BeginStateMachine

	///////////////////////////////////////////////////////////////
	State( STATE_Rnd )
		OnEnter
			m_Owner->CancelOrders();

		OnMsg( MSG_ATTACKED )
			// Attacker becomes our target, retaliate
			if(msg->m_Sender != targetCreatureHANDLE)
			{
				targetCreatureHANDLE = msg->m_Sender;
				SetState(STATE_Attack);
			}

		OnUpdate
			targetCreatureHANDLE = getClosestTarget();

			/*
			If a player is close enough to get our attention, then attack.
			Otherwise, wander randomly
			*/
			if(targetCreatureHANDLE != INVALID_ID)
			{
				SetState(STATE_Pause_Before_Attack);
			}
			else if(m_Owner->anyCollisions() || !m_Owner->HasOrders())
			{
				// Go someplace random
				m_Owner->CancelOrders();
				vec3 waypoint = getRandomWalk();
				float speed = FRAND_RANGE(0.5f, 0.7f);
				m_Owner->QueueCommand(CommandMoveToLocation(waypoint, speed, FLT_EPSILON, 2000.f));
			}

	///////////////////////////////////////////////////////////////
	State( STATE_Pause_Before_Attack )
		OnEnter
			// pause for a moment before reacting
			m_Owner->CancelOrders();
			m_Owner->QueueCommand(CommandFreeze(FRAND_RANGE(200.0f, 400.0f), targetCreatureHANDLE));

		OnUpdate
			if(!m_Owner->HasOrders())
			{
				SetState(STATE_Attack);
			}

	///////////////////////////////////////////////////////////////
	State( STATE_Attack )
		OnEnter
			m_Owner->CancelOrders();
			g_SoundSystem.play(m_Owner->getAttnSfx());

		OnMsg( MSG_ATTACKED )
			// Attacker becomes our new target, retaliate
			if(msg->m_Sender != targetCreatureHANDLE)
			{
				targetCreatureHANDLE = msg->m_Sender;
				SetState(STATE_Attack);
			}

		OnUpdate
			/*
			If we don't have a target, resume wandering.
			Else If target is out of range, resume wandering
			Else If we are low on health, flee.
			Else If we don't have anything to do, keep attacking.
			*/
			if(!haveTarget())
			{
				SetState(STATE_Rnd);
			}
			else if(distanceToTarget() > thresholdLoseInterest)
			{
				SetState(STATE_Rnd);
			}
			else if(m_Owner->getHealthPercentage() < fleeThresholdForHealth)
			{
				SetState(STATE_Flee);
			}
			else if(!m_Owner->HasOrders())
			{
				orderTheAttack();
			}

	///////////////////////////////////////////////////////////////
	State( STATE_Flee )
		OnEnter
			m_Owner->CancelOrders();
			g_SoundSystem.play(m_Owner->getAttnSfx());

		OnMsg( MSG_ATTACKED )
			// Attacker becomes our new target, flee
			if(msg->m_Sender != targetCreatureHANDLE)
			{
				targetCreatureHANDLE = msg->m_Sender;
				SetState(STATE_Flee);
			}

		OnUpdate
			/*
			If we don't have a target, resume wandering.
			Else If target is out of range, resume wandering
			Else If we are not low on health anymore, attack again.
			Else If we don't have anything to do, keep fleeing.
			*/
			if(!haveTarget())
			{
				SetState(STATE_Rnd);
			}
			else if(distanceToTarget() > thresholdLoseInterest)
			{
				SetState(STATE_Rnd);
			}
			else if(m_Owner->getHealthPercentage() >= fleeThresholdForHealth)
			{
				SetState(STATE_Attack);
			}
			else if(!m_Owner->HasOrders())
			{
				m_Owner->QueueCommand(CommandFlee(targetCreatureHANDLE, FRAND_RANGE(0.9f, 1.0f), thresholdLoseInterest, 5000.0f));
			}

	///////////////////////////////////////////////////////////////
EndStateMachine
}