Fixes casting checks

This commit is contained in:
Kamron Batman 2018-08-19 01:38:55 +08:00
parent 7ea00fbf4f
commit 03dd5f1926
431 changed files with 5616 additions and 6250 deletions

View file

@ -409,8 +409,8 @@ namespace Server.Factions
{
TimeSpan gameTime = TimeSpan.Zero;
if ( m_From is PlayerMobile )
gameTime = ((PlayerMobile)m_From).GameTime;
if ( m_From is PlayerMobile mobile )
gameTime = mobile.GameTime;
int kp = 0;

View file

@ -198,10 +198,8 @@ namespace Server.Factions
public void HonorLeadership_OnTarget( Mobile from, object obj )
{
if ( obj is Mobile )
if ( obj is Mobile recv )
{
Mobile recv = (Mobile) obj;
PlayerState giveState = PlayerState.Find( from );
PlayerState recvState = PlayerState.Find( recv );
@ -353,7 +351,7 @@ namespace Server.Factions
int killPoints = pl.KillPoints;
if( mob.Backpack != null )
if ( mob.Backpack != null )
{
//Ordinarily, through normal faction removal, this will never find any sigils.
//Only with a leave delay less than the ReturnPeriod or a Faction Kick/Ban, will this ever do anything
@ -377,8 +375,8 @@ namespace Server.Factions
Members.Remove( pl );
if ( mob is PlayerMobile )
((PlayerMobile)mob).FactionPlayerState = null;
if ( mob is PlayerMobile mobile )
mobile.FactionPlayerState = null;
mob.InvalidateProperties();
mob.Delta( MobileDelta.Noto );
@ -397,8 +395,8 @@ namespace Server.Factions
if ( Commander == mob )
Commander = null;
if ( mob is PlayerMobile )
((PlayerMobile)mob).ValidateEquipment();
if ( mob is PlayerMobile playerMobile )
playerMobile.ValidateEquipment();
if ( killPoints > 0 )
DistributePoints( killPoints );
@ -436,9 +434,7 @@ namespace Server.Factions
private bool AlreadyHasCharInFaction( Mobile mob )
{
Account acct = mob.Account as Account;
if ( acct != null )
if ( mob.Account is Account acct )
{
for ( int i = 0; i < acct.Length; ++i )
{
@ -454,9 +450,7 @@ namespace Server.Factions
public static bool IsFactionBanned( Mobile mob )
{
Account acct = mob.Account as Account;
if ( acct == null )
if ( !(mob.Account is Account acct) )
return false;
return ( acct.GetTag( "FactionBanned" ) != null );
@ -464,9 +458,7 @@ namespace Server.Factions
public void OnJoinAccepted( Mobile mob )
{
PlayerMobile pm = mob as PlayerMobile;
if ( pm == null )
if ( !(mob is PlayerMobile pm) )
return; // sanity
PlayerState pl = PlayerState.Find( pm );
@ -483,7 +475,7 @@ namespace Server.Factions
{
Guild guild = pm.Guild as Guild;
if ( guild.Leader != pm )
if ( guild?.Leader != pm )
pm.SendLocalizedMessage( 1005057 ); // You cannot join a faction because you are in a guild and not the guildmaster
else if ( guild.Type != GuildType.Regular )
pm.SendLocalizedMessage( 1042161 ); // You cannot join a faction because your guild is an Order or Chaos type.
@ -499,9 +491,7 @@ namespace Server.Factions
for ( int i = 0; i < members.Count; ++i )
{
PlayerMobile member = members[i] as PlayerMobile;
if ( member == null )
if ( !(members[i] is PlayerMobile member) )
continue;
JoinGuilded( member, guild );
@ -745,9 +735,9 @@ namespace Server.Factions
public static void FactionCommander_OnTarget( Mobile from, object obj )
{
if ( obj is PlayerMobile )
if ( obj is PlayerMobile mobile )
{
Mobile targ = (Mobile)obj;
Mobile targ = mobile;
PlayerState pl = PlayerState.Find( targ );
if ( pl != null )
@ -774,9 +764,9 @@ namespace Server.Factions
public static void FactionElection_OnTarget( Mobile from, object obj )
{
if ( obj is FactionStone )
if ( obj is FactionStone stone )
{
Faction faction = ((FactionStone)obj).Faction;
Faction faction = stone.Faction;
if ( faction != null )
from.SendGump( new ElectionManagementGump( faction.Election ) );
@ -798,10 +788,9 @@ namespace Server.Factions
public static void FactionKick_OnTarget( Mobile from, object obj )
{
if ( obj is Mobile )
if ( obj is Mobile mob )
{
Mobile mob = (Mobile) obj;
PlayerState pl = PlayerState.Find( (Mobile) mob );
PlayerState pl = PlayerState.Find( mob );
if ( pl != null )
{
@ -1004,7 +993,7 @@ namespace Server.Factions
public bool CanHandleInflux( int influx )
{
if( !StabilityActive())
if ( !StabilityActive())
return true;
Faction smallest = FindSmallestFaction();
@ -1063,9 +1052,8 @@ namespace Server.Factions
if ( killerState == null )
return;
if ( victim is BaseCreature )
if ( victim is BaseCreature bc )
{
BaseCreature bc = (BaseCreature)victim;
Faction victimFaction = bc.FactionAllegiance;
if ( bc.Map == Faction.Facet && victimFaction != null && killerState.Faction != victimFaction )
@ -1261,17 +1249,15 @@ namespace Server.Factions
if ( pl != null )
return pl.Faction;
if ( inherit && mob is BaseCreature )
if ( inherit && mob is BaseCreature bc )
{
BaseCreature bc = (BaseCreature)mob;
if ( bc.Controlled )
return Find( bc.ControlMaster, false );
else if ( bc.Summoned )
if ( bc.Summoned )
return Find( bc.SummonMaster, false );
else if ( creatureAllegiances && mob is BaseFactionGuard )
return ((BaseFactionGuard)mob).Faction;
else if ( creatureAllegiances )
if ( creatureAllegiances && bc is BaseFactionGuard guard )
return guard.Faction;
if ( creatureAllegiances )
return bc.FactionAllegiance;
}
@ -1364,9 +1350,7 @@ namespace Server.Factions
}
case FactionKickType.Ban:
{
Account acct = mob.Account as Account;
if ( acct != null )
if ( mob.Account is Account acct )
{
if ( acct.GetTag( "FactionBanned" ) == null )
{
@ -1404,9 +1388,7 @@ namespace Server.Factions
}
case FactionKickType.Unban:
{
Account acct = mob.Account as Account;
if ( acct != null )
if ( mob.Account is Account acct )
{
if ( acct.GetTag( "FactionBanned" ) == null )
{

View file

@ -45,17 +45,16 @@ namespace Server.Factions
public void Attach()
{
if ( m_Item is IFactionItem )
((IFactionItem)m_Item).FactionItemState = this;
if ( m_Item is IFactionItem item )
item.FactionItemState = this;
if ( m_Faction != null )
m_Faction.State.FactionItems.Add( this );
m_Faction?.State.FactionItems.Add( this );
}
public void Detach()
{
if ( m_Item is IFactionItem )
((IFactionItem)m_Item).FactionItemState = null;
if ( m_Item is IFactionItem item )
item.FactionItemState = null;
if ( m_Faction != null && m_Faction.State.FactionItems.Contains( this ) )
m_Faction.State.FactionItems.Remove( this );
@ -107,11 +106,11 @@ namespace Server.Factions
public static FactionItem Find( Item item )
{
if ( item is IFactionItem )
if ( item is IFactionItem factionItem )
{
FactionItem state = ((IFactionItem)item).FactionItemState;
FactionItem state = factionItem.FactionItemState;
if ( state != null && state.HasExpired )
if ( state?.HasExpired == true )
{
state.Detach();
state = null;
@ -143,4 +142,4 @@ namespace Server.Factions
return item;
}
}
}
}

View file

@ -51,7 +51,7 @@ namespace Server.Factions
for ( int i = 0; i < members.Count; ++i )
{
PlayerState ps = members[i];
if ( ps.IsActive )
{
ps.IsActive = false;
@ -219,7 +219,7 @@ namespace Server.Factions
}
m_Faction.State = this;
m_Faction.ZeroRankOffset = m_Members.Count;
m_Members.Sort();
@ -254,9 +254,7 @@ namespace Server.Factions
for ( int i = 0; i < factionTrapCount; ++i )
{
BaseFactionTrap trap = reader.ReadItem() as BaseFactionTrap;
if ( trap != null && !trap.CheckDecay() )
if ( reader.ReadItem() is BaseFactionTrap trap && !trap.CheckDecay() )
m_FactionTraps.Add( trap );
}
}
@ -309,4 +307,4 @@ namespace Server.Factions
writer.Write( (Item) m_FactionTraps[i] );
}
}
}
}

View file

@ -40,8 +40,8 @@ namespace Server.Factions
if ( FactionGump.Exists( from ) )
from.SendLocalizedMessage( 1042160 ); // You already have a faction menu open.
else if ( town.Owner != null && from is PlayerMobile )
from.SendGump( new FinanceGump( (PlayerMobile)from, town.Owner, town ) );
else if ( town.Owner != null && from is PlayerMobile mobile )
mobile.SendGump( new FinanceGump( mobile, town.Owner, town ) );
break;
}
@ -75,7 +75,7 @@ namespace Server.Factions
{
PlayerState pl = PlayerState.Find( from );
if ( pl != null && pl.Finance != null )
if ( pl?.Finance != null )
{
pl.Finance.Finance = null;
from.SendLocalizedMessage( 1005081 ); // You have been fired as Finance Minister
@ -87,7 +87,7 @@ namespace Server.Factions
{
PlayerState pl = PlayerState.Find( from );
if ( pl != null && pl.Sheriff != null )
if ( pl?.Sheriff != null )
{
pl.Sheriff.Sheriff = null;
from.SendLocalizedMessage( 1010270 ); // You have been fired as Sheriff
@ -99,16 +99,16 @@ namespace Server.Factions
{
PlayerState pl = PlayerState.Find( from );
if ( pl != null && pl.IsLeaving )
if ( pl?.IsLeaving == true )
{
if ( Faction.CheckLeaveTimer( from ) )
break;
TimeSpan remaining = ( pl.Leaving + Faction.LeavePeriod ) - DateTime.UtcNow;
if( remaining.TotalDays >= 1 )
if ( remaining.TotalDays >= 1 )
from.SendLocalizedMessage( 1042743, remaining.TotalDays.ToString( "N0" ) ) ;// Your term of service will come to an end in ~1_DAYS~ days.
else if( remaining.TotalHours >= 1 )
else if ( remaining.TotalHours >= 1 )
from.SendLocalizedMessage( 1042741, remaining.TotalHours.ToString( "N0" ) ); // Your term of service will come to an end in ~1_HOURS~ hours.
else
from.SendLocalizedMessage( 1042742 ); // Your term of service will come to an end in less than one hour.
@ -156,4 +156,4 @@ namespace Server.Factions
}
}
}
}
}

View file

@ -169,9 +169,8 @@ namespace Server.Factions
public void Invalidate()
{
if ( m_Mobile is PlayerMobile )
if ( m_Mobile is PlayerMobile pm )
{
PlayerMobile pm = (PlayerMobile)m_Mobile;
pm.InvalidateProperties();
pm.InvalidateMyRunUO();
}
@ -179,8 +178,8 @@ namespace Server.Factions
public void Attach()
{
if ( m_Mobile is PlayerMobile )
((PlayerMobile)m_Mobile).FactionPlayerState = this;
if ( m_Mobile is PlayerMobile mobile )
mobile.FactionPlayerState = this;
}
public PlayerState( Mobile mob, Faction faction, List<PlayerState> owner )
@ -241,10 +240,7 @@ namespace Server.Factions
public static PlayerState Find( Mobile mob )
{
if ( mob is PlayerMobile )
return ((PlayerMobile)mob).FactionPlayerState;
return null;
return mob is PlayerMobile mobile ? mobile.FactionPlayerState : null;
}
public int CompareTo( object obj )

View file

@ -59,20 +59,16 @@ namespace Server.Factions
if ( type.IsSubclassOf( typeof( Faction ) ) )
{
Faction faction = Construct( type ) as Faction;
if ( faction != null )
if ( Construct( type ) is Faction faction )
Faction.Factions.Add( faction );
}
else if ( type.IsSubclassOf( typeof( Town ) ) )
{
Town town = Construct( type ) as Town;
if ( town != null )
if ( Construct( type ) is Town town )
Town.Towns.Add( town );
}
}
}
}
}
}
}

View file

@ -30,14 +30,10 @@ namespace Server.Factions
if ( m.AccessLevel >= AccessLevel.Counselor || Contains( oldLocation ) )
return true;
if ( m is PlayerMobile ) {
PlayerMobile pm = (PlayerMobile)m;
if ( pm.DuelContext != null ) {
m.SendMessage( "You may not enter this area while participating in a duel or a tournament." );
return false;
}
if ( m is PlayerMobile pm && pm.DuelContext != null) {
pm.SendMessage( "You may not enter this area while participating in a duel or a tournament." );
return false;
}
return ( Faction.Find( m, true, true ) != null );
@ -48,4 +44,4 @@ namespace Server.Factions
return false;
}
}
}
}

View file

@ -134,13 +134,8 @@ namespace Server.Factions
foreach ( BaseMonolith monolith in monoliths )
{
if ( monolith is TownMonolith )
{
TownMonolith townMonolith = (TownMonolith)monolith;
if ( townMonolith.Town == this )
return townMonolith;
}
if ( monolith is TownMonolith townMonolith && townMonolith.Town == this )
return townMonolith;
}
return null;
@ -184,20 +179,10 @@ namespace Server.Factions
else if ( isSheriff )
type = "guard";
if ( obj is BaseFactionVendor )
{
BaseFactionVendor vendor = (BaseFactionVendor)obj;
if ( vendor.Town == this && isFinance )
vendor.Delete();
}
else if ( obj is BaseFactionGuard )
{
BaseFactionGuard guard = (BaseFactionGuard)obj;
if ( guard.Town == this && isSheriff )
guard.Delete();
}
if ( obj is BaseFactionVendor vendor && vendor.Town == this && isFinance )
vendor.Delete();
else if ( obj is BaseFactionGuard guard && guard.Town == this && isSheriff )
guard.Delete();
else
{
from.SendMessage( "That is not a {0}!", type );
@ -208,16 +193,14 @@ namespace Server.Factions
public void StartIncomeTimer()
{
if ( m_IncomeTimer != null )
m_IncomeTimer.Stop();
m_IncomeTimer?.Stop();
m_IncomeTimer = Timer.DelayCall( TimeSpan.FromMinutes( 1.0 ), TimeSpan.FromMinutes( 1.0 ), new TimerCallback( CheckIncome ) );
}
public void StopIncomeTimer()
{
if ( m_IncomeTimer != null )
m_IncomeTimer.Stop();
m_IncomeTimer?.Stop();
m_IncomeTimer = null;
}