Esempio n. 1
0
void SpriteSystem::heroAttack(BaseSprite *hero)
{
    if (hero->getSpriteState() == SPRITESTATE_DEAD) return;
    
    hero->startAction(SPRITESTATE_ATTACK);
    //判断弹道
    if (hero->getSpConf().type != SPRITETYPE_FRONT)//不是前排人物
    {
        int magicId = hero->getSpConf().magicGroup.magic1;
        Magic* magic = Magic::create(m_magConf[magicId]);
        magic->startMagic(hero, hero->getTargetSp(), 0.8);
        this->addChild(magic,2);
    }
    else
    {
        //随机攻击力
        int randAttack = hero->getSpConf().attackMin + rand()%(hero->getSpConf().attackMax - hero->getSpConf().attackMin);
        //更新生命值
        hero->getTargetSp()->setCurLife(hero->getTargetSp()->getCurLife() - randAttack);
        //显示敌人生命值
        showLifeTop(hero->getTargetSp());
    }
    if(hero->getTargetSp()->getCurLife() <= 0)
    {
        hero->getTargetSp()->startAction(SPRITESTATE_DEAD);//没有移除
        //改变攻击对象
        setAttackTarget();
    }
}
Esempio n. 2
0
void SpriteSystem::enemyAttack(float dt)
{
    for(uint i = 0; i < m_vEnemys.size(); i++)
    {
        BaseSprite* enemy = m_vEnemys.at(i);
        if(enemy->getSpriteState() != SPRITESTATE_DEAD)//如果没有死亡
        {
            m_fAttackElapseTime[i] += dt;//更新时间
            if (m_fAttackElapseTime[i] >= enemy->getSpConf().attackSpeed)//怪物达到攻击时间
            {
                m_fAttackElapseTime[i] = 0;//计时归零
                enemy->startAction(SPRITESTATE_ATTACK);//攻击动作
                //判断弹道
                if (enemy->getSpConf().type != SPRITETYPE_FRONT)//不是前排人物
                {
                    int magicId = enemy->getSpConf().magicGroup.magic1;
//                    Magic* magic = m_vMagics.at(magicId);//这样多个英雄释放同一种技能时会重复addChild。
                    Magic* magic = Magic::create(m_magConf[magicId]);
                    magic->startMagic(enemy, enemy->getTargetSp(), 0.8);
                    magic->setFlippedX(true);//怪物攻击特效翻转
                    this->addChild(magic,2);
                }
                else
                {
                    //随机攻击力
                    int randAttack = enemy->getSpConf().attackMin + rand()%(enemy->getSpConf().attackMax - enemy->getSpConf().attackMin);
                    //更新生命值
                    enemy->getTargetSp()->setCurLife(enemy->getTargetSp()->getCurLife() - randAttack);
                }
                if(enemy->getTargetSp()->getCurLife() <= 0)
                {
                    enemy->getTargetSp()->startAction(SPRITESTATE_DEAD);//没有移除
                    long index = m_vHeros.getIndex(enemy->getTargetSp());
                    m_itItem[index]->setEnabled(false);//禁用技能按钮
                    //改变攻击对象
                    setAttackTarget();
                }
                
                if (enemy->getCurPower() < enemy->getSpConf().power)
                {
                    enemy->setCurPower(enemy->getCurPower() + 1);//怒气+1
                }
                else
                {
//                    enemy->setIsMagic(true);//允许释放魔法
                    //直接释放技能(大招)
                    enemy->startAction(SPRITESTATE_MAGIC);
                }
            }
        }
    }
}
void MoGong::coverCardAnalyse()
{
    Role::coverCardAnalyse();
    SafeList<Card*> selectedCoverCards = this->coverArea->getSelectedCards();
    try{
    switch(state)
    {
    case MO_GUAN_CHONG_JI:
        if(selectedCoverCards[0]->getElement()=="fire")
            decisionArea->enable(0);
        break;
      case MO_GUAN_CHONG_JI_HIT:
        decisionArea->enable(0);
        break;
     case LEI_GUANG_SAN_SHE:
        if(selectedCoverCards.size()==1)
        {
            decisionArea->enable(0);
            playerArea->disableAll();
            playerArea->setQuota(0);
        }
        else
        {
            decisionArea->disable(0);
            playerArea->enableEnemy();
            playerArea->setQuota(1);
        }
        break;
     case DUO_CHONG_SHE_JI:
        setAttackTarget();
        playerArea->disablePlayerItem(lastTarget);
        break;
    }
    }catch(int error){
        logic->onError(error);
    }
}
Esempio n. 4
0
bool CON_EnemyCanAttack::onEvaluate(const BTInputParam& input) const
{
	const BlackBoard& inputData	= input.getRealData<BlackBoard>();

	auto self = inputData.self;

	auto area = self->getAttackArea();
	area.x += self->getPositionX();
	area.y += self->getPositionY();

	// 寻找可攻击目标;
	GameObject *foundObject = nullptr;
	OBJECTS->callObjects([&](int id, GameObject *object, GameObjectView *view) -> bool {
		if (object && !object->shouldClean() && object->group() != self->group()) // 对象不销毁,非同组;
		{
			if (area.containsPoint(object->getPosition()))
			{
				foundObject = object;
				return false;	// 寻找第一个可攻击目标;
			}
		}
		return true;
	});

	if (foundObject)
	{
		self->setAttackTarget(foundObject);
		return true;
	}
	else
	{
		return false;
	}

	return false;
}
Esempio n. 5
0
void Role::cardAnalyse()
{
    int i;
    QList<Card*> selectedCards=handArea->getSelectedCards();
    Player* myself=dataInterface->getMyself();
    QString cardName;
    switch (state)
    {
//normal action
    case 1:
//追加攻击或法术行动
    case 11:
    case 12:
        if(selectedCards[0]->getType()=="magic" )
        {
            cardName=selectedCards[0]->getName();
            if(cardName==QStringLiteral("中毒"))
                playerArea->enableAll();
            if(cardName==QStringLiteral("虚弱"))
            {
                playerArea->reset();
                for(i=0;i<dataInterface->getPlayerMax();i++)
                    if(!dataInterface->getPlayerList().at(i)->checkBasicStatus(1))
                        playerArea->enablePlayerItem(i);
            }
            if(cardName==QStringLiteral("圣盾"))
            {
                playerArea->reset();
                for(i=0;i<dataInterface->getPlayerMax();i++)
                    if(!dataInterface->getPlayerList().at(i)->checkBasicStatus(2))
                        playerArea->enablePlayerItem(i);
            }
            if(cardName==QStringLiteral("魔弹"))
            {
                playerArea->reset();
                playerArea->enablePlayerItem(nextCounterClockwise);
            }
        }
        else
    case 10:
            setAttackTarget();
    break;
//attacked reply
    case 2:
        if(selectedCards[0]->getType()=="attack" )
        {
            playerArea->reset();
            playerArea->enableEnemy();
            playerArea->disablePlayerItem(sourceID);
        }
        if(selectedCards[0]->getElement()=="light")
        {
            playerArea->reset();
            decisionArea->enable(0);
        }
    break;
//drop cards
    case 3:
//天使祝福给牌
    case 751:
//魔爆冲击弃牌,充盈
    case 851:
    case 2951:
        decisionArea->enable(0);
    break;
//魔弹reply
    case 8:
        cardName=selectedCards[0]->getName();
        if(cardName==QStringLiteral("魔弹"))
        {
            playerArea->reset();
            playerArea->enablePlayerItem(moDanNextID);
        }
        else if(cardName==QStringLiteral("圣光"))
        {
            playerArea->reset();
            decisionArea->enable(0);
        }
        break;
    }
}
Esempio n. 6
0
void SpriteSystem::initBSandMagic()
{
    //初始化人物
    struct _stHeroConf
    {
        float spScale[3];//缩放
        Point spPosStart[3];//起始位置
        Point spPosEnd[3];//结束位置
        bool  spFlip[3];//是否翻转,英雄翻转,敌人不翻转,面对面
        
        _stHeroConf()
        {
            spScale[0] = 1.5f; spScale[1] = 1.5f; spScale[2] = 1.5f;
            spFlip[0] = true; spFlip[1] = true; spFlip[2] = true;
            spPosStart[0] = PointS_1; spPosStart[1] = PointS_2; spPosStart[2] = PointS_3;
            spPosEnd[0] = PointE_1; spPosEnd[1] = PointE_2; spPosEnd[2] = PointE_3;
        }
    }_stHeroConf;
    
    struct _stEnemyConf
    {
        float spScale[3];//缩放
        Point spPosStart[3];//起始位置
        Point spPosEnd[3];//结束位置
        bool  spFlip[3];//是否翻转,英雄翻转,敌人不翻转,面对面
        
        _stEnemyConf()
        {
            spScale[0] = 1.5f; spScale[1] = 1.5f; spScale[2] = 1.5f;
            spFlip[0] = false; spFlip[1] = false; spFlip[2] = false;
            spPosStart[0] = PointS_4; spPosStart[1] = PointS_5; spPosStart[2] = PointS_6;
            spPosEnd[0] = PointE_4; spPosEnd[1] = PointE_5; spPosEnd[2] = PointE_6;
        }
    }_stEnemyConf;
    
    //初始化英雄和敌人
    for (unsigned int i = 0; i < 3; i++)
    {
        BaseSprite* hero = BaseSprite::create(m_bsConf[i]);
        hero->setScale(_stHeroConf.spScale[i]);
        hero->setPosition(_stHeroConf.spPosStart[i]);
        hero->setFlippedX(_stHeroConf.spFlip[i]);
        hero->startAction(SPRITESTATE_IDLE);
        hero->move(MoveType_To, _stHeroConf.spPosEnd[i], 4.5f);//执行完有回调
        addChild(hero,1);
        //加入向量
        m_vHeros.pushBack(hero);
        
        BaseSprite* enemy = BaseSprite::create(m_bsConf[i+3]);
        enemy->setScale(_stEnemyConf.spScale[i]);
        enemy->setPosition(_stEnemyConf.spPosStart[i]);
        enemy->setFlippedX(_stEnemyConf.spFlip[i]);
        enemy->startAction(SPRITESTATE_IDLE);
        enemy->move(MoveType_To, _stEnemyConf.spPosEnd[i], 4.5f);//执行完有回调
        addChild(enemy,1);
        //加入向量
        m_vEnemys.pushBack(enemy);
        
        Node* node = Node::create();
        Sprite* lifebg = Sprite::create(s_ptBg);//背景
        m_ptLifeTop[i] = ProgressTimer::create(Sprite::create(s_ptLife2));//进度条
        m_ptLifeTop[i]->setType(ProgressTimer::Type::BAR);//条形
        m_ptLifeTop[i]->setMidpoint(Point::ANCHOR_MIDDLE_LEFT);//(0,0.5)锚点为增长原点
        m_ptLifeTop[i]->setBarChangeRate(Point::ANCHOR_MIDDLE_RIGHT);//向(1,0.5)增长
        m_ptLifeTop[i]->setPercentage(100);
        
        node->setPosition(enemy->getContentSize().width/2,enemy->getContentSize().height*0.8);
        enemy->addChild(node);
        node->addChild(lifebg, 0);
        node->addChild(m_ptLifeTop[i], 1);
        node->setScale(0.8);
        
        //添加敌人生命值
    }
 
    setAttackTarget();//设置攻击目标
    
//    //初始化技能、远程攻击 --》不能这样,因为多个英雄释放同一种技能时,会重复addChild
//    for(int i = 0; i < 5; i++)
//    {
//        Magic* magic = Magic::create(m_magConf[i]);
//        m_vMagics.pushBack(magic);//这里会retain一下
//    }
    scheduleUpdate();
}