Пример #1
0
    public Vector2 ApproachWalk(Vector2 dest)
    {
        Vector2 Dir = new Vector2();
        int     min = RogueGeneric.Distance(logicalPos, dest);

        for (int i = 1; i <= 9; i++)
        {
            Vector2 tmp = RogueGeneric.GetVectorFromNum(i);
            if (tmp != new Vector2() && AttemptMove <MovingObject>((int)tmp.x, (int)tmp.y))
            {
                int distance = RogueGeneric.Distance(logicalPos + tmp, dest);
                if (distance < min)
                {
                    min = distance;
                    Dir = tmp;
                }
                else if (distance == min)
                {
                    if ((logicalPos + tmp - dest).sqrMagnitude < (logicalPos + Dir - dest).sqrMagnitude)
                    {
                        Dir = tmp;
                    }
                }
            }
        }

        return(Dir);
    }
Пример #2
0
    //敵キャラ移動用メソッド GameManagerから呼ばれる
    public TurnCommand CommandEnemy()
    {
        SetCommand(TurnCommand.Undef);
        int xDir = 0;
        int yDir = 0;


        if (Status.UsableMagicList.Count > 0)
        {
            SetCommand(SpecialCommand());
        }

        if (GetCommand() != TurnCommand.Undef)
        {
            print(UseMagic);
        }

        Vector2 distance = GameManager.instance.player.logicalPos - logicalPos;

        if (GetCommand() == TurnCommand.Undef)
        {
            if (distance.x <= 1.0f && distance.x >= -1.0f &&
                distance.y <= 1.0f && distance.y >= -1.0f)
            {
                SetDirection(distance);
                SetAttackLine(GetDirection());
                if (AttemptAttack <Wall>().Count == 0)
                {
                    SetCommand(TurnCommand.Attack);
                }
            }
        }

        if (GetCommand() == TurnCommand.Undef)
        {
            Vector2 tmp;
            if (RogueGeneric.Distance(Player.instance.logicalPos, logicalPos) > 5)
            {
                tmp = RandomWalk();
            }
            else
            {
                tmp = ApproachWalk(Player.instance.logicalPos);
            }
            xDir = (int)tmp.x;
            yDir = (int)tmp.y;
            if (AttemptMove <Player>(xDir, yDir))
            {
                SetCommand(TurnCommand.Move);
            }
        }

        TurnCount++;
        return(GetCommand());
    }
Пример #3
0
    private TurnCommand SpecialCommand()
    {
        Vector2 TargetPos;

        List <Enemy> enemies = GameManager.instance.GetEnemyList();

        foreach (Enemy e in enemies)
        {
            TargetPos = e.logicalPos;

            if (Status.UsableMagicList.Count != 0)
            {
                foreach (string m in Status.UsableMagicList)
                {
                    MagicProfile tmp = MagicManager.instance.GetMagicProfileFromID(m);

                    if (tmp.EffectTypeValue == MagicProfile.MagicEffectType.SummonMonster)
                    {
                        if (TurnCount > 10)
                        {
                            UseMagic   = m;
                            TurnCount -= 10;
                            return(TurnCommand.CastMagic);
                        }
                    }

                    if (tmp.FigureTypeValue == MagicProfile.MagicFigureType.Shot &&
                        tmp.EffectTypeValue == MagicProfile.MagicEffectType.Damege)
                    {
                        if ((TargetPos - logicalPos).x == (TargetPos - logicalPos).y ||
                            (TargetPos - logicalPos).x == 0 ||
                            (TargetPos - logicalPos).y == 0)
                        {
                            if (RogueGeneric.Distance(TargetPos, logicalPos) > tmp.Range)
                            {
                                continue;
                            }
                            if (CheckHitLine <Enemy>(logicalPos, TargetPos, AttackableLayer, true))
                            {
                                SetDirection(TargetPos - logicalPos);
                                SetAttackLine(GetDirection());
                                UseMagic = m;
                                return(TurnCommand.CastMagic);
                            }
                        }
                    }
                }
            }
        }

        return(TurnCommand.Undef);
    }
Пример #4
0
    //敵キャラ移動用メソッド GameManagerから呼ばれる
    public TurnCommand CommandNPC()
    {
        if (swapFlag)
        {
            swapFlag = false;
            SetCommand(TurnCommand.Move);
            destPos = SwapDestPos;
            return(GetCommand());
        }
        else
        {
            SetCommand(TurnCommand.Undef);
        }
        int xDir = 0;
        int yDir = 0;

        if (GetCommand() == TurnCommand.Undef)
        {
            if (Status.UsableMagicList.Count > 0)
            {
                SetCommand(SpecialCommand());
            }
        }

        if (GetCommand() == TurnCommand.Undef)
        {
            Vector2      distance;
            List <Enemy> enemies = GameManager.instance.GetEnemyList();

            foreach (Enemy e in enemies)
            {
                distance = e.logicalPos - logicalPos;
                if (distance.x <= 1.0f && distance.x >= -1.0f &&
                    distance.y <= 1.0f && distance.y >= -1.0f)
                {
                    SetDirection(distance);
                    SetAttackLine(GetDirection());
                    if (AttemptAttack <Wall>().Count == 0)
                    {
                        SetCommand(TurnCommand.Attack);
                    }
                }
            }
        }

        if (GetCommand() == TurnCommand.Undef)
        {
            Vector2 tmp;
            tmp = ApproachWalk(Player.instance.logicalPos);
            List <Enemy> enemies = GameManager.instance.GetEnemyList();
            foreach (Enemy e in enemies)
            {
                if (RogueGeneric.Distance(e.logicalPos, logicalPos) < 5)
                {
                    tmp = ApproachWalk(e.logicalPos);
                }
            }
            xDir = (int)tmp.x;
            yDir = (int)tmp.y;
            if (AttemptMove <Player>(xDir, yDir))
            {
                SetCommand(TurnCommand.Move);
            }
        }

        TurnCount++;
        return(GetCommand());
    }