Ejemplo n.º 1
0
        public void ChangeTool(ToolType toolType)
        {
            if (toolType == type)
            {
                return;
            }
            _type = toolType;

            if (toolType == ToolType.None)
            {
                _tool = null;
            }
            else if (toolType == ToolType.Translation)
            {
                _tool = TRANSLATION_TOOL;
            }
            else if (toolType == ToolType.Rotation)
            {
                _tool = ROTATION_TOOL;
            }
            else if (toolType == ToolType.Scaling)
            {
                _tool = SCALING_TOOL;
            }
            else if (toolType == ToolType.VertexTranslation)
            {
                _tool = VERTEX_TRANSLATION_TOOL;
            }

            _tool?.Reset();
            OnToolChanged(new ToolChangedEventArgs(toolType));
        }
Ejemplo n.º 2
0
 /// <summary>Get whether the tool is currently enabled.</summary>
 /// <param name="player">The current player.</param>
 /// <param name="tool">The tool selected by the player (if any).</param>
 /// <param name="item">The item selected by the player (if any).</param>
 /// <param name="location">The current location.</param>
 public override bool IsEnabled(Farmer player, Tool?tool, Item?item, GameLocation location)
 {
     return
         (tool is MeleeWeapon {
         type.Value : MeleeWeapon.defenseSword
     } weapon &&
          !weapon.isScythe());
 }
Ejemplo n.º 3
0
 protected Target(Tool?tool, Speed?speed, Zone?zone, Command?command, Frame?frame, IEnumerable <double>?external)
 {
     Tool     = tool ?? Tool.Default;
     Speed    = speed ?? Speed.Default;
     Zone     = zone ?? Zone.Default;
     Frame    = frame ?? Frame.Default;
     Command  = command ?? Command.Default;
     External = (external is not null) ? external.ToArray() : new double[0];
 }
Ejemplo n.º 4
0
        public bool GetOnlineTool()
        {
            try
            {
                List <Tool> tools = ApiClient.Tools_GetToolsAsync(App.ApplicationName).Result;
                Tool = tools.First();

                return(true);
            }
            catch (Exception ex)
            {
                App.Instance.ShowError("Error retrieving tool information", "An error occurred while attempting to retrieve tool information from the API.", ex);
                return(false);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Switches to a specified tool
        /// </summary>
        /// <param name="tool">The tool to switch to or null to reset.</param>
        public void switchTool(Tool?tool)
        {
            currentTool = tool;

            switch (tool)
            {
            case (Tool.HAMMER):
                setCursor(hammer);
                break;

            case (Tool.PLANK):
                setCursor(plank);
                break;

            case (null):
                Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
                break;
            }
        }
Ejemplo n.º 6
0
        private void UpdateStage(Farmer player, IEnumerable <Item> added)
        {
            Tool?upgraded = player.toolBeingUpgraded.Value;

            if (Count < MaxCount - 1 && upgraded != null && upgraded.BaseName == TargetName)
            {
                Count = MaxCount - (Variant - upgraded.UpgradeLevel) - 1;
            }
            else if (Count == MaxCount - 1)
            {
                foreach (Item item in added)
                {
                    if (item is Tool tool && tool.BaseName == TargetName)
                    {
                        Count = MaxCount;
                        MarkAsCompleted();
                        break;
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private void Update()
        {
            if (pauseMenu.isPaused)
            {
                if (currentTool == null)
                {
                    return;
                }
                else
                {
                    pausedOnTool = currentTool;
                    switchTool(null);
                }
            }
            else if (currentTool == null)
            {
                switchTool(pausedOnTool);
            }

            if (res.width != Screen.currentResolution.width || res.height != Screen.currentResolution.height)
            {
                switchTool(currentTool);
            }
        }
Ejemplo n.º 8
0
 public JointTarget(double[] joints, Tool?tool = null, Speed?speed = null, Zone?zone = null, Command?command = null, Frame?frame = null, IEnumerable <double>?external = null) : base(tool, speed, zone, command, frame, external)
 {
     Array.Resize(ref joints, 6);
     Joints = joints;
 }
Ejemplo n.º 9
0
    List <string> Program()
    {
        string indent = "  ";
        var    code   = new List <string>
        {
            "def Program():"
        };

        // Attribute declarations
        var attributes = _program.Attributes;

        foreach (var tool in attributes.OfType <Tool>().Where(t => !t.UseController))
        {
            Plane tcp         = tool.Tcp;
            var   originPlane = new Plane(Point3d.Origin, Vector3d.YAxis, -Vector3d.XAxis);
            tcp.Orient(ref originPlane);
            Point3d tcpPoint = tcp.Origin / 1000;
            tcp.Origin = tcpPoint;
            double[] axisAngle = RobotSystemUR.PlaneToAxisAngle(ref tcp);

            Point3d cog = tool.Centroid;
            cog.Transform(originPlane.ToTransform());
            cog /= 1000;

            code.Add(indent + $"{tool.Name}Tcp = p[{axisAngle[0]:0.#####}, {axisAngle[1]:0.#####}, {axisAngle[2]:0.#####}, {axisAngle[3]:0.#####}, {axisAngle[4]:0.#####}, {axisAngle[5]:0.#####}]");
            code.Add(indent + $"{tool.Name}Weight = {tool.Weight:0.###}");
            code.Add(indent + $"{tool.Name}Cog = [{cog.X:0.#####}, {cog.Y:0.#####}, {cog.Z:0.#####}]");
        }

        foreach (var speed in attributes.OfType <Speed>())
        {
            double linearSpeed = speed.TranslationSpeed / 1000;
            code.Add(indent + $"{speed.Name} = {linearSpeed:0.#####}");
        }

        foreach (var zone in attributes.OfType <Zone>())
        {
            double zoneDistance = zone.Distance / 1000;
            code.Add(indent + $"{zone.Name} = {zoneDistance:0.#####}");
        }

        foreach (var command in attributes.OfType <Command>())
        {
            string declaration = command.Declaration(_program);

            if (!string.IsNullOrWhiteSpace(declaration))
            {
                code.Add(indent + declaration);
            }
        }

        // Init commands

        foreach (var command in _program.InitCommands)
        {
            string commands = command.Code(_program, Target.Default);
            code.Add(indent + commands);
        }

        Tool?currentTool = null;

        // Targets

        foreach (var cellTarget in _program.Targets)
        {
            var programTarget = cellTarget.ProgramTargets[0];
            var target        = programTarget.Target;

            if (currentTool is null || target.Tool != currentTool)
            {
                code.Add(Tool(target.Tool));
                currentTool = target.Tool;
            }

            string moveText;
            string zoneDistance = target.Zone.Name;

            if (programTarget.IsJointTarget || (programTarget.IsJointMotion && programTarget.ForcedConfiguration))
            {
                double[] joints = programTarget.IsJointTarget ? ((JointTarget)programTarget.Target).Joints : programTarget.Kinematics.Joints;
                var      speed  = GetAxisSpeed();
                moveText = $"  movej([{joints[0]:0.####}, {joints[1]:0.####}, {joints[2]:0.####}, {joints[3]:0.####}, {joints[4]:0.####}, {joints[5]:0.####}], {speed}, r={zoneDistance})";
            }
            else
            {
                var cartesian = (CartesianTarget)target;
                var plane     = cartesian.Plane;
                plane.Orient(ref target.Frame.Plane);
                plane.InverseOrient(ref _cell.BasePlane);
                var axisAngle = _cell.PlaneToNumbers(plane);

                switch (cartesian.Motion)
                {
                case Motions.Joint:
                {
                    var speed = GetAxisSpeed();
                    moveText = $"  movej(p[{axisAngle[0]:0.#####}, {axisAngle[1]:0.#####}, {axisAngle[2]:0.#####}, {axisAngle[3]:0.#####}, {axisAngle[4]:0.#####}, {axisAngle[5]:0.#####}], {speed}, r={zoneDistance})";
                    break;
                }

                case Motions.Linear:
                {
                    double linearAccel = target.Speed.TranslationAccel / 1000;

                    string speed = target.Speed.Time > 0 ?
                                   $"t={target.Speed.Time: 0.####}" :
                                   $"a={linearAccel:0.#####}, v={target.Speed.Name}";

                    moveText = $"  movel(p[{axisAngle[0]:0.#####}, {axisAngle[1]:0.#####}, {axisAngle[2]:0.#####}, {axisAngle[3]:0.#####}, {axisAngle[4]:0.#####}, {axisAngle[5]:0.#####}], {speed}, r={zoneDistance})";
                    break;
                }

                default:
                    throw new ArgumentException($" Motion '{cartesian.Motion}' not supported.", nameof(cartesian.Motion));
                }
            }

            foreach (var command in programTarget.Commands.Where(c => c.RunBefore))
            {
                string commands = command.Code(_program, target);
                commands = indent + commands;
                code.Add(commands);
            }

            code.Add(moveText);

            foreach (var command in programTarget.Commands.Where(c => !c.RunBefore))
            {
                string commands = command.Code(_program, target);
                commands = indent + commands;
                code.Add(commands);
            }

            string GetAxisSpeed()
            {
                var speed = target.Speed;

                if (speed.Time > 0)
                {
                    return($"t={speed.Time:0.####}");
                }

                double axisSpeed;

                if (cellTarget.DeltaTime > 0)
                {
                    int    leadIndex     = programTarget.LeadingJoint;
                    double leadAxisSpeed = _robot.Joints[leadIndex].MaxSpeed;
                    double percentage    = cellTarget.MinTime / cellTarget.DeltaTime;
                    axisSpeed = percentage * leadAxisSpeed;
                }
                else
                {
                    const double maxTranslationSpeed = 1000.0;
                    double       leadAxisSpeed       = _robot.Joints.Max(j => j.MaxSpeed);
                    double       percentage          = speed.TranslationSpeed / maxTranslationSpeed;
                    axisSpeed = percentage * leadAxisSpeed;
                }

                double axisAccel = target.Speed.AxisAccel;

                return($"a={axisAccel:0.####}, v={axisSpeed:0.####}");
            }
        }

        code.Add("end");
        return(code);
    }
Ejemplo n.º 10
0
        /// <summary>Apply the tool to the given tile.</summary>
        /// <param name="tile">The tile to modify.</param>
        /// <param name="tileObj">The object on the tile.</param>
        /// <param name="tileFeature">The feature on the tile.</param>
        /// <param name="player">The current player.</param>
        /// <param name="tool">The tool selected by the player (if any).</param>
        /// <param name="item">The item selected by the player (if any).</param>
        /// <param name="location">The current location.</param>
        public override bool Apply(Vector2 tile, SObject?tileObj, TerrainFeature?tileFeature, Farmer player, Tool?tool, Item?item, GameLocation location)
        {
            // apply melee weapon
            if (tool is MeleeWeapon weapon)
            {
                return(this.UseWeaponOnTile(weapon, tile, player, location));
            }

            // apply tool
            if (tool != null && this.CustomNames.Contains(tool.Name))
            {
                return(this.UseToolOnTile(tool, tile, player, location));
            }

            // apply item
            if (item is { Stack : > 0 } && this.CustomNames.Contains(item.Name))
Ejemplo n.º 11
0
 /// <summary>Get whether the tool is currently enabled.</summary>
 /// <param name="player">The current player.</param>
 /// <param name="tool">The tool selected by the player (if any).</param>
 /// <param name="item">The item selected by the player (if any).</param>
 /// <param name="location">The current location.</param>
 public override bool IsEnabled(Farmer player, Tool?tool, Item?item, GameLocation location)
 {
     return
         ((tool != null && this.CustomNames.Contains(tool.Name)) ||
          (item != null && this.CustomNames.Contains(item.Name)));
 }
Ejemplo n.º 12
0
 /// <summary>Get whether the tool is currently enabled.</summary>
 /// <param name="player">The current player.</param>
 /// <param name="tool">The tool selected by the player (if any).</param>
 /// <param name="item">The item selected by the player (if any).</param>
 /// <param name="location">The current location.</param>
 public override bool IsEnabled(Farmer player, Tool?tool, Item?item, GameLocation location)
 {
     return
         (tool is MeleeWeapon {
         type.Value : not(MeleeWeapon.dagger or MeleeWeapon.defenseSword)
     });
Ejemplo n.º 13
0
        /// <summary>Apply the tool to the given tile.</summary>
        /// <param name="tile">The tile to modify.</param>
        /// <param name="tileObj">The object on the tile.</param>
        /// <param name="tileFeature">The feature on the tile.</param>
        /// <param name="player">The current player.</param>
        /// <param name="tool">The tool selected by the player (if any).</param>
        /// <param name="item">The item selected by the player (if any).</param>
        /// <param name="location">The current location.</param>
        public override bool Apply(Vector2 tile, SObject?tileObj, TerrainFeature?tileFeature, Farmer player, Tool?tool, Item?item, GameLocation location)
        {
            tool = tool.AssertNotNull();

            this.Reflection.GetField <bool>(tool, "canPlaySound").SetValue(false);
            return(this.UseToolOnTile(tool, tile, player, location));
        }
Ejemplo n.º 14
0
 public CartesianTarget(Plane plane, RobotConfigurations?configuration = null, Motions motion = Motions.Joint, Tool?tool = null, Speed?speed = null, Zone?zone = null, Command?command = null, Frame?frame = null, IEnumerable <double>?external = null)
     : base(tool, speed, zone, command, frame, external)
 {
     Plane         = plane;
     Motion        = motion;
     Configuration = configuration;
 }
Ejemplo n.º 15
0
 /// <summary>Get whether the tool is currently enabled.</summary>
 /// <param name="player">The current player.</param>
 /// <param name="tool">The tool selected by the player (if any).</param>
 /// <param name="item">The item selected by the player (if any).</param>
 /// <param name="location">The current location.</param>
 public override bool IsEnabled(Farmer player, Tool?tool, Item?item, GameLocation location)
 {
     return
         (this.Config.Enable &&
          tool is { Name : "Seed Bag" });
Ejemplo n.º 16
0
 /// <summary>Get whether the tool is currently enabled.</summary>
 /// <param name="player">The current player.</param>
 /// <param name="tool">The tool selected by the player (if any).</param>
 /// <param name="item">The item selected by the player (if any).</param>
 /// <param name="location">The current location.</param>
 public override bool IsEnabled(Farmer player, Tool?tool, Item?item, GameLocation location)
 {
     return(tool is Axe);
 }
 /// <summary>Get whether the tool is currently enabled.</summary>
 /// <param name="player">The current player.</param>
 /// <param name="tool">The tool selected by the player (if any).</param>
 /// <param name="item">The item selected by the player (if any).</param>
 /// <param name="location">The current location.</param>
 public override bool IsEnabled(Farmer player, Tool?tool, Item?item, GameLocation location)
 {
     return
         (this.Config.Enable &&
          item is { ParentSheetIndex : 297, Stack : > 0 });
Ejemplo n.º 18
0
        /// <summary>Apply the tool to the given tile.</summary>
        /// <param name="tile">The tile to modify.</param>
        /// <param name="tileObj">The object on the tile.</param>
        /// <param name="tileFeature">The feature on the tile.</param>
        /// <param name="player">The current player.</param>
        /// <param name="tool">The tool selected by the player (if any).</param>
        /// <param name="item">The item selected by the player (if any).</param>
        /// <param name="location">The current location.</param>
        public override bool Apply(Vector2 tile, SObject?tileObj, TerrainFeature?tileFeature, Farmer player, Tool?tool, Item?item, GameLocation location)
        {
            tool = tool.AssertNotNull();

            // clear weeds
            if (this.Config.ClearWeeds && this.IsWeed(tileObj))
            {
                return(this.UseToolOnTile(tool, tile, player, location));
            }

            // collect artifact spots
            if (this.Config.DigArtifactSpots && tileObj?.ParentSheetIndex == HoeAttachment.ArtifactSpotItemID)
            {
                return(this.UseToolOnTile(tool, tile, player, location));
            }

            // harvest ginger
            if (this.Config.HarvestGinger && tileFeature is HoeDirt dirt && dirt.crop?.whichForageCrop.Value == Crop.forageCrop_ginger && dirt.crop.hitWithHoe((int)tile.X, (int)tile.Y, location, dirt))
            {
                dirt.destroyCrop(tile, showAnimation: false, location);
                return(true);
            }

            // till plain dirt
            if (this.Config.TillDirt && tileFeature == null && tileObj == null && this.TryStartCooldown(tile.ToString(), this.TillDirtDelay))
            {
                return(this.UseToolOnTile(tool, tile, player, location));
            }

            return(false);
        }
Ejemplo n.º 19
0
 /// <summary>Get whether the tool is currently enabled.</summary>
 /// <param name="player">The current player.</param>
 /// <param name="tool">The tool selected by the player (if any).</param>
 /// <param name="item">The item selected by the player (if any).</param>
 /// <param name="location">The current location.</param>
 public override bool IsEnabled(Farmer player, Tool?tool, Item?item, GameLocation location)
 {
     return
         ((this.Config.TillDirt || this.Config.ClearWeeds || this.Config.DigArtifactSpots) &&
          tool is Hoe);
 }
Ejemplo n.º 20
0
        /// <summary>Apply the tool to the given tile.</summary>
        /// <param name="tile">The tile to modify.</param>
        /// <param name="tileObj">The object on the tile.</param>
        /// <param name="tileFeature">The feature on the tile.</param>
        /// <param name="player">The current player.</param>
        /// <param name="tool">The tool selected by the player (if any).</param>
        /// <param name="item">The item selected by the player (if any).</param>
        /// <param name="location">The current location.</param>
        public override bool Apply(Vector2 tile, SObject?tileObj, TerrainFeature?tileFeature, Farmer player, Tool?tool, Item?item, GameLocation location)
        {
            tool = tool.AssertNotNull();

            // break stones
            if (this.Config.ClearDebris && tileObj?.Name == "Stone")
            {
                return(this.UseToolOnTile(tool, tile, player, location));
            }

            // break flooring & paths
            if (this.Config.ClearFlooring && tileFeature is Flooring)
            {
                return(this.UseToolOnTile(tool, tile, player, location));
            }

            // break objects
            if (this.Config.ClearObjects && tileObj != null)
            {
                return(this.UseToolOnTile(tool, tile, player, location));
            }

            // break mine containers
            if (this.Config.BreakMineContainers && this.TryBreakContainer(tile, tileObj, tool, location))
            {
                return(true);
            }

            // clear weeds
            if (this.Config.ClearWeeds && this.IsWeed(tileObj))
            {
                return(this.UseToolOnTile(tool, tile, player, location));
            }

            // handle dirt
            if (tileFeature is HoeDirt dirt && tileObj is null)
            {
                // clear tilled dirt
                if (this.Config.ClearDirt && dirt.crop == null)
                {
                    return(this.UseToolOnTile(tool, tile, player, location));
                }

                // clear dead crops
                if (this.Config.ClearDeadCrops && dirt.crop != null && dirt.crop.dead.Value)
                {
                    return(this.UseToolOnTile(tool, tile, player, location));
                }
            }

            // clear boulders / meteorites
            // This needs to check if the axe upgrade level is high enough first, to avoid spamming
            // 'need to upgrade your tool' messages. Based on ResourceClump.performToolAction.
            if (this.Config.ClearBouldersAndMeteorites)
            {
                if (this.CanBreakBoulderAt(location, tile, player, tool, out Func <Tool, bool>?applyTool))
                {
                    applyTool(tool);
                    return(true);
                }
            }

            // harvest spawned mine objects
            if (this.Config.HarvestMineSpawns && location is MineShaft && tileObj?.IsSpawnedObject == true && this.CheckTileAction(location, tile, player))
            {
                this.CancelAnimation(player, FarmerSprite.harvestItemDown, FarmerSprite.harvestItemLeft, FarmerSprite.harvestItemRight, FarmerSprite.harvestItemUp);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 21
0
        /// <summary>Apply the tool to the given tile.</summary>
        /// <param name="tile">The tile to modify.</param>
        /// <param name="tileObj">The object on the tile.</param>
        /// <param name="tileFeature">The feature on the tile.</param>
        /// <param name="player">The current player.</param>
        /// <param name="tool">The tool selected by the player (if any).</param>
        /// <param name="item">The item selected by the player (if any).</param>
        /// <param name="location">The current location.</param>
        public override bool Apply(Vector2 tile, SObject?tileObj, TerrainFeature?tileFeature, Farmer player, Tool?tool, Item?item, GameLocation location)
        {
            tool = tool.AssertNotNull();

            // clear dead crops
            if (this.Config.ClearDeadCrops && this.TryClearDeadCrop(location, tile, tileFeature, player))
            {
                return(true);
            }

            // break mine containers
            if (this.Config.BreakMineContainers && this.TryBreakContainer(tile, tileObj, tool, location))
            {
                return(true);
            }

            // harvest grass
            if (this.Config.HarvestGrass && this.TryHarvestGrass(tileFeature as Grass, location, tile))
            {
                return(true);
            }

            // attack monsters
            if (this.Config.AttackMonsters && this.UseWeaponOnTile((MeleeWeapon)tool, tile, player, location))
            {
                return(false);
            }

            return(false);
        }
Ejemplo n.º 22
0
        /// <summary>Apply the tool to the given tile.</summary>
        /// <param name="tile">The tile to modify.</param>
        /// <param name="tileObj">The object on the tile.</param>
        /// <param name="tileFeature">The feature on the tile.</param>
        /// <param name="player">The current player.</param>
        /// <param name="tool">The tool selected by the player (if any).</param>
        /// <param name="item">The item selected by the player (if any).</param>
        /// <param name="location">The current location.</param>
        public override bool Apply(Vector2 tile, SObject?tileObj, TerrainFeature?tileFeature, Farmer player, Tool?tool, Item?item, GameLocation location)
        {
            tool = tool.AssertNotNull();

            if (this.TryStartCooldown(tile.ToString(), this.AnimalCheckDelay))
            {
                FarmAnimal?animal = this.GetBestHarvestableFarmAnimal(tool, location, tile);
                if (animal != null)
                {
                    Vector2 useAt = this.GetToolPixelPosition(tile);

                    this.Reflection.GetField <FarmAnimal>(tool, "animal").SetValue(animal);
                    tool.DoFunction(location, (int)useAt.X, (int)useAt.Y, 0, player);

                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 23
0
        /// <summary>Apply the tool to the given tile.</summary>
        /// <param name="tile">The tile to modify.</param>
        /// <param name="tileObj">The object on the tile.</param>
        /// <param name="tileFeature">The feature on the tile.</param>
        /// <param name="player">The current player.</param>
        /// <param name="tool">The tool selected by the player (if any).</param>
        /// <param name="item">The item selected by the player (if any).</param>
        /// <param name="location">The current location.</param>
        public override bool Apply(Vector2 tile, SObject?tileObj, TerrainFeature?tileFeature, Farmer player, Tool?tool, Item?item, GameLocation location)
        {
            tool = tool.AssertNotNull();

            // clear debris
            if (this.Config.ClearDebris && (this.IsTwig(tileObj) || this.IsWeed(tileObj)))
            {
                return(this.UseToolOnTile(tool, tile, player, location));
            }

            // cut terrain features
            switch (tileFeature)
            {
            // cut non-fruit tree
            case Tree tree:
                return(this.ShouldCut(tree, tile, location) && this.UseToolOnTile(tool, tile, player, location));

            // cut fruit tree
            case FruitTree tree:
                return(this.ShouldCut(tree) && this.UseToolOnTile(tool, tile, player, location));

            // cut bushes
            case Bush bush:
                return(this.ShouldCut(bush) && this.UseToolOnTile(tool, tile, player, location));

            // clear crops
            case HoeDirt {
                    crop: not null
            } dirt:
                if (this.Config.ClearDeadCrops && dirt.crop.dead.Value)
                {
                    return(this.UseToolOnTile(tool, tile, player, location));
                }
                if (this.Config.ClearLiveCrops && !dirt.crop.dead.Value)
                {
                    return(this.UseToolOnTile(tool, tile, player, location));
                }
                break;
            }

            // cut resource stumps
            if (this.Config.ClearDebris || this.Config.CutGiantCrops)
            {
                if (this.TryGetResourceClumpCoveringTile(location, tile, player, out ResourceClump? clump, out Func <Tool, bool>?applyTool))
                {
                    // giant crops
                    if (this.Config.CutGiantCrops && clump is GiantCrop)
                    {
                        applyTool(tool);
                        return(true);
                    }

                    // big stumps and fallen logs
                    // This needs to check if the axe upgrade level is high enough first, to avoid spamming
                    // 'need to upgrade your tool' messages. Based on ResourceClump.performToolAction.
                    if (this.Config.ClearDebris && this.ResourceUpgradeLevelsNeeded.ContainsKey(clump.parentSheetIndex.Value) && tool.UpgradeLevel >= this.ResourceUpgradeLevelsNeeded[clump.parentSheetIndex.Value])
                    {
                        applyTool(tool);
                        return(true);
                    }
                }
            }

            // cut bushes in large terrain features
            if (this.Config.CutBushes)
            {
                foreach (Bush bush in location.largeTerrainFeatures.OfType <Bush>().Where(p => p.tilePosition.Value == tile))
                {
                    if (this.ShouldCut(bush) && this.UseToolOnTile(tool, tile, player, location))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 24
0
 /// <summary>Get whether the tool is currently enabled.</summary>
 /// <param name="player">The current player.</param>
 /// <param name="tool">The tool selected by the player (if any).</param>
 /// <param name="item">The item selected by the player (if any).</param>
 /// <param name="location">The current location.</param>
 public override bool IsEnabled(Farmer player, Tool?tool, Item?item, GameLocation location)
 {
     return
         (this.Config.Enable &&
          item is { Category : SObject.SeedsCategory, Stack : > 0 });
Ejemplo n.º 25
0
    List <string> SrcFile(int file, int group)
    {
        string groupName = _cell.MechanicalGroups[group].Name;
        int    start     = _program.MultiFileIndices[file];
        int    end       = (file == _program.MultiFileIndices.Count - 1) ? _program.Targets.Count : _program.MultiFileIndices[file + 1];

        var code = new List <string>
        {
            $@"&ACCESS RVP
&REL 1
DEF {_program.Name}_{groupName}_{file:000}()
"
        };

        Tool?  currentTool         = null;
        Frame? currentFrame        = null;
        Speed? currentSpeed        = null;
        double currentPercentSpeed = 0;
        Zone?  currentZone         = null;

        for (int j = start; j < end; j++)
        {
            var cellTarget    = _program.Targets[j];
            var programTarget = cellTarget.ProgramTargets[group];
            var target        = programTarget.Target;

            if (currentTool is null || target.Tool != currentTool)
            {
                code.Add(SetTool(target.Tool));
                currentTool = target.Tool;
            }

            if (currentFrame is null || target.Frame != currentFrame)
            {
                code.Add(SetFrame(target.Frame));
                currentFrame = target.Frame;
            }

            if (target.Zone.IsFlyBy && (currentZone is null || target.Zone != currentZone))
            {
                code.Add($"$APO.CDIS = {target.Zone.Name}");
                currentZone = target.Zone;
            }

            if (programTarget.Index > 0)
            {
                if (programTarget.LeadingJoint > 5)
                {
                    code.Add(ExternalSpeed(programTarget));
                }
                else
                {
                    if (currentSpeed is null || target.Speed != currentSpeed)
                    {
                        if (!programTarget.IsJointMotion)
                        {
                            double rotation = target.Speed.RotationSpeed.ToDegrees();
                            code.Add($"$VEL.CP = {target.Speed.Name}\r\n$VEL.ORI1 = {rotation:0.###}\r\n$VEL.ORI2 = {rotation:0.####}");
                            currentSpeed = target.Speed;
                        }
                    }

                    if (programTarget.IsJointMotion)
                    {
                        double percentSpeed = cellTarget.MinTime / cellTarget.DeltaTime;

                        if (Abs(currentPercentSpeed - percentSpeed) > UnitTol)
                        {
                            code.Add("BAS(#VEL_PTP, 100)");
                            if (cellTarget.DeltaTime > UnitTol)
                            {
                                code.Add($"$VEL_AXIS[{programTarget.LeadingJoint + 1}] = {percentSpeed * 100:0.###}");
                            }
                            currentPercentSpeed = percentSpeed;
                        }
                    }
                }
            }

            // external axes

            string external = string.Empty;

            double[] values = _cell.MechanicalGroups[group].RadiansToDegreesExternal(target);

            for (int i = 0; i < target.External.Length; i++)
            {
                int num = i + 1;
                external += $",E{num} {values[i]:0.####}";
            }

            // motion command

            string moveText;

            if (programTarget.IsJointTarget)
            {
                var      jointTarget  = (JointTarget)target;
                double[] jointDegrees = jointTarget.Joints.Map((x, i) => _cell.MechanicalGroups[group].Robot.RadianToDegree(x, i));

                moveText = $"PTP {{A1 {jointDegrees[0]:0.####},A2 {jointDegrees[1]:0.####},A3 {jointDegrees[2]:0.####},A4 {jointDegrees[3]:0.####},A5 {jointDegrees[4]:0.####},A6 {jointDegrees[5]:0.####}{external}}}";
                if (target.Zone.IsFlyBy)
                {
                    moveText += " C_PTP";
                }
            }
            else
            {
                var cartesian = (CartesianTarget)target;
                var plane     = cartesian.Plane;
                var euler     = RobotCellKuka.PlaneToEuler(plane);

                switch (cartesian.Motion)
                {
                case Motions.Joint:
                {
                    string bits = string.Empty;
                    //  if (target.ChangesConfiguration)
                    {
                        double[] jointDegrees = programTarget.Kinematics.Joints.Map((x, i) => _cell.MechanicalGroups[group].Robot.RadianToDegree(x, i));
                        int      turnNum      = 0;
                        for (int i = 0; i < 6; i++)
                        {
                            if (jointDegrees[i] < 0)
                            {
                                turnNum += (int)Pow(2, i);
                            }
                        }

                        var  configuration = programTarget.Kinematics.Configuration;
                        bool shoulder      = configuration.HasFlag(RobotConfigurations.Shoulder);
                        bool elbow         = configuration.HasFlag(RobotConfigurations.Elbow);
                        elbow = !elbow;
                        bool wrist = configuration.HasFlag(RobotConfigurations.Wrist);

                        int configNum = 0;
                        if (shoulder)
                        {
                            configNum += 1;
                        }
                        if (elbow)
                        {
                            configNum += 2;
                        }
                        if (wrist)
                        {
                            configNum += 4;
                        }

                        string status = Convert.ToString(configNum, 2);
                        string turn   = Convert.ToString(turnNum, 2);
                        bits = $",S'B{status:000}',T'B{turn:000000}'";
                    }

                    moveText = $"PTP {{{GetXyzAbc(euler)}{external}{bits}}}";
                    if (target.Zone.IsFlyBy)
                    {
                        moveText += " C_PTP";
                    }
                    break;
                }

                case Motions.Linear:
                {
                    moveText = $"LIN {{{GetXyzAbc(euler)}{external}}}";
                    if (target.Zone.IsFlyBy)
                    {
                        moveText += " C_DIS";
                    }
                    break;
                }

                default:
                    throw new ArgumentException($" Motion '{cartesian.Motion}' not supported.", nameof(cartesian.Motion));
                }
            }

            foreach (var command in programTarget.Commands.Where(c => c.RunBefore))
            {
                code.Add(command.Code(_program, target));
            }

            code.Add(moveText);

            foreach (var command in programTarget.Commands.Where(c => !c.RunBefore))
            {
                code.Add(command.Code(_program, target));
            }
        }

        code.Add("END");
        return(code);
    }
Ejemplo n.º 26
0
 /// <summary>Get whether the tool is currently enabled.</summary>
 /// <param name="player">The current player.</param>
 /// <param name="tool">The tool selected by the player (if any).</param>
 /// <param name="item">The item selected by the player (if any).</param>
 /// <param name="location">The current location.</param>
 public override bool IsEnabled(Farmer player, Tool?tool, Item?item, GameLocation location)
 {
     return
         (this.Config.Enable &&
          tool is Slingshot);
 }