Reorganizes Project (#41)
This commit is contained in:
parent
08bf44af9a
commit
3614a66aee
3499 changed files with 79 additions and 55 deletions
234
Projects/Scripts/Engines/Ethics/Core/Ethic.cs
Normal file
234
Projects/Scripts/Engines/Ethics/Core/Ethic.cs
Normal file
|
|
@ -0,0 +1,234 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
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 static readonly Ethic Hero = new HeroEthic();
|
||||
public static readonly Ethic Evil = new EvilEthic();
|
||||
|
||||
public static readonly Ethic[] Ethics =
|
||||
{
|
||||
Hero,
|
||||
Evil
|
||||
};
|
||||
|
||||
protected EthicDefinition m_Definition;
|
||||
|
||||
protected PlayerCollection m_Players;
|
||||
|
||||
public Ethic()
|
||||
{
|
||||
m_Players = new PlayerCollection();
|
||||
}
|
||||
|
||||
public EthicDefinition Definition => m_Definition;
|
||||
|
||||
public PlayerCollection Players => m_Players;
|
||||
|
||||
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 += 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;
|
||||
|
||||
if (!e.Mobile.GetItemsInRange(2).Any(item => item is AnkhNorth || item is AnkhWest))
|
||||
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 mobile && mobile.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 bc)
|
||||
{
|
||||
if (bc.Controlled)
|
||||
return Find(bc.ControlMaster, false);
|
||||
if (bc.Summoned)
|
||||
return Find(bc.SummonMaster, false);
|
||||
if (allegiance)
|
||||
return bc.EthicAllegiance;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
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, 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
59
Projects/Scripts/Engines/Ethics/Core/Persistance.cs
Normal file
59
Projects/Scripts/Engines/Ethics/Core/Persistance.cs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
namespace Server.Ethics
|
||||
{
|
||||
public class EthicsPersistance : Item
|
||||
{
|
||||
[Constructible]
|
||||
public EthicsPersistance()
|
||||
: base(1)
|
||||
{
|
||||
Movable = false;
|
||||
|
||||
if (Instance?.Deleted != false)
|
||||
Instance = this;
|
||||
else
|
||||
base.Delete();
|
||||
}
|
||||
|
||||
public EthicsPersistance(Serial serial)
|
||||
: base(serial)
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public static EthicsPersistance Instance{ get; private set; }
|
||||
|
||||
public override string DefaultName => "Ethics Persistance - Internal";
|
||||
|
||||
public override void Serialize(GenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
writer.Write(0); // version
|
||||
|
||||
for (int i = 0; i < Ethic.Ethics.Length; ++i)
|
||||
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 < Ethic.Ethics.Length; ++i)
|
||||
Ethic.Ethics[i].Deserialize(reader);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Delete()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
160
Projects/Scripts/Engines/Ethics/Core/Player.cs
Normal file
160
Projects/Scripts/Engines/Ethics/Core/Player.cs
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using Server.Mobiles;
|
||||
|
||||
namespace Server.Ethics
|
||||
{
|
||||
public class PlayerCollection : Collection<Player>
|
||||
{
|
||||
}
|
||||
|
||||
[PropertyObject]
|
||||
public class Player
|
||||
{
|
||||
private DateTime m_Shield;
|
||||
|
||||
public Player(Ethic ethic, Mobile mobile)
|
||||
{
|
||||
Ethic = ethic;
|
||||
Mobile = mobile;
|
||||
|
||||
Power = 5;
|
||||
History = 5;
|
||||
}
|
||||
|
||||
public Player(Ethic ethic, GenericReader reader)
|
||||
{
|
||||
Ethic = ethic;
|
||||
|
||||
int version = reader.ReadEncodedInt();
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
Mobile = reader.ReadMobile();
|
||||
|
||||
Power = reader.ReadEncodedInt();
|
||||
History = reader.ReadEncodedInt();
|
||||
|
||||
Steed = reader.ReadMobile();
|
||||
Familiar = reader.ReadMobile();
|
||||
|
||||
m_Shield = reader.ReadDeltaTime();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Ethic Ethic{ get; }
|
||||
|
||||
public Mobile Mobile{ get; }
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster, AccessLevel.Administrator)]
|
||||
public int Power{ get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster, AccessLevel.Administrator)]
|
||||
public int History{ get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster, AccessLevel.Administrator)]
|
||||
public Mobile Steed{ get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster, AccessLevel.Administrator)]
|
||||
public Mobile Familiar{ get; set; }
|
||||
|
||||
[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 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 bc)
|
||||
{
|
||||
if (bc.Controlled)
|
||||
pm = bc.ControlMaster as PlayerMobile;
|
||||
else if (bc.Summoned)
|
||||
pm = bc.SummonMaster as PlayerMobile;
|
||||
}
|
||||
|
||||
if (pm == null)
|
||||
return null;
|
||||
}
|
||||
|
||||
Player pl = pm.EthicPlayer;
|
||||
|
||||
if (pl?.Ethic.IsEligible(pl.Mobile) == false)
|
||||
pm.EthicPlayer = pl = null;
|
||||
|
||||
return pl;
|
||||
}
|
||||
|
||||
public void BeginShield()
|
||||
{
|
||||
m_Shield = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public void FinishShield()
|
||||
{
|
||||
m_Shield = DateTime.MinValue;
|
||||
}
|
||||
|
||||
public void CheckAttach()
|
||||
{
|
||||
if (Ethic.IsEligible(Mobile))
|
||||
Attach();
|
||||
}
|
||||
|
||||
public void Attach()
|
||||
{
|
||||
if (Mobile is PlayerMobile mobile)
|
||||
mobile.EthicPlayer = this;
|
||||
|
||||
Ethic.Players.Add(this);
|
||||
}
|
||||
|
||||
public void Detach()
|
||||
{
|
||||
if (Mobile is PlayerMobile mobile)
|
||||
mobile.EthicPlayer = null;
|
||||
|
||||
Ethic.Players.Remove(this);
|
||||
}
|
||||
|
||||
public void Serialize(GenericWriter writer)
|
||||
{
|
||||
writer.WriteEncodedInt(0); // version
|
||||
|
||||
writer.Write(Mobile);
|
||||
|
||||
writer.WriteEncodedInt(Power);
|
||||
writer.WriteEncodedInt(History);
|
||||
|
||||
writer.Write(Steed);
|
||||
writer.Write(Familiar);
|
||||
|
||||
writer.WriteDeltaTime(m_Shield);
|
||||
}
|
||||
}
|
||||
}
|
||||
33
Projects/Scripts/Engines/Ethics/Core/Power.cs
Normal file
33
Projects/Scripts/Engines/Ethics/Core/Power.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
using Server.Network;
|
||||
|
||||
namespace Server.Ethics
|
||||
{
|
||||
public abstract class Power
|
||||
{
|
||||
protected PowerDefinition m_Definition;
|
||||
|
||||
public PowerDefinition Definition => m_Definition;
|
||||
|
||||
public virtual bool CheckInvoke(Player from)
|
||||
{
|
||||
if (!from.Mobile.CheckAlive())
|
||||
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;
|
||||
}
|
||||
|
||||
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