* Fixes a bug with the main loop. Removes unnecessary optimizations for RDRand. * WIP - Rewriting packets. * Cleanup and updates README * Converts more packets * Fixes header * Converts Effects packets. * Forgot the send command * Adds the start of containers packets. * Adds message packets with caching * Extends the send methods * Starts to add Acquire methods * Converted the packets * Cleanup * Cleanup * Adds more packets * Adds more packets * Fixes clearing arrays from pool. Adds Mobile Incoming * Converts more packets. * Moves more packets * Moves more packets * Test compression * Merges * Migrating to an idiomatic syntax that also supports compression, and proxying. * Optimize the stack alloc. Changes attributes * Converted container packets * Visual Studio doesn't auto save files. I am still getting used to subpar IDEs. * Adds static packet caching. Will profile later. Converts more packets * Fixes packets and changes how compression is configured * WIP - Adds basics for Gumps. Not finished though. * Fix file * Fixes formatting * Changed SpanWriter to be more idiomatic. * Fixes Span vs RawSpan and missing stackallocs * Converts over some more gumps * WIP - Deletes 32bit support. * Drops RDRand32 support. * Fixes gump compilation * Converting gump components * Removes old huffman compression function * Revert signature for backwards compatibility * WIP - Converting more gump components * Creates ArraySet for the strings. Updates AppendTo to reference that. * Converts the maining gump components * Cleans up gump components * Cleans up directives * Cleans up ArraySet and moves it. Adds null-coalescing-assignment * Cleanup, Target Packets, and C# 8 changes. * Removed OPL Packet * World packets * Fixing packet uses * Cleans up code. Fixes packet uses in various places. * More cleanup for packets * Code cleanup * Converts more packet uses and cleans up more code * More code cleanup * Finishes fixing the packets in Item * Updates secure trade packets * Updates core and gets it to compile. * Moved packets to scripts. Fixed account handler use of packets * Code cleanup * Updates chat packets * Code cleanuo * Adds party packets, but need to implement them. * Party packets WIP * Finishes party packets * Rearrange movement namespaces and classes * Finishes plant packets * Code Formatting * Fixes moving effects * Code cleanup, eliminates equipinfo * Adds more packets. Fixes bugs with various packets. * Finishes mahjon packets * Fixes mahjong packet * Code cleanup * Finishes mahjong packets * Adds Map packets * Add multifacet maps and charts * Cleans up some packets with UTF8 * Optimizes packets * Cleans up more packets. Moves the MessageHelper * Removes assistant support. Removes extended protocol. Incorporates MapUO packets as normal packets. * Updates protocol extensions packet receiver * Fixes a few bugs. Fixes a few more packets. * Code cleanup and fixing more packets * Fixes packet effects * Cleaned up more code * Buff Icon cleanup * Removed unused constructors * Code Cleanup. Adds BoatHS Packets * Moves house files. Updates house foundation packets. * Deployment cleanup * Fixes: * Code cleanup * More code cleanup * More code cleanup * Cleaned up BaseHouse * Enforces styling * Converts foreach to linq where possible. * Dont need that * Goals/Readme updates * Removes 32bit support at the highest level. Turns on HRT by default. * Code cleanup. Fixes extended features packet. * Fixes various bugs * Code cleanup * Code cleanup * Code cleanup. Fixes gump X/Y assignment. * Code cleanup using |= operator * More code cleanup * Cleanup * Fixes spacing issues. Thanks Visual Studio. You suck. * Compiler error * Fixes NPE from RunUO 2.7 * Renames ScriptCompiler to AssemblyHandler. Fixes packets. Updates README * Fixes more packets. Stupid trailing nulls. * Fixes various bugs. * Fixes for gumps * Fixes more gump stuff. Going to split it out later since it is getting insane * Recoded the gump writing * WIP * *Added output path of scripts project to dev branch *Activated debugging in code
253 lines
7.1 KiB
C#
253 lines
7.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Server.Engines.MLQuests.Gumps;
|
|
using Server.Engines.MLQuests.Objectives;
|
|
using Server.Engines.MLQuests.Rewards;
|
|
using Server.Mobiles;
|
|
|
|
namespace Server.Engines.MLQuests
|
|
{
|
|
public enum ObjectiveType
|
|
{
|
|
All,
|
|
Any
|
|
}
|
|
|
|
public class MLQuest
|
|
{
|
|
public static readonly TextDefinition
|
|
CompletionNoticeDefault =
|
|
new TextDefinition(1072273); // You've completed a quest! Don't forget to collect your reward.
|
|
|
|
public static readonly TextDefinition CompletionNoticeShort = new TextDefinition(1046258); // Your quest is complete.
|
|
|
|
public static readonly TextDefinition
|
|
CompletionNoticeShortReturn = new TextDefinition(1073775); // Your quest is complete. Return for your reward.
|
|
|
|
public static readonly TextDefinition
|
|
CompletionNoticeCraft = new TextDefinition(1073967); // You obtained what you seek, now receive your reward.
|
|
|
|
public MLQuest()
|
|
{
|
|
Activated = false;
|
|
Objectives = new List<BaseObjective>();
|
|
ObjectiveType = ObjectiveType.All;
|
|
Rewards = new List<BaseReward>();
|
|
CompletionNotice = CompletionNoticeDefault;
|
|
|
|
Instances = new List<MLQuestInstance>();
|
|
|
|
SaveEnabled = true;
|
|
}
|
|
|
|
public bool Deserialized{ get; set; }
|
|
|
|
public bool SaveEnabled{ get; set; }
|
|
|
|
// TODO: Flags? (Deserialized, SaveEnabled, Activated)
|
|
|
|
public bool Activated{ get; set; }
|
|
|
|
public List<BaseObjective> Objectives{ get; set; }
|
|
|
|
public ObjectiveType ObjectiveType{ get; set; }
|
|
|
|
public List<BaseReward> Rewards{ get; set; }
|
|
|
|
public List<MLQuestInstance> Instances{ get; set; }
|
|
|
|
public bool OneTimeOnly{ get; set; }
|
|
|
|
public bool HasRestartDelay{ get; set; }
|
|
|
|
public bool IsEscort => HasObjective<EscortObjective>();
|
|
|
|
public bool IsSkillTrainer => HasObjective<GainSkillObjective>();
|
|
|
|
public bool RequiresCollection => HasObjective<CollectObjective>() || HasObjective<DeliverObjective>();
|
|
|
|
public virtual bool RecordCompletion => OneTimeOnly || HasRestartDelay;
|
|
|
|
public virtual bool IsChainTriggered => false;
|
|
public virtual Type NextQuest => null;
|
|
|
|
public TextDefinition Title{ get; set; }
|
|
|
|
public TextDefinition Description{ get; set; }
|
|
|
|
public TextDefinition RefusalMessage{ get; set; }
|
|
|
|
public TextDefinition InProgressMessage{ get; set; }
|
|
|
|
public TextDefinition CompletionMessage{ get; set; }
|
|
|
|
public TextDefinition CompletionNotice{ get; set; }
|
|
|
|
public virtual int Version => 0;
|
|
|
|
public bool HasObjective<T>() where T : BaseObjective => Objectives.OfType<T>().Any();
|
|
|
|
public virtual void Generate()
|
|
{
|
|
if (MLQuestSystem.Debug)
|
|
Console.WriteLine("INFO: Generating quest: {0}", GetType());
|
|
}
|
|
|
|
public MLQuestInstance CreateInstance(IQuestGiver quester, PlayerMobile pm) => new MLQuestInstance(this, quester, pm);
|
|
|
|
public bool CanOffer(IQuestGiver quester, PlayerMobile pm, bool message) => CanOffer(quester, pm, MLQuestSystem.GetContext(pm), message);
|
|
|
|
public virtual bool CanOffer(IQuestGiver quester, PlayerMobile pm, MLQuestContext context, bool message)
|
|
{
|
|
if (!Activated || quester.Deleted)
|
|
return false;
|
|
|
|
if (context != null)
|
|
{
|
|
if (context.IsFull)
|
|
{
|
|
if (message)
|
|
MLQuestSystem.Tell(quester, pm, 1080107); // I'm sorry, I have nothing for you at this time.
|
|
|
|
return false;
|
|
}
|
|
|
|
MLQuest checkQuest = this;
|
|
|
|
while (checkQuest != null)
|
|
{
|
|
if (context.HasDoneQuest(checkQuest, out DateTime nextAvailable))
|
|
{
|
|
if (checkQuest.OneTimeOnly)
|
|
{
|
|
if (message)
|
|
MLQuestSystem.Tell(quester, pm, 1075454); // I cannot offer you the quest again.
|
|
|
|
return false;
|
|
}
|
|
|
|
if (nextAvailable > DateTime.UtcNow)
|
|
{
|
|
if (message)
|
|
MLQuestSystem.Tell(quester, pm,
|
|
1075575); // I'm sorry, but I don't have anything else for you right now. Could you check back with me in a few minutes?
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (checkQuest.NextQuest == null)
|
|
break;
|
|
|
|
checkQuest = MLQuestSystem.FindQuest(checkQuest.NextQuest);
|
|
}
|
|
}
|
|
|
|
return Objectives.All(obj => obj.CanOffer(quester, pm, message));
|
|
}
|
|
|
|
public virtual void SendOffer(IQuestGiver quester, PlayerMobile pm)
|
|
{
|
|
pm.SendGump(new QuestOfferGump(this, quester, pm));
|
|
}
|
|
|
|
public virtual void OnAccept(IQuestGiver quester, PlayerMobile pm)
|
|
{
|
|
if (!CanOffer(quester, pm, true))
|
|
return;
|
|
|
|
MLQuestInstance instance = CreateInstance(quester, pm);
|
|
|
|
pm.SendLocalizedMessage(1049019); // You have accepted the Quest.
|
|
pm.SendSound(0x2E7); // private sound
|
|
|
|
OnAccepted(instance);
|
|
|
|
foreach (BaseObjectiveInstance obj in instance.Objectives)
|
|
obj.OnQuestAccepted();
|
|
}
|
|
|
|
public virtual void OnAccepted(MLQuestInstance instance)
|
|
{
|
|
}
|
|
|
|
public virtual void OnRefuse(IQuestGiver quester, PlayerMobile pm)
|
|
{
|
|
pm.SendGump(new QuestConversationGump(this, pm, RefusalMessage));
|
|
}
|
|
|
|
public virtual void GetRewards(MLQuestInstance instance)
|
|
{
|
|
instance.SendRewardGump();
|
|
}
|
|
|
|
public virtual void OnRewardClaimed(MLQuestInstance instance)
|
|
{
|
|
}
|
|
|
|
public virtual void OnCancel(MLQuestInstance instance)
|
|
{
|
|
}
|
|
|
|
public virtual void OnQuesterDeleted(MLQuestInstance instance)
|
|
{
|
|
}
|
|
|
|
public virtual void OnPlayerDeath(MLQuestInstance instance)
|
|
{
|
|
}
|
|
|
|
public virtual TimeSpan GetRestartDelay() => TimeSpan.FromSeconds(Utility.Random(1, 5) * 30);
|
|
|
|
public static void Serialize(GenericWriter writer, MLQuest quest)
|
|
{
|
|
MLQuestSystem.WriteQuestRef(writer, quest);
|
|
writer.Write(quest.Version);
|
|
}
|
|
|
|
public static void Deserialize(GenericReader reader, int version)
|
|
{
|
|
MLQuest quest = MLQuestSystem.ReadQuestRef(reader);
|
|
int oldVersion = reader.ReadInt();
|
|
|
|
if (quest == null)
|
|
return; // not saved or no longer exists
|
|
|
|
quest.Refresh(oldVersion);
|
|
quest.Deserialized = true;
|
|
}
|
|
|
|
public virtual void Refresh(int oldVersion)
|
|
{
|
|
}
|
|
|
|
#region Generation Methods
|
|
|
|
public void PutSpawner(Spawner s, Point3D loc, Map map)
|
|
{
|
|
string name = $"MLQS-{GetType().Name}";
|
|
|
|
IEnumerable<Item> toDelete = map.GetItemsInRange(loc, 0).Where(item => item is Spawner && item.Name == name);
|
|
|
|
foreach (Item item in toDelete)
|
|
item.Delete();
|
|
|
|
s.Name = name;
|
|
s.MoveToWorld(loc, map);
|
|
}
|
|
|
|
public void PutDeco(Item deco, Point3D loc, Map map)
|
|
{
|
|
// Auto cleanup on regeneration
|
|
IEnumerable<Item> toDelete = map.GetItemsInRange(loc, 0).Where(item => item.ItemID == deco.ItemID && item.Z == loc.Z);
|
|
|
|
foreach (Item item in toDelete)
|
|
item.Delete();
|
|
|
|
deco.MoveToWorld(loc, map);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|