private void removePilotToolStripMenuItem_Click(object sender, EventArgs e) { TreeNode node = SectorTree.SelectedNode; MyObjectBuilder_Sector sector = (MyObjectBuilder_Sector)node.Parent.Parent.Tag; Console.WriteLine("in method"); if (node.Nodes.ContainsKey("Pilot")) { Console.WriteLine("Contains Pilot"); TreeNode pilotNode = node.Nodes[node.Nodes.IndexOfKey("Pilot")]; MyObjectBuilder_Cockpit cockpit = (MyObjectBuilder_Cockpit)pilotNode.Tag; long Pilot_id = 0; if (cockpit.Pilot != null) { DialogResult dialogResult = MessageBox.Show("Overwrite \"" + SectorTree.SelectedNode.Parent.Parent.Text + "\"?", "Save", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { MyObjectBuilder_Character pilot = (MyObjectBuilder_Character)cockpit.Pilot; MyObjectBuilder_Character newPilot = (MyObjectBuilder_Character)pilot.Clone(); MyPositionAndOrientation newpos = (MyPositionAndOrientation)newPilot.PositionAndOrientation; newpos.Position.X = 0; newpos.Position.Y = 0; newpos.Position.Z = 0; newPilot.PositionAndOrientation = newpos; newPilot.AutoenableJetpackDelay = 0; newPilot.JetpackEnabled = true; newPilot.Battery.ProducerEnabled = true; cockpit.Pilot = null; sector.SectorObjects.Add(newPilot); Pilot_id = newPilot.EntityId; string file = Path.Combine(this.saves_path, SectorTree.SelectedNode.Parent.Parent.Text, "SANDBOX_0_0_0_.sbs"); string backupfile = Path.Combine(this.saves_path, SectorTree.SelectedNode.Parent.Parent.Text, "SANDBOX_0_0_0_.BAK2"); if (File.Exists(backupfile)) { File.Delete(backupfile); } File.Move(file, backupfile); label1.Text = "Saving..."; MyObjectBuilder_Sector mySector = (MyObjectBuilder_Sector)SectorTree.SelectedNode.Parent.Parent.Tag; using (FileStream sr = File.Open(file, FileMode.Create)) { MyObjectBuilder_Base.SerializeXML(sr, mySector); sr.Dispose(); } //now update the sbc file String sbcfile = Path.Combine(this.saves_path, node.Parent.Parent.Text, "Sandbox.sbc"); XDocument sbcFile = XDocument.Load(sbcfile); sbcFile.Root.SetElementValue("ControlledObject", Pilot_id); sbcFile.Save(sbcfile); this.create_tree(node.Parent.Parent, mySector); label1.Text = ""; } else { return; } } } }
public virtual void GetObjectBuilder(MyObjectBuilder_Character objectBuilder) { objectBuilder.OxygenLevel = SuitOxygenLevel; objectBuilder.EnvironmentOxygenLevel = EnvironmentOxygenLevel; objectBuilder.NeedsOxygenFromSuit = NeedsOxygenFromSuit; if (m_storedGases != null && m_storedGases.Length > 0) { if (objectBuilder.StoredGases == null) { objectBuilder.StoredGases = new List <MyObjectBuilder_Character.StoredGas>(); } foreach (var storedGas in m_storedGases) { if (!objectBuilder.StoredGases.TrueForAll((obGas) => obGas.Id != storedGas.Id)) { continue; } objectBuilder.StoredGases.Add(new MyObjectBuilder_Character.StoredGas { Id = storedGas.Id, FillLevel = storedGas.FillLevel }); } } }
public override bool OnSave(BitStream stream) { Debug.Assert(Instance != null, "Saving null replicable!"); if (Instance == null) { return(false); } stream.WriteBool(Instance.IsUsing is MyShipController); if (Instance.IsUsing is MyShipController) { long ownerId = Instance.IsUsing.EntityId; VRage.Serialization.MySerializer.Write(stream, ref ownerId); long characterId = Instance.EntityId; VRage.Serialization.MySerializer.Write(stream, ref characterId); } else { MyObjectBuilder_Character builder = (MyObjectBuilder_Character)Instance.GetObjectBuilder(); VRage.Serialization.MySerializer.Write(stream, ref builder, MyObjectBuilderSerializer.Dynamic); } return(true); }
private IMyPlayer FindPlayer(IMyEngineerToolBase handTool) { List <IMyPlayer> players = new List <IMyPlayer>(); MyAPIGateway.Players.GetPlayers(players); foreach (IMyPlayer player in players) { IMyCharacter character = player.Controller.ControlledEntity as IMyCharacter; if (character == null) { continue; } // The most inefficient way of finding which player is equiped with what tool. // What is needed is either MyCharacter.CurrentWeapon, or MyEngineerToolBase.Owner exposed through the appropriate interface. MyObjectBuilder_Character c = character.GetObjectBuilder(true) as MyObjectBuilder_Character; if (c != null && c.HandWeapon != null && c.HandWeapon.EntityId == handTool.EntityId) { return(player); } } return(null); }
protected override void OnLoad(BitStream stream, Action <MyCharacter> loadingDoneHandler) { bool isUsing; VRage.Serialization.MySerializer.CreateAndRead(stream, out isUsing); if (isUsing) { long ownerId; VRage.Serialization.MySerializer.CreateAndRead(stream, out ownerId); long characterId; VRage.Serialization.MySerializer.CreateAndRead(stream, out characterId); MyEntities.CallAsync(() => LoadAsync(ownerId, characterId, loadingDoneHandler)); } else { MyCharacter character = new MyCharacter(); MyObjectBuilder_Character builder = (MyObjectBuilder_Character)VRage.Serialization.MySerializer.CreateAndRead <MyObjectBuilder_EntityBase>(stream, MyObjectBuilderSerializer.Dynamic); TryRemoveExistingEntity(builder.EntityId); Vector3 velocity = builder.LinearVelocity; velocity /= MyEntityPhysicsStateGroup.EffectiveSimulationRatio; builder.LinearVelocity = velocity; MyEntities.InitAsync(character, builder, true, (e) => loadingDoneHandler(character)); } }
public virtual void Init(MyObjectBuilder_Character characterBuilder) { if (characterBuilder == null) return; m_inertiaDampenersNotification = new MyHudNotification(); m_jetpackToggleNotification = new MyHudNotification(); CurrentAutoEnableDelay = characterBuilder.AutoenableJetpackDelay; if (ThrustComp != null) Character.Components.Remove<MyJetpackThrustComponent>(); var thrustProperties = Character.Definition.Jetpack.ThrustProperties; FuelConverterDefinition = null;; FuelConverterDefinition = !MyFakes.ENABLE_HYDROGEN_FUEL ? new MyFuelConverterInfo { Efficiency = 1.0f } : Character.Definition.Jetpack.ThrustProperties.FuelConverter; MyDefinitionId fuelId = new MyDefinitionId(); if (!FuelConverterDefinition.FuelId.IsNull()) fuelId = thrustProperties.FuelConverter.FuelId; MyGasProperties fuelDef = null; if (MyFakes.ENABLE_HYDROGEN_FUEL) MyDefinitionManager.Static.TryGetDefinition(fuelId, out fuelDef); FuelDefinition = fuelDef ?? new MyGasProperties // Use electricity by default { Id = MyResourceDistributorComponent.ElectricityId, EnergyDensity = 1f, }; ForceMagnitude = thrustProperties.ForceMagnitude; MinPowerConsumption = thrustProperties.MinPowerConsumption; MaxPowerConsumption = thrustProperties.MaxPowerConsumption; MinPlanetaryInfluence = thrustProperties.MinPlanetaryInfluence; MaxPlanetaryInfluence = thrustProperties.MaxPlanetaryInfluence; EffectivenessAtMinInfluence = thrustProperties.EffectivenessAtMinInfluence; EffectivenessAtMaxInfluence = thrustProperties.EffectivenessAtMaxInfluence; NeedsAtmosphereForInfluence = thrustProperties.NeedsAtmosphereForInfluence; ConsumptionFactorPerG = thrustProperties.ConsumptionFactorPerG; MyEntityThrustComponent thrustComp = new MyJetpackThrustComponent(); thrustComp.Init(); Character.Components.Add(thrustComp); ThrustComp.DampenersEnabled = characterBuilder.DampenersEnabled; foreach (Vector3I direction in Base6Directions.IntDirections) { ThrustComp.Register(Character, direction); // Preferably there should be a jetpack entity (equipment) that could hold the thrusts instead of the character } thrustComp.ResourceSink(Character).TemporaryConnectedEntity = Character; Character.SuitRechargeDistributor.AddSink(thrustComp.ResourceSink(Character)); TurnOnJetpack(characterBuilder.JetpackEnabled, true, true); }
public CharacterEntity(FileInfo characterFile) : base(null) { MyObjectBuilder_Character character = BaseObjectManager.LoadContentFile <MyObjectBuilder_Character>(characterFile); ObjectBuilder = character; m_inventory = new InventoryEntity(character.Inventory); }
public virtual void Init(MyObjectBuilder_Character characterOb) { if (MySession.Static.SurvivalMode) { m_suitOxygenAmount = characterOb.OxygenLevel * Definition.OxygenCapacity; } else { m_suitOxygenAmount = Definition.OxygenCapacity; } m_oldSuitOxygenLevel = SuitOxygenLevel; m_gasIdToIndex = new Dictionary <MyDefinitionId, int>(); if (MyFakes.ENABLE_HYDROGEN_FUEL && Definition.SuitResourceStorage != null) { m_storedGases = new GasData[Definition.SuitResourceStorage.Count]; for (int gasIndex = 0; gasIndex < m_storedGases.Length; ++gasIndex) { var gasInfo = Definition.SuitResourceStorage[gasIndex]; m_storedGases[gasIndex] = new GasData { Id = gasInfo.Id, FillLevel = 1f, MaxCapacity = gasInfo.MaxCapacity, Throughput = gasInfo.Throughput }; m_gasIdToIndex.Add(gasInfo.Id, gasIndex); } if (characterOb.StoredGases != null) { foreach (var gasInfo in characterOb.StoredGases) { int gasIndex; if (!m_gasIdToIndex.TryGetValue(gasInfo.Id, out gasIndex)) { continue; } m_storedGases[gasIndex].FillLevel = gasInfo.FillLevel; } } } if (m_storedGases == null) { m_storedGases = new GasData[0]; } m_oxygenBottleRefillNotification = new MyHudNotification(text: MySpaceTexts.NotificationBottleRefill, level: MyNotificationLevel.Important); m_lowOxygenNotification = new MyHudNotification(text: MySpaceTexts.NotificationOxygenLow, font: MyFontEnum.Red, level: MyNotificationLevel.Important); m_criticalOxygenNotification = new MyHudNotification(text: MySpaceTexts.NotificationOxygenCritical, font: MyFontEnum.Red, level: MyNotificationLevel.Important); m_helmetToggleNotification = m_helmetToggleNotification ?? new MyHudNotification(); // Init() is called when toggling helmet so this check is required m_needsOxygen = Definition.NeedsOxygen; NeedsUpdateBeforeSimulation100 = true; }
static public string GetPlayerSuitLightStatus(MyObjectBuilder_Character CharacterInfo) { bool BitVal = false; if (CurrentPlayerState == 0) { BitVal = CharacterInfo.LightEnabled; } return(BitVal.ToString()); }
static public string GetPlayerOxygen(MyObjectBuilder_Character CharacterInfo) { double percentDouble = 0; if (CurrentPlayerState == 0) { percentDouble = CharacterInfo.OxygenLevel * 10000f / 100; } return(percentDouble.ToString()); }
static public string GetPlayerEnergy(MyObjectBuilder_Character CharacterInfo) { double percentDouble = 0; if (CurrentPlayerState == 0) { percentDouble = CharacterInfo.Battery.CurrentCapacity * 10000000f; } return(percentDouble.ToString()); }
static public string GetPlayerAntennaStatus(MyObjectBuilder_Character CharacterInfo) { bool BitVal = false; if (CurrentPlayerState == 0) { BitVal = CharacterInfo.EnableBroadcasting; } return(BitVal.ToString()); }
public static MyObjectBuilder_Character FindCharacter(string userName) { HashSet <IMyEntity> entities = new HashSet <IMyEntity>(); Wrapper.GameAction(() => { MyAPIGateway.Entities.GetEntities(entities); }); foreach (IMyEntity entity in entities) { MyObjectBuilder_Character character = null; try { if (entity.GetObjectBuilder() is MyObjectBuilder_Character) { character = (MyObjectBuilder_Character)entity.GetObjectBuilder(); } else { continue; } } catch { continue; } CharacterEntity charEntity = new CharacterEntity(character, entity); if (character.DisplayName.ToLower().Equals(userName.ToLower()) && charEntity.Health > 0f) { return(character); } } /* * This works, but it doesn't do what I wanted (they don't get removed from their current cockpit) * IMyEntity entityCheck = FindControlledEntity(userName); * if (entityCheck != null && entityCheck.GetObjectBuilder() is MyObjectBuilder_CubeGrid) * { * MyObjectBuilder_CubeGrid grid = (MyObjectBuilder_CubeGrid)entityCheck.GetObjectBuilder(); * foreach (MyObjectBuilder_CubeBlock block in grid.CubeBlocks) * { * if(block is MyObjectBuilder_Cockpit) * { * MyObjectBuilder_Cockpit cockpit = (MyObjectBuilder_Cockpit)block; * if (cockpit.Pilot != null && cockpit.Pilot.DisplayName.ToLower().Contains(userName.ToLower())) * return cockpit.Pilot; * } * } * } */ return(null); }
public InventoryEditorModel(MyObjectBuilder_Inventory inventory, float maxVolume, MyObjectBuilder_Character character = null) { _inventory = inventory; _maxVolume = maxVolume; _character = character; UpdateGeneralFromEntityBase(); // Cube.InventorySize.X * CUbe.InventorySize.Y * CUbe.InventorySize.Z * 1000 * Sandbox.InventorySizeMultiplier; // or Cube.InventoryMaxVolume * 1000 * Sandbox.InventorySizeMultiplier; //Character.Inventory = 0.4 * 1000 * Sandbox.InventorySizeMultiplier; }
public static void SendCharacterCreated(MyObjectBuilder_Character character, MyCockpit cockpit) { MySyncCreate.SendEntityCreated(character); AttachToCockpitMsg msg = new AttachToCockpitMsg(); msg.CharacterEntityId = character.EntityId; msg.CockpitEntityId = cockpit.EntityId; Sync.Layer.SendMessageToAll(msg); }
public CharacterEntity(MyObjectBuilder_Character definition, Object backingObject) : base(definition, backingObject) { m_inventory = new InventoryEntity(definition.Inventory, InternalGetCharacterInventory()); EntityEventManager.EntityEvent newEvent = new EntityEventManager.EntityEvent(); newEvent.type = EntityEventManager.EntityEventType.OnCharacterCreated; newEvent.timestamp = DateTime.Now; newEvent.entity = this; newEvent.priority = 1; EntityEventManager.Instance.AddEvent(newEvent); }
public virtual void GetObjectBuilder(MyObjectBuilder_Character characterBuilder) { characterBuilder.DampenersEnabled = DampenersTurnedOn; bool jetpackEnabled = TurnedOn; if (MySession.Static.ControlledEntity is MyCockpit) { jetpackEnabled = (MySession.Static.ControlledEntity as MyCockpit).PilotJetpackEnabledBackup; } characterBuilder.JetpackEnabled = jetpackEnabled; characterBuilder.AutoenableJetpackDelay = CurrentAutoEnableDelay; }
private void TransportPlayer(IMyEntity entity) { if (entity is IMyCharacter) { MyObjectBuilder_Character c = (MyObjectBuilder_Character)entity.GetObjectBuilder(); if (c.Health < 1) { return; } Thread.Sleep(50); BoundingSphereD sphere = new BoundingSphereD(entity.GetTopMostParent().GetPosition(), 300); List <IMyEntity> entities = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere); bool found = false; foreach (IMyEntity testEntity in entities) { if (testEntity == entity) { continue; } found = true; break; } if (found) { return; } MoveEntity(entity); } else if (entity is IMyCubeGrid) { foreach (string name in PluginSettings.Instance.NewUserTransportSpawnShipNames) { if (entity.DisplayName.ToLower().Contains(name.ToLower())) { if (PluginSettings.Instance.DynamicClientConcealEnabled) { //ClientEntityManagement.SyncFix.Add(entity.EntityId, DateTime.Now); } MoveEntity(entity); break; } } } }
static public string GetPlayerSpeed(MyObjectBuilder_Character CharacterInfo) { string StringVal = string.Empty; if (CurrentPlayerState == 0) { float Xvalue = CharacterInfo.LinearVelocity.X; float Yvalue = CharacterInfo.LinearVelocity.Y; float Zvalue = CharacterInfo.LinearVelocity.Z; Vector3 testVector = new Vector3(Xvalue, Yvalue, Zvalue); StringVal = testVector.Length().ToString() + " m/s"; } return(StringVal); }
public void FoundPlayer(long playerIdentityId, MyObjectBuilder_Character character) { var charPosition = character?.PositionAndOrientation?.Position; var playerPosition = new Vector3D(charPosition.Value.x, charPosition.Value.y, charPosition.Value.z); FoundPlayers[playerIdentityId] = new ZoneScanResultItem() { PlayerIdentityId = playerIdentityId, Character = character, DistanceToCenter = Vector3D.Distance(ZoneCenter, playerPosition) }; CharactersFound = FoundPlayers.Count; }
private bool hasPilot() { List <Sandbox.ModAPI.IMySlimBlock> allCockpits = new List <Sandbox.ModAPI.IMySlimBlock>(); myGrid.GetBlocks(allCockpits, block => block.FatBlock != null && block.FatBlock is Ingame.IMyCockpit); foreach (IMySlimBlock cockpit in allCockpits) { MyObjectBuilder_Character pilot = (cockpit.FatBlock.GetObjectBuilderCubeBlock() as MyObjectBuilder_Cockpit).Pilot; if (pilot != null) { if (hasPilot_value != pilot) { log("got a pilot in " + cockpit.FatBlock.DisplayNameText + ", pilot is " + pilot.DisplayName, "hasPilot()", Logger.severity.DEBUG); } hasPilot_value = pilot; return(true); } } hasPilot_value = null; return(false); }
//Add switch case for CurrentPlayerState for each method below in this region only. //If CurrentPlayerState !=0 pass the stashed Player Entity - Needs to be written. static public string GetPlayerHealth(MyObjectBuilder_Character CharacterInfo) { float?percentFloat = null; if (CurrentPlayerState == 0) { if (!CharacterInfo.Health.HasValue) { percentFloat = 100.00f; } else { percentFloat = CharacterInfo.Health.Value; } } else { percentFloat = 666666; } return(percentFloat.ToString()); }
public override void Handle() { if (!PluginSettings.Instance.ServerRespawnMenuOverride) { return; } List <IMyPlayer> players = new List <IMyPlayer>(); MyAPIGateway.Players.GetPlayers(players); foreach (IMyPlayer player in players) { if (player.Controller != null && player.Controller.ControlledEntity != null && player.Controller.ControlledEntity.Entity != null) { IMyEntity entity = player.Controller.ControlledEntity.Entity; if (entity is IMyCharacter) { MyObjectBuilder_Character character = (MyObjectBuilder_Character)entity.GetObjectBuilder(); if (character.Health < 1 && !m_deathTracker.ContainsKey(entity.EntityId)) { m_deathTracker.Add(entity.EntityId, DateTime.Now); Logging.WriteLineAndConsole(string.Format("Found a dead character")); } else if (character.Health < 1 && m_deathTracker.ContainsKey(entity.EntityId) && !m_respawnShown.Contains(entity.EntityId) && (DateTime.Now - m_deathTracker[entity.EntityId]).TotalSeconds > 3) { m_respawnShown.Add(entity.EntityId); Wrapper.GameAction(() => { ServerNetworkManager.ShowRespawnMenu(player.SteamUserId); }); } } } } base.Handle(); }
public override bool OnSave(BitStream stream) { stream.WriteBool(Instance.IsUsing is MyShipController); if (Instance.IsUsing is MyShipController) { long ownerId = Instance.IsUsing.EntityId; VRage.Serialization.MySerializer.Write(stream, ref ownerId); long characterId = Instance.EntityId; VRage.Serialization.MySerializer.Write(stream, ref characterId); } else { MyObjectBuilder_Character builder = (MyObjectBuilder_Character)Instance.GetObjectBuilder(); Vector3 velocity = builder.LinearVelocity; velocity *= MyEntityPhysicsStateGroup.EffectiveSimulationRatio; builder.LinearVelocity = velocity; VRage.Serialization.MySerializer.Write(stream, ref builder, MyObjectBuilderSerializer.Dynamic); } return(true); }
void SpawnSimpleSkinnedObject() { var skin = new MySkinnedEntity(); MyObjectBuilder_Character ob = new MyObjectBuilder_Character(); ob.PositionAndOrientation = new VRage.MyPositionAndOrientation(MySector.MainCamera.Position + 2 * MySector.MainCamera.ForwardVector, MySector.MainCamera.ForwardVector, MySector.MainCamera.UpVector); skin.Init(null, @"Models\Characters\Basic\ME_barbar.mwm", null, null); skin.Init(ob); MyEntities.Add(skin); var command = new MyAnimationCommand() { AnimationSubtypeName = "IdleBarbar", FrameOption = MyFrameOption.Loop, TimeScale = 1 }; skin.AddCommand(command); m_skins.Add(skin); }
public virtual void GetObjectBuilder(MyObjectBuilder_Character objectBuilder) { objectBuilder.OxygenLevel = this.SuitOxygenLevel; objectBuilder.EnvironmentOxygenLevel = base.Character.EnvironmentOxygenLevel; objectBuilder.NeedsOxygenFromSuit = this.NeedsOxygenFromSuit; if ((this.m_storedGases != null) && (this.m_storedGases.Length != 0)) { if (objectBuilder.StoredGases == null) { objectBuilder.StoredGases = new List <MyObjectBuilder_Character.StoredGas>(); } foreach (GasData storedGas in this.m_storedGases) { if (objectBuilder.StoredGases.TrueForAll(obGas => obGas.Id != storedGas.Id)) { MyObjectBuilder_Character.StoredGas item = new MyObjectBuilder_Character.StoredGas { Id = (SerializableDefinitionId)storedGas.Id, FillLevel = storedGas.FillLevel }; objectBuilder.StoredGases.Add(item); } } } }
public virtual void Init(MyObjectBuilder_Character characterOb) { m_lastOxygenUpdateTime = MySession.Static.GameplayFrameCounter; m_gasIdToIndex = new Dictionary<MyDefinitionId, int>(); if (MyFakes.ENABLE_HYDROGEN_FUEL && Definition.SuitResourceStorage != null) { m_storedGases = new GasData[Definition.SuitResourceStorage.Count]; for(int gasIndex = 0; gasIndex < m_storedGases.Length; ++gasIndex) { var gasInfo = Definition.SuitResourceStorage[gasIndex]; m_storedGases[gasIndex] = new GasData { Id = gasInfo.Id, FillLevel = 1f, MaxCapacity = gasInfo.MaxCapacity, Throughput = gasInfo.Throughput, LastOutputTime = MySession.Static.GameplayFrameCounter, LastInputTime = MySession.Static.GameplayFrameCounter }; m_gasIdToIndex.Add(gasInfo.Id, gasIndex); } if (characterOb.StoredGases != null) { if (!MySession.Static.CreativeMode) { foreach (var gasInfo in characterOb.StoredGases) { int gasIndex; if (!m_gasIdToIndex.TryGetValue(gasInfo.Id, out gasIndex)) continue; m_storedGases[gasIndex].FillLevel = gasInfo.FillLevel; } } } } if(m_storedGases == null) m_storedGases = new GasData[0]; Debug.Assert(ContainsGasStorage(OxygenId), characterOb.SubtypeName + " is missing Oxygen resource."); Debug.Assert(ContainsGasStorage(HydrogenId), characterOb.SubtypeName + " is missing Hydrogen resource."); if (MySession.Static.Settings.EnableOxygen) { float oxygenFillLevel = GetGasFillLevel(OxygenId); m_oldSuitOxygenLevel = oxygenFillLevel == 0f ? OxygenCapacity : oxygenFillLevel; } EnvironmentOxygenLevel = characterOb.EnvironmentOxygenLevel; m_oxygenBottleRefillNotification = new MyHudNotification(text: MySpaceTexts.NotificationBottleRefill, level: MyNotificationLevel.Important); m_gasBottleRefillNotification = new MyHudNotification(text: MySpaceTexts.NotificationGasBottleRefill, level: MyNotificationLevel.Important); m_lowOxygenNotification = new MyHudNotification(text: MySpaceTexts.NotificationOxygenLow, font: MyFontEnum.Red, level: MyNotificationLevel.Important); m_criticalOxygenNotification = new MyHudNotification(text: MySpaceTexts.NotificationOxygenCritical, font: MyFontEnum.Red, level: MyNotificationLevel.Important); m_helmetToggleNotification = m_helmetToggleNotification ?? new MyHudNotification(); // Init() is called when toggling helmet so this check is required m_needsOxygen = Definition.NeedsOxygen; NeedsUpdateBeforeSimulation = true; NeedsUpdateBeforeSimulation100 = true; }
public static bool Move(string userName, Vector3D position) { //CharacterEntity charEntity = SectorObjectManager.Instance.GetTypedInternalData<CharacterEntity>().FirstOrDefault(x => x.DisplayName.ToLower() == userName.ToLower() && x.Health > 0); MyObjectBuilder_Character charEntity = FindCharacter(userName); if (charEntity == null) { Essentials.Log.Info(string.Format("Unable to find CharacterEntity of '{0}'", userName)); return(false); } CubeGridEntity gridEntity = new CubeGridEntity(new FileInfo(Essentials.PluginPath + "MovePlayer.sbc")); gridEntity.EntityId = BaseEntity.GenerateEntityId(); foreach (MyObjectBuilder_CubeBlock block in gridEntity.BaseCubeBlocks) { // set ownership MyObjectBuilder_Cockpit cockpit = block as MyObjectBuilder_Cockpit; if (cockpit != null) { cockpit.Pilot = charEntity; } } gridEntity.PositionAndOrientation = new MyPositionAndOrientation(position, Vector3.Forward, Vector3.Up); Wrapper.GameAction(() => { MyObjectBuilder_EntityBase baseEntity = gridEntity.Export(); MyAPIGateway.Entities.RemapObjectBuilder(baseEntity); IMyEntity entity = MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd(baseEntity); Type someManager = SandboxGameAssemblyWrapper.Instance.GetAssemblyType(SectorObjectManager.EntityBaseNetManagerNamespace, SectorObjectManager.EntityBaseNetManagerClass); Wrapper.InvokeStaticMethod(someManager, SectorObjectManager.EntityBaseNetManagerSendEntity, new object[] { entity.GetObjectBuilder() }); gridEntity = new CubeGridEntity((MyObjectBuilder_CubeGrid)entity.GetObjectBuilder(), entity); MyMultiplayer.ReplicateImmediatelly(MyExternalReplicable.FindByObject(entity)); }); DateTime _loadTime = DateTime.Now; while (gridEntity.IsLoading) { if (DateTime.Now - _loadTime > TimeSpan.FromSeconds(20)) { break; } } if (gridEntity.IsLoading) { Essentials.Log.Info("Failed to load cockpit entity: {0}", gridEntity.EntityId); return(false); } foreach (CubeBlockEntity block in gridEntity.CubeBlocks) { if (block is CockpitEntity) { block.IntegrityPercent = 0.1f; } } gridEntity.Dispose(); MyMultiplayer.ReplicateImmediatelly(MyExternalReplicable.FindByObject(gridEntity)); return(true); }
public void Go() { Players.Clear(); MyAPIGateway.Players.GetPlayers(Players); foreach (IMyPlayer p in Players) { if (p.IsBot) { continue; } IMyEntity entity = p.Controller.ControlledEntity.Entity; entity = Utilities.GetCharacterEntity(entity); PoopPlayer pp; if (Poopers.ContainsKey(p.IdentityId)) { pp = Poopers[p.IdentityId]; } else { pp = new PoopPlayer() { PoopAmount = 0, Player = p }; Poopers.Add(p.IdentityId, pp); } float amount = MyUtils.GetRandomFloat(Config.Instance.PoopAmountPerSecondMin, Config.Instance.PoopAmountPerSecondMax); bool toilet = false; character = p.Character.GetObjectBuilder(false) as MyObjectBuilder_Character; switch (character.MovementState) { case MyCharacterMovementEnum.Sitting: IMyCubeBlock cb = p.Controller.ControlledEntity.Entity as IMyCubeBlock; String seatmodel = cb.DefinitionDisplayNameText.ToLower(); if (seatmodel.Contains("toilet")) { amount *= Config.Instance.PoopMultiplierToilet; toilet = true; } else { amount *= Config.Instance.PoopMultiplierSit; } break; case MyCharacterMovementEnum.Flying: case MyCharacterMovementEnum.Falling: amount *= Config.Instance.PoopMultiplierFly; break; case MyCharacterMovementEnum.Crouching: case MyCharacterMovementEnum.CrouchRotatingRight: case MyCharacterMovementEnum.CrouchRotatingLeft: case MyCharacterMovementEnum.CrouchWalking: case MyCharacterMovementEnum.CrouchBackWalking: case MyCharacterMovementEnum.CrouchStrafingLeft: case MyCharacterMovementEnum.CrouchStrafingRight: case MyCharacterMovementEnum.CrouchWalkingRightFront: case MyCharacterMovementEnum.CrouchWalkingRightBack: case MyCharacterMovementEnum.CrouchWalkingLeftFront: case MyCharacterMovementEnum.CrouchWalkingLeftBack: amount *= Config.Instance.PoopMultiplierCrouch; break; case MyCharacterMovementEnum.Walking: case MyCharacterMovementEnum.BackWalking: case MyCharacterMovementEnum.WalkStrafingLeft: case MyCharacterMovementEnum.WalkStrafingRight: case MyCharacterMovementEnum.WalkingRightFront: case MyCharacterMovementEnum.WalkingRightBack: case MyCharacterMovementEnum.WalkingLeftFront: case MyCharacterMovementEnum.WalkingLeftBack: amount *= Config.Instance.PoopMultiplierWalk; break; case MyCharacterMovementEnum.Running: case MyCharacterMovementEnum.Backrunning: case MyCharacterMovementEnum.RunStrafingLeft: case MyCharacterMovementEnum.RunStrafingRight: case MyCharacterMovementEnum.RunningRightFront: case MyCharacterMovementEnum.RunningRightBack: case MyCharacterMovementEnum.RunningLeftBack: case MyCharacterMovementEnum.RunningLeftFront: case MyCharacterMovementEnum.Sprinting: case MyCharacterMovementEnum.Jump: amount *= Config.Instance.PoopMultiplierSprint; break; case MyCharacterMovementEnum.Died: amount = 0f; break; } pp.PoopAmount += (float)Math.Round(amount, 3); //MyLog.Default.WriteLine("Biogas: Added " + amount + " to " + p.DisplayName + " -> " + pp.PoopAmount); if ((toilet && pp.PoopAmount >= 0.1f) || MyUtils.GetRandomFloat(0, 1) <= Config.Instance.PoopChancePerSecond || pp.PoopAmount >= Config.Instance.PoopAlwaysAt) { IMyInventory inventory = entity.GetInventory(); inventory.AddItems((VRage.MyFixedPoint)Math.Round(pp.PoopAmount, 3), new MyObjectBuilder_Ore() { SubtypeName = "Organic" }); pp.PoopAmount = 0; //MyLog.Default.WriteLine("Biogas: " + p.DisplayName + " pooped"); if (Config.Instance.PoopSounds) { MyVisualScriptLogicProvider.PlaySingleSoundAtPosition("Fart" + MyUtils.GetRandomInt(0, 5), p.GetPosition()); } } } }
private void InitInventory(MyObjectBuilder_Character characterOb) { bool inventoryAlreadyExists = this.GetInventory() != null; if (!inventoryAlreadyExists) { if (m_characterDefinition.InventoryDefinition == null) { m_characterDefinition.InventoryDefinition = new MyObjectBuilder_InventoryDefinition(); } Components.Add<MyInventoryBase>(new MyInventory(m_characterDefinition.InventoryDefinition, 0, this)); var currentInventory = this.GetInventory(); currentInventory.Init(characterOb.Inventory); Debug.Assert(currentInventory.Owner == this, "Inventory ownership was not set!"); MyCubeBuilder.BuildComponent.AfterCharacterCreate(this); if (MyFakes.ENABLE_MEDIEVAL_INVENTORY && InventoryAggregate != null) { var internalAggregate = InventoryAggregate.GetInventory(MyStringHash.GetOrCompute("Internal")) as MyInventoryAggregate; if (internalAggregate != null) { internalAggregate.AddComponent(currentInventory); } else { InventoryAggregate.AddComponent(currentInventory); } } } this.GetInventory().ContentsChanged += inventory_OnContentsChanged; this.GetInventory().BeforeContentsChanged += inventory_OnBeforeContentsChanged; this.GetInventory().BeforeRemovedFromContainer += inventory_OnRemovedFromContainer; }
public virtual void GetObjectBuilder(MyObjectBuilder_Character objectBuilder) { objectBuilder.OxygenLevel = SuitOxygenLevel; objectBuilder.EnvironmentOxygenLevel = EnvironmentOxygenLevel; objectBuilder.NeedsOxygenFromSuit = NeedsOxygenFromSuit; if (m_storedGases != null && m_storedGases.Length > 0) { if(objectBuilder.StoredGases == null) objectBuilder.StoredGases = new List<MyObjectBuilder_Character.StoredGas>(); foreach (var storedGas in m_storedGases) { if (!objectBuilder.StoredGases.TrueForAll((obGas) => obGas.Id != storedGas.Id)) continue; objectBuilder.StoredGases.Add(new MyObjectBuilder_Character.StoredGas { Id = storedGas.Id, FillLevel = storedGas.FillLevel }); } } }
public void ClearPilotAndAutopilot() { Pilot = null; Autopilot = null; AttachedPlayerId = null; }
void SpawnSimpleSkinnedObject() { var skin = new MySkinnedEntity(); MyObjectBuilder_Character ob = new MyObjectBuilder_Character(); ob.EntityDefinitionId = new SerializableDefinitionId(typeof(MyObjectBuilder_Character), "Medieval_barbarian"); ob.PositionAndOrientation = new VRage.MyPositionAndOrientation(MySector.MainCamera.Position + 2 * MySector.MainCamera.ForwardVector, MySector.MainCamera.ForwardVector, MySector.MainCamera.UpVector); skin.Init(null, @"Models\Characters\Basic\ME_barbar.mwm", null, null); skin.Init(ob); MyEntities.Add(skin); var command = new MyAnimationCommand() { AnimationSubtypeName = "IdleBarbar", FrameOption = MyFrameOption.Loop, TimeScale = 1 }; skin.AddCommand(command); m_skins.Add(skin); }
public virtual void GetObjectBuilder(MyObjectBuilder_Character characterBuilder) { characterBuilder.DampenersEnabled = DampenersTurnedOn; bool jetpackEnabled = TurnedOn; if (MySession.Static.ControlledEntity is MyCockpit) { jetpackEnabled = (MySession.Static.ControlledEntity as MyCockpit).PilotJetpackEnabledBackup; } characterBuilder.JetpackEnabled = jetpackEnabled; characterBuilder.AutoenableJetpackDelay = CurrentAutoEnableDelay; }
public virtual void Init(MyObjectBuilder_Character characterOb) { string str; string str2; this.m_lastOxygenUpdateTime = MySession.Static.GameplayFrameCounter; this.m_gasIdToIndex = new Dictionary <MyDefinitionId, int>(); if (MyFakes.ENABLE_HYDROGEN_FUEL && (this.Definition.SuitResourceStorage != null)) { this.m_storedGases = new GasData[this.Definition.SuitResourceStorage.Count]; int index = 0; while (true) { if (index >= this.m_storedGases.Length) { if ((characterOb.StoredGases != null) && !MySession.Static.CreativeMode) { foreach (MyObjectBuilder_Character.StoredGas gas in characterOb.StoredGases) { int num2; if (this.m_gasIdToIndex.TryGetValue(gas.Id, out num2)) { this.m_storedGases[num2].FillLevel = gas.FillLevel; } } } break; } SuitResourceDefinition definition = this.Definition.SuitResourceStorage[index]; GasData data1 = new GasData(); data1.Id = definition.Id; data1.FillLevel = 1f; data1.MaxCapacity = definition.MaxCapacity; data1.Throughput = definition.Throughput; data1.LastOutputTime = MySession.Static.GameplayFrameCounter; data1.LastInputTime = MySession.Static.GameplayFrameCounter; this.m_storedGases[index] = data1; this.m_gasIdToIndex.Add(definition.Id, index); index++; } } if (this.m_storedGases == null) { this.m_storedGases = new GasData[0]; } if (MySession.Static.Settings.EnableOxygen) { float gasFillLevel = this.GetGasFillLevel(OxygenId); this.m_oldSuitOxygenLevel = (gasFillLevel == 0f) ? this.OxygenCapacity : gasFillLevel; } if (Sync.IsServer) { base.Character.EnvironmentOxygenLevelSync.Value = characterOb.EnvironmentOxygenLevel; base.Character.OxygenLevelAtCharacterLocation.Value = 0f; } base.Character.Definition.AnimationNameToSubtypeName.TryGetValue("HelmetOpen", out str); base.Character.Definition.AnimationNameToSubtypeName.TryGetValue("HelmetClose", out str2); if (((str == null) || (str2 == null)) && (!base.Character.UseNewAnimationSystem || (base.Character.AnimationController.Controller.GetLayerByName("Helmet") == null))) { this.NeedsOxygenFromSuit = this.Definition.NeedsOxygen; } else { this.NeedsOxygenFromSuit = characterOb.NeedsOxygenFromSuit; } base.NeedsUpdateBeforeSimulation = true; base.NeedsUpdateBeforeSimulation100 = true; if (this.m_soundEmitter == null) { this.m_soundEmitter = new MyEntity3DSoundEmitter(base.Character, false, 1f); } if (!this.HelmetEnabled) { this.AnimateHelmet(); } }
public static void GetModelAndDefinition(MyObjectBuilder_Character characterOb, out string characterModel, out MyCharacterDefinition characterDefinition, ref Vector3 colorMask) { characterModel = GetRealModel(characterOb.CharacterModel, ref colorMask); characterDefinition = null; if (!MyDefinitionManager.Static.Characters.TryGetValue(characterModel, out characterDefinition)) { //System.Diagnostics.Debug.Fail("Character model " + m_characterModel + " not found!"); characterDefinition = MyDefinitionManager.Static.Characters.First(); characterModel = characterDefinition.Model; } }
/// <summary> /// Removes all sign of a pilot/characrter from a cockpit cube. /// </summary> /// <param name="cockpit">The specific cube.</param> /// <param name="character">Specific character to remove, if required, otherwise ANY chararcter will be removed.</param> /// <returns>Returns true if a character was removed.</returns> public static bool RemoveHierarchyCharacter(this MyObjectBuilder_Cockpit cockpit, MyObjectBuilder_Character character = null) { bool retValue = false; MyObjectBuilder_ComponentContainer.ComponentData hierarchyComponentBase = cockpit.ComponentContainer?.Components?.FirstOrDefault(e => e.TypeId == "MyHierarchyComponentBase"); var hierarchyBase = hierarchyComponentBase?.Component as MyObjectBuilder_HierarchyComponentBase; if (hierarchyBase != null && hierarchyBase.Children.Count > 0) { for (int i = 0; i < hierarchyBase.Children.Count; i++) { if (character != null && hierarchyBase.Children[i] == character) { retValue = true; hierarchyBase.Children.RemoveAt(i); i--; break; } if (character == null && hierarchyBase.Children[i] is MyObjectBuilder_Character) { retValue = true; hierarchyBase.Children.RemoveAt(i); i--; } } if (hierarchyBase.Children.Count == 0) { cockpit.ComponentContainer.Components.Remove(hierarchyComponentBase); } } if (retValue) { cockpit.ClearPilotAndAutopilot(); cockpit.PilotRelativeWorld = null; // This should also clear Pilot. cockpit.Pilot = null; } return(retValue); }
private void InitInventory(MyObjectBuilder_Character characterOb) { bool inventoryAlreadyExists = this.GetInventory() != null; if (!inventoryAlreadyExists) { if (m_characterDefinition.InventoryDefinition == null) { m_characterDefinition.InventoryDefinition = new MyObjectBuilder_InventoryDefinition(); } MyInventory currentInventory = new MyInventory(m_characterDefinition.InventoryDefinition, 0); // CH: This is very ugly, but it is caused by the fact that we don't have proper inventory definitions // and I didn't want to add max item count to inventory constructors currentInventory.Init(null); if (InventoryAggregate != null) { InventoryAggregate.AddComponent(currentInventory); } else { Components.Add<MyInventoryBase>(currentInventory); } currentInventory.Init(characterOb.Inventory); Debug.Assert(currentInventory.Owner == this, "Inventory ownership was not set!"); // Creates the aggregate inventory MyCubeBuilder.BuildComponent.AfterCharacterCreate(this); if (MyFakes.ENABLE_MEDIEVAL_INVENTORY && InventoryAggregate != null) { var internalAggregate = InventoryAggregate.GetInventory(MyStringHash.GetOrCompute("Internal")) as MyInventoryAggregate; if (internalAggregate != null) { internalAggregate.AddComponent(currentInventory); } else { InventoryAggregate.AddComponent(currentInventory); } } } else if (MyPerGameSettings.ConstrainInventory()) { MyInventory inventory = this.GetInventory(); inventory.FixInventoryVolume(m_characterDefinition.InventoryDefinition.InventoryVolume); } this.GetInventory().ContentsChanged += inventory_OnContentsChanged; this.GetInventory().BeforeContentsChanged += inventory_OnBeforeContentsChanged; this.GetInventory().BeforeRemovedFromContainer += inventory_OnRemovedFromContainer; }
public virtual void Init(MyObjectBuilder_Character characterOb) { m_lastOxygenUpdateTime = MySession.Static.GameplayFrameCounter; m_gasIdToIndex = new Dictionary<MyDefinitionId, int>(); if (MyFakes.ENABLE_HYDROGEN_FUEL && Definition.SuitResourceStorage != null) { m_storedGases = new GasData[Definition.SuitResourceStorage.Count]; for(int gasIndex = 0; gasIndex < m_storedGases.Length; ++gasIndex) { var gasInfo = Definition.SuitResourceStorage[gasIndex]; m_storedGases[gasIndex] = new GasData { Id = gasInfo.Id, FillLevel = 1f, MaxCapacity = gasInfo.MaxCapacity, Throughput = gasInfo.Throughput, LastOutputTime = MySession.Static.GameplayFrameCounter, LastInputTime = MySession.Static.GameplayFrameCounter }; m_gasIdToIndex.Add(gasInfo.Id, gasIndex); } if (characterOb.StoredGases != null) { if (!MySession.Static.CreativeMode) { foreach (var gasInfo in characterOb.StoredGases) { int gasIndex; if (!m_gasIdToIndex.TryGetValue(gasInfo.Id, out gasIndex)) continue; m_storedGases[gasIndex].FillLevel = gasInfo.FillLevel; } } } } if(m_storedGases == null) m_storedGases = new GasData[0]; Debug.Assert(ContainsGasStorage(OxygenId), characterOb.SubtypeName + " is missing Oxygen resource."); Debug.Assert(ContainsGasStorage(HydrogenId), characterOb.SubtypeName + " is missing Hydrogen resource."); if (MySession.Static.Settings.EnableOxygen) { float oxygenFillLevel = GetGasFillLevel(OxygenId); m_oldSuitOxygenLevel = oxygenFillLevel == 0f ? OxygenCapacity : oxygenFillLevel; } EnvironmentOxygenLevel = characterOb.EnvironmentOxygenLevel; OxygenLevelAtCharacterLocation = 0f; m_oxygenBottleRefillNotification = new MyHudNotification(text: MySpaceTexts.NotificationBottleRefill, level: MyNotificationLevel.Important); m_gasBottleRefillNotification = new MyHudNotification(text: MySpaceTexts.NotificationGasBottleRefill, level: MyNotificationLevel.Important); m_lowOxygenNotification = new MyHudNotification(text: MySpaceTexts.NotificationOxygenLow, font: MyFontEnum.Red, level: MyNotificationLevel.Important); m_criticalOxygenNotification = new MyHudNotification(text: MySpaceTexts.NotificationOxygenCritical, font: MyFontEnum.Red, level: MyNotificationLevel.Important); m_helmetToggleNotification = m_helmetToggleNotification ?? new MyHudNotification(); // Init() is called when toggling helmet so this check is required // todo: this should be independent on animation/layer names string animationOpenHelmet; string animationCloseHelmet; Character.Definition.AnimationNameToSubtypeName.TryGetValue("HelmetOpen", out animationOpenHelmet); Character.Definition.AnimationNameToSubtypeName.TryGetValue("HelmetClose", out animationCloseHelmet); if ((animationOpenHelmet != null && animationCloseHelmet != null) || (Character.UseNewAnimationSystem && Character.AnimationController.Controller.GetLayerByName("Helmet") != null)) { NeedsOxygenFromSuit = characterOb.NeedsOxygenFromSuit; } else { NeedsOxygenFromSuit = Definition.NeedsOxygen; // compatibility } NeedsUpdateBeforeSimulation = true; NeedsUpdateBeforeSimulation100 = true; if (m_soundEmitter == null) m_soundEmitter = new MyEntity3DSoundEmitter(Character); if (!HelmetEnabled) // default state == helmet is enabled AnimateHelmet(); }
public static void RemoveHierarchyCharacter(this MyObjectBuilder_CubeBlock cube, MyObjectBuilder_Character character) { if (character == null) { return; } MyObjectBuilder_Cockpit cockpit = cube as MyObjectBuilder_Cockpit; var hierarchyBase = cockpit?.ComponentContainer.Components.FirstOrDefault(e => e.TypeId == "MyHierarchyComponentBase")?.Component as MyObjectBuilder_HierarchyComponentBase; if (hierarchyBase != null) { for (int i = 0; i < hierarchyBase.Children.Count; i++) { if (hierarchyBase.Children[i] == character) { hierarchyBase.Children.RemoveAt(i); return; } } } }
public virtual void GetObjectBuilder(MyObjectBuilder_Character characterBuilder) { characterBuilder.DampenersEnabled = DampenersTurnedOn; characterBuilder.JetpackEnabled = TurnedOn; characterBuilder.AutoenableJetpackDelay = CurrentAutoEnableDelay; }