Adds more formatting

This commit is contained in:
Kamron Batman 2018-08-19 21:28:24 +08:00
parent e77d695684
commit f674ec2be0
68 changed files with 530 additions and 876 deletions

View file

@ -60,8 +60,7 @@ namespace Server.Items
foreach( Mobile m in GetMobilesInRange( 0 ) )
{
BaseCreature bc = m as BaseCreature;
if ( m.Alive && !m.IsDeadBondedPet && (bc == null || bc.Controlled || bc.Summoned) )
if ( m.Alive && !m.IsDeadBondedPet && (!(m is BaseCreature bc) || bc.Controlled || bc.Summoned) )
{
toDamage.Add( m );
}

View file

@ -59,31 +59,35 @@ namespace Server.Items
return;
}
if ( obj is IArcaneEquip && obj is Item )
if ( obj is IArcaneEquip eq && eq is Item item )
{
Item item = (Item)obj;
CraftResource resource = CraftResource.None;
if ( item is BaseClothing )
resource = ((BaseClothing)item).Resource;
else if ( item is BaseArmor )
resource = ((BaseArmor)item).Resource;
else if ( item is BaseWeapon ) // Sanity, weapons cannot receive gems...
resource = ((BaseWeapon)item).Resource;
IArcaneEquip eq = (IArcaneEquip)obj;
switch (item)
{
case BaseClothing clothing:
resource = clothing.Resource;
break;
case BaseArmor armor:
resource = armor.Resource;
break;
// Sanity, weapons cannot receive gems...
case BaseWeapon weapon:
resource = weapon.Resource;
break;
}
if ( !item.IsChildOf( from.Backpack ) )
{
from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it.
return;
}
else if ( item.LootType == LootType.Blessed )
if ( item.LootType == LootType.Blessed )
{
from.SendMessage( "You can only use this on exceptionally crafted robes, thigh boots, cloaks, or leather gloves." );
return;
}
else if ( resource != CraftResource.None && resource != CraftResource.RegularLeather )
if ( resource != CraftResource.None && resource != CraftResource.RegularLeather )
{
from.SendLocalizedMessage( 1049690 ); // Arcane gems can not be used on that type of leather.
return;
@ -117,30 +121,37 @@ namespace Server.Items
{
bool isExceptional = false;
if ( item is BaseClothing )
isExceptional = ( ((BaseClothing)item).Quality == ClothingQuality.Exceptional );
else if ( item is BaseArmor )
isExceptional = ( ((BaseArmor)item).Quality == ArmorQuality.Exceptional );
else if ( item is BaseWeapon )
isExceptional = ( ((BaseWeapon)item).Quality == WeaponQuality.Exceptional );
switch (item)
{
case BaseClothing clothing:
isExceptional = clothing.Quality == ClothingQuality.Exceptional;
break;
case BaseArmor armor:
isExceptional = armor.Quality == ArmorQuality.Exceptional;
break;
case BaseWeapon weapon:
isExceptional = weapon.Quality == WeaponQuality.Exceptional;
break;
}
if ( isExceptional )
{
if ( item is BaseClothing )
switch (item)
{
((BaseClothing)item).Quality = ClothingQuality.Regular;
((BaseClothing)item).Crafter = from;
}
else if ( item is BaseArmor )
{
((BaseArmor)item).Quality = ArmorQuality.Regular;
((BaseArmor)item).Crafter = from;
((BaseArmor)item).PhysicalBonus = ((BaseArmor)item).FireBonus = ((BaseArmor)item).ColdBonus = ((BaseArmor)item).PoisonBonus = ((BaseArmor)item).EnergyBonus = 0; // Is there a method to remove bonuses?
}
else if ( item is BaseWeapon ) // Sanity, weapons cannot receive gems...
{
((BaseWeapon)item).Quality = WeaponQuality.Regular;
((BaseWeapon)item).Crafter = from;
case BaseClothing clothing:
clothing.Quality = ClothingQuality.Regular;
clothing.Crafter = @from;
break;
case BaseArmor armor:
armor.Quality = ArmorQuality.Regular;
armor.Crafter = @from;
armor.PhysicalBonus = armor.FireBonus = armor.ColdBonus = armor.PoisonBonus = armor.EnergyBonus = 0; // Is there a method to remove bonuses?
break;
// Sanity, weapons cannot receive gems...
case BaseWeapon weapon:
weapon.Quality = WeaponQuality.Regular;
weapon.Crafter = @from;
break;
}
eq.CurArcaneCharges = eq.MaxArcaneCharges = charges;
@ -177,13 +188,8 @@ namespace Server.Items
{
Item obj = items[i];
if ( obj is IArcaneEquip )
{
IArcaneEquip eq = (IArcaneEquip)obj;
if ( eq.IsArcane )
avail += eq.CurArcaneCharges;
}
if ( obj is IArcaneEquip eq && eq.IsArcane )
avail += eq.CurArcaneCharges;
}
if ( avail < amount )
@ -193,23 +199,16 @@ namespace Server.Items
{
Item obj = items[i];
if ( obj is IArcaneEquip )
if ( obj is IArcaneEquip eq && eq.IsArcane )
{
IArcaneEquip eq = (IArcaneEquip)obj;
if ( eq.IsArcane )
if ( eq.CurArcaneCharges > amount )
{
if ( eq.CurArcaneCharges > amount )
{
eq.CurArcaneCharges -= amount;
break;
}
else
{
amount -= eq.CurArcaneCharges;
eq.CurArcaneCharges = 0;
}
eq.CurArcaneCharges -= amount;
break;
}
amount -= eq.CurArcaneCharges;
eq.CurArcaneCharges = 0;
}
}

View file

@ -98,17 +98,15 @@ namespace Server.Items
Container root = parent as Container;
while (root != null && root.Parent is Container)
while (root?.Parent is Container)
{
root = (Container)root.Parent;
}
parent = root ?? parent;
if (parent is SecureTradeContainer && AccountGold.ConvertOnTrade)
if (parent is SecureTradeContainer trade && AccountGold.ConvertOnTrade)
{
var trade = (SecureTradeContainer)parent;
if (trade.Trade.From.Container == trade)
{
tradeInfo = trade.Trade.From;
@ -120,12 +118,12 @@ namespace Server.Items
owner = tradeInfo.Mobile;
}
}
else if (parent is BankBox && AccountGold.ConvertOnBank)
else if (parent is BankBox box && AccountGold.ConvertOnBank)
{
owner = ((BankBox)parent).Owner;
owner = box.Owner;
}
if (owner == null || owner.Account == null || !owner.Account.DepositGold(Worth))
if (owner?.Account == null || !owner.Account.DepositGold(Worth))
{
return;
}
@ -134,17 +132,13 @@ namespace Server.Items
{
if (owner.NetState != null && !owner.NetState.NewSecureTrading)
{
int gold;
int plat = Math.DivRem(Worth, AccountGold.CurrencyThreshold, out gold);
int plat = Math.DivRem(Worth, AccountGold.CurrencyThreshold, out var gold);
tradeInfo.Plat += plat;
tradeInfo.Gold += gold;
}
if (tradeInfo.VirtualCheck != null)
{
tradeInfo.VirtualCheck.UpdateTrade(tradeInfo.Mobile);
}
tradeInfo.VirtualCheck?.UpdateTrade(tradeInfo.Mobile);
}
owner.SendLocalizedMessage(1042763, Worth.ToString("#,0"));
@ -239,9 +233,7 @@ namespace Server.Items
// Gold was deposited in your account:
from.SendLocalizedMessage(1042672, true, deposited.ToString("#,0"));
var pm = from as PlayerMobile;
if (pm != null)
if (@from is PlayerMobile pm)
{
var qs = pm.Quest;

View file

@ -80,23 +80,23 @@ namespace Server.Items
if ( mt != null && !( to is ChaosDragoon || to is ChaosDragoonElite ) )
mt.Rider = null;
if (to is PlayerMobile)
if (to is PlayerMobile mobile)
{
if (Server.Spells.Ninjitsu.AnimalForm.UnderTransformation(to))
if (Server.Spells.Ninjitsu.AnimalForm.UnderTransformation(mobile))
{
to.SendLocalizedMessage(1114066, from.Name); // ~1_NAME~ knocked you out of animal form!
mobile.SendLocalizedMessage(1114066, from.Name); // ~1_NAME~ knocked you out of animal form!
}
else if (to.Mounted)
else if (mobile.Mounted)
{
to.SendLocalizedMessage(1040023); // You have been knocked off of your mount!
mobile.SendLocalizedMessage(1040023); // You have been knocked off of your mount!
}
(to as PlayerMobile).SetMountBlock(BlockMountType.Dazed, TimeSpan.FromSeconds( Core.ML ? 10 : 3 ), true);
mobile.SetMountBlock(BlockMountType.Dazed, TimeSpan.FromSeconds( Core.ML ? 10 : 3 ), true);
}
if (Core.AOS && from is PlayerMobile) /* only failsafe, attacker should already be dismounted */
if (Core.AOS) /* only failsafe, attacker should already be dismounted */
{
(from as PlayerMobile).SetMountBlock( BlockMountType.BolaRecovery, TimeSpan.FromSeconds( Core.ML ? 10 : 3 ), true );
(from as PlayerMobile)?.SetMountBlock( BlockMountType.BolaRecovery, TimeSpan.FromSeconds( Core.ML ? 10 : 3 ), true );
}
to.Damage(1);
@ -160,10 +160,8 @@ namespace Server.Items
if ( m_Bola.Deleted )
return;
if ( obj is Mobile )
if ( obj is Mobile to )
{
Mobile to = (Mobile)obj;
if ( !m_Bola.IsChildOf( from.Backpack ) )
{
from.SendLocalizedMessage( 1040019 ); // The bola must be in your pack to use it.
@ -231,4 +229,4 @@ namespace Server.Items
int version = reader.ReadInt();
}
}
}
}

View file

@ -88,9 +88,7 @@ namespace Server.Items
if ( i >= items.Count )
continue;
BulletinMessage msg = items[i] as BulletinMessage;
if ( msg == null )
if ( !(items[i] is BulletinMessage msg) )
continue;
if ( msg.Thread == null && CheckTime( msg.LastPostTime, ThreadDeletionTime ) )
@ -111,9 +109,7 @@ namespace Server.Items
if ( i >= items.Count )
continue;
BulletinMessage check = items[i] as BulletinMessage;
if ( check == null )
if ( !(items[i] is BulletinMessage check) )
continue;
if ( check.Thread == msg )
@ -134,9 +130,7 @@ namespace Server.Items
for ( int i = 0; i < items.Count; ++i )
{
BulletinMessage msg = items[i] as BulletinMessage;
if ( msg == null || msg.Poster != poster )
if ( !(items[i] is BulletinMessage msg) || msg.Poster != poster )
continue;
if ( onlyCheckRoot && msg.Thread != null )
@ -227,9 +221,8 @@ namespace Server.Items
Mobile from = state.Mobile;
int packetID = pvSrc.ReadByte();
BaseBulletinBoard board = World.FindItem( pvSrc.ReadInt32() ) as BaseBulletinBoard;
if ( board == null || !board.CheckRange( from ) )
if ( !(World.FindItem( pvSrc.ReadInt32() ) is BaseBulletinBoard board) || !board.CheckRange( from ) )
return;
switch ( packetID )
@ -243,9 +236,7 @@ namespace Server.Items
public static void BBRequestContent( Mobile from, BaseBulletinBoard board, PacketReader pvSrc )
{
BulletinMessage msg = World.FindItem( pvSrc.ReadInt32() ) as BulletinMessage;
if ( msg == null || msg.Parent != board )
if ( !(World.FindItem( pvSrc.ReadInt32() ) is BulletinMessage msg) || msg.Parent != board )
return;
from.Send( new BBMessageContent( board, msg ) );
@ -253,9 +244,7 @@ namespace Server.Items
public static void BBRequestHeader( Mobile from, BaseBulletinBoard board, PacketReader pvSrc )
{
BulletinMessage msg = World.FindItem( pvSrc.ReadInt32() ) as BulletinMessage;
if ( msg == null || msg.Parent != board )
if ( !(World.FindItem( pvSrc.ReadInt32() ) is BulletinMessage msg) || msg.Parent != board )
return;
from.Send( new BBMessageHeader( board, msg ) );
@ -270,7 +259,7 @@ namespace Server.Items
int breakout = 0;
while ( thread != null && thread.Thread != null && breakout++ < 10 )
while ( thread?.Thread != null && breakout++ < 10 )
thread = thread.Thread;
DateTime lastPostTime = DateTime.MinValue;
@ -306,9 +295,7 @@ namespace Server.Items
public static void BBRemoveMessage( Mobile from, BaseBulletinBoard board, PacketReader pvSrc )
{
BulletinMessage msg = World.FindItem( pvSrc.ReadInt32() ) as BulletinMessage;
if ( msg == null || msg.Parent != board )
if ( !(World.FindItem( pvSrc.ReadInt32() ) is BulletinMessage msg) || msg.Parent != board )
return;
if ( from.AccessLevel < AccessLevel.GameMaster && msg.Poster != from )
@ -476,7 +463,7 @@ namespace Server.Items
public void Validate()
{
if ( !( Parent is BulletinBoard && ((BulletinBoard)Parent).Items.Contains( this ) ) )
if ( (Parent as BulletinBoard)?.Items.Contains( this ) == false )
Delete();
}
}
@ -637,4 +624,4 @@ namespace Server.Items
return v;
}
}
}
}

View file

@ -210,10 +210,8 @@ namespace Server.Items
}
}
}
else if ( targeted is ReceiverCrystal )
else if ( targeted is ReceiverCrystal receiver )
{
ReceiverCrystal receiver = (ReceiverCrystal) targeted;
if ( m_Crystal.Receivers.Count >= 10 )
{
from.SendLocalizedMessage( 1010042 ); // This broadcast crystal is already linked to 10 receivers.
@ -234,18 +232,16 @@ namespace Server.Items
}
else if ( targeted == from )
{
foreach( ReceiverCrystal receiver in new List<ReceiverCrystal>( m_Crystal.Receivers ) )
foreach( ReceiverCrystal rc in new List<ReceiverCrystal>( m_Crystal.Receivers ) )
{
receiver.Sender = null;
rc.Sender = null;
}
from.SendLocalizedMessage( 1010046 ); // You unlink the broadcast crystal from all of its receivers.
}
else
{
Item targItem = targeted as Item;
if ( targItem != null && targItem.VerifyMove( from ) )
if ( targeted is Item targItem && targItem.VerifyMove( from ) )
{
CrystalRechargeInfo info = CrystalRechargeInfo.Get( targItem.GetType() );
@ -373,13 +369,13 @@ namespace Server.Items
string text = String.Format( "{0} says {1}", from.Name, message );
if ( this.RootParent is Mobile )
if ( this.RootParent is Mobile mobile )
{
((Mobile)this.RootParent).SendMessage( 0x2B2, "Crystal: " + text );
mobile.SendMessage( 0x2B2, "Crystal: " + text );
}
else if ( this.RootParent is Item )
else if ( this.RootParent is Item item )
{
((Item)this.RootParent).PublicOverheadMessage( MessageType.Regular, 0x2B2, false, "Crystal: " + text );
item.PublicOverheadMessage( MessageType.Regular, 0x2B2, false, "Crystal: " + text );
}
else
{
@ -445,9 +441,7 @@ namespace Server.Items
}
else
{
Item targItem = targeted as Item;
if ( targItem != null && targItem.VerifyMove( from ) )
if ( targeted is Item targItem && targItem.VerifyMove( from ) )
{
CrystalRechargeInfo info = CrystalRechargeInfo.Get( targItem.GetType() );

View file

@ -436,13 +436,7 @@ namespace Server.Items
public static string GetCorpseName( Mobile m )
{
if ( m is BaseCreature )
{
BaseCreature bc = (BaseCreature)m;
return bc.CorpseNameOverride ?? bc.CorpseName;
}
return null;
return m is BaseCreature bc ? bc.CorpseNameOverride ?? bc.CorpseName : null;
}
public static void Initialize()
@ -484,13 +478,8 @@ namespace Server.Items
{
c.AssignInstancedLoot();
}
else if ( Core.AOS )
{
PlayerMobile pm = owner as PlayerMobile;
if ( pm != null )
c.RestoreEquip = pm.EquipSnapshot;
}
else if ( Core.AOS && owner is PlayerMobile pm )
c.RestoreEquip = pm.EquipSnapshot;
}
else
{
@ -945,9 +934,7 @@ namespace Server.Items
public override void OnClick()
{
Corpse corpse = Owner.Target as Corpse;
if ( corpse != null && Owner.From.CheckAlive() )
if ( Owner.Target is Corpse corpse && Owner.From.CheckAlive() )
corpse.Open( Owner.From, false );
}
}
@ -1034,9 +1021,7 @@ namespace Server.Items
#region Self Looting
if ( checkSelfLoot && from == m_Owner && !GetFlag( CorpseFlag.SelfLooted ) && this.Items.Count != 0 )
{
DeathRobe robe = from.FindItemOnLayer( Layer.OuterTorso ) as DeathRobe;
if ( robe != null )
if ( @from.FindItemOnLayer( Layer.OuterTorso ) is DeathRobe robe )
{
Map map = from.Map;
@ -1118,17 +1103,14 @@ namespace Server.Items
return;
#region Quests
PlayerMobile player = from as PlayerMobile;
if ( player != null )
if ( @from is PlayerMobile player )
{
QuestSystem qs = player.Quest;
if ( qs is UzeraanTurmoilQuest )
{
GetDaemonBoneObjective obj = qs.FindObjective( typeof( GetDaemonBoneObjective ) ) as GetDaemonBoneObjective;
if ( obj != null && obj.CorpseWithBone == this && ( !obj.Completed || UzeraanTurmoilQuest.HasLostDaemonBone( player ) ) )
if ( qs.FindObjective( typeof( GetDaemonBoneObjective ) ) is GetDaemonBoneObjective obj && obj.CorpseWithBone == this && ( !obj.Completed || UzeraanTurmoilQuest.HasLostDaemonBone( player ) ) )
{
Item bone = new QuestDaemonBone();
@ -1151,9 +1133,7 @@ namespace Server.Items
}
else if ( qs is TheSummoningQuest )
{
VanquishDaemonObjective obj = qs.FindObjective( typeof( VanquishDaemonObjective ) ) as VanquishDaemonObjective;
if ( obj != null && obj.Completed && obj.CorpseWithSkull == this )
if ( qs.FindObjective( typeof( VanquishDaemonObjective ) ) is VanquishDaemonObjective obj && obj.Completed && obj.CorpseWithSkull == this )
{
GoldenSkull sk = new GoldenSkull();
@ -1276,9 +1256,9 @@ namespace Server.Items
if ( IsCriminalAction( from ) )
from.CriminalAction( true );
}
else if ( dead is BaseCreature )
else if ( dead is BaseCreature creature )
{
((BaseCreature)dead).OnCarve( from, this, item );
creature.OnCarve( from, this, item );
}
else
{

View file

@ -183,13 +183,13 @@ namespace Server.Items
writer.Write( m_TriggerDelay );
writer.Write( m_SoundDelay );
if ( m_Source is Item )
writer.Write( m_Source as Item );
if ( m_Source is Item srcItem )
writer.Write( srcItem );
else
writer.Write( m_Source as Mobile );
if ( m_Target is Item )
writer.Write( m_Target as Item );
if ( m_Target is Item targItem )
writer.Write( targItem );
else
writer.Write( m_Target as Mobile );
@ -269,12 +269,12 @@ namespace Server.Items
IEntity ent = null;
if (m_PlaySoundAtTrigger)
ent = trigger as IEntity;
ent = trigger;
if (ent == null)
ent = this;
Effects.PlaySound((ent is Item) ? ((Item)ent).GetWorldLocation() : ent.Location, ent.Map, m_SoundID);
Effects.PlaySound((ent as Item)?.GetWorldLocation() ?? ent.Location, ent.Map, m_SoundID);
}
public void DoEffect(IEntity trigger)
@ -282,7 +282,7 @@ namespace Server.Items
if (Deleted || m_TriggerType == EffectTriggerType.None)
return;
if (trigger is Mobile && ((Mobile)trigger).Hidden && ((Mobile)trigger).AccessLevel > AccessLevel.Player)
if (trigger is Mobile mobile && mobile.Hidden && mobile.AccessLevel > AccessLevel.Player)
return;
if (m_SoundID > 0)

View file

@ -100,23 +100,20 @@ namespace Server.Items
HeldBy.PublicOverheadMessage( MessageType.Regular, 957, false, m_Ticks.ToString() );
else if ( RootParent == null )
PublicOverheadMessage( MessageType.Regular, 957, false, m_Ticks.ToString() );
else if ( RootParent is Mobile )
((Mobile)RootParent).PublicOverheadMessage( MessageType.Regular, 957, false, m_Ticks.ToString() );
else if ( RootParent is Mobile mobile )
mobile.PublicOverheadMessage( MessageType.Regular, 957, false, m_Ticks.ToString() );
break;
}
default:
{
if ( HeldBy != null )
HeldBy.DropHolding();
HeldBy?.DropHolding();
if ( m_Users != null )
{
foreach ( Mobile m in m_Users )
{
ThrowTarget targ = m.Target as ThrowTarget;
if ( targ != null && targ.Bomb == this )
if ( m.Target is ThrowTarget targ && targ.Bomb == this )
Target.Cancel( m );
}
@ -124,9 +121,8 @@ namespace Server.Items
m_Users = null;
}
if ( RootParent is Mobile )
if ( RootParent is Mobile parent )
{
Mobile parent = (Mobile)RootParent;
parent.SendLocalizedMessage( 1060583 ); // The firebomb explodes in your hand!
AOS.Damage( parent, Utility.Random( 3 ) + 4, 0, 100, 0, 0, 0 );
}
@ -140,15 +136,13 @@ namespace Server.Items
eable.Free();
Mobile victim;
for ( int i = 0; i < toDamage.Count; ++i )
{
victim = toDamage[i];
Mobile victim = toDamage[i];
if ( m_LitBy == null || (SpellHelper.ValidIndirectTarget( m_LitBy, victim ) && m_LitBy.CanBeHarmful( victim, false )) )
{
if ( m_LitBy != null )
m_LitBy.DoHarmful( victim );
m_LitBy?.DoHarmful( victim );
AOS.Damage( victim, m_LitBy, Utility.Random( 3 ) + 4, 0, 100, 0, 0, 0 );
}
@ -168,21 +162,14 @@ namespace Server.Items
if ( Deleted || Map == Map.Internal || !IsChildOf( from.Backpack ) )
return;
IPoint3D p = obj as IPoint3D;
if ( p == null )
if ( !(obj is IPoint3D p) )
return;
SpellHelper.GetSurfaceTop( ref p );
from.RevealingAction();
IEntity to;
if ( p is Mobile )
to = (Mobile)p;
else
to = new Entity( Serial.Zero, new Point3D( p ), Map );
IEntity to = p as IEntity ?? new Entity( Serial.Zero, new Point3D( p ), Map );
Effects.SendMovingEffect( from, to, ItemID, 7, 0, false, false, Hue, 0 );
@ -257,8 +244,7 @@ namespace Server.Items
{
if ( ItemID == 0x398C && m_LitBy == null || (SpellHelper.ValidIndirectTarget( m_LitBy, m ) && m_LitBy.CanBeHarmful( m, false )) )
{
if ( m_LitBy != null )
m_LitBy.DoHarmful( m );
m_LitBy?.DoHarmful( m );
AOS.Damage( m, m_LitBy, 2, 0, 100, 0, 0, 0 );
m.PlaySound( 0x208 );
@ -284,15 +270,13 @@ namespace Server.Items
return;
}
Mobile victim;
for ( int i = 0; i < m_Burning.Count; )
{
victim = m_Burning[i];
Mobile victim = m_Burning[i];
if ( victim.Location == Location && victim.Map == Map && (m_LitBy == null || ( SpellHelper.ValidIndirectTarget( m_LitBy, victim ) && m_LitBy.CanBeHarmful( victim, false ) )) )
{
if ( m_LitBy != null )
m_LitBy.DoHarmful( victim );
m_LitBy?.DoHarmful( victim );
AOS.Damage( victim, m_LitBy, Utility.Random( 3 ) + 4, 0, 100, 0, 0, 0 );
++i;

View file

@ -60,10 +60,10 @@ namespace Server.Items
addon.Map = Map.Internal;
if ( addon is BaseAddon )
result = ( (BaseAddon) addon ).CouldFit( addon.Location, from.Map, from, ref house );
else if ( addon is BaseAddonContainer )
result = ( (BaseAddonContainer) addon ).CouldFit( addon.Location, from.Map, from, ref house );
if ( addon is BaseAddon baseAddon )
result = baseAddon.CouldFit( baseAddon.Location, from.Map, from, ref house );
else if ( addon is BaseAddonContainer container )
result = container.CouldFit( container.Location, from.Map, from, ref house );
addon.Map = from.Map;
@ -101,10 +101,8 @@ namespace Server.Items
private void ClearComponents( Item item )
{
if ( item is BaseAddon )
if ( item is BaseAddon addon )
{
BaseAddon addon = (BaseAddon) item;
foreach ( AddonComponent c in addon.Components )
{
c.Addon = null;
@ -113,17 +111,15 @@ namespace Server.Items
addon.Components.Clear();
}
else if ( item is BaseAddonContainer )
else if ( item is BaseAddonContainer addonContainer )
{
BaseAddonContainer addon = (BaseAddonContainer) item;
foreach ( AddonContainerComponent c in addon.Components )
foreach ( AddonContainerComponent c in addonContainer.Components )
{
c.Addon = null;
c.Delete();
}
addon.Components.Clear();
addonContainer.Components.Clear();
}
}
}

View file

@ -29,14 +29,12 @@ namespace Server.Items
protected override void OnTarget( Mobile from, object targeted )
{
if ( targeted is Item )
if ( targeted is Item item )
{
Item item = (Item)targeted;
if ( item.Movable == false && from.AccessLevel == AccessLevel.Player )
return;
Type type = targeted.GetType();
Type type = item.GetType();
FlippableAttribute[] AttributeArray = (FlippableAttribute[])type.GetCustomAttributes( typeof( FlippableAttribute ), false );
@ -47,7 +45,7 @@ namespace Server.Items
FlippableAttribute fa = AttributeArray[0];
fa.Flip( (Item)targeted );
fa.Flip( item );
}
}
}

View file

@ -74,10 +74,8 @@ namespace Server.Items
parent = root ?? parent;
if (parent is SecureTradeContainer && AccountGold.ConvertOnTrade)
if (parent is SecureTradeContainer trade && AccountGold.ConvertOnTrade)
{
var trade = (SecureTradeContainer)parent;
if (trade.Trade.From.Container == trade)
{
tradeInfo = trade.Trade.From;
@ -89,12 +87,12 @@ namespace Server.Items
owner = tradeInfo.Mobile;
}
}
else if (parent is BankBox && AccountGold.ConvertOnBank)
else if (parent is BankBox box && AccountGold.ConvertOnBank)
{
owner = ((BankBox)parent).Owner;
owner = box.Owner;
}
if (owner == null || owner.Account == null || !owner.Account.DepositGold(Amount))
if (owner?.Account == null || !owner.Account.DepositGold(Amount))
{
return;
}
@ -103,17 +101,13 @@ namespace Server.Items
{
if (owner.NetState != null && !owner.NetState.NewSecureTrading)
{
int gold;
int plat = Math.DivRem(Amount, AccountGold.CurrencyThreshold, out gold);
int plat = Math.DivRem(Amount, AccountGold.CurrencyThreshold, out var gold);
tradeInfo.Plat += plat;
tradeInfo.Gold += gold;
}
if (tradeInfo.VirtualCheck != null)
{
tradeInfo.VirtualCheck.UpdateTrade(tradeInfo.Mobile);
}
tradeInfo.VirtualCheck?.UpdateTrade(tradeInfo.Mobile);
}
owner.SendLocalizedMessage(1042763, Amount.ToString("#,0"));

View file

@ -150,10 +150,9 @@ namespace Server.Items
protected override void OnTarget( Mobile from, object targeted )
{
if ( targeted is Item && InteriorDecorator.CheckUse( m_Decorator, from ) )
if ( targeted is Item item && InteriorDecorator.CheckUse( m_Decorator, from ) )
{
BaseHouse house = BaseHouse.FindHouseAt( from );
Item item = (Item)targeted;
bool isDecorableComponent = false;
@ -162,23 +161,20 @@ namespace Server.Items
object addon = null;
int count = 0;
if ( item is AddonComponent )
switch (item)
{
AddonComponent component = (AddonComponent) item;
count = component.Addon.Components.Count;
addon = component.Addon;
}
else if ( item is AddonContainerComponent )
{
AddonContainerComponent component = (AddonContainerComponent) item;
count = component.Addon.Components.Count;
addon = component.Addon;
}
else if ( item is BaseAddonContainer )
{
BaseAddonContainer container = (BaseAddonContainer) item;
count = container.Components.Count;
addon = container;
case AddonComponent component:
count = component.Addon.Components.Count;
addon = component.Addon;
break;
case AddonContainerComponent containerComponent:
count = containerComponent.Addon.Components.Count;
addon = containerComponent.Addon;
break;
case BaseAddonContainer container:
count = container.Components.Count;
addon = container;
break;
}
if ( count == 1 && Core.SE )
@ -244,12 +240,18 @@ namespace Server.Items
{
object addon = null;
if ( item is AddonComponent )
addon = ((AddonComponent) item).Addon;
else if ( item is AddonContainerComponent )
addon = ((AddonContainerComponent) item).Addon;
else if ( item is BaseAddonContainer )
addon = (BaseAddonContainer) item;
switch (item)
{
case AddonComponent component:
addon = component.Addon;
break;
case AddonContainerComponent containerComponent:
addon = containerComponent.Addon;
break;
case BaseAddonContainer container:
addon = container;
break;
}
FlippableAddonAttribute[] aAttributes = (FlippableAddonAttribute[]) addon.GetType().GetCustomAttributes( typeof( FlippableAddonAttribute ), false );

View file

@ -50,10 +50,8 @@ namespace Server.Items
foreach ( Item item in items )
{
if ( item is Key )
if ( item is Key key )
{
Key key = (Key) item;
if ( key.KeyValue == keyValue )
key.Delete();
}
@ -75,10 +73,8 @@ namespace Server.Items
foreach ( Item item in items )
{
if ( item is Key )
if ( item is Key key )
{
Key key = (Key) item;
if ( key.KeyValue == keyValue )
return true;
}
@ -293,52 +289,37 @@ namespace Server.Items
{
if ( o.KeyValue == this.KeyValue )
{
if ( o is BaseDoor && !((BaseDoor)o).UseLocks() )
{
if ( o is BaseDoor door && !door.UseLocks() )
return false;
}
else
o.Locked = !o.Locked;
if ( o is LockableContainer cont1 )
{
o.Locked = !o.Locked;
if ( o is LockableContainer )
{
LockableContainer cont = (LockableContainer)o;
if ( cont.LockLevel == -255 )
cont.LockLevel = cont.RequiredSkill - 10;
}
if ( o is Item )
{
Item item = (Item) o;
if ( o.Locked )
item.SendLocalizedMessageTo( from, 1048000 ); // You lock it.
else
item.SendLocalizedMessageTo( from, 1048001 ); // You unlock it.
if ( item is LockableContainer )
{
LockableContainer cont = (LockableContainer) item;
if ( cont.TrapType != TrapType.None && cont.TrapOnLockpick )
{
if ( o.Locked )
item.SendLocalizedMessageTo( from, 501673 ); // You re-enable the trap.
else
item.SendLocalizedMessageTo( from, 501672 ); // You disable the trap temporarily. Lock it again to re-enable it.
}
}
}
return true;
if ( cont1.LockLevel == -255 )
cont1.LockLevel = cont1.RequiredSkill - 10;
}
if ( o is Item item )
{
if ( o.Locked )
item.SendLocalizedMessageTo( from, 1048000 ); // You lock it.
else
item.SendLocalizedMessageTo( from, 1048001 ); // You unlock it.
if ( item is LockableContainer cont && cont.TrapType != TrapType.None && cont.TrapOnLockpick )
{
if ( o.Locked )
cont.SendLocalizedMessageTo( from, 501673 ); // You re-enable the trap.
else
cont.SendLocalizedMessageTo( from, 501672 ); // You disable the trap temporarily. Lock it again to re-enable it.
}
}
return true;
}
else
{
return false;
}
return false;
}
private class RenamePrompt : Prompt
@ -388,9 +369,9 @@ namespace Server.Items
from.Prompt = new RenamePrompt( m_Key );
}
else if ( targeted is ILockable )
else if ( targeted is ILockable lockable )
{
if ( m_Key.UseOn( from, (ILockable) targeted ) )
if ( m_Key.UseOn( from, lockable ) )
number = -1;
else
number = 501668; // This key doesn't seem to unlock that.
@ -426,10 +407,8 @@ namespace Server.Items
int number;
if ( targeted is Key )
if ( targeted is Key k )
{
Key k = (Key)targeted;
if ( k.m_KeyVal == 0 )
{
number = 501675; // This key is also blank.
@ -465,4 +444,4 @@ namespace Server.Items
}
}
}
}
}

View file

@ -30,24 +30,20 @@ namespace Server.Items
return false;
}
Key key = dropped as Key;
if ( key == null || key.KeyValue == 0 )
if ( !(dropped is Key key) || key.KeyValue == 0 )
{
from.SendLocalizedMessage( 501689 ); // Only non-blank keys can be put on a keyring.
return false;
}
else if ( this.Keys.Count >= MaxKeys )
if ( this.Keys.Count >= MaxKeys )
{
from.SendLocalizedMessage( 1008138 ); // This keyring is full.
return false;
}
else
{
Add( key );
from.SendLocalizedMessage( 501691 ); // You put the key on the keyring.
return true;
}
Add( key );
from.SendLocalizedMessage( 501691 ); // You put the key on the keyring.
return true;
}
public override void OnDoubleClick( Mobile from )
@ -84,10 +80,8 @@ namespace Server.Items
m_KeyRing.Open( from );
from.SendLocalizedMessage( 501685 ); // You open the keyring.
}
else if ( targeted is ILockable )
else if ( targeted is ILockable o )
{
ILockable o = (ILockable) targeted;
foreach ( Key key in m_KeyRing.Keys )
{
if ( key.UseOn( from, o ) )
@ -125,9 +119,7 @@ namespace Server.Items
public void Open( Mobile from )
{
Container cont = this.Parent as Container;
if ( cont == null )
if ( !(this.Parent is Container cont) )
return;
for ( int i = m_Keys.Count - 1; i >= 0; i-- )

View file

@ -75,9 +75,9 @@ namespace Server.Items
{
from.SendLocalizedMessage( 1005401 ); // You cannot bury the stone here.
}
else if ( from is PlayerMobile && ((PlayerMobile)from).Young )
else if ( @from is PlayerMobile mobile && mobile.Young )
{
from.SendLocalizedMessage( 1049543 ); // You decide against traveling to Felucca while you are still young.
mobile.SendLocalizedMessage( 1049543 ); // You decide against traveling to Felucca while you are still young.
}
else if ( from.Kills >= 5 )
{

View file

@ -61,14 +61,12 @@ namespace Server.Items
{
from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it.
}
else if ( obj is Item && ((Item)obj).RootParent != from )
else if ( obj is Item item && item.RootParent != from )
{
from.SendLocalizedMessage( 1005425 ); // You may only wipe down items you are holding or carrying.
}
else if ( obj is BaseWeapon )
else if ( obj is BaseWeapon weapon )
{
BaseWeapon weapon = (BaseWeapon)obj;
if ( weapon.Poison == null || weapon.PoisonCharges <= 0 )
{
from.LocalOverheadMessage( Network.MessageType.Regular, 0x3B2, 1005422 ); // Hmmmm... this does not need to be cleaned.
@ -86,10 +84,8 @@ namespace Server.Items
from.SendLocalizedMessage( 1010497 ); // You have cleaned the item.
}
}
else if ( obj == from && obj is PlayerMobile )
else if ( obj == from && obj is PlayerMobile pm )
{
PlayerMobile pm = (PlayerMobile)obj;
if ( pm.BodyMod == 183 || pm.BodyMod == 184 )
{
pm.SavagePaintExpiration = TimeSpan.Zero;
@ -107,10 +103,8 @@ namespace Server.Items
}
}
#region Firebomb
else if ( obj is BaseBeverage )
else if ( obj is BaseBeverage beverage )
{
BaseBeverage beverage = (BaseBeverage) obj;
if ( beverage.Content == BeverageType.Liquor )
{
Firebomb bomb = new Firebomb( beverage.ItemID );

View file

@ -505,7 +505,7 @@ namespace Server.Items
{
from.SendLocalizedMessage( 501356 ); // This person is already banned!
}
else if ( poster is BaseCreature && ((BaseCreature)poster).NoHouseRestrictions )
else if ( poster is BaseCreature creature && creature.NoHouseRestrictions )
{
from.SendLocalizedMessage( 1062040 ); // You cannot ban that.
}

View file

@ -62,9 +62,7 @@ namespace Server.Items
foreach( Mobile m in GetMobilesInRange( 0 ) )
{
BaseCreature bc = m as BaseCreature;
if ( m.Alive && !m.IsDeadBondedPet && (bc == null || bc.Controlled || bc.Summoned) )
if ( m.Alive && !m.IsDeadBondedPet && (!(m is BaseCreature bc) || bc.Controlled || bc.Summoned) )
{
toDamage.Add( m );
}

View file

@ -48,13 +48,12 @@ namespace Server.Items
{
Mobile m = null;
if ( parent is Item )
m = ((Item)parent).RootParent as Mobile;
else if ( parent is Mobile )
m = (Mobile)parent;
if ( parent is Item item )
m = item.RootParent as Mobile;
else if ( parent is Mobile mobile )
m = mobile;
if ( m != null )
m.CloseGump( typeof( PromotionalTokenGump ) );
m?.CloseGump( typeof( PromotionalTokenGump ) );
}
public override void Serialize( GenericWriter writer )
@ -123,10 +122,10 @@ namespace Server.Items
public override Item CreateItemFor( Mobile from )
{
if ( from != null && from.Account != null )
if ( @from?.Account != null )
return new SoulstoneFragment( from.Account.ToString() );
else
return null;
return null;
}
public override TextDefinition ItemGumpName => 1070999;// <center>Soulstone Fragment</center>

View file

@ -323,8 +323,8 @@ namespace Server.Items
}
else
{
ClientFlags flags = mobile.NetState == null ? ClientFlags.None : mobile.NetState.Flags;
bool young = mobile is PlayerMobile ? ((PlayerMobile)mobile).Young : false;
ClientFlags flags = mobile.NetState?.Flags ?? ClientFlags.None;
bool young = mobile is PlayerMobile playerMobile && playerMobile.Young;
if ( Core.SE && (flags & ClientFlags.Tokuno) != 0 )
checkLists = young ? PMList.SEListsYoung : PMList.SELists;

View file

@ -53,9 +53,8 @@ namespace Server.Items
{
message = "It cannot weight itself.";
}
else if ( targeted is Item )
else if ( targeted is Item item )
{
Item item = (Item)targeted;
object root = item.RootParent;
if ( (root != null && root != from) || item.Parent == from )
@ -90,4 +89,4 @@ namespace Server.Items
}
}
}
}
}

View file

@ -994,7 +994,7 @@ namespace Server.Items
return false;
}
if (GetFlag(ConditionFlag.DenyFollowers) && (m.Followers != 0 || (m is PlayerMobile && ((PlayerMobile)m).AutoStabled.Count != 0)))
if (GetFlag(ConditionFlag.DenyFollowers) && (m.Followers != 0 || (m is PlayerMobile mobile && mobile.AutoStabled.Count != 0)))
{
m.SendLocalizedMessage(1077250); // No pets permitted beyond this point.
return false;

View file

@ -54,8 +54,8 @@ namespace Server.Items
from.BodyMod = ( from.Female ? 184 : 183 );
from.HueMod = 0;
if ( from is PlayerMobile )
((PlayerMobile)from).SavagePaintExpiration = TimeSpan.FromDays( 7.0 );
if ( @from is PlayerMobile mobile )
mobile.SavagePaintExpiration = TimeSpan.FromDays( 7.0 );
from.SendLocalizedMessage( 1042537 ); // You now bear the markings of the savage tribe. Your body paint will last about a week or you can remove it with an oil cloth.

View file

@ -111,8 +111,8 @@ namespace Server.Items
foreach ( Item item in GetItemsInRange( NeighborRange ) )
{
if ( item != this && item is WarningItem )
list.Add( (WarningItem)item );
if ( item != this && item is WarningItem warningItem )
list.Add( warningItem );
}
for ( int i = 0; i < list.Count; i++ )

View file

@ -115,9 +115,9 @@ namespace Server.Items
protected override void OnTarget( Mobile from, object target )
{
if ( target is WayPoint && m_Point != null )
if ( target is WayPoint point && m_Point != null )
{
m_Point.NextPoint = (WayPoint)target;
m_Point.NextPoint = point;
}
else
{
@ -137,14 +137,14 @@ namespace Server.Items
protected override void OnTarget( Mobile from, object targeted )
{
if ( targeted is WayPoint )
if ( targeted is WayPoint wayPoint )
{
if ( m_Last != null )
m_Last.NextPoint = (WayPoint)targeted;
m_Last.NextPoint = wayPoint;
}
else if ( targeted is IPoint3D )
else if ( targeted is IPoint3D d )
{
Point3D p = new Point3D( (IPoint3D)targeted );
Point3D p = new Point3D( d );
WayPoint point = new WayPoint( m_Last );
point.MoveToWorld( p, from.Map );