public void SetAccount(IAccount acc) { if (Account == acc) { return; } ++Version; Extra += "{ACCOUNT CHANGED FROM '" + Account + "' TO '" + acc + "'}"; var profile = AutoDonate.FindProfile(Account); if (profile != null) { profile.Remove(this); } Account = acc; profile = AutoDonate.EnsureProfile(Account); if (profile != null) { profile.Add(this); } LogToFile(); }
protected override void Compile() { _Admin = User.AccessLevel >= AutoDonate.Access; if (Profile == null || Profile.Account == null || (!_Admin && User.AccessLevel <= Profile.Account.AccessLevel && !Profile.Account.IsSharedWith(User.Account))) { Profile = AutoDonate.EnsureProfile(User.Account); } if (Profile != null) { _DonationTier = Profile.Tier; _DonationValue = Profile.TotalValue; _DonationCredit = Profile.TotalCredit; _DonationCount = _Admin ? Profile.Transactions.Count : Profile.Visible.Count(); Title = "Donations: " + Profile.Account; } base.Compile(); }
private bool Deliver(string message, params object[] args) { IAccount a = DeliverTo.Account; if (a == null) { return(false); } if (AutoDonate.Find(a) == null) { AutoDonate.Register(a, new DonationProfile(a)); } AutoDonate.Profiles[a].Credits += _Credit; if (IsGift) { AutoDonate.Profiles[a].AddGift(this, message, args); } return(DeliveryConversion()); }
private void Deliver(Mobile m) { if (m == null || m.Account == null) { return; } if (Account != m.Account) { SetAccount(m.Account); } var dp = AutoDonate.EnsureProfile(Account); if (dp == null) { return; } long credit, bonus; var total = GetCredit(dp, true, out credit, out bonus); Credit = credit; Bonus = bonus; var bag = DonationEvents.InvokeTransPack(this, dp); if (bag == null || bag.Deleted) { dp.Credit += total; return; } Protect(bag); while (credit > 0) { var cur = AutoDonate.CMOptions.CurrencyType.CreateInstance(); if (cur == null) { bag.Delete(); break; } Protect(cur); if (cur.Stackable) { cur.Amount = (int)Math.Min(credit, 60000); } credit -= cur.Amount; bag.DropItem(cur); } if (bag.Deleted) { dp.Credit += total; return; } while (bonus > 0) { var cur = AutoDonate.CMOptions.CurrencyType.CreateInstance(); if (cur == null) { bag.Delete(); break; } Protect(cur); cur.Name = String.Format("{0} [Bonus]", cur.ResolveName(m)); if (cur.Stackable) { cur.Amount = (int)Math.Min(bonus, 60000); } bonus -= cur.Amount; bag.DropItem(cur); } if (bag.Deleted || bag.GiveTo(m, GiveFlags.PackBankDelete) == GiveFlags.Delete) { dp.Credit += total; } }
private bool DeliveryConversion() { const int amountCap = 60000; double exchangeRate = AutoDonate.CMOptions.ExchangeRate; DonationProfile dp = AutoDonate.Find(DeliverTo.Account); Container bank = DeliverTo.BankBox; if (bank != null) { Bag bag = new Bag(); if (IsGift) { bag.Name = "A Donation Gift Bag"; bag.Hue = 1152; string text = dp.Gifts.ContainsKey(ID) ? dp.Gifts[ID] : null; if (String.IsNullOrWhiteSpace(text)) { text = "Hi, " + DeliverTo.RawName + ", "; text += "Here is a gift, a token of my appreciation. "; text += "Don't spend it all in one place! "; text += "Regards, " + DeliverFrom.RawName; } bag.DropItem(new DonationGiftBook(DeliverFrom, text)); } else { bag.Name = "A Donation Reward Bag"; bag.Hue = 1152; } long exchanged = (long)(Credit * exchangeRate); while (exchanged >= amountCap) { Item cur = AutoDonate.CMOptions.CurrencyType.CreateInstance(); cur.Amount = amountCap; bag.DropItem(cur); if (cur.IsChildOf(bag)) { exchanged -= cur.Amount; } } if (exchanged > 0) { Item cur = AutoDonate.CMOptions.CurrencyType.CreateInstance(); cur.Amount = (int)exchanged; bag.DropItem(cur); if (cur.IsChildOf(bag)) { exchanged -= cur.Amount; } } if (exchanged > 0) { bag.Delete(); return(false); } bank.DropItem(bag); dp.Credits -= Credit; } return(true); }