コード例 #1
0
ファイル: GameController.cs プロジェクト: Pongparit/ABSU
    IEnumerator defaultFieldEvent()
    {
        DefaultField field     = defaultField.Find(x => x.Id == players[currentPlayer].fieldId);
        Player       curPlayer = players[currentPlayer];
        Player       owner     = field.owner;

        if ((owner == null || owner == curPlayer) && curPlayer.buyQouta > 0)
        {
            //No Owner
            isShopOpen = true;
            isBuyFin   = false;
            ShopCanvas.SetActive(isShopOpen);
            // Debug.Log(defaultField.Find(x => x.Id== curPlayer.fieldId).ToString());
            shoplist.Display(curPlayer, defaultField.Find(x => x.Id == curPlayer.fieldId));
            // logManager.addLog("test");
            yield return(new WaitUntil(() => isBuyFin == true));

            curPlayer.updateUI();
            field.updateUI();

            isShopOpen = false;
            ShopCanvas.SetActive(isShopOpen);
            //
            yield return(null);
        }
        else
        {
            //Other Owner
            int standCost   = field.getStandCost();
            int buyoutPrice = field.getBuyOutPrice();
            //Reduce Money here
            if (curPlayer.money > standCost)
            {
                curPlayer.money -= standCost;
                owner.money     += standCost;

                logManager.addLog(string.Format("{0} Lose {1} Baht to {2}.", curPlayer.name, standCost, owner.name));
                owner.updateUI();
                curPlayer.updateUI();
                // field.updateUI();
                if (curPlayer.money >= buyoutPrice)
                {
                    //Buy out here
                    isBuyFin    = false;
                    isBuyOut    = false;
                    isBuyoutFin = false;
                    BuyOutCanvas.SetActive(true);
                    buyout.Display(curPlayer, defaultField.Find(x => x.Id == curPlayer.fieldId));
                    yield return(new WaitUntil(() => isBuyoutFin == true));

                    BuyOutCanvas.SetActive(false);
                    owner.updateUI();
                    curPlayer.updateUI();
                    field.updateUI();
                    if (isBuyOut && curPlayer.buyQouta > 0 && field.type == FieldType.defaultField)
                    {
                        isShopOpen = true;
                        ShopCanvas.SetActive(isShopOpen);
                        shoplist.Display(curPlayer, defaultField.Find(x => x.Id == curPlayer.fieldId));
                        yield return(new WaitUntil(() => isBuyFin == true));

                        isShopOpen = false;
                        ShopCanvas.SetActive(isShopOpen);
                        owner.updateUI();
                        curPlayer.updateUI();
                        field.updateUI();
                    }
                }
            }
            else
            {
                owner.money += standCost;
                foreach (DefaultField f in curPlayer.owning)
                {
                    f.removePlant();
                    f.owner = null;
                }
                players.Remove(curPlayer);
            }

            yield return(null);
        }
    }