void MonsterController::register_enemy(GameInst* enemy) { mids.push_back(enemy->id); RVO::Vector2 enemy_position(enemy->x, enemy->y); EnemyInst* e = (EnemyInst*)enemy; EffectiveStats& estats = e->effective_stats(); EnemyBehaviour& eb = e->behaviour(); }
void BattleCommanderStateDirection::CheckPointingActor(void){ Cursor3D* cursor3d(_accessor->GetCursor3D()); if(!cursor3d->GetVisible()){ _pointing_actor = nullptr; return; } D3DXVECTOR3 cursor_position(cursor3d->GetPosition()); HitSphere cursor_hit(nullptr, cursor_position, 5.0f); //敵と味方を全部辿って、当たっている奴の中で一番近いやつを指す _pointing_actor = nullptr; float min_length(1000.0f); int player_count(_accessor->GetPlayerCount()); for(int i=0; i<player_count; i++){ BattleActor* player(_accessor->GetPlayer(i)); Hit* player_hit(player->GetCursorHit()); bool hit(player_hit->HitCheck(&cursor_hit)); if(hit){ D3DXVECTOR3 player_position(player->GetPosition()); D3DXVECTOR3 v(player_position - cursor_position); float length(D3DXVec3Length(&v)); if(min_length > length){ min_length = length; _pointing_actor = player; } } } int enemy_count(_accessor->GetEnemyCount()); for(int i=0; i<enemy_count; i++){ BattleActor* enemy(_accessor->GetEnemy(i)); Hit* enemy_hit(enemy->GetCursorHit()); bool hit(enemy_hit->HitCheck(&cursor_hit)); if(hit){ D3DXVECTOR3 enemy_position(enemy->GetPosition()); D3DXVECTOR3 v(enemy_position - cursor_position); float length(D3DXVec3Length(&v)); if(min_length > length){ min_length = length; _pointing_actor = enemy; } } } }
void EnemyAIAttackNeighbor::Update(void){ if(_accessor == nullptr){return;} if(_owner == nullptr){return;} //一番近いターゲットの索敵 float min_length(1000000.0f); BattleActor* target_player(nullptr); for(int i = 0; i<PLAYER_MAX; i++){ BattleActor* player(_accessor->GetPlayer(i)); if(player == nullptr){continue;} D3DXVECTOR3 player_position(player->GetPosition()); D3DXVECTOR3 enemy_position(_owner->GetPosition()); D3DXVECTOR3 enemy_to_player(player_position - enemy_position); D3DXVECTOR3 h_enemy_to_player(enemy_to_player); h_enemy_to_player.y = 0.0f; float h_sq_length(D3DXVec3LengthSq(&h_enemy_to_player)); if(h_sq_length < min_length){ min_length = h_sq_length; target_player = player; } } min_length = sqrt(min_length); const float SEARCH_RANGE(50.0f); const float ATTACK_RANGE(10.0f); if(target_player == nullptr || min_length > SEARCH_RANGE){return;} //一定以上なら向かう if(min_length > ATTACK_RANGE){ _owner->WalkTo(target_player->GetPosition()); } //十分近かったらそいつの方向いて攻撃 else{ //向きチェック if(_owner->GetSkill() == nullptr){ _owner->SetSkill(new BattleSkillAttack(_owner, _renderer, _accessor)); _owner->SetAction(new BattleActionSkill(_owner)); } } }