public bool TransferTokens(IVoteSite site, int amount, bool message = true) { if (site == null || Deleted || Owner == null || Owner.Deleted) { return(false); } bool limitReached = false; int total = GetTokenTotal(DateTime.UtcNow); if (Voting.CMOptions.DailyLimit > 0) { if (total >= Voting.CMOptions.DailyLimit) { limitReached = true; amount = 0; } else if ((total + amount) > Voting.CMOptions.DailyLimit) { limitReached = true; amount = (total + amount) - Voting.CMOptions.DailyLimit; } } if (amount > 0) { var token = new VoteToken(amount); string name = token.ResolveName(Owner.GetLanguage()); if (Owner.Backpack.TryDropItem(Owner, token, true)) { if (message) { Owner.SendMessage( 0x55, "{0}{1}{2} {3} been placed in your backpack.", (!name.StartsWith("a") && amount == 1) ? "a" : String.Empty, name, (!name.EndsWith("s") && amount > 1) ? "s" : String.Empty, (amount > 1) ? "have" : "has"); } } else if (Owner.BankBox.TryDropItem(Owner, token, true)) { if (message) { Owner.SendMessage( 0x55, "{0}{1}{2} {3} been placed in your bank.", (!name.StartsWith("a") && amount == 1) ? "a" : String.Empty, name, (!name.EndsWith("s") && amount > 1) ? "s" : String.Empty, (amount > 1) ? "have" : "has"); } } else { if (Owner.NetState == null) { token.MoveToWorld(Owner.LogoutLocation, Owner.LogoutMap); } else { token.MoveToWorld(Owner.Location, Owner.Map); } if (message) { Owner.SendMessage( 0x55, "{0}{1}{2} {3} been placed at your feet.", (!name.StartsWith("a") && amount == 1) ? "a" : String.Empty, name, (!name.EndsWith("s") && amount > 1) ? "s" : String.Empty, (amount > 1) ? "have" : "has"); } } } if (limitReached && message) { Owner.SendMessage( 0x22, "You have reached your daily token limit of {0}.", Voting.CMOptions.DailyLimit.ToString("#,#")); } RegisterTokens(site, amount); return(true); }
public bool TransferTokens(IVoteSite site, int amount, bool message = true) { if (site == null || Deleted || Owner == null || Owner.Deleted) { return false; } bool limitReached = false; int total = GetTokenTotal(DateTime.UtcNow); if (Voting.CMOptions.DailyLimit > 0) { if (total >= Voting.CMOptions.DailyLimit) { limitReached = true; amount = 0; } else if ((total + amount) > Voting.CMOptions.DailyLimit) { limitReached = true; amount = (total + amount) - Voting.CMOptions.DailyLimit; } } if (amount > 0) { var token = new VoteToken(amount); string name = token.ResolveName(Owner.GetLanguage()); if (Owner.Backpack.TryDropItem(Owner, token, true)) { if (message) { Owner.SendMessage( 0x55, "{0}{1}{2} {3} been placed in your backpack.", (!name.StartsWith("a") && amount == 1) ? "a" : String.Empty, name, (!name.EndsWith("s") && amount > 1) ? "s" : String.Empty, (amount > 1) ? "have" : "has"); } } else if (Owner.BankBox.TryDropItem(Owner, token, true)) { if (message) { Owner.SendMessage( 0x55, "{0}{1}{2} {3} been placed in your bank.", (!name.StartsWith("a") && amount == 1) ? "a" : String.Empty, name, (!name.EndsWith("s") && amount > 1) ? "s" : String.Empty, (amount > 1) ? "have" : "has"); } } else { if (Owner.NetState == null) { token.MoveToWorld(Owner.LogoutLocation, Owner.LogoutMap); } else { token.MoveToWorld(Owner.Location, Owner.Map); } if (message) { Owner.SendMessage( 0x55, "{0}{1}{2} {3} been placed at your feet.", (!name.StartsWith("a") && amount == 1) ? "a" : String.Empty, name, (!name.EndsWith("s") && amount > 1) ? "s" : String.Empty, (amount > 1) ? "have" : "has"); } } } if (limitReached && message) { Owner.SendMessage(0x22, "You have reached your daily token limit of {0:#,0}.", Voting.CMOptions.DailyLimit); } RegisterTokens(site, amount); return true; }