public ActionResult ConfirmTransfer(int id) { var item = InventoryTransfer.TryFind(id); if (item == null || item.IsCompleted || item.IsCancelled) { return(RedirectToAction("Transfers")); } item.Store = item.From.Store; try { item.Serial = (from x in InventoryTransfer.Queryable where x.Store.Id == item.Store.Id select x.Serial).Max() + 1; } catch { item.Serial = 1; } item.IsCompleted = true; item.ModificationTime = DateTime.Now; using (var scope = new TransactionScope()) { item.UpdateAndFlush(); foreach (var x in item.Details) { InventoryHelpers.ChangeNotification(TransactionType.InventoryTransfer, item.Id, item.ModificationTime, item.From, item.To, x.Product, -x.Quantity); } } return(RedirectToAction("Transfers")); }
public ActionResult Confirm(int id) { var dt = DateTime.Now; bool changed = false; var entity = CustomerRefund.Find(id); using (var scope = new TransactionScope()) { foreach (var item in entity.Details) { var qty = GetRefundableQuantity(item.SalesOrderDetail.Id); if (qty < item.Quantity) { changed = true; if (qty > 0.0m) { item.Quantity = qty; item.Update(); } else { item.Delete(); } } } if (changed) { entity.Updater = CurrentUser.Employee; entity.ModificationTime = dt; entity.UpdateAndFlush(); return(RedirectToAction("Edit", new { id = entity.Id, notify = true })); } } using (var scope = new TransactionScope()) { foreach (var detail in entity.Details.Where(x => !(x.Quantity > 0.0m)).ToList()) { detail.DeleteAndFlush(); } foreach (var x in entity.Details) { InventoryHelpers.ChangeNotification(TransactionType.CustomerRefund, entity.Id, dt, x.SalesOrderDetail.Warehouse, null, x.Product, x.Quantity); } entity.Updater = CurrentUser.Employee; entity.ModificationTime = dt; entity.Date = dt; entity.IsCompleted = true; entity.UpdateAndFlush(); } return(RedirectToAction("View", new { id = entity.Id })); }
public Pickupable RemoveItemFromContainer(TechType techType, int amount) { if (ContainsItem(techType)) { var itemData = ContainerItems.FirstOrDefault(x => x.TechType == techType); var item = InventoryHelpers.ConvertToPickupable(itemData); ContainerItems.Remove(itemData); //OnContainerUpdate?.Invoke(GetTotalCount(),_maxItems); return(item); } return(null); }
private bool PickupNearbyItems(Client client) { var pickupItems = client.Game.Items.Where(i => i.Ground && Pickit.Pickit.ShouldPickupItem(client.Game, i)).OrderBy(n => n.Location.Distance(client.Game.Me.Location)); Log.Information($"Killed Mephisto, picking up {pickupItems.Count()} items "); foreach (var item in pickupItems) { if (item.Location.Distance(client.Game.Me.Location) > 30) { Log.Warning($"Skipped {item} since it's at location {item.Location}, while player at {client.Game.Me.Location}"); continue; } if (!client.Game.IsInGame()) { return(false); } InventoryHelpers.MoveInventoryItemsToCube(client.Game); if (client.Game.Inventory.FindFreeSpace(item) == null) { Log.Warning($"Skipped {item.GetFullDescription()} since inventory is full"); continue; } if (!GeneralHelpers.TryWithTimeout((retryCount => { if (client.Game.Me.Location.Distance(item.Location) >= 5) { client.Game.TeleportToLocation(item.Location); return(false); } else { client.Game.PickupItem(item); Thread.Sleep(50); if (client.Game.Inventory.FindItemById(item.Id) == null && !item.IsGold) { return(false); } } return(true); }), TimeSpan.FromSeconds(3))) { Log.Warning($"Picking up item {item.GetFullDescription()} at location {item.Location} from location {client.Game.Me.Location} failed"); } } return(true); }
public bool AddItemToContainer(InventoryItem item) { try { ContainerItems.Add(InventoryHelpers.CovertToItemData(item, true)); //OnContainerUpdate?.Invoke(GetTotalCount(), _maxItems); } catch (Exception e) { QuickLogger.Error($"Class: [Storage Container] | Method: [AddItemToContainer] | Error: ${e.Message}"); return(false); } return(true); }
private async Task <bool> PickupNearbyItems(Game game, double distance) { var pickupItems = game.Items.Where(i => { return(i.Ground && game.Me.Location.Distance(i.Location) < distance && Pickit.Pickit.ShouldPickupItem(game, i)); }).OrderBy(n => game.Me.Location.Distance(n.Location)); foreach (var item in pickupItems) { if (!game.IsInGame()) { return(false); } InventoryHelpers.MoveInventoryItemsToCube(game); if (game.Inventory.FindFreeSpace(item) == null) { continue; } await GeneralHelpers.TryWithTimeout(async (retryCount) => { if (game.Me.Location.Distance(item.Location) >= 5) { var pathNearest = await _pathingService.GetPathToLocation(game.MapId, Difficulty.Normal, Area.Travincal, game.Me.Location, item.Location, MovementMode.Walking); await MovementHelpers.TakePathOfLocations(game, pathNearest, MovementMode.Walking); return(false); } return(true); }, TimeSpan.FromSeconds(3)); if (game.Me.Location.Distance(item.Location) < 5) { game.PickupItem(item); } } InventoryHelpers.MoveInventoryItemsToCube(game); return(true); }
internal void AttemptToTakeItem(TechType techType) { var amount = GetItemCount(techType); QuickLogger.Debug($"Container returned {amount} item/s for TechType {techType}"); #if SUBNAUTICA var itemSize = CraftData.GetItemSize(techType); #elif BELOWZERO var itemSize = TechData.GetItemSize(techType); #endif if (Inventory.main.HasRoomFor(itemSize.x, itemSize.y)) { if (amount > 0) { QuickLogger.Debug($"Attempting to take {_multiplier} item/s"); for (int i = 0; i < _multiplier; i++) { var itemData = ContainerItems.FirstOrDefault(x => x.TechType == techType); Pickupable pickup = InventoryHelpers.ConvertToPickupable(itemData); if (pickup == null) { QuickLogger.Debug($"There are 0 {techType} in the container while using first or default Current Amount of {techType} is: {GetItemCount(techType)}", true); return; } Inventory.main.Pickup(pickup); ContainerItems.Remove(itemData); //OnContainerUpdate?.Invoke(GetTotalCount(),_maxItems); } } else { QuickLogger.Debug($"There are 0 {techType} in the container.", true); } } }
public ActionResult Confirm(int id) { PurchaseOrder item = PurchaseOrder.Find(id); var qry = from x in item.Details group x by x.Warehouse into g select new { Warehouse = g.Key, Details = g.ToList() }; var dt = DateTime.Now; var employee = CurrentUser.Employee; using (var scope = new TransactionScope()) { foreach (var x in qry) { var master = new InventoryReceipt { Order = item, Warehouse = x.Warehouse, CreationTime = dt, ModificationTime = dt, Creator = employee, Updater = employee, Store = x.Warehouse.Store }; master.Create(); foreach (var y in x.Details) { var detail = new InventoryReceiptDetail { Receipt = master, Product = y.Product, QuantityOrdered = y.Quantity, Quantity = y.Quantity, ProductCode = y.ProductCode, ProductName = y.ProductName }; detail.Create(); InventoryHelpers.ChangeNotification(TransactionType.PurchaseOrder, item.Id, item.ModificationTime, x.Warehouse, null, y.Product, y.Quantity); } } foreach (var x in item.Details) { var price = x.Product.Prices.SingleOrDefault(t => t.List.Id == 0); if (price == null) { price = new ProductPrice { List = PriceList.Find(0), Product = x.Product }; } price.Value = x.Price; price.Save(); } item.IsCompleted = true; item.ModificationTime = DateTime.Now; item.UpdateAndFlush(); } return(RedirectToAction("Index")); }
public async Task <bool> MuleItemsForClient(Client client) { var muleGameName = $"{_botConfig.GameNamePrefix}m{GameCount++}"; if (!client.CreateGame(Difficulty.Normal, muleGameName, _botConfig.GamePassword, _botConfig.GameDescriptions?.ElementAtOrDefault(0))) { await Task.Delay(TimeSpan.FromSeconds(10)); return(false); } var failedToJoinCount = 0; foreach (var account in _muleConfig.Accounts) { List <Item> muleItems = GetMuleItems(client, account); if (!muleItems.Any()) { continue; } var accountCharacters = GetAccountCharactersForMule(account); foreach (var character in accountCharacters) { InventoryHelpers.CleanupCursorItem(client.Game); if (!HasAnyItemsToMule(client)) { break; } var muleClient = new Client(); var accountCharacter = new AccountCharacter() { Username = account.Username, Password = account.Password, Character = character }; if (!RealmConnectHelpers.ConnectToRealm( muleClient, _botConfig, accountCharacter)) { Log.Error($"Fail to connect to realm with {account.Username} with character {character}"); return(false); } if (!muleClient.JoinGame(muleGameName, _botConfig.GamePassword)) { Log.Error($"Fail to join game with {account.Username} with character {character}"); failedToJoinCount++; await Task.Delay(TimeSpan.FromSeconds(5) *failedToJoinCount); if (failedToJoinCount > 5) { client.Game.LeaveGame(); await Task.Delay(TimeSpan.FromSeconds(2)); client.RejoinMCP(); return(false); } continue; } await Task.Delay(TimeSpan.FromSeconds(2)); InventoryHelpers.CleanupCursorItem(muleClient.Game); MoveItemResult moveItemResult = MoveItemResult.Succes; do { var movableInventoryItems = muleClient.Game.Inventory.Items.Where(i => Pickit.Pickit.CanTouchInventoryItem(muleClient.Game, i)).ToList(); moveItemResult = InventoryHelpers.StashItemsAndGold(muleClient.Game, movableInventoryItems, 0); if (moveItemResult == MoveItemResult.Failed) { break; } var itemsToTrade = GetItemsToTrade(muleClient.Game.Inventory, muleItems); if (!itemsToTrade.Any()) { break; } var stashItemsToTrade = itemsToTrade.Where(i => i.Container == ContainerType.Stash || i.Container == ContainerType.Stash2).ToList(); if (stashItemsToTrade.Count > 0) { moveItemResult = InventoryHelpers.MoveStashItemsToInventory(client.Game, stashItemsToTrade); InventoryHelpers.CleanupCursorItem(client.Game); } else { moveItemResult = MoveItemResult.Succes; } var itemIdsToTrade = itemsToTrade.Select(i => i.Id).ToHashSet(); itemsToTrade = client.Game.Inventory.Items.Where(i => itemIdsToTrade.Contains(i.Id)).ToList(); if (!itemsToTrade.Any()) { break; } if (moveItemResult != MoveItemResult.Failed) { moveItemResult = await TradeInventoryItems(client, muleClient, itemsToTrade); await Task.Delay(TimeSpan.FromSeconds(5)); } muleItems = GetMuleItems(client, account); if (!muleItems.Any()) { break; } } while (moveItemResult == MoveItemResult.Succes); await Task.Delay(TimeSpan.FromSeconds(2)); muleClient.Game.LeaveGame(); await Task.Delay(TimeSpan.FromSeconds(1)); muleClient.Disconnect(); if (moveItemResult == MoveItemResult.Failed) { client.Game.LeaveGame(); await Task.Delay(TimeSpan.FromSeconds(2)); client.RejoinMCP(); return(false); } } } var stashInventoryItems = client.Game.Inventory.Items.Where(i => i.IsIdentified && Pickit.Pickit.ShouldKeepItem(client.Game, i) && Pickit.Pickit.CanTouchInventoryItem(client.Game, i)).ToList(); InventoryHelpers.StashItemsAndGold(client.Game, stashInventoryItems, 0); client.Game.LeaveGame(); await Task.Delay(TimeSpan.FromSeconds(2)); if (!client.RejoinMCP()) { return(false); } return(true); }
public virtual ActionResult Confirm(int id) { var entity = SalesOrder.TryFind(id); if (entity == null || entity.IsCompleted || entity.IsCancelled) { return(RedirectToAction("Index")); } entity.Updater = CurrentUser.Employee; entity.ModificationTime = DateTime.Now; entity.IsDelivered = false; entity.IsCompleted = true; foreach (var detail in entity.Details) { if (detail.Price == decimal.Zero) { return(View("ZeroPriceError", entity)); } } if (entity.ShipTo == null) { //entity.IsDelivered = true; using (var scope = new TransactionScope()) { var warehouse = entity.PointOfSale.Warehouse; var dt = DateTime.Now; foreach (var x in entity.Details) { x.Warehouse = warehouse; x.Update(); InventoryHelpers.ChangeNotification(TransactionType.SalesOrder, entity.Id, dt, warehouse, null, x.Product, -x.Quantity); } entity.UpdateAndFlush(); } } else { DeliveryOrder deliver = new DeliveryOrder(); deliver.Date = DateTime.Now; deliver.CreationTime = DateTime.Now; deliver.Creator = CurrentUser.Employee; deliver.Updater = entity.Creator; deliver.Customer = entity.Customer; deliver.ShipTo = entity.ShipTo; deliver.Store = entity.Store; using (var scope = new TransactionScope()) { deliver.CreateAndFlush(); } foreach (var detail in entity.Details) { var detaild = (new DeliveryOrderDetail { DeliveryOrder = deliver, OrderDetail = detail, Quantity = detail.Quantity, ProductName = detail.ProductName, Product = detail.Product, ProductCode = detail.ProductCode }); using (var scope = new TransactionScope()) { detaild.CreateAndFlush(); } } } return(RedirectToAction("Index")); }
public async Task <bool> PerformTownTasks(Client client, TownManagementOptions options) { var game = client.Game; var movementMode = GetMovementMode(game); game.CleanupCursorItem(); InventoryHelpers.CleanupPotionsInBelt(game); if (client.Game.Me.Class == CharacterClass.Paladin && client.Game.Me.HasSkill(Skill.Vigor)) { client.Game.ChangeSkill(Skill.Vigor, Hand.Right); } if (!await GeneralHelpers.PickupCorpseIfExists(client, _pathingService)) { Log.Error($"{client.Game.Me.Name} failed to pickup corpse"); return(false); } if (client.Game.Act != options.Act) { var targetTownArea = WayPointHelpers.MapTownArea(options.Act); var pathToTownWayPoint = await _pathingService.ToTownWayPoint(client.Game, movementMode); if (!await MovementHelpers.TakePathOfLocations(client.Game, pathToTownWayPoint, movementMode)) { Log.Warning($"Teleporting to {client.Game.Act} waypoint failed"); return(false); } var townWaypoint = client.Game.GetEntityByCode(client.Game.Act.MapTownWayPointCode()).Single(); Log.Information($"Taking waypoint to {targetTownArea}"); if (!GeneralHelpers.TryWithTimeout((_) => { client.Game.TakeWaypoint(townWaypoint, options.Act.MapTownWayPoint()); return(GeneralHelpers.TryWithTimeout((_) => client.Game.Area == targetTownArea, TimeSpan.FromSeconds(2))); }, TimeSpan.FromSeconds(5))) { Log.Information($"Moving to {options.Act} failed"); return(false); } } var townArea = WayPointHelpers.MapTownArea(game.Act); if (!await IdentifyItems(game, movementMode)) { return(false); } if (!await RefreshAndSellItems(game, movementMode, options)) { return(false); } if (!await RepairItems(game, movementMode)) { return(false); } if (InventoryHelpers.HasAnyItemsToStash(client.Game)) { var pathStash = await _pathingService.GetPathToObject(game.MapId, Difficulty.Normal, townArea, game.Me.Location, EntityCode.Stash, movementMode); if (!await MovementHelpers.TakePathOfLocations(game, pathStash, movementMode)) { Log.Warning($"{movementMode} failed at location {game.Me.Location}"); } var stashItemsResult = InventoryHelpers.StashItemsToKeep(game, _externalMessagingClient); if (stashItemsResult != Enums.MoveItemResult.Succes) { Log.Warning($"Stashing items failed with result {stashItemsResult}"); } } if (CubeHelpers.AnyGemsToTransmuteInStash(client.Game)) { var pathStash = await _pathingService.GetPathToObject(game.MapId, Difficulty.Normal, townArea, game.Me.Location, EntityCode.Stash, movementMode); if (!await MovementHelpers.TakePathOfLocations(game, pathStash, movementMode)) { Log.Warning($"{movementMode} failed at location {game.Me.Location}"); } CubeHelpers.TransmuteGems(client.Game); } if (!await GambleItems(client, movementMode)) { return(false); } return(true); }