/// <summary> /// Kill all cheat implementation /// </summary> static void KillAllEnabled(MyGameplayCheat cheat) { // We need player ship to recognize friends if (MySession.PlayerShip == null) { return; } foreach (var entity in MyEntities.GetEntities().ToArray()) { MySmallShip smallShip = entity as MySmallShip; if (smallShip != null && smallShip.Visible && smallShip != MySession.PlayerShip && MyFactions.GetFactionsRelation(MySession.PlayerShip, smallShip) == MyFactionRelationEnum.Enemy) { entity.DoDamage(0, 1000000, 0, MyDamageType.Unknown, MyAmmoType.Unknown, null); } MyPrefabContainer container = entity as MyPrefabContainer; if (container != null && MyFactions.GetFactionsRelation(MySession.PlayerShip, container) == MyFactionRelationEnum.Enemy) { foreach (var prefab in container.GetPrefabs().ToArray()) { MyPrefabLargeWeapon largeWeapon = prefab as MyPrefabLargeWeapon; if (largeWeapon != null) { prefab.DoDamage(0, 1000000, 0, MyDamageType.Unknown, MyAmmoType.Unknown, null); } } } } }
protected float GetDeviatedAngleByDamageRatio() { MyPrefabLargeWeapon prefabLargeWeapon = GetWeaponBase().PrefabParent; if (MySession.PlayerShip != null && MyFactions.GetFactionsRelation(prefabLargeWeapon, MySession.PlayerShip) == MyFactionRelationEnum.Enemy) { float degrees = (float)Math.Pow(120, prefabLargeWeapon.GetDamageRatio() * 1.5 - 1.2) * 4f; return(MathHelper.ToRadians(degrees)); } return(0f); }
private static bool CanShout(IMyObjectToDetect detectedObject) { MyEntity detectedEntity = detectedObject as MyEntity; if (detectedEntity != null) { MyFactionRelationEnum factionRelation = MyFactions.GetFactionsRelation(MySession.PlayerShip, detectedEntity); if (detectedEntity is MySmallShipBot && factionRelation != MyFactionRelationEnum.Friend) { MySmallShipBot bot = detectedEntity as MySmallShipBot; return(!bot.IsParked() && !bot.IsPilotDead()); } if (detectedEntity is MyPrefabLargeWeapon && factionRelation == MyFactionRelationEnum.Enemy) { MyPrefabLargeWeapon largeWeapon = detectedEntity as MyPrefabLargeWeapon; return(largeWeapon.IsWorking()); } } return(false); }
public void DoWork() { // Search for target to attack ClosestEnemy = null; ClosestVisual = null; float distanceSqr = m_seeDistance * m_seeDistance; float closestEnemyDistanceSqr = float.PositiveInfinity; float closestVisualDistanceSqr = float.PositiveInfinity; using (var rbFounded = PoolList <MyRBElement> .Get()) { try { MyEntities.EntityCloseLock.AcquireShared(); MyDynamicAABBTree prunningStructure = MyPhysics.physicsSystem.GetRigidBodyModule().GetPruningStructure(); BoundingBox rbInputElementGetWorldSpaceAABB = new BoundingBox( m_botWorldMatrix.Translation - new Vector3(m_seeDistance), m_botWorldMatrix.Translation + new Vector3(m_seeDistance)); prunningStructure.OverlapAllBoundingBox(ref rbInputElementGetWorldSpaceAABB, rbFounded, (uint)MyElementFlag.EF_RB_ELEMENT); //now try find spot foreach (MyRBElement rb in rbFounded) { if (m_bot == null) { return; } var rigidBody = rb.GetRigidBody(); if (rigidBody == null) { continue; } MyEntity entity = ((MyPhysicsBody)rigidBody.m_UserData).Entity; if (entity == m_bot || entity == null || entity.AIPriority == -1) { continue; } entity = entity.GetBaseEntity(); // Large weapons // Ignore spoiled holograms if (m_bot.IsSpoiledHologram(entity)) { continue; } // Don't attack disabled weapons MyPrefabLargeWeapon largeWeapon = entity as MyPrefabLargeWeapon; MySmallShip smallShip = entity as MySmallShip; MyPrefabLargeShip largeShip = entity as MyPrefabLargeShip; if (largeWeapon != null && !largeWeapon.IsWorking()) { continue; } // Test smallships and largeweapons if (smallShip != null || largeWeapon != null || largeShip != null) { // Is enemy? if (MyFactions.GetFactionsRelation(m_bot, entity) == MyFactionRelationEnum.Enemy && CanSeeTarget(m_bot, entity)) { var entityDistanceSqr = Vector3.DistanceSquared(entity.GetPosition(), m_position); if (entityDistanceSqr < distanceSqr && (ClosestEnemy == null || entity.AIPriority >= ClosestEnemy.AIPriority) && (entityDistanceSqr < closestEnemyDistanceSqr || entity.AIPriority > ClosestEnemy.AIPriority)) { MyLine line = new MyLine(m_position, entity.GetPosition(), true); var result = MyEntities.GetIntersectionWithLine(ref line, m_bot, entity, true, ignoreChilds: true); if (!result.HasValue) { // Visual Detection - ignore visualy detected targets if they are further than any normaly detected target if (IsVisualyDetected(smallShip)) { if (entityDistanceSqr < closestVisualDistanceSqr) { ClosestVisual = entity; closestVisualDistanceSqr = entityDistanceSqr; } } else { closestEnemyDistanceSqr = entityDistanceSqr; ClosestEnemy = entity; } } } } } } } finally { MyEntities.EntityCloseLock.ReleaseShared(); } } }
internal override void Update(MySmallShipBot bot) { base.Update(bot); if (m_target != null && !m_target.IsDead()) { MySmallShip smallShipTarget = m_target as MySmallShip; MyPrefabLargeWeapon largeWeaponTarget = m_target as MyPrefabLargeWeapon; if (largeWeaponTarget != null && !largeWeaponTarget.IsWorking()) { m_isInvalid = true; return; } if (m_timeToAlarmCheck >= 0) { m_timeToAlarmCheck -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS; // When transition from curious behavior try raise alarm (if this doesn't work pass some flag curious behavior) if (m_timeToAlarmCheck < 0 && smallShipTarget != null && smallShipTarget.HasRadarJammerActive()) { bot.LaunchAlarm(smallShipTarget); } } UpdateVisibility(bot); if (m_targetVisible) { AttackTarget(bot, m_targetVisible); findSmallship.Init(bot); // Attack player to prevent his passivity when we have invicible wingmans m_playerAttackDecisionTimer -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS; if (smallShipTarget != null && smallShipTarget.Leader == MySession.PlayerShip && m_playerAttackDecisionTimer <= 0) { m_playerAttackDecisionTimer = 2.5f; if (MyMwcUtils.GetRandomFloat(0, 1.0f) < 0.7f) { m_target = smallShipTarget.Leader; } } } else { m_state = StateEnum.CLOSING; findSmallship.Update(bot, m_target); if (findSmallship.PathNotFound) { bot.IsSleeping = true; m_isInvalid = true; } else if (!findSmallship.GotPosition()) { AttackTarget(bot, false); } } } }
public MyGuiControlPrefabLargeWeaponUse(IMyGuiControlsParent parent, MyPrefabLargeWeapon prefab, MyTexture2D texture) : base(parent, prefab, texture) { }
public MyGuiControlPrefabLargeWeaponUse(IMyGuiControlsParent parent, MyPrefabLargeWeapon prefab) : base(parent, prefab) { }
/// <summary> /// CreatePrefab /// </summary> /// <param name="hudLabelText"></param> /// <param name="objBuilder"></param> /// <returns></returns> public MyPrefabBase CreatePrefab(string hudLabelText, MyPrefabContainer prefabContainer, MyMwcObjectBuilder_PrefabBase prefabBuilder) { Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyPrefabFactory.CreatePrefab"); MyPrefabConfiguration config = MyPrefabConstants.GetPrefabConfiguration(prefabBuilder.GetObjectBuilderType(), prefabBuilder.GetObjectBuilderId().Value); Vector3 relativePosition = MyPrefabContainer.GetRelativePositionInAbsoluteCoords(prefabBuilder.PositionInContainer); Matrix prefabLocalOrientation = Matrix.CreateFromYawPitchRoll(prefabBuilder.AnglesInContainer.X, prefabBuilder.AnglesInContainer.Y, prefabBuilder.AnglesInContainer.Z); MyPrefabBase prefab = null; if (config is MyPrefabConfigurationKinematic) { prefab = new MyPrefabKinematic(prefabContainer); } else if (config is MyPrefabConfigurationLight) { prefab = new MyPrefabLight(prefabContainer); } else if (config is MyPrefabConfigurationLargeWeapon) { prefab = new MyPrefabLargeWeapon(prefabContainer); } else if (config is MyPrefabConfigurationSound) { prefab = new MyPrefabSound(prefabContainer); } else if (config is MyPrefabConfigurationParticles) { prefab = new MyPrefabParticles(prefabContainer); } else if (config is MyPrefabConfigurationLargeShip) { prefab = new MyPrefabLargeShip(prefabContainer); } else if (config is MyPrefabConfigurationHangar) { prefab = new MyPrefabHangar(prefabContainer); } else if (config is MyPrefabConfigurationFoundationFactory) { prefab = new MyPrefabFoundationFactory(prefabContainer); } else if (config is MyPrefabConfigurationSecurityControlHUB) { prefab = new MyPrefabSecurityControlHUB(prefabContainer); } else if (config is MyPrefabConfigurationBankNode) { prefab = new MyPrefabBankNode(prefabContainer); } else if (config is MyPrefabConfigurationGenerator) { prefab = new MyPrefabGenerator(prefabContainer); } else if (config is MyPrefabConfigurationScanner) { prefab = new MyPrefabScanner(prefabContainer); } else if (config is MyPrefabConfigurationCamera) { prefab = new MyPrefabCamera(prefabContainer); } else if (config is MyPrefabConfigurationAlarm) { prefab = new MyPrefabAlarm(prefabContainer); } else { prefab = new MyPrefab(prefabContainer); //prefab.Init(hudLabelText, relativePosition, prefabLocalOrientation, prefabBuilder, config); } prefab.Init(hudLabelText, relativePosition, prefabLocalOrientation, prefabBuilder, config); Render.MyRender.GetRenderProfiler().EndProfilingBlock(); return(prefab); }