示例#1
0
        private async Task Move(UnitAlgorithm.Target target, float speed = 0.15f)
        {
            if (army.type != Army.Type.LOCAL)
            {
                R.DrawMovePaths(transform.position, target);
                R.pool.targetRect.transform.position = target.pos.ArrayToWorld();
                R.pool.targetRect.SetActive(true);
                await Task.Delay(200);
            }

            R.DrawMovePaths();
            R.pool.targetRect.SetActive(false);
            var start = transform.position.WorldToArray();

            if (array[start.x][start.y] == this)
            {
                array[start.x][start.y] = null;
            }

            var stopW      = transform.position;
            int smokeDelay = 3;
            int smokeCount = 0;

            foreach (var path in target.paths)
            {
                await R.Move(gameObject, stopW += path, speed,
                             () =>
                {
                    R.camCtrl.Focus(transform.position);
                    if (++smokeCount < smokeDelay)
                    {
                        return;
                    }
                    smokeCount = 0;
                    R.pool.Show(ObjectPool.POOL_KEY.MOVING_SMOKE, transform.position);
                });
            }

            R.pool.Hide(ObjectPool.POOL_KEY.MOVING_SMOKE);
            var stop = target.pos;

            array[stop.x][stop.y] = this;
            R.info.UpdateUnitUI(stop);
        }
示例#2
0
        public async Task <Vector3Int?> Move(List <Action> actions)
        {
            var targets = FindMoveTargets();
            var posList = new List <Vector3Int>();

            foreach (var t in targets)
            {
                posList.Add(t.pos);
                R.pool.Show(ObjectPool.POOL_KEY.RED_ALPHA, t.pos.ArrayToWorld());
            }

            while (true)
            {
                var click = await R.input.WaitForClicking();

                if (Battle.endTurnCancel.IsCancellationRequested || !posList.Contains(click.Value))
                {
                    R.pool.Hide(ObjectPool.POOL_KEY.RED_ALPHA);
                    R.DrawMovePaths();
                    R.pool.targetRect.SetActive(false);
                    R.info.armyUI.UpdateTerrain(transform.position.WorldToArray());
                    return(null);
                }

                var pos = click.Value;
                UnitAlgorithm.Target target = default(UnitAlgorithm.Target);
                foreach (var t in targets)
                {
                    if (t.pos == pos)
                    {
                        target = t; break;
                    }
                }
                R.DrawMovePaths();
                if (!R.pool.targetRect.activeSelf)
                {
                    R.pool.targetRect.transform.position = pos.ArrayToWorld();
                    R.pool.targetRect.SetActive(true);
                    R.DrawMovePaths(transform.position, target);
                    R.info.armyUI.UpdateTerrain(pos);
                    continue;
                }
                else if (pos != R.pool.targetRect.transform.position.WorldToArray())
                {
                    await R.Move(R.pool.targetRect, pos.ArrayToWorld(), 0.5f);

                    R.DrawMovePaths(transform.position, target);
                    R.info.armyUI.UpdateTerrain(pos);
                    continue;
                }

                // Move to pos using target and do actions if any
                R.pool.Hide(ObjectPool.POOL_KEY.RED_ALPHA);
                R.pool.targetRect.SetActive(false);
                R.pool.selectRect.SetActive(false);
                var moveAction = new MoveAction(transform.position.WorldToArray(), pos);
                actions.Add(moveAction);
                await Move(target, 0.15f);

                R.pool.targetRect.transform.position = transform.position;
                R.pool.targetRect.SetActive(true);
                var result = await OnAction(actions);

                // Check OnAction result
                click = result == ResultOnAction.NOACTION ? await R.input.WaitForClicking() : R.input.click;

                R.pool.targetRect.SetActive(false);
                switch (result)
                {
                case ResultOnAction.FAILED:
                    await Move(target.Reverse, 0.15f);

                    return(null);

                case ResultOnAction.NOACTION:
                case ResultOnAction.CANCELED:
                    if (Battle.endTurnCancel.IsCancellationRequested)
                    {
                        goto case ResultOnAction.FAILED;
                    }
                    actions.RemoveAt(actions.Count - 1);
                    if (click == pos)
                    {
                        R.pool.targetRect.SetActive(true);
                        bool ok = await Play(actions, moveAction);

                        R.pool.targetRect.SetActive(false);
                        if (ok)
                        {
                            isSleep = true;
                            goto case ResultOnAction.SUCCESSFULED;
                        }
                        goto case ResultOnAction.FAILED;
                    }
                    else
                    {
                        await Move(target.Reverse, 0.15f);

                        R.pool.selectRect.SetActive(true);
                        R.info.armyUI.UpdateTerrain(transform.position.WorldToArray());
                        foreach (var point in posList)
                        {
                            R.pool.Show(ObjectPool.POOL_KEY.RED_ALPHA, point.ArrayToWorld());
                        }
                        continue;
                    }

                case ResultOnAction.SUCCESSFULED:
                    R.pool.selectRect.transform.position = pos.ArrayToWorld();
                    R.pool.selectRect.SetActive(true);
                    return(pos);
                }
            }
        }