void IUpdatable.Update()
        {
            IMyAngleGrinder grinder = Main.GrinderHandler?.EquippedGrinder;

            if (grinder == null)
            {
                return;
            }

            bool inputReadable = !MyAPIGateway.Gui.IsCursorVisible && !MyAPIGateway.Gui.ChatEntryVisible;

            if (TargetBlock == null && inputReadable && MyAPIGateway.Input.IsGameControlPressed(MyControlsSpace.SECONDARY_TOOL_ACTION))
            {
                MyCasterComponent casterComp = grinder?.Components?.Get <MyCasterComponent>();
                IMySlimBlock      target     = casterComp?.HitBlock as IMySlimBlock;

                if (target != null)
                {
                    SetLocalTarget(target);
                }
            }

            if (TargetBlock != null && (!inputReadable || MyAPIGateway.Input.IsNewGameControlReleased(MyControlsSpace.SECONDARY_TOOL_ACTION)))
            {
                SetLocalTarget(null);
            }

            if (TargetBlock != null)
            {
                bool finishedGrinding = TargetBlock.IsFullyDismounted;

                // TODO: some targetting sprite?
                //Vector3D blockCenterPos = Vector3D.Transform(BlockLocalCenter, TargetBlock.CubeGrid.WorldMatrix);
                //float blockSize = (TargetBlock.Max - TargetBlock.Min + Vector3I.One).AbsMin() * TargetBlock.CubeGrid.GridSize;
                //Vector4 color = (finishedGrinding ? Color.Lime : Color.Blue);
                //MyTransparentGeometry.AddPointBillboard(MyStringId.GetOrCompute("WhiteDot"), color, blockCenterPos, blockSize, 0, blendType: BlendTypeEnum.AdditiveTop);

                if (finishedGrinding)
                {
                    Main.Notifications.Print(Channel.Precision, $"Precision Grind: target was grinded!", MyFontEnum.Green, 16);
                }
                else
                {
                    Main.Notifications.Print(Channel.Precision, $"Precision Grind: locked to {TargetBlock.BlockDefinition.DisplayNameText}", MyFontEnum.Debug, 16);
                }
            }
        }
        public override void OnControlAcquired(Sandbox.Game.Entities.Character.MyCharacter owner)
        {
            base.OnControlAcquired(owner);

            if (owner == null || owner.Parent == null)
            {
                return;
            }

            if (owner == MySession.Static.LocalCharacter && !owner.Parent.Components.Contains(typeof(MyCasterComponent)))
            {
                MyDrillSensorRayCast raycaster           = new MyDrillSensorRayCast(0, DEFAULT_REACH_DISTANCE);
                MyCasterComponent    raycastingComponent = new MyCasterComponent(raycaster);
                owner.Parent.Components.Add(raycastingComponent);
                controller = owner;
            }
        }
        public void Init(MyObjectBuilder_EntityBase builder, MyHandItemDefinition definition)
        {
            m_handItemDef = definition;
            System.Diagnostics.Debug.Assert(definition != null, "Missing definition for tool!");
            if (definition != null)
            {
                m_physItemDef = MyDefinitionManager.Static.GetPhysicalItemForHandItem(definition.Id);
                m_gunBase     = new MyToolBase(m_handItemDef.MuzzlePosition, WorldMatrix);
            }
            else
            {
                m_gunBase = new MyToolBase(Vector3.Zero, WorldMatrix);
            }
            base.Init(builder);

            if (PhysicalObject != null)
            {
                PhysicalObject.GunEntity = builder;
            }
            if ((definition as MyEngineerToolBaseDefinition) != null)
            {
                m_speedMultiplier    = (m_handItemDef as MyEngineerToolBaseDefinition).SpeedMultiplier;
                m_distanceMultiplier = (definition as MyEngineerToolBaseDefinition).DistanceMultiplier;
            }
            MyDrillSensorRayCast raycaster = new MyDrillSensorRayCast(0f, DEFAULT_REACH_DISTANCE * m_distanceMultiplier);

            m_raycastComponent = new MyCasterComponent(raycaster);
            m_raycastComponent.SetPointOfReference(m_gunBase.GetMuzzleWorldPosition());
            Components.Add <MyCasterComponent>(m_raycastComponent);

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                MyStringHash.GetOrCompute("Utility"),
                MyEnergyConstants.REQUIRED_INPUT_ENGINEERING_TOOL,
                CalculateRequiredPower);
            SinkComp       = sinkComp;
            m_soundEmitter = new MyEntity3DSoundEmitter(this);
        }
示例#4
0
 public override void UpdateOnceBeforeFrame()
 {
     welder          = Entity as IMyWelder;
     caster          = Entity.Components.Get <MyCasterComponent>();
     wrenchCablePort = Entity.GameLogic.GetAs <WrenchPort>();
 }