Clean up: Bugs, LINQ, constructors, default values, and null checks (#18)
This commit is contained in:
parent
e748af4430
commit
513e54f70e
1094 changed files with 15913 additions and 21892 deletions
|
|
@ -22,9 +22,8 @@ using System;
|
|||
|
||||
namespace Server.Items
|
||||
{
|
||||
public class BaseMulti : Item
|
||||
public abstract class BaseMulti : Item
|
||||
{
|
||||
[Constructible]
|
||||
public BaseMulti(int itemID) : base(itemID)
|
||||
{
|
||||
Movable = false;
|
||||
|
|
@ -162,4 +161,4 @@ namespace Server.Items
|
|||
ItemID -= 0x4000;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ namespace Server.Items
|
|||
|
||||
public virtual bool CheckHold(Mobile m, Item item, bool message, bool checkItems, int plusItems, int plusWeight)
|
||||
{
|
||||
if (m != null && m.AccessLevel < AccessLevel.GameMaster)
|
||||
if (m?.AccessLevel < AccessLevel.GameMaster)
|
||||
{
|
||||
if (IsDecoContainer)
|
||||
{
|
||||
|
|
@ -607,15 +607,13 @@ namespace Server.Items
|
|||
{
|
||||
DisplayTo(from);
|
||||
|
||||
SecureTradeContainer cont = GetSecureTradeCont();
|
||||
SecureTrade trade = GetSecureTradeCont()?.Trade;
|
||||
|
||||
if (cont != null)
|
||||
if (trade != null)
|
||||
{
|
||||
SecureTrade trade = cont.Trade;
|
||||
|
||||
if (trade != null && trade.From.Mobile == from)
|
||||
if (trade.From.Mobile == from)
|
||||
DisplayTo(trade.To.Mobile);
|
||||
else if (trade != null && trade.To.Mobile == from)
|
||||
else if (trade.To.Mobile == from)
|
||||
DisplayTo(trade.From.Mobile);
|
||||
}
|
||||
}
|
||||
|
|
@ -675,50 +673,50 @@ namespace Server.Items
|
|||
|
||||
public void ProcessOpeners(Mobile opener)
|
||||
{
|
||||
if (!IsPublicContainer)
|
||||
if (IsPublicContainer)
|
||||
return;
|
||||
|
||||
bool contains = false;
|
||||
|
||||
if (Openers != null)
|
||||
{
|
||||
bool contains = false;
|
||||
Point3D worldLoc = GetWorldLocation();
|
||||
Map map = Map;
|
||||
|
||||
if (Openers != null)
|
||||
for (int i = 0; i < Openers.Count; ++i)
|
||||
{
|
||||
Point3D worldLoc = GetWorldLocation();
|
||||
Map map = Map;
|
||||
Mobile mob = Openers[i];
|
||||
|
||||
for (int i = 0; i < Openers.Count; ++i)
|
||||
if (mob == opener)
|
||||
{
|
||||
Mobile mob = Openers[i];
|
||||
contains = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
int range = GetUpdateRange(mob);
|
||||
|
||||
if (mob == opener)
|
||||
{
|
||||
contains = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
int range = GetUpdateRange(mob);
|
||||
|
||||
if (mob.Map != map || !mob.InRange(worldLoc, range))
|
||||
Openers.RemoveAt(i--);
|
||||
}
|
||||
if (mob.Map != map || !mob.InRange(worldLoc, range))
|
||||
Openers.RemoveAt(i--);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!contains)
|
||||
{
|
||||
if (Openers == null)
|
||||
Openers = new List<Mobile>();
|
||||
if (!contains)
|
||||
{
|
||||
if (Openers == null)
|
||||
Openers = new List<Mobile>();
|
||||
|
||||
Openers.Add(opener);
|
||||
}
|
||||
else if (Openers != null && Openers.Count == 0)
|
||||
{
|
||||
Openers = null;
|
||||
}
|
||||
Openers.Add(opener);
|
||||
}
|
||||
else if (Openers?.Count == 0)
|
||||
{
|
||||
Openers = null;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void SendContentTo(NetState state)
|
||||
{
|
||||
if (state != null && state.ContainerGridLines)
|
||||
if (state?.ContainerGridLines == true)
|
||||
state.Send(new ContainerContent6017(state.Mobile, this));
|
||||
else
|
||||
state.Send(new ContainerContent(state.Mobile, this));
|
||||
|
|
@ -1122,17 +1120,7 @@ namespace Server.Items
|
|||
return -1;
|
||||
}
|
||||
|
||||
public int ConsumeTotal(Type[] types, int[] amounts)
|
||||
{
|
||||
return ConsumeTotal(types, amounts, true, null);
|
||||
}
|
||||
|
||||
public int ConsumeTotal(Type[] types, int[] amounts, bool recurse)
|
||||
{
|
||||
return ConsumeTotal(types, amounts, recurse, null);
|
||||
}
|
||||
|
||||
public int ConsumeTotal(Type[] types, int[] amounts, bool recurse, OnItemConsumed callback)
|
||||
public int ConsumeTotal(Type[] types, int[] amounts, bool recurse = true, OnItemConsumed callback = null)
|
||||
{
|
||||
if (types.Length != amounts.Length)
|
||||
throw new ArgumentException();
|
||||
|
|
@ -1181,17 +1169,7 @@ namespace Server.Items
|
|||
return -1;
|
||||
}
|
||||
|
||||
public bool ConsumeTotal(Type type, int amount)
|
||||
{
|
||||
return ConsumeTotal(type, amount, true, null);
|
||||
}
|
||||
|
||||
public bool ConsumeTotal(Type type, int amount, bool recurse)
|
||||
{
|
||||
return ConsumeTotal(type, amount, recurse, null);
|
||||
}
|
||||
|
||||
public bool ConsumeTotal(Type type, int amount, bool recurse, OnItemConsumed callback)
|
||||
public bool ConsumeTotal(Type type, int amount = 1, bool recurse = true, OnItemConsumed callback = null)
|
||||
{
|
||||
Item[] items = FindItemsByType(type, recurse);
|
||||
|
||||
|
|
@ -1234,12 +1212,7 @@ namespace Server.Items
|
|||
return false;
|
||||
}
|
||||
|
||||
public int ConsumeUpTo(Type type, int amount)
|
||||
{
|
||||
return ConsumeUpTo(type, amount, true);
|
||||
}
|
||||
|
||||
public int ConsumeUpTo(Type type, int amount, bool recurse)
|
||||
public int ConsumeUpTo(Type type, int amount, bool recurse = true)
|
||||
{
|
||||
int consumed = 0;
|
||||
|
||||
|
|
@ -1256,37 +1229,37 @@ namespace Server.Items
|
|||
private static void RecurseConsumeUpTo(Item current, Type type, int amount, bool recurse, ref int consumed,
|
||||
Queue<Item> toDelete)
|
||||
{
|
||||
if (current != null && current.Items.Count > 0)
|
||||
if (current == null || current.Items.Count == 0)
|
||||
return;
|
||||
|
||||
List<Item> list = current.Items;
|
||||
|
||||
for (int i = 0; i < list.Count; ++i)
|
||||
{
|
||||
List<Item> list = current.Items;
|
||||
Item item = list[i];
|
||||
|
||||
for (int i = 0; i < list.Count; ++i)
|
||||
if (type.IsInstanceOfType(item))
|
||||
{
|
||||
Item item = list[i];
|
||||
int need = amount - consumed;
|
||||
int theirAmount = item.Amount;
|
||||
|
||||
if (type.IsInstanceOfType(item))
|
||||
if (theirAmount <= need)
|
||||
{
|
||||
int need = amount - consumed;
|
||||
int theirAmount = item.Amount;
|
||||
|
||||
if (theirAmount <= need)
|
||||
{
|
||||
toDelete.Enqueue(item);
|
||||
consumed += theirAmount;
|
||||
}
|
||||
else
|
||||
{
|
||||
item.Amount -= need;
|
||||
consumed += need;
|
||||
|
||||
return;
|
||||
}
|
||||
toDelete.Enqueue(item);
|
||||
consumed += theirAmount;
|
||||
}
|
||||
else if (recurse && item is Container)
|
||||
else
|
||||
{
|
||||
RecurseConsumeUpTo(item, type, amount, true, ref consumed, toDelete);
|
||||
item.Amount -= need;
|
||||
consumed += need;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (recurse && item is Container)
|
||||
{
|
||||
RecurseConsumeUpTo(item, type, amount, true, ref consumed, toDelete);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1572,7 +1545,7 @@ namespace Server.Items
|
|||
|
||||
private static Item RecurseFindItemByType(Item current, Type[] types, bool recurse)
|
||||
{
|
||||
if (current == null || current.Items.Count <= 0)
|
||||
if (current == null || current.Items.Count == 0)
|
||||
return null;
|
||||
|
||||
List<Item> list = current.Items;
|
||||
|
|
@ -1635,12 +1608,12 @@ namespace Server.Items
|
|||
}
|
||||
}
|
||||
|
||||
public T FindItemByType<T>(bool recurse = true, Predicate<T> predicate = null) where T : Item
|
||||
public T FindItemByType<T>(bool recurse = true) where T : Item
|
||||
{
|
||||
return RecurseFindItemByType(this, recurse, predicate);
|
||||
return RecurseFindItemByType<T>(this, recurse);
|
||||
}
|
||||
|
||||
private static T RecurseFindItemByType<T>(Item current, bool recurse, Predicate<T> predicate) where T : Item
|
||||
private static T RecurseFindItemByType<T>(Item current, bool recurse = true, Predicate<T> predicate = null) where T : Item
|
||||
{
|
||||
if (current == null || current.Items.Count == 0)
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -97,8 +97,8 @@ namespace Server.Items
|
|||
{
|
||||
Opened = false;
|
||||
|
||||
if (Owner != null && SendDeleteOnClose)
|
||||
Owner.Send(RemovePacket);
|
||||
if (SendDeleteOnClose)
|
||||
Owner?.Send(RemovePacket);
|
||||
}
|
||||
|
||||
public override void OnSingleClick(Mobile from)
|
||||
|
|
@ -116,30 +116,26 @@ namespace Server.Items
|
|||
|
||||
public override bool IsAccessibleTo(Mobile check)
|
||||
{
|
||||
if (check == Owner && Opened || check.AccessLevel >= AccessLevel.GameMaster)
|
||||
return base.IsAccessibleTo(check);
|
||||
return false;
|
||||
return (check == Owner && Opened || check.AccessLevel >= AccessLevel.GameMaster) && base.IsAccessibleTo(check);
|
||||
}
|
||||
|
||||
public override bool OnDragDrop(Mobile from, Item dropped)
|
||||
{
|
||||
if (from == Owner && Opened || from.AccessLevel >= AccessLevel.GameMaster)
|
||||
return base.OnDragDrop(from, dropped);
|
||||
return false;
|
||||
return (from == Owner && Opened || from.AccessLevel >= AccessLevel.GameMaster) && base.OnDragDrop(from, dropped);
|
||||
}
|
||||
|
||||
public override bool OnDragDropInto(Mobile from, Item item, Point3D p)
|
||||
{
|
||||
if (from == Owner && Opened || from.AccessLevel >= AccessLevel.GameMaster)
|
||||
return base.OnDragDropInto(from, item, p);
|
||||
return false;
|
||||
return (from == Owner && Opened || from.AccessLevel >= AccessLevel.GameMaster) &&
|
||||
base.OnDragDropInto(from, item, p);
|
||||
}
|
||||
|
||||
public override int GetTotal(TotalType type)
|
||||
{
|
||||
if (AccountGold.Enabled && Owner?.Account != null && type == TotalType.Gold) return Owner.Account.TotalGold;
|
||||
if (AccountGold.Enabled && Owner?.Account != null && type == TotalType.Gold)
|
||||
return Owner.Account.TotalGold;
|
||||
|
||||
return base.GetTotal(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,12 +42,7 @@ namespace Server.Items
|
|||
{
|
||||
if (item == Trade.From.VirtualCheck || item == Trade.To.VirtualCheck) return true;
|
||||
|
||||
Mobile to;
|
||||
|
||||
if (Trade.From.Container != this)
|
||||
to = Trade.From.Mobile;
|
||||
else
|
||||
to = Trade.To.Mobile;
|
||||
Mobile to = Trade.From.Container != this ? Trade.From.Mobile : Trade.To.Mobile;
|
||||
|
||||
return m.CheckTrade(to, item, this, message, checkItems, plusItems, plusWeight);
|
||||
}
|
||||
|
|
@ -60,49 +55,52 @@ namespace Server.Items
|
|||
|
||||
public override bool IsAccessibleTo(Mobile check)
|
||||
{
|
||||
if (!IsChildOf(check) || Trade == null || !Trade.Valid)
|
||||
return false;
|
||||
|
||||
return base.IsAccessibleTo(check);
|
||||
return IsChildOf(check) && Trade?.Valid == true && base.IsAccessibleTo(check);
|
||||
}
|
||||
|
||||
public override void OnItemAdded(Item item)
|
||||
{
|
||||
if (!(item is VirtualCheck)) ClearChecks();
|
||||
if (!(item is VirtualCheck))
|
||||
ClearChecks();
|
||||
}
|
||||
|
||||
public override void OnItemRemoved(Item item)
|
||||
{
|
||||
if (!(item is VirtualCheck)) ClearChecks();
|
||||
if (!(item is VirtualCheck))
|
||||
ClearChecks();
|
||||
}
|
||||
|
||||
public override void OnSubItemAdded(Item item)
|
||||
{
|
||||
if (!(item is VirtualCheck)) ClearChecks();
|
||||
if (!(item is VirtualCheck))
|
||||
ClearChecks();
|
||||
}
|
||||
|
||||
public override void OnSubItemRemoved(Item item)
|
||||
{
|
||||
if (!(item is VirtualCheck)) ClearChecks();
|
||||
if (!(item is VirtualCheck))
|
||||
ClearChecks();
|
||||
}
|
||||
|
||||
public void ClearChecks()
|
||||
{
|
||||
if (Trade != null)
|
||||
{
|
||||
if (Trade.From != null && !Trade.From.IsDisposed) Trade.From.Accepted = false;
|
||||
if (Trade == null)
|
||||
return;
|
||||
|
||||
if (Trade.To != null && !Trade.To.IsDisposed) Trade.To.Accepted = false;
|
||||
if (Trade.From?.IsDisposed == false)
|
||||
Trade.From.Accepted = false;
|
||||
|
||||
Trade.Update();
|
||||
}
|
||||
if (Trade.To?.IsDisposed == false)
|
||||
Trade.To.Accepted = false;
|
||||
|
||||
Trade.Update();
|
||||
}
|
||||
|
||||
public override bool IsChildVisibleTo(Mobile m, Item child)
|
||||
{
|
||||
if (child is VirtualCheck) return AccountGold.Enabled && (m.NetState == null || !m.NetState.NewSecureTrading);
|
||||
|
||||
return base.IsChildVisibleTo(m, child);
|
||||
return child is VirtualCheck
|
||||
? AccountGold.Enabled && m.NetState?.NewSecureTrading != true
|
||||
: base.IsChildVisibleTo(m, child);
|
||||
}
|
||||
|
||||
public override void Serialize(GenericWriter writer)
|
||||
|
|
@ -119,4 +117,4 @@ namespace Server.Items
|
|||
int version = reader.ReadInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,7 @@
|
|||
#region Header
|
||||
|
||||
// **********
|
||||
// ServUO - VirtualCheck.cs
|
||||
// **********
|
||||
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
|
||||
using System.Drawing;
|
||||
using Server.Gumps;
|
||||
using Server.Items;
|
||||
using Server.Network;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public sealed class VirtualCheck : Item
|
||||
|
|
@ -25,12 +12,7 @@ namespace Server
|
|||
|
||||
private int _Plat;
|
||||
|
||||
public VirtualCheck()
|
||||
: this(0, 0)
|
||||
{
|
||||
}
|
||||
|
||||
public VirtualCheck(int plat, int gold)
|
||||
public VirtualCheck(int plat = 0, int gold = 0)
|
||||
: base(0x14F0)
|
||||
{
|
||||
Plat = plat;
|
||||
|
|
@ -90,7 +72,7 @@ namespace Server
|
|||
{
|
||||
if (UseEditGump && IsAccessibleTo(from))
|
||||
{
|
||||
if (Editor?.Check == null || Editor.Check.Deleted)
|
||||
if (Editor?.Check?.Deleted != false)
|
||||
{
|
||||
Editor = new EditGump(from, this);
|
||||
Editor.Send();
|
||||
|
|
@ -196,14 +178,15 @@ namespace Server
|
|||
{
|
||||
base.OnServerClose(owner);
|
||||
|
||||
if (Check != null && !Check.Deleted) Check.UpdateTrade(User);
|
||||
if (Check?.Deleted == false)
|
||||
Check.UpdateTrade(User);
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
User.CloseGump<EditGump>();
|
||||
|
||||
if (Check != null && !Check.Deleted)
|
||||
if (Check?.Deleted == false)
|
||||
Check.UpdateTrade(User);
|
||||
else
|
||||
Check = null;
|
||||
|
|
@ -211,7 +194,7 @@ namespace Server
|
|||
|
||||
public void Send()
|
||||
{
|
||||
if (Check != null && !Check.Deleted)
|
||||
if (Check?.Deleted == false)
|
||||
User.SendGump(this);
|
||||
else
|
||||
Close();
|
||||
|
|
@ -219,13 +202,14 @@ namespace Server
|
|||
|
||||
public void Refresh(bool recompile)
|
||||
{
|
||||
if (Check == null || Check.Deleted)
|
||||
if (Check?.Deleted != false)
|
||||
{
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
if (recompile) CompileLayout();
|
||||
if (recompile)
|
||||
CompileLayout();
|
||||
|
||||
Close();
|
||||
Send();
|
||||
|
|
@ -233,7 +217,8 @@ namespace Server
|
|||
|
||||
private void CompileLayout()
|
||||
{
|
||||
if (Check == null || Check.Deleted) return;
|
||||
if (Check?.Deleted != false)
|
||||
return;
|
||||
|
||||
Entries.ForEach(e => e.Parent = null);
|
||||
Entries.Clear();
|
||||
|
|
@ -248,9 +233,9 @@ namespace Server
|
|||
AddImage(360, 8, 113);
|
||||
|
||||
string title =
|
||||
$"<BASEFONT COLOR=#{Color.DarkSlateGray.ToArgb():X}><CENTER>BANK OF {User.RawName.ToUpper()}</CENTER>";
|
||||
$"<BASEFONT COLOR=#FF2F4F4F><CENTER>BANK OF {User.RawName.ToUpper()}</CENTER>";
|
||||
|
||||
AddHtml(40, 15, 320, 20, title, false, false);
|
||||
AddHtml(40, 15, 320, 20, title);
|
||||
|
||||
// Platinum Row
|
||||
AddBackground(15, 60, 175, 20, 9300);
|
||||
|
|
@ -258,7 +243,7 @@ namespace Server
|
|||
AddItem(20, 45, 3826); // Plat
|
||||
AddLabel(60, 50, 0, User.Account.TotalPlat.ToString("#,0"));
|
||||
|
||||
AddButton(195, 50, 95, 95, (int)Buttons.AllPlat, GumpButtonType.Reply, 0); // ->
|
||||
AddButton(195, 50, 95, 95, (int)Buttons.AllPlat); // ->
|
||||
|
||||
AddBackground(210, 60, 175, 20, 9300);
|
||||
AddBackground(215, 45, 165, 30, 9350);
|
||||
|
|
@ -270,21 +255,21 @@ namespace Server
|
|||
AddItem(20, 85, 3823); // Gold
|
||||
AddLabel(60, 90, 0, User.Account.TotalGold.ToString("#,0"));
|
||||
|
||||
AddButton(195, 90, 95, 95, (int)Buttons.AllGold, GumpButtonType.Reply, 0); // ->
|
||||
AddButton(195, 90, 95, 95, (int)Buttons.AllGold); // ->
|
||||
|
||||
AddBackground(210, 100, 175, 20, 9300);
|
||||
AddBackground(215, 85, 165, 30, 9350);
|
||||
AddTextEntry(225, 90, 145, 20, 0, 1, _Gold.ToString(), User.Account.TotalGold.ToString().Length);
|
||||
|
||||
// Buttons
|
||||
AddButton(20, 128, 12006, 12007, (int)Buttons.Close, GumpButtonType.Reply, 0);
|
||||
AddButton(215, 128, 12003, 12004, (int)Buttons.Clear, GumpButtonType.Reply, 0);
|
||||
AddButton(305, 128, 12000, 12002, (int)Buttons.Accept, GumpButtonType.Reply, 0);
|
||||
AddButton(20, 128, 12006, 12007, (int)Buttons.Close);
|
||||
AddButton(215, 128, 12003, 12004, (int)Buttons.Clear);
|
||||
AddButton(305, 128, 12000, 12002, (int)Buttons.Accept);
|
||||
}
|
||||
|
||||
public override void OnResponse(NetState sender, RelayInfo info)
|
||||
{
|
||||
if (Check == null || Check.Deleted || sender.Mobile != User)
|
||||
if (Check?.Deleted != false || sender.Mobile != User)
|
||||
{
|
||||
Close();
|
||||
return;
|
||||
|
|
@ -352,9 +337,10 @@ namespace Server
|
|||
break;
|
||||
}
|
||||
|
||||
if (updated) User.SendMessage("Your offer has been updated.");
|
||||
if (updated)
|
||||
User.SendMessage("Your offer has been updated.");
|
||||
|
||||
if (refresh && Check != null && !Check.Deleted)
|
||||
if (refresh && Check?.Deleted == false)
|
||||
{
|
||||
Refresh(true);
|
||||
return;
|
||||
|
|
@ -364,4 +350,4 @@ namespace Server
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue