public void WithdrawInventory(Mobile from, int amount, CommodityBrokerEntry entry) { if (from == null || Plot == null || entry == null || !m_CommodityEntries.Contains(entry)) { return; } Container pack = from.Backpack; if (pack != null) { while (amount > 60000) { CommodityDeed deed = new CommodityDeed(); Item item = Loot.Construct(entry.CommodityType); item.Amount = 60000; deed.SetCommodity(item); pack.DropItem(deed); amount -= 60000; entry.Stock -= 60000; } CommodityDeed deed2 = new CommodityDeed(); Item newitem = Loot.Construct(entry.CommodityType); newitem.Amount = amount; deed2.SetCommodity(newitem); pack.DropItem(deed2); entry.Stock -= amount; } if (Plot != null && from == Plot.Owner) { from.SendLocalizedMessage(1150221, string.Format("{0}\t#{1}\t{2}", amount.ToString(), entry.Label, Plot.ShopName != null ? Plot.ShopName : "a shop with no name")); // You have removed ~1_QUANTITY~ units of ~2_ITEMNAME~ from the inventory of "~3_SHOPNAME~" } }
public override void OnResponse(NetState sender, RelayInfo info) { Mobile from = sender.Mobile; int available = Vendor.MaxAmount - MiningCooperative.PurchaseAmount(from); int payment = Vendor.Quantity * Vendor.Price; if (info.ButtonID == 1) { if (available > 0) { if (Banker.Withdraw(from, payment, true)) { CommodityDeed deed = new CommodityDeed(); deed.SetCommodity(new EtherealSand(Vendor.Quantity)); from.AddToBackpack(deed); MiningCooperative.AddPurchase(from, Vendor.Quantity); from.SendGump(new MiningCooperativeGump(Vendor, from)); } else { Vendor.Say(500192); // Begging thy pardon, but thou canst not afford that. } } else { Vendor.Say(1159195); // Begging thy pardon, but your family has purchased the maximum amount of that commodity. I cannot sell you more until a new shipment arrives! } } }
private void ConvertCommodities() { var items = new List <Item>(Items); for (int i = 0; i < items.Count; i++) { var item = items[i]; if (item is ICommodity && ((ICommodity)item).IsDeedable) { var deed = new CommodityDeed(); if (deed.SetCommodity(item)) { DropItem(deed); } else { deed.Delete(); } } } ColUtility.Free(items); }
private void TakeCommodities(Container c, Type type, ref int amount) { if (c == null) { return; } Item[] items = c.FindItemsByType(typeof(CommodityDeed)); List <Item> toSell = new List <Item>(); for (var index = 0; index < items.Length; index++) { Item item = items[index]; if (item is CommodityDeed commodityDeed && commodityDeed.Commodity != null && commodityDeed.Commodity.GetType() == type) { Item commodity = commodityDeed.Commodity; if (commodity.Amount <= amount) { toSell.Add(item); amount -= commodity.Amount; } else { CommodityDeed newDeed = new CommodityDeed(); Item newItem = Loot.Construct(type); newItem.Amount = amount; newDeed.SetCommodity(newItem); commodity.Amount -= amount; commodityDeed.InvalidateProperties(); toSell.Add(newDeed); amount = 0; } } } for (var index = 0; index < toSell.Count; index++) { Item item = toSell[index]; AddInventory(null, item); } }
private bool GiveItems(Mobile from, Type type, int amt, StorageEntry entry) { int amount = amt; while (amount > 60000) { CommodityDeed deed = new CommodityDeed(); Item item = Loot.Construct(type); item.Amount = 60000; deed.SetCommodity(item); amount -= 60000; if (from.Backpack == null || !from.Backpack.TryDropItem(from, deed, false)) { deed.Delete(); return(false); } else { entry.RemoveCommodity(type, 60000); } } CommodityDeed deed2 = new CommodityDeed(); Item item2 = Loot.Construct(type); item2.Amount = amount; deed2.SetCommodity(item2); if (from.Backpack == null || !from.Backpack.TryDropItem(from, deed2, false)) { deed2.Delete(); return(false); } else { entry.RemoveCommodity(type, amount); } return(true); }
public static void Run() { List <Item> items = new List <Item>(); List <Item> validItems = new List <Item>(); List <Mobile> hairCleanup = new List <Mobile>(); int boxes = 0; foreach (Item item in World.Items.Values) { if (item.Map == null) { items.Add(item); continue; } else if (item is CommodityDeed) { CommodityDeed deed = (CommodityDeed)item; if (deed.Commodity != null) { validItems.Add(deed.Commodity); } continue; } else if (item is BaseHouse) { BaseHouse house = (BaseHouse)item; foreach (RelocatedEntity relEntity in house.RelocatedEntities) { if (relEntity.Entity is Item) { validItems.Add((Item)relEntity.Entity); } } foreach (VendorInventory inventory in house.VendorInventories) { foreach (Item subItem in inventory.Items) { validItems.Add(subItem); } } } else if (item is BankBox) { BankBox box = (BankBox)item; Mobile owner = box.Owner; if (owner == null) { items.Add(box); ++boxes; } else if (box.Items.Count == 0) { items.Add(box); ++boxes; } continue; } else if ((item.Layer == Layer.Hair || item.Layer == Layer.FacialHair)) { object rootParent = item.RootParent; if (rootParent is Mobile) { Mobile rootMobile = (Mobile)rootParent; if (item.Parent != rootMobile && rootMobile.IsPlayer()) { items.Add(item); continue; } else if (item.Parent == rootMobile) { hairCleanup.Add(rootMobile); continue; } } } if (item.Parent != null || item.Map != Map.Internal || item.HeldBy != null) { continue; } if (item.Location != Point3D.Zero) { continue; } if (!IsBuggable(item)) { continue; } if (item is BaseBoat || item is BaseDockedBoat) { continue; } items.Add(item); } for (int i = 0; i < validItems.Count; ++i) { items.Remove(validItems[i]); } if (items.Count > 0) { if (boxes > 0) { Console.WriteLine("Cleanup: Detected {0} inaccessible items, including {1} bank boxes, removing..", items.Count, boxes); } else { Console.WriteLine("Cleanup: Detected {0} inaccessible items, removing..", items.Count); } for (int i = 0; i < items.Count; ++i) { items[i].Delete(); } } if (hairCleanup.Count > 0) { Console.WriteLine("Cleanup: Detected {0} hair and facial hair items being worn, converting to their virtual counterparts..", hairCleanup.Count); for (int i = 0; i < hairCleanup.Count; i++) { hairCleanup[i].ConvertHair(); } } }
public static void Run() { List <Item> items = new List <Item>(); List <Item> validItems = new List <Item>(); List <Mobile> hairCleanup = new List <Mobile>(); int boxes = 0; foreach (Item item in World.Items.Values) { if (item.Map == null) { items.Add(item); continue; } else if (item is CommodityDeed) { CommodityDeed deed = (CommodityDeed)item; if (deed.Commodity != null) { validItems.Add(deed.Commodity); } continue; } else if (item is BaseHouse) { BaseHouse house = (BaseHouse)item; foreach (RelocatedEntity relEntity in house.RelocatedEntities) { if (relEntity.Entity is Item) { validItems.Add((Item)relEntity.Entity); } } foreach (VendorInventory inventory in house.VendorInventories) { foreach (Item subItem in inventory.Items) { validItems.Add(subItem); } } } else if (item is BankBox) { BankBox box = (BankBox)item; Mobile owner = box.Owner; if (owner == null) { items.Add(box); ++boxes; } else if (box.Items.Count == 0) { items.Add(box); ++boxes; } continue; } else if ((item.Layer == Layer.Hair || item.Layer == Layer.FacialHair)) { object rootParent = item.RootParent; if (rootParent is Mobile) { Mobile rootMobile = (Mobile)rootParent; if (item.Parent != rootMobile && rootMobile.AccessLevel == AccessLevel.Player) { items.Add(item); continue; } else if (item.Parent == rootMobile) { hairCleanup.Add(rootMobile); continue; } } } if (item.Parent != null || item.Map != Map.Internal || item.HeldBy != null) { continue; } if (item.Location != Point3D.Zero) { continue; } if (!IsBuggable(item)) { continue; } items.Add(item); } for (int i = 0; i < validItems.Count; ++i) { items.Remove(validItems[i]); } if (items.Count > 0) { for (int i = 0; i < items.Count; ++i) { items[i].Delete(); } } if (hairCleanup.Count > 0) { for (int i = 0; i < hairCleanup.Count; i++) { hairCleanup[i].ConvertHair(); } } }
/// <summary> /// Core procedure of the donation system for stackable items. /// </summary> /// <param name="m">The player whose backpack the items will be taken</param> /// <param name="type">The type of the donation item.</param> /// <param name="ratio">Number of points per unit of the item.</param> /// <param name="amount">How much is he going to donate.</param> private void Donate(Mobile m, Type type, double ratio, int amount) { if (amount <= 0) { // That is not a valid donation quantity. m.SendLocalizedMessage(1073181); return; } int sum = GetTotalAmountByType(m, type); int points = (int)(amount * ratio); if (sum < amount) { // You do not have enough to make a donation of that magnitude! m.SendLocalizedMessage(1073182); } else if (points <= 0) { // Your donation is too small to award any points. Try giving a larger donation. m.SendLocalizedMessage(1073166); } else { List <Item> packItems = new List <Item>(m.Backpack.Items); for (int i = 0; amount > 0 && i < packItems.Count; i++) { Item item = packItems[i]; CommodityDeed deed = null; if (item is CommodityDeed) { deed = item as CommodityDeed; item = deed.Commodity; } if (item != null && item.GetType() == type) { if (amount >= item.Amount) { amount -= item.Amount; item.Delete(); if (deed != null) { deed.Delete(); } } else { item.Amount -= amount; amount = 0; if (deed != null) { deed.InvalidateProperties(); } } } } m_Collection.Award(m, points); } }
public InternalTarget(CommodityDeed deed) : base(3, false, TargetFlags.None) => m_Deed = deed;
public static void Run() { ArrayList items = new ArrayList(); ArrayList validItems = new ArrayList(); int boxes = 0; foreach (Item item in World.Items.Values) { if (item.Map == null) { items.Add(item); continue; } else if (item is CommodityDeed) { CommodityDeed deed = (CommodityDeed)item; if (deed.Commodity != null) { validItems.Add(deed.Commodity); } continue; } else if (item is BaseHouse) { BaseHouse house = (BaseHouse)item; foreach (RelocatedEntity relEntity in house.RelocatedEntities) { if (relEntity.Entity is Item) { validItems.Add(relEntity.Entity); } } foreach (VendorInventory inventory in house.VendorInventories) { foreach (Item subItem in inventory.Items) { validItems.Add(subItem); } } } else if (item is BankBox) { BankBox box = (BankBox)item; Mobile owner = box.Owner; if (owner == null) { items.Add(box); ++boxes; } else if (!owner.Player && box.Items.Count == 0) { items.Add(box); ++boxes; } continue; } else if ((item.Layer == Layer.Hair || item.Layer == Layer.FacialHair)) { object rootParent = item.RootParent; if (rootParent is Mobile && item.Parent != rootParent && ((Mobile)rootParent).AccessLevel == AccessLevel.Player) { items.Add(item); continue; } } if (item.Parent != null || item.Map != Map.Internal || item.HeldBy != null) { continue; } if (item.Location != Point3D.Zero) { continue; } if (!IsBuggable(item)) { continue; } items.Add(item); } for (int i = 0; i < validItems.Count; ++i) { items.Remove(validItems[i]); } if (items.Count > 0) { if (boxes > 0) { Console.WriteLine("Cleanup: Detected {0} inaccessible items, including {1} bank boxes, removing..", items.Count, boxes); } else { Console.WriteLine("Cleanup: Detected {0} inaccessible items, removing..", items.Count); } for (int i = 0; i < items.Count; ++i) { ((Item)items[i]).Delete(); } } }
public static void Run() { ArrayList items = new ArrayList(); ArrayList commodities = new ArrayList(); int boxes = 0; foreach (Item item in World.Items.Values) { if (item is CommodityDeed) { CommodityDeed deed = (CommodityDeed)item; if (deed.Commodity != null) { commodities.Add(deed.Commodity); } continue; } else if (item is BankBox) { BankBox box = (BankBox)item; Mobile owner = box.Owner; if (owner == null) { items.Add(box); ++boxes; } else if (!owner.Player && box.Items.Count == 0) { items.Add(box); ++boxes; } continue; } if (item.Parent != null || item.Map != Map.Internal || item.HeldBy != null) { continue; } if (item.Location != Point3D.Zero) { continue; } if (!IsBuggable(item)) { continue; } items.Add(item); } for (int i = 0; i < commodities.Count; ++i) { items.Remove(commodities[i]); } if (items.Count > 0) { if (boxes > 0) { Console.WriteLine("Cleanup: Detected {0} inaccessible items, including {1} bank boxes, removing..", items.Count, boxes); } else { Console.WriteLine("Cleanup: Detected {0} inaccessible items, removing..", items.Count); } for (int i = 0; i < items.Count; ++i) { ((Item)items[i]).Delete(); } } }
public InternalSellInfo() { Add(typeof(CommodityDeed), CommodityDeed.GetSBSellValue()); Add(typeof(VendorRentalContract), VendorRentalContract.GetSBSellValue()); }
public InternalBuyInfo() { Add(new GenericBuyInfo("Commodity Deed", typeof(CommodityDeed), CommodityDeed.GetSBPurchaseValue(), 25, 0x14F0, 0x47)); Add(new GenericBuyInfo("Vendor Rental Contract", typeof(VendorRentalContract), VendorRentalContract.GetSBPurchaseValue(), 25, 0x14F0, 0)); }
public static void Run() { List <Item> items = new List <Item>(); List <Item> validItems = new List <Item>(); List <Mobile> hairCleanup = new List <Mobile>(); List <Mobile> mobiles = new List <Mobile>(); List <Mobile> validMobiles = new List <Mobile>(); List <Mobile> orphans = new List <Mobile>(); int stabled = 0; foreach (Mobile m in World.Mobiles.Values) { if (m is PlayerMobile) { PlayerMobile pm = (PlayerMobile)m; if (pm.Account == null) { orphans.Add(m); } else if (!Ethic.Enabled && pm.EthicPlayer != null) { pm.EthicPlayer.Detach(); } } else { BaseCreature pet = m as BaseCreature; if (pet != null && pet.Controlled && !pet.Summoned && pet.ControlMaster != null && !pet.Blessed && pet.ControlMaster.Player && !pet.IsStabled && pet.Map != Map.Internal) { if (pet.IsDeadPet) { pet.Resurrect(); } PlayerMobile master = pet.ControlMaster as PlayerMobile; if (master != null) { master.StablePet(pet, true, true); stabled++; } } else //Invalid Internalized Mobiles { if (pet != null && (pet.IsStabled || (pet is BaseMount && ((BaseMount)pet).Rider != null))) { continue; } if (m.Spawner != null || m.Blessed) { continue; } if (m is PlayerMobile || m.Player || m is PlayerVendor || m is PlayerBarkeeper) { continue; } if (m.Map != null && m.Map != Map.Internal) { continue; } if (m.Location != Point3D.Zero) { continue; } mobiles.Add(m); } } } int boxes = 0; int emptyboxes = 0; int spawners = 0; int parents = 0; int emptyspawners = 0; foreach (Item item in World.Items.Values) { if (item.Map == null) { items.Add(item); continue; } else if (item is Spawner) { if (item.Map == Map.Internal && item.Parent == null) { spawners++; continue; } else if (item.Parent == null && (((Spawner)item).Entries == null || ((Spawner)item).Entries.Count == 0)) { items.Add(item); //Console.WriteLine( "Cleanup: Detected invalid spawner {0} at ({1},{2},{3}) [{4}]", item.Serial, item.X, item.Y, item.Z, item.Map ); emptyspawners++; } } else if (item is CommodityDeed) { CommodityDeed deed = (CommodityDeed)item; if (deed.CommodityItem != null) { validItems.Add(deed.CommodityItem); } continue; } else if (item is BaseHouse) { BaseHouse house = (BaseHouse)item; List <IEntity> entities = house.GetHouseEntities(); foreach (RelocatedEntity relEntity in house.RelocatedEntities) { if (relEntity.Entity is Item) { validItems.Add((Item)relEntity.Entity); } } foreach (VendorInventory inventory in house.VendorInventories) { foreach (Item subItem in inventory.Items) { validItems.Add(subItem); } } } else if (item is BankBox) { BankBox box = (BankBox)item; Mobile owner = box.Owner; if (owner == null) { items.Add(box); ++boxes; } else if (box.Items.Count == 0) { items.Add(box); ++emptyboxes; } continue; } else if ((item.Layer == Layer.Hair || item.Layer == Layer.FacialHair)) { object rootParent = item.RootParent; if (rootParent is Mobile) { Mobile rootMobile = (Mobile)rootParent; if (item.Parent != rootMobile /*&& rootMobile.AccessLevel == AccessLevel.Player*/) { items.Add(item); continue; } else if (item.Parent == rootMobile) { hairCleanup.Add(rootMobile); continue; } } } else if (item is Container) { List <Item> contitems = item.AcquireItems(); for (int i = contitems.Count - 1; i >= 0; i--) { Item child = contitems[i]; if (child.Parent != item) { //if ( child is Spawner && child.Parent == null ) // item.Items.RemoveAt( i-- ); Console.WriteLine("Cleanup: Detected orphan item {0} ({1}) of {2} ({3}) has parent of {4} ({5})", child.GetType().Name, child.Serial, item.GetType().Name, item.Serial, child.Parent == null ? "(-null-)" : child.Parent.GetType().Name, child.Parent is IEntity ? ((IEntity)child.Parent).Serial.ToString() : "N/A"); contitems.RemoveAt(i); //Clean this up if (child.Parent is Item) { Item parent = (Item)child.Parent; List <Item> parentitems = parent.AcquireItems(); parentitems.Add(child); } else if (child.Parent is Mobile) { Mobile parent = (Mobile)child.Parent; parent.Items.Add(child); } parents++; } } } else if (item.RootParent is BaseTreasureChest) //Clear out all items in a treasure chest { items.Add(item); continue; } else if (item is CharacterStatueDeed) { CharacterStatueDeed deed = item as CharacterStatueDeed; if (deed.Statue != null) { validMobiles.Add(deed.Statue); if (deed.Statue.Plinth != null) { validItems.Add(deed.Statue.Plinth); } } } else if (item is KeyRing) { validItems.AddRange(((KeyRing)item).Keys); } if (item.Parent != null || (item.Map != null && item.Map != Map.Internal) || item.HeldBy != null) { continue; } if (item.Location != Point3D.Zero) { continue; } if (!IsBuggable(item)) { continue; } if (!item.Movable) { continue; } items.Add(item); } for (int i = 0; i < validItems.Count; ++i) { items.Remove(validItems[i]); } for (int i = 0; i < validMobiles.Count; ++i) { mobiles.Remove(validMobiles[i]); } if (items.Count > 0) { String message = String.Format("Cleanup: Detected {0} inaccessible items, ", items.Count); if (boxes > 0) { message += String.Format("including {0} bank box{1}, ", boxes, boxes != 1 ? "es" : String.Empty); } if (emptyboxes > 0) { message += String.Format("{1}{0} empty bank box{2}, ", emptyboxes, boxes == 0 ? "including " : String.Empty, emptyboxes != 1 ? "es" : String.Empty); } if (emptyspawners > 0) { message += String.Format("{1} {0} empty/invalid spawner{2}, ", emptyspawners, (emptyboxes == 0 && boxes == 0) ? "including " : String.Empty, emptyspawners != 1 ? "s" : String.Empty); } message += "removing.."; Console.WriteLine(message); for (int i = 0; i < items.Count; ++i) { //Console.WriteLine( "Item: {0} - {2} ({1})", items[i].Name, items[i].Serial, items[i].GetType() ); items[i].Delete(); } } if (spawners > 0) { Console.WriteLine("Cleanup: Detected {0} inaccessible spawners..", spawners); } if (parents > 0) { Console.WriteLine("Cleanup: Detected {0} invalid parent-child items, fixing references..", parents); } if (hairCleanup.Count > 0) { Console.WriteLine("Cleanup: Detected {0} hair and facial hair items being worn, converting to virtual hair..", hairCleanup.Count); for (int i = 0; i < hairCleanup.Count; i++) { hairCleanup[i].ConvertHair(); } } if (orphans.Count > 0) { Console.WriteLine("Cleanup: Detected {0} orphaned players, removing..", orphans.Count); for (int i = 0; i < orphans.Count; ++i) { orphans[i].Delete(); } } if (stabled > 0) { Console.WriteLine("Cleanup: Detected {0} pets requiring stables..", stabled); } if (mobiles.Count > 0) { Console.WriteLine("Cleanup: Detected {0} invalid mobiles, removing...", mobiles.Count); for (int i = 0; i < mobiles.Count; ++i) { mobiles[i].Delete(); } } }
// Attempt to encode a commodity deed with new data public static bool RCDEncode(CommodityDeed cd, string sData) { ClassNameTranslator cnt = new ClassNameTranslator(); // Make sure there isn't already a resource attached to the deed if (cd.CommodityAmount > 0) { RCDLogger.Log(LogType.Text, string.Format("{0}:{1}:{2}:{3}:{4}", cd.Serial.ToString(), cnt.TranslateClass(cd.Type), cd.CommodityAmount.ToString(), cd.Location, "ALREADY FILLED")); RCDCaller.SendMessage("Warning! Filled deed detected... see logfile!"); return(false); } // Perform the replacement int iStartIDX = sData.IndexOf("\""); int iEndIDX = sData.IndexOf("\"", iStartIDX + 1); string sType = sData.Substring((iStartIDX + 1), (iEndIDX - iStartIDX - 1)); Type tType = ScriptCompiler.FindTypeByName(sType); if (tType == null) { // Invalid RCDLogger.Log(LogType.Text, string.Format("{0}:{1}:{2}:{3}:{4}", cd.Serial.ToString(), sType, "", cd.Location, "INVALID")); RCDCaller.SendMessage("Warning! Invalid type detected... see logfile!"); return(false); } // Next work out the quantity of the data we're going to map to the deed iStartIDX = sData.IndexOf(",", iEndIDX) + 1; iEndIDX = sData.Length; string sQuantity = sData.Substring(iStartIDX, (iEndIDX - iStartIDX)); int iQuantity; try { iQuantity = Convert.ToInt32(sQuantity); } catch (Exception e) { Console.WriteLine("RemapCommDeeds: Exception - (trying to convert {0} to an integer)", sQuantity); RCDLogger.Log(LogType.Text, string.Format("{0}:{1}:{2}:{3}:{4}", cd.Serial.ToString(), cd.Type.ToString(), sQuantity, cd.Location, "INVALID")); RCDCaller.SendMessage("Warning! Invalid quantity detected (non numeric)... see logfile!"); return(false); } // All good, encode it... cd.Type = tType; cd.CommodityAmount = iQuantity; cd.Description = string.Format("{0} {1}", iQuantity, cnt.TranslateClass(tType)); RCDLogger.Log(LogType.Text, string.Format("{0}:{1}:{2}:{3}:{4}", cd.Serial.ToString(), sType, iQuantity, cd.Location, "PATCHED")); return(true); }