Exemplo n.º 1
0
        /// <summary>
        /// Deserialisation
        /// changed: 24.09.05
        /// </summary>
        public void Deserialisation(GenericReader gr)
        {
            int version = gr.ReadInt();

            switch (version)
            {
            case 0:                     // version = 0;
            {
                // Delivery obj
                int nDel = gr.ReadInt();
                if (nDel > 0)
                {
                    for (int t = 0; t < nDel; t++)
                    {
                        int _id     = gr.ReadInt();
                        int _amount = gr.ReadInt();
                        delivery.Add(_id, _amount);
                    }
                }
                // Npc obj
                int nNpc = gr.ReadInt();
                if (nNpc > 0)
                {
                    for (int t = 0; t < nNpc; t++)
                    {
                        int _id     = gr.ReadInt();
                        int _amount = gr.ReadInt();
                        npcobj.Add(_id, _amount);
                    }
                }
                // Areas
                int nAreas = gr.ReadInt();
                if (nAreas > 0)
                {
                    for (int t = 0; t < nAreas; t++)
                    {
                        areas.Add(gr.ReadInt());
                    }
                }
                // init section
                activeQuest = World.CreateQuestById(gr.ReadInt());
                completed   = gr.ReadBool();
                break;
            }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// BaseQuest[] for npcId
 /// </summary>
 public static BaseQuest[] GetQuestsFor(int npcId)
 {
     if (_NPCQuests.ContainsKey(npcId))
     {
         if (_NPCQuests[npcId] is BaseQuest[])
         {
             return((BaseQuest[])_NPCQuests[npcId]);                      //optimized
         }
         else if (_NPCQuests[npcId] is ArrayList)
         {
             ArrayList quests = new ArrayList();
             foreach (int qId in (_NPCQuests[npcId] as ArrayList))
             {
                 BaseQuest bq = World.CreateQuestById(qId);
                 if (bq != null)
                 {
                     quests.Add(bq);
                 }
             }
             return((BaseQuest[])quests.ToArray(typeof(BaseQuest)));                        //support un optimized
         }
     }
     return(new BaseQuest[] {});
 }
Exemplo n.º 3
0
        /// <summary>
        /// total reinitialisation, check and fill quests to arrays
        /// </summary>
        public static void Init()
        {
            // second initialisation exclude
            if (status != InitStatus.None || World.Loading)
            {
                return;
            }
            status = InitStatus.Started;

            bool haveExeption = false;
            bool haveWarns    = false;

            try             // strongly recomended to use (for exclude server crush if uncorrect scripts)
            {
                BaseQuest[]    allQuests    = GetAllQuestsInWorld();
                BaseCreature[] allCreatures = GetAllCreaturesInWorld();

                //sort all Creatures by ID
                Hashtable SortedCreatures = new Hashtable();
                foreach (BaseCreature bc in allCreatures)
                {
                    if (!SortedCreatures.ContainsKey(bc.Id))
                    {
                        SortedCreatures.Add((int)bc.Id, bc);
                    }
                    else
                    {
                        if (bc.Id > 0)
                        {
                            string text  = string.Format("* {0} is already have ( [{2}].Id = {1} )", bc.GetType().Name, bc.Id, ((BaseCreature)(SortedCreatures[bc.Id])).GetType().Name);
                            string data1 = string.Format("\t> Check this creatureId \"{0}\" in each script", bc.Id);
                            AddErr(text, data1);
                        }
                    }
                    if (bc.Quests != null && (bc.GetType().Name != "BaseNPC") && bc.Quests.Length > 0)
                    {
                        string text  = string.Format("* {0} already have Quests line", bc.GetType().Name);
                        string data1 = string.Format("\t> Need remove/remark this line \"Quests = new ...\"");
                        string data2 = string.Format("\t-> remark mean \"//Quests = new ...\"");
                        AddErr(text, data1, data2);
                    }
                }
                // some text output
                if (errors.Count > 0)
                {
                    errors.Insert(0, "");
                    errors.Insert(0, "Start checking Creatures [Server.Creatures]");
                    AddErrHeader("");
                    AddErrHeader("Start checking Quests [Server.Quests]");
                    AddErrHeader("");
                    haveWarns = true;
                }
                // checking and fill quest arrays
                foreach (BaseQuest bq in allQuests)
                {
                    CheckQuest(SortedCreatures, bq.NPCId, bq, true, "NPCId");                       //checks NPC Id
                    CheckQuest(SortedCreatures, bq.NPCTargetId, bq, false, "NpcTargetId");          //checks Target Id

                    if (!bq.QuestIsBugged)
                    {
                        if (bq.PreviousQuest > 0 && !QuestExists(bq.PreviousQuest))                             //checks PreviousQuest
                        {
                            string text  = string.Format("* {0} have bad link to PreviousQuest (prev quest is not exist)", bq.GetType().Name);
                            string data1 = string.Format("\t> Try do quest by number {0}", bq.PreviousQuest);
                            string data2 = string.Format("\t> Or comment this line \"previousQuest = {0};\"", bq.PreviousQuest);
                            AddErr(text, data1, data2);
                        }
                        if (bq.NextQuest > 0 && !QuestExists(bq.NextQuest))                            //checks NextQuest
                        {
                            string text  = string.Format("* {0} have bad link to NextQuest (next quest is not exist)", bq.GetType().Name);
                            string data1 = string.Format("\t> Try do quest by number {0}", bq.NextQuest);
                            string data2 = string.Format("\t> Or comment this line \"nextQuest = {0};\"", bq.NextQuest);
                            AddErr(text, data1, data2);
                        }
                        if (bq.QuestFlags == 0)                           //checks for bad questflag
                        {
                            string text  = string.Format("* {0} have bad questFlags ( value is 0 )", bq.GetType().Name);
                            string data1 = string.Format("\t> Try change value to \"questFlags = 0x20;\"");
                            AddErr(text, data1);
                        }
                    }
                }
                // some text output
                if (errors.Count > 0 && !haveWarns)
                {
                    errors.Insert(0, "");
                    errors.Insert(0, "Start checking Quests [Server.Quests]");
                }
                // optimisations (this operation allow use this code convertions only one time and then free some processor time )
                // int[] -> BaseQuest[] for each NPC
                Hashtable tmp = new Hashtable();
                foreach (int cId in _NPCQuests.Keys)
                {
                    ArrayList list   = (ArrayList)_NPCQuests[cId];
                    ArrayList quests = new ArrayList();
                    foreach (int qId in list)
                    {
                        BaseQuest bq = World.CreateQuestById(qId);
                        if (bq != null)
                        {
                            quests.Add(bq);
                        }
                    }
                    tmp.Add(cId, (BaseQuest[])quests.ToArray(typeof(BaseQuest)));
                }
                _NPCQuests.Clear();
                _NPCQuests = tmp;
                //End Of Optimisations
            }
            catch (Exception e)
            {
                haveExeption = true;
                AddErrHeader("");
                AddErrHeader("Exeption: {0}", e);
                AddErrHeader("");
                AddErrHeader("message: {0}", e.Message);
                AddErrHeader("source: {0}", e.Source);
                AddErrHeader("stack trace: {0}", e.StackTrace);
                AddErrHeader("inner exeption: {0}", e.InnerException);
                AddErrHeader("target site: {0}", e.TargetSite);
                AddErrHeader("help link: {0}", e.HelpLink);
            }
            finally
            {
            }

            // each NPC can use this section after initialisations
            if (!haveExeption)
            {
                status = InitStatus.Done;                              // if have exeprion - not allow use quests
            }
        }