Reorganizes Project (#41)
This commit is contained in:
parent
08bf44af9a
commit
3614a66aee
3499 changed files with 79 additions and 55 deletions
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue