ModernUO/Scripts/Items/Misc/Gold.cs
2018-08-19 21:28:24 +08:00

144 lines
2.8 KiB
C#

using System;
using Server.Accounting;
namespace Server.Items
{
public class Gold : Item
{
public override double DefaultWeight
{
get { return ( Core.ML ? ( 0.02 / 3 ) : 0.02 ); }
}
[Constructible]
public Gold() : this( 1 )
{
}
[Constructible]
public Gold( int amountFrom, int amountTo ) : this( Utility.RandomMinMax( amountFrom, amountTo ) )
{
}
[Constructible]
public Gold( int amount ) : base( 0xEED )
{
Stackable = true;
Amount = amount;
}
public Gold( Serial serial ) : base( serial )
{
}
public override int GetDropSound()
{
if ( Amount <= 1 )
return 0x2E4;
else if ( Amount <= 5 )
return 0x2E5;
else
return 0x2E6;
}
protected override void OnAmountChange( int oldValue )
{
int newValue = this.Amount;
UpdateTotal( this, TotalType.Gold, newValue - oldValue );
}
#if NEWPARENT
public override void OnAdded(IEntity parent)
#else
public override void OnAdded(object parent)
#endif
{
base.OnAdded(parent);
if (!AccountGold.Enabled)
{
return;
}
Mobile owner = null;
SecureTradeInfo tradeInfo = null;
Container root = parent as Container;
while (root != null && root.Parent is Container)
{
root = (Container)root.Parent;
}
parent = root ?? parent;
if (parent is SecureTradeContainer trade && AccountGold.ConvertOnTrade)
{
if (trade.Trade.From.Container == trade)
{
tradeInfo = trade.Trade.From;
owner = tradeInfo.Mobile;
}
else if (trade.Trade.To.Container == trade)
{
tradeInfo = trade.Trade.To;
owner = tradeInfo.Mobile;
}
}
else if (parent is BankBox box && AccountGold.ConvertOnBank)
{
owner = box.Owner;
}
if (owner?.Account == null || !owner.Account.DepositGold(Amount))
{
return;
}
if (tradeInfo != null)
{
if (owner.NetState != null && !owner.NetState.NewSecureTrading)
{
int plat = Math.DivRem(Amount, AccountGold.CurrencyThreshold, out var gold);
tradeInfo.Plat += plat;
tradeInfo.Gold += gold;
}
tradeInfo.VirtualCheck?.UpdateTrade(tradeInfo.Mobile);
}
owner.SendLocalizedMessage(1042763, Amount.ToString("#,0"));
Delete();
((Container)parent).UpdateTotals();
}
public override int GetTotal( TotalType type )
{
int baseTotal = base.GetTotal( type );
if ( type == TotalType.Gold )
baseTotal += this.Amount;
return baseTotal;
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 ); // version
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
}