Fixes FindItemsByType and FindItemByType and new override of IsLockedDown and IsSecure by renaming their methods.

This commit is contained in:
Kamron Batman 2018-09-15 15:50:35 -07:00
parent 7321fa1b63
commit a48ebb3a5f
50 changed files with 416 additions and 643 deletions

View file

@ -68,7 +68,7 @@ namespace Server.Mobiles
// When we have no ammo, we flee
Container pack = m_Mobile.Backpack;
if (pack?.FindItemByType(typeof(Arrow)) == null)
if (pack?.FindItemByType<Arrow>() == null)
{
Action = ActionType.Flee;
return true;

View file

@ -81,7 +81,7 @@ namespace Server.Mobiles
if (cpack != null)
{
Item steala = cpack.FindItemByType(typeof(Bandage));
Item steala = cpack.FindItemByType<Bandage>();
if (steala != null)
{
m_Mobile.DebugSay("Trying to steal from combatant.");
@ -89,7 +89,7 @@ namespace Server.Mobiles
m_Mobile.Target?.Invoke(m_Mobile, steala);
}
Item stealb = cpack.FindItemByType(typeof(Nightshade));
Item stealb = cpack.FindItemByType<Nightshade>();
if (stealb != null)
{
m_Mobile.DebugSay("Trying to steal from combatant.");
@ -97,7 +97,7 @@ namespace Server.Mobiles
m_Mobile.Target?.Invoke(m_Mobile, stealb);
}
Item stealc = cpack.FindItemByType(typeof(BlackPearl));
Item stealc = cpack.FindItemByType<BlackPearl>();
if (stealc != null)
{
m_Mobile.DebugSay("Trying to steal from combatant.");
@ -105,14 +105,14 @@ namespace Server.Mobiles
m_Mobile.Target?.Invoke(m_Mobile, stealc);
}
Item steald = cpack.FindItemByType(typeof(MandrakeRoot));
Item steald = cpack.FindItemByType<MandrakeRoot>();
if (steald != null)
{
m_Mobile.DebugSay("Trying to steal from combatant.");
m_Mobile.UseSkill(SkillName.Stealing);
m_Mobile.Target?.Invoke(m_Mobile, steald);
}
else if (steala == null && stealb == null && stealc == null && steald == null)
else if (steala == null && stealb == null && stealc == null)
{
m_Mobile.DebugSay("I am going to flee from {0}", combatant.Name);

View file

@ -1778,9 +1778,7 @@ namespace Server.Mobiles
if (Core.AOS && Backpack != null && !Backpack.Deleted)
{
List<Item> ilist = Backpack.FindItemsByType<Item>(FindItems_Callback);
for (int i = 0; i < ilist.Count; i++) Backpack.AddItem(ilist[i]);
Backpack.FindItemsByType<Item>(FindItems_Callback).ForEach(item => Backpack.AddItem(item));
}
EquipSnapshot = new List<Item>(Items);
@ -1813,53 +1811,52 @@ namespace Server.Mobiles
private bool CheckInsuranceOnDeath(Item item)
{
if (InsuranceEnabled && item.Insured)
if (!InsuranceEnabled || !item.Insured)
return false;
#region Dueling
if (m_DuelPlayer != null && DuelContext != null && DuelContext.Registered && DuelContext.Started &&
!m_DuelPlayer.Eliminated)
return true;
#endregion
if (AutoRenewInsurance)
{
#region Dueling
int cost = GetInsuranceCost(item);
if (m_DuelPlayer != null && DuelContext != null && DuelContext.Registered && DuelContext.Started &&
!m_DuelPlayer.Eliminated)
return true;
if (m_InsuranceAward != null)
cost /= 2;
#endregion
if (AutoRenewInsurance)
if (Banker.Withdraw(this, cost))
{
int cost = GetInsuranceCost(item);
if (m_InsuranceAward != null)
cost /= 2;
if (Banker.Withdraw(this, cost))
{
m_InsuranceCost += cost;
item.PaidInsurance = true;
SendLocalizedMessage(1060398,
cost.ToString()); // ~1_AMOUNT~ gold has been withdrawn from your bank box.
}
else
{
SendLocalizedMessage(1061079, "", 0x23); // You lack the funds to purchase the insurance
item.PaidInsurance = false;
item.Insured = false;
m_NonAutoreinsuredItems++;
}
m_InsuranceCost += cost;
item.PaidInsurance = true;
SendLocalizedMessage(1060398,
cost.ToString()); // ~1_AMOUNT~ gold has been withdrawn from your bank box.
}
else
{
SendLocalizedMessage(1061079, "", 0x23); // You lack the funds to purchase the insurance
item.PaidInsurance = false;
item.Insured = false;
m_NonAutoreinsuredItems++;
}
if (m_InsuranceAward != null)
if (Banker.Deposit(m_InsuranceAward, 300))
if (m_InsuranceAward is PlayerMobile mobile)
mobile.m_InsuranceBonus += 300;
return true;
}
else
{
item.PaidInsurance = false;
item.Insured = false;
}
return false;
if (m_InsuranceAward != null)
if (Banker.Deposit(m_InsuranceAward, 300))
if (m_InsuranceAward is PlayerMobile mobile)
mobile.m_InsuranceBonus += 300;
return true;
}
public override DeathMoveResult GetParentMoveResultFor(Item item)
@ -2014,7 +2011,8 @@ namespace Server.Mobiles
if (!buff.RetainThroughDeath)
list.Add(buff);
for (int i = 0; i < list.Count; i++) RemoveBuff(list[i]);
for (int i = 0; i < list.Count; i++)
RemoveBuff(list[i]);
}
}
@ -2129,7 +2127,7 @@ namespace Server.Mobiles
{
Type type = talisman.Protection.Type;
if (type.IsAssignableFrom(from.GetType()))
if (type.IsInstanceOfType(from))
amount = (int)(amount * (1 - (double)talisman.Protection.Amount / 100));
}
@ -3532,7 +3530,7 @@ namespace Server.Mobiles
Container pack = Backpack;
if (pack != null)
items.AddRange(pack.FindItemsByType<Item>(true, DisplayInItemInsuranceGump));
items.AddRange(pack.FindItemsByType<Item>(DisplayInItemInsuranceGump));
// TODO: Investigate item sorting

View file

@ -48,7 +48,8 @@ namespace Server.Mobiles
List<BankCheck> checks = bank.FindItemsByType<BankCheck>();
balance += gold.Aggregate(0L, (c, t) => c + t.Amount);
if (balance >= int.MaxValue) return int.MaxValue;
if (balance >= int.MaxValue)
return int.MaxValue;
balance += checks.Aggregate(0L, (c, t) => c + t.Worth);
}
@ -94,8 +95,7 @@ namespace Server.Mobiles
// If for whatever reason the TOL checks fail, we should still try old methods for withdrawing currency.
if (AccountGold.Enabled && from.Account != null && from.Account.WithdrawGold(amount)) return true;
Item[] gold, checks;
int balance = GetBalance(from, out gold, out checks);
int balance = GetBalance(from, out Item[] gold, out Item[] checks);
if (balance < amount) return false;
@ -278,11 +278,9 @@ namespace Server.Mobiles
if (split.Length >= 2)
{
int amount;
Container pack = e.Mobile.Backpack;
if (!int.TryParse(split[1], out amount))
if (!int.TryParse(split[1], out int amount))
break;
if (!Core.ML && amount > 5000 || Core.ML && amount > 60000)
@ -363,9 +361,7 @@ namespace Server.Mobiles
if (split.Length >= 2)
{
int amount;
if (!int.TryParse(split[1], out amount))
if (!int.TryParse(split[1], out int amount))
break;
if (amount < 5000)

View file

@ -41,9 +41,7 @@ namespace Server.Mobiles
{
m_NextCheckPack = DateTime.UtcNow + TimeSpan.FromSeconds(2.0);
Item deed = pack.FindItemByType(typeof(HouseDeed), false);
if (deed != null)
if (pack.FindItemByType<HouseDeed>(false) != null)
{
// If you have a deed, I can appraise it or buy it from you...
PrivateOverheadMessage(MessageType.Regular, 0x3B2, 500605, m.NetState);