public override void Update() { base.Update(); MyCharacterStatComponent statComponent = null; if (MySession.LocalCharacter != null) { statComponent = MySession.LocalCharacter.StatComp; } if (statComponent != m_statComponent) { m_statComponent = statComponent; m_sortedStats.Clear(); if (m_statComponent != null) { foreach (var stat in m_statComponent.Stats) { m_sortedStats.Add(stat); } m_sortedStats.Sort((leftStat, rightStat) => { return(rightStat.StatDefinition.GuiDef.Priority - leftStat.StatDefinition.GuiDef.Priority); }); } RecreateControls(); } }
public override void Update() { base.Update(); MyCharacterStatComponent statComponent = null; if (MySession.Static.LocalCharacter != null) { statComponent = MySession.Static.LocalCharacter.StatComp; } if (statComponent != null && statComponent != m_statComponent && statComponent.Stats.Count > 0) // statComponent can be changed during the update, however, it may not be filled up with stats yet in that time.. { m_statComponent = statComponent; m_sortedStats.Clear(); if (m_statComponent != null) { foreach (var stat in m_statComponent.Stats) { m_sortedStats.Add(stat); } m_sortedStats.Sort((leftStat, rightStat) => { return(rightStat.StatDefinition.GuiDef.Priority - leftStat.StatDefinition.GuiDef.Priority); }); } RecreateControls(); } }
private void InventoryConsumeItem_Implementation(MyFixedPoint amount, SerializableDefinitionId itemId, long consumerEntityId) { if ((consumerEntityId == 0) || MyEntities.EntityExists(consumerEntityId)) { MyFixedPoint point = this.GetItemAmount(itemId, MyItemFlags.None, false); if (point < amount) { amount = point; } MyEntity entityById = null; if (consumerEntityId != 0) { entityById = MyEntities.GetEntityById(consumerEntityId, false); if (entityById == null) { return; } } if (entityById.Components != null) { MyUsableItemDefinition definition = MyDefinitionManager.Static.GetDefinition(itemId) as MyUsableItemDefinition; if (definition != null) { MyCharacter character = entityById as MyCharacter; if (character != null) { character.SoundComp.StartSecondarySound(definition.UseSound, true); } MyConsumableItemDefinition definition2 = definition as MyConsumableItemDefinition; if (definition2 != null) { MyCharacterStatComponent component = entityById.Components.Get <MyEntityStatComponent>() as MyCharacterStatComponent; if (component != null) { component.Consume(amount, definition2); } } } } if (1 != 0) { this.RemoveItemsOfType(amount, itemId, MyItemFlags.None, false); } } }