예제 #1
0
    public AIBase createHeroAI(CAMP_TYPE eCampType) {
        AIBase pAI = null;
        switch(eCampType) {
            case CAMP_TYPE.eATTACKER:
                pAI = new AIHeroAttack();
                break;
            case CAMP_TYPE.eDEFENSE:
                pAI = new AIHeroDefend();
                break;
            default:
                break;
        }

       return pAI;
    }
예제 #2
0
    // 根据战士类型和阵营来创建AI,根据阵营和战士类型来创建目标选择策略
    public AIBase createAI(Toy pToy, HERO_TYPE eHeroType, CAMP_TYPE eCampType)
    {
        AIBase pAI = null;
        switch (eHeroType)
        {
            case HERO_TYPE.AI_WARRIOR:            // 战士
            case HERO_TYPE.AI_MASTER:             // 法师
            case HERO_TYPE.AI_TANKING:            // 肉盾
            case HERO_TYPE.AI_SHOOTER:            // 射手
            case HERO_TYPE.AI_WIZARD:             // 巫师
            case HERO_TYPE.AI_PARADIN:            // 奶骑
                {
                    pAI = createHeroAI(eCampType);

                    IBehavior pBehavior = null;
                    // 设置IDLE行为
                    pBehavior = new IdleBehavior();
                    pAI.setIdleBehavior(pBehavior);

                    // 设置思考行为
                    pBehavior = new ThinkBehavior();
                    pAI.setThinkBehavior(pBehavior);

                    // 冷却行为
                    pBehavior = new CoolDownBehavior();
                    pAI.setCoolDownBehavior(pBehavior);

                    // 设置攻击行为
                    pBehavior = new AttackBehavior();
                    pAI.setAttackBehavior(pBehavior);

                    // 设置选择策略
                    IChoiceStrategy pChoiceStrategy = createChooseStrategy();
                    pAI.setChoiceStrategy(pChoiceStrategy);
                }
                break;
            default:
                break;
                
        }

        return pAI;
    }
예제 #3
0
    private bool initToy(Toy pToy, int nTypeID, int nQuality, CAMP_TYPE eCampType, stHeroData pHeroData)
    {
        if (null == pToy)
        {
            return false;
        }

        // 这边是AI类型和英雄类型ID之间的转化关系
        HERO_TYPE eHeroType = (HERO_TYPE)(nTypeID % 10000);

        pToy.TOY_CAMP = eCampType;
        pToy.init(nTypeID, pHeroData);

        pToy.setToyManager(ToyManager.Instance());
        pToy.setMapManager(MapManage.Instance());

        // 建议toy信息都完整了再绑定AI
        pToy.bindMyAI(eHeroType, eCampType);

        return true;
    }
예제 #4
0
    // 只有ID和品质可以影响toy的外观--只创建英雄所以其实可以不用工程方法
    public Toy createToy(int nTypeID, int nQuality, CAMP_TYPE eCampType, stHeroData pHeroData)
    {
        Toy pToy = null;
        stHeroCfg pConfig = HeroConfig.Instance().getHeroInfoById(nTypeID);
        if (null != pConfig)
        {
            HeroToy pHeroToy = new HeroToy();

            // 这样将model放开可以使模型易于扩展
            HeroModel pHeroModel = new HeroModel();
            pHeroModel.init(nTypeID, nQuality);
            pHeroToy.bindModel(pHeroModel);

            pHeroToy.setHeroConfig(pConfig);
            pHeroToy.setHeroData(pHeroData);

            initToy(pHeroToy, nTypeID, nQuality, eCampType, pHeroData);
            pToy = pHeroToy;
        }

        return pToy;
    }
예제 #5
0
    public Vector2 getFreeCell(CAMP_TYPE eCamp)
    {
        int nMinRow = 0;
        int nMaxRow = MAP_ROWS / 2 - 1;
        int i, j;

        if (eCamp == CAMP_TYPE.eDEFENSE)
        {
            nMaxRow = MAP_ROWS - 1;
            nMinRow = MAP_ROWS / 2 + 1;

            for (i = nMaxRow; i >= nMinRow; --i)
            {
                for (j = 0; j < MAP_COLS; ++j)
                {
                    // 表示是空闲的
                    if (0 == m_arrMask[i, j])
                    {
                        return new Vector2(i, j);
                    }
                }
            }
        }
        else
        {
            for (i = nMinRow; i <= nMaxRow; ++i)
            {
                for (j = 0; j < MAP_COLS; ++j)
                {
                    // 表示是空闲的
                    if (0 == m_arrMask[i, j])
                    {
                        return new Vector2(i, j);
                    }
                }
            }
        }

        return Vector2.zero;
    }