protected float CalculateRequiredPower()
 {
     return(ShouldBePowered() ? SinkComp.MaxRequiredInputByType(MyResourceDistributorComponent.ElectricityId) : 0.0f);
 }
Ejemplo n.º 2
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            m_physicalItemId = new MyDefinitionId(typeof(MyObjectBuilder_PhysicalGunObject), "HandDrillItem");
            if (objectBuilder.SubtypeName != null && objectBuilder.SubtypeName.Length > 0)
            {
                m_physicalItemId = new MyDefinitionId(typeof(MyObjectBuilder_PhysicalGunObject), objectBuilder.SubtypeName + "Item");
            }
            PhysicalObject = (MyObjectBuilder_PhysicalGunObject)MyObjectBuilderSerializer.CreateNewObject(m_physicalItemId);

            (PositionComp as MyPositionComponent).WorldPositionChanged = WorldPositionChanged;

            m_handItemDefId = objectBuilder.GetId();

            var definition = MyDefinitionManager.Static.TryGetHandItemDefinition(ref m_handItemDefId);

            m_speedMultiplier = 1f / (definition as MyHandDrillDefinition).SpeedMultiplier;
            m_drillBase       = new MyDrillBase(this,
                                                MyDrillConstants.DRILL_HAND_DUST_EFFECT,
                                                MyDrillConstants.DRILL_HAND_DUST_STONES_EFFECT,
                                                MyDrillConstants.DRILL_HAND_SPARKS_EFFECT,
                                                new MyDrillSensorRayCast(-0.5f, 2.15f),
                                                new MyDrillCutOut(1.0f, 0.35f * (definition as MyHandDrillDefinition).DistanceMultiplier),
                                                SPIKE_SLOWDOWN_TIME_IN_SECONDS,
                                                floatingObjectSpawnOffset: -0.25f,
                                                floatingObjectSpawnRadius: 1.4f * 0.25f
                                                );
            m_drillBase.VoxelHarvestRatio = MyDrillConstants.VOXEL_HARVEST_RATIO * (definition as MyHandDrillDefinition).HarvestRatioMultiplier;
            AddDebugRenderComponent(new Components.MyDebugRenderCompomentDrawDrillBase(m_drillBase));
            base.Init(objectBuilder);

            m_physItemDef = MyDefinitionManager.Static.GetPhysicalItemDefinition(m_physicalItemId);
            Init(null, m_physItemDef.Model, null, null, null);
            Render.CastShadows            = true;
            Render.NeedsResolveCastShadow = false;

            m_spike        = Subparts["Spike"];
            m_spikeBasePos = m_spike.PositionComp.LocalMatrix.Translation;

            m_drillBase.IgnoredEntities.Add(this);
            m_drillBase.OnWorldPositionChanged(PositionComp.WorldMatrix);

            PhysicalObject.GunEntity          = (MyObjectBuilder_EntityBase)objectBuilder.Clone();
            PhysicalObject.GunEntity.EntityId = this.EntityId;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;
            m_oreDetectorBase.DetectionRadius = 20;
            m_oreDetectorBase.OnCheckControl  = OnCheckControl;

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                MyStringHash.GetOrCompute("Utility"),
                MyEnergyConstants.REQUIRED_INPUT_HAND_DRILL,
                () => m_tryingToDrill ? SinkComp.MaxRequiredInputByType(MyResourceDistributorComponent.ElectricityId) : 0f);
            SinkComp = sinkComp;

            foreach (ToolSound toolSound in definition.ToolSounds)
            {
                if (toolSound.type == null || toolSound.subtype == null || toolSound.sound == null)
                {
                    continue;
                }
                if (toolSound.type.Equals("Main"))
                {
                    if (toolSound.subtype.Equals("Idle"))
                    {
                        m_drillBase.m_idleSoundLoop = new MySoundPair(toolSound.sound);
                    }
                    if (toolSound.subtype.Equals("Soundset"))
                    {
                        m_drillBase.m_drillMaterial = MyStringHash.GetOrCompute(toolSound.sound);
                    }
                }
            }
        }