Fixes code according to modern code style. Fixes a few expression bugs.
This commit is contained in:
parent
89eea25e5f
commit
970fd563b2
3324 changed files with 441118 additions and 433755 deletions
|
|
@ -1,251 +1,310 @@
|
|||
using System;
|
||||
using Server.Mobiles;
|
||||
using System.Collections.Generic;
|
||||
using Server.Mobiles;
|
||||
|
||||
namespace Server.Factions
|
||||
{
|
||||
public class PlayerState : IComparable
|
||||
{
|
||||
private int m_KillPoints;
|
||||
private MerchantTitle m_MerchantTitle;
|
||||
private RankDefinition m_Rank;
|
||||
public class PlayerState : IComparable
|
||||
{
|
||||
private Town m_Finance;
|
||||
|
||||
private Town m_Sheriff;
|
||||
private Town m_Finance;
|
||||
private bool m_InvalidateRank = true;
|
||||
private int m_KillPoints;
|
||||
private MerchantTitle m_MerchantTitle;
|
||||
private RankDefinition m_Rank;
|
||||
private int m_RankIndex = -1;
|
||||
|
||||
public Mobile Mobile { get; }
|
||||
private Town m_Sheriff;
|
||||
|
||||
public Faction Faction { get; }
|
||||
public PlayerState(Mobile mob, Faction faction, List<PlayerState> owner)
|
||||
{
|
||||
Mobile = mob;
|
||||
Faction = faction;
|
||||
Owner = owner;
|
||||
|
||||
public List<PlayerState> Owner { get; }
|
||||
Attach();
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
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 { get; private set; }
|
||||
public PlayerState(GenericReader reader, Faction faction, List<PlayerState> owner)
|
||||
{
|
||||
Faction = faction;
|
||||
Owner = owner;
|
||||
|
||||
public int KillPoints {
|
||||
get => m_KillPoints;
|
||||
set {
|
||||
if ( m_KillPoints != value ) {
|
||||
if ( value > m_KillPoints ) {
|
||||
if ( m_KillPoints <= 0 ) {
|
||||
if ( value <= 0 ) {
|
||||
m_KillPoints = value;
|
||||
Invalidate();
|
||||
return;
|
||||
}
|
||||
int version = reader.ReadEncodedInt();
|
||||
|
||||
Owner.Remove( this );
|
||||
Owner.Insert( Faction.ZeroRankOffset, this );
|
||||
switch (version)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
IsActive = reader.ReadBool();
|
||||
LastHonorTime = reader.ReadDateTime();
|
||||
goto case 0;
|
||||
}
|
||||
case 0:
|
||||
{
|
||||
Mobile = reader.ReadMobile();
|
||||
|
||||
m_RankIndex = Faction.ZeroRankOffset;
|
||||
Faction.ZeroRankOffset++;
|
||||
}
|
||||
while ( ( m_RankIndex - 1 ) >= 0 ) {
|
||||
PlayerState p = Owner[m_RankIndex-1] as PlayerState;
|
||||
if ( value > p.KillPoints ) {
|
||||
Owner[m_RankIndex] = p;
|
||||
Owner[m_RankIndex-1] = this;
|
||||
RankIndex--;
|
||||
p.RankIndex++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ( value <= 0 ) {
|
||||
if ( m_KillPoints <= 0 ) {
|
||||
m_KillPoints = value;
|
||||
Invalidate();
|
||||
return;
|
||||
}
|
||||
m_KillPoints = reader.ReadEncodedInt();
|
||||
m_MerchantTitle = (MerchantTitle)reader.ReadEncodedInt();
|
||||
|
||||
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--;
|
||||
}
|
||||
Leaving = reader.ReadDateTime();
|
||||
|
||||
m_RankIndex = -1;
|
||||
Faction.ZeroRankOffset--;
|
||||
}
|
||||
else {
|
||||
while ( ( m_RankIndex + 1 ) < Faction.ZeroRankOffset ) {
|
||||
PlayerState p = Owner[m_RankIndex+1] as PlayerState;
|
||||
if ( value < p.KillPoints ) {
|
||||
Owner[m_RankIndex+1] = this;
|
||||
Owner[m_RankIndex] = p;
|
||||
RankIndex++;
|
||||
p.RankIndex--;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_KillPoints = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
Attach();
|
||||
}
|
||||
|
||||
private bool m_InvalidateRank = true;
|
||||
private int m_RankIndex = -1;
|
||||
public Mobile Mobile{ get; }
|
||||
|
||||
public int RankIndex { get => m_RankIndex;
|
||||
set { if ( m_RankIndex != value ) { m_RankIndex = value; m_InvalidateRank = true; } } }
|
||||
public Faction Faction{ get; }
|
||||
|
||||
public RankDefinition Rank {
|
||||
get {
|
||||
if ( m_InvalidateRank ) {
|
||||
RankDefinition[] ranks = Faction.Definition.Ranks;
|
||||
int percent;
|
||||
public List<PlayerState> Owner{ get; }
|
||||
|
||||
if ( Owner.Count == 1 )
|
||||
percent = 1000;
|
||||
else if ( m_RankIndex == -1 )
|
||||
percent = 0;
|
||||
else
|
||||
percent = ( ( Faction.ZeroRankOffset - m_RankIndex ) * 1000 ) / Faction.ZeroRankOffset;
|
||||
public MerchantTitle MerchantTitle
|
||||
{
|
||||
get => m_MerchantTitle;
|
||||
set
|
||||
{
|
||||
m_MerchantTitle = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
for ( int i = 0; i < ranks.Length; i++ ) {
|
||||
RankDefinition check = ranks[i];
|
||||
public Town Sheriff
|
||||
{
|
||||
get => m_Sheriff;
|
||||
set
|
||||
{
|
||||
m_Sheriff = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
if ( percent >= check.Required ) {
|
||||
m_Rank = check;
|
||||
m_InvalidateRank = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
public Town Finance
|
||||
{
|
||||
get => m_Finance;
|
||||
set
|
||||
{
|
||||
m_Finance = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
public List<SilverGivenEntry> SilverGiven{ get; private set; }
|
||||
|
||||
return m_Rank;
|
||||
}
|
||||
}
|
||||
public int KillPoints
|
||||
{
|
||||
get => m_KillPoints;
|
||||
set
|
||||
{
|
||||
if (m_KillPoints != value)
|
||||
{
|
||||
if (value > m_KillPoints)
|
||||
{
|
||||
if (m_KillPoints <= 0)
|
||||
{
|
||||
if (value <= 0)
|
||||
{
|
||||
m_KillPoints = value;
|
||||
Invalidate();
|
||||
return;
|
||||
}
|
||||
|
||||
public DateTime LastHonorTime { get; set; }
|
||||
Owner.Remove(this);
|
||||
Owner.Insert(Faction.ZeroRankOffset, this);
|
||||
|
||||
public DateTime Leaving { get; set; }
|
||||
m_RankIndex = Faction.ZeroRankOffset;
|
||||
Faction.ZeroRankOffset++;
|
||||
}
|
||||
|
||||
public bool IsLeaving => ( Leaving > DateTime.MinValue );
|
||||
while (m_RankIndex - 1 >= 0)
|
||||
{
|
||||
PlayerState p = Owner[m_RankIndex - 1];
|
||||
if (value > p.KillPoints)
|
||||
{
|
||||
Owner[m_RankIndex] = p;
|
||||
Owner[m_RankIndex - 1] = this;
|
||||
RankIndex--;
|
||||
p.RankIndex++;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value <= 0)
|
||||
{
|
||||
if (m_KillPoints <= 0)
|
||||
{
|
||||
m_KillPoints = value;
|
||||
Invalidate();
|
||||
return;
|
||||
}
|
||||
|
||||
public bool IsActive { get; set; }
|
||||
while (m_RankIndex + 1 < Faction.ZeroRankOffset)
|
||||
{
|
||||
PlayerState p = Owner[m_RankIndex + 1];
|
||||
Owner[m_RankIndex + 1] = this;
|
||||
Owner[m_RankIndex] = p;
|
||||
RankIndex++;
|
||||
p.RankIndex--;
|
||||
}
|
||||
|
||||
public bool CanGiveSilverTo( Mobile mob )
|
||||
{
|
||||
if ( SilverGiven == null )
|
||||
return true;
|
||||
m_RankIndex = -1;
|
||||
Faction.ZeroRankOffset--;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (m_RankIndex + 1 < Faction.ZeroRankOffset)
|
||||
{
|
||||
PlayerState p = Owner[m_RankIndex + 1];
|
||||
if (value < p.KillPoints)
|
||||
{
|
||||
Owner[m_RankIndex + 1] = this;
|
||||
Owner[m_RankIndex] = p;
|
||||
RankIndex++;
|
||||
p.RankIndex--;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ( int i = 0; i < SilverGiven.Count; ++i )
|
||||
{
|
||||
SilverGivenEntry sge = SilverGiven[i];
|
||||
m_KillPoints = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( sge.IsExpired )
|
||||
SilverGiven.RemoveAt( i-- );
|
||||
else if ( sge.GivenTo == mob )
|
||||
return false;
|
||||
}
|
||||
public int RankIndex
|
||||
{
|
||||
get => m_RankIndex;
|
||||
set
|
||||
{
|
||||
if (m_RankIndex != value)
|
||||
{
|
||||
m_RankIndex = value;
|
||||
m_InvalidateRank = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public RankDefinition Rank
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_InvalidateRank)
|
||||
{
|
||||
RankDefinition[] ranks = Faction.Definition.Ranks;
|
||||
int percent;
|
||||
|
||||
public void OnGivenSilverTo( Mobile mob )
|
||||
{
|
||||
if ( SilverGiven == null )
|
||||
SilverGiven = new List<SilverGivenEntry>();
|
||||
if (Owner.Count == 1)
|
||||
percent = 1000;
|
||||
else if (m_RankIndex == -1)
|
||||
percent = 0;
|
||||
else
|
||||
percent = (Faction.ZeroRankOffset - m_RankIndex) * 1000 / Faction.ZeroRankOffset;
|
||||
|
||||
SilverGiven.Add( new SilverGivenEntry( mob ) );
|
||||
}
|
||||
for (int i = 0; i < ranks.Length; i++)
|
||||
{
|
||||
RankDefinition check = ranks[i];
|
||||
|
||||
public void Invalidate()
|
||||
{
|
||||
if ( Mobile is PlayerMobile pm )
|
||||
{
|
||||
pm.InvalidateProperties();
|
||||
pm.InvalidateMyRunUO();
|
||||
}
|
||||
}
|
||||
if (percent >= check.Required)
|
||||
{
|
||||
m_Rank = check;
|
||||
m_InvalidateRank = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Attach()
|
||||
{
|
||||
if ( Mobile is PlayerMobile mobile )
|
||||
mobile.FactionPlayerState = this;
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
public PlayerState( Mobile mob, Faction faction, List<PlayerState> owner )
|
||||
{
|
||||
Mobile = mob;
|
||||
Faction = faction;
|
||||
Owner = owner;
|
||||
return m_Rank;
|
||||
}
|
||||
}
|
||||
|
||||
Attach();
|
||||
Invalidate();
|
||||
}
|
||||
public DateTime LastHonorTime{ get; set; }
|
||||
|
||||
public PlayerState( GenericReader reader, Faction faction, List<PlayerState> owner )
|
||||
{
|
||||
Faction = faction;
|
||||
Owner = owner;
|
||||
public DateTime Leaving{ get; set; }
|
||||
|
||||
int version = reader.ReadEncodedInt();
|
||||
public bool IsLeaving => Leaving > DateTime.MinValue;
|
||||
|
||||
switch ( version )
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
IsActive = reader.ReadBool();
|
||||
LastHonorTime = reader.ReadDateTime();
|
||||
goto case 0;
|
||||
}
|
||||
case 0:
|
||||
{
|
||||
Mobile = reader.ReadMobile();
|
||||
public bool IsActive{ get; set; }
|
||||
|
||||
m_KillPoints = reader.ReadEncodedInt();
|
||||
m_MerchantTitle = (MerchantTitle)reader.ReadEncodedInt();
|
||||
public int CompareTo(object obj)
|
||||
{
|
||||
return ((PlayerState)obj).m_KillPoints - m_KillPoints;
|
||||
}
|
||||
|
||||
Leaving = reader.ReadDateTime();
|
||||
public bool CanGiveSilverTo(Mobile mob)
|
||||
{
|
||||
if (SilverGiven == null)
|
||||
return true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < SilverGiven.Count; ++i)
|
||||
{
|
||||
SilverGivenEntry sge = SilverGiven[i];
|
||||
|
||||
Attach();
|
||||
}
|
||||
if (sge.IsExpired)
|
||||
SilverGiven.RemoveAt(i--);
|
||||
else if (sge.GivenTo == mob)
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Serialize( GenericWriter writer )
|
||||
{
|
||||
writer.WriteEncodedInt( (int) 1 ); // version
|
||||
return true;
|
||||
}
|
||||
|
||||
writer.Write( IsActive );
|
||||
writer.Write( LastHonorTime );
|
||||
public void OnGivenSilverTo(Mobile mob)
|
||||
{
|
||||
if (SilverGiven == null)
|
||||
SilverGiven = new List<SilverGivenEntry>();
|
||||
|
||||
writer.Write( (Mobile) Mobile );
|
||||
SilverGiven.Add(new SilverGivenEntry(mob));
|
||||
}
|
||||
|
||||
writer.WriteEncodedInt( (int) m_KillPoints );
|
||||
writer.WriteEncodedInt( (int) m_MerchantTitle );
|
||||
public void Invalidate()
|
||||
{
|
||||
if (Mobile is PlayerMobile pm)
|
||||
{
|
||||
pm.InvalidateProperties();
|
||||
pm.InvalidateMyRunUO();
|
||||
}
|
||||
}
|
||||
|
||||
writer.Write( (DateTime) Leaving );
|
||||
}
|
||||
public void Attach()
|
||||
{
|
||||
if (Mobile is PlayerMobile mobile)
|
||||
mobile.FactionPlayerState = this;
|
||||
}
|
||||
|
||||
public static PlayerState Find( Mobile mob )
|
||||
{
|
||||
return mob is PlayerMobile mobile ? mobile.FactionPlayerState : null;
|
||||
}
|
||||
public void Serialize(GenericWriter writer)
|
||||
{
|
||||
writer.WriteEncodedInt(1); // version
|
||||
|
||||
public int CompareTo( object obj )
|
||||
{
|
||||
return ((PlayerState)obj).m_KillPoints - m_KillPoints;
|
||||
}
|
||||
}
|
||||
}
|
||||
writer.Write(IsActive);
|
||||
writer.Write(LastHonorTime);
|
||||
|
||||
writer.Write(Mobile);
|
||||
|
||||
writer.WriteEncodedInt(m_KillPoints);
|
||||
writer.WriteEncodedInt((int)m_MerchantTitle);
|
||||
|
||||
writer.Write(Leaving);
|
||||
}
|
||||
|
||||
public static PlayerState Find(Mobile mob)
|
||||
{
|
||||
return mob is PlayerMobile mobile ? mobile.FactionPlayerState : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue