protected override void OnTarget(Mobile from, object targeted) { DonationEntry entry = m_Collection.Donations[m_EntryIndex]; if (!(targeted is Item) || !((Item)targeted).IsChildOf(from.Backpack) || targeted.GetType() != entry.Type) { from.SendLocalizedMessage(1073390); // The item you selected to donate is not of the type you picked. } else if (targeted is TreasureMap && !CollectionController.CheckTreasureMap((TreasureMap)targeted, entry.Award)) { from.SendLocalizedMessage(1073390); // The item you selected to donate is not of the type you picked. } else { ((Item)targeted).Delete(); m_Collection.Award(from, (int)entry.Award); } from.SendGump(new CollectionDonateGump(m_Collection, from)); }
public override void OnResponse(NetState sender, RelayInfo info) { if (m_ExpireTimer != null) { m_ExpireTimer.Stop(); } if (info.ButtonID == 2) { double award = 0.0; if (m_Pet.ControlMaster != sender.Mobile) { return; } if (!m_Collection.CheckType(m_Pet, out award)) { sender.Mobile.SendLocalizedMessage(1073113); // This Collection is not accepting that type of creature. return; } /*if ( ( m_Collection.Points + award ) > m_Collection.PointsPerTier && m_Collection.Tier >= m_Collection.MaxTiers ) * { * sender.Mobile.SendLocalizedMessage( 1072815 ); // This Collection is too full to accept this item right now. * return; * }*/ m_Pet.Delete(); m_Collection.Award(sender.Mobile, (int)award); sender.Mobile.SendGump(new CollectionDonateGump(m_Collection, sender.Mobile)); } else { sender.Mobile.SendLocalizedMessage(1073114); // You decide to not transfer this follower. } }
/// <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); } }