Beispiel #1
0
        public void GetNewQuest(int serverMessageIndex = -1) // Generates a new quest and sends it to all clients
        {
            if (!NetworkServer.active || Questing.ClientMessage.Instances.Count > Questing.Config.questAmountMax)
            {
                return;
            }


            // Attemots to get a new quest
            Questing.ClientMessage message;
            try
            {
                message = Questing.Quest.GetQuest(serverMessageIndex);
            }
            catch {
                if (Core.debugMode) {
                    Debug.LogError("RPGMOD: Error when obtaining quest");
                }
                message = new Questing.ClientMessage();
            }

            // If the quest has the default description it is deemed bad to send
            if (message.description != "bad")
            {
                QuestCooldown = Run.instance.GetRunStopwatch();
                message.SendToAll();
            }
        }
Beispiel #2
0
        public void Update()
        {
            if (GameStarted)
            {
                if (Questing.Config.questingEnabled)
                {
                    ManageQuests();
                }

                // Debug Keys
                if (Core.debugMode)
                {
                    if (Input.GetKeyDown(KeyCode.F3))
                    {
                        GetNewQuest();
                    }

                    if (Input.GetKeyDown(KeyCode.F4))
                    {
                        Questing.ClientMessage message = Questing.ClientMessage.Instances.Last();
                        message.active = false;
                        message.SendToAll();
                    }
                }
            }

            // Reload config key
            if (Input.GetKeyDown(KeyCode.F6))
            {
                Questing.Config.Load(Config, true);
                ResetUI();
            }
        }
Beispiel #3
0
        public void OnQuestRecieved(NetworkMessage networkMessage) // Runs when a quest is recieved
        {
            Questing.ClientMessage message = networkMessage.ReadMessage<Questing.ClientMessage>();

            // Checks through unique id the specific index that the message relates to
            int messageIndex = -1;
            int i = 0;
            while (i < Questing.ClientMessage.Instances.Count)
            {
                // Check unique id for match
                if (Questing.ClientMessage.Instances[i].id == message.id)
                {
                    messageIndex = i;
                    break;
                };
                i++;
            }

            if (messageIndex == -1)
            {
                messageIndex = Questing.ClientMessage.Instances.Count;
            }

            //

            if (Core.debugMode)
            {
                Debug.Log("Message recieved at " + messageIndex);
                Debug.Log(Questing.UI.Instances.Count);
                Debug.Log(Questing.ClientMessage.Instances.Count);
                Debug.Log(Questing.ServerMessage.Instances.Count);
            }

            if (message.advancingStage) {
                DestroyUIInstances();
            }

            // Updates the decscription displayed for the quest
            if (message.active && Questing.UI.Instances[messageIndex] != null)
            {
                Questing.UI.Instances[messageIndex].QuestDataDescription = message.description;
            }

            // Removes the message
            if (!message.active && messageIndex < Questing.ClientMessage.Instances.Count)
            {
                Questing.ClientMessage.Instances.RemoveAt(messageIndex);
                if (!message.advancingStage)
                {
                    Destroy(Questing.UI.Instances[messageIndex]);
                    Questing.UI.Instances.RemoveAt(messageIndex);

                    for (int j = messageIndex; j < Questing.UI.Instances.Count; j++)
                    {
                        Questing.UI.Instances[j].Index = j;
                    }
                }

                if (NetworkServer.active)
                {
                    Core.usedIDs.Remove(message.id);
                    Core.usedTypes[((Questing.Type)int.Parse(message.description.Split(',')[0]))] -= 1;

                    if (message.advancingStage && !Questing.Config.restartQuestsOnStageChange)
                    {
                        if (Core.debugMode)
                        {
                            Debug.Log("SOFT removal at " + messageIndex);
                        }
                    }
                    else
                    {
                        Questing.ServerMessage.Instances.RemoveAt(messageIndex);
                        if (Core.debugMode)
                        {
                            Debug.Log("HARD removal at " + messageIndex);
                        }
                    }

                }
            }
            // Updates the existing client message
            else if (messageIndex < Questing.ClientMessage.Instances.Count)
            {
                Questing.ClientMessage.Instances[messageIndex] = message;
            }
            // Adds a client message
            else
            {
                message.RegisterInstance();
                Questing.ClientMessage.Instances.Last().active = true;
                if (Core.debugMode)
                {
                    Debug.Log("Adding new message");
                }
            }

            if (Core.debugMode)
            {
                Debug.Log(message.active);
            }
        }