コード例 #1
0
void GameDataManager::setHeroMoveType(Move_Type type)
{
	this->heroMoveType = type;

	bool isMainLandLevel = MainLandManager::Get()->isMainLand(LevelManager::sShareInstance()->getCurMapId());
	SpriteSeer * seer = GameManager::Get()->getHero();
	if (seer && !isMainLandLevel)
	{
		seer->SetMoveType(type);
		seer->moveToTarget(seer->getPosition(), seer->getPosition());
	}

	HSJoystick * stick = HSJoystick::sharedJoystick();

	if (stick)
	{
		if (!isMainLandLevel)
		{
			stick->setIsEnable(MOVE_BY_JOY == type ? true : false);
		}
		else
		{
			stick->setIsEnable(false);
		}	
	}
}
コード例 #2
0
//----------------------------------------------------------------------------------------
void BaseLevelBuilder::createSeer()
{
	// TODO : tile physics
	if(m_level->m_levelDataReference->mapFilePointer == NULL)
		return;

	unsigned int playerType = UserData::GetUserType();
	ASSERT(m_level->m_levelDataReference->mapFilePointer != NULL, "map file is empty");	

	SpriteSeer* seer = LevelObjectCreator::sCreateSeer(UserData::Get()->getUserId(),UserData::Get()->getUserName(),
		playerType ,
		true
		);

	seer->SetID(UserData::Get()->getUserId());
	seer->setTag(MAP_TAG_SEER);
	m_level->m_pObjectsLayer->addChild(seer, LevelLayer::sCalcZorder(seer->getPosition()));

	GameManager::Get()->setHero(seer);
	GameManager::Get()->setHeroTypeId(seer->GetTypeId());

	SkillDispMgr::Get()->Load("Data/skill.bin", "Data/animationMap.bin");
	SkillDispMgr::Get()->LoadFairy("Data/fairyskill.bin", "Data/fairyanimation.bin");


	// TODO : 实际上,影子可以放到LevelLayer里,不一定要放到ObjectLayer里。
	CATLObjectLayer* pObjLayer = dynamic_cast<CATLObjectLayer*>(m_level->m_pObjectsLayer);
	if(pObjLayer)
	{
		pObjLayer->AddRoleShadow(seer);
	}
}
コード例 #3
0
SpriteMonster * SpriteMonsterMgr::getNearestMonster()
{
	SpriteMonster * nearestMonster = NULL;
	float distance = 10000.0f;
	SpriteSeer * hero = GameManager::Get()->getHero();
	if (!hero || m_tabMonsters.size() == 0)
	{
		return NULL;
	}

	map<int, SpriteMonster*>::iterator it = m_tabMonsters.begin();

	SpriteMonster * firstMonster = it->second;

	//能被锁定的怪物才记入数据,隐身不计入
	if (firstMonster->getCanBeFocus() && !firstMonster->getIsAlliance())
	{
		distance = ccpDistance(firstMonster->getPosition(), hero->getPosition());
		nearestMonster = firstMonster;
	}	

	for(; it != m_tabMonsters.end(); it++ )
	{
		SpriteMonster* monster = it->second;
		if (!monster->getCanBeFocus() || monster->getIsAlliance())
		{
			continue;
		}

		float dis = ccpDistance(monster->getPosition(), hero->getPosition());
		if (dis < distance && monster->fsm_rule.IsRunning())
		{
			distance = dis;
			nearestMonster = monster;
		}	
	}

	return nearestMonster;
}
コード例 #4
0
//----------------------------------------------------------------------------------------
//			others function means other players'
//----------------------------------------------------------------------------------------
void BaseLevelBuilder::addOtherPlayer(unsigned int uid, const char* userName,unsigned int type, cocos2d::CCPoint pt, unsigned int orient, unsigned int battleSide)
{
	std::map<uint32_t, OthersPlayerInfo>::iterator itor = m_level->m_othersPlayerInfo.find(uid);
	if (itor == m_level->m_othersPlayerInfo.end())
	{
		//
		OthersPlayerInfo playerInfo;
		playerInfo.seer = NULL;
		playerInfo.pet = NULL;
#if _DEBUG
		playerInfo.name = userName;
#endif
		//add seer
		ASSERT(m_level->m_levelDataReference->mapFilePointer != NULL, "map file is empty");
		SpriteSeer* seer = LevelObjectCreator::sCreateSeer(uid,userName,
			type, 
			false);

		if(NULL == seer)
		{
			return;
		}

		

		seer->SetID(uid);
		seer->setTag(MAP_TAG_OTHER_SEER);
		seer->setPosition(pt);
		seer->SetBattleSide(battleSide);

		if (m_level->m_pObjectsLayer)
		{
			m_level->m_pObjectsLayer->addChild(seer, LevelLayer::sCalcZorder(seer->getPosition()));

			bool isMainLand = MainLandManager::Get()->isMainLand(m_level->m_id);
			int	animID;
			if (isMainLand)
			{
				animID = kTypeIdle_FaceDown_Stand_MAIN;
			}
			else
			{
				animID = kTypeIdle_FaceDown_Stand_OTH;
			}
			
			/*switch(orient)
			{
			case DIRECTION_UP:
			animID = kTypeIdle_FaceUp_Stand_MAIN;
			break;
			case DIRECTION_LEFT:
			break;
			case DIRECTION_BOTTOM:
			break;
			case DIRECTION_RIGHT:
			break;
			default:
			break;
			}*/
			seer->SetAnim(animID,1,true);
		}

		playerInfo.seer = seer;

		//add pet
		//if (petType != 0)
		//{
		//	SpriteElf* elf = LevelObjectCreator::sCreateSpriteElf(petType, 0, true,
		//		MAP_TAG_OTHER_FOLLOW_SPRITE ,
		//		true);

		//	elf->setTag(MAP_TAG_OTHER_FOLLOW_SPRITE);
		//	elf->followSeerPosition(pt, true);
		//	m_level->addChild(elf, LevelLayer::sCalcZorder(elf->getPosition()));

		//	playerInfo.pet = elf;
		//}

		//
		m_level->m_othersPlayerInfo.insert(std::pair<uint32_t, OthersPlayerInfo>(uid, playerInfo));

		CATLObjectLayer* pObjLayer = dynamic_cast<CATLObjectLayer*>(m_level->m_pObjectsLayer);
		if(pObjLayer)
		{
			pObjLayer->AddRoleShadow(seer);
		}

	}
	else
	{
		CCLog("error, the player has add before");
	}
}
コード例 #5
0
ファイル: PvAIManager.cpp プロジェクト: niuzb/hellopetclient
void PvAIManager::moveToHero()
{
    SpriteSeer * hero = GameManager::Get()->getHero();

    SkillDispMgr * skillMgr = SkillDispMgr::Get();

    int skillId = getBestSkill();
    if (skillId)
    {
        for (size_t i = 0; i < skills.size(); i++)
        {
            if (skillId == skills[i])
            {
                skills.erase(skills.begin() + i);
                skills.push_back(skillId);
                break;
            }
        }

        if (skillMgr->GetSkillInfo(skillId)->type != ToNormalAttack)
        {
            CCPoint vec = ccpSub(hero->getPosition(), aiPlayer->getPosition());
            vec = ccpNormalize(vec);
            aiPlayer->setDirection(vec);
            if(!aiPlayer->DoSkillAttack(skillId))
            {
                if (hero)
                {
                    if( aiPlayer->canMove )
                        aiPlayer->moveToTarget(hero->getPosition(), aiPlayer->getPosition());
                }
            }
        }
        else
        {
            CCPoint vec = ccpSub(hero->getPosition(), aiPlayer->getPosition());
            vec = ccpNormalize(vec);
            aiPlayer->setDirection(vec);
            aiPlayer->DoNormalAttack();
        }
    }
    else if (hero)
    {
        CCPoint pt = hero->getPosition();
        CCPoint pixPos = aiPlayer->getPosition();
        if (LevelManager::sShareInstance()->isPointReachable(pt))
        {
            aiPlayer->moveToTarget(pt, pixPos);
        }
        else
        {
            CCPoint vec = ccpNormalize(ccpSub(pt, pixPos));
            do
            {
                pt = ccpSub(pt, vec);
            } while (!LevelManager::sShareInstance()->isPointReachable(pt));
            aiPlayer->moveToTarget(pt, pixPos);
        }
    }

    return;
}
コード例 #6
0
ファイル: PvAIManager.cpp プロジェクト: niuzb/hellopetclient
int PvAIManager::getBestSkill()
{
    int skillId = 0;
    int normalAttackId = 0;
    bool canDoSkill = false;

    SpriteSeer * hero = GameManager::Get()->getHero();
    if (!hero)
    {
        return skillId;
    }

    //循环遍历确定是否有技能正在释放
    SkillDispMgr * skillMgr = SkillDispMgr::Get();

    bool doingSkill = false;
    for (size_t i = 0; i < skills.size(); i++)
    {
        const SKILL_INFO * info = skillMgr->GetSkillInfo(skills[i]);

        if (aiPlayer->m_pStateMachine->CheckStateRuning(info->type))
        {
            doingSkill = true;
            break;
        }
    }

    //从头遍历可以释放的技能
    for (size_t i = 0; i < skills.size(); i++)
    {
        const SKILL_INFO * info = skillMgr->GetSkillInfo(skills[i]);

        //找出普通攻击id
        if (info->type == ToNormalAttack)
        {
            normalAttackId = skills[i];
            continue;
        }

        //未释放技能时才检测技能cd及距离
        if (!doingSkill)
        {

            if (skillMgr->IsCD(aiPlayerId, skills[i]))
            {
                continue;
            }

            if (ccpDistance(aiPlayer->getPosition(), hero->getPosition()) < info->longDistanceAttackRange)
            {
                canDoSkill = true;
                skillId = skills[i];

                break;
            }
        }
    }

    //普通攻击
    if (!canDoSkill && normalAttackId)
    {
        const SKILL_INFO * info = skillMgr->GetSkillInfo(normalAttackId);
        if (ccpDistance(aiPlayer->getPosition(), hero->getPosition()) < info->longDistanceAttackRange)
        {
            skillId = normalAttackId;
        }
    }


    return skillId;
}
コード例 #7
0
cocos2d::CCNode* ElfAttackTrigger::GetNearestMonster( void )
{
	cocos2d::CCNode* pRet = NULL;
	float minDis = 0.0f;
	minDis = m_pSkill->longDistanceAttackRange;

	if(minDis <= 0.0f)
		minDis = 320.0f;

	minDis *= minDis;
	if(LevelManager::sShareInstance()->isCurrentPVPLevel())
	{
		if(LevelManager::sShareInstance()->getCurrentLevelLayer())
		{
			USERINFO* pHeroInfo = UserData::Get()->GetUserInfo(m_pRole->GetID());

			std::map<unsigned int, OthersPlayerInfo>& otherPlayer = LevelManager::sShareInstance()->getCurrentLevelLayer()->m_othersPlayerInfo;
			for(std::map<unsigned int, OthersPlayerInfo>::const_iterator iter = otherPlayer.begin(); iter != otherPlayer.end(); iter++)
			{
				SpriteSeer* pOhterHero = iter->second.seer; 

				if(m_pRole == pOhterHero || pOhterHero == NULL)
					continue;

				USERINFO* pOtherInfo = UserData::Get()->GetUserInfo(pOhterHero->GetID());
				if(pHeroInfo && pOhterHero)
				{
					if(pHeroInfo->battleSide % 2 == pOtherInfo->battleSide % 2)
						continue;
				}

				float dis = ccpDistanceSQ(pOhterHero->getPosition(), m_pElf->getPosition());
				if( dis <= minDis)
				{
					pRet = pOhterHero;
					minDis = dis;

				}
			}

			
		}
	}
	else
	{
		const map<int, SpriteMonster*>& allMonster = SpriteMonsterMgr::Get()->GetAllMonster();
		for(map<int, SpriteMonster*>::const_iterator iter = allMonster.begin(); iter != allMonster.end(); iter++)
		{
			float dis = ccpDistanceSQ(iter->second->getPosition(), m_pElf->getPosition());
			if( dis <= minDis)
			{
				pRet = iter->second;
				minDis = dis;

			}
		}
	}
	

	return pRet;
}
コード例 #8
0
cocos2d::CCPoint ElfAimDirectionHandler::GetAimDirection()
{
	CCPoint ret = m_pElf->getDirectionVector();
	CCPoint rolePos = m_pElf->getPosition();

	
	if(LevelManager::sShareInstance()->isCurrentPVPLevel())
	{
		if(LevelManager::sShareInstance()->getCurrentLevelLayer())
		{
			float minDis = m_pSkill->longDistanceAttackRange;

			if(minDis <= 0.0f)
				minDis = 320.0f;

			minDis *= minDis;

			SpriteSeer* pNearestHero = NULL;

			std::map<unsigned int, OthersPlayerInfo>& otherPlayer = LevelManager::sShareInstance()->getCurrentLevelLayer()->m_othersPlayerInfo;

			for(std::map<unsigned int, OthersPlayerInfo>::const_iterator iter = otherPlayer.begin(); iter != otherPlayer.end(); iter++)
			{
				SpriteSeer* pOhterHero = iter->second.seer; 
				if(m_pRole == pOhterHero || pOhterHero == NULL)
					continue;

				float dis = ccpDistanceSQ(pOhterHero->getPosition(), m_pElf->getPosition());
				if( dis <= minDis)
				{
					pNearestHero = pOhterHero;
					minDis = dis;

				}
			}

			if(pNearestHero)
			{
				m_bAimMonster = true;
				m_nearestMonsterPos = pNearestHero->getPosition();
				ret = ccpSub(m_nearestMonsterPos, rolePos);
			}
		}
	}
	else
	{
		SpriteMonster* pNearestMonster = GetNearestMonster();

		if(pNearestMonster)
		{
			m_bAimMonster = true;
			m_nearestMonsterPos = pNearestMonster->getPosition();
			ret = ccpSub(m_nearestMonsterPos, rolePos);

		}
	}

	

	ret = ccpNormalize(ret);

	return ret;
}