using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using DOL.GS;
using DOL.Database;
using DOL.Events;
using DOL.GS.Quests;
using DOL.GS.PacketHandler;
using DOL.GS.Scripts.Quests;
using DOL.Storm;
using log4net;
public class SampleInteractQuest : RewardQuest
{
// The title of the quest
protected const string _QuestTitle = "Interact Test Quest";
// The realm this quest is in
protected const eRealm _Realm = eRealm.Albion;
// The name of the NPC this quest is attached too
protected const string _QuestNPCName = "Interact Test";
protected QuestGoal _QuestGoal;
protected static ItemTemplate m_wildOats = null;
protected static ItemTemplate m_rustyDagger = null;
// This list will maintain the world objects to make sure they don't get deleted (garbage collected) when removed from world.
protected static List<GameStaticItem> m_worldRustyDaggers = new List<GameStaticItem>();
// The maximum number of times a single character can do this quest
public override int MaxQuestCount
{
get { return 9999; }
}
/// <summary>
/// The fully-fledged story to the quest.
/// </summary>
public override string Story
{
get
{
String desc = "This is a test quest to demonstrate interacting with different StaticObjects.";
return desc;
}
}
/// <summary>
/// A summary of the quest's story.
/// </summary>
public override string Summary
{
get
{
return String.Format("For the different steps interact with the static item indicated in your journal.");
}
}
/// <summary>
/// The text for individual quest steps as shown in the journal.
/// </summary>
public override string Description
{
get
{
switch (Step)
{
case 1:
return "Collect Wild Oats";
case 2:
return "Collect Rusty Daggers (careful, sharp)";
case 3:
return "Return to " + _QuestNPCName + " and end this silly quest.";
default:
return "No Queststep Description available.";
}
}
}
/// <summary>
/// Text showing upon finishing the quest.
/// </summary>
public override String Conclusion
{
get
{
return "Yay, done!";
}
}
public SampleInteractQuest()
: base()
{
Init(null);
}
public SampleInteractQuest(GamePlayer questingPlayer)
: base(questingPlayer, 1)
{
Init(questingPlayer);
}
public SampleInteractQuest(GamePlayer questingPlayer, int step)
: base(questingPlayer, step)
{
Init(questingPlayer);
}
public SampleInteractQuest(GamePlayer questingPlayer, DBQuest dbQuest)
: base(questingPlayer, dbQuest)
{
Init(questingPlayer);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
public override string Name
{
get { return _QuestTitle; }
}
public virtual QuestGoal QuestGoals
{
set { _QuestGoal = value; }
get { return _QuestGoal; }
}
protected virtual string QuestNPCName
{
get { return _QuestNPCName; }
}
protected static GameNPC _QuestNPC = null;
protected virtual GameNPC QuestNPC
{
get { return _QuestNPC; }
}
protected virtual Type QuestClass
{
get { return MethodBase.GetCurrentMethod().DeclaringType; }
}
[ScriptLoadedEvent]
public static void ScriptLoaded(DOLEvent e, object sender, EventArgs args)
{
if (log.IsInfoEnabled)
log.Info("Quest \"" + _QuestTitle + "\" initializing ...");
GameNPC[] npcs = WorldMgr.GetNPCsByName(_QuestNPCName, _Realm);
if (npcs != null && npcs.Length > 0)
{
_QuestNPC = npcs[0];
}
if (_QuestNPC == null)
{
_QuestNPC = new GameNPC();
_QuestNPC.Name = _QuestNPCName;
_QuestNPC.Model = 5;
_QuestNPC.Size = 50;
_QuestNPC.CurrentRegionID = 27;
_QuestNPC.X = 91728;
_QuestNPC.Y = 86536;
_QuestNPC.Z = 5193;
_QuestNPC.Heading = 1249;
_QuestNPC.Realm = eRealm.Albion;
_QuestNPC.Level = 1;
_QuestNPC.Flags ^= (uint)GameNPC.eFlags.PEACE;
_QuestNPC.AddToWorld();
log.Info("Quest \"" + _QuestTitle + "\" npc " + _QuestNPCName + " not found, creating ...");
return;
}
GameEventMgr.AddHandler(GamePlayerEvent.AcceptQuest, new DOLEventHandler(HandleQuestEvent));
GameEventMgr.AddHandler(GamePlayerEvent.DeclineQuest, new DOLEventHandler(HandleQuestEvent));
GameEventMgr.AddHandler(GamePlayerEvent.AbortQuest, new DOLEventHandler(HandleQuestEvent));
GameEventMgr.AddHandler(_QuestNPC, GameLivingEvent.Interact, new DOLEventHandler(TalkToQuestGiver));
GameEventMgr.AddHandler(_QuestNPC, GameLivingEvent.WhisperReceive, new DOLEventHandler(TalkToQuestGiver));
_QuestNPC.AddQuestToGive(MethodBase.GetCurrentMethod().DeclaringType);
m_wildOats = GameServer.Database.FindObjectByKey<ItemTemplate>("quest_wild_oats");
if (m_wildOats == null)
{
m_wildOats = new ItemTemplate();
m_wildOats.Name = "Wild Oats";
if (log.IsWarnEnabled)
log.Warn("Could not find " + m_wildOats.Name + ", creating it ...");
m_wildOats.Level = 1;
m_wildOats.Weight = 1;
m_wildOats.Model = 4172;
m_wildOats.Object_Type = 0;
m_wildOats.Item_Type = 0;
m_wildOats.Id_nb = "quest_wild_oats";
m_wildOats.Hand = 0;
m_wildOats.Platinum = 0;
m_wildOats.Gold = 0;
m_wildOats.Silver = 0;
m_wildOats.Copper = 0;
m_wildOats.IsPickable = true;
m_wildOats.IsDropable = true;
m_wildOats.IsTradable = false;
m_wildOats.CanDropAsLoot = false;
m_wildOats.Color = 0;
m_wildOats.Bonus = 0; // default bonus
m_wildOats.Bonus1 = 0;
m_wildOats.Bonus1Type = (int)0;
m_wildOats.Bonus2 = 0;
m_wildOats.Bonus2Type = (int)0;
m_wildOats.Bonus3 = 0;
m_wildOats.Bonus3Type = (int)0;
m_wildOats.Bonus4 = 0;
m_wildOats.Bonus4Type = (int)0;
m_wildOats.Bonus5 = 0;
m_wildOats.Bonus5Type = (int)0;
m_wildOats.Bonus6 = 0;
m_wildOats.Bonus6Type = (int)0;
m_wildOats.Bonus7 = 0;
m_wildOats.Bonus7Type = (int)0;
m_wildOats.Bonus8 = 0;
m_wildOats.Bonus8Type = (int)0;
m_wildOats.Bonus9 = 0;
m_wildOats.Bonus9Type = (int)0;
m_wildOats.Bonus10 = 0;
m_wildOats.Bonus10Type = (int)0;
m_wildOats.ExtraBonus = 0;
m_wildOats.ExtraBonusType = (int)0;
m_wildOats.Effect = 0;
m_wildOats.Emblem = 0;
m_wildOats.Charges = 0;
m_wildOats.MaxCharges = 0;
m_wildOats.SpellID = 0;
m_wildOats.ProcSpellID = 0;
m_wildOats.Type_Damage = 0;
m_wildOats.Realm = 0;
m_wildOats.MaxCount = 1;
m_wildOats.PackSize = 1;
m_wildOats.Extension = 0;
m_wildOats.Quality = 100;
m_wildOats.Condition = 100;
m_wildOats.MaxCondition = 100;
m_wildOats.Durability = 100;
m_wildOats.MaxDurability = 100;
m_wildOats.PoisonCharges = 0;
m_wildOats.PoisonMaxCharges = 0;
m_wildOats.PoisonSpellID = 0;
m_wildOats.ProcSpellID1 = 0;
m_wildOats.SpellID1 = 0;
m_wildOats.MaxCharges1 = 0;
m_wildOats.Charges1 = 0;
}
m_rustyDagger = GameServer.Database.FindObjectByKey<ItemTemplate>("quest_rusty_dagger");
if (m_rustyDagger == null)
{
m_rustyDagger = new ItemTemplate();
m_rustyDagger.Name = "Rusty Dagger";
if (log.IsWarnEnabled)
log.Warn("Could not find " + m_rustyDagger.Name + ", creating it ...");
m_rustyDagger.Level = 1;
m_rustyDagger.Weight = 1;
m_rustyDagger.Model = 1;
m_rustyDagger.Object_Type = 0;
m_rustyDagger.Item_Type = 0;
m_rustyDagger.Id_nb = "quest_rusty_dagger";
m_rustyDagger.Hand = 0;
m_rustyDagger.Platinum = 0;
m_rustyDagger.Gold = 0;
m_rustyDagger.Silver = 0;
m_rustyDagger.Copper = 0;
m_rustyDagger.IsPickable = true;
m_rustyDagger.IsDropable = true;
m_rustyDagger.IsTradable = false;
m_rustyDagger.CanDropAsLoot = false;
m_rustyDagger.Color = 63;
m_rustyDagger.Bonus = 0; // default bonus
m_rustyDagger.Bonus1 = 0;
m_rustyDagger.Bonus1Type = (int)0;
m_rustyDagger.Bonus2 = 0;
m_rustyDagger.Bonus2Type = (int)0;
m_rustyDagger.Bonus3 = 0;
m_rustyDagger.Bonus3Type = (int)0;
m_rustyDagger.Bonus4 = 0;
m_rustyDagger.Bonus4Type = (int)0;
m_rustyDagger.Bonus5 = 0;
m_rustyDagger.Bonus5Type = (int)0;
m_rustyDagger.Bonus6 = 0;
m_rustyDagger.Bonus6Type = (int)0;
m_rustyDagger.Bonus7 = 0;
m_rustyDagger.Bonus7Type = (int)0;
m_rustyDagger.Bonus8 = 0;
m_rustyDagger.Bonus8Type = (int)0;
m_rustyDagger.Bonus9 = 0;
m_rustyDagger.Bonus9Type = (int)0;
m_rustyDagger.Bonus10 = 0;
m_rustyDagger.Bonus10Type = (int)0;
m_rustyDagger.ExtraBonus = 0;
m_rustyDagger.ExtraBonusType = (int)0;
m_rustyDagger.Effect = 0;
m_rustyDagger.Emblem = 0;
m_rustyDagger.Charges = 0;
m_rustyDagger.MaxCharges = 0;
m_rustyDagger.SpellID = 0;
m_rustyDagger.ProcSpellID = 0;
m_rustyDagger.Type_Damage = 0;
m_rustyDagger.Realm = 0;
m_rustyDagger.MaxCount = 1;
m_rustyDagger.PackSize = 1;
m_rustyDagger.Extension = 0;
m_rustyDagger.Quality = 100;
m_rustyDagger.Condition = 100;
m_rustyDagger.MaxCondition = 100;
m_rustyDagger.Durability = 100;
m_rustyDagger.MaxDurability = 100;
m_rustyDagger.PoisonCharges = 0;
m_rustyDagger.PoisonMaxCharges = 0;
m_rustyDagger.PoisonSpellID = 0;
m_rustyDagger.ProcSpellID1 = 0;
m_rustyDagger.SpellID1 = 0;
m_rustyDagger.MaxCharges1 = 0;
m_rustyDagger.Charges1 = 0;
}
// now add a few static objects to demonstrate how these can either be in the world already or added here.
GameLocation l = new GameLocation("Rusty Dagger", 27, 91456, 86520, 5136, 1592);
for (int x = 0; x < 10; x++)
{
GameStaticItem w = new GameStaticItem();
w.Name = l.Name;
w.Model = 1;
w.CurrentRegionID = l.RegionID;
w.X = l.X + Util.Random(300);
w.Y = l.Y + Util.Random(300);
w.Z = l.Z;
w.Heading = (ushort)Util.Random(0, 2000);
m_worldRustyDaggers.Add(w);
w.AddToWorld();
}
if (log.IsInfoEnabled)
log.Info("Quest \"" + _QuestTitle + "\" initialized.");
}
[ScriptUnloadedEvent]
public static void ScriptUnloaded(DOLEvent e, object sender, EventArgs args)
{
if (_QuestNPC == null)
return;
GameEventMgr.RemoveHandler(GamePlayerEvent.AcceptQuest, new DOLEventHandler(HandleQuestEvent));
GameEventMgr.RemoveHandler(GamePlayerEvent.DeclineQuest, new DOLEventHandler(HandleQuestEvent));
GameEventMgr.RemoveHandler(GamePlayerEvent.AbortQuest, new DOLEventHandler(HandleQuestEvent));
GameEventMgr.RemoveHandler(_QuestNPC, GameObjectEvent.Interact, new DOLEventHandler(TalkToQuestGiver));
GameEventMgr.RemoveHandler(_QuestNPC, GameLivingEvent.WhisperReceive, new DOLEventHandler(TalkToQuestGiver));
_QuestNPC.RemoveQuestToGive(MethodBase.GetCurrentMethod().DeclaringType);
}
protected static void TalkToQuestGiver(DOLEvent e, object sender, EventArgs args)
{
//We get the player from the event arguments and check if he qualifies
GamePlayer player = ((SourceEventArgs)args).Source as GamePlayer;
if (player == null)
return;
TalkToQuestGiver(player, _QuestNPC, MethodBase.GetCurrentMethod().DeclaringType, e);
}
/// <summary>
/// Callback for player accept/decline action.
/// </summary>
/// <param name="e"></param>
/// <param name="sender"></param>
/// <param name="args"></param>
protected static void HandleQuestEvent(DOLEvent e, object sender, EventArgs args)
{
QuestEventArgs qargs = args as QuestEventArgs;
if (qargs == null)
return;
if (qargs.Source.Name != _QuestNPC.Name)
return;
HandleQuestEvent(qargs.Player, _QuestNPC, MethodBase.GetCurrentMethod().DeclaringType, e);
}
public virtual void Init(GamePlayer player)
{
Level = 1;
QuestGiver = QuestNPC;
Rewards.MoneyPercent = 1;
Rewards.Experience = 0;
if (player != null)
{
AddInteractStep(1, m_wildOats.Name, 3, m_wildOats, "You collect some oats.");
AddInteractStep(2, m_rustyDagger.Name, 3, m_rustyDagger, "You pick up a rusty dagger.");
AddGoal("Collect " + m_wildOats.Name, QuestGoal.GoalType.ScoutMission, 3, m_wildOats);
log.Debug("added goal oats");
if (Step > 1)
{
AddGoal("Collect " + m_rustyDagger.Name, QuestGoal.GoalType.ScoutMission, 3, m_rustyDagger);
log.Debug("added goal daggers");
if (Step > 2)
{
AddGoal("Talk to " + _QuestNPCName + " to finish this quest.", QuestGoal.GoalType.ScoutMission, 1, null);
log.Debug("added goal return talk");
}
}
}
}
protected override void OnObjectInteract(QuestStepInteraction info)
{
Goals[Step - 1].Advance();
if (Goals[Step - 1].IsAchieved)
{
Step++;
if (Step == 2)
{
AddGoal("Collect " + m_rustyDagger.Name, QuestGoal.GoalType.ScoutMission, 3, m_rustyDagger);
log.Debug("added goal daggers");
}
else if (Step == 3)
{
AddGoal("Talk to " + _QuestNPCName + " to finish this quest.", QuestGoal.GoalType.ScoutMission, 1, null);
log.Debug("added goal return talk");
}
}
}
/// <summary>
/// This method checks if a player qualifies for this quest
/// </summary>
/// <returns>true if qualified, false if not</returns>
public override bool CheckQuestQualification(GamePlayer player)
{
// We're not going to offer this quest if the player is already on it...
if (player.IsDoingQuest(this.GetType()) != null)
return false;
return true;
}
protected static void TalkToQuestGiver(GamePlayer player, GameNPC npc, Type questClass, DOLEvent e)
{
SampleInteractQuest quest = player.IsDoingQuest(questClass) as SampleInteractQuest;
npc.TurnTo(player);
if (e == GameObjectEvent.Interact)
{
if (quest == null)
{
quest = new SampleInteractQuest();
if (quest == null)
{
log.Error("Activator.CreateInstance failed to create instance of type " + questClass.FullName);
return;
}
quest.OfferQuest(player);
}
else if (quest.Step == 3)
{
RemoveAllItem(npc, player, m_wildOats, true);
RemoveAllItem(npc, player, m_rustyDagger, true);
npc.SayTo(player, "Terrific, you are done!");
quest.FinishQuest();
}
}
}
protected static void HandleQuestEvent(GamePlayer player, GameNPC npc, Type questClass, DOLEvent e)
{
if (player == null)
return;
if (e == GamePlayerEvent.AcceptQuest)
{
if (player.IsDoingQuest(questClass) != null)
return;
if (npc.CanGiveQuest(questClass, player) <= 0)
return;
if (npc.GiveQuest(questClass, player, 1))
{
SampleInteractQuest quest = player.IsDoingQuest(questClass) as SampleInteractQuest;
}
}
}
public override void AbortQuest()
{
GamePlayer player = QuestPlayer;
base.AbortQuest();
if (player == null || QuestNPC == null)
return;
RemoveAllItem(null, player, m_wildOats, true);
RemoveAllItem(null, player, m_rustyDagger, true);
player.Out.SendNPCsQuestEffect(QuestNPC, QuestNPC.CanGiveOneQuest(player));
SendSystemMessage(player, "Aborting Quest " + Name + ".");
}
}
Return to “%s” DOL Code Contributions
Users browsing this forum: No registered users and 1 guest