コード例 #1
0
        static Tombstone()
        {
            Battle.onReset += () =>
            {
                var a    = Config.instance.map.terrainArray;
                var size = new Vector2Int(a.Length, a[0].Length);
                array = new Tombstone[size.x][];
                for (int x = 0; x < size.x; ++x)
                {
                    array[x] = new Tombstone[size.y];
                }

                list.Clear();
            };

            Battle.onTurnBegin += OnTurnBegin;
        }
コード例 #2
0
 public Data(Tombstone tombstone)
 {
     pos  = tombstone.transform.position.WorldToArray();
     turn = tombstone.turn;
 }
コード例 #3
0
        public async Task <Unit> Buy(List <Action> actions)
        {
            var unit = await R.shop.Buy(this);

            if (!unit)
            {
                return(null);
            }

            var thisPos = transform.position.WorldToArray();

            R.info.UpdateUnitUI(thisPos);
            var prevUnit          = Unit.array[thisPos.x][thisPos.y] == unit ? null : Unit.array[thisPos.x][thisPos.y];
            int?prevTombstoneTurn = Tombstone.array[thisPos.x][thisPos.y]?.turn;

            isBuying = true;

            // Local lambda
            System.Action cancelUnit = async() =>
            {
                army.money += unit.cost;
                (await unit.Die())?.Destroy();
                Unit.array[thisPos.x][thisPos.y] = prevUnit;
                if (prevTombstoneTurn != null)
                {
                    Tombstone.NewOrUpdate(transform.position, (int)prevTombstoneTurn);
                }
                isBuying = false;
            };

            if (prevUnit)
            {
                --prevUnit.spriteRenderer.sortingOrder;
            }
            var buyAction = new BuyAction(thisPos, unit.name);

            while (true)
            {
                R.input.click = null;
                actions.Clear(); actions.Add(buyAction);
                var result = await unit.OnAction(actions);

                switch (result)
                {
                case Unit.ResultOnAction.SUCCESSFULED:
                    isBuying = false;
                    if (prevUnit)
                    {
                        ++prevUnit.spriteRenderer.sortingOrder;
                    }
                    return(unit);

                case Unit.ResultOnAction.FAILED:
                    cancelUnit();
                    if (prevUnit)
                    {
                        ++prevUnit.spriteRenderer.sortingOrder;
                    }
                    return(null);

                case Unit.ResultOnAction.CANCELED:
                case Unit.ResultOnAction.NOACTION:
                    actions.RemoveAt(actions.Count - 1);
                    if (result == Unit.ResultOnAction.NOACTION || (!prevUnit && R.input.click == thisPos))
                    {
                        if (await Play(actions, buyAction))
                        {
                            unit.isSleep = true;
                            goto case Unit.ResultOnAction.SUCCESSFULED;
                        }
                        goto case Unit.ResultOnAction.FAILED;
                    }
                    break;
                }
            }
        }