This commit is contained in:
mark 2009-08-23 03:19:37 +00:00
parent 60ad317065
commit 4933751ac4
7 changed files with 312 additions and 91 deletions

View file

@ -15,23 +15,132 @@ namespace Server.Factions
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{ return m_Mobile; } }
public Faction Faction{ get{ return m_Faction; } }
public List<PlayerState> Owner { get { return m_Owner; } }
public int KillPoints{ get{ return m_KillPoints; } set{ m_KillPoints = value; } }
public MerchantTitle MerchantTitle{ get{ return m_MerchantTitle; } set{ m_MerchantTitle = value; Invalidate(); } }
public RankDefinition Rank{ get{ return m_Rank; } set{ m_Rank = value; Invalidate(); } }
public Town Sheriff{ get{ return m_Sheriff; } set{ m_Sheriff = value; Invalidate(); } }
public Town Finance{ get{ return m_Finance; } set{ m_Finance = value; Invalidate(); } }
public List<SilverGivenEntry> SilverGiven { get { return m_SilverGiven; } }
public int KillPoints {
get { return m_KillPoints; }
set {
if ( m_KillPoints != value ) {
if ( value > m_KillPoints ) {
if ( m_KillPoints <= 0 ) {
if ( value <= 0 ) {
m_KillPoints = value;
Invalidate();
return;
}
m_Owner.Remove( this );
m_Owner.Insert( m_Faction.ZeroRankOffset, this );
m_RankIndex = m_Faction.ZeroRankOffset;
m_Faction.ZeroRankOffset++;
}
while ( ( m_RankIndex - 1 ) >= 0 ) {
PlayerState p = m_Owner[m_RankIndex-1] as PlayerState;
if ( value > p.KillPoints ) {
m_Owner[m_RankIndex] = p;
m_Owner[m_RankIndex-1] = this;
RankIndex--;
p.RankIndex++;
}
else
break;
}
}
else {
if ( value <= 0 ) {
if ( m_KillPoints <= 0 ) {
m_KillPoints = value;
Invalidate();
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;
RankIndex++;
p.RankIndex--;
}
m_RankIndex = -1;
m_Faction.ZeroRankOffset--;
}
else {
while ( ( m_RankIndex + 1 ) < m_Faction.ZeroRankOffset ) {
PlayerState p = m_Owner[m_RankIndex+1] as PlayerState;
if ( value < p.KillPoints ) {
m_Owner[m_RankIndex+1] = this;
m_Owner[m_RankIndex] = p;
RankIndex++;
p.RankIndex--;
}
else
break;
}
}
}
m_KillPoints = value;
Invalidate();
}
}
}
private bool m_InvalidateRank = true;
private int m_RankIndex = -1;
public int RankIndex { get { return m_RankIndex; } set { if ( m_RankIndex != value ) { m_RankIndex = value; m_InvalidateRank = true; } } }
public RankDefinition Rank {
get {
if ( m_InvalidateRank ) {
RankDefinition[] ranks = m_Faction.Definition.Ranks;
int percent;
if ( m_Owner.Count == 1 )
percent = 1000;
else if ( m_RankIndex == -1 )
percent = 0;
else
percent = ( ( m_Faction.ZeroRankOffset - m_RankIndex ) * 1000 ) / m_Faction.ZeroRankOffset;
for ( int i = 0; i < ranks.Length; i++ ) {
RankDefinition check = ranks[i];
if ( percent >= check.Required ) {
m_Rank = check;
m_InvalidateRank = false;
break;
}
}
Invalidate();
}
return m_Rank;
}
}
public DateTime LastHonorTime{ get{ return m_LastHonorTime; } set{ m_LastHonorTime = value; } }
public DateTime Leaving{ get{ return m_Leaving; } set{ m_Leaving = value; } }
public bool IsLeaving{ get{ return ( m_Leaving > DateTime.MinValue ); } }
public bool IsActive{ get{ return m_IsActive; } set{ m_IsActive = value; } }
public bool CanGiveSilverTo( Mobile mob )
{
if ( m_SilverGiven == null )
@ -61,7 +170,11 @@ namespace Server.Factions
public void Invalidate()
{
if ( m_Mobile is PlayerMobile )
((PlayerMobile)m_Mobile).InvalidateProperties();
{
PlayerMobile pm = (PlayerMobile)m_Mobile;
pm.InvalidateProperties();
pm.InvalidateMyRunUO();
}
}
public void Attach()
@ -76,8 +189,6 @@ namespace Server.Factions
m_Faction = faction;
m_Owner = owner;
m_Rank = faction.Definition.Ranks[faction.Definition.Ranks.Length - 1];
Attach();
Invalidate();
}
@ -91,6 +202,12 @@ namespace Server.Factions
switch ( version )
{
case 1:
{
m_IsActive = reader.ReadBool();
m_LastHonorTime = reader.ReadDateTime();
goto case 0;
}
case 0:
{
m_Mobile = reader.ReadMobile();
@ -109,7 +226,10 @@ namespace Server.Factions
public void Serialize( GenericWriter writer )
{
writer.WriteEncodedInt( (int) 0 ); // version
writer.WriteEncodedInt( (int) 1 ); // version
writer.Write( m_IsActive );
writer.Write( m_LastHonorTime );
writer.Write( (Mobile) m_Mobile );