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

View file

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

View file

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

View file

@ -1,270 +1,271 @@
using System;
using Server.Mobiles;
using Server.Gumps;
using Server.Misc;
using Server.Mobiles;
namespace Server.Engines.MLQuests.Objectives
{
public class EscortObjective : BaseObjective
{
public QuestArea Destination { get; set; }
public class EscortObjective : BaseObjective
{
public EscortObjective()
: this(null)
{
}
public EscortObjective()
: this( null )
{
}
public EscortObjective(QuestArea destination)
{
Destination = destination;
}
public EscortObjective( QuestArea destination )
{
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;
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 );
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.
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;
}
}
}
return false;
}
DateTime nextEscort = pm.LastEscortTime + BaseEscortable.EscortDelay;
DateTime nextEscort = pm.LastEscortTime + BaseEscortable.EscortDelay;
if ( nextEscort > DateTime.UtcNow )
{
if ( message )
{
int minutes = (int)Math.Ceiling( ( nextEscort - DateTime.UtcNow ).TotalMinutes );
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.
}
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 false;
}
return true;
}
return true;
}
public override void WriteToGump( Gump g, ref int y )
{
g.AddHtmlLocalized( 98, y, 312, 16, 1072206, 0x15F90, false, false ); // Escort to
public override void WriteToGump(Gump g, ref int y)
{
g.AddHtmlLocalized(98, y, 312, 16, 1072206, 0x15F90, false, false); // Escort to
if ( Destination.Name.Number > 0 )
g.AddHtmlLocalized( 173, y, 312, 20, Destination.Name.Number, 0xFFFFFF, false, false );
else if ( Destination.Name.String != null )
g.AddLabel( 173, y, 0x481, Destination.Name.String );
if (Destination.Name.Number > 0)
g.AddHtmlLocalized(173, y, 312, 20, Destination.Name.Number, 0xFFFFFF, false, false);
else if (Destination.Name.String != null)
g.AddLabel(173, y, 0x481, Destination.Name.String);
y += 16;
}
y += 16;
}
public override BaseObjectiveInstance CreateInstance( MLQuestInstance instance )
{
if ( instance == null || Destination == null )
return null;
public override BaseObjectiveInstance CreateInstance(MLQuestInstance instance)
{
if (instance == null || Destination == null)
return null;
return new EscortObjectiveInstance( this, instance );
}
}
return new EscortObjectiveInstance(this, instance);
}
}
public class EscortObjectiveInstance : BaseObjectiveInstance
{
private EscortObjective m_Objective;
private Timer m_Timer;
private DateTime m_LastSeenEscorter;
private BaseCreature m_Escort;
public class EscortObjectiveInstance : BaseObjectiveInstance
{
private BaseCreature m_Escort;
private DateTime m_LastSeenEscorter;
private EscortObjective m_Objective;
private Timer m_Timer;
public bool HasCompleted { get; set; }
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;
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);
}
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 bool IsCompleted()
{
return HasCompleted;
}
public override DataType ExtraDataType => DataType.EscortObjective;
private void CheckDestination()
{
if ( m_Escort == null || HasCompleted ) // Completed by deserialization
{
StopTimer();
return;
}
public override bool IsCompleted()
{
return HasCompleted;
}
MLQuestInstance instance = Instance;
PlayerMobile pm = instance.Player;
private void CheckDestination()
{
if (m_Escort == null || HasCompleted) // Completed by deserialization
{
StopTimer();
return;
}
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.
MLQuestInstance instance = Instance;
PlayerMobile pm = instance.Player;
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 );
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.
EndFollow( m_Escort );
StopTimer();
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);
HasCompleted = true;
CheckComplete();
EndFollow(m_Escort);
StopTimer();
// 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;
}
}
HasCompleted = true;
CheckComplete();
private void StopTimer()
{
if ( m_Timer != null )
{
m_Timer.Stop();
m_Timer = null;
}
}
// 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;
}
}
public static void BeginFollow( BaseCreature quester, PlayerMobile pm )
{
quester.ControlSlots = 0;
quester.SetControlMaster( pm );
private void StopTimer()
{
if (m_Timer != null)
{
m_Timer.Stop();
m_Timer = null;
}
}
quester.ActiveSpeed = 0.1;
quester.PassiveSpeed = 0.2;
public static void BeginFollow(BaseCreature quester, PlayerMobile pm)
{
quester.ControlSlots = 0;
quester.SetControlMaster(pm);
quester.ControlOrder = OrderType.Follow;
quester.ControlTarget = pm;
quester.ActiveSpeed = 0.1;
quester.PassiveSpeed = 0.2;
quester.CantWalk = false;
quester.CurrentSpeed = 0.1;
}
quester.ControlOrder = OrderType.Follow;
quester.ControlTarget = pm;
public static void EndFollow( BaseCreature quester )
{
quester.ActiveSpeed = 0.2;
quester.PassiveSpeed = 1.0;
quester.CantWalk = false;
quester.CurrentSpeed = 0.1;
}
quester.ControlOrder = OrderType.None;
quester.ControlTarget = null;
public static void EndFollow(BaseCreature quester)
{
quester.ActiveSpeed = 0.2;
quester.PassiveSpeed = 1.0;
quester.CurrentSpeed = 1.0;
quester.ControlOrder = OrderType.None;
quester.ControlTarget = null;
quester.SetControlMaster( null );
quester.CurrentSpeed = 1.0;
(quester as BaseEscortable)?.BeginDelete();
}
quester.SetControlMaster(null);
public override void OnQuestAccepted()
{
MLQuestInstance instance = Instance;
PlayerMobile pm = instance.Player;
(quester as BaseEscortable)?.BeginDelete();
}
pm.LastEscortTime = DateTime.UtcNow;
public override void OnQuestAccepted()
{
MLQuestInstance instance = Instance;
PlayerMobile pm = instance.Player;
if ( m_Escort != null )
BeginFollow( m_Escort, pm );
}
pm.LastEscortTime = DateTime.UtcNow;
public void Abandon()
{
StopTimer();
if (m_Escort != null)
BeginFollow(m_Escort, pm);
}
MLQuestInstance instance = Instance;
PlayerMobile pm = instance.Player;
public void Abandon()
{
StopTimer();
if ( m_Escort != null && !m_Escort.Deleted )
{
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!
MLQuestInstance instance = Instance;
PlayerMobile pm = instance.Player;
EndFollow( m_Escort );
}
if (m_Escort != null && !m_Escort.Deleted)
{
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!
// 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...
EndFollow(m_Escort);
}
if ( !instance.Removed )
instance.Cancel();
}
// 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...
public override void OnQuesterDeleted()
{
if ( IsCompleted() || Instance.Removed )
return;
if (!instance.Removed)
instance.Cancel();
}
Abandon();
}
public override void OnQuesterDeleted()
{
if (IsCompleted() || Instance.Removed)
return;
public override void OnPlayerDeath()
{
// Note: OSI also cancels it when the quest is already complete
if ( /*IsCompleted() ||*/ Instance.Removed )
return;
Abandon();
}
Instance.Cancel();
}
public override void OnPlayerDeath()
{
// Note: OSI also cancels it when the quest is already complete
if ( /*IsCompleted() ||*/ Instance.Removed)
return;
public override void OnExpire()
{
Abandon();
}
Instance.Cancel();
}
public override void WriteToGump( Gump g, ref int y )
{
m_Objective.WriteToGump( g, ref y );
public override void OnExpire()
{
Abandon();
}
base.WriteToGump( g, ref y );
public override void WriteToGump(Gump g, ref int y)
{
m_Objective.WriteToGump(g, ref y);
// No extra instance stuff printed for this objective
}
base.WriteToGump(g, ref y);
public override DataType ExtraDataType => DataType.EscortObjective;
// No extra instance stuff printed for this objective
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write( HasCompleted );
}
}
}
writer.Write(HasCompleted);
}
}
}

View file

@ -1,172 +1,174 @@
using System;
using Server.Mobiles;
using Server.Gumps;
using Server.Mobiles;
namespace Server.Engines.MLQuests.Objectives
{
public enum GainSkillObjectiveFlags : byte
{
None = 0x00,
UseReal = 0x01,
Accelerate = 0x02
}
public enum GainSkillObjectiveFlags : byte
{
None = 0x00,
UseReal = 0x01,
Accelerate = 0x02
}
public class GainSkillObjective : BaseObjective
{
private GainSkillObjectiveFlags m_Flags;
public class GainSkillObjective : BaseObjective
{
private GainSkillObjectiveFlags m_Flags;
public SkillName Skill { get; set; }
public GainSkillObjective()
: this(SkillName.Alchemy, 0)
{
}
public int ThresholdFixed { get; set; }
public GainSkillObjective(SkillName skill, int thresholdFixed)
: this(skill, thresholdFixed, false, false)
{
}
public bool UseReal
{
get => GetFlag( GainSkillObjectiveFlags.UseReal );
set => SetFlag( GainSkillObjectiveFlags.UseReal, value );
}
public GainSkillObjective(SkillName skill, int thresholdFixed, bool useReal, bool accelerate)
{
Skill = skill;
ThresholdFixed = thresholdFixed;
m_Flags = GainSkillObjectiveFlags.None;
public bool Accelerate
{
get => GetFlag( GainSkillObjectiveFlags.Accelerate );
set => SetFlag( GainSkillObjectiveFlags.Accelerate, value );
}
if (useReal)
m_Flags |= GainSkillObjectiveFlags.UseReal;
public GainSkillObjective()
: this( SkillName.Alchemy, 0 )
{
}
if (accelerate)
m_Flags |= GainSkillObjectiveFlags.Accelerate;
}
public GainSkillObjective( SkillName skill, int thresholdFixed )
: this( skill, thresholdFixed, false, false )
{
}
public SkillName Skill{ get; set; }
public GainSkillObjective( SkillName skill, int thresholdFixed, bool useReal, bool accelerate )
{
Skill = skill;
ThresholdFixed = thresholdFixed;
m_Flags = GainSkillObjectiveFlags.None;
public int ThresholdFixed{ get; set; }
if ( useReal )
m_Flags |= GainSkillObjectiveFlags.UseReal;
public bool UseReal
{
get => GetFlag(GainSkillObjectiveFlags.UseReal);
set => SetFlag(GainSkillObjectiveFlags.UseReal, value);
}
if ( accelerate )
m_Flags |= GainSkillObjectiveFlags.Accelerate;
}
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];
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!
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 false;
}
return true;
}
return true;
}
public override void WriteToGump( Gump g, ref int y )
{
int skillLabel = AosSkillBonuses.GetLabel( Skill );
string args;
public override void WriteToGump(Gump g, ref int y)
{
int skillLabel = AosSkillBonuses.GetLabel(Skill);
string args;
if ( ThresholdFixed % 10 == 0 )
args = $"#{skillLabel}\t{ThresholdFixed / 10}"; // as seen on OSI
else
args = $"#{skillLabel}\t{(double) ThresholdFixed / 10:0.0}"; // for non-integer skill levels
if (ThresholdFixed % 10 == 0)
args = $"#{skillLabel}\t{ThresholdFixed / 10}"; // as seen on OSI
else
args = $"#{skillLabel}\t{(double)ThresholdFixed / 10:0.0}"; // for non-integer skill levels
g.AddHtmlLocalized( 98, y, 312, 16, 1077485, args, 0x15F90, false, false ); // Increase ~1_SKILL~ to ~2_VALUE~
y += 16;
}
g.AddHtmlLocalized(98, y, 312, 16, 1077485, args, 0x15F90, false, false); // Increase ~1_SKILL~ to ~2_VALUE~
y += 16;
}
public override BaseObjectiveInstance CreateInstance( MLQuestInstance instance )
{
return new GainSkillObjectiveInstance( this, instance );
}
public override BaseObjectiveInstance CreateInstance(MLQuestInstance instance)
{
return new GainSkillObjectiveInstance(this, instance);
}
private bool GetFlag( GainSkillObjectiveFlags flag )
{
return ( ( m_Flags & flag ) != 0 );
}
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;
}
}
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 GainSkillObjective Objective { get; set; }
// 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 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 bool Handles(SkillName skill)
{
return Objective.Skill == skill;
}
public override bool IsCompleted()
{
PlayerMobile pm = Instance.Player;
public override bool IsCompleted()
{
PlayerMobile pm = Instance.Player;
int valueFixed = Objective.UseReal ? pm.Skills[Objective.Skill].Fixed : pm.Skills[Objective.Skill].BaseFixedPoint;
int valueFixed = Objective.UseReal
? pm.Skills[Objective.Skill].Fixed
: pm.Skills[Objective.Skill].BaseFixedPoint;
return ( valueFixed >= Objective.ThresholdFixed );
}
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;
// 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;
PlayerMobile pm = Instance.Player;
pm.AcceleratedSkill = Objective.Skill;
pm.AcceleratedStart = DateTime.UtcNow + TimeSpan.FromMinutes( 15 ); // TODO: Is there a max duration?
}
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;
public override void OnQuestCancelled()
{
if (!Objective.Accelerate)
return;
PlayerMobile pm = Instance.Player;
PlayerMobile pm = Instance.Player;
pm.AcceleratedStart = DateTime.UtcNow;
pm.PlaySound( 0x100 );
}
pm.AcceleratedStart = DateTime.UtcNow;
pm.PlaySound(0x100);
}
public override void OnQuestCompleted()
{
OnQuestCancelled();
}
public override void OnQuestCompleted()
{
OnQuestCancelled();
}
public override void WriteToGump( Gump g, ref int y )
{
Objective.WriteToGump( g, ref y );
public override void WriteToGump(Gump g, ref int y)
{
Objective.WriteToGump(g, ref y);
base.WriteToGump( g, ref y );
base.WriteToGump(g, ref y);
if ( IsCompleted() )
{
g.AddHtmlLocalized( 113, y, 312, 20, 1055121, 0xFFFFFF, false, false ); // Complete
y += 16;
}
}
}
}
if (IsCompleted())
{
g.AddHtmlLocalized(113, y, 312, 20, 1055121, 0xFFFFFF, false, false); // Complete
y += 16;
}
}
}
}

View file

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