Пример #1
0
 public virtual void RefreshCoordinates()
 {
     PlacedPosition = Pivot + PosOffset;
     if (SubCellFlags != SubCellFlags.Free)
     {
         CellBlocking = CellUtils.Combine(SubCellFlags, CellBlocking, transform);
     }
 }
Пример #2
0
    private bool WantMove()
    {
        if (Settings.monsterMoveOnGround)
        {
            var map     = Game.Map;
            var cell    = map.WorldToCell(transform.position);
            var surface = CellUtils.Combine(SubCellFlags.HasFloor, transform);

            if ((map.GetCellBlocking(cell + Vector2Int.down) & surface) != 0)
            {
                if (map.IsXNearNextCell(transform.position.x, desiredDirection))
                {
                    if ((map.GetCellBlocking(cell + new Vector2Int(desiredDirection, -1)) & surface) == 0
                        /*|| (map.GetCellBlocking(cell + new Vector2Int(desiredDirection, 0), placeable) & fullBlock) != 0*/)
                    {
                        return(false);
                    }
                }
            }
        }

        return(true);
    }
Пример #3
0
    private void TryPlaceArm(int index)
    {
        var  map         = Game.Map;
        bool otherPlaced = ArmCatched;
        var  center      = ArmSphere.transform.position.XY();
        var  center3d    = ArmSphere.transform.position + new Vector3(0, 0, Settings.legZ[index]);

        var radius2 = new Vector2(ArmSphere.radius, ArmSphere.radius);

        map.Get(placeables, center - radius2, 2 * radius2, Ksid.Catch);

        foreach (var p in placeables)
        {
            var pos = p.GetClosestPoint(center3d);
            if (!otherPlaced || Vector2.Dot(desiredVelocity, pos - center3d) >= 0)
            {
                if (Physics.Raycast(center3d, pos - center3d, out var hitInfo, ArmSphere.radius, Settings.armCatchLayerMask))
                {
                    if ((hitInfo.point - pos).sqrMagnitude < 0.001 && ConnectLabel(index, ref hitInfo, p))
                    {
                        PlaceLeg3d(index, ref hitInfo, Catch);
                        placeables.Clear();
                        return;
                    }
                }
            }
        }

        placeables.Clear();

        var c  = map.WorldToCell(ArmSphere.transform.position.XY());
        var c1 = c - Settings.ArmCellRadius;
        var c2 = c + Settings.ArmCellRadius + Vector2Int.one;

        var blocking = CellUtils.Combine(SubCellFlags.Full, transform);

        for (int y = c1.y; y < c2.y; y++)
        {
            for (int x = c1.x; x < c.x; x++)
            {
                if ((map.GetCellBlocking(new Vector2Int(x, y)) & blocking) == blocking &&
                    (map.GetCellBlocking(new Vector2Int(x + 1, y)) & blocking) != blocking &&
                    (map.GetCellBlocking(new Vector2Int(x + 1, y + 1)) & blocking) != blocking &&
                    (map.GetCellBlocking(new Vector2Int(x, y + 1)) & blocking) != blocking)
                {
                    armCandidates.Add(map.CellToWorld(new Vector2Int(x + 1, y + 1)));
                }
            }
            for (int x = c.x + 1; x < c2.x; x++)
            {
                if ((map.GetCellBlocking(new Vector2Int(x, y)) & blocking) == blocking &&
                    (map.GetCellBlocking(new Vector2Int(x - 1, y)) & blocking) != blocking &&
                    (map.GetCellBlocking(new Vector2Int(x - 1, y + 1)) & blocking) != blocking &&
                    (map.GetCellBlocking(new Vector2Int(x, y + 1)) & blocking) != blocking)
                {
                    armCandidates.Add(map.CellToWorld(new Vector2Int(x, y + 1)));
                }
            }
        }

        foreach (var pos in armCandidates)
        {
            if (!otherPlaced || Vector2.Dot(desiredVelocity, pos - center) >= 0)
            {
                if (RayCastArm(index, new Vector3(pos.x, pos.y, ArmSphere.transform.position.z), ArmSphere.radius))
                {
                    break;
                }
            }
        }

        armCandidates.Clear();
    }