private MyStringHash RayCastGround() { MyStringHash walkSurfaceMaterial = new MyStringHash(); float maxDistValue = MyConstants.DEFAULT_GROUND_SEARCH_DISTANCE; var from = m_character.PositionComp.GetPosition() + m_character.PositionComp.WorldMatrix.Up * 0.5; //(needs some small distance from the bottom or the following call to HavokWorld.CastRay will find no hits) var to = from + m_character.PositionComp.WorldMatrix.Down * maxDistValue; MyPhysics.CastRay(from, to, m_hits, MyPhysics.CollisionLayers.CharacterCollisionLayer); // Skips invalid hits (null body, self character) int index = 0; while ((index < m_hits.Count) && ((m_hits[index].HkHitInfo.Body == null) || (m_hits[index].HkHitInfo.GetHitEntity() == Entity.Components))) { index++; } if (m_hits.Count == 0) { m_standingOnGrid = null; } if (index < m_hits.Count) { // We must take only closest hit (others are hidden behind) var h = m_hits[index]; var entity = h.HkHitInfo.GetHitEntity(); var sqDist = Vector3D.DistanceSquared((Vector3D)h.Position, from); if (sqDist < maxDistValue * maxDistValue) { var cubeGrid = entity as MyCubeGrid; var voxelBase = entity as MyVoxelBase; m_standingOnGrid = cubeGrid; if (cubeGrid != null) { walkSurfaceMaterial = cubeGrid.Physics.GetMaterialAt(h.Position); } else if (voxelBase != null && voxelBase.Storage != null && voxelBase.Storage.DataProvider != null) { var materialDefinition = voxelBase.GetMaterialAt(ref h.Position); if (materialDefinition != null) { walkSurfaceMaterial = MyStringHash.GetOrCompute(materialDefinition.MaterialTypeName); } } if (walkSurfaceMaterial.ToString().Length == 0) { walkSurfaceMaterial = MyMaterialType.ROCK; } } } m_hits.Clear(); return(walkSurfaceMaterial); }
public virtual MyObjectBuilder_EntityStat GetObjectBuilder() { var builder = new MyObjectBuilder_EntityStat(); MyEntityStatDefinition definition = MyDefinitionManager.Static.GetDefinition(new MyDefinitionId(builder.TypeId, StatId)) as MyEntityStatDefinition; builder.SubtypeName = m_statId.ToString(); Debug.Assert(definition != null); if (definition != null) { Debug.Assert(definition.MaxValue != 0); builder.Value = m_currentValue / (definition.MaxValue != 0 ? definition.MaxValue : 1); // Save stat value relative to the definition maximum value builder.MaxValue = m_maxValue / (definition.MaxValue != 0 ? definition.MaxValue : 1); // Save stat maximum value relative to the definition maximum value } else { builder.Value = m_currentValue / m_maxValue; builder.MaxValue = 1.0f; } builder.Effects = null; if (m_effects != null && m_effects.Count > 0) { int savedEffectCount = m_effects.Count; foreach (var effectPair in m_effects) { if (effectPair.Value.Duration < 0) { --savedEffectCount; // Don't save the permanent effects } } if (savedEffectCount > 0) { builder.Effects = new MyObjectBuilder_EntityStatRegenEffect[savedEffectCount]; int effectIndex = 0; foreach (var effectPair in m_effects) { if (effectPair.Value.Duration >= 0) { builder.Effects[effectIndex++] = effectPair.Value.GetObjectBuilder(); } } } } return(builder); }
public MyEffectInstance CreateEffect(IMySourceVoice input, MyStringHash effect, MySourceVoice[] cues = null, float? duration = null) { if(!m_effects.ContainsKey(effect)) { Debug.Fail(string.Format("Effect not found: {0}", effect.ToString())); return null; } var instance = new MyEffectInstance(m_effects[effect], input, cues, duration, m_engine); m_activeEffects.Add(instance); return instance; }
public MyEffectInstance CreateEffect(IMySourceVoice input, MyStringHash effect, MySourceVoice[] cues = null, float?duration = null) { if (!m_effects.ContainsKey(effect)) { Debug.Fail(string.Format("Effect not found: {0}", effect.ToString())); return(null); } var instance = new MyEffectInstance(m_effects[effect], input, cues, duration, m_engine); m_activeEffects.Add(instance); return(instance); }
public Initializer() { // move radar blocks to radar resource group // first make sure radar group exists. If it does not, radar will stay in its original group. MyStringHash radar = MyStringHash.GetOrCompute("Radar"); foreach (MyDefinitionBase radarGroupDefn in MyDefinitionManager.Static.GetAllDefinitions()) { if (radarGroupDefn is MyResourceDistributionGroupDefinition && radarGroupDefn.Id.SubtypeId == radar) { // find each radar block and move it to radar group foreach (MyDefinitionBase radarBlockDefn in MyDefinitionManager.Static.GetAllDefinitions()) { if (radarBlockDefn is MyCubeBlockDefinition && radarBlockDefn.Id.SubtypeName.ToLower().Contains("radar")) // RadarEquipment.IsRadarOrJammer { MyBeaconDefinition beaconDefn = radarBlockDefn as MyBeaconDefinition; if (beaconDefn != null) { beaconDefn.ResourceSinkGroup = radar.ToString(); continue; } MyLaserAntennaDefinition lasAntDefn = radarBlockDefn as MyLaserAntennaDefinition; if (lasAntDefn != null) { lasAntDefn.ResourceSinkGroup = radar; continue; } MyRadioAntennaDefinition radAntDefn = radarBlockDefn as MyRadioAntennaDefinition; if (radAntDefn != null) { radAntDefn.ResourceSinkGroup = radar; continue; } // stop trying to guess what the radar block is made of } } break; } } }
public override MyObjectBuilder_DefinitionBase GetObjectBuilder() { MyObjectBuilder_VoxelMaterialDefinition ob = (MyObjectBuilder_VoxelMaterialDefinition)base.GetObjectBuilder(); ob.MaterialTypeName = MaterialTypeName; ob.MinedOre = MinedOre; ob.MinedOreRatio = MinedOreRatio; ob.CanBeHarvested = CanBeHarvested; ob.IsRare = IsRare; ob.SpawnsInAsteroids = SpawnsInAsteroids; ob.SpawnsFromMeteorites = SpawnsFromMeteorites; ob.DamageRatio = DamageRatio; ob.DiffuseXZ = DiffuseXZ; ob.DiffuseY = DiffuseY; ob.NormalXZ = NormalXZ; ob.NormalY = NormalY; ob.SpecularPower = SpecularPower; ob.SpecularShininess = SpecularShininess; ob.ParticleEffect = ParticleEffect.ToString(); ob.DamagedMaterial = DamagedMaterial.ToString(); ob.DamageThreashold = DamageThreshold / 255f; return(ob); }
private MyStringHash RayCastGround() { MyStringHash walkSurfaceMaterial = new MyStringHash(); float maxDistValue = MyConstants.DEFAULT_GROUND_SEARCH_DISTANCE; var from = m_character.PositionComp.GetPosition() + m_character.PositionComp.WorldMatrix.Up * 0.5; //(needs some small distance from the bottom or the following call to HavokWorld.CastRay will find no hits) var to = from + m_character.PositionComp.WorldMatrix.Down * maxDistValue; MyPhysics.CastRay(from, to, m_hits, MyPhysics.CollisionLayers.CharacterCollisionLayer); // Skips invalid hits (null body, self character) int index = 0; while ((index < m_hits.Count) && ((m_hits[index].HkHitInfo.Body == null) || (m_hits[index].HkHitInfo.GetHitEntity() == Entity.Components))) { index++; } if (m_hits.Count == 0) { if ((m_standingOnGrid != null || m_standingOnVoxel != null) && ShouldUpdateSoundEmitters) { m_standingOnGrid = null; m_standingOnVoxel = null; MyEntity3DSoundEmitter.UpdateEntityEmitters(true, true, false); } else { m_standingOnGrid = null; m_standingOnVoxel = null; } } if (index < m_hits.Count) { // We must take only closest hit (others are hidden behind) var h = m_hits[index]; var entity = h.HkHitInfo.GetHitEntity(); var sqDist = Vector3D.DistanceSquared((Vector3D)h.Position, from); if (sqDist < maxDistValue * maxDistValue) { var cubeGrid = entity as MyCubeGrid; var voxelBase = entity as MyVoxelBase; if (((cubeGrid != null && m_standingOnGrid != cubeGrid) || (voxelBase != null && m_standingOnVoxel != voxelBase)) && ShouldUpdateSoundEmitters) { m_standingOnGrid = cubeGrid; m_standingOnVoxel = voxelBase; MyEntity3DSoundEmitter.UpdateEntityEmitters(true, true, true); } else { m_standingOnGrid = cubeGrid; m_standingOnVoxel = voxelBase; } if(cubeGrid != null || voxelBase != null) m_jumpReady = true; if (cubeGrid != null) walkSurfaceMaterial = cubeGrid.Physics.GetMaterialAt(h.Position + m_character.PositionComp.WorldMatrix.Down * 0.1f); else if (voxelBase != null && voxelBase.Storage != null && voxelBase.Storage.DataProvider != null) { var materialDefinition = voxelBase.GetMaterialAt(ref h.Position); if (materialDefinition != null) walkSurfaceMaterial = MyStringHash.GetOrCompute(materialDefinition.MaterialTypeName); } if (walkSurfaceMaterial.ToString().Length == 0) walkSurfaceMaterial = MyMaterialType.ROCK; } } m_hits.Clear(); return walkSurfaceMaterial; }
private void ApplyDamage(DamageImpactEnum damageImpact, MyStringHash myDamageType) { if (!Sync.IsServer) return; if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW && MyDebugDrawSettings.DEBUG_DRAW_SHOW_DAMAGE) { if (damageImpact != DamageImpactEnum.NoDamage) { VRageRender.MyRenderProxy.DebugDrawText2D(new Vector2(100, 100), "DAMAGE! TYPE: " + myDamageType.ToString() + " IMPACT: " + damageImpact.ToString(), Color.Red, 1); } } switch (damageImpact) { case DamageImpactEnum.SmallDamage: DoDamage(MyPerGameSettings.CharacterSmallDamage, myDamageType, true); break; case DamageImpactEnum.MediumDamage: DoDamage(MyPerGameSettings.CharacterMediumDamage, myDamageType, true); break; case DamageImpactEnum.CriticalDamage: DoDamage(MyPerGameSettings.CharacterCriticalDamage, myDamageType, true); break; case DamageImpactEnum.DeadlyDamage: DoDamage(MyPerGameSettings.CharacterDeadlyDamage, myDamageType, true); break; case DamageImpactEnum.NoDamage: default: break; } }
private MyStringHash RayCastGround() { MyStringHash walkSurfaceMaterial = new MyStringHash(); var from = m_character.PositionComp.GetPosition() + m_character.PositionComp.WorldMatrix.Up * 0.1; //(needs some small distance from the bottom or the following call to HavokWorld.CastRay will find no hits) var to = from + m_character.PositionComp.WorldMatrix.Down * MyConstants.DEFAULT_GROUND_SEARCH_DISTANCE; MyPhysics.CastRay(from, to, m_hits); // Skips invalid hits (null body, self character) int index = 0; while ((index < m_hits.Count) && ((m_hits[index].HkHitInfo.Body == null) || (m_hits[index].HkHitInfo.GetHitEntity() == Entity.Components))) { index++; } //m_walkingSurfaceType = MyWalkingSurfaceType.None; if (index < m_hits.Count) { // We must take only closest hit (others are hidden behind) var h = m_hits[index]; var entity = h.HkHitInfo.GetHitEntity(); var sqDist = Vector3D.DistanceSquared((Vector3D)h.Position, from); if (sqDist < MyConstants.DEFAULT_GROUND_SEARCH_DISTANCE * MyConstants.DEFAULT_GROUND_SEARCH_DISTANCE) { var cubeGrid = entity as MyCubeGrid; var voxelBase = entity as MyVoxelBase; if (cubeGrid != null) walkSurfaceMaterial = cubeGrid.Physics.GetMaterialAt(h.Position); else if (voxelBase != null && voxelBase.Storage != null && voxelBase.Storage.DataProvider != null) { var materialDefinition = voxelBase.GetMaterialAt(ref h.Position); if(materialDefinition != null) walkSurfaceMaterial = MyStringHash.GetOrCompute(materialDefinition.MaterialTypeName); } if (walkSurfaceMaterial.ToString().Length == 0) walkSurfaceMaterial = MyMaterialType.ROCK; } } m_hits.Clear(); return walkSurfaceMaterial; }
/// <summary> /// This just iterates through registered listeners and informs them.. /// </summary> /// <param name="entityId"></param> /// <param name="eventType"></param> /// <param name="eventParams"></param> private static void InvokeEventOnListeners(long entityId, MyStringHash eventType, EntityEventParams eventParams) { var previousValue = ProcessingEvents; if (previousValue) { m_debugCounter++; System.Diagnostics.Debug.Assert(m_debugCounter < 4, "Invokation of entity events are generating more than 3 other entity events and this call get's too long. We should rework the mechanism to some queue and have postponed invokation instead.."); } if (m_debugCounter > 5) { System.Diagnostics.Debug.Fail("Loop on entity events detected, ignoring event " + eventType.String + " and returning.. "); return; } ProcessingEvents = true; if (RegisteredListeners.ContainsKey(entityId)) { if (RegisteredListeners[entityId].ContainsKey(eventType)) { foreach (var registered in RegisteredListeners[entityId][eventType]) { // TODO: This is now in safe block, this should be propably removed later, when this is tested and safe try { registered.Handler(eventParams); } catch (Exception e) { System.Diagnostics.Debug.Fail(String.Format("Invoking registered method for entity event {0} failed. {1} ", eventType.ToString(), e.Message)); } } } } ProcessingEvents = previousValue; if (!ProcessingEvents) { m_debugCounter = 0; } if (HasPostponedOperations && !ProcessingEvents) { ProcessPostponedRegistrations(); } }
public override string ToString() { return(Hash.ToString()); }
public override string ToString() { return(m_statId.ToString()); }
public override string ToString() { return($"{Utils.ColorMaskToHSVText(ColorExtensions.UnpackHSVFromUint(ColorMaskPacked))}/{Skin.ToString()}"); }
public override string ToString() { return($"MountPoints:\t{string.Join(", ", MountPoints)}\tCubeSize:\t{MyCubeSize.ToString()}\tSizeX:\t{SizeX.ToString()}\tSizeY:\t{SizeY.ToString()}\tSizeZ:\t{SizeZ.ToString()}\tSubtypeId:\t{SubtypeId.ToString()}\tSubtypeName:\t{SubtypeName}\tModName:\t{ModName}\tID:\t{Id}"); }
public override MyObjectBuilder_DefinitionBase GetObjectBuilder() { var ob = (MyObjectBuilder_HandItemDefinition)base.GetObjectBuilder(); ob.Id = Id; ob.LeftHandOrientation = Quaternion.CreateFromRotationMatrix(LeftHand); ob.LeftHandPosition = LeftHand.Translation; ob.RightHandOrientation = Quaternion.CreateFromRotationMatrix(RightHand); ob.RightHandPosition = RightHand.Translation; ob.ItemOrientation = Quaternion.CreateFromRotationMatrix(ItemLocation); ob.ItemPosition = ItemLocation.Translation; ob.ItemWalkingOrientation = Quaternion.CreateFromRotationMatrix(ItemWalkingLocation); ob.ItemWalkingPosition = ItemWalkingLocation.Translation; ob.BlendTime = BlendTime; ob.XAmplitudeOffset = XAmplitudeOffset; ob.YAmplitudeOffset = YAmplitudeOffset; ob.ZAmplitudeOffset = ZAmplitudeOffset; ob.XAmplitudeScale = XAmplitudeScale; ob.YAmplitudeScale = YAmplitudeScale; ob.ZAmplitudeScale = ZAmplitudeScale; ob.RunMultiplier = RunMultiplier; ob.ItemWalkingOrientation3rd = Quaternion.CreateFromRotationMatrix(ItemWalkingLocation3rd); ob.ItemWalkingPosition3rd = ItemWalkingLocation3rd.Translation; ob.ItemOrientation3rd = Quaternion.CreateFromRotationMatrix(ItemLocation3rd); ob.ItemPosition3rd = ItemLocation3rd.Translation; ob.AmplitudeMultiplier3rd = AmplitudeMultiplier3rd; ob.SimulateLeftHand = SimulateLeftHand; ob.SimulateRightHand = SimulateRightHand; ob.FingersAnimation = FingersAnimation; ob.ItemShootOrientation = Quaternion.CreateFromRotationMatrix(ItemShootLocation); ob.ItemShootPosition = ItemShootLocation.Translation; ob.ItemShootOrientation3rd = Quaternion.CreateFromRotationMatrix(ItemShootLocation3rd); ob.ItemShootPosition3rd = ItemShootLocation3rd.Translation; ob.ShootBlend = ShootBlend; ob.ItemIronsightOrientation = Quaternion.CreateFromRotationMatrix(ItemIronsightLocation); ob.ItemIronsightPosition = ItemIronsightLocation.Translation; ob.MuzzlePosition = MuzzlePosition; ob.ShootScatter = ShootScatter; ob.ScatterSpeed = ScatterSpeed; ob.PhysicalItemId = PhysicalItemId; ob.LightColor = LightColor; ob.LightFalloff = LightFalloff; ob.LightRadius = LightRadius; ob.LightGlareSize = LightGlareSize; ob.LightIntensityLower = LightIntensityLower; ob.LightIntensityUpper = LightIntensityUpper; ob.ShakeAmountTarget = ShakeAmountTarget; ob.ShakeAmountNoTarget = ShakeAmountNoTarget; ob.ToolSounds = ToolSounds; ob.ToolMaterial = ToolMaterial.ToString(); ob.ItemPositioning = ItemPositioning; ob.ItemPositioning3rd = ItemPositioning3rd; ob.ItemPositioningWalk = ItemPositioningWalk; ob.ItemPositioningWalk3rd = ItemPositioningWalk3rd; ob.ItemPositioningShoot = ItemPositioningShoot; ob.ItemPositioningShoot3rd = ItemPositioningShoot3rd; return(ob); }