Changes properties to use automatic property initializers
This commit is contained in:
parent
f0a48ad431
commit
06fa31a7bf
623 changed files with 13072 additions and 19304 deletions
|
|
@ -14,22 +14,16 @@ namespace Server.Factions
|
|||
public const int MaxCandidates = 10;
|
||||
public const int CandidateRank = 5;
|
||||
|
||||
private Faction m_Faction;
|
||||
private List<Candidate> m_Candidates;
|
||||
public Faction Faction { get; }
|
||||
|
||||
private ElectionState m_State;
|
||||
private DateTime m_LastStateTime;
|
||||
public List<Candidate> Candidates { get; }
|
||||
|
||||
public Faction Faction => m_Faction;
|
||||
|
||||
public List<Candidate> Candidates => m_Candidates;
|
||||
|
||||
public ElectionState State{ get => m_State;
|
||||
set{ m_State = value; m_LastStateTime = DateTime.UtcNow; } }
|
||||
public DateTime LastStateTime => m_LastStateTime;
|
||||
public ElectionState State{ get => CurrentState;
|
||||
set{ CurrentState = value; LastStateTime = DateTime.UtcNow; } }
|
||||
public DateTime LastStateTime { get; private set; }
|
||||
|
||||
[CommandProperty( AccessLevel.GameMaster )]
|
||||
public ElectionState CurrentState => m_State;
|
||||
public ElectionState CurrentState { get; private set; }
|
||||
|
||||
[CommandProperty( AccessLevel.GameMaster, AccessLevel.Administrator )]
|
||||
public TimeSpan NextStateTime
|
||||
|
|
@ -38,7 +32,7 @@ namespace Server.Factions
|
|||
{
|
||||
TimeSpan period;
|
||||
|
||||
switch ( m_State )
|
||||
switch ( CurrentState )
|
||||
{
|
||||
default:
|
||||
case ElectionState.Pending: period = PendingPeriod; break;
|
||||
|
|
@ -46,7 +40,7 @@ namespace Server.Factions
|
|||
case ElectionState.Campaign: period = CampaignPeriod; break;
|
||||
}
|
||||
|
||||
TimeSpan until = (m_LastStateTime + period) - DateTime.UtcNow;
|
||||
TimeSpan until = (LastStateTime + period) - DateTime.UtcNow;
|
||||
|
||||
if ( until < TimeSpan.Zero )
|
||||
until = TimeSpan.Zero;
|
||||
|
|
@ -57,7 +51,7 @@ namespace Server.Factions
|
|||
{
|
||||
TimeSpan period;
|
||||
|
||||
switch ( m_State )
|
||||
switch ( CurrentState )
|
||||
{
|
||||
default:
|
||||
case ElectionState.Pending: period = PendingPeriod; break;
|
||||
|
|
@ -65,7 +59,7 @@ namespace Server.Factions
|
|||
case ElectionState.Campaign: period = CampaignPeriod; break;
|
||||
}
|
||||
|
||||
m_LastStateTime = DateTime.UtcNow - period + value;
|
||||
LastStateTime = DateTime.UtcNow - period + value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -78,8 +72,8 @@ namespace Server.Factions
|
|||
|
||||
public Election( Faction faction )
|
||||
{
|
||||
m_Faction = faction;
|
||||
m_Candidates = new List<Candidate>();
|
||||
Faction = faction;
|
||||
Candidates = new List<Candidate>();
|
||||
|
||||
StartTimer();
|
||||
}
|
||||
|
|
@ -92,12 +86,12 @@ namespace Server.Factions
|
|||
{
|
||||
case 0:
|
||||
{
|
||||
m_Faction = Faction.ReadReference( reader );
|
||||
Faction = Faction.ReadReference( reader );
|
||||
|
||||
m_LastStateTime = reader.ReadDateTime();
|
||||
m_State = (ElectionState)reader.ReadEncodedInt();
|
||||
LastStateTime = reader.ReadDateTime();
|
||||
CurrentState = (ElectionState)reader.ReadEncodedInt();
|
||||
|
||||
m_Candidates = new List<Candidate>();
|
||||
Candidates = new List<Candidate>();
|
||||
|
||||
int count = reader.ReadEncodedInt();
|
||||
|
||||
|
|
@ -106,7 +100,7 @@ namespace Server.Factions
|
|||
Candidate cd = new Candidate( reader );
|
||||
|
||||
if ( cd.Mobile != null )
|
||||
m_Candidates.Add( cd );
|
||||
Candidates.Add( cd );
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -120,15 +114,15 @@ namespace Server.Factions
|
|||
{
|
||||
writer.WriteEncodedInt( (int) 0 ); // version
|
||||
|
||||
Faction.WriteReference( writer, m_Faction );
|
||||
Faction.WriteReference( writer, Faction );
|
||||
|
||||
writer.Write( (DateTime) m_LastStateTime );
|
||||
writer.WriteEncodedInt( (int) m_State );
|
||||
writer.Write( (DateTime) LastStateTime );
|
||||
writer.WriteEncodedInt( (int) CurrentState );
|
||||
|
||||
writer.WriteEncodedInt( m_Candidates.Count );
|
||||
writer.WriteEncodedInt( Candidates.Count );
|
||||
|
||||
for ( int i = 0; i < m_Candidates.Count; ++i )
|
||||
m_Candidates[i].Serialize( writer );
|
||||
for ( int i = 0; i < Candidates.Count; ++i )
|
||||
Candidates[i].Serialize( writer );
|
||||
}
|
||||
|
||||
public void AddCandidate( Mobile mob )
|
||||
|
|
@ -136,17 +130,17 @@ namespace Server.Factions
|
|||
if ( IsCandidate( mob ) )
|
||||
return;
|
||||
|
||||
m_Candidates.Add( new Candidate( mob ) );
|
||||
Candidates.Add( new Candidate( mob ) );
|
||||
mob.SendLocalizedMessage( 1010117 ); // You are now running for office.
|
||||
}
|
||||
|
||||
public void RemoveVoter( Mobile mob )
|
||||
{
|
||||
if ( m_State == ElectionState.Election )
|
||||
if ( CurrentState == ElectionState.Election )
|
||||
{
|
||||
for ( int i = 0; i < m_Candidates.Count; ++i )
|
||||
for ( int i = 0; i < Candidates.Count; ++i )
|
||||
{
|
||||
List<Voter> voters = m_Candidates[i].Voters;
|
||||
List<Voter> voters = Candidates[i].Voters;
|
||||
|
||||
for ( int j = 0; j < voters.Count; ++j )
|
||||
{
|
||||
|
|
@ -166,38 +160,38 @@ namespace Server.Factions
|
|||
if ( cd == null )
|
||||
return;
|
||||
|
||||
m_Candidates.Remove( cd );
|
||||
Candidates.Remove( cd );
|
||||
mob.SendLocalizedMessage( 1038031 );
|
||||
|
||||
if ( m_State == ElectionState.Election )
|
||||
if ( CurrentState == ElectionState.Election )
|
||||
{
|
||||
if ( m_Candidates.Count == 1 )
|
||||
if ( Candidates.Count == 1 )
|
||||
{
|
||||
m_Faction.Broadcast( 1038031 ); // There are no longer any valid candidates in the Faction Commander election.
|
||||
Faction.Broadcast( 1038031 ); // There are no longer any valid candidates in the Faction Commander election.
|
||||
|
||||
Candidate winner = m_Candidates[0];
|
||||
Candidate winner = Candidates[0];
|
||||
|
||||
Mobile winMob = winner.Mobile;
|
||||
PlayerState pl = PlayerState.Find( winMob );
|
||||
|
||||
if ( pl == null || pl.Faction != m_Faction || winMob == m_Faction.Commander )
|
||||
if ( pl == null || pl.Faction != Faction || winMob == Faction.Commander )
|
||||
{
|
||||
m_Faction.Broadcast( 1038026 ); // Faction leadership has not changed.
|
||||
Faction.Broadcast( 1038026 ); // Faction leadership has not changed.
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Faction.Broadcast( 1038028 ); // The faction has a new commander.
|
||||
m_Faction.Commander = winMob;
|
||||
Faction.Broadcast( 1038028 ); // The faction has a new commander.
|
||||
Faction.Commander = winMob;
|
||||
}
|
||||
|
||||
m_Candidates.Clear();
|
||||
Candidates.Clear();
|
||||
State = ElectionState.Pending;
|
||||
}
|
||||
else if ( m_Candidates.Count == 0 ) // well, I guess this'll never happen
|
||||
else if ( Candidates.Count == 0 ) // well, I guess this'll never happen
|
||||
{
|
||||
m_Faction.Broadcast( 1038031 ); // There are no longer any valid candidates in the Faction Commander election.
|
||||
Faction.Broadcast( 1038031 ); // There are no longer any valid candidates in the Faction Commander election.
|
||||
|
||||
m_Candidates.Clear();
|
||||
Candidates.Clear();
|
||||
State = ElectionState.Pending;
|
||||
}
|
||||
}
|
||||
|
|
@ -210,7 +204,7 @@ namespace Server.Factions
|
|||
|
||||
public bool CanVote( Mobile mob )
|
||||
{
|
||||
return ( m_State == ElectionState.Election && !HasVoted( mob ) );
|
||||
return ( CurrentState == ElectionState.Election && !HasVoted( mob ) );
|
||||
}
|
||||
|
||||
public bool HasVoted( Mobile mob )
|
||||
|
|
@ -220,10 +214,10 @@ namespace Server.Factions
|
|||
|
||||
public Candidate FindCandidate( Mobile mob )
|
||||
{
|
||||
for ( int i = 0; i < m_Candidates.Count; ++i )
|
||||
for ( int i = 0; i < Candidates.Count; ++i )
|
||||
{
|
||||
if ( m_Candidates[i].Mobile == mob )
|
||||
return m_Candidates[i];
|
||||
if ( Candidates[i].Mobile == mob )
|
||||
return Candidates[i];
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
@ -231,16 +225,16 @@ namespace Server.Factions
|
|||
|
||||
public Candidate FindVoter( Mobile mob )
|
||||
{
|
||||
for ( int i = 0; i < m_Candidates.Count; ++i )
|
||||
for ( int i = 0; i < Candidates.Count; ++i )
|
||||
{
|
||||
List<Voter> voters = m_Candidates[i].Voters;
|
||||
List<Voter> voters = Candidates[i].Voters;
|
||||
|
||||
for ( int j = 0; j < voters.Count; ++j )
|
||||
{
|
||||
Voter voter = voters[j];
|
||||
|
||||
if ( voter.From == mob )
|
||||
return m_Candidates[i];
|
||||
return Candidates[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -252,20 +246,20 @@ namespace Server.Factions
|
|||
if ( IsCandidate( mob ) )
|
||||
return false;
|
||||
|
||||
if ( m_Candidates.Count >= MaxCandidates )
|
||||
if ( Candidates.Count >= MaxCandidates )
|
||||
return false;
|
||||
|
||||
if ( m_State != ElectionState.Campaign )
|
||||
if ( CurrentState != ElectionState.Campaign )
|
||||
return false; // sanity..
|
||||
|
||||
PlayerState pl = PlayerState.Find( mob );
|
||||
|
||||
return ( pl != null && pl.Faction == m_Faction && pl.Rank.Rank >= CandidateRank );
|
||||
return ( pl != null && pl.Faction == Faction && pl.Rank.Rank >= CandidateRank );
|
||||
}
|
||||
|
||||
public void Slice()
|
||||
{
|
||||
if ( m_Faction.Election != this )
|
||||
if ( Faction.Election != this )
|
||||
{
|
||||
m_Timer?.Stop();
|
||||
|
||||
|
|
@ -274,55 +268,55 @@ namespace Server.Factions
|
|||
return;
|
||||
}
|
||||
|
||||
switch ( m_State )
|
||||
switch ( CurrentState )
|
||||
{
|
||||
case ElectionState.Pending:
|
||||
{
|
||||
if ( (m_LastStateTime + PendingPeriod) > DateTime.UtcNow )
|
||||
if ( (LastStateTime + PendingPeriod) > DateTime.UtcNow )
|
||||
break;
|
||||
|
||||
m_Faction.Broadcast( 1038023 ); // Campaigning for the Faction Commander election has begun.
|
||||
Faction.Broadcast( 1038023 ); // Campaigning for the Faction Commander election has begun.
|
||||
|
||||
m_Candidates.Clear();
|
||||
Candidates.Clear();
|
||||
State = ElectionState.Campaign;
|
||||
|
||||
break;
|
||||
}
|
||||
case ElectionState.Campaign:
|
||||
{
|
||||
if ( (m_LastStateTime + CampaignPeriod) > DateTime.UtcNow )
|
||||
if ( (LastStateTime + CampaignPeriod) > DateTime.UtcNow )
|
||||
break;
|
||||
|
||||
if ( m_Candidates.Count == 0 )
|
||||
if ( Candidates.Count == 0 )
|
||||
{
|
||||
m_Faction.Broadcast( 1038025 ); // Nobody ran for office.
|
||||
Faction.Broadcast( 1038025 ); // Nobody ran for office.
|
||||
State = ElectionState.Pending;
|
||||
}
|
||||
else if ( m_Candidates.Count == 1 )
|
||||
else if ( Candidates.Count == 1 )
|
||||
{
|
||||
m_Faction.Broadcast( 1038029 ); // Only one member ran for office.
|
||||
Faction.Broadcast( 1038029 ); // Only one member ran for office.
|
||||
|
||||
Candidate winner = m_Candidates[0];
|
||||
Candidate winner = Candidates[0];
|
||||
|
||||
Mobile mob = winner.Mobile;
|
||||
PlayerState pl = PlayerState.Find( mob );
|
||||
|
||||
if ( pl == null || pl.Faction != m_Faction || mob == m_Faction.Commander )
|
||||
if ( pl == null || pl.Faction != Faction || mob == Faction.Commander )
|
||||
{
|
||||
m_Faction.Broadcast( 1038026 ); // Faction leadership has not changed.
|
||||
Faction.Broadcast( 1038026 ); // Faction leadership has not changed.
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Faction.Broadcast( 1038028 ); // The faction has a new commander.
|
||||
m_Faction.Commander = mob;
|
||||
Faction.Broadcast( 1038028 ); // The faction has a new commander.
|
||||
Faction.Commander = mob;
|
||||
}
|
||||
|
||||
m_Candidates.Clear();
|
||||
Candidates.Clear();
|
||||
State = ElectionState.Pending;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Faction.Broadcast( 1038030 );
|
||||
Faction.Broadcast( 1038030 );
|
||||
State = ElectionState.Election;
|
||||
}
|
||||
|
||||
|
|
@ -330,20 +324,20 @@ namespace Server.Factions
|
|||
}
|
||||
case ElectionState.Election:
|
||||
{
|
||||
if ( (m_LastStateTime + VotingPeriod) > DateTime.UtcNow )
|
||||
if ( (LastStateTime + VotingPeriod) > DateTime.UtcNow )
|
||||
break;
|
||||
|
||||
m_Faction.Broadcast( 1038024 ); // The results for the Faction Commander election are in
|
||||
Faction.Broadcast( 1038024 ); // The results for the Faction Commander election are in
|
||||
|
||||
Candidate winner = null;
|
||||
|
||||
for ( int i = 0; i < m_Candidates.Count; ++i )
|
||||
for ( int i = 0; i < Candidates.Count; ++i )
|
||||
{
|
||||
Candidate cd = m_Candidates[i];
|
||||
Candidate cd = Candidates[i];
|
||||
|
||||
PlayerState pl = PlayerState.Find( cd.Mobile );
|
||||
|
||||
if ( pl == null || pl.Faction != m_Faction )
|
||||
if ( pl == null || pl.Faction != Faction )
|
||||
continue;
|
||||
|
||||
//cd.CleanMuleVotes();
|
||||
|
|
@ -354,19 +348,19 @@ namespace Server.Factions
|
|||
|
||||
if ( winner == null )
|
||||
{
|
||||
m_Faction.Broadcast( 1038026 ); // Faction leadership has not changed.
|
||||
Faction.Broadcast( 1038026 ); // Faction leadership has not changed.
|
||||
}
|
||||
else if ( winner.Mobile == m_Faction.Commander )
|
||||
else if ( winner.Mobile == Faction.Commander )
|
||||
{
|
||||
m_Faction.Broadcast( 1038027 ); // The incumbent won the election.
|
||||
Faction.Broadcast( 1038027 ); // The incumbent won the election.
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Faction.Broadcast( 1038028 ); // The faction has a new commander.
|
||||
m_Faction.Commander = winner.Mobile;
|
||||
Faction.Broadcast( 1038028 ); // The faction has a new commander.
|
||||
Faction.Commander = winner.Mobile;
|
||||
}
|
||||
|
||||
m_Candidates.Clear();
|
||||
Candidates.Clear();
|
||||
State = ElectionState.Pending;
|
||||
|
||||
break;
|
||||
|
|
@ -377,35 +371,29 @@ namespace Server.Factions
|
|||
|
||||
public class Voter
|
||||
{
|
||||
private Mobile m_From;
|
||||
private Mobile m_Candidate;
|
||||
public Mobile From { get; }
|
||||
|
||||
private IPAddress m_Address;
|
||||
private DateTime m_Time;
|
||||
public Mobile Candidate { get; }
|
||||
|
||||
public Mobile From => m_From;
|
||||
public IPAddress Address { get; }
|
||||
|
||||
public Mobile Candidate => m_Candidate;
|
||||
|
||||
public IPAddress Address => m_Address;
|
||||
|
||||
public DateTime Time => m_Time;
|
||||
public DateTime Time { get; }
|
||||
|
||||
public object[] AcquireFields()
|
||||
{
|
||||
TimeSpan gameTime = TimeSpan.Zero;
|
||||
|
||||
if ( m_From is PlayerMobile mobile )
|
||||
if ( From is PlayerMobile mobile )
|
||||
gameTime = mobile.GameTime;
|
||||
|
||||
int kp = 0;
|
||||
|
||||
PlayerState pl = PlayerState.Find( m_From );
|
||||
PlayerState pl = PlayerState.Find( From );
|
||||
|
||||
if ( pl != null )
|
||||
kp = pl.KillPoints;
|
||||
|
||||
int sk = m_From.Skills.Total;
|
||||
int sk = From.Skills.Total;
|
||||
|
||||
int factorSkills = 50 + ( (sk * 100 ) / 10000 );
|
||||
int factorKillPts = 100 + (kp*2);
|
||||
|
|
@ -418,25 +406,25 @@ namespace Server.Factions
|
|||
else if ( totalFactor < 0 )
|
||||
totalFactor = 0;
|
||||
|
||||
return new object[]{ m_From, m_Address, m_Time, totalFactor };
|
||||
return new object[]{ From, Address, Time, totalFactor };
|
||||
}
|
||||
|
||||
public Voter( Mobile from, Mobile candidate )
|
||||
{
|
||||
m_From = from;
|
||||
m_Candidate = candidate;
|
||||
From = from;
|
||||
Candidate = candidate;
|
||||
|
||||
if ( m_From.NetState != null )
|
||||
m_Address = m_From.NetState.Address;
|
||||
if ( From.NetState != null )
|
||||
Address = From.NetState.Address;
|
||||
else
|
||||
m_Address = IPAddress.None;
|
||||
Address = IPAddress.None;
|
||||
|
||||
m_Time = DateTime.UtcNow;
|
||||
Time = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public Voter( GenericReader reader, Mobile candidate )
|
||||
{
|
||||
m_Candidate = candidate;
|
||||
Candidate = candidate;
|
||||
|
||||
int version = reader.ReadEncodedInt();
|
||||
|
||||
|
|
@ -444,9 +432,9 @@ namespace Server.Factions
|
|||
{
|
||||
case 0:
|
||||
{
|
||||
m_From = reader.ReadMobile();
|
||||
m_Address = Utility.Intern( reader.ReadIPAddress() );
|
||||
m_Time = reader.ReadDateTime();
|
||||
From = reader.ReadMobile();
|
||||
Address = Utility.Intern( reader.ReadIPAddress() );
|
||||
Time = reader.ReadDateTime();
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
@ -457,37 +445,35 @@ namespace Server.Factions
|
|||
{
|
||||
writer.WriteEncodedInt( (int) 0 );
|
||||
|
||||
writer.Write( (Mobile) m_From );
|
||||
writer.Write( (IPAddress) m_Address );
|
||||
writer.Write( (DateTime) m_Time );
|
||||
writer.Write( (Mobile) From );
|
||||
writer.Write( (IPAddress) Address );
|
||||
writer.Write( (DateTime) Time );
|
||||
}
|
||||
}
|
||||
|
||||
public class Candidate
|
||||
{
|
||||
private Mobile m_Mobile;
|
||||
private List<Voter> m_Voters;
|
||||
public Mobile Mobile { get; }
|
||||
|
||||
public Mobile Mobile => m_Mobile;
|
||||
public List<Voter> Voters => m_Voters;
|
||||
public List<Voter> Voters { get; }
|
||||
|
||||
public int Votes => m_Voters.Count;
|
||||
public int Votes => Voters.Count;
|
||||
|
||||
public void CleanMuleVotes()
|
||||
{
|
||||
for ( int i = 0; i < m_Voters.Count; ++i )
|
||||
for ( int i = 0; i < Voters.Count; ++i )
|
||||
{
|
||||
Voter voter = (Voter)m_Voters[i];
|
||||
Voter voter = (Voter)Voters[i];
|
||||
|
||||
if ( (int)voter.AcquireFields()[3] < 90 )
|
||||
m_Voters.RemoveAt( i-- );
|
||||
Voters.RemoveAt( i-- );
|
||||
}
|
||||
}
|
||||
|
||||
public Candidate( Mobile mob )
|
||||
{
|
||||
m_Mobile = mob;
|
||||
m_Voters = new List<Voter>();
|
||||
Mobile = mob;
|
||||
Voters = new List<Voter>();
|
||||
}
|
||||
|
||||
public Candidate( GenericReader reader )
|
||||
|
|
@ -498,30 +484,30 @@ namespace Server.Factions
|
|||
{
|
||||
case 1:
|
||||
{
|
||||
m_Mobile = reader.ReadMobile();
|
||||
Mobile = reader.ReadMobile();
|
||||
|
||||
int count = reader.ReadEncodedInt();
|
||||
m_Voters = new List<Voter>( count );
|
||||
Voters = new List<Voter>( count );
|
||||
|
||||
for ( int i = 0; i < count; ++i )
|
||||
{
|
||||
Voter voter = new Voter( reader, m_Mobile );
|
||||
Voter voter = new Voter( reader, Mobile );
|
||||
|
||||
if ( voter.From != null )
|
||||
m_Voters.Add( voter );
|
||||
Voters.Add( voter );
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 0:
|
||||
{
|
||||
m_Mobile = reader.ReadMobile();
|
||||
Mobile = reader.ReadMobile();
|
||||
|
||||
List<Mobile> mobs = reader.ReadStrongMobileList();
|
||||
m_Voters = new List<Voter>( mobs.Count );
|
||||
Voters = new List<Voter>( mobs.Count );
|
||||
|
||||
for ( int i = 0; i < mobs.Count; ++i )
|
||||
m_Voters.Add( new Voter( mobs[i], m_Mobile ) );
|
||||
Voters.Add( new Voter( mobs[i], Mobile ) );
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
@ -532,12 +518,12 @@ namespace Server.Factions
|
|||
{
|
||||
writer.WriteEncodedInt( (int) 1 ); // version
|
||||
|
||||
writer.Write( (Mobile) m_Mobile );
|
||||
writer.Write( (Mobile) Mobile );
|
||||
|
||||
writer.WriteEncodedInt( (int) m_Voters.Count );
|
||||
writer.WriteEncodedInt( (int) Voters.Count );
|
||||
|
||||
for ( int i = 0; i < m_Voters.Count; ++i )
|
||||
((Voter)m_Voters[i]).Serialize( writer );
|
||||
for ( int i = 0; i < Voters.Count; ++i )
|
||||
((Voter)Voters[i]).Serialize( writer );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,14 +18,8 @@ namespace Server.Factions
|
|||
public int ZeroRankOffset;
|
||||
|
||||
private FactionDefinition m_Definition;
|
||||
private FactionState m_State;
|
||||
private StrongholdRegion m_StrongholdRegion;
|
||||
|
||||
public StrongholdRegion StrongholdRegion
|
||||
{
|
||||
get => m_StrongholdRegion;
|
||||
set => m_StrongholdRegion = value;
|
||||
}
|
||||
public StrongholdRegion StrongholdRegion { get; set; }
|
||||
|
||||
public FactionDefinition Definition
|
||||
{
|
||||
|
|
@ -33,49 +27,45 @@ namespace Server.Factions
|
|||
set
|
||||
{
|
||||
m_Definition = value;
|
||||
m_StrongholdRegion = new StrongholdRegion( this );
|
||||
StrongholdRegion = new StrongholdRegion( this );
|
||||
}
|
||||
}
|
||||
|
||||
public FactionState State
|
||||
{
|
||||
get => m_State;
|
||||
set => m_State = value;
|
||||
}
|
||||
public FactionState State { get; set; }
|
||||
|
||||
public Election Election
|
||||
{
|
||||
get => m_State.Election;
|
||||
set => m_State.Election = value;
|
||||
get => State.Election;
|
||||
set => State.Election = value;
|
||||
}
|
||||
|
||||
public Mobile Commander
|
||||
{
|
||||
get => m_State.Commander;
|
||||
set => m_State.Commander = value;
|
||||
get => State.Commander;
|
||||
set => State.Commander = value;
|
||||
}
|
||||
|
||||
public int Tithe
|
||||
{
|
||||
get => m_State.Tithe;
|
||||
set => m_State.Tithe = value;
|
||||
get => State.Tithe;
|
||||
set => State.Tithe = value;
|
||||
}
|
||||
|
||||
public int Silver
|
||||
{
|
||||
get => m_State.Silver;
|
||||
set => m_State.Silver = value;
|
||||
get => State.Silver;
|
||||
set => State.Silver = value;
|
||||
}
|
||||
|
||||
public List<PlayerState> Members
|
||||
{
|
||||
get => m_State.Members;
|
||||
set => m_State.Members = value;
|
||||
get => State.Members;
|
||||
set => State.Members = value;
|
||||
}
|
||||
|
||||
public static readonly TimeSpan LeavePeriod = TimeSpan.FromDays( 3.0 );
|
||||
|
||||
public bool FactionMessageReady => m_State.FactionMessageReady;
|
||||
public bool FactionMessageReady => State.FactionMessageReady;
|
||||
|
||||
public void Broadcast( string text )
|
||||
{
|
||||
|
|
@ -117,7 +107,7 @@ namespace Server.Factions
|
|||
public void EndBroadcast( Mobile from, string text )
|
||||
{
|
||||
if ( from.AccessLevel == AccessLevel.Player )
|
||||
m_State.RegisterBroadcast();
|
||||
State.RegisterBroadcast();
|
||||
|
||||
Broadcast( Definition.HueBroadcast, "{0} [Commander] {1} : {2}", from.Name, Definition.FriendlyName, text );
|
||||
}
|
||||
|
|
@ -514,7 +504,7 @@ namespace Server.Factions
|
|||
|
||||
public Faction()
|
||||
{
|
||||
m_State = new FactionState( this );
|
||||
State = new FactionState( this );
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
|
@ -949,8 +939,8 @@ namespace Server.Factions
|
|||
|
||||
public List<BaseFactionTrap> Traps
|
||||
{
|
||||
get => m_State.Traps;
|
||||
set => m_State.Traps = value;
|
||||
get => State.Traps;
|
||||
set => State.Traps = value;
|
||||
}
|
||||
|
||||
public const int StabilityFactor = 300; // 300% greater (3 times) than smallest faction
|
||||
|
|
|
|||
|
|
@ -11,28 +11,26 @@ namespace Server.Factions
|
|||
{
|
||||
public static readonly TimeSpan ExpirationPeriod = TimeSpan.FromDays( 21.0 );
|
||||
|
||||
private Item m_Item;
|
||||
private Faction m_Faction;
|
||||
private DateTime m_Expiration;
|
||||
public Item Item { get; }
|
||||
|
||||
public Item Item => m_Item;
|
||||
public Faction Faction => m_Faction;
|
||||
public DateTime Expiration => m_Expiration;
|
||||
public Faction Faction { get; }
|
||||
|
||||
public DateTime Expiration { get; private set; }
|
||||
|
||||
public bool HasExpired
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Item == null || m_Item.Deleted )
|
||||
if ( Item == null || Item.Deleted )
|
||||
return true;
|
||||
|
||||
return ( m_Expiration != DateTime.MinValue && DateTime.UtcNow >= m_Expiration );
|
||||
return ( Expiration != DateTime.MinValue && DateTime.UtcNow >= Expiration );
|
||||
}
|
||||
}
|
||||
|
||||
public void StartExpiration()
|
||||
{
|
||||
m_Expiration = DateTime.UtcNow + ExpirationPeriod;
|
||||
Expiration = DateTime.UtcNow + ExpirationPeriod;
|
||||
}
|
||||
|
||||
public void CheckAttach()
|
||||
|
|
@ -45,25 +43,25 @@ namespace Server.Factions
|
|||
|
||||
public void Attach()
|
||||
{
|
||||
if ( m_Item is IFactionItem item )
|
||||
if ( Item is IFactionItem item )
|
||||
item.FactionItemState = this;
|
||||
|
||||
m_Faction?.State.FactionItems.Add( this );
|
||||
Faction?.State.FactionItems.Add( this );
|
||||
}
|
||||
|
||||
public void Detach()
|
||||
{
|
||||
if ( m_Item is IFactionItem item )
|
||||
if ( Item is IFactionItem item )
|
||||
item.FactionItemState = null;
|
||||
|
||||
if ( m_Faction != null && m_Faction.State.FactionItems.Contains( this ) )
|
||||
m_Faction.State.FactionItems.Remove( this );
|
||||
if ( Faction != null && Faction.State.FactionItems.Contains( this ) )
|
||||
Faction.State.FactionItems.Remove( this );
|
||||
}
|
||||
|
||||
public FactionItem( Item item, Faction faction )
|
||||
{
|
||||
m_Item = item;
|
||||
m_Faction = faction;
|
||||
Item = item;
|
||||
Faction = faction;
|
||||
}
|
||||
|
||||
public FactionItem( GenericReader reader, Faction faction )
|
||||
|
|
@ -74,21 +72,21 @@ namespace Server.Factions
|
|||
{
|
||||
case 0:
|
||||
{
|
||||
m_Item = reader.ReadItem();
|
||||
m_Expiration = reader.ReadDateTime();
|
||||
Item = reader.ReadItem();
|
||||
Expiration = reader.ReadDateTime();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_Faction = faction;
|
||||
Faction = faction;
|
||||
}
|
||||
|
||||
public void Serialize( GenericWriter writer )
|
||||
{
|
||||
writer.WriteEncodedInt( (int) 0 );
|
||||
|
||||
writer.Write( (Item) m_Item );
|
||||
writer.Write( (DateTime) m_Expiration );
|
||||
writer.Write( (Item) Item );
|
||||
writer.Write( (DateTime) Expiration );
|
||||
}
|
||||
|
||||
public static int GetMaxWearables( Mobile mob )
|
||||
|
|
|
|||
|
|
@ -7,22 +7,13 @@ namespace Server.Factions
|
|||
{
|
||||
private Faction m_Faction;
|
||||
private Mobile m_Commander;
|
||||
private int m_Tithe;
|
||||
private int m_Silver;
|
||||
private List<PlayerState> m_Members;
|
||||
private Election m_Election;
|
||||
private List<FactionItem> m_FactionItems;
|
||||
private List<BaseFactionTrap> m_FactionTraps;
|
||||
private DateTime m_LastAtrophy;
|
||||
|
||||
private const int BroadcastsPerPeriod = 2;
|
||||
private static readonly TimeSpan BroadcastPeriod = TimeSpan.FromHours( 1.0 );
|
||||
|
||||
private DateTime[] m_LastBroadcasts = new DateTime[BroadcastsPerPeriod];
|
||||
|
||||
public DateTime LastAtrophy{ get => m_LastAtrophy;
|
||||
set => m_LastAtrophy = value;
|
||||
}
|
||||
public DateTime LastAtrophy { get; set; }
|
||||
|
||||
public bool FactionMessageReady
|
||||
{
|
||||
|
|
@ -38,17 +29,17 @@ namespace Server.Factions
|
|||
}
|
||||
}
|
||||
|
||||
public bool IsAtrophyReady => DateTime.UtcNow >= (m_LastAtrophy + TimeSpan.FromHours( 47.0 ));
|
||||
public bool IsAtrophyReady => DateTime.UtcNow >= (LastAtrophy + TimeSpan.FromHours( 47.0 ));
|
||||
|
||||
public int CheckAtrophy()
|
||||
{
|
||||
if ( DateTime.UtcNow < (m_LastAtrophy + TimeSpan.FromHours( 47.0 )) )
|
||||
if ( DateTime.UtcNow < (LastAtrophy + TimeSpan.FromHours( 47.0 )) )
|
||||
return 0;
|
||||
|
||||
int distrib = 0;
|
||||
m_LastAtrophy = DateTime.UtcNow;
|
||||
LastAtrophy = DateTime.UtcNow;
|
||||
|
||||
List<PlayerState> members = new List<PlayerState>( m_Members );
|
||||
List<PlayerState> members = new List<PlayerState>( Members );
|
||||
|
||||
for ( int i = 0; i < members.Count; ++i )
|
||||
{
|
||||
|
|
@ -83,23 +74,11 @@ namespace Server.Factions
|
|||
}
|
||||
}
|
||||
|
||||
public List<FactionItem> FactionItems
|
||||
{
|
||||
get => m_FactionItems;
|
||||
set => m_FactionItems = value;
|
||||
}
|
||||
public List<FactionItem> FactionItems { get; set; }
|
||||
|
||||
public List<BaseFactionTrap> Traps
|
||||
{
|
||||
get => m_FactionTraps;
|
||||
set => m_FactionTraps = value;
|
||||
}
|
||||
public List<BaseFactionTrap> Traps { get; set; }
|
||||
|
||||
public Election Election
|
||||
{
|
||||
get => m_Election;
|
||||
set => m_Election = value;
|
||||
}
|
||||
public Election Election { get; set; }
|
||||
|
||||
public Mobile Commander
|
||||
{
|
||||
|
|
@ -127,32 +106,20 @@ namespace Server.Factions
|
|||
}
|
||||
}
|
||||
|
||||
public int Tithe
|
||||
{
|
||||
get => m_Tithe;
|
||||
set => m_Tithe = value;
|
||||
}
|
||||
public int Tithe { get; set; }
|
||||
|
||||
public int Silver
|
||||
{
|
||||
get => m_Silver;
|
||||
set => m_Silver = value;
|
||||
}
|
||||
public int Silver { get; set; }
|
||||
|
||||
public List<PlayerState> Members
|
||||
{
|
||||
get => m_Members;
|
||||
set => m_Members = value;
|
||||
}
|
||||
public List<PlayerState> Members { get; set; }
|
||||
|
||||
public FactionState( Faction faction )
|
||||
{
|
||||
m_Faction = faction;
|
||||
m_Tithe = 50;
|
||||
m_Members = new List<PlayerState>();
|
||||
m_Election = new Election( faction );
|
||||
m_FactionItems = new List<FactionItem>();
|
||||
m_FactionTraps = new List<BaseFactionTrap>();
|
||||
Tithe = 50;
|
||||
Members = new List<PlayerState>();
|
||||
Election = new Election( faction );
|
||||
FactionItems = new List<FactionItem>();
|
||||
Traps = new List<BaseFactionTrap>();
|
||||
}
|
||||
|
||||
public FactionState( GenericReader reader )
|
||||
|
|
@ -163,7 +130,7 @@ namespace Server.Factions
|
|||
{
|
||||
case 5:
|
||||
{
|
||||
m_LastAtrophy = reader.ReadDateTime();
|
||||
LastAtrophy = reader.ReadDateTime();
|
||||
goto case 4;
|
||||
}
|
||||
case 4:
|
||||
|
|
@ -184,7 +151,7 @@ namespace Server.Factions
|
|||
case 2:
|
||||
case 1:
|
||||
{
|
||||
m_Election = new Election( reader );
|
||||
Election = new Election( reader );
|
||||
|
||||
goto case 0;
|
||||
}
|
||||
|
|
@ -195,7 +162,7 @@ namespace Server.Factions
|
|||
m_Commander = reader.ReadMobile();
|
||||
|
||||
if ( version < 5 )
|
||||
m_LastAtrophy = DateTime.UtcNow;
|
||||
LastAtrophy = DateTime.UtcNow;
|
||||
|
||||
if ( version < 4 )
|
||||
{
|
||||
|
|
@ -205,28 +172,28 @@ namespace Server.Factions
|
|||
m_LastBroadcasts[0] = time;
|
||||
}
|
||||
|
||||
m_Tithe = reader.ReadEncodedInt();
|
||||
m_Silver = reader.ReadEncodedInt();
|
||||
Tithe = reader.ReadEncodedInt();
|
||||
Silver = reader.ReadEncodedInt();
|
||||
|
||||
int memberCount = reader.ReadEncodedInt();
|
||||
|
||||
m_Members = new List<PlayerState>();
|
||||
Members = new List<PlayerState>();
|
||||
|
||||
for ( int i = 0; i < memberCount; ++i )
|
||||
{
|
||||
PlayerState pl = new PlayerState( reader, m_Faction, m_Members );
|
||||
PlayerState pl = new PlayerState( reader, m_Faction, Members );
|
||||
|
||||
if ( pl.Mobile != null )
|
||||
m_Members.Add( pl );
|
||||
Members.Add( pl );
|
||||
}
|
||||
|
||||
m_Faction.State = this;
|
||||
|
||||
m_Faction.ZeroRankOffset = m_Members.Count;
|
||||
m_Members.Sort();
|
||||
m_Faction.ZeroRankOffset = Members.Count;
|
||||
Members.Sort();
|
||||
|
||||
for ( int i = m_Members.Count - 1; i >= 0; i-- ) {
|
||||
PlayerState player = m_Members[i];
|
||||
for ( int i = Members.Count - 1; i >= 0; i-- ) {
|
||||
PlayerState player = Members[i];
|
||||
|
||||
if ( player.KillPoints <= 0 )
|
||||
m_Faction.ZeroRankOffset = i;
|
||||
|
|
@ -234,7 +201,7 @@ namespace Server.Factions
|
|||
player.RankIndex = i;
|
||||
}
|
||||
|
||||
m_FactionItems = new List<FactionItem>();
|
||||
FactionItems = new List<FactionItem>();
|
||||
|
||||
if ( version >= 2 )
|
||||
{
|
||||
|
|
@ -248,7 +215,7 @@ namespace Server.Factions
|
|||
}
|
||||
}
|
||||
|
||||
m_FactionTraps = new List<BaseFactionTrap>();
|
||||
Traps = new List<BaseFactionTrap>();
|
||||
|
||||
if ( version >= 3 )
|
||||
{
|
||||
|
|
@ -257,7 +224,7 @@ namespace Server.Factions
|
|||
for ( int i = 0; i < factionTrapCount; ++i )
|
||||
{
|
||||
if ( reader.ReadItem() is BaseFactionTrap trap && !trap.CheckDecay() )
|
||||
m_FactionTraps.Add( trap );
|
||||
Traps.Add( trap );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -266,47 +233,47 @@ namespace Server.Factions
|
|||
}
|
||||
|
||||
if ( version < 1 )
|
||||
m_Election = new Election( m_Faction );
|
||||
Election = new Election( m_Faction );
|
||||
}
|
||||
|
||||
public void Serialize( GenericWriter writer )
|
||||
{
|
||||
writer.WriteEncodedInt( (int) 5 ); // version
|
||||
|
||||
writer.Write( m_LastAtrophy );
|
||||
writer.Write( LastAtrophy );
|
||||
|
||||
writer.WriteEncodedInt( (int) m_LastBroadcasts.Length );
|
||||
|
||||
for ( int i = 0; i < m_LastBroadcasts.Length; ++i )
|
||||
writer.Write( (DateTime) m_LastBroadcasts[i] );
|
||||
|
||||
m_Election.Serialize( writer );
|
||||
Election.Serialize( writer );
|
||||
|
||||
Faction.WriteReference( writer, m_Faction );
|
||||
|
||||
writer.Write( (Mobile) m_Commander );
|
||||
|
||||
writer.WriteEncodedInt( (int) m_Tithe );
|
||||
writer.WriteEncodedInt( (int) m_Silver );
|
||||
writer.WriteEncodedInt( (int) Tithe );
|
||||
writer.WriteEncodedInt( (int) Silver );
|
||||
|
||||
writer.WriteEncodedInt( (int) m_Members.Count );
|
||||
writer.WriteEncodedInt( (int) Members.Count );
|
||||
|
||||
for ( int i = 0; i < m_Members.Count; ++i )
|
||||
for ( int i = 0; i < Members.Count; ++i )
|
||||
{
|
||||
PlayerState pl = (PlayerState) m_Members[i];
|
||||
PlayerState pl = (PlayerState) Members[i];
|
||||
|
||||
pl.Serialize( writer );
|
||||
}
|
||||
|
||||
writer.WriteEncodedInt( (int) m_FactionItems.Count );
|
||||
writer.WriteEncodedInt( (int) FactionItems.Count );
|
||||
|
||||
for ( int i = 0; i < m_FactionItems.Count; ++i )
|
||||
m_FactionItems[i].Serialize( writer );
|
||||
for ( int i = 0; i < FactionItems.Count; ++i )
|
||||
FactionItems[i].Serialize( writer );
|
||||
|
||||
writer.WriteEncodedInt( (int) m_FactionTraps.Count );
|
||||
writer.WriteEncodedInt( (int) Traps.Count );
|
||||
|
||||
for ( int i = 0; i < m_FactionTraps.Count; ++i )
|
||||
writer.Write( (Item) m_FactionTraps[i] );
|
||||
for ( int i = 0; i < Traps.Count; ++i )
|
||||
writer.Write( (Item) Traps[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,22 +5,20 @@ namespace Server.Factions
|
|||
{
|
||||
public class GuardList
|
||||
{
|
||||
private GuardDefinition m_Definition;
|
||||
private List<BaseFactionGuard> m_Guards;
|
||||
public GuardDefinition Definition { get; }
|
||||
|
||||
public GuardDefinition Definition => m_Definition;
|
||||
public List<BaseFactionGuard> Guards => m_Guards;
|
||||
public List<BaseFactionGuard> Guards { get; }
|
||||
|
||||
public BaseFactionGuard Construct()
|
||||
{
|
||||
try{ return Activator.CreateInstance( m_Definition.Type ) as BaseFactionGuard; }
|
||||
try{ return Activator.CreateInstance( Definition.Type ) as BaseFactionGuard; }
|
||||
catch{ return null; }
|
||||
}
|
||||
|
||||
public GuardList( GuardDefinition definition )
|
||||
{
|
||||
m_Definition = definition;
|
||||
m_Guards = new List<BaseFactionGuard>();
|
||||
Definition = definition;
|
||||
Guards = new List<BaseFactionGuard>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -12,56 +12,53 @@ namespace Server.Factions
|
|||
|
||||
public class MerchantTitleInfo
|
||||
{
|
||||
private SkillName m_Skill;
|
||||
private double m_Requirement;
|
||||
private TextDefinition m_Title;
|
||||
private TextDefinition m_Label;
|
||||
private TextDefinition m_Assigned;
|
||||
public SkillName Skill { get; }
|
||||
|
||||
public SkillName Skill => m_Skill;
|
||||
public double Requirement => m_Requirement;
|
||||
public TextDefinition Title => m_Title;
|
||||
public TextDefinition Label => m_Label;
|
||||
public TextDefinition Assigned => m_Assigned;
|
||||
public double Requirement { get; }
|
||||
|
||||
public TextDefinition Title { get; }
|
||||
|
||||
public TextDefinition Label { get; }
|
||||
|
||||
public TextDefinition Assigned { get; }
|
||||
|
||||
public MerchantTitleInfo( SkillName skill, double requirement, TextDefinition title, TextDefinition label, TextDefinition assigned )
|
||||
{
|
||||
m_Skill = skill;
|
||||
m_Requirement = requirement;
|
||||
m_Title = title;
|
||||
m_Label = label;
|
||||
m_Assigned = assigned;
|
||||
Skill = skill;
|
||||
Requirement = requirement;
|
||||
Title = title;
|
||||
Label = label;
|
||||
Assigned = assigned;
|
||||
}
|
||||
}
|
||||
|
||||
public class MerchantTitles
|
||||
{
|
||||
private static MerchantTitleInfo[] m_Info = {
|
||||
new MerchantTitleInfo( SkillName.Inscribe, 90.0, new TextDefinition( 1060773, "Scribe" ), new TextDefinition( 1011468, "SCRIBE" ), new TextDefinition( 1010121, "You now have the faction title of scribe" ) ),
|
||||
new MerchantTitleInfo( SkillName.Carpentry, 90.0, new TextDefinition( 1060774, "Carpenter" ), new TextDefinition( 1011469, "CARPENTER" ), new TextDefinition( 1010122, "You now have the faction title of carpenter" ) ),
|
||||
new MerchantTitleInfo( SkillName.Tinkering, 90.0, new TextDefinition( 1022984, "Tinker" ), new TextDefinition( 1011470, "TINKER" ), new TextDefinition( 1010123, "You now have the faction title of tinker" ) ),
|
||||
new MerchantTitleInfo( SkillName.Blacksmith, 90.0, new TextDefinition( 1023016, "Blacksmith" ), new TextDefinition( 1011471, "BLACKSMITH" ), new TextDefinition( 1010124, "You now have the faction title of blacksmith" ) ),
|
||||
new MerchantTitleInfo( SkillName.Fletching, 90.0, new TextDefinition( 1023022, "Bowyer" ), new TextDefinition( 1011472, "BOWYER" ), new TextDefinition( 1010125, "You now have the faction title of Bowyer" ) ),
|
||||
new MerchantTitleInfo( SkillName.Tailoring, 90.0, new TextDefinition( 1022982, "Tailor" ), new TextDefinition( 1018300, "TAILOR" ), new TextDefinition( 1042162, "You now have the faction title of Tailor" ) ),
|
||||
};
|
||||
|
||||
public static MerchantTitleInfo[] Info => m_Info;
|
||||
public static MerchantTitleInfo[] Info { get; } =
|
||||
{
|
||||
new MerchantTitleInfo( SkillName.Inscribe, 90.0, new TextDefinition( 1060773, "Scribe" ), new TextDefinition( 1011468, "SCRIBE" ), new TextDefinition( 1010121, "You now have the faction title of scribe" ) ),
|
||||
new MerchantTitleInfo( SkillName.Carpentry, 90.0, new TextDefinition( 1060774, "Carpenter" ), new TextDefinition( 1011469, "CARPENTER" ), new TextDefinition( 1010122, "You now have the faction title of carpenter" ) ),
|
||||
new MerchantTitleInfo( SkillName.Tinkering, 90.0, new TextDefinition( 1022984, "Tinker" ), new TextDefinition( 1011470, "TINKER" ), new TextDefinition( 1010123, "You now have the faction title of tinker" ) ),
|
||||
new MerchantTitleInfo( SkillName.Blacksmith, 90.0, new TextDefinition( 1023016, "Blacksmith" ), new TextDefinition( 1011471, "BLACKSMITH" ), new TextDefinition( 1010124, "You now have the faction title of blacksmith" ) ),
|
||||
new MerchantTitleInfo( SkillName.Fletching, 90.0, new TextDefinition( 1023022, "Bowyer" ), new TextDefinition( 1011472, "BOWYER" ), new TextDefinition( 1010125, "You now have the faction title of Bowyer" ) ),
|
||||
new MerchantTitleInfo( SkillName.Tailoring, 90.0, new TextDefinition( 1022982, "Tailor" ), new TextDefinition( 1018300, "TAILOR" ), new TextDefinition( 1042162, "You now have the faction title of Tailor" ) ),
|
||||
};
|
||||
|
||||
public static MerchantTitleInfo GetInfo( MerchantTitle title )
|
||||
{
|
||||
int idx = (int)title - 1;
|
||||
|
||||
if ( idx >= 0 && idx < m_Info.Length )
|
||||
return m_Info[idx];
|
||||
if ( idx >= 0 && idx < Info.Length )
|
||||
return Info[idx];
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static bool HasMerchantQualifications( Mobile mob )
|
||||
{
|
||||
for ( int i = 0; i < m_Info.Length; ++i )
|
||||
for ( int i = 0; i < Info.Length; ++i )
|
||||
{
|
||||
if ( IsQualified( mob, m_Info[i] ) )
|
||||
if ( IsQualified( mob, Info[i] ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@ namespace Server.Factions
|
|||
{
|
||||
public class FactionPersistance : Item
|
||||
{
|
||||
private static FactionPersistance m_Instance;
|
||||
|
||||
public static FactionPersistance Instance => m_Instance;
|
||||
public static FactionPersistance Instance { get; private set; }
|
||||
|
||||
public override string DefaultName => "Faction Persistance - Internal";
|
||||
|
||||
|
|
@ -14,8 +12,8 @@ namespace Server.Factions
|
|||
{
|
||||
Movable = false;
|
||||
|
||||
if ( m_Instance == null || m_Instance.Deleted )
|
||||
m_Instance = this;
|
||||
if ( Instance == null || Instance.Deleted )
|
||||
Instance = this;
|
||||
else
|
||||
base.Delete();
|
||||
}
|
||||
|
|
@ -29,7 +27,7 @@ namespace Server.Factions
|
|||
|
||||
public FactionPersistance( Serial serial ) : base( serial )
|
||||
{
|
||||
m_Instance = this;
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public override void Serialize( GenericWriter writer )
|
||||
|
|
|
|||
|
|
@ -6,31 +6,26 @@ namespace Server.Factions
|
|||
{
|
||||
public class PlayerState : IComparable
|
||||
{
|
||||
private Mobile m_Mobile;
|
||||
private Faction m_Faction;
|
||||
private List<PlayerState> m_Owner;
|
||||
private int m_KillPoints;
|
||||
private DateTime m_Leaving;
|
||||
private MerchantTitle m_MerchantTitle;
|
||||
private RankDefinition m_Rank;
|
||||
private List<SilverGivenEntry> m_SilverGiven;
|
||||
private bool m_IsActive;
|
||||
|
||||
private Town m_Sheriff;
|
||||
private Town m_Finance;
|
||||
|
||||
private DateTime m_LastHonorTime;
|
||||
public Mobile Mobile { get; }
|
||||
|
||||
public Faction Faction { get; }
|
||||
|
||||
public List<PlayerState> Owner { get; }
|
||||
|
||||
public Mobile Mobile => m_Mobile;
|
||||
public Faction Faction => m_Faction;
|
||||
public List<PlayerState> Owner => m_Owner;
|
||||
public MerchantTitle MerchantTitle{ get => m_MerchantTitle;
|
||||
set{ m_MerchantTitle = value; Invalidate(); } }
|
||||
public Town Sheriff{ get => m_Sheriff;
|
||||
set{ m_Sheriff = value; Invalidate(); } }
|
||||
public Town Finance{ get => m_Finance;
|
||||
set{ m_Finance = value; Invalidate(); } }
|
||||
public List<SilverGivenEntry> SilverGiven => m_SilverGiven;
|
||||
public List<SilverGivenEntry> SilverGiven { get; private set; }
|
||||
|
||||
public int KillPoints {
|
||||
get => m_KillPoints;
|
||||
|
|
@ -44,17 +39,17 @@ namespace Server.Factions
|
|||
return;
|
||||
}
|
||||
|
||||
m_Owner.Remove( this );
|
||||
m_Owner.Insert( m_Faction.ZeroRankOffset, this );
|
||||
Owner.Remove( this );
|
||||
Owner.Insert( Faction.ZeroRankOffset, this );
|
||||
|
||||
m_RankIndex = m_Faction.ZeroRankOffset;
|
||||
m_Faction.ZeroRankOffset++;
|
||||
m_RankIndex = Faction.ZeroRankOffset;
|
||||
Faction.ZeroRankOffset++;
|
||||
}
|
||||
while ( ( m_RankIndex - 1 ) >= 0 ) {
|
||||
PlayerState p = m_Owner[m_RankIndex-1] as PlayerState;
|
||||
PlayerState p = Owner[m_RankIndex-1] as PlayerState;
|
||||
if ( value > p.KillPoints ) {
|
||||
m_Owner[m_RankIndex] = p;
|
||||
m_Owner[m_RankIndex-1] = this;
|
||||
Owner[m_RankIndex] = p;
|
||||
Owner[m_RankIndex-1] = this;
|
||||
RankIndex--;
|
||||
p.RankIndex++;
|
||||
}
|
||||
|
|
@ -70,23 +65,23 @@ namespace Server.Factions
|
|||
return;
|
||||
}
|
||||
|
||||
while ( ( m_RankIndex + 1 ) < m_Faction.ZeroRankOffset ) {
|
||||
PlayerState p = m_Owner[m_RankIndex+1] as PlayerState;
|
||||
m_Owner[m_RankIndex+1] = this;
|
||||
m_Owner[m_RankIndex] = p;
|
||||
while ( ( m_RankIndex + 1 ) < Faction.ZeroRankOffset ) {
|
||||
PlayerState p = Owner[m_RankIndex+1] as PlayerState;
|
||||
Owner[m_RankIndex+1] = this;
|
||||
Owner[m_RankIndex] = p;
|
||||
RankIndex++;
|
||||
p.RankIndex--;
|
||||
}
|
||||
|
||||
m_RankIndex = -1;
|
||||
m_Faction.ZeroRankOffset--;
|
||||
Faction.ZeroRankOffset--;
|
||||
}
|
||||
else {
|
||||
while ( ( m_RankIndex + 1 ) < m_Faction.ZeroRankOffset ) {
|
||||
PlayerState p = m_Owner[m_RankIndex+1] as PlayerState;
|
||||
while ( ( m_RankIndex + 1 ) < Faction.ZeroRankOffset ) {
|
||||
PlayerState p = Owner[m_RankIndex+1] as PlayerState;
|
||||
if ( value < p.KillPoints ) {
|
||||
m_Owner[m_RankIndex+1] = this;
|
||||
m_Owner[m_RankIndex] = p;
|
||||
Owner[m_RankIndex+1] = this;
|
||||
Owner[m_RankIndex] = p;
|
||||
RankIndex++;
|
||||
p.RankIndex--;
|
||||
}
|
||||
|
|
@ -111,15 +106,15 @@ namespace Server.Factions
|
|||
public RankDefinition Rank {
|
||||
get {
|
||||
if ( m_InvalidateRank ) {
|
||||
RankDefinition[] ranks = m_Faction.Definition.Ranks;
|
||||
RankDefinition[] ranks = Faction.Definition.Ranks;
|
||||
int percent;
|
||||
|
||||
if ( m_Owner.Count == 1 )
|
||||
if ( Owner.Count == 1 )
|
||||
percent = 1000;
|
||||
else if ( m_RankIndex == -1 )
|
||||
percent = 0;
|
||||
else
|
||||
percent = ( ( m_Faction.ZeroRankOffset - m_RankIndex ) * 1000 ) / m_Faction.ZeroRankOffset;
|
||||
percent = ( ( Faction.ZeroRankOffset - m_RankIndex ) * 1000 ) / Faction.ZeroRankOffset;
|
||||
|
||||
for ( int i = 0; i < ranks.Length; i++ ) {
|
||||
RankDefinition check = ranks[i];
|
||||
|
|
@ -138,29 +133,25 @@ namespace Server.Factions
|
|||
}
|
||||
}
|
||||
|
||||
public DateTime LastHonorTime{ get => m_LastHonorTime;
|
||||
set => m_LastHonorTime = value;
|
||||
}
|
||||
public DateTime Leaving{ get => m_Leaving;
|
||||
set => m_Leaving = value;
|
||||
}
|
||||
public bool IsLeaving => ( m_Leaving > DateTime.MinValue );
|
||||
public DateTime LastHonorTime { get; set; }
|
||||
|
||||
public bool IsActive{ get => m_IsActive;
|
||||
set => m_IsActive = value;
|
||||
}
|
||||
public DateTime Leaving { get; set; }
|
||||
|
||||
public bool IsLeaving => ( Leaving > DateTime.MinValue );
|
||||
|
||||
public bool IsActive { get; set; }
|
||||
|
||||
public bool CanGiveSilverTo( Mobile mob )
|
||||
{
|
||||
if ( m_SilverGiven == null )
|
||||
if ( SilverGiven == null )
|
||||
return true;
|
||||
|
||||
for ( int i = 0; i < m_SilverGiven.Count; ++i )
|
||||
for ( int i = 0; i < SilverGiven.Count; ++i )
|
||||
{
|
||||
SilverGivenEntry sge = m_SilverGiven[i];
|
||||
SilverGivenEntry sge = SilverGiven[i];
|
||||
|
||||
if ( sge.IsExpired )
|
||||
m_SilverGiven.RemoveAt( i-- );
|
||||
SilverGiven.RemoveAt( i-- );
|
||||
else if ( sge.GivenTo == mob )
|
||||
return false;
|
||||
}
|
||||
|
|
@ -170,15 +161,15 @@ namespace Server.Factions
|
|||
|
||||
public void OnGivenSilverTo( Mobile mob )
|
||||
{
|
||||
if ( m_SilverGiven == null )
|
||||
m_SilverGiven = new List<SilverGivenEntry>();
|
||||
if ( SilverGiven == null )
|
||||
SilverGiven = new List<SilverGivenEntry>();
|
||||
|
||||
m_SilverGiven.Add( new SilverGivenEntry( mob ) );
|
||||
SilverGiven.Add( new SilverGivenEntry( mob ) );
|
||||
}
|
||||
|
||||
public void Invalidate()
|
||||
{
|
||||
if ( m_Mobile is PlayerMobile pm )
|
||||
if ( Mobile is PlayerMobile pm )
|
||||
{
|
||||
pm.InvalidateProperties();
|
||||
pm.InvalidateMyRunUO();
|
||||
|
|
@ -187,15 +178,15 @@ namespace Server.Factions
|
|||
|
||||
public void Attach()
|
||||
{
|
||||
if ( m_Mobile is PlayerMobile mobile )
|
||||
if ( Mobile is PlayerMobile mobile )
|
||||
mobile.FactionPlayerState = this;
|
||||
}
|
||||
|
||||
public PlayerState( Mobile mob, Faction faction, List<PlayerState> owner )
|
||||
{
|
||||
m_Mobile = mob;
|
||||
m_Faction = faction;
|
||||
m_Owner = owner;
|
||||
Mobile = mob;
|
||||
Faction = faction;
|
||||
Owner = owner;
|
||||
|
||||
Attach();
|
||||
Invalidate();
|
||||
|
|
@ -203,8 +194,8 @@ namespace Server.Factions
|
|||
|
||||
public PlayerState( GenericReader reader, Faction faction, List<PlayerState> owner )
|
||||
{
|
||||
m_Faction = faction;
|
||||
m_Owner = owner;
|
||||
Faction = faction;
|
||||
Owner = owner;
|
||||
|
||||
int version = reader.ReadEncodedInt();
|
||||
|
||||
|
|
@ -212,18 +203,18 @@ namespace Server.Factions
|
|||
{
|
||||
case 1:
|
||||
{
|
||||
m_IsActive = reader.ReadBool();
|
||||
m_LastHonorTime = reader.ReadDateTime();
|
||||
IsActive = reader.ReadBool();
|
||||
LastHonorTime = reader.ReadDateTime();
|
||||
goto case 0;
|
||||
}
|
||||
case 0:
|
||||
{
|
||||
m_Mobile = reader.ReadMobile();
|
||||
Mobile = reader.ReadMobile();
|
||||
|
||||
m_KillPoints = reader.ReadEncodedInt();
|
||||
m_MerchantTitle = (MerchantTitle)reader.ReadEncodedInt();
|
||||
|
||||
m_Leaving = reader.ReadDateTime();
|
||||
Leaving = reader.ReadDateTime();
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
@ -236,15 +227,15 @@ namespace Server.Factions
|
|||
{
|
||||
writer.WriteEncodedInt( (int) 1 ); // version
|
||||
|
||||
writer.Write( m_IsActive );
|
||||
writer.Write( m_LastHonorTime );
|
||||
writer.Write( IsActive );
|
||||
writer.Write( LastHonorTime );
|
||||
|
||||
writer.Write( (Mobile) m_Mobile );
|
||||
writer.Write( (Mobile) Mobile );
|
||||
|
||||
writer.WriteEncodedInt( (int) m_KillPoints );
|
||||
writer.WriteEncodedInt( (int) m_MerchantTitle );
|
||||
|
||||
writer.Write( (DateTime) m_Leaving );
|
||||
writer.Write( (DateTime) Leaving );
|
||||
}
|
||||
|
||||
public static PlayerState Find( Mobile mob )
|
||||
|
|
|
|||
|
|
@ -6,18 +6,16 @@ namespace Server.Factions
|
|||
{
|
||||
public static readonly TimeSpan ExpirePeriod = TimeSpan.FromHours( 3.0 );
|
||||
|
||||
private Mobile m_GivenTo;
|
||||
private DateTime m_TimeOfGift;
|
||||
public Mobile GivenTo { get; }
|
||||
|
||||
public Mobile GivenTo => m_GivenTo;
|
||||
public DateTime TimeOfGift => m_TimeOfGift;
|
||||
public DateTime TimeOfGift { get; }
|
||||
|
||||
public bool IsExpired => ( m_TimeOfGift + ExpirePeriod ) < DateTime.UtcNow;
|
||||
public bool IsExpired => ( TimeOfGift + ExpirePeriod ) < DateTime.UtcNow;
|
||||
|
||||
public SilverGivenEntry( Mobile givenTo )
|
||||
{
|
||||
m_GivenTo = givenTo;
|
||||
m_TimeOfGift = DateTime.UtcNow;
|
||||
GivenTo = givenTo;
|
||||
TimeOfGift = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,17 +5,11 @@ namespace Server.Factions
|
|||
{
|
||||
public class StrongholdRegion : BaseRegion
|
||||
{
|
||||
private Faction m_Faction;
|
||||
|
||||
public Faction Faction
|
||||
{
|
||||
get => m_Faction;
|
||||
set => m_Faction = value;
|
||||
}
|
||||
public Faction Faction { get; set; }
|
||||
|
||||
public StrongholdRegion( Faction faction ) : base( faction.Definition.FriendlyName, Faction.Facet, DefaultPriority, faction.Definition.Stronghold.Area )
|
||||
{
|
||||
m_Faction = faction;
|
||||
Faction = faction;
|
||||
|
||||
Register();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,14 +9,9 @@ namespace Server.Factions
|
|||
[CustomEnum( new[]{ "Britain", "Magincia", "Minoc", "Moonglow", "Skara Brae", "Trinsic", "Vesper", "Yew" } )]
|
||||
public abstract class Town : IComparable
|
||||
{
|
||||
private TownDefinition m_Definition;
|
||||
private TownState m_State;
|
||||
|
||||
public TownDefinition Definition
|
||||
{
|
||||
get => m_Definition;
|
||||
set => m_Definition = value;
|
||||
}
|
||||
public TownDefinition Definition { get; set; }
|
||||
|
||||
public TownState State
|
||||
{
|
||||
|
|
@ -244,29 +239,18 @@ namespace Server.Factions
|
|||
return list;
|
||||
}
|
||||
|
||||
private List<VendorList> m_VendorLists;
|
||||
private List<GuardList> m_GuardLists;
|
||||
public List<VendorList> VendorLists { get; set; }
|
||||
|
||||
public List<VendorList> VendorLists
|
||||
{
|
||||
get => m_VendorLists;
|
||||
set => m_VendorLists = value;
|
||||
}
|
||||
|
||||
public List<GuardList> GuardLists
|
||||
{
|
||||
get => m_GuardLists;
|
||||
set => m_GuardLists = value;
|
||||
}
|
||||
public List<GuardList> GuardLists { get; set; }
|
||||
|
||||
public void ConstructGuardLists()
|
||||
{
|
||||
GuardDefinition[] defs = ( Owner == null ? new GuardDefinition[0] : Owner.Definition.Guards );
|
||||
|
||||
m_GuardLists = new List<GuardList>();
|
||||
GuardLists = new List<GuardList>();
|
||||
|
||||
for ( int i = 0; i < defs.Length; ++i )
|
||||
m_GuardLists.Add( new GuardList( defs[i] ) );
|
||||
GuardLists.Add( new GuardList( defs[i] ) );
|
||||
}
|
||||
|
||||
public GuardList FindGuardList( Type type )
|
||||
|
|
@ -288,10 +272,10 @@ namespace Server.Factions
|
|||
{
|
||||
VendorDefinition[] defs = VendorDefinition.Definitions;
|
||||
|
||||
m_VendorLists = new List<VendorList>();
|
||||
VendorLists = new List<VendorList>();
|
||||
|
||||
for ( int i = 0; i < defs.Length; ++i )
|
||||
m_VendorLists.Add( new VendorList( defs[i] ) );
|
||||
VendorLists.Add( new VendorList( defs[i] ) );
|
||||
}
|
||||
|
||||
public VendorList FindVendorList( Type type )
|
||||
|
|
@ -468,12 +452,12 @@ namespace Server.Factions
|
|||
|
||||
public int CompareTo( object obj )
|
||||
{
|
||||
return m_Definition.Sort - ((Town)obj).m_Definition.Sort;
|
||||
return Definition.Sort - ((Town)obj).Definition.Sort;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return m_Definition.FriendlyName;
|
||||
return Definition.FriendlyName;
|
||||
}
|
||||
|
||||
public static void WriteReference( GenericWriter writer, Town town )
|
||||
|
|
|
|||
|
|
@ -4,29 +4,12 @@ namespace Server.Factions
|
|||
{
|
||||
public class TownState
|
||||
{
|
||||
private Town m_Town;
|
||||
private Faction m_Owner;
|
||||
|
||||
private Mobile m_Sheriff;
|
||||
private Mobile m_Finance;
|
||||
|
||||
private int m_Silver;
|
||||
private int m_Tax;
|
||||
public Town Town { get; set; }
|
||||
|
||||
private DateTime m_LastTaxChange;
|
||||
private DateTime m_LastIncome;
|
||||
|
||||
public Town Town
|
||||
{
|
||||
get => m_Town;
|
||||
set => m_Town = value;
|
||||
}
|
||||
|
||||
public Faction Owner
|
||||
{
|
||||
get => m_Owner;
|
||||
set => m_Owner = value;
|
||||
}
|
||||
public Faction Owner { get; set; }
|
||||
|
||||
public Mobile Sheriff
|
||||
{
|
||||
|
|
@ -48,7 +31,7 @@ namespace Server.Factions
|
|||
PlayerState pl = PlayerState.Find( m_Sheriff );
|
||||
|
||||
if ( pl != null )
|
||||
pl.Sheriff = m_Town;
|
||||
pl.Sheriff = Town;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -73,38 +56,22 @@ namespace Server.Factions
|
|||
PlayerState pl = PlayerState.Find( m_Finance );
|
||||
|
||||
if ( pl != null )
|
||||
pl.Finance = m_Town;
|
||||
pl.Finance = Town;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int Silver
|
||||
{
|
||||
get => m_Silver;
|
||||
set => m_Silver = value;
|
||||
}
|
||||
public int Silver { get; set; }
|
||||
|
||||
public int Tax
|
||||
{
|
||||
get => m_Tax;
|
||||
set => m_Tax = value;
|
||||
}
|
||||
public int Tax { get; set; }
|
||||
|
||||
public DateTime LastTaxChange
|
||||
{
|
||||
get => m_LastTaxChange;
|
||||
set => m_LastTaxChange = value;
|
||||
}
|
||||
public DateTime LastTaxChange { get; set; }
|
||||
|
||||
public DateTime LastIncome
|
||||
{
|
||||
get => m_LastIncome;
|
||||
set => m_LastIncome = value;
|
||||
}
|
||||
public DateTime LastIncome { get; set; }
|
||||
|
||||
public TownState( Town town )
|
||||
{
|
||||
m_Town = town;
|
||||
Town = town;
|
||||
}
|
||||
|
||||
public TownState( GenericReader reader )
|
||||
|
|
@ -115,32 +82,32 @@ namespace Server.Factions
|
|||
{
|
||||
case 3:
|
||||
{
|
||||
m_LastIncome = reader.ReadDateTime();
|
||||
LastIncome = reader.ReadDateTime();
|
||||
|
||||
goto case 2;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
m_Tax = reader.ReadEncodedInt();
|
||||
m_LastTaxChange = reader.ReadDateTime();
|
||||
Tax = reader.ReadEncodedInt();
|
||||
LastTaxChange = reader.ReadDateTime();
|
||||
|
||||
goto case 1;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
m_Silver = reader.ReadEncodedInt();
|
||||
Silver = reader.ReadEncodedInt();
|
||||
|
||||
goto case 0;
|
||||
}
|
||||
case 0:
|
||||
{
|
||||
m_Town = Town.ReadReference( reader );
|
||||
m_Owner = Faction.ReadReference( reader );
|
||||
Town = Town.ReadReference( reader );
|
||||
Owner = Faction.ReadReference( reader );
|
||||
|
||||
m_Sheriff = reader.ReadMobile();
|
||||
m_Finance = reader.ReadMobile();
|
||||
|
||||
m_Town.State = this;
|
||||
Town.State = this;
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
@ -151,15 +118,15 @@ namespace Server.Factions
|
|||
{
|
||||
writer.WriteEncodedInt( (int) 3 ); // version
|
||||
|
||||
writer.Write( (DateTime) m_LastIncome );
|
||||
writer.Write( (DateTime) LastIncome );
|
||||
|
||||
writer.WriteEncodedInt( (int) m_Tax );
|
||||
writer.Write( (DateTime) m_LastTaxChange );
|
||||
writer.WriteEncodedInt( (int) Tax );
|
||||
writer.Write( (DateTime) LastTaxChange );
|
||||
|
||||
writer.WriteEncodedInt( (int) m_Silver );
|
||||
writer.WriteEncodedInt( (int) Silver );
|
||||
|
||||
Town.WriteReference( writer, m_Town );
|
||||
Faction.WriteReference( writer, m_Owner );
|
||||
Town.WriteReference( writer, Town );
|
||||
Faction.WriteReference( writer, Owner );
|
||||
|
||||
writer.Write( (Mobile) m_Sheriff );
|
||||
writer.Write( (Mobile) m_Finance );
|
||||
|
|
|
|||
|
|
@ -5,22 +5,20 @@ namespace Server.Factions
|
|||
{
|
||||
public class VendorList
|
||||
{
|
||||
private VendorDefinition m_Definition;
|
||||
private List<BaseFactionVendor> m_Vendors;
|
||||
public VendorDefinition Definition { get; }
|
||||
|
||||
public VendorDefinition Definition => m_Definition;
|
||||
public List<BaseFactionVendor> Vendors => m_Vendors;
|
||||
public List<BaseFactionVendor> Vendors { get; }
|
||||
|
||||
public BaseFactionVendor Construct( Town town, Faction faction )
|
||||
{
|
||||
try{ return Activator.CreateInstance( m_Definition.Type, new object[]{ town, faction } ) as BaseFactionVendor; }
|
||||
try{ return Activator.CreateInstance( Definition.Type, new object[]{ town, faction } ) as BaseFactionVendor; }
|
||||
catch{ return null; }
|
||||
}
|
||||
|
||||
public VendorList( VendorDefinition definition )
|
||||
{
|
||||
m_Definition = definition;
|
||||
m_Vendors = new List<BaseFactionVendor>();
|
||||
Definition = definition;
|
||||
Vendors = new List<BaseFactionVendor>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue