BOOL ActorStateMachine::UpdateEffectiveAttack(){
	FnActor actor;
	actor.Object(this->character);
	float frame = actor.QueryCurrentFrame(0);
	//sprintf(debug, "%s frame:%lf\n", debug, frame );
	if (frame > 15.0){
		this->effectiveAttack =	TRUE;
	}
	/*
	if (this->attackKeyQueue[currentAttackIndex] == ULTIMATE_ATT){
		if (frame > 20.0){
			this->newAttack = TRUE;
			this->effectiveAttack =	TRUE;
		}
	}else if (this->attackKeyQueue[currentAttackIndex] == HEAVY_ATT){
		if (frame > 20.0){
			this->effectiveAttack =	TRUE;
		}
	}else if (this->currentAttackIndex > 0){
		if (frame > 10.0){
			this->effectiveAttack =	TRUE;
		}
	}*/
	return FALSE;
}
int ActorStateMachine::AttackEnemy(float enemyPos[3], SHOT_CODE *shot_code){
	if (shot_code != NULL){
		*shot_code = FALSE;
	}
	// the return value is the attack power
	FnActor actor;
	actor.Object(this->character);
	float attackerPos[3], attackerDir[3];
	actor.GetWorldPosition(attackerPos);
	actor.GetWorldDirection(attackerDir,NULL);
	float frame = actor.QueryCurrentFrame(0);

	float dist = 0.0;
	for (int i = 0;i< 3;i++){
		dist += (attackerPos[i] - enemyPos[i]) * (attackerPos[i] - enemyPos[i]);
	}
	//sprintf(debug, "%s dist = %lf\n",debug,dist);
	if ( dist >= ROBOT_ATTACKRANGE ){
		return 0; // no attack power
	}
	float cosine,dotProduct;
	//float v[3];
	dotProduct = 0.0;
	for (int i = 0;i< 3;i++){
		dotProduct += (enemyPos[i] - attackerPos[i]) * attackerDir[i];
	}
	float length = 0.0;
	for (int i = 0;i< 3;i++){
		length += (enemyPos[i] - attackerPos[i])* (enemyPos[i] - attackerPos[i]);
	}
	cosine = dotProduct / sqrt(length);
	//sprintf(debug, "%s cosine = %lf\n",debug,cosine);

	if (this->attackKeyQueue[currentAttackIndex] == HEAVY_ATT || currentAttackIndex == MAXATTACK -1){
		*shot_code = BIG_SHOT;
	}else {
		*shot_code = SMALL_SHOT;
	}

	if (this->currentAttackIndex == 0){
		if (cosine > 0.8){ // normal or heavy attack, only attack the front side enemy
			//sprintf(debug, "%s attack power = %d\n",debug,1);
			return 1;
		}
	}else if (this->currentAttackIndex <= 3){
		if (cosine >= 0.0){
			//sprintf(debug, "%s attack power = %d\n",debug,2);
			return 3;
		}
	}
	return 0;
}