Beispiel #1
0
        public static BattleBlockVector FromInt(int hash)
        {
            var lb = new BattleBlockVector();

            lb.X = hash / 10000;
            lb.Y = hash % 10000;
            return(lb);
        }
Beispiel #2
0
        public static List <BattleBlockVector> FromInt(HashSet <int> hashs)
        {
            List <BattleBlockVector> list = new List <BattleBlockVector>();

            foreach (int hash in hashs)
            {
                list.Add(BattleBlockVector.FromInt(hash));
            }
            return(list);
        }
Beispiel #3
0
 //增加一个战斗角色
 public void AddBattleRole(RoleInstance role, BattleBlockVector pos, int team, bool isAI)
 {
     role.View.GetAnimator().SetFloat("speed", 0);
     role.BattleModel = this;
     role.Pos         = pos;
     role.team        = team;
     role.isAI        = isAI;
     role.isActed     = false;
     role.isWaiting   = false;
     if (!Roles.Contains(role))
     {
         Roles.Add(role);
     }
 }
Beispiel #4
0
 public RoleInstance GetAliveRole(BattleBlockVector vec)
 {
     foreach (var r in Roles)
     {
         if (r.IsDead())
         {
             continue;
         }
         if (r.Pos.Equals(vec))
         {
             return(r);
         }
     }
     return(null);
 }
Beispiel #5
0
        /// <summary>
        /// 返回附近距离为1的格子
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public IEnumerable <BattleBlockVector> GetNearBlocks(int x, int y)
        {
            for (int i = 0; i < 4; ++i)
            {
                int xx = x + dx[i];
                int yy = y + dy[i];
                if (xx < 0 || xx >= MOVEBLOCK_MAX_X)
                {
                    continue;
                }
                if (yy < 0 || yy >= MOVEBLOCK_MAX_Y)
                {
                    continue;
                }

                if (Exists != null && !Exists(xx, yy))
                {
                    continue;
                }

                var rst = new BattleBlockVector(xx, yy);
                yield return(rst);
            }
        }
Beispiel #6
0
        //返回附近六个格子之一
        public BattleBlockVector GetNearBlock(int x, int y, MoveDirection dir)
        {
            int newx = x;
            int newy = y;

            switch (dir)
            {
            case MoveDirection.DOWN:
                newy += 1;
                break;

            case MoveDirection.UP:
                newy -= 1;
                break;

            case MoveDirection.LEFT:
                newx -= 1;
                break;

            case MoveDirection.RIGHT:
                newx += 1;
                break;

            default:     //jyx2 不允许其他的方向,只有四向
                return(null);
            }

            if (Exists != null && !Exists(newx, newy))
            {
                return(null);
            }

            var rst = new BattleBlockVector(newx, newy);

            return(rst);
        }
Beispiel #7
0
 //求两点的距离
 public int GetDistance(BattleBlockVector pos)
 {
     return(GetDistance(X, Y, pos.X, pos.Y));
 }
Beispiel #8
0
        /// <summary>
        /// 获取技能覆盖范围
        /// </summary>
        /// <param name="covertype"></param>
        /// <param name="tx"></param>
        /// <param name="ty"></param>
        /// <param name="sx"></param>
        /// <param name="sy"></param>
        /// <param name="coversize"></param>
        /// <returns></returns>
        public List <BattleBlockVector> GetSkillCoverBlocks(SkillCoverType covertype, int tx, int ty,
                                                            int sx, int sy, int coversize)
        {
            var rst = new List <BattleBlockVector>();

            switch (covertype)
            {
            //点攻击,只有一个格子
            case SkillCoverType.POINT:
                rst.Add(new BattleBlockVector()
                {
                    X = tx, Y = ty
                });
                break;

            case SkillCoverType.FAN:
            {
                MoveDirection direction = GetDirection(tx, ty, sx, sy);
                if (direction == MoveDirection.ERROR)
                {
                    break;
                }
                rst.Add(new BattleBlockVector()
                    {
                        X = tx, Y = ty
                    });
                if (direction == MoveDirection.UP_LEFT)
                {
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.UP_LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.UP_RIGHT));
                }
                else if (direction == MoveDirection.UP_RIGHT)
                {
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.UP_LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.UP_RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.RIGHT));
                }
                else if (direction == MoveDirection.RIGHT)
                {
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.UP_RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.DOWN_RIGHT));
                }
                else if (direction == MoveDirection.DOWN_RIGHT)
                {
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.DOWN_RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.DOWN_LEFT));
                }
                else if (direction == MoveDirection.DOWN_LEFT)
                {
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.DOWN_RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.DOWN_LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.LEFT));
                }
                else if (direction == MoveDirection.LEFT)
                {
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.DOWN_LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.UP_LEFT));
                }
                break;
            }

            case SkillCoverType.FACE:
                rst.Add(new BattleBlockVector()
                {
                    X = tx, Y = ty
                });
                rst.AddRange(GetNearBlocks(tx, ty, coversize));
                break;

            case SkillCoverType.LINE:
            {
                if (coversize == 0)
                {
                    coversize = 1;                         //修正直线攻击没有攻击覆盖的BUG
                }
                int           tmpx      = sx;
                int           tmpy      = sy;
                MoveDirection direction = GetDirection(tx, ty, sx, sy);
                if (direction == MoveDirection.ERROR)
                {
                    break;
                }
                for (int i = 0; i < coversize; ++i)
                {
                    BattleBlockVector b = GetNearBlock(tmpx, tmpy, direction);
                    if (b == null)
                    {
                        continue;
                    }
                    rst.Add(b);
                    tmpx = b.X;
                    tmpy = b.Y;
                }
                break;
            }

            case SkillCoverType.FRONT:
            {
                MoveDirection direction = GetDirection(tx, ty, sx, sy);
                if (direction == MoveDirection.ERROR)
                {
                    break;
                }
                rst.Add(new BattleBlockVector()
                    {
                        X = tx, Y = ty
                    });
                if (direction == MoveDirection.UP_LEFT)
                {
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.LEFT));
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.UP_RIGHT));
                }
                else if (direction == MoveDirection.UP_RIGHT)
                {
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.UP_LEFT));
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.RIGHT));
                }
                else if (direction == MoveDirection.RIGHT)
                {
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.UP_RIGHT));
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.DOWN_RIGHT));
                }
                else if (direction == MoveDirection.DOWN_RIGHT)
                {
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.RIGHT));
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.DOWN_LEFT));
                }
                else if (direction == MoveDirection.DOWN_LEFT)
                {
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.DOWN_RIGHT));
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.LEFT));
                }
                else if (direction == MoveDirection.LEFT)
                {
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.DOWN_LEFT));
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.UP_LEFT));
                }
                break;
            }

            case SkillCoverType.FRONTCROSS:
            {
                MoveDirection direction = GetDirection(tx, ty, sx, sy);
                if (direction == MoveDirection.ERROR)
                {
                    break;
                }
                rst.Add(new BattleBlockVector()
                    {
                        X = tx, Y = ty
                    });
                if (direction == MoveDirection.UP_LEFT)
                {
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.LEFT));
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.UP_RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.UP_LEFT));
                }
                else if (direction == MoveDirection.UP_RIGHT)
                {
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.UP_LEFT));
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.UP_RIGHT));
                }
                else if (direction == MoveDirection.RIGHT)
                {
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.UP_RIGHT));
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.DOWN_RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.RIGHT));
                }
                else if (direction == MoveDirection.DOWN_RIGHT)
                {
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.RIGHT));
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.DOWN_LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.DOWN_RIGHT));
                }
                else if (direction == MoveDirection.DOWN_LEFT)
                {
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.DOWN_RIGHT));
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.DOWN_LEFT));
                }
                else if (direction == MoveDirection.LEFT)
                {
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.DOWN_LEFT));
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.UP_LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.LEFT));
                }
                break;
            }

            case SkillCoverType.FANGSHE:    //放射
            {
                rst.Add(new BattleBlockVector()
                    {
                        X = tx, Y = ty
                    });
                var roundblocks = GetNearBlocks(tx, ty, 1);
                rst.AddRange(roundblocks);
                foreach (var b in roundblocks)
                {
                    MoveDirection direction = GetDirection(b.X, b.Y, sx, sy);
                    if (direction == MoveDirection.ERROR)
                    {
                        continue;
                    }
                    var block = GetNearBlock(b.X, b.Y, direction);
                    if (block == null)
                    {
                        continue;
                    }
                    rst.Add(block);
                }
                break;
            }

            case SkillCoverType.STAR:
            {
                rst.Add(new BattleBlockVector()
                    {
                        X = tx, Y = ty
                    });
                for (int i = 0; i < 6; ++i)
                {
                    int           tmpx      = tx;
                    int           tmpy      = ty;
                    MoveDirection direction = (MoveDirection)i;
                    for (int j = 0; j < coversize; ++j)
                    {
                        BattleBlockVector b = GetNearBlock(tmpx, tmpy, direction);
                        if (b == null)
                        {
                            continue;
                        }
                        rst.Add(b);
                        tmpx = b.X;
                        tmpy = b.Y;
                    }
                }
                break;
            }

            case SkillCoverType.ZHUIXING:
            {
                MoveDirection direction = GetDirection(tx, ty, sx, sy);
                if (direction == MoveDirection.ERROR)
                {
                    break;
                }
                rst.Add(new BattleBlockVector()
                    {
                        X = tx, Y = ty
                    });
                if (direction == MoveDirection.UP_LEFT)
                {
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.LEFT));
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.UP_RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.UP_LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.UP_RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.UP_LEFT, MoveDirection.UP_LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.UP_LEFT, MoveDirection.LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.UP_LEFT, MoveDirection.UP_RIGHT));
                }
                else if (direction == MoveDirection.UP_RIGHT)
                {
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.UP_LEFT));
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.UP_RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.UP_LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.UP_RIGHT, MoveDirection.UP_RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.UP_RIGHT, MoveDirection.UP_LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.UP_RIGHT, MoveDirection.RIGHT));
                }
                else if (direction == MoveDirection.RIGHT)
                {
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.UP_RIGHT));
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.DOWN_RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.UP_RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.DOWN_RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.RIGHT, MoveDirection.RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.RIGHT, MoveDirection.UP_RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.RIGHT, MoveDirection.DOWN_RIGHT));
                }
                else if (direction == MoveDirection.DOWN_RIGHT)
                {
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.RIGHT));
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.DOWN_LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.DOWN_RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.DOWN_LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.DOWN_RIGHT, MoveDirection.DOWN_RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.DOWN_RIGHT, MoveDirection.RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.DOWN_RIGHT, MoveDirection.DOWN_LEFT));
                }
                else if (direction == MoveDirection.DOWN_LEFT)
                {
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.DOWN_RIGHT));
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.DOWN_LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.DOWN_RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.DOWN_LEFT, MoveDirection.DOWN_LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.DOWN_LEFT, MoveDirection.DOWN_RIGHT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.DOWN_LEFT, MoveDirection.LEFT));
                }
                else if (direction == MoveDirection.LEFT)
                {
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.DOWN_LEFT));
                    rst.Add(GetNearBlock(sx, sy, MoveDirection.UP_LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.DOWN_LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.UP_LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.LEFT, MoveDirection.DOWN_LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.LEFT, MoveDirection.LEFT));
                    rst.Add(GetNearBlock(tx, ty, MoveDirection.LEFT, MoveDirection.UP_LEFT));
                }
                break;
            }

            default:
                throw new ArgumentOutOfRangeException(nameof(covertype), covertype, null);
            }

            return(rst);
        }