#W# Source and Scripts added. Added Scripts/Settings.cs to expose some basic tweak able settings.
This commit is contained in:
parent
b51c58f514
commit
3045c83799
3512 changed files with 627673 additions and 0 deletions
255
Scripts/Engines/Ethics/Core/Ethic.cs
Normal file
255
Scripts/Engines/Ethics/Core/Ethic.cs
Normal file
|
|
@ -0,0 +1,255 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Server.Mobiles;
|
||||
|
||||
namespace Server.Ethics
|
||||
{
|
||||
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;
|
||||
|
||||
item.SavedFlags &= ~0x100;
|
||||
}
|
||||
|
||||
if ( ( item.SavedFlags & 0x200 ) != 0 )
|
||||
{
|
||||
if ( item.Hue == Evil.Definition.PrimaryHue )
|
||||
return Evil;
|
||||
|
||||
item.SavedFlags &= ~0x200;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static bool CheckTrade( Mobile from, Mobile to, Mobile newOwner, Item item )
|
||||
{
|
||||
Ethic itemEthic = Find( item );
|
||||
|
||||
if ( itemEthic == null || Find( newOwner ) == itemEthic )
|
||||
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." );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool CheckEquip( Mobile from, Item item )
|
||||
{
|
||||
Ethic itemEthic = Find( item );
|
||||
|
||||
if ( itemEthic == null || Find( from ) == itemEthic )
|
||||
return true;
|
||||
|
||||
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 false;
|
||||
}
|
||||
|
||||
public static bool IsImbued( Item item )
|
||||
{
|
||||
return IsImbued( item, false );
|
||||
}
|
||||
|
||||
public static bool IsImbued( Item item, bool recurse )
|
||||
{
|
||||
if ( Find( item ) != null )
|
||||
return true;
|
||||
|
||||
if ( recurse )
|
||||
{
|
||||
foreach ( Item child in item.Items )
|
||||
{
|
||||
if ( IsImbued( child, true ) )
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
if( Enabled )
|
||||
EventSink.Speech += new SpeechEventHandler( EventSink_Speech );
|
||||
}
|
||||
|
||||
public static void EventSink_Speech( SpeechEventArgs e )
|
||||
{
|
||||
if ( e.Blocked || e.Handled )
|
||||
return;
|
||||
|
||||
Player pl = Player.Find( e.Mobile );
|
||||
|
||||
if ( pl == null )
|
||||
{
|
||||
for ( int i = 0; i < Ethics.Length; ++i )
|
||||
{
|
||||
Ethic ethic = Ethics[i];
|
||||
|
||||
if ( !ethic.IsEligible( e.Mobile ) )
|
||||
continue;
|
||||
|
||||
if ( !Insensitive.Equals( ethic.Definition.JoinPhrase.String, e.Speech ) )
|
||||
continue;
|
||||
|
||||
bool isNearAnkh = false;
|
||||
|
||||
foreach ( Item item in e.Mobile.GetItemsInRange( 2 ) )
|
||||
{
|
||||
if ( item is Items.AnkhNorth || item is Items.AnkhWest )
|
||||
{
|
||||
isNearAnkh = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !isNearAnkh )
|
||||
continue;
|
||||
|
||||
pl = new Player( ethic, e.Mobile );
|
||||
|
||||
pl.Attach();
|
||||
|
||||
e.Mobile.FixedEffect( 0x373A, 10, 30 );
|
||||
e.Mobile.PlaySound( 0x209 );
|
||||
|
||||
e.Handled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( e.Mobile is PlayerMobile && ( e.Mobile as PlayerMobile ).DuelContext != null )
|
||||
return;
|
||||
|
||||
Ethic ethic = pl.Ethic;
|
||||
|
||||
for ( int i = 0; i < ethic.Definition.Powers.Length; ++i )
|
||||
{
|
||||
Power power = ethic.Definition.Powers[i];
|
||||
|
||||
if ( !Insensitive.Equals( power.Definition.Phrase.String, e.Speech ) )
|
||||
continue;
|
||||
|
||||
if ( !power.CheckInvoke( pl ) )
|
||||
continue;
|
||||
|
||||
power.BeginInvoke( pl );
|
||||
e.Handled = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected EthicDefinition m_Definition;
|
||||
|
||||
protected PlayerCollection m_Players;
|
||||
|
||||
public EthicDefinition Definition
|
||||
{
|
||||
get { return m_Definition; }
|
||||
}
|
||||
|
||||
public PlayerCollection Players
|
||||
{
|
||||
get { return m_Players; }
|
||||
}
|
||||
|
||||
public static Ethic Find( Mobile mob )
|
||||
{
|
||||
return Find( mob, false, false );
|
||||
}
|
||||
|
||||
public static Ethic Find( Mobile mob, bool inherit )
|
||||
{
|
||||
return Find( mob, inherit, false );
|
||||
}
|
||||
|
||||
public static Ethic Find( Mobile mob, bool inherit, bool allegiance )
|
||||
{
|
||||
Player pl = Player.Find( mob );
|
||||
|
||||
if ( pl != null )
|
||||
return pl.Ethic;
|
||||
|
||||
if ( inherit && mob is BaseCreature )
|
||||
{
|
||||
BaseCreature bc = (BaseCreature) mob;
|
||||
|
||||
if ( bc.Controlled )
|
||||
return Find( bc.ControlMaster, false );
|
||||
else if ( bc.Summoned )
|
||||
return Find( bc.SummonMaster, false );
|
||||
else if ( allegiance )
|
||||
return bc.EthicAllegiance;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Ethic()
|
||||
{
|
||||
m_Players = new PlayerCollection();
|
||||
}
|
||||
|
||||
public abstract bool IsEligible( Mobile mob );
|
||||
|
||||
public virtual void Deserialize( GenericReader reader )
|
||||
{
|
||||
int version = reader.ReadEncodedInt();
|
||||
|
||||
switch ( version )
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
int playerCount = reader.ReadEncodedInt();
|
||||
|
||||
for ( int i = 0; i < playerCount; ++i )
|
||||
{
|
||||
Player pl = new Player( this, reader );
|
||||
|
||||
if ( pl.Mobile != null )
|
||||
Timer.DelayCall( TimeSpan.Zero, new TimerCallback( pl.CheckAttach ) );
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Serialize( GenericWriter writer )
|
||||
{
|
||||
writer.WriteEncodedInt( 0 ); // version
|
||||
|
||||
writer.WriteEncodedInt( m_Players.Count );
|
||||
|
||||
for ( int i = 0; i < m_Players.Count; ++i )
|
||||
m_Players[i].Serialize( writer );
|
||||
}
|
||||
|
||||
public static readonly Ethic Hero = new Hero.HeroEthic();
|
||||
public static readonly Ethic Evil = new Evil.EvilEthic();
|
||||
|
||||
public static readonly Ethic[] Ethics = new Ethic[]
|
||||
{
|
||||
Hero,
|
||||
Evil
|
||||
};
|
||||
}
|
||||
}
|
||||
66
Scripts/Engines/Ethics/Core/Persistance.cs
Normal file
66
Scripts/Engines/Ethics/Core/Persistance.cs
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
using System;
|
||||
|
||||
namespace Server.Ethics
|
||||
{
|
||||
public class EthicsPersistance : Item
|
||||
{
|
||||
private static EthicsPersistance m_Instance;
|
||||
|
||||
public static EthicsPersistance Instance { get { return m_Instance; } }
|
||||
|
||||
public override string DefaultName
|
||||
{
|
||||
get { return "Ethics Persistance - Internal"; }
|
||||
}
|
||||
|
||||
[Constructable]
|
||||
public EthicsPersistance()
|
||||
: base( 1 )
|
||||
{
|
||||
Movable = false;
|
||||
|
||||
if ( m_Instance == null || m_Instance.Deleted )
|
||||
m_Instance = this;
|
||||
else
|
||||
base.Delete();
|
||||
}
|
||||
|
||||
public EthicsPersistance( Serial serial )
|
||||
: base( serial )
|
||||
{
|
||||
m_Instance = this;
|
||||
}
|
||||
|
||||
public override void Serialize( GenericWriter writer )
|
||||
{
|
||||
base.Serialize( writer );
|
||||
|
||||
writer.Write( (int) 0 ); // version
|
||||
|
||||
for ( int i = 0; i < Ethics.Ethic.Ethics.Length; ++i )
|
||||
Ethics.Ethic.Ethics[i].Serialize( writer );
|
||||
}
|
||||
|
||||
public override void Deserialize( GenericReader reader )
|
||||
{
|
||||
base.Deserialize( reader );
|
||||
|
||||
int version = reader.ReadInt();
|
||||
|
||||
switch ( version )
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
for ( int i = 0; i < Ethics.Ethic.Ethics.Length; ++i )
|
||||
Ethics.Ethic.Ethics[i].Deserialize( reader );
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Delete()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
171
Scripts/Engines/Ethics/Core/Player.cs
Normal file
171
Scripts/Engines/Ethics/Core/Player.cs
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Server.Mobiles;
|
||||
|
||||
namespace Server.Ethics
|
||||
{
|
||||
public class PlayerCollection : System.Collections.ObjectModel.Collection<Player>
|
||||
{
|
||||
}
|
||||
|
||||
[PropertyObject]
|
||||
public class Player
|
||||
{
|
||||
public static Player Find( Mobile mob )
|
||||
{
|
||||
return Find( mob, false );
|
||||
}
|
||||
|
||||
public static Player Find( Mobile mob, bool inherit )
|
||||
{
|
||||
PlayerMobile pm = mob as PlayerMobile;
|
||||
|
||||
if ( pm == null )
|
||||
{
|
||||
if ( inherit && mob is BaseCreature )
|
||||
{
|
||||
BaseCreature bc = mob as BaseCreature;
|
||||
|
||||
if ( bc != null && bc.Controlled )
|
||||
pm = bc.ControlMaster as PlayerMobile;
|
||||
else if ( bc != null && bc.Summoned )
|
||||
pm = bc.SummonMaster as PlayerMobile;
|
||||
}
|
||||
|
||||
if ( pm == null )
|
||||
return null;
|
||||
}
|
||||
|
||||
Player pl = pm.EthicPlayer;
|
||||
|
||||
if ( pl != null && !pl.Ethic.IsEligible( pl.Mobile ) )
|
||||
pm.EthicPlayer = pl = null;
|
||||
|
||||
return pl;
|
||||
}
|
||||
|
||||
private Ethic m_Ethic;
|
||||
private Mobile m_Mobile;
|
||||
|
||||
private int m_Power;
|
||||
private int m_History;
|
||||
|
||||
private Mobile m_Steed;
|
||||
private Mobile m_Familiar;
|
||||
|
||||
private DateTime m_Shield;
|
||||
|
||||
public Ethic Ethic { get { return m_Ethic; } }
|
||||
public Mobile Mobile { get { return m_Mobile; } }
|
||||
|
||||
[CommandProperty( AccessLevel.GameMaster, AccessLevel.Administrator )]
|
||||
public int Power { get { return m_Power; } set { m_Power = value; } }
|
||||
|
||||
[CommandProperty( AccessLevel.GameMaster, AccessLevel.Administrator )]
|
||||
public int History { get { return m_History; } set { m_History = value; } }
|
||||
|
||||
[CommandProperty( AccessLevel.GameMaster, AccessLevel.Administrator )]
|
||||
public Mobile Steed { get { return m_Steed; } set { m_Steed = value; } }
|
||||
|
||||
[CommandProperty( AccessLevel.GameMaster, AccessLevel.Administrator )]
|
||||
public Mobile Familiar { get { return m_Familiar; } set { m_Familiar = value; } }
|
||||
|
||||
[CommandProperty( AccessLevel.GameMaster )]
|
||||
public bool IsShielded
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Shield == DateTime.MinValue )
|
||||
return false;
|
||||
|
||||
if ( DateTime.UtcNow < ( m_Shield + TimeSpan.FromHours( 1.0 ) ) )
|
||||
return true;
|
||||
|
||||
FinishShield();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void BeginShield()
|
||||
{
|
||||
m_Shield = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public void FinishShield()
|
||||
{
|
||||
m_Shield = DateTime.MinValue;
|
||||
}
|
||||
|
||||
public Player( Ethic ethic, Mobile mobile )
|
||||
{
|
||||
m_Ethic = ethic;
|
||||
m_Mobile = mobile;
|
||||
|
||||
m_Power = 5;
|
||||
m_History = 5;
|
||||
}
|
||||
|
||||
public void CheckAttach()
|
||||
{
|
||||
if ( m_Ethic.IsEligible( m_Mobile ) )
|
||||
Attach();
|
||||
}
|
||||
|
||||
public void Attach()
|
||||
{
|
||||
if ( m_Mobile is PlayerMobile )
|
||||
( m_Mobile as PlayerMobile ).EthicPlayer = this;
|
||||
|
||||
m_Ethic.Players.Add( this );
|
||||
}
|
||||
|
||||
public void Detach()
|
||||
{
|
||||
if ( m_Mobile is PlayerMobile )
|
||||
( m_Mobile as PlayerMobile ).EthicPlayer = null;
|
||||
|
||||
m_Ethic.Players.Remove( this );
|
||||
}
|
||||
|
||||
public Player( Ethic ethic, GenericReader reader )
|
||||
{
|
||||
m_Ethic = ethic;
|
||||
|
||||
int version = reader.ReadEncodedInt();
|
||||
|
||||
switch ( version )
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
m_Mobile = reader.ReadMobile();
|
||||
|
||||
m_Power = reader.ReadEncodedInt();
|
||||
m_History = reader.ReadEncodedInt();
|
||||
|
||||
m_Steed = reader.ReadMobile();
|
||||
m_Familiar = reader.ReadMobile();
|
||||
|
||||
m_Shield = reader.ReadDeltaTime();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Serialize( GenericWriter writer )
|
||||
{
|
||||
writer.WriteEncodedInt( 0 ); // version
|
||||
|
||||
writer.Write( m_Mobile );
|
||||
|
||||
writer.WriteEncodedInt( m_Power );
|
||||
writer.WriteEncodedInt( m_History );
|
||||
|
||||
writer.Write( m_Steed );
|
||||
writer.Write( m_Familiar );
|
||||
|
||||
writer.WriteDeltaTime( m_Shield );
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Scripts/Engines/Ethics/Core/Power.cs
Normal file
34
Scripts/Engines/Ethics/Core/Power.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Server.Ethics
|
||||
{
|
||||
public abstract class Power
|
||||
{
|
||||
protected PowerDefinition m_Definition;
|
||||
|
||||
public PowerDefinition Definition { get { return m_Definition; } }
|
||||
|
||||
public virtual bool CheckInvoke( Player from )
|
||||
{
|
||||
if ( !from.Mobile.CheckAlive() )
|
||||
return false;
|
||||
|
||||
if ( from.Power < m_Definition.Power )
|
||||
{
|
||||
from.Mobile.LocalOverheadMessage( Server.Network.MessageType.Regular, 0x3B2, false, "You lack the power to invoke this ability." );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract void BeginInvoke( Player from );
|
||||
|
||||
public virtual void FinishInvoke( Player from )
|
||||
{
|
||||
from.Power -= m_Definition.Power;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue