Exemple #1
0
        public static Unit New(Name name, Army army, Vector3?wPos = null)
        {
            var unit = Instantiate(R.asset.prefab.units[name], wPos != null ? wPos.Value : Vector3.zero, Quaternion.identity);

            unit.levelNameGenerator = UnitAlgorithm.LevelNameGenerator(unit);
            unit.army = army;
            return(unit);
        }
Exemple #2
0
        public async Task <Vector3Int?> Attack(List <Action> actions)
        {
            var targets = FindAttackTargets();

            foreach (var pos in targets)
            {
                R.pool.Show(ObjectPool.POOL_KEY.YELLOW_ALPHA, pos.ArrayToWorld());
            }

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

                if (Battle.endTurnCancel.IsCancellationRequested || !targets.Contains(click.Value))
                {
                    R.pool.Hide(ObjectPool.POOL_KEY.YELLOW_ALPHA);
                    R.pool.selectCircle.SetActive(false);
                    return(null);
                }

                var pos = click.Value;
                if (!R.pool.selectCircle.activeSelf)
                {
                    R.pool.selectCircle.transform.position = pos.ArrayToWorld();
                    R.pool.selectCircle.SetActive(true);
                    R.info.UpdateUnitUI(pos);
                    continue;
                }
                else if (pos != R.pool.selectCircle.transform.position.WorldToArray())
                {
                    await R.Move(R.pool.selectCircle, pos.ArrayToWorld(), 0.5f);

                    R.info.UpdateUnitUI(pos);
                    continue;
                }

                R.pool.Hide(ObjectPool.POOL_KEY.YELLOW_ALPHA);
                float eDeltaH = -1f, thisDeltaH = -1f;
                var   unit = array[pos.x][pos.y];
                if (unit && unit.army.group != army.group)
                {
                    UnitAlgorithm.CalculateAttack(this, unit, out eDeltaH, out thisDeltaH);
                }

                bool result = await Play(actions, new AttackAction(transform.position.WorldToArray(), pos, eDeltaH, thisDeltaH));

                R.pool.selectCircle.SetActive(false);
                R.info.passiveUnitUI.SetActive(false);
                if (result)
                {
                    await Attack(pos, eDeltaH, thisDeltaH);

                    R.info.UpdateUnitUI(transform.position.WorldToArray());
                    return(pos);
                }
                return(null);
            }
        }
Exemple #3
0
        public IReadOnlyList <Vector3Int> FindRaiseTargets()
        {
            var result = new List <Vector3Int>();

            foreach (var pos in UnitAlgorithm.FindTarget(transform.position.WorldToArray(), 0, 0))
            {
                if (Tombstone.array[pos.x][pos.y] && !array[pos.x][pos.y])
                {
                    result.Add(pos);
                }
            }

            return(result);
        }
Exemple #4
0
        public IReadOnlyList <Vector3Int> FindHealTargets()
        {
            var result = new List <Vector3Int>();

            foreach (var pos in UnitAlgorithm.FindTarget(transform.position.WorldToArray(), 0, 1))
            {
                if (array[pos.x][pos.y]?.army.group == army.group)
                {
                    result.Add(pos);
                }
            }

            return(result);
        }
Exemple #5
0
        public virtual IReadOnlyList <Vector3Int> FindAttackTargets()
        {
            var result = new List <Vector3Int>();

            foreach (var pos in UnitAlgorithm.FindTarget(transform.position.WorldToArray(), 0, 0))
            {
                var unit = array[pos.x][pos.y];
                if (unit && unit.army.group != army.group)
                {
                    result.Add(pos);
                }
            }

            return(result);
        }
Exemple #6
0
        public override IReadOnlyList <Vector3Int> FindAttackTargets()
        {
            if (army != Battle.instance.army)
            {
                return(base.FindAttackTargets());
            }
            var result = new List <Vector3Int>();

            foreach (var pos in UnitAlgorithm.FindTarget(transform.position.WorldToArray(), 0, 1))
            {
                var unit = array[pos.x][pos.y];
                if (unit && unit.army.group != army.group)
                {
                    result.Add(pos);
                }
            }

            return(result);
        }
        public override IReadOnlyList <Vector3Int> FindAttackTargets()
        {
            var result = new List <Vector3Int>();

            if (isMoving || Castle.isBuying || army != Battle.instance.army)
            {
                return(result);
            }

            foreach (var pos in UnitAlgorithm.FindTarget(transform.position.WorldToArray(), 1, 3))
            {
                var unit    = array[pos.x][pos.y];
                var terrain = AETerrain.array[pos.x][pos.y];
                if (unit && unit.army.group != army.group || terrain is House && (terrain as House).CanBreak())
                {
                    result.Add(pos);
                }
            }

            return(result);
        }
Exemple #8
0
 public IReadOnlyList <UnitAlgorithm.Target> FindMoveTargets() => UnitAlgorithm.FindMove(this);