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); }