public bool Run(params object[] args) { NWPlaceable terminal = Object.OBJECT_SELF; int bankID = terminal.GetLocalInt("BANK_ID"); if (bankID <= 0) { return(false); } NWPlayer player = _.GetLastDisturbed(); NWItem item = _.GetInventoryDisturbItem(); int disturbType = _.GetInventoryDisturbType(); int itemCount = terminal.InventoryItems.Count(); int itemLimit = terminal.GetLocalInt("BANK_LIMIT"); if (itemLimit <= 0) { itemLimit = 20; } Data.Entity.Bank bank = _data.Single <Data.Entity.Bank>(x => x.ID == bankID); if (disturbType == INVENTORY_DISTURB_TYPE_ADDED) { if (itemCount > itemLimit) { _item.ReturnItem(player, item); player.SendMessage(_color.Red("No more items can be placed inside.")); } else { BankItem itemEntity = new BankItem { ItemName = item.Name, ItemTag = item.Tag, ItemResref = item.Resref, ItemID = item.GlobalID.ToString(), ItemObject = _serialization.Serialize(item), BankID = bank.ID, PlayerID = player.GlobalID, DateStored = DateTime.UtcNow }; _data.SubmitDataChange(itemEntity, DatabaseActionType.Insert); } } else if (disturbType == INVENTORY_DISTURB_TYPE_REMOVED) { var record = _data.Get <BankItem>(item.GlobalID); _data.SubmitDataChange(record, DatabaseActionType.Delete); } player.SendMessage(_color.White("Item Limit: " + (itemCount > itemLimit ? itemLimit : itemCount) + " / ") + _color.Red("" + itemLimit)); return(true); }
public bool Run(params object[] args) { NWPlayer player = _.GetLastOpenedBy(); if (!player.IsPlayer) { return(false); } NWPlaceable terminal = Object.OBJECT_SELF; NWArea area = terminal.Area; int bankID = terminal.GetLocalInt("BANK_ID"); if (bankID <= 0) { Console.WriteLine("WARNING: Bank ID is not set on bank in area: " + area.Name); return(false); } Data.Entity.Bank entity = _data.SingleOrDefault <Data.Entity.Bank>(x => x.ID == bankID); if (entity == null) { entity = new Data.Entity.Bank { AreaName = area.Name, AreaResref = area.Resref, AreaTag = area.Tag, ID = bankID }; _data.SubmitDataChange(entity, DatabaseActionType.Insert); } var bankItems = _data.Where <BankItem>(x => x.PlayerID == player.GlobalID && x.BankID == entity.ID); foreach (BankItem item in bankItems.Where(x => x.PlayerID == player.GlobalID)) { _serialization.DeserializeItem(item.ItemObject, terminal); } terminal.IsLocked = true; player.SendMessage("Walk away from the terminal when you are finished banking."); return(true); }
public void Main() { NWPlayer player = _.GetLastOpenedBy(); if (!player.IsPlayer) { return; } NWPlaceable terminal = _.OBJECT_SELF; NWArea area = terminal.Area; int bankID = terminal.GetLocalInt("BANK_ID"); if (bankID <= 0) { Console.WriteLine("WARNING: Bank ID is not set on bank in area: " + area.Name); return; } Data.Entity.Bank entity = DataService.Bank.GetByID(bankID); if (entity == null) { entity = new Data.Entity.Bank { AreaName = area.Name, AreaResref = area.Resref, AreaTag = area.Tag, ID = bankID }; DataService.SubmitDataChange(entity, DatabaseActionType.Insert); } var bankItems = DataService.BankItem.GetAllByPlayerIDAndBankID(player.GlobalID, bankID); foreach (BankItem item in bankItems.Where(x => x.PlayerID == player.GlobalID)) { SerializationService.DeserializeItem(item.ItemObject, terminal); } terminal.IsLocked = true; player.SendMessage("Walk away from the terminal when you are finished banking."); }