示例#1
0
 public void Init()
 {
     userRaycast.Init();
     poolController.Init();
     userController.Init();
     championController.Init();
 }
示例#2
0
    /// <summary>
    /// 商店购买后地图上生成战士
    /// </summary>
    public bool BuyChampionFromShop(Champion champion)
    {
        //获取位置
        int emptyIndex = -1;

        for (int i = 0; i < ownChampionInventoryArray.Length; i++)
        {
            if (ownChampionInventoryArray[i] == null)
            {
                emptyIndex = i;
                break;
            }
        }

        //空间不足
        if (emptyIndex == -1)
        {
            return(false);
        }

        //金币不足
        if (currentGold < champion.cost)
        {
            return(false);
        }

        //实例化
        GameObject championPrefab = PhotonNetwork.Instantiate(champion.prefab.name, map.ownInventoryGridPositions[emptyIndex], Quaternion.Euler(0, cameraBehavior.GetCameraPoint(playerID, PointType.start).eulerAngles.y, 0));

        ChampionController championController = championPrefab.GetComponent <ChampionController>();

        championController.Init(champion);
        championController.photonView.RPC("setDisable", RpcTarget.All);


        //设置物体的网格属性
        championController.SetGridPosition(Map.GRIDTYPE_OWN_INVENTORY, emptyIndex, -1);

        //设置世界坐标
        championController.SetWorldPosition();

        //存入数组
        StoreChampionInArray(Map.GRIDTYPE_OWN_INVENTORY, map.ownTriggerArray[emptyIndex].gridX, -1, championPrefab);

        //扣除商品费用
        currentGold -= champion.cost;

        //更新
        photonView.RPC("UpdatePlayer", RpcTarget.All, playerID, currentHP, currentGold, currentRank);
        uIController.UpdateUI();

        return(true);
    }
    /// <summary>
    /// Adds champion from shop to inventory
    /// </summary>
    public bool BuyChampionFromShop(Champion champion)
    {
        //get first empty inventory slot
        int emptyIndex = -1;

        for (int i = 0; i < ownChampionInventoryArray.Length; i++)
        {
            if (ownChampionInventoryArray[i] == null)
            {
                emptyIndex = i;
                break;
            }
        }

        //return if no slot to add champion
        if (emptyIndex == -1)
        {
            return(false);
        }

        //we dont have enought gold return
        if (currentGold < champion.cost)
        {
            return(false);
        }

        //instantiate champion prefab
        GameObject championPrefab = Instantiate(champion.prefab);

        //get championController
        ChampionController championController = championPrefab.GetComponent <ChampionController>();

        //setup chapioncontroller
        championController.Init(champion, ChampionController.TEAMID_PLAYER);

        //set grid position
        championController.SetGridPosition(Map.GRIDTYPE_OWN_INVENTORY, emptyIndex, -1);

        //set position and rotation
        championController.SetWorldPosition();
        championController.SetWorldRotation();


        //store champion in inventory array
        StoreChampionInArray(Map.GRIDTYPE_OWN_INVENTORY, map.ownTriggerArray[emptyIndex].gridX, -1, championPrefab);



        //only upgrade when in preparation stage
        if (currentGameStage == GameStage.Preparation)
        {
            TryUpgradeChampion(champion); //upgrade champion
        }
        //deduct gold
        currentGold -= champion.cost;

        //set gold on ui
        uIController.UpdateUI();

        //return true if succesful buy
        return(true);
    }
    /// <summary>
    /// Creates and adds a new random champion to the map
    /// </summary>
    public void AddRandomChampion()
    {
        //get an empty slot
        int indexX;
        int indexZ;

        GetEmptySlot(out indexX, out indexZ);

        //dont add champion if there is no empty slot
        if (indexX == -1 || indexZ == -1)
        {
            return;
        }

        Champion champion = championShop.GetRandomChampionInfo();

        //instantiate champion prefab
        GameObject championPrefab = Instantiate(champion.prefab);

        //add champion to array
        gridChampionsArray[indexX, indexZ] = championPrefab;

        //get champion controller
        ChampionController championController = championPrefab.GetComponent <ChampionController>();

        //setup chapioncontroller
        championController.Init(champion, ChampionController.TEAMID_AI);

        //set grid position
        championController.SetGridPosition(Map.GRIDTYPE_HEXA_MAP, indexX, indexZ + 4);

        //set position and rotation
        championController.SetWorldPosition();
        championController.SetWorldRotation();

        //check for champion upgrade
        List <ChampionController> championList_lvl_1 = new List <ChampionController>();
        List <ChampionController> championList_lvl_2 = new List <ChampionController>();

        for (int x = 0; x < Map.hexMapSizeX; x++)
        {
            for (int z = 0; z < Map.hexMapSizeZ / 2; z++)
            {
                //there is a champion
                if (gridChampionsArray[x, z] != null)
                {
                    //get character
                    ChampionController cc = gridChampionsArray[x, z].GetComponent <ChampionController>();

                    //check if is the same type of champion that we are buying
                    if (cc.champion == champion)
                    {
                        if (cc.lvl == 1)
                        {
                            championList_lvl_1.Add(cc);
                        }
                        else if (cc.lvl == 2)
                        {
                            championList_lvl_2.Add(cc);
                        }
                    }
                }
            }
        }

        //if we have 3 we upgrade a champion and delete rest
        if (championList_lvl_1.Count == 3)
        {
            //upgrade
            championList_lvl_1[2].UpgradeLevel();

            //destroy gameobjects
            Destroy(championList_lvl_1[0].gameObject);
            Destroy(championList_lvl_1[1].gameObject);

            //we upgrade to lvl 3
            if (championList_lvl_2.Count == 2)
            {
                //upgrade
                championList_lvl_1[2].UpgradeLevel();

                //destroy gameobjects
                Destroy(championList_lvl_2[0].gameObject);
                Destroy(championList_lvl_2[1].gameObject);
            }
        }


        CalculateBonuses();
    }