#include "GEffectManager.h"

#ifdef _DXLIB
#include "GStaticDataDX.h"
#else
#include "GStaticData.h"
#endif

using namespace std;
using namespace GEnum;

GEffectManager::GEffectManager(){
}

GEffectManager::~GEffectManager(){
	clear();
}


void GEffectManager::process(bool isMove, bool bIsAI){

	HPLRect merginedGameRange = getStaticData()->getMerginedGameRange();


	//adds.clear();
	for(std::list<GEffect*>::iterator it = getList()->begin();
		it != getList()->end();)
	{

		GEffect* effect = *it;

		/*if(merginedGameRange.isShare(effect->getHitArea()) == false){
			/////
			// 画面外に出た→死亡

			effect->setAlive(false);
		}*/

		if(isMove && effect->isAlive()){

			/*effect->collision(
				getStaticData()->getBlockManager()->getBlockMatrix(),
				getStaticData()->getBlockManager()->getBlockMap()
				);*/
			staticData.collisionObject( effect );

			/*HPLVector c = effect->getCenter();
			c.add(effect->getVelocityAngle());
			effect->setCenter(c);*/

			if( bIsAI ) {
				algorithm(effect);
			}

			
		}

		if(effect->isAlive()){

#ifdef _DXLIB
			effect->draw();
#else
			effect->draw(getStaticData()->getImageManager());
#endif

			it ++;

		}else{

			if( effect->getType() == Sequence::Effect::CONSTRUCT ) {
				// コンストラクタは味方を呼び出す
				
				if( getStaticData()->m_CommonWork.isEnemyCreatable() ) {
					// 生成して良いか確認する

					GPlayer* lpEnemy = getStaticData()->m_ObjectManager.m_EnemyManager.create(
						effect->m_nCreateEnemyType,
						effect->getCenter(),
						effect->m_nParentForceID );
				}

				
			}

			it = getList()->erase(it);
			delete effect;
		}
	}


}


GEffect* GEffectManager::create(int t, HPLVector center,
								int nCreateEnemyType, int nParentForceID){
	GEffect* ef = new GEffect(t);
	ef->setCenter(center);
	ef->m_nCreateEnemyType = nCreateEnemyType;
	ef->m_nParentForceID = nParentForceID;
	getList()->push_back(ef);
	
	return ef;
}

void GEffectManager::algorithm(GEffect* effect){
	int t = effect->getType();

	int st = effect->getState()->getState();

	HPLSequenceState seqState = effect->getSequence()->getState();

	////
	// 移動
	HPLVector center = effect->getCenter();
	HPLVector velocityAngle = effect->getVelocityAngle();


	//center.add(velocityAngle);
	//effect->setCenter(center);
	effect->setVelocityAngle(velocityAngle);
}
