More cast conversion fixes

This commit is contained in:
Kamron Batman 2018-09-06 18:07:42 -07:00
parent 3f45bd57b9
commit aba9452161
46 changed files with 359 additions and 506 deletions

View file

@ -132,9 +132,7 @@ namespace Server.Items
foreach ( NetState state in eable )
{
PlayerMobile pm = state.Mobile as PlayerMobile;
if ( pm != null && GetEntry( pm ) == null )
if ( state.Mobile is PlayerMobile pm && GetEntry( pm ) == null )
{
CampfireEntry entry = new CampfireEntry( pm, this );

View file

@ -103,7 +103,7 @@ namespace Server.Items
{
from.SendLocalizedMessage( 1042600 ); // That is not a corpse!
}
else if ( targeted is Corpse && ((Corpse)targeted).VisitedByTaxidermist )
else if ( targeted is Corpse corpse && corpse.VisitedByTaxidermist )
{
from.SendLocalizedMessage( 1042596 ); // That corpse seems to have been visited by a taxidermist already.
}
@ -138,11 +138,9 @@ namespace Server.Items
Mobile hunter = null;
int weight = 0;
if ( targeted is BigFish )
if ( targeted is BigFish fish )
{
BigFish fish = targeted as BigFish;
hunter = fish.Fisher;
hunter = fish.Fisher;
weight = (int)fish.Weight;
fish.Consume();
@ -151,17 +149,15 @@ namespace Server.Items
from.AddToBackpack( new TrophyDeed( m_Table[i], hunter, weight ) );
if ( targeted is Corpse )
((Corpse)targeted).VisitedByTaxidermist = true;
if ( targeted is Corpse corpse1 )
corpse1.VisitedByTaxidermist = true;
m_Kit.Delete();
return;
}
else
{
from.SendLocalizedMessage( 1042598 ); // You do not have enough boards.
return;
}
from.SendLocalizedMessage( 1042598 ); // You do not have enough boards.
return;
}
}
}
@ -303,9 +299,9 @@ namespace Server.Items
{
Item deed = this.Deed;
if ( this.Parent is Item )
if ( this.Parent is Item item )
{
((Item)this.Parent).AddItem( deed );
item.AddItem( deed );
deed.Location = this.Location;
}
else

View file

@ -114,16 +114,14 @@ namespace Server.Items
}
}
public virtual bool RequireDeepWater{ get{ return true; } }
public virtual bool RequireDeepWater => true;
public void OnTarget( Mobile from, object obj )
{
if ( Deleted || m_InUse )
return;
IPoint3D p3D = obj as IPoint3D;
if ( p3D == null )
if ( !(obj is IPoint3D p3D) )
return;
Map map = from.Map;

View file

@ -123,9 +123,7 @@ namespace Server.Items
if ( !item.IsChildOf( from.Backpack ) && item.Parent != from )
return;
PlayerMobile pm = from as PlayerMobile;
if ( pm == null )
if ( !(from is PlayerMobile pm) )
return;
ContextMenuEntry miningEntry = new ContextMenuEntry( pm.ToggleMiningStone ? 6179 : 6178 );
@ -239,4 +237,4 @@ namespace Server.Items
#endregion
}
}
}

View file

@ -123,9 +123,9 @@ namespace Server.Items
{
m.SendLocalizedMessage( 1061632 ); // You can't do that while carrying the sigil.
}
else if ( m_TargetMap == Map.Felucca && m is PlayerMobile && ((PlayerMobile)m).Young )
else if ( m_TargetMap == Map.Felucca && m is PlayerMobile mobile && mobile.Young )
{
m.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 ( (m.Kills >= 5 && m_TargetMap != Map.Felucca) || ( m_TargetMap == Map.Tokuno && (flags & ClientFlags.Tokuno) == 0 ) || ( m_TargetMap == Map.Malas && (flags & ClientFlags.Malas) == 0 ) || ( m_TargetMap == Map.Ilshenar && (flags & ClientFlags.Ilshenar) == 0 ) )
{
@ -160,7 +160,7 @@ namespace Server.Items
writer.Write( m_Target );
writer.Write( m_TargetMap );
// Version 1
writer.Write( m_bDispellable );
}
@ -461,4 +461,4 @@ namespace Server.Items
m_Gate.EndConfirmation( m_From );
}
}
}
}

View file

@ -217,82 +217,75 @@ namespace Server.Items
public override bool OnDragDrop( Mobile from, Item item )
{
if ( item is BasePotion )
{
BasePotion pot = (BasePotion)item;
int toHold = Math.Min( 100 - m_Held, pot.Amount );
if ( toHold <= 0 )
{
from.SendLocalizedMessage( 502233 ); // The keg will not hold any more!
return false;
}
else if ( m_Held == 0 )
{
#region Mondain's Legacy
if ( (int) pot.PotionEffect >= (int) PotionEffect.Invisibility )
{
from.SendLocalizedMessage( 502232 ); // The keg is not designed to hold that type of object.
return false;
}
#endregion
if ( GiveBottle( from, toHold ) )
{
m_Type = pot.PotionEffect;
Held = toHold;
from.PlaySound( 0x240 );
from.SendLocalizedMessage( 502237 ); // You place the empty bottle in your backpack.
item.Consume( toHold );
if ( !item.Deleted )
item.Bounce( from );
return true;
}
else
{
from.SendLocalizedMessage( 502238 ); // You don't have room for the empty bottle in your backpack.
return false;
}
}
else if ( pot.PotionEffect != m_Type )
{
from.SendLocalizedMessage( 502236 ); // You decide that it would be a bad idea to mix different types of potions.
return false;
}
else
{
if ( GiveBottle( from, toHold ) )
{
Held += toHold;
from.PlaySound( 0x240 );
from.SendLocalizedMessage( 502237 ); // You place the empty bottle in your backpack.
item.Consume( toHold );
if ( !item.Deleted )
item.Bounce( from );
return true;
}
else
{
from.SendLocalizedMessage( 502238 ); // You don't have room for the empty bottle in your backpack.
return false;
}
}
}
else
if (!(item is BasePotion pot))
{
from.SendLocalizedMessage( 502232 ); // The keg is not designed to hold that type of object.
return false;
}
int toHold = Math.Min( 100 - m_Held, pot.Amount );
if ( toHold <= 0 )
{
from.SendLocalizedMessage( 502233 ); // The keg will not hold any more!
return false;
}
if ( m_Held == 0 )
{
#region Mondain's Legacy
if ( (int) pot.PotionEffect >= (int) PotionEffect.Invisibility )
{
from.SendLocalizedMessage( 502232 ); // The keg is not designed to hold that type of object.
return false;
}
#endregion
if ( GiveBottle( from, toHold ) )
{
m_Type = pot.PotionEffect;
Held = toHold;
from.PlaySound( 0x240 );
from.SendLocalizedMessage( 502237 ); // You place the empty bottle in your backpack.
pot.Consume( toHold );
if ( !pot.Deleted )
pot.Bounce( from );
return true;
}
from.SendLocalizedMessage( 502238 ); // You don't have room for the empty bottle in your backpack.
return false;
}
if ( pot.PotionEffect != m_Type )
{
from.SendLocalizedMessage( 502236 ); // You decide that it would be a bad idea to mix different types of potions.
return false;
}
if ( GiveBottle( from, toHold ) )
{
Held += toHold;
from.PlaySound( 0x240 );
from.SendLocalizedMessage( 502237 ); // You place the empty bottle in your backpack.
pot.Consume( toHold );
if ( !pot.Deleted )
pot.Bounce( from );
return true;
}
from.SendLocalizedMessage( 502238 ); // You don't have room for the empty bottle in your backpack.
return false;
}
public bool GiveBottle( Mobile m, int amount )

View file

@ -81,13 +81,9 @@ namespace Server.Items
if ( handTwo is BaseWeapon )
handOne = handTwo;
if ( handTwo is BaseRanged )
{
BaseRanged ranged = (BaseRanged) handTwo;
if ( ranged.Balanced )
return true;
}
if ( handTwo is BaseRanged ranged && ranged.Balanced )
return true;
return ( handOne == null || handTwo == null );
}
@ -223,10 +219,8 @@ namespace Server.Items
public override bool StackWith( Mobile from, Item dropped, bool playSound )
{
if ( dropped is BasePotion && ((BasePotion)dropped).m_PotionEffect == m_PotionEffect )
return base.StackWith( from, dropped, playSound );
return false;
return dropped is BasePotion potion && potion.m_PotionEffect == m_PotionEffect &&
base.StackWith(from, potion, playSound);
}
#region ICraftable Members

View file

@ -40,9 +40,7 @@ namespace Server.Items
return;
}
ThrowTarget targ = from.Target as ThrowTarget;
if ( targ != null && targ.Potion == this )
if ( from.Target is ThrowTarget targ && targ.Potion == this )
return;
from.RevealingAction();
@ -86,9 +84,7 @@ namespace Server.Items
// Check if any other players are using this potion
for ( int i = 0; i < m_Users.Count; i ++ )
{
ThrowTarget targ = m_Users[ i ].Target as ThrowTarget;
if ( targ != null && targ.Potion == this )
if ( m_Users[ i ].Target is ThrowTarget targ && targ.Potion == this )
Target.Cancel( from );
}
@ -112,9 +108,7 @@ namespace Server.Items
public static void AddDelay( Mobile m )
{
Timer timer = m_Delay[ m ] as Timer;
if ( timer != null )
if ( m_Delay[ m ] is Timer timer )
timer.Stop();
m_Delay[ m ] = Timer.DelayCall( TimeSpan.FromSeconds( 30 ), new TimerStateCallback( EndDelay_Callback ), m );
@ -122,9 +116,7 @@ namespace Server.Items
public static int GetDelay( Mobile m )
{
Timer timer = m_Delay[ m ] as Timer;
if ( timer != null && timer.Next > DateTime.UtcNow )
if ( m_Delay[ m ] is Timer timer && timer.Next > DateTime.UtcNow )
return (int) (timer.Next - DateTime.UtcNow).TotalSeconds;
return 0;
@ -132,15 +124,13 @@ namespace Server.Items
private static void EndDelay_Callback( object obj )
{
if ( obj is Mobile )
EndDelay( (Mobile) obj );
if ( obj is Mobile mobile )
EndDelay( mobile );
}
public static void EndDelay( Mobile m )
{
Timer timer = m_Delay[ m ] as Timer;
if ( timer != null )
if ( m_Delay[ m ] is Timer timer )
{
timer.Stop();
m_Delay.Remove( m );
@ -167,13 +157,11 @@ namespace Server.Items
if ( m_Potion.Deleted || m_Potion.Map == Map.Internal )
return;
IPoint3D p = targeted as IPoint3D;
if ( p == null || from.Map == null )
if ( !(targeted is IPoint3D p) || from.Map == null )
return;
// Add delay
BaseConflagrationPotion.AddDelay( from );
AddDelay( from );
SpellHelper.GetSurfaceTop( ref p );
@ -181,8 +169,8 @@ namespace Server.Items
IEntity to;
if ( p is Mobile )
to = (Mobile)p;
if ( p is Mobile mobile )
to = mobile;
else
to = new Entity( Serial.Zero, new Point3D( p ), from.Map );

View file

@ -41,9 +41,7 @@ namespace Server.Items
return;
}
ThrowTarget targ = from.Target as ThrowTarget;
if ( targ != null && targ.Potion == this )
if ( from.Target is ThrowTarget targ && targ.Potion == this )
return;
from.RevealingAction();
@ -87,9 +85,7 @@ namespace Server.Items
// Check if any other players are using this potion
for ( int i = 0; i < m_Users.Count; i ++ )
{
ThrowTarget targ = m_Users[ i ].Target as ThrowTarget;
if ( targ != null && targ.Potion == this )
if ( m_Users[ i ].Target is ThrowTarget targ && targ.Potion == this )
Target.Cancel( from );
}
@ -102,10 +98,8 @@ namespace Server.Items
foreach ( Mobile mobile in map.GetMobilesInRange( loc, Radius ) )
{
if ( mobile is BaseCreature )
if ( mobile is BaseCreature mon )
{
BaseCreature mon = (BaseCreature) mobile;
if ( mon.Controlled || mon.Summoned )
continue;
@ -134,9 +128,7 @@ namespace Server.Items
public static void AddDelay( Mobile m )
{
Timer timer = m_Delay[ m ] as Timer;
if ( timer != null )
if ( m_Delay[ m ] is Timer timer )
timer.Stop();
m_Delay[ m ] = Timer.DelayCall( TimeSpan.FromSeconds( 60 ), new TimerStateCallback( EndDelay_Callback ), m );
@ -144,9 +136,7 @@ namespace Server.Items
public static int GetDelay( Mobile m )
{
Timer timer = m_Delay[ m ] as Timer;
if ( timer != null && timer.Next > DateTime.UtcNow )
if ( m_Delay[ m ] is Timer timer && timer.Next > DateTime.UtcNow )
return (int) (timer.Next - DateTime.UtcNow).TotalSeconds;
return 0;
@ -154,15 +144,13 @@ namespace Server.Items
private static void EndDelay_Callback( object obj )
{
if ( obj is Mobile )
EndDelay( (Mobile) obj );
if ( obj is Mobile mobile )
EndDelay( mobile );
}
public static void EndDelay( Mobile m )
{
Timer timer = m_Delay[ m ] as Timer;
if ( timer != null )
if ( m_Delay[ m ] is Timer timer )
{
timer.Stop();
m_Delay.Remove( m );
@ -189,13 +177,11 @@ namespace Server.Items
if ( m_Potion.Deleted || m_Potion.Map == Map.Internal )
return;
IPoint3D p = targeted as IPoint3D;
if ( p == null || from.Map == null )
if ( !(targeted is IPoint3D p) || from.Map == null )
return;
// Add delay
BaseConfusionBlastPotion.AddDelay( from );
AddDelay( from );
SpellHelper.GetSurfaceTop( ref p );
@ -203,8 +189,8 @@ namespace Server.Items
IEntity to;
if ( p is Mobile )
to = (Mobile)p;
if ( p is Mobile mobile )
to = mobile;
else
to = new Entity( Serial.Zero, new Point3D( p ), from.Map );

View file

@ -117,17 +117,13 @@ namespace Server.Items
Point3D loc;
Map map;
if ( parent is Item )
if ( parent is Item item )
{
Item item = (Item)parent;
loc = item.GetWorldLocation();
map = item.Map;
}
else if ( parent is Mobile )
else if ( parent is Mobile m )
{
Mobile m = (Mobile)parent;
loc = m.Location;
map = m.Map;
}
@ -141,10 +137,10 @@ namespace Server.Items
}
else
{
if ( parent is Item )
((Item)parent).PublicOverheadMessage( MessageType.Regular, 0x22, false, timer.ToString() );
else if ( parent is Mobile )
((Mobile)parent).PublicOverheadMessage( MessageType.Regular, 0x22, false, timer.ToString() );
if ( parent is Item item )
item.PublicOverheadMessage( MessageType.Regular, 0x22, false, timer.ToString() );
else if ( parent is Mobile mobile )
mobile.PublicOverheadMessage( MessageType.Regular, 0x22, false, timer.ToString() );
states[1] = timer - 1;
}
@ -187,9 +183,7 @@ namespace Server.Items
if ( m_Potion.Deleted || m_Potion.Map == Map.Internal )
return;
IPoint3D p = targeted as IPoint3D;
if ( p == null )
if ( !(targeted is IPoint3D p) )
return;
Map map = from.Map;
@ -201,16 +195,14 @@ namespace Server.Items
from.RevealingAction();
IEntity to;
IEntity to = new Entity( Serial.Zero, new Point3D( p ), map );
to = new Entity( Serial.Zero, new Point3D( p ), map );
if ( p is Mobile )
if ( p is Mobile m )
{
if ( !RelativeLocation ) // explosion location = current mob location.
p = ((Mobile)p).Location;
p = m.Location;
else
to = (Mobile)p;
to = m;
}
Effects.SendMovingEffect( from, to, m_Potion.ItemID, 7, 0, false, false, m_Potion.Hue, 0 );
@ -235,9 +227,8 @@ namespace Server.Items
for ( int i = 0; m_Users != null && i < m_Users.Count; ++i )
{
Mobile m = m_Users[i];
ThrowTarget targ = m.Target as ThrowTarget;
if ( targ != null && targ.Potion == this )
if ( m.Target is ThrowTarget targ && targ.Potion == this )
Target.Cancel( m );
}
@ -259,9 +250,9 @@ namespace Server.Items
foreach ( IEntity o in eable )
{
if ( o is Mobile && (from == null || (SpellHelper.ValidIndirectTarget( from, (Mobile)o ) && from.CanBeHarmful( (Mobile)o, false ))))
if ( o is Mobile mobile && (from == null || (SpellHelper.ValidIndirectTarget( from, mobile ) && from.CanBeHarmful( mobile, false ))))
{
toExplode.Add( o );
toExplode.Add( mobile );
++toDamage;
}
else if ( o is BaseExplosionPotion && o != this )
@ -279,12 +270,9 @@ namespace Server.Items
{
object o = toExplode[i];
if ( o is Mobile )
if ( o is Mobile m )
{
Mobile m = (Mobile)o;
if ( from != null )
from.DoHarmful( m );
from?.DoHarmful( m );
int damage = Utility.RandomMinMax( min, max );
@ -297,10 +285,8 @@ namespace Server.Items
AOS.Damage( m, from, damage, 0, 100, 0, 0, 0 );
}
else if ( o is BaseExplosionPotion )
else if ( o is BaseExplosionPotion pot )
{
BaseExplosionPotion pot = (BaseExplosionPotion)o;
pot.Explode( from, false, pot.GetWorldLocation(), pot.Map );
}
}

View file

@ -39,8 +39,8 @@ namespace Server.Items
private static void Hide_Callback( object obj )
{
if ( obj is Mobile )
Hide( (Mobile) obj );
if ( obj is Mobile mobile )
Hide( mobile );
}
public static void Hide( Mobile m )
@ -60,8 +60,8 @@ namespace Server.Items
private static void EndHide_Callback( object obj )
{
if ( obj is Mobile )
EndHide( (Mobile) obj );
if ( obj is Mobile mobile )
EndHide( mobile );
}
public static void EndHide( Mobile m )

View file

@ -270,13 +270,14 @@ namespace Server.Items
{
NetState ns = toCheck.NetState;
if ( ns != null ) {
foreach ( Gump gump in ns.Gumps ) {
RunebookGump bookGump = gump as RunebookGump;
if (ns == null)
return false;
if ( bookGump != null && bookGump.Book == this ) {
return true;
}
foreach ( Gump gump in ns.Gumps )
{
if ( gump is RunebookGump bookGump && bookGump.Book == this )
{
return true;
}
}
@ -295,7 +296,7 @@ namespace Server.Items
if ( m_Crafter != null )
list.Add( 1050043, m_Crafter.Name ); // crafted by ~1_NAME~
if ( m_Description != null && m_Description.Length > 0 )
if ( !string.IsNullOrEmpty(m_Description) )
list.Add( m_Description );
}
@ -358,9 +359,7 @@ namespace Server.Items
public override void OnAfterDuped( Item newItem )
{
Runebook book = newItem as Runebook;
if ( book == null )
if ( !(newItem is Runebook book) )
return;
book.m_Entries = new List<RunebookEntry>();
@ -388,7 +387,7 @@ namespace Server.Items
public override bool OnDragDrop( Mobile from, Item dropped )
{
if ( dropped is RecallRune )
if ( dropped is RecallRune rune )
{
if ( IsLockedDown && from.AccessLevel < AccessLevel.GameMaster )
{
@ -400,13 +399,11 @@ namespace Server.Items
}
else if ( m_Entries.Count < 16 )
{
RecallRune rune = (RecallRune)dropped;
if ( rune.Marked && rune.TargetMap != null )
{
m_Entries.Add( new RunebookEntry( rune.Target, rune.TargetMap, rune.Description, rune.House ) );
dropped.Delete();
rune.Delete();
from.Send( new PlaySound( 0x42, GetWorldLocation() ) );
@ -419,10 +416,8 @@ namespace Server.Items
return true;
}
else
{
from.SendLocalizedMessage( 502409 ); // This rune does not have a marked location.
}
from.SendLocalizedMessage( 502409 ); // This rune does not have a marked location.
}
else
{

View file

@ -64,10 +64,8 @@ namespace Server.Items
private static void AllSpells_OnTarget( Mobile from, object obj )
{
if ( obj is Spellbook )
if ( obj is Spellbook book )
{
Spellbook book = (Spellbook)obj;
if ( book.BookCount == 64 )
book.Content = ulong.MaxValue;
else
@ -268,8 +266,8 @@ namespace Server.Items
Item item = from.FindItemOnLayer( Layer.OneHanded );
if ( item is Spellbook )
list.Add( (Spellbook)item );
if ( item is Spellbook spellbook )
list.Add( spellbook );
Container pack = from.Backpack;
@ -280,8 +278,8 @@ namespace Server.Items
{
item = pack.Items[i];
if ( item is Spellbook )
list.Add( (Spellbook)item );
if ( item is Spellbook spellbook1 )
list.Add( spellbook1 );
}
return list;
@ -352,45 +350,38 @@ namespace Server.Items
public override bool OnDragDrop( Mobile from, Item dropped )
{
if ( dropped is SpellScroll && dropped.Amount == 1 )
if ( dropped is SpellScroll scroll && scroll.Amount == 1 )
{
SpellScroll scroll = (SpellScroll)dropped;
SpellbookType type = GetTypeForSpell( scroll.SpellID );
if ( type != this.SpellbookType )
{
return false;
}
else if ( HasSpell( scroll.SpellID ) )
if ( HasSpell( scroll.SpellID ) )
{
from.SendLocalizedMessage( 500179 ); // That spell is already present in that spellbook.
return false;
}
else
int val = scroll.SpellID - BookOffset;
if ( val >= 0 && val < BookCount )
{
int val = scroll.SpellID - BookOffset;
m_Content |= (ulong)1 << val;
++m_Count;
if ( val >= 0 && val < BookCount )
{
m_Content |= (ulong)1 << val;
++m_Count;
InvalidateProperties();
InvalidateProperties();
scroll.Delete();
scroll.Delete();
from.Send( new PlaySound( 0x249, GetWorldLocation() ) );
return true;
}
return false;
from.Send( new PlaySound( 0x249, GetWorldLocation() ) );
return true;
}
}
else
{
return false;
}
return false;
}
[CommandProperty( AccessLevel.GameMaster )]
@ -452,9 +443,7 @@ namespace Server.Items
public override void OnAfterDuped( Item newItem )
{
Spellbook book = newItem as Spellbook;
if ( book == null )
if ( !(newItem is Spellbook book) )
return;
book.m_AosAttributes = new AosAttributes( newItem, m_AosAttributes );
@ -463,10 +452,8 @@ namespace Server.Items
public override void OnAdded(IEntity parent)
{
if ( Core.AOS && parent is Mobile )
if ( Core.AOS && parent is Mobile from )
{
Mobile from = (Mobile)parent;
m_AosSkillBonuses.AddTo( from );
int strBonus = m_AosAttributes.BonusStr;
@ -493,10 +480,8 @@ namespace Server.Items
public override void OnRemoved(IEntity parent)
{
if ( Core.AOS && parent is Mobile )
if ( Core.AOS && parent is Mobile from )
{
Mobile from = (Mobile)parent;
m_AosSkillBonuses.Remove();
string modName = this.Serial.ToString();
@ -802,31 +787,31 @@ namespace Server.Items
if ( m_AosSkillBonuses == null )
m_AosSkillBonuses = new AosSkillBonuses( this );
if ( Core.AOS && Parent is Mobile )
m_AosSkillBonuses.AddTo( (Mobile) Parent );
if ( Core.AOS && Parent is Mobile mobile )
m_AosSkillBonuses.AddTo( mobile );
int strBonus = m_AosAttributes.BonusStr;
int dexBonus = m_AosAttributes.BonusDex;
int intBonus = m_AosAttributes.BonusInt;
if ( Parent is Mobile && (strBonus != 0 || dexBonus != 0 || intBonus != 0) )
if ( Parent is Mobile m )
{
Mobile m = (Mobile)Parent;
if (strBonus != 0 || dexBonus != 0 || intBonus != 0)
{
string modName = Serial.ToString();
string modName = Serial.ToString();
if ( strBonus != 0 )
m.AddStatMod( new StatMod( StatType.Str, modName + "Str", strBonus, TimeSpan.Zero ) );
if ( strBonus != 0 )
m.AddStatMod( new StatMod( StatType.Str, modName + "Str", strBonus, TimeSpan.Zero ) );
if ( dexBonus != 0 )
m.AddStatMod( new StatMod( StatType.Dex, modName + "Dex", dexBonus, TimeSpan.Zero ) );
if ( dexBonus != 0 )
m.AddStatMod( new StatMod( StatType.Dex, modName + "Dex", dexBonus, TimeSpan.Zero ) );
if ( intBonus != 0 )
m.AddStatMod( new StatMod( StatType.Int, modName + "Int", intBonus, TimeSpan.Zero ) );
}
if ( intBonus != 0 )
m.AddStatMod( new StatMod( StatType.Int, modName + "Int", intBonus, TimeSpan.Zero ) );
m.CheckStatTimers();
}
if ( Parent is Mobile )
((Mobile)Parent).CheckStatTimers();
}
private static int[] m_LegendPropertyCounts = new int[]

View file

@ -81,9 +81,7 @@ namespace Server.Items
private static void EventSink_BandageTargetRequest(BandageTargetRequestEventArgs e)
{
Bandage b = e.Bandage as Bandage;
if (b == null || b.Deleted)
if (!(e.Bandage is Bandage b) || b.Deleted)
return;
Mobile from = e.Mobile;
@ -124,11 +122,11 @@ namespace Server.Items
if ( m_Bandage.Deleted )
return;
if ( targeted is Mobile )
if ( targeted is Mobile mobile )
{
if ( from.InRange( m_Bandage.GetWorldLocation(), Bandage.Range ) )
{
if ( BandageContext.BeginHeal( from, (Mobile)targeted ) != null )
if ( BandageContext.BeginHeal( from, mobile ) != null )
{
if ( !Engines.ConPVP.DuelContext.IsFreeConsume( from ) )
m_Bandage.Consume();
@ -139,9 +137,9 @@ namespace Server.Items
from.SendLocalizedMessage( 500295 ); // You are too far away to do that.
}
}
else if ( targeted is PlagueBeastInnard )
else if ( targeted is PlagueBeastInnard innard )
{
if ( ((PlagueBeastInnard) targeted).OnBandage( from ) )
if ( innard.OnBandage( from ) )
m_Bandage.Consume();
}
else
@ -152,9 +150,9 @@ namespace Server.Items
protected override void OnNonlocalTarget( Mobile from, object targeted )
{
if ( targeted is PlagueBeastInnard )
if ( targeted is PlagueBeastInnard innard )
{
if ( ((PlagueBeastInnard) targeted).OnBandage( from ) )
if ( innard.OnBandage( from ) )
m_Bandage.Consume();
}
else
@ -469,17 +467,17 @@ namespace Server.Items
public static BandageContext BeginHeal( Mobile healer, Mobile patient )
{
bool isDeadPet = ( patient is BaseCreature && ((BaseCreature)patient).IsDeadPet );
BaseCreature creature = patient as BaseCreature;
if ( patient is Golem )
{
healer.SendLocalizedMessage( 500970 ); // Bandages cannot be used on that.
}
else if ( patient is BaseCreature && ((BaseCreature)patient).IsAnimatedDead )
else if ( creature?.IsAnimatedDead == true )
{
healer.SendLocalizedMessage( 500951 ); // You cannot heal that.
}
else if ( !patient.Poisoned && patient.Hits == patient.HitsMax && !BleedAttack.IsBleeding( patient ) && !isDeadPet )
else if ( !patient.Poisoned && patient.Hits == patient.HitsMax && !BleedAttack.IsBleeding( patient ) && creature?.IsDeadPet != true )
{
healer.SendLocalizedMessage( 500955 ); // That being is not damaged!
}
@ -534,8 +532,7 @@ namespace Server.Items
BandageContext context = GetContext( healer );
if ( context != null )
context.StopHeal();
context?.StopHeal();
seconds *= 1000;
context = new BandageContext( healer, patient, TimeSpan.FromMilliseconds( seconds ) );

View file

@ -199,8 +199,8 @@ namespace Server.Items
return;
IPoint3D loc;
if ( targeted is Item )
loc = ((Item)targeted).GetWorldLocation();
if ( targeted is Item item )
loc = item.GetWorldLocation();
else
loc = targeted as IPoint3D;

View file

@ -67,14 +67,12 @@ namespace Server.Items
Recipe r = this.Recipe;
if ( r != null && from is PlayerMobile )
if ( r != null && @from is PlayerMobile pm )
{
PlayerMobile pm = from as PlayerMobile;
if ( !pm.HasRecipe( r ) )
{
bool allRequiredSkills = true;
double chance = r.CraftItem.GetSuccessChance( from, null, r.CraftSystem, false, ref allRequiredSkills );
double chance = r.CraftItem.GetSuccessChance( pm, null, r.CraftSystem, false, ref allRequiredSkills );
if ( allRequiredSkills && chance >= 0.0 )
{

View file

@ -165,9 +165,7 @@ namespace Server.Items
public static BaseInstrument GetInstrument( Mobile from )
{
BaseInstrument item = m_Instruments[from] as BaseInstrument;
if ( item == null )
if ( !(m_Instruments[@from] is BaseInstrument item) )
return null;
if ( !item.IsChildOf( from.Backpack ) )
@ -202,9 +200,7 @@ namespace Server.Items
public static void OnPickedInstrument( Mobile from, object targeted, object state )
{
BaseInstrument instrument = targeted as BaseInstrument;
if ( instrument == null )
if ( !(targeted is BaseInstrument instrument) )
{
from.SendLocalizedMessage( 500619 ); // That is not a musical instrument.
}
@ -214,8 +210,7 @@ namespace Server.Items
InstrumentPickedCallback callback = state as InstrumentPickedCallback;
if ( callback != null )
callback( from, instrument );
callback?.Invoke( @from, instrument );
}
}

View file

@ -316,9 +316,9 @@ namespace Server.Items
if (WeaponIsValid(weapon, from))
{
if (targeted is Mobile)
if (targeted is Mobile mobile)
{
Shoot(player, (Mobile)targeted, weapon);
Shoot(player, mobile, weapon);
}
else if (targeted.GetType() == weapon.AmmoType)
{
@ -382,4 +382,4 @@ namespace Server.Items
}
}
}
}
}

View file

@ -173,21 +173,19 @@ 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.QuestItem )
{
from.SendLocalizedMessage( 1151836 ); // You may not dye toggled quest items.
}
else if ( item is IDyable && m_Tub.AllowDyables )
else if ( item is IDyable dyable && m_Tub.AllowDyables )
{
if ( !from.InRange( m_Tub.GetWorldLocation(), 1 ) || !from.InRange( item.GetWorldLocation(), 1 ) )
from.SendLocalizedMessage( 500446 ); // That is too far away.
else if ( item.Parent is Mobile )
from.SendLocalizedMessage( 500861 ); // Can't Dye clothing that is being worn.
else if ( ((IDyable)item).Dye( from, m_Tub ) )
else if ( dyable.Dye( from, m_Tub ) )
from.PlaySound( 0x23E );
}
else if ( (FurnitureAttribute.Check( item ) || (item is PotionKeg)) && m_Tub.AllowFurniture )
@ -258,7 +256,7 @@ namespace Server.Items
from.PlaySound( 0x23E );
}
}
else if ( (item is BaseArmor && (((BaseArmor)item).MaterialType == ArmorMaterialType.Leather || ((BaseArmor)item).MaterialType == ArmorMaterialType.Studded) || item is ElvenBoots || item is WoodlandBelt) && m_Tub.AllowLeather )
else if ( (item is BaseArmor armor && (armor.MaterialType == ArmorMaterialType.Leather || armor.MaterialType == ArmorMaterialType.Studded) || item is ElvenBoots || item is WoodlandBelt) && m_Tub.AllowLeather )
{
if ( !from.InRange( m_Tub.GetWorldLocation(), 1 ) || !from.InRange( item.GetWorldLocation(), 1 ) )
{

View file

@ -77,10 +77,8 @@ namespace Server.Items
public virtual void SetTubHue( Mobile from, object state, int hue )
{
if ( state is DyeTub )
if ( state is DyeTub tub )
{
DyeTub tub = state as DyeTub;
tub.DyedHue = hue;
/* dyes.m_UsesRemaining--; let this change ride till the overhaul */
@ -89,10 +87,8 @@ namespace Server.Items
protected override void OnTarget( Mobile from, object targeted )
{
if ( targeted is DyeTub )
if ( targeted is DyeTub tub )
{
DyeTub tub = (DyeTub) targeted;
if ( tub.Redyable )
{
if ( tub.MetallicHues ) /* OSI has three metallic tubs now */

View file

@ -71,20 +71,16 @@ namespace Server.Items
{
from.SendLocalizedMessage( 1063305 ); // Didn't your parents ever tell you not to run with scissors in your hand?!
}
else if ( targeted is Item && !((Item)targeted).Movable )
else if ( targeted is Item item && !item.Movable )
{
if ( targeted is IScissorable && ( targeted is PlagueBeastInnard || targeted is PlagueBeastMutationCore ) )
if ( item is IScissorable obj && ( obj is PlagueBeastInnard || obj is PlagueBeastMutationCore ) )
{
IScissorable obj = (IScissorable) targeted;
if ( CanScissor( from, obj ) && obj.Scissor( from, m_Item ) )
from.PlaySound( 0x248 );
}
}
else if ( targeted is IScissorable )
else if ( targeted is IScissorable obj )
{
IScissorable obj = (IScissorable)targeted;
if ( CanScissor( from, obj ) && obj.Scissor( from, m_Item ) )
from.PlaySound( 0x248 );
}
@ -96,10 +92,8 @@ namespace Server.Items
protected override void OnNonlocalTarget( Mobile from, object targeted )
{
if ( targeted is IScissorable && ( targeted is PlagueBeastInnard || targeted is PlagueBeastMutationCore ) )
if ( targeted is IScissorable obj && ( obj is PlagueBeastInnard || obj is PlagueBeastMutationCore ) )
{
IScissorable obj = (IScissorable) targeted;
if ( CanScissor( from, obj ) && obj.Scissor( from, m_Item ) )
from.PlaySound( 0x248 );
}
@ -110,7 +104,7 @@ namespace Server.Items
public static bool CanScissor( Mobile from, IScissorable obj )
{
if ( obj is Item && ( (Item)obj ).Nontransferable )
if ( obj is Item item && item.Nontransferable )
{
from.SendLocalizedMessage( 502440 ); // Scissors can not be used on that to produce anything.
return false;

View file

@ -212,10 +212,8 @@ namespace Server.Items
m_From.NameMod = NameList.RandomName( m_From.Female ? "female" : "male" );
if ( m_From is PlayerMobile )
if ( m_From is PlayerMobile pm )
{
PlayerMobile pm = (PlayerMobile)m_From;
if ( hair )
pm.SetHairMods( entry.m_ItemID, -2 );
else
@ -297,10 +295,10 @@ namespace Server.Items
{
m_Player.NameMod = null;
if ( m_Player is PlayerMobile )
((PlayerMobile)m_Player).SetHairMods( -1, -1 );
if ( m_Player is PlayerMobile mobile )
mobile.SetHairMods( -1, -1 );
DisguiseTimers.RemoveTimer( m_Player );
RemoveTimer( m_Player );
}
}

View file

@ -73,16 +73,16 @@ namespace Server.Items
if ( m_Item.Deleted )
return;
if ( targeted is ILockpickable )
if ( targeted is ILockpickable lockpickable )
{
Item item = (Item)targeted;
Item item = lockpickable as Item;
from.Direction = from.GetDirectionTo( item );
if ( ((ILockpickable)targeted).Locked )
if ( lockpickable.Locked )
{
from.PlaySound( 0x241 );
new InternalTimer( from, (ILockpickable)targeted, m_Item ).Start();
new InternalTimer( from, lockpickable, m_Item ).Start();
}
else
{
@ -101,7 +101,7 @@ namespace Server.Items
private Mobile m_From;
private ILockpickable m_Item;
private Lockpick m_Lockpick;
public InternalTimer( Mobile from, ILockpickable item, Lockpick lockpick ) : base( TimeSpan.FromSeconds( 3.0 ) )
{
m_From = from;
@ -124,7 +124,7 @@ namespace Server.Items
m_Lockpick.Consume();
}
}
protected override void OnTick()
{
Item item = (Item)m_Item;
@ -168,4 +168,4 @@ namespace Server.Items
}
}
}
}
}

View file

@ -26,20 +26,15 @@ namespace Server.Items
from.Send( new MessageLocalizedAffix( from.Serial, from.Body, MessageType.Regular, 0x3B2, 3, 1008146 + (int)Clock.GetMoonPhase( Map.Trammel, from.X, from.Y ), "", AffixType.Prepend, "Trammel : ", "" ) );
from.Send( new MessageLocalizedAffix( from.Serial, from.Body, MessageType.Regular, 0x3B2, 3, 1008146 + (int)Clock.GetMoonPhase( Map.Felucca, from.X, from.Y ), "", AffixType.Prepend, "Felucca : ", "" ) );
PlayerMobile player = from as PlayerMobile;
if ( player != null )
if ( @from is PlayerMobile player )
{
QuestSystem qs = player.Quest;
if ( qs is WitchApprenticeQuest )
{
FindIngredientObjective obj = qs.FindObjective( typeof( FindIngredientObjective ) ) as FindIngredientObjective;
if ( obj != null && !obj.Completed && obj.Ingredient == Ingredient.StarChart )
if ( qs.FindObjective( typeof( FindIngredientObjective ) ) is FindIngredientObjective obj && !obj.Completed && obj.Ingredient == Ingredient.StarChart )
{
int hours, minutes;
Clock.GetTime( from.Map, from.X, from.Y, out hours, out minutes );
Clock.GetTime( from.Map, from.X, from.Y, out int hours, out int _ );
if ( hours < 5 || hours > 17 )
{
@ -74,4 +69,4 @@ namespace Server.Items
int version = reader.ReadInt();
}
}
}
}