예제 #1
0
        public int CheckQuest(Character Target)
        {
            int count = OnCheckQuest(Target.id);

            if (IsWaypointsCleared == true)
            {
                int i = 0;
                SMSG_SENDNAVIGATIONPOINT spkt2 = new SMSG_SENDNAVIGATIONPOINT();
                spkt2.SessionId = Target.id;
                spkt2.QuestID   = this.QuestId;
                foreach (ObjectiveList.Waypoint waypoint in QuestBase.UserGetWaypoints(Target, this.QuestId))
                {
                    Predicate <MapObject> IsNpc = delegate(MapObject match)
                    {
                        return(match.ModelId == waypoint.NpcId);
                    };

                    MapObject myObject = Target.currentzone.Regiontree.SearchActor(IsNpc, SearchFlags.Npcs);
                    if (myObject != null)
                    {
                        i++;
                        spkt2.AddPosition(waypoint.NpcId, myObject.Position.x, myObject.Position.y, myObject.Position.z);
                    }
                }
                if (i > 0)
                {
                    Target.client.Send((byte[])spkt2);
                    IsWaypointsCleared = false;
                }
            }
            return(count);
        }
예제 #2
0
        /// <title>Saga.AddStep</title>
        /// <code>
        /// Saga.AddStep(cid, QuestID, StepId, State);
        /// </code>
        /// <description>
        /// Adds a step to the quest. This can only be done during initialisation.
        /// 0 = Hidden, 1 = Visible, 2 = Completed
        /// </description>
        /// <example>
        ///function QUEST_START(cid)
        ///     -- Initialize all quest steps
        ///     -- Initialize all starting navigation points
        ///
        ///     Saga.AddStep(cid, QuestID, 101, 1);
        ///     Saga.AddStep(cid, QuestID, 102, 0);
        ///     Saga.AddStep(cid, QuestID, 103, 0);
        ///	    Saga.InsertQuest(cid, QuestID, 1);
        ///
        ///     return 0;
        ///end
        /// </example>
        public static void AddStep(uint CID, uint QID, uint StepID)
        {
            Character Character;

            if (LifeCycle.TryGetById(CID, out Character))
            {
                List <Saga.Quests.Objectives.ObjectiveList.StepInfo> Steps = QuestBase.GetSteps(Character, QID);
                Steps.Add(new Saga.Quests.Objectives.ObjectiveList.StepInfo(0, QID, StepID));
            }
        }
예제 #3
0
        public static bool UserTalktoTarget(uint NpcId, Character Target, QuestBase Quest)
        {
            try
            {
                Quest.CheckQuest(Target);
                if (true)
                {
                    /*
                     * //Predicate to remove the activated npc
                     * Predicate<ObjectiveList.Activation> FindActivatedNpc =
                     *  delegate(ObjectiveList.Activation objective)
                     * {
                     *  return objective.NpcId == NpcId && objective.Quest == Quest.QuestId;
                     * };
                     */


                    //Target.QuestObjectives.ActivatedNpc.RemoveAll(FindActivatedNpc);

                    /*
                     * MapObject myObject = Target.currentzone.Regiontree.SearchActor(IsNpc, Target, SearchFlags.Npcs);
                     * if (myObject != null)
                     * {
                     *  BaseMob temp = myObject as BaseMob;
                     * }*/

                    /**/

                    Regiontree tree = Target.currentzone.Regiontree;
                    foreach (MapObject a in tree.SearchActors(Target, SearchFlags.Npcs))
                    {
                        if (a.ModelId == NpcId)
                        {
                            BaseMob mob = a as BaseMob;
                            if (mob != null)
                            {
                                Common.Actions.UpdateIcon(Target, mob);
                            }
                        }
                    }

                    return(true);
                }
            }
            catch (QuestFailedException)
            {
                //Do nothing here
                return(false);
            }
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        public static uint GetCurrentStep(uint cid, uint QID)
        {
            Character character;

            if (LifeCycle.TryGetById(cid, out character))
            {
                if (character.QuestObjectives[QID] != null)
                {
                    List <Saga.Quests.Objectives.ObjectiveList.StepInfo> steps =
                        QuestBase.GetSteps(character, QID);
                    foreach (Saga.Quests.Objectives.ObjectiveList.StepInfo c in steps)
                    {
                        if (c.State == 1)
                        {
                            return(c.StepId);
                        }
                    }
                }
            }

            return(0);
        }
예제 #5
0
        public static void InvalidateQuest(QuestBase Quest, Character Target)
        {
            List <ObjectiveList.Waypoint> removedpoints = new List <ObjectiveList.Waypoint>();

            Predicate <ObjectiveList.Elimination> FindElimintation =
                delegate(ObjectiveList.Elimination Objective)
            {
                return(Objective.Quest == Quest.QuestId);
            };

            Predicate <ObjectiveList.Loot> FindLootObjective =
                delegate(ObjectiveList.Loot Objective)
            {
                return(Objective.Quest == Quest.QuestId);
            };

            Predicate <ObjectiveList.Position> FindPoint =
                delegate(ObjectiveList.Position Objective)
            {
                return(Objective.Quest == Quest.QuestId);
            };

            Predicate <ObjectiveList.Activation> ActivatedNpc =
                delegate(ObjectiveList.Activation Objective)
            {
                return(Objective.Quest == Quest.QuestId);
            };

            Predicate <ObjectiveList.SubStep> FindSubsteps =
                delegate(ObjectiveList.SubStep Objective)
            {
                return(Objective.Quest == Quest.QuestId);
            };

            Predicate <ObjectiveList.Waypoint> FindGuidancePoints =
                delegate(ObjectiveList.Waypoint Objective)
            {
                bool isQuest = Objective.Quest == Quest.QuestId;
                if (isQuest)
                {
                    removedpoints.Add(Objective);
                }
                return(isQuest);
            };

            Predicate <ObjectiveList.Loot2> FindNonDiscardableItems =
                delegate(ObjectiveList.Loot2 objective)
            {
                return(objective.Quest == Quest.QuestId);
            };

            Target.QuestObjectives.Elimintations.RemoveAll(FindElimintation);
            Target.QuestObjectives.ActivatedNpc.RemoveAll(ActivatedNpc);
            Target.QuestObjectives.LootObjectives.RemoveAll(FindLootObjective);
            Target.QuestObjectives.Points.RemoveAll(FindPoint);
            Target.QuestObjectives.Substeps.RemoveAll(FindSubsteps);
            Target.QuestObjectives.Steps.Remove(Quest.QuestId);
            Target.QuestObjectives.NonDiscardableItems.RemoveAll(FindNonDiscardableItems);
            Target.QuestObjectives.GuidancePoints.RemoveAll(FindGuidancePoints);

            foreach (ObjectiveList.Waypoint objective in removedpoints)
            {
                Regiontree tree = Target.currentzone.Regiontree;
                foreach (MapObject a in tree.SearchActors(Target, SearchFlags.Npcs))
                {
                    BaseMob mob = a as BaseMob;
                    if (a.ModelId == objective.NpcId && mob != null)
                    {
                        Common.Actions.UpdateIcon(Target, mob);
                    }
                }
            }
        }
예제 #6
0
        /// <title>Saga.StepComplete</title>
        /// <code>
        /// Saga.StepComplete(cid, QuestID, StepId);
        /// </code>
        /// <description>
        /// Completes a quest
        /// </description>
        /// <example>
        /// function QUEST_STEP_2(cid)
        ///	    -- Talk to mischa
        ///     local NPCIndex = 1000;
        ///     local ret = Saga.GetNPCIndex(cid);
        ///
        ///     Saga.AddWaypoint(cid, QuestID, NPCIndex, -12092, -6490, -8284, 1);
        ///     if ret == NPCIndex then
        ///         Saga.StepComplete(cid, QuestID, 102);
        ///     else
        ///         return  -1;
        ///     end
        ///
        ///     Saga.ClearWaypoints(cid, QuestID);
        ///     return 0;
        /// end
        /// </example>
        public static void StepComplete(uint cid, uint QID, uint StepID)
        {
            Character characterTarget;
            List <Saga.Quests.Objectives.ObjectiveList.StepInfo> Steps;

            if (LifeCycle.TryGetById(cid, out characterTarget))
            {
                uint stepIndexies = 0;
                Steps = QuestBase.GetSteps(characterTarget, QID);
                IEnumerator <Saga.Quests.Objectives.ObjectiveList.StepInfo> i = Steps.GetEnumerator();
                while (i.MoveNext())
                {
                    if (i.Current.StepId == StepID)
                    {
                        i.Current.State = 2;
                        if (i.MoveNext())
                        {
                            if (i.Current.State == 0)
                            {
                                i.Current.State = 1;
                                stepIndexies    = i.Current.StepId;
                            }
                        }
                        break;
                    }
                }

                QuestBase.InvalidateStep(QID, StepID, characterTarget);
                if (characterTarget.QuestObjectives[QID] != null)
                {
                    SMSG_QUESTSTEPUPDATE spkt = new SMSG_QUESTSTEPUPDATE();
                    spkt.QuestID    = QID;
                    spkt.StepID     = StepID;
                    spkt.NextStepID = stepIndexies;
                    spkt.Progress   = 2;
                    spkt.SessionId  = characterTarget.id;
                    characterTarget.client.Send((byte[])spkt);
                    CommonFunctions.UpdateNpcIcons(characterTarget);
                }
            }

            /*
             *
             * QuestBase myQuest;
             * Character characterTarget;
             *
             * if (LifeCycle.TryGetById(cid, out characterTarget))
             * if (characterTarget.client.questlist.TryGetValue(QID, out myQuest))
             * {
             *      uint stepIndexies = 0;
             *      IEnumerator<StepInfo> i = myQuest.listofsteps.GetEnumerator();
             *      while (i.MoveNext())
             *          if (i.Current.StepID == StepID)
             *          {
             *              i.Current.Status = 2;
             *              if (i.MoveNext())
             *                  if (i.Current.Status == 0)
             *                  {
             *                      i.Current.Status = 1;
             *                      stepIndexies = i.Current.StepID;
             *                  }
             *              break;
             *          }
             *
             *      SMSG_QUESTSTEPUPDATE spkt = new SMSG_QUESTSTEPUPDATE();
             *      spkt.QuestID = QID;
             *      spkt.StepID = StepID;
             *      spkt.NextStepID = stepIndexies;
             *      spkt.Progress = 2;
             *      spkt.SessionId = characterTarget.id;
             *      characterTarget.client.Send((byte[])spkt);
             *      CommonFunctions.UpdateNpcIcons(characterTarget);
             * }
             * else if (characterTarget.client.pendingquest != null && characterTarget.client.pendingquest.QuestId == QID)
             * {
             *      uint stepIndexies = 0;
             *      IEnumerator<StepInfo> i = characterTarget.client.pendingquest.listofsteps.GetEnumerator();
             *      while (i.MoveNext())
             *      {
             *          if (i.Current.StepID == StepID)
             *          {
             *              i.Current.Status = 2;
             *
             *              if (i.MoveNext())
             *                  if (i.Current.Status == 0)
             *                  {
             *                      i.Current.Status = 1;
             *                      stepIndexies = i.Current.StepID;
             *                  }
             *              break;
             *          }
             *      }
             *  }
             *
             * //// Deactive
             * ///  All inactivated item mobs here
             *
             * List<LootObjective> d = new List<LootObjective>();
             * List<LootObjective> e = QuestBase.GetLootObjectives(QID, characterTarget);
             * foreach (LootObjective c in e)
             * {
             *  if (c.StepID == StepID)
             *  {
             *      d.Add(c);
             *  }
             * }
             * foreach (LootObjective c in d)
             * {
             *  e.Remove(c);
             * }
             *
             * foreach (MapObject c in characterTarget.ObjectsInSightrange)
             * {
             *  if (c.id >= ActorManager.PlayerBorder &&
             *         c.id < ActorManager.MapItemBorder)
             *  {
             *      Predicate<LootObjective> ActionObjectDeactivate = delegate(LootObjective f)
             *      {
             *          return f.NPCType == c.ModelId;
             *      };
             *
             *      if (d.Exists(ActionObjectDeactivate) == true)
             *      {
             *          MapItem item = c as MapItem;
             *          SMSG_ITEMUPDATE spkt = new SMSG_ITEMUPDATE();
             *          spkt.ActorID = c.id;
             *          spkt.Active1 = 0;
             *          spkt.Active = item.IsHighlighted(characterTarget);
             *          spkt.Active2 = item.IsInteractable(characterTarget);
             *          spkt.SessionId = characterTarget.id;
             *          characterTarget.client.Send((byte[])spkt);
             *      }
             *  }
             * }
             *
             */
        }
예제 #7
0
        /// <summary>
        /// Inserts a new quests into the questlist.
        /// </summary>
        public static void InsertQuest(uint cid, uint QID, byte slot)
        {
            QuestBase oldQuest;
            QuestBase newQuest;
            Character Character;


            if (LifeCycle.TryGetById(cid, out Character))
            {
                newQuest = Character.QuestObjectives[QID];
                if (newQuest == null)
                {
                    if (Singleton.Quests.TryFindQuests(QID, out newQuest))
                    {
                        if (slot == 1)
                        {
                            oldQuest = Character.QuestObjectives.OfficialQuest;
                            Character.QuestObjectives.OfficialQuest = newQuest;
                            newQuest.questtype = slot;
                        }
                        else if (slot == 2)
                        {
                            oldQuest = Character.QuestObjectives.PersonalQuest;
                            Character.QuestObjectives.PersonalQuest = newQuest;
                            newQuest.questtype = slot;
                        }


                        List <Saga.Quests.Objectives.ObjectiveList.StepInfo> Steps2 =
                            QuestBase.GetSteps(Character, QID);

                        if (Steps2.Count == 0)
                        {
                            newQuest.OnStart(Character.id);
                        }
                        if (Steps2.Count > 0)
                        {
                            newQuest.isnew  = true;
                            Steps2[0].State = 1;
                        }

                        SMSG_QUESTREMOVE spkt4 = Character.Tag as SMSG_QUESTREMOVE;
                        if (spkt4 != null)
                        {
                            Character.client.Send((byte[])spkt4);
                            Character.Tag = null;
                        }

                        // Send new Quest list
                        SMSG_QUESTINFO spkt3 = new SMSG_QUESTINFO();
                        spkt3.SessionId = Character.id;
                        foreach (QuestBase Quest in Character.QuestObjectives)
                        {
                            List <Saga.Quests.Objectives.ObjectiveList.StepInfo> Steps =
                                QuestBase.GetSteps(Character, Quest.QuestId);
                            spkt3.AddQuest(Quest.QuestId, (byte)Steps.Count);
                            for (int i = 0; i < Steps.Count; i++)
                            {
                                Saga.Quests.Objectives.ObjectiveList.StepInfo currentStep
                                    = Steps[i];
                                uint nextstep = (i + 1 < Steps.Count) ? Steps[i + 1].StepId : 0;
                                spkt3.AddQuestStep(currentStep.StepId, currentStep.State, nextstep, Quest.isnew);
                                if (Quest.isnew == true)
                                {
                                    Quest.isnew = false;
                                }
                            }
                        }
                        Character.client.Send((byte[])spkt3);

                        newQuest.CheckQuest(Character);

                        /*
                         * // Send waypoint contruction
                         * SMSG_SENDNAVIGATIONPOINT spkt2 = new SMSG_SENDNAVIGATIONPOINT();
                         * spkt2.SessionId = Character.id;
                         * spkt2.QuestID = QID;
                         * foreach (Saga.Quests.Objectives.ObjectiveList.Waypoint waypoint in QuestBase.UserGetWaypoints(Character, QID))
                         * {
                         *
                         *  //Predicate to search the npc
                         *  Predicate<MapObject> IsNpc = delegate(MapObject match)
                         *  {
                         *      return match.ModelId == waypoint.NpcId;
                         *  };
                         *
                         *  MapObject myObject = Character.currentzone.Regiontree.SearchActor(IsNpc, SearchFlags.Npcs);
                         *  if ( myObject != null )
                         *  {
                         *      spkt2.AddPosition(waypoint.NpcId, myObject.Position.x, myObject.Position.y, myObject.Position.z);
                         *      if ( Point.IsInSightRangeByRadius(Character.Position, myObject.Position))
                         *      {
                         *          BaseMob temp = (BaseMob)myObject;
                         *          Common.Actions.UpdateIcon(Character, temp);
                         *      }
                         *  }
                         * }
                         * Character.client.Send((byte[])spkt2);*/
                    }
                    else
                    {
                        Console.WriteLine("Quest not found");
                    }
                }
            }
            else
            {
                Trace.TraceError("Character not found");
            }
        }