Exemplo n.º 1
0
    public void SetUpAllEmails(EmailListJSON loadedEmails) // Called from XMLSaveLoad
    {
        foreach (EmailEntry email in loadedEmails.emailEntries)
        {
            if (email.entryID != "____") // Only continue if this is not a blank entry
            {
                allEmailsInData.Add(email);
                Debug.Log("loaded email entryID = " + email.entryID + " | conversationID = " + email.conversationID);

                // Make new EmailConversations if not already made
                if (emailConversationsDictionary.ContainsKey(email.conversationID) == false)
                {
                    EmailConversation newConversation = new EmailConversation();
                    newConversation.conversationID = email.conversationID;

                    emailConversationsDictionary.Add(newConversation.conversationID, newConversation);
                    Debug.Log("Created New Email Conversation: " + newConversation.conversationID);

                    // Add the initial email
                    newConversation.AddNextEmail(email);
                }

                // Check if player has received this email before. If so, add it to the conversation
                if (email.received)
                {
                    emailConversationsDictionary[email.conversationID].AddNextEmail(email);
                }

                // Find Max stage for each conversation
                emailConversationsDictionary[email.conversationID].CheckMaxStage(email.stage);
            }
        }

        CheckNotifications();
    }
Exemplo n.º 2
0
    /// <summary>
    /// currentEmail is the EmailEntry the player is replying to.
    /// playerReplyGBN is a single-character string g,b,or n
    /// </summary>
    /// <param name="currentEmail"></param>
    public void RecordPlayerReplyAndQueueNextEmail(EmailEntry currentEmail, string playerReplyGBN, string playerReplyFull)
    // Will run when player has replied to an email. Finds next Email, Packs it, sends to DeliveryMgr
    // NOTE: Has to queue TWO emails: The initial reply *and* the next item order (if there is one)
    {
        EmailConversation currentConversation = emailConversationsDictionary[currentEmail.conversationID];


        // -------------------- RECORD PLAYER RESPONSE --------------
        // Before Anything else, record the player's response. Important for saving and loading emails later
        currentEmail.playerReplyGBN = playerReplyGBN;
        currentEmail.replied        = true;

        EmailEntry playerReplyEmail = new EmailEntry();

        playerReplyEmail.conversationID = currentEmail.conversationID;
        playerReplyEmail.characterName  = "Player";
        playerReplyEmail.stage          = currentEmail.stage;
        playerReplyEmail.entryID        = currentEmail.conversationID + "_" + currentEmail.stage + "_" + "player";
        playerReplyEmail.bodyText       = playerReplyFull;
        playerReplyEmail.received       = true;
        playerReplyEmail.dateTime       = System.DateTime.Now.ToString("dddd MMM dd h:mm:ss tt");

        // Put player reply to allEmails List in the right spot
        int targetIndex = allEmailsInData.IndexOf(currentEmail) + 1;

        allEmailsInData.Insert(targetIndex, playerReplyEmail);

        // Add player reply to Conversation
        currentConversation.AddNextEmail(playerReplyEmail);



        // ----------------- FIND NEXT EMAIL ----------------
        // Find next emailID
        // Examples: davinta_0_normal_initial_n
        //davinta_0_normal_reply_g
        //davinta_0_normal_reply_b
        //davinta_0_normal_reply_n


        // Create the string to find the next emailID (The immediate reply to the player).
        string replyEmailID = currentEmail.conversationID + "_" + currentEmail.stage + "_" +
                              currentEmail.state + "_" + "reply" + "_" + playerReplyGBN;

        Debug.Log("Next NPC Reply EmailID = " + replyEmailID);

        // Create the email on disc, we will send it to Delivery Manager shortly
        EmailEntry replyEmail = GetEmailByID(replyEmailID);

        Debug.Log("Found reply email: " + replyEmail.entryID);


        // ---------------- QUEUE NEXT TIME EMAIL ---------------

        EmailEntry nextTimeEmail = new EmailEntry();
        string     nextEmailID   = currentEmail.conversationID + "_" + (currentEmail.stage + 1) + "_" +
                                   "normal" + "_" + "initial" + "_" + "n";

        if (currentConversation.stage < currentConversation.maxStage)
        {
            nextTimeEmail = GetEmailByID(nextEmailID);
        }


        // ---------------- SEND NEXT EMAILS TO DELIVERY MANAGER -----------

        // Immediate NPC Response Order
        Order emailOrder = new Order();

        emailOrder.myOrderType = Order.orderType.email;
        emailOrder.orderAmount = 1;
        emailOrder.orderID     = replyEmail.entryID;
        GetComponent <DelayedOrderManager>().AddNewOrder
            (emailOrder, 1, "You have a reply email from " + replyEmail.characterName); // 1 minute

        // Next time NPC Initial Email Order
        if (nextTimeEmail.entryID != null)
        {
            Order nextTimeEmailOrder = new Order();
            nextTimeEmailOrder.myOrderType = Order.orderType.email;
            nextTimeEmailOrder.orderAmount = 1;
            nextTimeEmailOrder.orderID     = nextTimeEmail.entryID;

            // Randomise delivery time between 1 - 6 hours (adjusted to 1 hour for development)
            int deliveryTime = 60;

            GetComponent <DelayedOrderManager>().AddNewOrder
                (nextTimeEmailOrder, deliveryTime, "You have a new email from " + replyEmail.characterName + "!"); // Six hours
        }
    }