private void CheckChangesOnCharacter() { if (Character.CurrentWeapon != m_previousWeapon) { DeactivateJetpackRagdoll(); ActivateJetpackRagdoll(); } m_previousWeapon = Character.CurrentWeapon; var movementState = Character.GetCurrentMovementState(); if (Character.JetpackEnabled && movementState == Common.ObjectBuilders.MyCharacterMovementEnum.Flying && Character.Physics.Enabled) { if (!IsRagdollActivated || !RagdollMapper.IsActive) { ActivateJetpackRagdoll(); } } else if (RagdollMapper.IsPartiallySimulated) { DeactivateJetpackRagdoll(); } if (Character.Physics != m_previousPhysics) { UpdateCharacterPhysics(); } m_previousPhysics = Character.Physics; if (Character.IsDead && !IsRagdollActivated && Character.Physics.Enabled) { InitDeadBodyPhysics(); } }
public override void UpdateBeforeSimulation() { if (MyAPIGateway.Utilities.IsDedicated) { return; } IMyLargeTurretBase turret = MyAPIGateway.Session?.Player?.Controller?.ControlledEntity?.Entity as IMyLargeTurretBase; if (turret == null) { ClearGPS(); return; } _wasInTurretLastFrame = true; _gunBase = turret as IMyGunObject <MyGunBase>; if (_gunBase.GunBase.CurrentAmmoDefinition == null) { ClearGPS(); return; } Vector3D turretLoc = turret.GetPosition(); float projectileSpeed = _gunBase.GunBase.CurrentAmmoDefinition.DesiredSpeed; float projectileRange = _gunBase.GunBase.CurrentAmmoDefinition.MaxTrajectory + 100; float projectileRangeSquared = projectileRange * projectileRange; foreach (IMyCubeGrid grid in _grids) { if (grid.Physics == null) { RemoveGPS(grid.EntityId); continue; } Vector3D gridLoc = grid.WorldAABB.Center; if (grid.EntityId == turret.CubeGrid.EntityId || Vector3D.DistanceSquared(gridLoc, turretLoc) > projectileRangeSquared || !GridHasHostileOwners(grid)) { RemoveGPS(grid.EntityId); continue; } Vector3D interceptPoint = CalculateProjectileInterceptPosition( projectileSpeed, turret.CubeGrid.Physics.LinearVelocity, turretLoc, grid.Physics.LinearVelocity, gridLoc, 10); AddGPS(grid.EntityId, interceptPoint); } }
public virtual void OnAddedToGroup(MyGridLogicalGroupData group) { this.TerminalSystem = group.TerminalSystem; this.ResourceDistributor = group.ResourceDistributor; this.WeaponSystem = group.WeaponSystem; if (string.IsNullOrEmpty(this.ResourceDistributor.DebugName)) { this.ResourceDistributor.DebugName = this.m_cubeGrid.ToString(); } this.m_cubeGrid.OnFatBlockAdded += new Action <MyCubeBlock>(this.ResourceDistributor.CubeGrid_OnFatBlockAddedOrRemoved); this.m_cubeGrid.OnFatBlockRemoved += new Action <MyCubeBlock>(this.ResourceDistributor.CubeGrid_OnFatBlockAddedOrRemoved); this.ResourceDistributor.AddSink(this.GyroSystem.ResourceSink); this.ResourceDistributor.AddSink(this.ConveyorSystem.ResourceSink); this.ConveyorSystem.ResourceSink.IsPoweredChanged += new Action(this.ResourceDistributor.ConveyorSystem_OnPoweredChanged); foreach (MyBlockGroup group2 in this.m_cubeGrid.BlockGroups) { this.TerminalSystem.AddUpdateGroup(group2, false, false); } this.TerminalSystem.GroupAdded += this.m_terminalSystem_GroupAdded; this.TerminalSystem.GroupRemoved += this.m_terminalSystem_GroupRemoved; foreach (MyCubeBlock block in this.m_cubeGrid.GetFatBlocks()) { if (!block.MarkedForClose) { MyTerminalBlock block2 = block as MyTerminalBlock; if (block2 != null) { this.TerminalSystem.Add(block2); } MyResourceSourceComponent source = block.Components.Get <MyResourceSourceComponent>(); if (source != null) { this.ResourceDistributor.AddSource(source); } MyResourceSinkComponent sink = block.Components.Get <MyResourceSinkComponent>(); if (sink != null) { this.ResourceDistributor.AddSink(sink); } IMyRechargeSocketOwner owner = block as IMyRechargeSocketOwner; if (owner != null) { owner.RechargeSocket.ResourceDistributor = group.ResourceDistributor; } IMyGunObject <MyDeviceBase> gun = block as IMyGunObject <MyDeviceBase>; if (gun != null) { this.WeaponSystem.Register(gun); } } } MyResourceDistributorComponent resourceDistributor = this.ResourceDistributor; resourceDistributor.OnPowerGenerationChanged = (Action <bool>)Delegate.Combine(resourceDistributor.OnPowerGenerationChanged, new Action <bool>(this.OnPowerGenerationChanged)); this.TerminalSystem.BlockManipulationFinishedFunction(); this.ResourceDistributor.UpdateBeforeSimulation(); }
internal void Unregister(IMyGunObject<MyDeviceBase> gun) { MyDebug.AssertDebug(gun != null); MyDebug.AssertDebug(m_gunsByDefId[gun.DefinitionId].Contains(gun)); m_gunsByDefId[gun.DefinitionId].Remove(gun); if (WeaponUnregistered != null) WeaponUnregistered(this, new EventArgs() { Weapon = gun }); }
public RegularWeapon(IMyTerminalBlock block, IMyRemoteControl remoteControl, IBehavior behavior) : base(block, remoteControl, behavior) { if (!_isValid) { return; } GetWeaponDefinition(_block); if (_weaponDefinition == null) { Logger.MsgDebug(_block.CustomName + " Weapon Definition Not Found", DebugTypeEnum.WeaponSetup); _isValid = false; return; } foreach (var ammoData in _weaponDefinition.WeaponAmmoDatas) { if (ammoData == null) { continue; } if (ammoData.RateOfFire > 0) { _rateOfFire = ammoData.RateOfFire; } } if (_block as IMyLargeTurretBase != null) { _isTurret = true; _turret = _block as IMyLargeTurretBase; _gunBase = _turret as IMyGunObject <MyGunBase>; } else if (_block as IMyUserControllableGun != null) { _isStatic = true; _staticGun = _block as IMyUserControllableGun; _gunBase = _staticGun as IMyGunObject <MyGunBase>; } else { Logger.MsgDebug(_block.CustomName + " Is Neither Gun Or Turret?", DebugTypeEnum.WeaponSetup); _isValid = false; return; } //Get Rate of Fire //Determine If Barrage Capable }
public override void UpdateOnceBeforeFrame() { block = (IMyFunctionalBlock)Entity; if (block.CubeGrid?.Physics == null) { return; } gun = (IMyGunObject <MyGunBase>)Entity; lastShotTime = gun.GunBase.LastShootTime.Ticks; NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME; }
internal void Unregister(IMyGunObject <MyDeviceBase> gun) { MyDebug.AssertDebug(gun != null); MyDebug.AssertDebug(m_gunsByDefId[gun.DefinitionId].Contains(gun)); m_gunsByDefId[gun.DefinitionId].Remove(gun); if (WeaponUnregistered != null) { WeaponUnregistered(this, new EventArgs() { Weapon = gun }); } }
internal void Register(IMyGunObject<MyDeviceBase> gun) { MyDebug.AssertDebug(gun != null); if (!m_gunsByDefId.ContainsKey(gun.DefinitionId)) { m_gunsByDefId.Add(gun.DefinitionId, new HashSet<IMyGunObject<MyDeviceBase>>()); } MyDebug.AssertDebug(!m_gunsByDefId[gun.DefinitionId].Contains(gun)); m_gunsByDefId[gun.DefinitionId].Add(gun); if (WeaponRegistered != null) WeaponRegistered(this, new EventArgs() { Weapon = gun }); }
/// <summary> /// Called when game logic is added to container /// </summary> public virtual void Init(WeaponControlLayer layer) { ControlLayer = layer; CubeBlock = (MyCubeBlock)layer.Entity; //Targeting = ; Block = CubeBlock as IMyFunctionalBlock; gun = CubeBlock as IMyGunObject <MyGunBase>; IsFixedGun = CubeBlock is IMySmallGatlingGun; PrimaryEmitter = new MyEntity3DSoundEmitter(CubeBlock, useStaticList: true); SecondaryEmitter = new MyEntity3DSoundEmitter(CubeBlock, useStaticList: true); InitializeSound(); Initialized = true; }
internal void Unregister(IMyGunObject<MyDeviceBase> gun) { MyDebug.AssertDebug(gun != null); if (!m_gunsByDefId.ContainsKey(gun.DefinitionId)) { MyDebug.FailRelease("deinition ID " + gun.DefinitionId + " not in m_gunsByDefId"); return; } MyDebug.AssertDebug(m_gunsByDefId[gun.DefinitionId].Contains(gun)); m_gunsByDefId[gun.DefinitionId].Remove(gun); if (WeaponUnregistered != null) WeaponUnregistered(this, new EventArgs() { Weapon = gun }); }
public override void UpdateOnceBeforeFrame() { try { if (MyAPIGateway.Session.IsServer && MyAPIGateway.Utilities.IsDedicated) { return; // DS doesn't need to play sounds } block = (IMyFunctionalBlock)Entity; if (block?.CubeGrid?.Physics == null) { return; // ignore projected grids } gun = (IMyGunObject <MyGunBase>)Entity; if (!gun.GunBase.HasProjectileAmmoDefined && !allMisTurrets) { return; // ignore missile turrets that don't have projectile ammo } var def = (MyWeaponBlockDefinition)block.SlimBlock.BlockDefinition; var weaponDef = MyDefinitionManager.Static.GetWeaponDefinition(def.WeaponDefinitionId); if (gun.GunBase.IsAmmoProjectile) { soundPair = weaponDef.WeaponAmmoDatas[0].ShootSound; } else { soundPair = weaponDef.WeaponAmmoDatas[1].ShootSound; } lastShotTime = gun.GunBase.LastShootTime.Ticks; soundEmitter = new MyEntity3DSoundEmitter((MyEntity)Entity); // create a sound emitter following this block entity block.IsWorkingChanged += BlockWorkingChanged; BlockWorkingChanged(block); } catch (Exception e) { LogError(e); } }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { base.Init(objectBuilder); try { _objectBuilder = objectBuilder; NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.BEFORE_NEXT_FRAME; // this.m_missileAmmoDefinition = weaponProperties.GetCurrentAmmoDefinitionAs<MyMissileAmmoDefinition>(); SetPowerSink(); cube = (IMyCubeBlock)Entity; block = (IMyFunctionalBlock)Entity; gun = Entity as IMyGunObject <MyGunBase>; GetAmmoProperties(); //get shoot time for initial check _lastShootTime = GetLastShootTime(); GetTurretMaxRange(); soundEmitter = new MyEntity3DSoundEmitter((MyEntity)Entity, true); projectileData = new RailgunProjectileData() { ShooterID = Entity.EntityId, DesiredSpeed = _desiredSpeed, MaxTrajectory = _maxTrajectory, DeviationAngle = _deviationAngle, ProjectileTrailColor = _trailColor, ProjectileTrailScale = _trailScale, }; RailgunCore.RegisterRailgun(projectileData.ShooterID, projectileData); } catch (Exception e) { MyAPIGateway.Utilities.ShowNotification("Exception in init", 10000, MyFontEnum.Red); MyLog.Default.WriteLine(e); } }
internal void Register(IMyGunObject <MyDeviceBase> gun) { MyDebug.AssertDebug(gun != null); if (!m_gunsByDefId.ContainsKey(gun.DefinitionId)) { m_gunsByDefId.Add(gun.DefinitionId, new HashSet <IMyGunObject <MyDeviceBase> >()); } MyDebug.AssertDebug(!m_gunsByDefId[gun.DefinitionId].Contains(gun)); m_gunsByDefId[gun.DefinitionId].Add(gun); if (WeaponRegistered != null) { WeaponRegistered(this, new EventArgs() { Weapon = gun }); } }
internal IMyGunObject <MyDeviceBase> GetGunWithAmmo(MyDefinitionId gunId, long shooter) { if (!m_gunsByDefId.ContainsKey(gunId)) { return(null); } IMyGunObject <MyDeviceBase> result = m_gunsByDefId[gunId].FirstOrDefault(); foreach (var gun in m_gunsByDefId[gunId]) { MyGunStatusEnum status; if (gun.CanShoot(MyShootActionEnum.PrimaryAction, shooter, out status)) { result = gun; break; } } return(result); }
internal void Unregister(IMyGunObject <MyDeviceBase> gun) { MyDebug.AssertDebug(gun != null); if (!m_gunsByDefId.ContainsKey(gun.DefinitionId)) { MyDebug.FailRelease("deinition ID " + gun.DefinitionId + " not in m_gunsByDefId"); return; } MyDebug.AssertDebug(m_gunsByDefId[gun.DefinitionId].Contains(gun)); m_gunsByDefId[gun.DefinitionId].Remove(gun); if (WeaponUnregistered != null) { WeaponUnregistered(this, new EventArgs() { Weapon = gun }); } }
private void CheckChangesOnCharacter() { //if (MyFakes.ENABLE_RAGDOLL_DEBUG) Debug.WriteLine("RagdollComponent.CheckChangesOnCharacter"); if (MyPerGameSettings.EnableRagdollInJetpack) { if (Character.CurrentWeapon != m_previousWeapon) { DeactivateJetpackRagdoll(); ActivateJetpackRagdoll(); } m_previousWeapon = Character.CurrentWeapon; var movementState = Character.GetCurrentMovementState(); var jetpack = Character.JetpackComp; if ((jetpack != null && jetpack.TurnedOn) && movementState == MyCharacterMovementEnum.Flying && Character.Physics.Enabled) { if (!IsRagdollActivated || !RagdollMapper.IsActive) { DeactivateJetpackRagdoll(); ActivateJetpackRagdoll(); } } else if (RagdollMapper != null && RagdollMapper.IsPartiallySimulated) { DeactivateJetpackRagdoll(); } } if (Character.Physics != m_previousPhysics) { UpdateCharacterPhysics(); } m_previousPhysics = Character.Physics; if (Character.IsDead && !IsRagdollActivated && Character.Physics.Enabled) { InitDeadBodyPhysics(); } }
internal bool CanShoot(MyShootActionEnum action, out MyGunStatusEnum status, out IMyGunObject <MyDeviceBase> FailedGun) { FailedGun = null; if (m_currentGuns == null) { status = MyGunStatusEnum.NotSelected; return(false); } bool result = false; status = MyGunStatusEnum.OK; // Report only one weapon status; Return true if any of the weapons can shoot foreach (var weapon in m_currentGuns) { MyGunStatusEnum weaponStatus; result |= weapon.CanShoot(action, m_shipController.ControllerInfo.Controller != null ? m_shipController.ControllerInfo.Controller.Player.Identity.IdentityId : m_shipController.OwnerId, out weaponStatus); // mw:TODO maybe autoswitch when gun has no ammo? //if (weaponStatus == MyGunStatusEnum.OutOfAmmo) //{ // if (weapon.GunBase.SwitchAmmoMagazineToFirstAvailable()) // { // weaponStatus = MyGunStatusEnum.OK; // result = true; // } //} if (weaponStatus != MyGunStatusEnum.OK) { FailedGun = weapon; status = weaponStatus; } } return(result); }
public override ChangeInfo Update(MyEntity owner, long playerID = 0) { bool thisWeaponIsCurrent = false; bool shipHasThisWeapon = false; var character = MySession.LocalCharacter; bool characterHasThisWeapon = character != null && (character.GetInventory().ContainItems(1, Definition.Id) || !character.WeaponTakesBuilderFromInventory(Definition.Id)); ChangeInfo changed = ChangeInfo.None; if (characterHasThisWeapon) { var currentWeapon = character.CurrentWeapon; if (currentWeapon != null) { thisWeaponIsCurrent = (MyDefinitionManager.Static.GetPhysicalItemForHandItem(currentWeapon.DefinitionId).Id == Definition.Id); } if (thisWeaponIsCurrent && currentWeapon is MyAutomaticRifleGun) { int amount = character.CurrentWeapon.GetAmmunitionAmount(); if (m_lastAmmoCount != amount) { m_lastAmmoCount = amount; IconText.Clear().AppendInt32(amount); changed |= ChangeInfo.IconText; } } } var shipControler = MySession.ControlledEntity as MyShipController; if (shipControler != null && shipControler.GridSelectionSystem.WeaponSystem != null) { // var shipWeaponType = shipControler.GetWeaponType(Definition.Id.TypeId); // shipHasThisWeapon = shipWeaponType.HasValue && shipControler.GridSelectionSystem.WeaponSystem.HasGunsOfId(shipWeaponType.Value); shipHasThisWeapon = shipControler.GridSelectionSystem.WeaponSystem.HasGunsOfId(Definition.Id); if (shipHasThisWeapon) { IMyGunObject <MyDeviceBase> gunObject = shipControler.GridSelectionSystem.WeaponSystem.GetGun(Definition.Id); if (gunObject.GunBase is MyGunBase) { int ammo = 0; foreach (var gun in shipControler.GridSelectionSystem.WeaponSystem.GetGunsById(Definition.Id)) { ammo += gun.GetAmmunitionAmount(); } if (ammo != m_lastAmmoCount) { m_lastAmmoCount = ammo; IconText.Clear().AppendInt32(ammo); changed |= ChangeInfo.IconText; } } } thisWeaponIsCurrent = shipControler.GridSelectionSystem.GetGunId() == Definition.Id; } changed |= SetEnabled(characterHasThisWeapon || shipHasThisWeapon); WantsToBeSelected = thisWeaponIsCurrent; m_needsWeaponSwitching = !thisWeaponIsCurrent; return(changed); }
private void ShootBeginFailed(MyShootActionEnum action, MyGunStatusEnum status, IMyGunObject<MyDeviceBase> failedGun) { failedGun.BeginFailReaction(action, status); }
private void ShowShootNotification(MyGunStatusEnum status, IMyGunObject<MyDeviceBase> weapon) { if (!ControllerInfo.IsLocallyHumanControlled()) return; switch (status) { case MyGunStatusEnum.NotSelected: if (m_noWeaponNotification == null) { m_noWeaponNotification = new MyHudNotification(MySpaceTexts.NotificationNoWeaponSelected, 2000, font: MyFontEnum.Red); MyHud.Notifications.Add(m_noWeaponNotification); } MyHud.Notifications.Add(m_noWeaponNotification); break; case MyGunStatusEnum.OutOfAmmo: if (m_outOfAmmoNotification == null) { m_outOfAmmoNotification = new MyHudNotification(MySpaceTexts.OutOfAmmo, 2000, font: MyFontEnum.Red); } if (weapon is MyCubeBlock) m_outOfAmmoNotification.SetTextFormatArguments((weapon as MyCubeBlock).DisplayNameText); MyHud.Notifications.Add(m_outOfAmmoNotification); break; case MyGunStatusEnum.NotFunctional: case MyGunStatusEnum.OutOfPower: if (m_weaponNotWorkingNotification == null) { m_weaponNotWorkingNotification = new MyHudNotification(MySpaceTexts.NotificationWeaponNotWorking, 2000, font: MyFontEnum.Red); } if (weapon is MyCubeBlock) m_weaponNotWorkingNotification.SetTextFormatArguments((weapon as MyCubeBlock).DisplayNameText); MyHud.Notifications.Add(m_weaponNotWorkingNotification); break; default: break; } }
private void Init(IMyEntity Entity) { try { m_entity = Entity; m_entityId = Entity.EntityId; Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; m_functionalBlock = Entity as IMyFunctionalBlock; m_cubeBlock = Entity as IMyCubeBlock; m_myCubeBlock = Entity as MyCubeBlock; CubeGrid = m_myCubeBlock.CubeGrid; _cubeGridEntityId = CubeGrid.EntityId; m_terminalBlock = Entity as IMyTerminalBlock; m_gunObject = m_cubeBlock as IMyGunObject <MyGunBase>; MyWeaponBlockDefinition weaponBlockDef = null; Debug.Write($"def == null ? {weaponBlockDef == null}", 1, debug); MyDefinitionManager.Static.TryGetDefinition <MyWeaponBlockDefinition>(new SerializableDefinitionId(m_functionalBlock.BlockDefinition.TypeId, m_functionalBlock.BlockDefinition.SubtypeId), out weaponBlockDef); m_weaponDef = MyDefinitionManager.Static.GetWeaponDefinition(weaponBlockDef.WeaponDefinitionId); Debug.Write($"weaponDef == null ? {m_weaponDef == null}", 1, debug); Debug.Write($"Attempting to get magDefId from {m_weaponDef.AmmoMagazinesId[0]} ...", 1, debug); m_magDefId = m_weaponDef.AmmoMagazinesId[0]; Debug.Write($"Complete. magDefId == null ? {m_magDefId == null}", 1, debug); m_magDef = MyDefinitionManager.Static.GetAmmoMagazineDefinition(m_magDefId); Debug.Write($"m_magDef == null ? {m_magDef == null}", 1, debug); Debug.Write($"m_weaponDef.WeaponAmmoDatas == null ? {m_weaponDef.WeaponAmmoDatas == null}", 1, debug); Debug.Write($"m_weaponDef.WeaponAmmoDatas.Count == {m_weaponDef.WeaponAmmoDatas.Count()}", 1, debug); MyWeaponDefinition.MyWeaponAmmoData data = null; var i = -1; while (i < m_weaponDef.WeaponAmmoDatas.Count() - 1) { i++; Debug.Write($"m_weaponDef.WeaponAmmoDatas[{i}] == null ? {m_weaponDef.WeaponAmmoDatas[i] == null }", 1, debug); if (m_weaponDef.WeaponAmmoDatas[i] == null) { continue; } data = m_weaponDef.WeaponAmmoDatas[i]; break; } m_timeoutMult = 60f / data.RateOfFire; m_chargeDefinitionId = m_magDefId; Debug.Write($"Attempting to get ammoDef from {m_magDef.AmmoDefinitionId} ...", 1, debug); var ammoDef = MyDefinitionManager.Static.GetAmmoDefinition(m_magDef.AmmoDefinitionId); Debug.Write($"Complete. ammoDef == null ? {ammoDef == null}", 1, debug); var damagePerShot = ammoDef.GetDamageForMechanicalObjects(); Debug.Write($"Damage per shot = {damagePerShot}", 1, debug); m_heatPerShot = (damagePerShot + ammoDef.MaxTrajectory + ammoDef.DesiredSpeed) * 0.01f; m_heatMax = m_cubeBlock.SlimBlock.MaxIntegrity; Debug.Write($"m_heatMax/m_heatPerShot = {m_heatMax}/{m_heatPerShot} = {m_heatMax / m_heatPerShot} shots", 1, debug); m_operationalPower = m_heatPerShot * 0.01f; m_maxAmmo = (int)(m_heatMax / m_heatPerShot); m_inventory = ((Sandbox.ModAPI.Ingame.IMyTerminalBlock)(Entity)).GetInventory(0) as IMyInventory; m_resourceSink = Entity.Components.Get <MyResourceSinkComponent>(); if (!LogicCore.Instance.BeamLogics.ContainsKey(Entity.EntityId)) { LogicCore.Instance.BeamLogics.Add(Entity.EntityId, this); Debug.Write("Added new beamlogic to BeamLogics dictionary.", 1, debug); } MyAPIGateway.Utilities.InvokeOnGameThread(() => RemoveSmokeEffects()); m_terminalBlock.AppendingCustomInfo += AppendCustomInfo; m_initialized = true; Debug.Write("Weapon initialization complete.", 1, debug); } catch (Exception e) { Debug.HandleException(e); MyAPIGateway.Parallel.Sleep(1000); Init(Entity); } }
private void CheckChangesOnCharacter() { MyCharacter character = base.Character; if (MyPerGameSettings.EnableRagdollInJetpack) { if (!ReferenceEquals(character.Physics, this.m_previousPhysics)) { this.UpdateCharacterPhysics(); this.m_previousPhysics = character.Physics; } if (Sync.IsServer) { goto TR_001B; } else if (character.ClosestParentId == 0) { goto TR_001B; } else { this.DeactivateJetpackRagdoll(); } } TR_0004: if ((character.IsDead && !this.IsRagdollActivated) && character.Physics.Enabled) { this.InitDeadBodyPhysics(); } return; TR_001B: if (!ReferenceEquals(character.CurrentWeapon, this.m_previousWeapon)) { this.DeactivateJetpackRagdoll(); this.ActivateJetpackRagdoll(); this.m_previousWeapon = character.CurrentWeapon; } MyCharacterJetpackComponent jetpackComp = character.JetpackComp; MyCharacterMovementEnum currentMovementState = character.GetCurrentMovementState(); if ((((jetpackComp == null) || !jetpackComp.TurnedOn) || (currentMovementState != MyCharacterMovementEnum.Flying)) && ((currentMovementState != MyCharacterMovementEnum.Falling) || !character.Physics.Enabled)) { if ((this.RagdollMapper != null) && this.RagdollMapper.IsPartiallySimulated) { this.DeactivateJetpackRagdoll(); } } else if (!this.IsRagdollActivated || !this.RagdollMapper.IsActive) { this.DeactivateJetpackRagdoll(); this.ActivateJetpackRagdoll(); } if (this.IsRagdollActivated && (character.Physics.Ragdoll != null)) { bool isDead = character.IsDead; using (List <HkRigidBody> .Enumerator enumerator = character.Physics.Ragdoll.RigidBodies.GetEnumerator()) { while (enumerator.MoveNext()) { enumerator.Current.EnableDeactivation = isDead; } } } goto TR_0004; }
private void CheckChangesOnCharacter() { //if (MyFakes.ENABLE_RAGDOLL_DEBUG) Debug.WriteLine("RagdollComponent.CheckChangesOnCharacter"); if (MyPerGameSettings.EnableRagdollInJetpack) { if (Character.CurrentWeapon != m_previousWeapon) { DeactivateJetpackRagdoll(); ActivateJetpackRagdoll(); } m_previousWeapon = Character.CurrentWeapon; var movementState = Character.GetCurrentMovementState(); var jetpack = Character.JetpackComp; if ((jetpack != null && jetpack.TurnedOn) && movementState == Common.ObjectBuilders.MyCharacterMovementEnum.Flying && Character.Physics.Enabled) { if (!IsRagdollActivated || !RagdollMapper.IsActive) { DeactivateJetpackRagdoll(); ActivateJetpackRagdoll(); } } else if (RagdollMapper != null && RagdollMapper.IsPartiallySimulated) { DeactivateJetpackRagdoll(); } } if (Character.Physics != m_previousPhysics) { UpdateCharacterPhysics(); } m_previousPhysics = Character.Physics; if (Character.IsDead && !IsRagdollActivated && Character.Physics.Enabled) { InitDeadBodyPhysics(); } }
internal bool CanShoot(MyShootActionEnum action, out MyGunStatusEnum status, out IMyGunObject<MyDeviceBase> FailedGun) { FailedGun = null; if (m_currentGuns == null) { status = MyGunStatusEnum.NotSelected; return false; } bool result = false; status = MyGunStatusEnum.OK; // Report only one weapon status; Return true if any of the weapons can shoot foreach (var weapon in m_currentGuns) { MyGunStatusEnum weaponStatus; result |= weapon.CanShoot(action, m_shipController.ControllerInfo.Controller != null ? m_shipController.ControllerInfo.Controller.Player.Identity.IdentityId : m_shipController.OwnerId, out weaponStatus); // mw:TODO maybe autoswitch when gun has no ammo? //if (weaponStatus == MyGunStatusEnum.OutOfAmmo) //{ // if (weapon.GunBase.SwitchAmmoMagazineToFirstAvailable()) // { // weaponStatus = MyGunStatusEnum.OK; // result = true; // } //} if (weaponStatus != MyGunStatusEnum.OK) { FailedGun = weapon; status = weaponStatus; } } return result; }
public virtual void UnregisterFromSystems(MyCubeBlock block) { if (block.GetType() != typeof(MyCubeBlock)) { if (this.ResourceDistributor != null) { MyResourceSourceComponent source = block.Components.Get <MyResourceSourceComponent>(); if (source != null) { this.ResourceDistributor.RemoveSource(source); } MyResourceSinkComponent sink = block.Components.Get <MyResourceSinkComponent>(); if (sink != null) { this.ResourceDistributor.RemoveSink(sink, true, false); } IMyRechargeSocketOwner owner = block as IMyRechargeSocketOwner; if (owner != null) { owner.RechargeSocket.ResourceDistributor = null; } } if (this.WeaponSystem != null) { IMyGunObject <MyDeviceBase> gun = block as IMyGunObject <MyDeviceBase>; if (gun != null) { this.WeaponSystem.Unregister(gun); } } if (this.TerminalSystem != null) { MyTerminalBlock block5 = block as MyTerminalBlock; if (block5 != null) { this.TerminalSystem.Remove(block5); } } if (block.HasInventory) { this.ConveyorSystem.Remove(block); } IMyConveyorEndpointBlock block2 = block as IMyConveyorEndpointBlock; if (block2 != null) { this.ConveyorSystem.RemoveConveyorBlock(block2); } IMyConveyorSegmentBlock segmentBlock = block as IMyConveyorSegmentBlock; if (segmentBlock != null) { this.ConveyorSystem.RemoveSegmentBlock(segmentBlock); } MyReflectorLight reflector = block as MyReflectorLight; if (reflector != null) { this.ReflectorLightSystem.Unregister(reflector); } MyDataBroadcaster broadcaster = block.Components.Get <MyDataBroadcaster>(); if (broadcaster != null) { this.RadioSystem.Unregister(broadcaster); } MyDataReceiver reciever = block.Components.Get <MyDataReceiver>(); if (reciever != null) { this.RadioSystem.Unregister(reciever); } if (MyFakes.ENABLE_WHEEL_CONTROLS_IN_COCKPIT) { MyMotorSuspension motor = block as MyMotorSuspension; if (motor != null) { this.WheelSystem.Unregister(motor); } } IMyLandingGear gear = block as IMyLandingGear; if (gear != null) { this.LandingSystem.Unregister(gear); } MyGyro gyro = block as MyGyro; if (gyro != null) { this.GyroSystem.Unregister(gyro); } MyCameraBlock camera = block as MyCameraBlock; if (camera != null) { this.CameraSystem.Unregister(camera); } } block.OnUnregisteredFromGridSystems(); }
public virtual void RegisterInSystems(MyCubeBlock block) { if (block.GetType() != typeof(MyCubeBlock)) { MyCubeBlock block1; if (this.ResourceDistributor != null) { MyResourceSourceComponent source = block.Components.Get <MyResourceSourceComponent>(); if (source != null) { this.ResourceDistributor.AddSource(source); } MyResourceSinkComponent sink = block.Components.Get <MyResourceSinkComponent>(); if (!(block is MyThrust) && (sink != null)) { this.ResourceDistributor.AddSink(sink); } IMyRechargeSocketOwner owner = block as IMyRechargeSocketOwner; if (owner != null) { owner.RechargeSocket.ResourceDistributor = this.ResourceDistributor; } } if (this.WeaponSystem != null) { IMyGunObject <MyDeviceBase> gun = block as IMyGunObject <MyDeviceBase>; if (gun != null) { this.WeaponSystem.Register(gun); } } if (this.TerminalSystem != null) { MyTerminalBlock block6 = block as MyTerminalBlock; if (block6 != null) { this.TerminalSystem.Add(block6); } } if ((block == null) || !block.HasInventory) { block1 = null; } else { block1 = block; } MyCubeBlock block2 = block1; if (block2 != null) { this.ConveyorSystem.Add(block2); } IMyConveyorEndpointBlock endpointBlock = block as IMyConveyorEndpointBlock; if (endpointBlock != null) { endpointBlock.InitializeConveyorEndpoint(); this.ConveyorSystem.AddConveyorBlock(endpointBlock); } IMyConveyorSegmentBlock segmentBlock = block as IMyConveyorSegmentBlock; if (segmentBlock != null) { segmentBlock.InitializeConveyorSegment(); this.ConveyorSystem.AddSegmentBlock(segmentBlock); } MyReflectorLight reflector = block as MyReflectorLight; if (reflector != null) { this.ReflectorLightSystem.Register(reflector); } if (block.Components.Contains(typeof(MyDataBroadcaster))) { MyDataBroadcaster broadcaster = block.Components.Get <MyDataBroadcaster>(); this.RadioSystem.Register(broadcaster); } if (block.Components.Contains(typeof(MyDataReceiver))) { MyDataReceiver reciever = block.Components.Get <MyDataReceiver>(); this.RadioSystem.Register(reciever); } if (MyFakes.ENABLE_WHEEL_CONTROLS_IN_COCKPIT) { MyMotorSuspension motor = block as MyMotorSuspension; if (motor != null) { this.WheelSystem.Register(motor); } } IMyLandingGear gear = block as IMyLandingGear; if (gear != null) { this.LandingSystem.Register(gear); } MyGyro gyro = block as MyGyro; if (gyro != null) { this.GyroSystem.Register(gyro); } MyCameraBlock camera = block as MyCameraBlock; if (camera != null) { this.CameraSystem.Register(camera); } } block.OnRegisteredToGridSystems(); }
public override void UpdateBeforeSimulation() { try { if (MyAPIGateway.Session.IsServer && MyAPIGateway.Utilities.IsDedicated) { return; } block = (IMyCubeBlock)Entity; if (block?.CubeGrid?.Physics == null) { return; // ignore projected grids } gun = (IMyGunObject <MyGunBase>)Entity; if (first) { first = false; lastShotTime = gun.GunBase.LastShootTime.Ticks; muzzleLocalMatrix = gun.GunBase.GetMuzzleLocalMatrix(); Setup(); // call the overwriteable method for other guns to change this class' variables if (justPlaced) { justPlaced = false; var placed = block as IMyLargeTurretBase; if (placed != null) { //MyAPIGateway.Utilities.ShowNotification("[ Valid turret, attempting to set filters ]", 4000, MyFontEnum.Blue); placed.ApplyAction(TargetMeteors); placed.ApplyAction(TargetMissiles); placed.ApplyAction(TargetSmallShips); placed.ApplyAction(TargetLargeShips); placed.ApplyAction(TargetCharacters); placed.ApplyAction(TargetStations); placed.ApplyAction(TargetNeutrals); } } } if (!block.IsFunctional) // block broken, pause everything (even ongoing animations) { return; } if (!useMuzzleLogic) { return; } // only animate if custom recoil dummy is setup with appropriate barrel subparts - default is False if (isAnimated) { ApplyRecoil(); } } catch (Exception e) { LogError(e); } }
void UpdatableModule.Update() { IMyGunObject <Sandbox.Game.Weapons.MyToolBase> gunObject = MyKernel.Tool as IMyGunObject <Sandbox.Game.Weapons.MyToolBase>; Toggled = MyKernel.Tool.Enabled || gunObject.IsShooting; }