public override bool TryResolveMainInteractVerb(Entity entity, EntityUniverseFacade facade, Vector3I location, TileConfiguration lookedAtTile, out string verb) { verb = facade.AnyInnerCableEntitiesInTile(location, out _) ? "nimbusfox.powerapi.verb.extract" : "nimbusfox.powerapi.verb.insert"; return(true); }
public override void Control(Entity entity, EntityUniverseFacade facade, ControlState main, ControlState alt) { if (!main.DownClick && !alt.DownClick) { return; } if (main.DownClick) { if (entity.PlayerEntityLogic.LookingAtTile(out var target, out _)) { if (facade.AnyInnerCableEntitiesInTile(target, out var entities)) { foreach (var lEntity in entities) { var itemBlob = BlobAllocator.Blob(true); itemBlob.SetString("code", ((InnerCableTileEntityLogic)lEntity.Logic).Tile); var item = GameContext.ItemDatabase.SpawnItemStack(itemBlob, null); if (item.IsNull()) { itemBlob.Delete("code"); itemBlob.SetString("kind", "staxel.item.Placer"); itemBlob.SetString("tile", ((InnerCableTileEntityLogic)lEntity.Logic).Tile); item = GameContext.ItemDatabase.SpawnItemStack(itemBlob, null); } ItemEntityBuilder.SpawnDroppedItem(entity, facade, item, target.ToVector3D(), Vector3D.Zero, Vector3D.Zero, SpawnDroppedFlags.AttemptPickup); facade.RemoveEntity(lEntity.Id); } } else { if (_targetCode == "nimbusfox.powerapi.verb.none") { var notification = GameContext.NotificationDatabase.CreateNotificationFromCode( "nimbusfox.powerapi.notifications.noCableSelected", facade.Step, new NotificationParams(), true); entity.PlayerEntityLogic.ShowNotification(notification); return; } if (!entity.Inventory.HasItemWithCode(_targetCode)) { var nparams = new NotificationParams(1); nparams.SetTranslation(0, _targetCode + ".name"); var notification = GameContext.NotificationDatabase.CreateNotificationFromCode( "nimbusfox.powerapi.notifications.noCable", facade.Step, nparams, true); entity.PlayerEntityLogic.ShowNotification(notification); return; } if (facade.ReadTile(target, TileAccessFlags.SynchronousWait, out var tile)) { if (!tile.Configuration.Components.Select <ChargeableComponent>().Any()) { var config = BlobAllocator.Blob(true); config.SetString("tile", _targetCode); InnerCableTileEntityBuilder.Spawn(target, config, facade); entity.Inventory.ConsumeItem(new ItemStack(entity.Inventory.GetItemStack(_slot).Item, 1)); } } } } } if (alt.DownClick) { var orig = _targetCode; var looped = false; loop: if (_slot + 1 >= entity.Inventory.SlotCount()) { _slot = 0; } for (var i = _slot; i < entity.Inventory.SlotCount(); i++) { var current = entity.Inventory.GetItemStack(i); if (current.IsNull()) { continue; } if (current.Item.Configuration.Components.Select <CableComponent>().Any()) { _slot = i; _targetCode = current.Item.GetItemCode(); break; } } if (orig == _targetCode) { if (!looped) { looped = true; _slot = 0; goto loop; } _targetCode = "nimbusfox.powerapi.verb.none"; } } entity.Inventory.ItemStoreNeedsStorage(); }