Example #1
0
 public static void QuestReturn(int index, QuestReturn qr, int quest_Log_ID)
 {
     try
     {
         ByteBuffer.ByteBuffer buffer = new ByteBuffer.ByteBuffer();
         BuildBasePacket((int)ClientSendPacketNumbers.QuestReturn, ref buffer);
         buffer.WriteString(DateTime.Now.ToString("yyyy-MM-dd-HH:mm:ss"));
         if (qr.Null)
         {
             buffer.WriteByte(1);
         }
         else
         {
             buffer.WriteByte(0);
             buffer.WriteInteger((int)qr.Status);
             buffer.WriteInteger(qr.Quest_ID);
             buffer.WriteInteger(quest_Log_ID);
             buffer.WriteInteger(qr.NPC_ID);
             buffer.WriteString(qr.Title);
             buffer.WriteString(qr.Text);
             buffer.WriteInteger(World.instance.GetQuestLog(Network.instance.Clients[index].Character_ID, qr.Quest_ID).ObjectiveProgress);
             buffer.WriteInteger(qr.Target);
         }
         Log.log("Sending Quest Return packet to client..", Log.LogType.SENT);
         sendData(ConnectionType.CLIENT, ClientSendPacketNumbers.QuestReturn.ToString(), index, buffer.ToArray());
     }
     catch (Exception e)
     {
         Log.log("Building Quest Return packet failed. > " + e.Message, Log.LogType.ERROR);
         return;
     }
 }
Example #2
0
        private static void RequestQuest(ConnectionType type, int index, byte[] data)
        {
            ByteBuffer.ByteBuffer buffer = new ByteBuffer.ByteBuffer();
            buffer.WriteBytes(data);
            ReadHeader(ref buffer);
            int Character_ID = buffer.ReadInteger();
            int NPC_ID       = buffer.ReadInteger();

            if (MathF.Distance(World.instance.players[Character_ID], World.instance.GetNPCByEntityID(NPC_ID)) <= World.InteractionDistance)
            {
                World.instance.UpdateQuestLog(Character_ID);
                bool        Create = false;
                QuestReturn qr     = World.instance.GetQuestContentByNPCEntityID(Character_ID, NPC_ID, out Create);
                Quest_Log   ql     = null;
                if (Create)
                {
                    ql = new Quest_Log(-1, Character_ID, qr.Quest_ID, QuestStatus.Available, 0);
                    World.instance.quest_log.Add(ql);
                    SendData.CreateQuestLog(ql);
                }
                else
                {
                    ql = World.instance.GetQuestLog(Character_ID, qr.Quest_ID);
                }
                if (ql != null)
                {
                    SendData.QuestReturn(index, qr, ql.Quest_Log_ID);
                }
            }
        }
Example #3
0
        public QuestReturn GetQuestContentByNPCEntityID(int Character_ID, int NPC_Entity_ID, out bool Create)
        {
            World.instance.UpdateQuestLog(Character_ID);
            QuestReturn  result        = new QuestReturn(true, QuestStatus.None, -1, -1, "", "", -1);
            NPC          Subject       = GetNPCByEntityID(NPC_Entity_ID);
            List <Quest> NPCQuests     = GetNPCQuests(Subject.NPC_ID);
            List <int>   Quests_In_log = new List <int>();

            foreach (Quest_Log ql in quest_log)
            {
                if (ql.Character_ID == Character_ID)
                {
                    //if (GetNPCEntityID(quests[ql.Quest_ID].NPC_Start_ID) == NPC_Entity_ID)
                    //{
                    if (GetNPCEntityID(quests[ql.Quest_ID].NPC_Start_ID) == NPC_Entity_ID ||
                        GetNPCEntityID(quests[ql.Quest_ID].NPC_End_ID) == NPC_Entity_ID)
                    {
                        if (ql.Status == QuestStatus.Available)
                        {
                            result.Null     = false;
                            result.Status   = ql.Status;
                            result.NPC_ID   = GetNPCEntityID(quests[ql.Quest_ID].NPC_Start_ID);
                            result.Quest_ID = ql.Quest_ID;
                            result.Target   = quests[ql.Quest_ID].Objective_Target;
                            result.Text     = quests[ql.Quest_ID].Start_Text;
                            result.Title    = quests[ql.Quest_ID].Title;
                        }
                        else if (ql.Status == QuestStatus.InProgress)
                        {
                            if (result.Status != QuestStatus.Available)
                            {
                                result.Null     = false;
                                result.Status   = ql.Status;
                                result.NPC_ID   = GetNPCEntityID(quests[ql.Quest_ID].NPC_Start_ID);
                                result.Quest_ID = ql.Quest_ID;
                                result.Target   = quests[ql.Quest_ID].Objective_Target;
                                result.Text     = quests[ql.Quest_ID].Start_Text;
                                result.Title    = quests[ql.Quest_ID].Title;
                            }
                        }
                        //}
                        //if (GetNPCEntityID(quests[ql.Quest_ID].NPC_End_ID) == NPC_Entity_ID)
                        //{
                        if (ql.Status == QuestStatus.Finished)
                        {
                            if (result.Status != QuestStatus.Available)
                            {
                                result.Null     = false;
                                result.Status   = ql.Status;
                                result.NPC_ID   = GetNPCEntityID(quests[ql.Quest_ID].NPC_End_ID);
                                result.Quest_ID = ql.Quest_ID;
                                result.Target   = quests[ql.Quest_ID].Objective_Target;
                                result.Text     = quests[ql.Quest_ID].End_Text;
                                result.Title    = quests[ql.Quest_ID].Title;
                            }
                        }
                        else if (ql.Status == QuestStatus.Complete)
                        {
                            if (result.Status != QuestStatus.Available)
                            {
                                result.Null     = false;
                                result.Status   = ql.Status;
                                result.NPC_ID   = GetNPCEntityID(quests[ql.Quest_ID].NPC_End_ID);
                                result.Quest_ID = ql.Quest_ID;
                                result.Target   = quests[ql.Quest_ID].Objective_Target;
                                result.Text     = quests[ql.Quest_ID].End_Text;
                                result.Title    = quests[ql.Quest_ID].Title;
                            }
                        }
                    }
                    //}
                }
            }
            if (result.Status == QuestStatus.None)
            {
                List <Quest> AvailableQuests = GetAvailableQuests(Character_ID);
                foreach (Quest q in AvailableQuests)
                {
                    if (GetNPCEntityID(q.NPC_End_ID) == NPC_Entity_ID || GetNPCEntityID(q.NPC_Start_ID) == NPC_Entity_ID)
                    {
                        bool found = false;
                        for (int i = 0; i < Quests_In_log.Count; i++)
                        {
                            if (q.ID == Quests_In_log[i])
                            {
                                found = true;
                            }
                        }
                        if (!found)
                        {
                            result.Null     = false;
                            result.Status   = QuestStatus.Available;
                            result.NPC_ID   = NPC_Entity_ID;
                            result.Quest_ID = q.ID;
                            result.Target   = quests[q.ID].Objective_Target;
                            result.Text     = quests[q.ID].End_Text;
                            result.Title    = quests[q.ID].Title;
                            Create          = true;
                            return(result);
                        }
                    }
                }
            }

            Create = false;
            return(result);
        }
Example #4
0
        private static void QuestInteract(ConnectionType type, int index, byte[] data)
        {
            ByteBuffer.ByteBuffer buffer = new ByteBuffer.ByteBuffer();
            buffer.WriteBytes(data);
            ReadHeader(ref buffer);
            int Character_ID = buffer.ReadInteger();
            int NPC_ID       = buffer.ReadInteger();

            if (MathF.Distance(World.instance.players[Character_ID], World.instance.GetNPCByEntityID(NPC_ID)) <= World.InteractionDistance)
            {
                World.instance.UpdateQuestLog(Character_ID);
                bool        Create = false;
                QuestReturn qr     = World.instance.GetQuestContentByNPCEntityID(Character_ID, NPC_ID, out Create);
                Quest_Log   ql     = null;
                ql = World.instance.GetQuestLog(Character_ID, qr.Quest_ID);
                if (qr.Null != true && ql != null)
                {
                    switch (qr.Status)
                    {
                    case QuestStatus.None:
                        break;

                    case QuestStatus.InProgress:
                        if (ql.ObjectiveProgress >= qr.Target)
                        {
                            World.instance.GetQuestLog(Character_ID, qr.Quest_ID).Status = QuestStatus.Finished;
                            qr = World.instance.GetQuestContentByNPCEntityID(Character_ID, NPC_ID, out Create);
                            SendData.QuestInteractConfirm(index, true, ql.Status, qr.NPC_ID, ql.Quest_ID);
                            SendData.UpdateQuestLog(ql);
                        }
                        else
                        {
                            SendData.QuestInteractConfirm(index, false);
                        }
                        break;

                    case QuestStatus.Complete:
                        SendData.QuestInteractConfirm(index, false);
                        break;

                    case QuestStatus.Finished:
                        World.instance.GetQuestLog(Character_ID, qr.Quest_ID).Status = QuestStatus.Complete;
                        qr = World.instance.GetQuestContentByNPCEntityID(Character_ID, NPC_ID, out Create);
                        SendData.QuestInteractConfirm(index, true, ql.Status, qr.NPC_ID, ql.Quest_ID);
                        SendData.UpdateQuestLog(ql);
                        if (World.instance.players.ContainsKey(Character_ID))
                        {
                            World.instance.players[Character_ID].experience += World.instance.quests[ql.Quest_ID].Experience;
                        }
                        // Get the next quest in the series
                        List <Quest> q = World.instance.GetAvailableQuests(Character_ID);
                        if (q != null && q.Count > 0)
                        {
                            foreach (Quest qu in q)
                            {
                                // Create a new quest log for it
                                Quest_Log newql = new Quest_Log(-1, Character_ID, qu.ID, QuestStatus.Available, 0);
                                // Update the synchronization server
                                SendData.CreateQuestLog(newql);
                                // Notify the client that a new quest is available
                                SendData.UpdateQuestLog(index, qu.ID, newql.Quest_Log_ID, World.instance.GetNPCEntityID(qu.NPC_Start_ID), newql.Status, newql.ObjectiveProgress, qu.Objective_Target);
                            }
                        }
                        break;

                    case QuestStatus.Available:
                        if (qr.Target == -1)
                        {
                            World.instance.GetQuestLog(Character_ID, qr.Quest_ID).Status = QuestStatus.Finished;
                            qr = World.instance.GetQuestContentByNPCEntityID(Character_ID, NPC_ID, out Create);
                            World.instance.UpdateQuestLog(Character_ID);
                        }
                        else
                        {
                            World.instance.GetQuestLog(Character_ID, qr.Quest_ID).Status = QuestStatus.InProgress;
                            qr = World.instance.GetQuestContentByNPCEntityID(Character_ID, NPC_ID, out Create);
                            World.instance.UpdateQuestLog(Character_ID);
                        }
                        SendData.QuestInteractConfirm(index, true, ql.Status, qr.NPC_ID, ql.Quest_ID);
                        SendData.UpdateQuestLog(ql);
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    SendData.QuestInteractConfirm(index, false);
                }
            }
            else
            {
                SendData.QuestInteractConfirm(index, false);
            }
            World.instance.UpdateQuestLog(Character_ID);
        }