private void HandleResponse(Mobile from, string text) { int amount = Utility.ToInt32(text); if (amount <= 0) { from.SendLocalizedMessage(1073181); // That is not a valid donation quantity. return; } if (from.Backpack == null) { return; } // Make sure we have enough if (m_Selected.Type == typeof(BankCheck)) { int count = from.Backpack.GetChecksWorth(true); if (count < amount) { from.SendLocalizedMessage(1073182); // You do not have enough to make a donation of that magnitude! return; } } else { int count = from.Backpack.GetAmount(m_Selected.Type, true, true); if (count < amount) { if (m_Selected.Type == typeof(Gold)) { from.SendLocalizedMessage(1073182); // You do not have enough to make a donation of that magnitude! } else { from.SendLocalizedMessage(1073167); // You do not have enough of that item to make a donation! } return; } } // Donate if (m_Selected.Type == typeof(BankCheck)) { from.Backpack.TakeFromChecks(amount, true); } else { from.Backpack.ConsumeTotal(m_Selected.Type, amount, true, true); } m_Collection.Donate((PlayerMobile)from, m_Selected, amount); }
private void HandleResponse(Mobile from, string text) { int amount = Utility.ToInt32(text); if (amount <= 0) { from.SendLocalizedMessage(1073181); // That is not a valid donation quantity. return; } if (from.Backpack == null) { return; } if (m_Selected.Type == typeof(Gold)) { if (amount * m_Selected.Points < 1) { from.SendLocalizedMessage(1073167); // You do not have enough of that item to make a donation! from.SendGump(new CommunityCollectionGump((PlayerMobile)from, m_Collection, m_Location)); return; } Item[] items = from.Backpack.FindItemsByType(m_Selected.Type, true); Account acct = from.Account as Account; int goldcount = 0; int accountcount = acct == null ? 0 : acct.TotalGold; int amountRemaining = amount; foreach (Item item in items) { goldcount += item.Amount; } if (goldcount >= amountRemaining) { foreach (Item item in items) { if (item.Amount <= amountRemaining) { item.Delete(); amountRemaining -= item.Amount; } else { item.Amount -= amountRemaining; amountRemaining = 0; } if (amountRemaining == 0) { break; } } } else if (goldcount + accountcount >= amountRemaining) { foreach (Item item in items) { amountRemaining -= item.Amount; item.Delete(); } Banker.Withdraw(from, amountRemaining); } else { from.SendLocalizedMessage(1073182); // You do not have enough to make a donation of that magnitude! from.SendGump(new CommunityCollectionGump((PlayerMobile)from, m_Collection, m_Location)); return; } from.Backpack.ConsumeTotal(m_Selected.Type, amount, true, true); m_Collection.Donate((PlayerMobile)from, m_Selected, amount); } else { if (amount * m_Selected.Points < 1) { from.SendLocalizedMessage(1073167); // You do not have enough of that item to make a donation! from.SendGump(new CommunityCollectionGump((PlayerMobile)from, m_Collection, m_Location)); return; } List <Item> items = FindTypes((PlayerMobile)from, m_Selected); if (items.Count > 0) { // count items int count = 0; for (int i = 0; i < items.Count; i++) { Item item = GetActual(items[i]); if (item != null && !item.Deleted) { count += item.Amount; } } // check if (amount > count) { from.SendLocalizedMessage(1073182); // You do not have enough to make a donation of that magnitude! from.SendGump(new CommunityCollectionGump((PlayerMobile)from, m_Collection, m_Location)); return; } else if (amount * m_Selected.Points < 1) { from.SendLocalizedMessage(m_Selected.Type == typeof(Gold) ? 1073182 : 1073167); // You do not have enough of that item to make a donation! from.SendGump(new CommunityCollectionGump((PlayerMobile)from, m_Collection, m_Location)); return; } // donate int deleted = 0; for (int i = 0; i < items.Count && deleted < amount; i++) { Item item = GetActual(items[i]); if (item == null || item.Deleted) { continue; } if (item.Stackable && item.Amount + deleted > amount && !item.Deleted) { item.Amount -= amount - deleted; deleted += amount - deleted; } else if (!item.Deleted) { deleted += item.Amount; items[i].Delete(); } if (items[i] is CommodityDeed && !items[i].Deleted) { items[i].InvalidateProperties(); } } m_Collection.Donate((PlayerMobile)from, m_Selected, amount); } else { from.SendLocalizedMessage(1073182); // You do not have enough to make a donation of that magnitude! } ColUtility.Free(items); } }
private void HandleResponse(Mobile from, string text) { int amount = Utility.ToInt32(text); if (amount <= 0) { from.SendLocalizedMessage(1073181); // That is not a valid donation quantity. return; } if (from.Backpack == null) { return; } if (m_Selected.Type == typeof(Gold)) { if (amount * m_Selected.Points < 1) { from.SendLocalizedMessage(1073167); // You do not have enough of that item to make a donation! from.SendGump(new CommunityCollectionGump((PlayerMobile)from, m_Collection, m_Location)); return; } Item[] items = from.Backpack.FindItemsByType(m_Selected.Type, true); Account acct = from.Account as Account; int goldcount = 0; int accountcount = acct == null ? 0 : acct.TotalGold; foreach (Item item in items) { goldcount += item.Amount; } if (goldcount >= amount) { foreach (Item item in items) { if (item.Amount <= amount) { item.Delete(); amount -= item.Amount; } else { item.Amount -= amount; amount = 0; } if (amount == 0) { break; } } } else if (goldcount + accountcount >= amount) { foreach (Item item in items) { amount -= item.Amount; item.Delete(); } Banker.Withdraw(from, amount); } else { from.SendLocalizedMessage(1073182); // You do not have enough to make a donation of that magnitude! from.SendGump(new CommunityCollectionGump((PlayerMobile)from, m_Collection, m_Location)); return; } m_Collection.Donate((PlayerMobile)from, m_Selected, amount); return; } else if (m_Selected.Type == typeof(Fish) || m_Selected.Type == typeof(Crab) || m_Selected.Type == typeof(Lobster) || m_Selected.Type == typeof(RedScales)) { if (amount * m_Selected.Points < 1) { from.SendLocalizedMessage(1073167); // You do not have enough of that item to make a donation! from.SendGump(new CommunityCollectionGump((PlayerMobile)from, m_Collection, m_Location)); return; } Item[] items; if (m_Selected.Type == typeof(Fish)) { items = CommunityCollectionGump.FindFishyItems(from.Backpack); } else if (m_Selected.Type == typeof(RedScales)) { items = CommunityCollectionGump.FindScales(from.Backpack); } else { items = CommunityCollectionGump.FindCrabsAndLobsters(from.Backpack); } if (items != null) { // count items int count = 0; for (int i = 0; i < items.Length; i++) { if (m_Selected.Validate((PlayerMobile)from, items[i]) && !items[i].Deleted) { count += items[i].Amount; } } // check if (amount > count) { from.SendLocalizedMessage(1073182); // You do not have enough to make a donation of that magnitude! from.SendGump(new CommunityCollectionGump((PlayerMobile)from, m_Collection, m_Location)); return; } else if (amount * m_Selected.Points < 1) { from.SendLocalizedMessage(1073167); // You do not have enough of that item to make a donation! from.SendGump(new CommunityCollectionGump((PlayerMobile)from, m_Collection, m_Location)); return; } // donate int deleted = 0; for (int i = 0; i < items.Length && deleted < amount; i++) { if (m_Selected.Validate((PlayerMobile)from, items[i]) && items[i].Stackable && items[i].Amount + deleted > amount && !items[i].Deleted) { items[i].Amount -= amount - deleted; deleted += amount - deleted; } else if (m_Selected.Validate((PlayerMobile)from, items[i]) && !items[i].Deleted) { deleted += items[i].Amount; items[i].Delete(); } } m_Collection.Donate((PlayerMobile)from, m_Selected, amount); return; } else { from.SendLocalizedMessage(1073182); // You do not have enough to make a donation of that magnitude! } } if (m_Selected.Type == typeof(BankCheck)) { int count = from.Backpack.GetChecksWorth(true); if (count < amount) { from.SendLocalizedMessage(1073182); // You do not have enough to make a donation of that magnitude! return; } } else { int count = from.Backpack.GetAmount(m_Selected.Type, true, true); if (count < amount) { if (m_Selected.Type == typeof(Gold)) { from.SendLocalizedMessage(1073182); // You do not have enough to make a donation of that magnitude! } else { from.SendLocalizedMessage(1073167); // You do not have enough of that item to make a donation! } return; } } // Donate if (m_Selected.Type == typeof(BankCheck)) { from.Backpack.TakeFromChecks(amount, true); } else { from.Backpack.ConsumeTotal(m_Selected.Type, amount, true, true); } m_Collection.Donate((PlayerMobile)from, m_Selected, amount); }
public override void OnResponse(Mobile from, string text) { if (!from.InRange(m_Location, 2) || !(from is PlayerMobile)) { return; } from.SendGump(new ComunityCollectionGump((PlayerMobile)from, m_Collection, m_Location)); int amount = Utility.ToInt32(text); if (amount <= 0) { from.SendLocalizedMessage(1073181); // That is not a valid donation quantity. return; } Item[] items = from.Backpack != null?from.Backpack.FindItemsByType(m_Selected.Type, true) : null; if (items != null) { // count items int count = 0; for (int i = 0; i < items.Length; i++) { if (items[i] is BankCheck && !items[i].Deleted) { count += ((BankCheck)items[i]).Worth; } else if (m_Selected.Validate((PlayerMobile)from, items[i]) && !items[i].Deleted) { count += items[i].Amount; } } // check if (amount > count) { from.SendLocalizedMessage(1073182); // You do not have enough to make a donation of that magnitude! return; } else if (amount * m_Selected.Points < 1) { from.SendLocalizedMessage(1073167); // You do not have enough of that item to make a donation! return; } // donate int deleted = 0; for (int i = 0; i < items.Length && deleted < amount; i++) { if (items[i] is BankCheck && !items[i].Deleted) { BankCheck check = (BankCheck)items[i]; if (check.Worth + deleted > amount) { check.Worth -= amount - deleted; deleted += amount - deleted; } else { deleted += check.Worth; check.Delete(); } } else if (m_Selected.Validate((PlayerMobile)from, items[i]) && items[i].Stackable && items[i].Amount + deleted > amount && !items[i].Deleted) { items[i].Amount -= amount - deleted; deleted += amount - deleted; } else if (m_Selected.Validate((PlayerMobile)from, items[i]) && !items[i].Deleted) { deleted += items[i].Amount; items[i].Delete(); } } m_Collection.Donate((PlayerMobile)from, m_Selected, amount); } else { from.SendLocalizedMessage(1073182); // You do not have enough to make a donation of that magnitude! } }