Reorganizes Project (#41)

This commit is contained in:
Kamron Batman 2019-08-02 18:13:40 -07:00 committed by GitHub
parent 08bf44af9a
commit 3614a66aee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3499 changed files with 79 additions and 55 deletions

View file

@ -0,0 +1,189 @@
using System;
using Server.Gumps;
using Server.Mobiles;
namespace Server.Engines.MLQuests.Objectives
{
public abstract class BaseObjective
{
public virtual bool IsTimed => false;
public virtual TimeSpan Duration => TimeSpan.Zero;
public virtual bool CanOffer(IQuestGiver quester, PlayerMobile pm, bool message)
{
return true;
}
public abstract void WriteToGump(Gump g, ref int y);
public virtual BaseObjectiveInstance CreateInstance(MLQuestInstance instance)
{
return null;
}
}
public abstract class BaseObjectiveInstance
{
public enum DataType : byte
{
None,
EscortObjective,
KillObjective,
DeliverObjective
}
public BaseObjectiveInstance(MLQuestInstance instance, BaseObjective obj)
{
Instance = instance;
if (obj.IsTimed)
EndTime = DateTime.UtcNow + obj.Duration;
}
public MLQuestInstance Instance{ get; }
public bool IsTimed => EndTime != DateTime.MinValue;
public DateTime EndTime{ get; set; }
public bool Expired{ get; set; }
public virtual DataType ExtraDataType => DataType.None;
public virtual void WriteToGump(Gump g, ref int y)
{
if (IsTimed)
WriteTimeRemaining(g, ref y, EndTime > DateTime.UtcNow ? EndTime - DateTime.UtcNow : TimeSpan.Zero);
}
public static void WriteTimeRemaining(Gump g, ref int y, TimeSpan timeRemaining)
{
g.AddHtmlLocalized(103, y, 120, 16, 1062379, 0x15F90); // Est. time remaining:
g.AddLabel(223, y, 0x481, timeRemaining.TotalSeconds.ToString("F0"));
y += 16;
}
public virtual bool AllowsQuestItem(Item item, Type type)
{
return false;
}
public virtual bool IsCompleted()
{
return false;
}
public virtual void CheckComplete()
{
if (IsCompleted())
{
Instance.Player.PlaySound(0x5B6); // public sound
Instance.CheckComplete();
}
}
public virtual void OnQuestAccepted()
{
}
public virtual void OnQuestCancelled()
{
}
public virtual void OnQuestCompleted()
{
}
public virtual bool OnBeforeClaimReward()
{
return true;
}
public virtual void OnClaimReward()
{
}
public virtual void OnAfterClaimReward()
{
}
public virtual void OnRewardClaimed()
{
}
public virtual void OnQuesterDeleted()
{
}
public virtual void OnPlayerDeath()
{
}
public virtual void OnExpire()
{
}
public virtual void Serialize(GenericWriter writer)
{
// Version info is written in MLQuestPersistence.Serialize
if (IsTimed)
{
writer.Write(true);
writer.WriteDeltaTime(EndTime);
}
else
{
writer.Write(false);
}
// For type checks on deserialization
// (This way quest objectives can be changed without breaking serialization)
writer.Write((byte)ExtraDataType);
}
public static void Deserialize(GenericReader reader, int version, BaseObjectiveInstance objInstance)
{
if (reader.ReadBool())
{
DateTime endTime = reader.ReadDeltaTime();
if (objInstance != null)
objInstance.EndTime = endTime;
}
DataType extraDataType = (DataType)reader.ReadByte();
switch (extraDataType)
{
case DataType.EscortObjective:
{
bool completed = reader.ReadBool();
if (objInstance is EscortObjectiveInstance instance)
instance.HasCompleted = completed;
break;
}
case DataType.KillObjective:
{
int slain = reader.ReadInt();
if (objInstance is KillObjectiveInstance instance)
instance.Slain = slain;
break;
}
case DataType.DeliverObjective:
{
bool completed = reader.ReadBool();
if (objInstance is DeliverObjectiveInstance instance)
instance.HasCompleted = completed;
break;
}
}
}
}
}

View file

@ -0,0 +1,214 @@
using System;
using System.Linq;
using Server.Gumps;
using Server.Items;
using Server.Mobiles;
namespace Server.Engines.MLQuests.Objectives
{
public class CollectObjective : BaseObjective
{
public CollectObjective(int amount = 0, Type type = null, TextDefinition name = null)
{
DesiredAmount = amount;
AcceptedType = type;
Name = name;
if (MLQuestSystem.Debug && ShowDetailed && name.Number > 0)
{
int itemid = LabelToItemID(name.Number);
if (itemid <= 0 || itemid > 0x4000)
Console.WriteLine("Warning: cliloc {0} is likely giving the wrong item ID", name.Number);
}
}
public int DesiredAmount{ get; set; }
public Type AcceptedType{ get; set; }
public TextDefinition Name{ get; set; }
public virtual bool ShowDetailed => true;
public bool CheckType(Type type)
{
return AcceptedType?.IsAssignableFrom(type) == true;
}
public virtual bool CheckItem(Item item)
{
return true;
}
public static int LabelToItemID(int label)
{
if (label < 1078872)
return label - 1020000;
return label - 1078872;
}
public override void WriteToGump(Gump g, ref int y)
{
if (ShowDetailed)
{
string amount = DesiredAmount.ToString();
g.AddHtmlLocalized(98, y, 350, 16, 1072205, 0x15F90); // Obtain
g.AddLabel(143, y, 0x481, amount);
if (Name.Number > 0)
{
g.AddHtmlLocalized(143 + amount.Length * 15, y, 190, 18, Name.Number, 0x77BF);
g.AddItem(350, y, LabelToItemID(Name.Number));
}
else if (Name.String != null)
{
g.AddLabel(143 + amount.Length * 15, y, 0x481, Name.String);
}
}
else
{
if (Name.Number > 0)
g.AddHtmlLocalized(98, y, 312, 32, Name.Number, 0x15F90);
else if (Name.String != null)
g.AddLabel(98, y, 0x481, Name.String);
}
y += 32;
}
public override BaseObjectiveInstance CreateInstance(MLQuestInstance instance)
{
return new CollectObjectiveInstance(this, instance);
}
}
#region Timed
public class TimedCollectObjective : CollectObjective
{
public TimedCollectObjective(TimeSpan duration, int amount, Type type, TextDefinition name)
: base(amount, type, name)
{
Duration = duration;
}
public override bool IsTimed => true;
public override TimeSpan Duration{ get; }
}
#endregion
public class CollectObjectiveInstance : BaseObjectiveInstance
{
public CollectObjectiveInstance(CollectObjective objective, MLQuestInstance instance)
: base(instance, objective)
{
Objective = objective;
}
public CollectObjective Objective{ get; set; }
private int GetCurrentTotal()
{
Container pack = Instance.Player.Backpack;
if (pack == null)
return 0;
Item[] items = pack.FindItemsByType(Objective.AcceptedType, false); // Note: subclasses are included
return items.Where(item => item.QuestItem && Objective.CheckItem(item)).Sum(item => item.Amount);
}
public override bool AllowsQuestItem(Item item, Type type)
{
return Objective.CheckType(type) && Objective.CheckItem(item);
}
public override bool IsCompleted()
{
return GetCurrentTotal() >= Objective.DesiredAmount;
}
public override void OnQuestCancelled()
{
PlayerMobile pm = Instance.Player;
Container pack = pm.Backpack;
if (pack == null)
return;
Type checkType = Objective.AcceptedType;
Item[] items = pack.FindItemsByType(checkType, false);
foreach (Item item in items)
if (item.QuestItem && !MLQuestSystem.CanMarkQuestItem(pm, item, checkType)
) // does another quest still need this item? (OSI just unmarks everything)
item.QuestItem = false;
}
// Should only be called after IsComplete() is checked to be true
public override void OnClaimReward()
{
Container pack = Instance.Player.Backpack;
if (pack == null)
return;
// TODO: OSI also counts the item in the cursor?
Item[] items = pack.FindItemsByType(Objective.AcceptedType, false);
int left = Objective.DesiredAmount;
foreach (Item item in items)
if (item.QuestItem && Objective.CheckItem(item))
{
if (left == 0)
return;
if (item.Amount > left)
{
item.Consume(left);
left = 0;
}
else
{
item.Delete();
left -= item.Amount;
}
}
}
public override void OnAfterClaimReward()
{
OnQuestCancelled(); // same thing, clear other quest items
}
public override void OnExpire()
{
OnQuestCancelled();
// No message
}
public override void WriteToGump(Gump g, ref int y)
{
Objective.WriteToGump(g, ref y);
y -= 16;
if (Objective.ShowDetailed)
{
base.WriteToGump(g, ref y);
g.AddHtmlLocalized(103, y, 120, 16, 3000087, 0x15F90); // Total
g.AddLabel(223, y, 0x481, GetCurrentTotal().ToString());
y += 16;
g.AddHtmlLocalized(103, y, 120, 16, 1074782, 0x15F90); // Return to
g.AddLabel(223, y, 0x481, QuesterNameAttribute.GetQuesterNameFor(Instance.QuesterType));
y += 16;
}
}
}
}

View file

@ -0,0 +1,229 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Server.Gumps;
using Server.Items;
using Server.Mobiles;
namespace Server.Engines.MLQuests.Objectives
{
public class DeliverObjective : BaseObjective
{
public DeliverObjective(Type delivery, int amount, TextDefinition name, Type destination, bool spawnsDelivery = true)
{
Delivery = delivery;
Amount = amount;
Name = name;
Destination = destination;
SpawnsDelivery = spawnsDelivery;
if (MLQuestSystem.Debug && name.Number > 0)
{
int itemid = CollectObjective.LabelToItemID(name.Number);
if (itemid <= 0 || itemid > 0x4000)
Console.WriteLine("Warning: cliloc {0} is likely giving the wrong item ID", name.Number);
}
}
public Type Delivery{ get; set; }
public int Amount{ get; set; }
public TextDefinition Name{ get; set; }
public Type Destination{ get; set; }
public bool SpawnsDelivery{ get; set; }
public virtual void SpawnDelivery(Container pack)
{
if (!SpawnsDelivery || pack == null)
return;
List<Item> delivery = new List<Item>();
for (int i = 0; i < Amount; ++i)
{
if (!(Activator.CreateInstance(Delivery) is Item item))
continue;
delivery.Add(item);
if (item.Stackable && Amount > 1)
{
item.Amount = Amount;
break;
}
}
foreach (Item item in delivery)
pack.DropItem(item); // Confirmed: on OSI items are added even if your pack is full
}
public override void WriteToGump(Gump g, ref int y)
{
string amount = Amount.ToString();
g.AddHtmlLocalized(98, y, 312, 16, 1072207, 0x15F90); // Deliver
g.AddLabel(143, y, 0x481, amount);
if (Name.Number > 0)
{
g.AddHtmlLocalized(143 + amount.Length * 15, y, 190, 18, Name.Number, 0x77BF);
g.AddItem(350, y, CollectObjective.LabelToItemID(Name.Number));
}
else if (Name.String != null)
{
g.AddLabel(143 + amount.Length * 15, y, 0x481, Name.String);
}
y += 32;
g.AddHtmlLocalized(103, y, 120, 16, 1072379, 0x15F90); // Deliver to
g.AddLabel(223, y, 0x481, QuesterNameAttribute.GetQuesterNameFor(Destination));
y += 16;
}
public override BaseObjectiveInstance CreateInstance(MLQuestInstance instance)
{
return new DeliverObjectiveInstance(this, instance);
}
}
#region Timed
public class TimedDeliverObjective : DeliverObjective
{
public TimedDeliverObjective(TimeSpan duration, Type delivery, int amount, TextDefinition name, Type destination,
bool spawnsDelivery = true)
: base(delivery, amount, name, destination, spawnsDelivery)
{
Duration = duration;
}
public override bool IsTimed => true;
public override TimeSpan Duration{ get; }
}
#endregion
public class DeliverObjectiveInstance : BaseObjectiveInstance
{
public DeliverObjectiveInstance(DeliverObjective objective, MLQuestInstance instance)
: base(instance, objective)
{
Objective = objective;
}
public DeliverObjective Objective{ get; set; }
public bool HasCompleted{ get; set; }
public override DataType ExtraDataType => DataType.DeliverObjective;
public virtual bool IsDestination(IQuestGiver quester, Type type)
{
Type destType = Objective.Destination;
return destType?.IsAssignableFrom(type) == true;
}
public override bool IsCompleted()
{
return HasCompleted;
}
public override void OnQuestAccepted()
{
Objective.SpawnDelivery(Instance.Player.Backpack);
}
// This is VERY similar to CollectObjective.GetCurrentTotal
private int GetCurrentTotal()
{
Container pack = Instance.Player.Backpack;
if (pack == null)
return 0;
Item[] items = pack.FindItemsByType(Objective.Delivery, false); // Note: subclasses are included
return items.Sum(item => item.Amount);
}
public override bool OnBeforeClaimReward()
{
PlayerMobile pm = Instance.Player;
int total = GetCurrentTotal();
int desired = Objective.Amount;
if (total < desired)
{
pm.SendLocalizedMessage(1074861); // You do not have everything you need!
pm.SendLocalizedMessage(1074885, $"{total}\t{desired}"); // You have ~1_val~ item(s) but require ~2_val~
return false;
}
return true;
}
// TODO: This is VERY similar to CollectObjective.OnClaimReward
public override void OnClaimReward()
{
Container pack = Instance.Player.Backpack;
if (pack == null)
return;
Item[] items = pack.FindItemsByType(Objective.Delivery, false);
int left = Objective.Amount;
foreach (Item item in items)
{
if (left == 0)
break;
if (item.Amount > left)
{
item.Consume(left);
left = 0;
}
else
{
item.Delete();
left -= item.Amount;
}
}
}
public override void OnQuestCancelled()
{
OnClaimReward(); // same effect
}
public override void OnExpire()
{
OnQuestCancelled();
Instance.Player.SendLocalizedMessage(1074813); // You have failed to complete your delivery.
}
public override void WriteToGump(Gump g, ref int y)
{
Objective.WriteToGump(g, ref y);
base.WriteToGump(g, ref y);
// No extra instance stuff printed for this objective
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write(HasCompleted);
}
}
}

View file

@ -0,0 +1,266 @@
using System;
using Server.Gumps;
using Server.Misc;
using Server.Mobiles;
namespace Server.Engines.MLQuests.Objectives
{
public class EscortObjective : BaseObjective
{
public EscortObjective(QuestArea destination = null)
{
Destination = destination;
}
public QuestArea Destination{ get; set; }
public override bool CanOffer(IQuestGiver quester, PlayerMobile pm, bool message)
{
if (quester is BaseCreature creature && creature.Controlled ||
quester is BaseEscortable escortable && escortable.IsBeingDeleted)
return false;
MLQuestContext context = MLQuestSystem.GetContext(pm);
if (context != null)
foreach (MLQuestInstance instance in context.QuestInstances)
if (instance.Quest.IsEscort)
{
if (message)
MLQuestSystem.Tell(quester, pm, 500896); // I see you already have an escort.
return false;
}
DateTime nextEscort = pm.LastEscortTime + BaseEscortable.EscortDelay;
if (nextEscort > DateTime.UtcNow)
{
if (message)
{
int minutes = (int)Math.Ceiling((nextEscort - DateTime.UtcNow).TotalMinutes);
if (minutes == 1)
MLQuestSystem.Tell(quester, pm, "You must rest 1 minute before we set out on this journey.");
else
MLQuestSystem.Tell(quester, pm, 1071195,
minutes.ToString()); // You must rest ~1_minsleft~ minutes before we set out on this journey.
}
return false;
}
return true;
}
public override void WriteToGump(Gump g, ref int y)
{
g.AddHtmlLocalized(98, y, 312, 16, 1072206, 0x15F90); // Escort to
if (Destination.Name.Number > 0)
g.AddHtmlLocalized(173, y, 312, 20, Destination.Name.Number, 0xFFFFFF);
else if (Destination.Name.String != null)
g.AddLabel(173, y, 0x481, Destination.Name.String);
y += 16;
}
public override BaseObjectiveInstance CreateInstance(MLQuestInstance instance)
{
if (instance == null || Destination == null)
return null;
return new EscortObjectiveInstance(this, instance);
}
}
public class EscortObjectiveInstance : BaseObjectiveInstance
{
private BaseCreature m_Escort;
private DateTime m_LastSeenEscorter;
private EscortObjective m_Objective;
private Timer m_Timer;
public EscortObjectiveInstance(EscortObjective objective, MLQuestInstance instance)
: base(instance, objective)
{
m_Objective = objective;
HasCompleted = false;
m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5), CheckDestination);
m_LastSeenEscorter = DateTime.UtcNow;
m_Escort = instance.Quester as BaseCreature;
if (MLQuestSystem.Debug && m_Escort == null && instance.Quester != null)
Console.WriteLine("Warning: EscortObjective is not supported for type '{0}'",
instance.Quester.GetType().Name);
}
public bool HasCompleted{ get; set; }
public override DataType ExtraDataType => DataType.EscortObjective;
public override bool IsCompleted()
{
return HasCompleted;
}
private void CheckDestination()
{
if (m_Escort == null || HasCompleted) // Completed by deserialization
{
StopTimer();
return;
}
MLQuestInstance instance = Instance;
PlayerMobile pm = instance.Player;
if (instance.Removed)
{
Abandon();
}
else if (m_Objective.Destination.Contains(m_Escort))
{
m_Escort.Say(1042809,
pm.Name); // We have arrived! I thank thee, ~1_PLAYER_NAME~! I have no further need of thy services. Here is thy pay.
if (pm.Young || m_Escort.Region.IsPartOf("Haven Island"))
Titles.AwardFame(pm, 10, true);
else
VirtueHelper.AwardVirtue(pm, VirtueName.Compassion,
m_Escort is BaseEscortable escortable && escortable.IsPrisoner ? 400 : 200);
EndFollow(m_Escort);
StopTimer();
HasCompleted = true;
CheckComplete();
// Auto claim reward
MLQuestSystem.OnDoubleClick(m_Escort, pm);
}
else if (pm.Map != m_Escort.Map || !pm.InRange(m_Escort, 30)) // TODO: verify range
{
if (m_LastSeenEscorter + BaseEscortable.AbandonDelay <= DateTime.UtcNow)
Abandon();
}
else
{
m_LastSeenEscorter = DateTime.UtcNow;
}
}
private void StopTimer()
{
if (m_Timer != null)
{
m_Timer.Stop();
m_Timer = null;
}
}
public static void BeginFollow(BaseCreature quester, PlayerMobile pm)
{
quester.ControlSlots = 0;
quester.SetControlMaster(pm);
quester.ActiveSpeed = 0.1;
quester.PassiveSpeed = 0.2;
quester.ControlOrder = OrderType.Follow;
quester.ControlTarget = pm;
quester.CantWalk = false;
quester.CurrentSpeed = 0.1;
}
public static void EndFollow(BaseCreature quester)
{
quester.ActiveSpeed = 0.2;
quester.PassiveSpeed = 1.0;
quester.ControlOrder = OrderType.None;
quester.ControlTarget = null;
quester.CurrentSpeed = 1.0;
quester.SetControlMaster(null);
(quester as BaseEscortable)?.BeginDelete();
}
public override void OnQuestAccepted()
{
MLQuestInstance instance = Instance;
PlayerMobile pm = instance.Player;
pm.LastEscortTime = DateTime.UtcNow;
if (m_Escort != null)
BeginFollow(m_Escort, pm);
}
public void Abandon()
{
StopTimer();
MLQuestInstance instance = Instance;
PlayerMobile pm = instance.Player;
if (m_Escort?.Deleted == false)
{
if (!pm.Alive)
m_Escort.Say(500901); // Ack! My escort has come to haunt me!
else
m_Escort.Say(500902); // My escort seems to have abandoned me!
EndFollow(m_Escort);
}
// Note: this sound is sent twice on OSI (once here and once in Cancel())
//m_Player.SendSound( 0x5B3 ); // private sound
pm.SendLocalizedMessage(1071194); // You have failed your escort quest...
if (!instance.Removed)
instance.Cancel();
}
public override void OnQuesterDeleted()
{
if (IsCompleted() || Instance.Removed)
return;
Abandon();
}
public override void OnPlayerDeath()
{
// Note: OSI also cancels it when the quest is already complete
if ( /*IsCompleted() ||*/ Instance.Removed)
return;
Instance.Cancel();
}
public override void OnExpire()
{
Abandon();
}
public override void WriteToGump(Gump g, ref int y)
{
m_Objective.WriteToGump(g, ref y);
base.WriteToGump(g, ref y);
// No extra instance stuff printed for this objective
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write(HasCompleted);
}
}
}

View file

@ -0,0 +1,162 @@
using System;
using Server.Gumps;
using Server.Mobiles;
namespace Server.Engines.MLQuests.Objectives
{
[Flags]
public enum GainSkillObjectiveFlags : byte
{
None = 0x00,
UseReal = 0x01,
Accelerate = 0x02
}
public class GainSkillObjective : BaseObjective
{
private GainSkillObjectiveFlags m_Flags;
public GainSkillObjective(SkillName skill = SkillName.Alchemy, int thresholdFixed = 0, bool useReal = false, bool accelerate = false)
{
Skill = skill;
ThresholdFixed = thresholdFixed;
m_Flags = GainSkillObjectiveFlags.None;
if (useReal)
m_Flags |= GainSkillObjectiveFlags.UseReal;
if (accelerate)
m_Flags |= GainSkillObjectiveFlags.Accelerate;
}
public SkillName Skill{ get; set; }
public int ThresholdFixed{ get; set; }
public bool UseReal
{
get => GetFlag(GainSkillObjectiveFlags.UseReal);
set => SetFlag(GainSkillObjectiveFlags.UseReal, value);
}
public bool Accelerate
{
get => GetFlag(GainSkillObjectiveFlags.Accelerate);
set => SetFlag(GainSkillObjectiveFlags.Accelerate, value);
}
public override bool CanOffer(IQuestGiver quester, PlayerMobile pm, bool message)
{
Skill skill = pm.Skills[Skill];
if ((UseReal ? skill.Fixed : skill.BaseFixedPoint) >= ThresholdFixed)
{
if (message)
MLQuestSystem.Tell(quester, pm, 1077772); // I cannot teach you, for you know all I can teach!
return false;
}
return true;
}
public override void WriteToGump(Gump g, ref int y)
{
int skillLabel = AosSkillBonuses.GetLabel(Skill);
string args;
args = ThresholdFixed % 10 == 0 ? $"#{skillLabel}\t{ThresholdFixed / 10}" : $"#{skillLabel}\t{(double)ThresholdFixed / 10:0.0}";
g.AddHtmlLocalized(98, y, 312, 16, 1077485, args, 0x15F90); // Increase ~1_SKILL~ to ~2_VALUE~
y += 16;
}
public override BaseObjectiveInstance CreateInstance(MLQuestInstance instance)
{
return new GainSkillObjectiveInstance(this, instance);
}
private bool GetFlag(GainSkillObjectiveFlags flag)
{
return (m_Flags & flag) != 0;
}
private void SetFlag(GainSkillObjectiveFlags flag, bool value)
{
if (value)
m_Flags |= flag;
else
m_Flags &= ~flag;
}
}
// On OSI, once this is complete, it will *stay* complete, even if you lower your skill again
public class GainSkillObjectiveInstance : BaseObjectiveInstance
{
public GainSkillObjectiveInstance(GainSkillObjective objective, MLQuestInstance instance)
: base(instance, objective)
{
Objective = objective;
}
public GainSkillObjective Objective{ get; set; }
public bool Handles(SkillName skill)
{
return Objective.Skill == skill;
}
public override bool IsCompleted()
{
PlayerMobile pm = Instance.Player;
int valueFixed = Objective.UseReal
? pm.Skills[Objective.Skill].Fixed
: pm.Skills[Objective.Skill].BaseFixedPoint;
return valueFixed >= Objective.ThresholdFixed;
}
// TODO: This may interfere with scrolls, or even quests among each other
// How does OSI deal with this?
public override void OnQuestAccepted()
{
if (!Objective.Accelerate)
return;
PlayerMobile pm = Instance.Player;
pm.AcceleratedSkill = Objective.Skill;
pm.AcceleratedStart = DateTime.UtcNow + TimeSpan.FromMinutes(15); // TODO: Is there a max duration?
}
public override void OnQuestCancelled()
{
if (!Objective.Accelerate)
return;
PlayerMobile pm = Instance.Player;
pm.AcceleratedStart = DateTime.UtcNow;
pm.PlaySound(0x100);
}
public override void OnQuestCompleted()
{
OnQuestCancelled();
}
public override void WriteToGump(Gump g, ref int y)
{
Objective.WriteToGump(g, ref y);
base.WriteToGump(g, ref y);
if (IsCompleted())
{
g.AddHtmlLocalized(113, y, 312, 20, 1055121, 0xFFFFFF); // Complete
y += 16;
}
}
}
}

View file

@ -0,0 +1,146 @@
using System;
using Server.Gumps;
using Server.Mobiles;
namespace Server.Engines.MLQuests.Objectives
{
public class KillObjective : BaseObjective
{
public KillObjective(
int amount = 0, Type[] types = null, TextDefinition name = null, QuestArea area = null)
{
DesiredAmount = amount;
AcceptedTypes = types;
Name = name;
Area = area;
}
public int DesiredAmount{ get; set; }
public Type[] AcceptedTypes{ get; set; }
public TextDefinition Name{ get; set; }
public QuestArea Area{ get; set; }
public override void WriteToGump(Gump g, ref int y)
{
string amount = DesiredAmount.ToString();
g.AddHtmlLocalized(98, y, 312, 16, 1072204, 0x15F90); // Slay
g.AddLabel(133, y, 0x481, amount);
if (Name.Number > 0)
g.AddHtmlLocalized(133 + amount.Length * 15, y, 190, 18, Name.Number, 0x77BF);
else if (Name.String != null)
g.AddLabel(133 + amount.Length * 15, y, 0x481, Name.String);
y += 16;
#region Location
if (Area != null)
{
g.AddHtmlLocalized(103, y, 312, 20, 1018327, 0x15F90); // Location
if (Area.Name.Number > 0)
g.AddHtmlLocalized(223, y, 312, 20, Area.Name.Number, 0xFFFFFF);
else if (Area.Name.String != null)
g.AddLabel(223, y, 0x481, Area.Name.String);
y += 16;
}
#endregion
}
public override BaseObjectiveInstance CreateInstance(MLQuestInstance instance)
{
return new KillObjectiveInstance(this, instance);
}
}
#region Timed
public class TimedKillObjective : KillObjective
{
public TimedKillObjective(TimeSpan duration, int amount, Type[] types, TextDefinition name, QuestArea area = null)
: base(amount, types, name, area)
{
Duration = duration;
}
public override bool IsTimed => true;
public override TimeSpan Duration{ get; }
}
#endregion
public class KillObjectiveInstance : BaseObjectiveInstance
{
public KillObjectiveInstance(KillObjective objective, MLQuestInstance instance)
: base(instance, objective)
{
Objective = objective;
Slain = 0;
}
public KillObjective Objective{ get; set; }
public int Slain{ get; set; }
public override DataType ExtraDataType => DataType.KillObjective;
public bool AddKill(Mobile mob, Type type)
{
int desired = Objective.DesiredAmount;
foreach (Type acceptedType in Objective.AcceptedTypes)
if (acceptedType.IsAssignableFrom(type))
{
if (Objective.Area?.Contains(mob) == false)
return false;
PlayerMobile pm = Instance.Player;
if (++Slain >= desired)
pm.SendLocalizedMessage(1075050); // You have killed all the required quest creatures of this type.
else
pm.SendLocalizedMessage(1075051,
(desired - Slain).ToString()); // You have killed a quest creature. ~1_val~ more left.
return true;
}
return false;
}
public override bool IsCompleted()
{
return Slain >= Objective.DesiredAmount;
}
public override void WriteToGump(Gump g, ref int y)
{
Objective.WriteToGump(g, ref y);
base.WriteToGump(g, ref y);
g.AddHtmlLocalized(103, y, 120, 16, 3000087, 0x15F90); // Total
g.AddLabel(223, y, 0x481, Slain.ToString());
y += 16;
g.AddHtmlLocalized(103, y, 120, 16, 1074782, 0x15F90); // Return to
g.AddLabel(223, y, 0x481, QuesterNameAttribute.GetQuesterNameFor(Instance.QuesterType));
y += 16;
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write(Slain);
}
}
}