Fixes code according to modern code style. Fixes a few expression bugs.

This commit is contained in:
Kamron Batman 2018-09-15 09:58:51 -07:00
parent 89eea25e5f
commit 970fd563b2
3324 changed files with 441118 additions and 433755 deletions

View file

@ -1,244 +1,242 @@
using System;
using Server.Ethics.Evil;
using Server.Ethics.Hero;
using Server.Items;
using Server.Mobiles;
namespace Server.Ethics
{
public abstract class Ethic
{
public static readonly bool Enabled = false;
public abstract class Ethic
{
public static readonly bool Enabled = false;
public static Ethic Find( Item item )
{
if ( ( item.SavedFlags & 0x100 ) != 0 )
{
if ( item.Hue == Hero.Definition.PrimaryHue )
return Hero;
public static readonly Ethic Hero = new HeroEthic();
public static readonly Ethic Evil = new EvilEthic();
item.SavedFlags &= ~0x100;
}
public static readonly Ethic[] Ethics =
{
Hero,
Evil
};
if ( ( item.SavedFlags & 0x200 ) != 0 )
{
if ( item.Hue == Evil.Definition.PrimaryHue )
return Evil;
protected EthicDefinition m_Definition;
item.SavedFlags &= ~0x200;
}
protected PlayerCollection m_Players;
return null;
}
public Ethic()
{
m_Players = new PlayerCollection();
}
public static bool CheckTrade( Mobile from, Mobile to, Mobile newOwner, Item item )
{
Ethic itemEthic = Find( item );
public EthicDefinition Definition => m_Definition;
if ( itemEthic == null || Find( newOwner ) == itemEthic )
return true;
public PlayerCollection Players => m_Players;
if ( itemEthic == Hero )
( from == newOwner ? to : from ).SendMessage( "Only heros may receive this item." );
else if ( itemEthic == Evil )
( from == newOwner ? to : from ).SendMessage( "Only the evil may receive this item." );
public static Ethic Find(Item item)
{
if ((item.SavedFlags & 0x100) != 0)
{
if (item.Hue == Hero.Definition.PrimaryHue)
return Hero;
return false;
}
item.SavedFlags &= ~0x100;
}
public static bool CheckEquip( Mobile from, Item item )
{
Ethic itemEthic = Find( item );
if ((item.SavedFlags & 0x200) != 0)
{
if (item.Hue == Evil.Definition.PrimaryHue)
return Evil;
if ( itemEthic == null || Find( from ) == itemEthic )
return true;
item.SavedFlags &= ~0x200;
}
if ( itemEthic == Hero )
from.SendMessage( "Only heros may wear this item." );
else if ( itemEthic == Evil )
from.SendMessage( "Only the evil may wear this item." );
return null;
}
return false;
}
public static bool CheckTrade(Mobile from, Mobile to, Mobile newOwner, Item item)
{
Ethic itemEthic = Find(item);
public static bool IsImbued( Item item )
{
return IsImbued( item, false );
}
if (itemEthic == null || Find(newOwner) == itemEthic)
return true;
public static bool IsImbued( Item item, bool recurse )
{
if ( Find( item ) != null )
return true;
if (itemEthic == Hero)
(from == newOwner ? to : from).SendMessage("Only heros may receive this item.");
else if (itemEthic == Evil)
(from == newOwner ? to : from).SendMessage("Only the evil may receive this item.");
if ( recurse )
{
foreach ( Item child in item.Items )
{
if ( IsImbued( child, true ) )
return true;
}
}
return false;
}
return false;
}
public static bool CheckEquip(Mobile from, Item item)
{
Ethic itemEthic = Find(item);
public static void Initialize()
{
if ( Enabled )
EventSink.Speech += EventSink_Speech;
}
if (itemEthic == null || Find(from) == itemEthic)
return true;
public static void EventSink_Speech( SpeechEventArgs e )
{
if ( e.Blocked || e.Handled )
return;
if (itemEthic == Hero)
from.SendMessage("Only heros may wear this item.");
else if (itemEthic == Evil)
from.SendMessage("Only the evil may wear this item.");
Player pl = Player.Find( e.Mobile );
return false;
}
if ( pl == null )
{
for ( int i = 0; i < Ethics.Length; ++i )
{
Ethic ethic = Ethics[i];
public static bool IsImbued(Item item)
{
return IsImbued(item, false);
}
if ( !ethic.IsEligible( e.Mobile ) )
continue;
public static bool IsImbued(Item item, bool recurse)
{
if (Find(item) != null)
return true;
if ( !Insensitive.Equals( ethic.Definition.JoinPhrase.String, e.Speech ) )
continue;
if (recurse)
foreach (Item child in item.Items)
if (IsImbued(child, true))
return true;
bool isNearAnkh = false;
return false;
}
foreach ( Item item in e.Mobile.GetItemsInRange( 2 ) )
{
if ( item is Items.AnkhNorth || item is Items.AnkhWest )
{
isNearAnkh = true;
break;
}
}
public static void Initialize()
{
if (Enabled)
EventSink.Speech += EventSink_Speech;
}
if ( !isNearAnkh )
continue;
public static void EventSink_Speech(SpeechEventArgs e)
{
if (e.Blocked || e.Handled)
return;
pl = new Player( ethic, e.Mobile );
Player pl = Player.Find(e.Mobile);
pl.Attach();
if (pl == null)
{
for (int i = 0; i < Ethics.Length; ++i)
{
Ethic ethic = Ethics[i];
e.Mobile.FixedEffect( 0x373A, 10, 30 );
e.Mobile.PlaySound( 0x209 );
if (!ethic.IsEligible(e.Mobile))
continue;
e.Handled = true;
break;
}
}
else
{
if ( e.Mobile is PlayerMobile mobile && mobile.DuelContext != null )
return;
if (!Insensitive.Equals(ethic.Definition.JoinPhrase.String, e.Speech))
continue;
Ethic ethic = pl.Ethic;
bool isNearAnkh = false;
for ( int i = 0; i < ethic.Definition.Powers.Length; ++i )
{
Power power = ethic.Definition.Powers[i];
foreach (Item item in e.Mobile.GetItemsInRange(2))
if (item is AnkhNorth || item is AnkhWest)
{
isNearAnkh = true;
break;
}
if ( !Insensitive.Equals( power.Definition.Phrase.String, e.Speech ) )
continue;
if (!isNearAnkh)
continue;
if ( !power.CheckInvoke( pl ) )
continue;
pl = new Player(ethic, e.Mobile);
power.BeginInvoke( pl );
e.Handled = true;
pl.Attach();
break;
}
}
}
e.Mobile.FixedEffect(0x373A, 10, 30);
e.Mobile.PlaySound(0x209);
protected EthicDefinition m_Definition;
e.Handled = true;
break;
}
}
else
{
if (e.Mobile is PlayerMobile mobile && mobile.DuelContext != null)
return;
protected PlayerCollection m_Players;
Ethic ethic = pl.Ethic;
public EthicDefinition Definition => m_Definition;
for (int i = 0; i < ethic.Definition.Powers.Length; ++i)
{
Power power = ethic.Definition.Powers[i];
public PlayerCollection Players => m_Players;
if (!Insensitive.Equals(power.Definition.Phrase.String, e.Speech))
continue;
public static Ethic Find( Mobile mob )
{
return Find( mob, false, false );
}
if (!power.CheckInvoke(pl))
continue;
public static Ethic Find( Mobile mob, bool inherit )
{
return Find( mob, inherit, false );
}
power.BeginInvoke(pl);
e.Handled = true;
public static Ethic Find( Mobile mob, bool inherit, bool allegiance )
{
Player pl = Player.Find( mob );
break;
}
}
}
if ( pl != null )
return pl.Ethic;
public static Ethic Find(Mobile mob)
{
return Find(mob, false, false);
}
if ( inherit && mob is BaseCreature bc )
{
if ( bc.Controlled )
return Find( bc.ControlMaster, false );
if ( bc.Summoned )
return Find( bc.SummonMaster, false );
if ( allegiance )
return bc.EthicAllegiance;
}
public static Ethic Find(Mobile mob, bool inherit)
{
return Find(mob, inherit, false);
}
return null;
}
public static Ethic Find(Mobile mob, bool inherit, bool allegiance)
{
Player pl = Player.Find(mob);
public Ethic()
{
m_Players = new PlayerCollection();
}
if (pl != null)
return pl.Ethic;
public abstract bool IsEligible( Mobile mob );
if (inherit && mob is BaseCreature bc)
{
if (bc.Controlled)
return Find(bc.ControlMaster, false);
if (bc.Summoned)
return Find(bc.SummonMaster, false);
if (allegiance)
return bc.EthicAllegiance;
}
public virtual void Deserialize( GenericReader reader )
{
int version = reader.ReadEncodedInt();
return null;
}
switch ( version )
{
case 0:
{
int playerCount = reader.ReadEncodedInt();
public abstract bool IsEligible(Mobile mob);
for ( int i = 0; i < playerCount; ++i )
{
Player pl = new Player( this, reader );
public virtual void Deserialize(GenericReader reader)
{
int version = reader.ReadEncodedInt();
if ( pl.Mobile != null )
Timer.DelayCall( TimeSpan.Zero, pl.CheckAttach );
}
switch (version)
{
case 0:
{
int playerCount = reader.ReadEncodedInt();
break;
}
}
}
for (int i = 0; i < playerCount; ++i)
{
Player pl = new Player(this, reader);
public virtual void Serialize( GenericWriter writer )
{
writer.WriteEncodedInt( 0 ); // version
if (pl.Mobile != null)
Timer.DelayCall(TimeSpan.Zero, pl.CheckAttach);
}
writer.WriteEncodedInt( m_Players.Count );
break;
}
}
}
for ( int i = 0; i < m_Players.Count; ++i )
m_Players[i].Serialize( writer );
}
public virtual void Serialize(GenericWriter writer)
{
writer.WriteEncodedInt(0); // version
public static readonly Ethic Hero = new Hero.HeroEthic();
public static readonly Ethic Evil = new Evil.EvilEthic();
writer.WriteEncodedInt(m_Players.Count);
public static readonly Ethic[] Ethics = {
Hero,
Evil
};
}
}
for (int i = 0; i < m_Players.Count; ++i)
m_Players[i].Serialize(writer);
}
}
}

View file

@ -1,59 +1,59 @@
namespace Server.Ethics
{
public class EthicsPersistance : Item
{
public static EthicsPersistance Instance { get; private set; }
public class EthicsPersistance : Item
{
[Constructible]
public EthicsPersistance()
: base(1)
{
Movable = false;
public override string DefaultName => "Ethics Persistance - Internal";
if (Instance == null || Instance.Deleted)
Instance = this;
else
base.Delete();
}
[Constructible]
public EthicsPersistance()
: base( 1 )
{
Movable = false;
public EthicsPersistance(Serial serial)
: base(serial)
{
Instance = this;
}
if ( Instance == null || Instance.Deleted )
Instance = this;
else
base.Delete();
}
public static EthicsPersistance Instance{ get; private set; }
public EthicsPersistance( Serial serial )
: base( serial )
{
Instance = this;
}
public override string DefaultName => "Ethics Persistance - Internal";
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write( (int) 0 ); // version
writer.Write(0); // version
for ( int i = 0; i < Ethic.Ethics.Length; ++i )
Ethic.Ethics[i].Serialize( writer );
}
for (int i = 0; i < Ethic.Ethics.Length; ++i)
Ethic.Ethics[i].Serialize(writer);
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
int version = reader.ReadInt();
switch ( version )
{
case 0:
{
for ( int i = 0; i < Ethic.Ethics.Length; ++i )
Ethic.Ethics[i].Deserialize( reader );
switch (version)
{
case 0:
{
for (int i = 0; i < Ethic.Ethics.Length; ++i)
Ethic.Ethics[i].Deserialize(reader);
break;
}
}
}
break;
}
}
}
public override void Delete()
{
}
}
}
public override void Delete()
{
}
}
}

View file

@ -1,159 +1,160 @@
using System;
using System.Collections.ObjectModel;
using Server.Mobiles;
namespace Server.Ethics
{
public class PlayerCollection : System.Collections.ObjectModel.Collection<Player>
{
}
public class PlayerCollection : Collection<Player>
{
}
[PropertyObject]
public class Player
{
public static Player Find( Mobile mob )
{
return Find( mob, false );
}
[PropertyObject]
public class Player
{
private DateTime m_Shield;
public static Player Find( Mobile mob, bool inherit )
{
PlayerMobile pm = mob as PlayerMobile;
public Player(Ethic ethic, Mobile mobile)
{
Ethic = ethic;
Mobile = mobile;
if ( pm == null )
{
if ( inherit && mob is BaseCreature bc )
{
if ( bc.Controlled )
pm = bc.ControlMaster as PlayerMobile;
else if ( bc.Summoned )
pm = bc.SummonMaster as PlayerMobile;
}
Power = 5;
History = 5;
}
if ( pm == null )
return null;
}
public Player(Ethic ethic, GenericReader reader)
{
Ethic = ethic;
Player pl = pm.EthicPlayer;
int version = reader.ReadEncodedInt();
if ( pl != null && !pl.Ethic.IsEligible( pl.Mobile ) )
pm.EthicPlayer = pl = null;
switch (version)
{
case 0:
{
Mobile = reader.ReadMobile();
return pl;
}
Power = reader.ReadEncodedInt();
History = reader.ReadEncodedInt();
private DateTime m_Shield;
Steed = reader.ReadMobile();
Familiar = reader.ReadMobile();
public Ethic Ethic { get; }
m_Shield = reader.ReadDeltaTime();
public Mobile Mobile { get; }
break;
}
}
}
[CommandProperty( AccessLevel.GameMaster, AccessLevel.Administrator )]
public int Power { get; set; }
public Ethic Ethic{ get; }
[CommandProperty( AccessLevel.GameMaster, AccessLevel.Administrator )]
public int History { get; set; }
public Mobile Mobile{ get; }
[CommandProperty( AccessLevel.GameMaster, AccessLevel.Administrator )]
public Mobile Steed { get; set; }
[CommandProperty(AccessLevel.GameMaster, AccessLevel.Administrator)]
public int Power{ get; set; }
[CommandProperty( AccessLevel.GameMaster, AccessLevel.Administrator )]
public Mobile Familiar { get; set; }
[CommandProperty(AccessLevel.GameMaster, AccessLevel.Administrator)]
public int History{ get; set; }
[CommandProperty( AccessLevel.GameMaster )]
public bool IsShielded
{
get
{
if ( m_Shield == DateTime.MinValue )
return false;
[CommandProperty(AccessLevel.GameMaster, AccessLevel.Administrator)]
public Mobile Steed{ get; set; }
if ( DateTime.UtcNow < ( m_Shield + TimeSpan.FromHours( 1.0 ) ) )
return true;
[CommandProperty(AccessLevel.GameMaster, AccessLevel.Administrator)]
public Mobile Familiar{ get; set; }
FinishShield();
return false;
}
}
[CommandProperty(AccessLevel.GameMaster)]
public bool IsShielded
{
get
{
if (m_Shield == DateTime.MinValue)
return false;
public void BeginShield()
{
m_Shield = DateTime.UtcNow;
}
if (DateTime.UtcNow < m_Shield + TimeSpan.FromHours(1.0))
return true;
public void FinishShield()
{
m_Shield = DateTime.MinValue;
}
FinishShield();
return false;
}
}
public Player( Ethic ethic, Mobile mobile )
{
Ethic = ethic;
Mobile = mobile;
public static Player Find(Mobile mob)
{
return Find(mob, false);
}
Power = 5;
History = 5;
}
public static Player Find(Mobile mob, bool inherit)
{
PlayerMobile pm = mob as PlayerMobile;
public void CheckAttach()
{
if ( Ethic.IsEligible( Mobile ) )
Attach();
}
if (pm == null)
{
if (inherit && mob is BaseCreature bc)
{
if (bc.Controlled)
pm = bc.ControlMaster as PlayerMobile;
else if (bc.Summoned)
pm = bc.SummonMaster as PlayerMobile;
}
public void Attach()
{
if ( Mobile is PlayerMobile mobile )
mobile.EthicPlayer = this;
if (pm == null)
return null;
}
Ethic.Players.Add( this );
}
Player pl = pm.EthicPlayer;
public void Detach()
{
if ( Mobile is PlayerMobile mobile )
mobile.EthicPlayer = null;
if (pl != null && !pl.Ethic.IsEligible(pl.Mobile))
pm.EthicPlayer = pl = null;
Ethic.Players.Remove( this );
}
return pl;
}
public Player( Ethic ethic, GenericReader reader )
{
Ethic = ethic;
public void BeginShield()
{
m_Shield = DateTime.UtcNow;
}
int version = reader.ReadEncodedInt();
public void FinishShield()
{
m_Shield = DateTime.MinValue;
}
switch ( version )
{
case 0:
{
Mobile = reader.ReadMobile();
public void CheckAttach()
{
if (Ethic.IsEligible(Mobile))
Attach();
}
Power = reader.ReadEncodedInt();
History = reader.ReadEncodedInt();
public void Attach()
{
if (Mobile is PlayerMobile mobile)
mobile.EthicPlayer = this;
Steed = reader.ReadMobile();
Familiar = reader.ReadMobile();
Ethic.Players.Add(this);
}
m_Shield = reader.ReadDeltaTime();
public void Detach()
{
if (Mobile is PlayerMobile mobile)
mobile.EthicPlayer = null;
break;
}
}
}
Ethic.Players.Remove(this);
}
public void Serialize( GenericWriter writer )
{
writer.WriteEncodedInt( 0 ); // version
public void Serialize(GenericWriter writer)
{
writer.WriteEncodedInt(0); // version
writer.Write( Mobile );
writer.Write(Mobile);
writer.WriteEncodedInt( Power );
writer.WriteEncodedInt( History );
writer.WriteEncodedInt(Power);
writer.WriteEncodedInt(History);
writer.Write( Steed );
writer.Write( Familiar );
writer.Write(Steed);
writer.Write(Familiar);
writer.WriteDeltaTime( m_Shield );
}
}
}
writer.WriteDeltaTime(m_Shield);
}
}
}

View file

@ -1,30 +1,33 @@
using Server.Network;
namespace Server.Ethics
{
public abstract class Power
{
protected PowerDefinition m_Definition;
public abstract class Power
{
protected PowerDefinition m_Definition;
public PowerDefinition Definition => m_Definition;
public PowerDefinition Definition => m_Definition;
public virtual bool CheckInvoke( Player from )
{
if ( !from.Mobile.CheckAlive() )
return false;
public virtual bool CheckInvoke(Player from)
{
if (!from.Mobile.CheckAlive())
return false;
if ( from.Power < m_Definition.Power )
{
from.Mobile.LocalOverheadMessage( Network.MessageType.Regular, 0x3B2, false, "You lack the power to invoke this ability." );
return false;
}
if (from.Power < m_Definition.Power)
{
from.Mobile.LocalOverheadMessage(MessageType.Regular, 0x3B2, false,
"You lack the power to invoke this ability.");
return false;
}
return true;
}
return true;
}
public abstract void BeginInvoke( Player from );
public abstract void BeginInvoke(Player from);
public virtual void FinishInvoke( Player from )
{
from.Power -= m_Definition.Power;
}
}
}
public virtual void FinishInvoke(Player from)
{
from.Power -= m_Definition.Power;
}
}
}