public override void OnAddedToScene() { base.OnAddedToScene(); if (_definition == null) { return; } _inventory = this.Get <MyInventoryBase>(_definition.Inventory) ?? this.Get <MyInventoryBase>(); MrzUtils.ShowNotificationDebug($"InvInteraction::Inventory {_inventory}"); var useObjComp = this.Get <MyUseObjectsComponentBase>(); if (useObjComp == null) { return; } var useObject = useObjComp.GetInteractiveObject("Generic"); _useObj = useObject as MyUseObjectGeneric; if (_useObj == null) { return; } _useObj.Interface = this; }
private void SwapItems(MyDefinitionId input, MyDefinitionId output, int amount) { MrzUtils.ShowNotificationDebug($"Swapping {amount}x {input} for {amount}x {output}."); if (_inventory.RemoveItems(input, amount)) { _inventory.AddItemsFuzzy(output, amount); } }
private void RequestInventoryInteraction(long entityId, bool insertion = true) { if (insertion && _definition.InteractionMode == InventoryInteractionMode.Output) { return; } if (!insertion && _definition.InteractionMode == InventoryInteractionMode.Input) { return; } MyEntity user; MyEntities.TryGetEntityById(entityId, out user); var userInv = user?.Get <MyInventoryBase>(MyCharacterConstants.MainInventory); if (userInv == null || _inventory == null) { return; } var from = insertion ? userInv : _inventory; var to = insertion ? _inventory : userInv; if (_definition.StartSearchFrom == InventorySearchStart.Front) { for (var i = 0; i < from.Items.Count; i++) { var item = from.Items.ItemAt(i); if (to.CanAddItems(item.DefinitionId, item.Amount) && to.TransferItemsFrom(from, item, item.Amount)) { MrzUtils.ShowNotificationDebug($"InvInteraction::Transferred {item} from {from} to {to}."); MyAPIGateway.Multiplayer.RaiseEvent(this, x => NotifyInventoryInteractionSuccess, entityId, (SerializableDefinitionId)item.DefinitionId, item.Amount); return; } } } else { for (var i = from.Items.Count - 1; i >= 0; i--) { var item = from.Items.ItemAt(i); if (to.CanAddItems(item.DefinitionId, item.Amount) && to.TransferItemsFrom(from, item, item.Amount)) { MrzUtils.ShowNotificationDebug($"InvInteraction::Transferred {item} from {from} to {to}."); MyAPIGateway.Multiplayer.RaiseEvent(this, x => NotifyInventoryInteractionSuccess, entityId, (SerializableDefinitionId)item.DefinitionId, item.Amount); return; } } } MyAPIGateway.Multiplayer.RaiseEvent(this, x => NotifyInventoryInteractionFailure, entityId); }
protected override bool Start(MyHandItemActionEnum action) { MrzUtils.ShowNotificationDebug($"AddItems::{_holdersInventory}"); if (action != MyHandItemActionEnum.Primary || _holdersInventory == null) { return(false); } return(true); }
protected override void Hit() { if (Target.Entity == null || !(Target.Entity is MyVoxelBase)) { return; } MrzUtils.ShowNotificationDebug($"VoxelPainter::Hit {Target.Entity}"); try { var voxelBase = Target.Entity as MyVoxelBase; voxelBase = voxelBase.RootVoxel; // getting the planet if (voxelBase.MarkedForClose) { return; } MyVoxelMaterialDefinition voxelMaterial = GetVoxelMaterial(voxelBase, Target.Position); MyVoxelMiningDefinition.MiningEntry miningDef; if (voxelMaterial != null && _mining.MiningEntries.TryGetValue(voxelMaterial.Index, out miningDef)) { UpdateDurability(-1); Vector3 pos; CalculateCoords(voxelBase, Target.Position, out pos); MrzUtils.ShowNotificationDebug($"VoxelPainter::Request Paint - Position:{Target.Position} Radius:{Definition.PaintRadius} Material:{_fillMaterial}", 1000); if (MrzUtils.IsServer) { var plane = new Plane(pos, Target.Normal); plane.D = Definition.PaintDepth; DoOperationServer(voxelBase, pos, Definition.PaintRadius, plane); } //MyAPIGateway.Multiplayer.RaiseStaticEvent(x => DoOperationServer, OperationServer.CreateCut( // Holder.EntityId, voxelBase.EntityId, pos, Modified //)); } else { if (Holder == MySession.Static.PlayerEntity) { _wrongToolMessage.Show(); } } } catch (Exception e) { MrzUtils.ShowNotificationDebug(e.Message); } }
private void TrySpawnEquipment(long deltaFrames) { _spawned = true; MrzUtils.ShowNotificationDebug($"TrySpawnEquipment::{Entity.EntityId}"); var inventory = this.Get <MyInventoryBase>(_definition.Inventory) ?? this.Get <MyInventoryBase>(); if (inventory == null) { return; } MrzUtils.ShowNotificationDebug($"TrySpawnEquipment::Inventory {_definition.Inventory}"); var loot = MyDefinitionManager.Get <MyLootTableDefinition>(_definition.LootTable); if (loot == null) { return; } MrzUtils.ShowNotificationDebug($"TrySpawnEquipment::Loot table {_definition.LootTable}"); var oldItems = inventory.Items.ToList <MyInventoryItem>(); MrzUtils.ShowNotificationDebug($"TrySpawnEquipment::Old count:{oldItems.Count}"); inventory.GenerateContent(loot); var newItems = inventory.Items; MrzUtils.ShowNotificationDebug($"TrySpawnEquipment::New count:{newItems.Count}"); for (var i = 0; i < newItems.Count; i++) { var newItem = newItems.ItemAt(i); if (i >= oldItems.Count) { MrzUtils.ShowNotificationDebug($"TrySpawnEquipment::Activating {newItem.DefinitionId}"); MyItemActivateHelper.ActivateItem(Entity, inventory, newItem); continue; } var oldItem = oldItems[i]; if (newItem.Amount > oldItem.Amount) { MrzUtils.ShowNotificationDebug($"TrySpawnEquipment::Activating {newItem.DefinitionId}"); MyItemActivateHelper.ActivateItem(Entity, inventory, newItem); } } }
public override void Init(MyEntityComponentDefinition definition) { base.Init(definition); _definition = definition as MrzInventoryInteractionComponentDefinition; if (_definition == null) { return; } _interactionMessage = _definition.InteractionMessage; MrzUtils.ShowNotificationDebug($"InvInteraction::IsServer = {MrzUtils.IsServer}", 500); _successNotification = MrzUtils.CreateNotification(MyTexts.GetString(_definition.SuccessNotification)); _failureNotification = MrzUtils.CreateNotification(MyTexts.GetString(_definition.FailureNotification), MrzUtils.NotificationType.Error); }
public override void Init(MyEntity holder, MyHandItem item, MyHandItemBehaviorDefinition definition) { base.Init(holder, item, definition); var def = (MrzVoxelPainterBehaviorDefinition)definition; _mining = MyDefinitionManager.Get <MyVoxelMiningDefinition>(def.Mining); for (var i = 0; i < _filter.Length; i++) { _filter[i] = _mining.MiningEntries.ContainsKey(i); } var material = MyDefinitionManager.Get <MyVoxelMaterialDefinition>(def.PaintMaterial); _fillMaterial = material?.Index ?? (byte)0; _inventory = holder.Get <MyInventoryBase>(MyCharacterConstants.MainInventory); _wrongToolMessage = MrzUtils.CreateNotification(string.Format(def.WrongToolMessage, Item.GetDefinition().DisplayNameText), MrzUtils.NotificationType.Error); }
protected override void Hit() { try { MrzUtils.ShowNotificationDebug("AddItems::AddItemsFuzzyOrLoot"); if (_holdersInventory != null && _holdersInventory.AddItemsFuzzyOrLoot(Definition.IdToAdd, Definition.AmountToAdd)) { UpdateDurability(-1); } else if (Holder == MySession.Static.PlayerEntity) { InventoryFullNotification.Show(); } } catch (Exception e) { MrzUtils.ShowNotificationDebug(e.Message); } }
public void Use(string dummyName, UseActionEnum actionEnum, MyEntity user) { MrzUtils.ShowNotificationDebug("InvInteraction::Use", 200); if (!actionEnum.HasFlags(actionEnum)) { return; } if (MrzUtils.IsServer) { MrzUtils.ShowNotificationDebug("InvInteraction::Server-side Use", 200); RequestInventoryInteraction(user.EntityId, !MyAPIGateway.Input.IsAnyShiftKeyDown()); } else { MrzUtils.ShowNotificationDebug("InvInteraction::Client-side Use", 200); MyAPIGateway.Multiplayer.RaiseEvent(this, x => RequestInventoryInteraction, user.EntityId, !MyAPIGateway.Input.IsAnyShiftKeyDown()); } }
public override bool Check(MyDefinitionId itemId) { var def = MyDefinitionManager.Get <MyInventoryItemDefinition>(itemId); if (def == null) { return(false); } var itemSize = def.Size; if (def is MyBlockItemDefinition) { MrzUtils.ShowNotificationDebug($"Original mass: {itemSize}"); itemSize *= _blockSize; MrzUtils.ShowNotificationDebug($"Corrected mass: {itemSize}"); } switch (_equality) { case MrzEqualityResult.Equal: return(itemSize == _size); case MrzEqualityResult.NotEqual: return(itemSize != _size); case MrzEqualityResult.Less: return(itemSize.IsLessThan(_size)); case MrzEqualityResult.Greater: return(itemSize.IsGreaterThan(_size)); case MrzEqualityResult.LessOrEqual: return(itemSize.IsLessOrEqual(_size)); case MrzEqualityResult.GreateOrEqual: return(itemSize.IsGreaterOrEqual(_size)); default: return(false); } }
public Mrz(string lastName, string firstName, string patronymic, string mrzLine2) { FirstName = MrzUtils.ToCyrillic(firstName); LastName = MrzUtils.ToCyrillic(lastName); Patronymic = MrzUtils.ToCyrillic(patronymic); var bd = mrzLine2.Substring(13, 6).Replace("O", "0").Replace("o", "0"); BirthDate = DateTime.ParseExact(bd, "yyMMdd", CultureInfo.InvariantCulture); var psn1 = mrzLine2.Substring(0, 3); var psn2 = mrzLine2.Substring(28, 1); var psn3 = mrzLine2.Substring(3, 6); var psn4 = $"{psn1}{psn2}{psn3}"; PassportSerial = psn4.Insert(2, " ").Insert(5, " ").Replace("O", "0").Replace("o", "0"); var pd = mrzLine2.Substring(29, 6).Replace("O", "0").Replace("o", "0"); PassportIssueDate = DateTime.ParseExact(pd, "yyMMdd", CultureInfo.InvariantCulture); PassportDivisionCode = mrzLine2.Substring(mrzLine2.Length - 3 - 6, 6).Insert(3, "-").Replace("O", "0").Replace("o", "0"); }
public override void OnAddedToScene() { base.OnAddedToScene(); if (!MrzUtils.IsServer) { return; } _block = this.Get <MyBlockComponent>(); if (_block == null) { MrzUtils.CreateNotificationDebug("MrzInventoryPullComponent can only be used on blocks."); return; } _destInventory = this.Get <MyInventoryBase>(tmp_destInventoryName) ?? this.Get <MyInventoryBase>(); if (_destInventory == null) { return; } FindSource(); }