Exemplo n.º 1
0
        public ViewResult MyDialogues()
        {
            ViewBag.UserAuth = User.Identity.IsAuthenticated;
            ViewBag.UserName = User.Identity.Name;

            User user1 = db.Users.Include(xc => xc.UserDialogues).ThenInclude(xc => xc.Dialogue).FirstOrDefault(x => x.Email == User.Identity.Name);

            List <Dialogue>    mainDialogues = new List <Dialogue>();
            List <UserAndRead> usersAndRead  = new List <UserAndRead>();
            var dialogues = user1.UserDialogues.Select(xc => xc.Dialogue).ToList();

            foreach (var d in dialogues)
            {
                mainDialogues.Add(db.Dialogues.Include(xc => xc.UserDialogues).ThenInclude(xc => xc.User).FirstOrDefault(x => x.DialogueId == d.DialogueId));
            }
            foreach (Dialogue d in mainDialogues)
            {
                UserDialogue ud     = d.UserDialogues.FirstOrDefault(x => x.UserId == user1.UserId);
                bool         IsRead = ud.IsRead;

                ud = d.UserDialogues.FirstOrDefault(x => x.UserId != user1.UserId);
                User user = ud.User;
                usersAndRead.Add(new UserAndRead {
                    User = user, IsRead = IsRead
                });
            }
            usersAndRead = usersAndRead.OrderBy(x => x.IsRead).ToList();
            return(View(usersAndRead));
        }
Exemplo n.º 2
0
        public static Werewolf CreateWerewolf(object userInput, Player player)
        {
            Werewolf selectedEnemyType = (Werewolf)userInput;
            var      state             = selectedEnemyType.Transformed ? IsTransformed.Transformed.ToString() : IsTransformed.NonTransformed.ToString(); // ToDo: this can be replaced by the enum instead of using strings

            UserDialogue.SelectedEnemy(state, selectedEnemyType.Name);

            if (selectedEnemyType.Transformed)
            {
                selectedEnemyType.Damage += 3;

                UserDialogue.DamageIncrease(selectedEnemyType.Damage);
            }

            UserDialogue.ShowEnemyStats(selectedEnemyType.Damage, selectedEnemyType.Armour, selectedEnemyType.HitPoints);
            return(selectedEnemyType);
        }
Exemplo n.º 3
0
        public static Ghost CreateGhost(object userInput, Player player)
        {
            Ghost selectedEnemyType = (Ghost)userInput;
            var   state             = selectedEnemyType.Angry ? GhostType.Angry.ToString() : GhostType.NotAngry.ToString();

            UserDialogue.SelectedEnemy(state, selectedEnemyType.Name);
            if (selectedEnemyType.Angry)
            {
                selectedEnemyType.Damage += 2;
                UserDialogue.DamageIncrease(selectedEnemyType.Damage);
            }
            else
            {
                selectedEnemyType.Damage -= 2;
                UserDialogue.DamageIncrease(selectedEnemyType.Damage);
            }
            UserDialogue.ShowEnemyStats(selectedEnemyType.Damage, selectedEnemyType.Armour, selectedEnemyType.HitPoints);
            return(selectedEnemyType);
        }
Exemplo n.º 4
0
        public IActionResult DialogueWith(string Text, int user2Id, int dialogueId)
        {
            if (Text.Length > 250)
            {
                Text = Text.Substring(250);
            }
            User    user1   = db.Users.Include(xc => xc.UserDialogues).ThenInclude(xc => xc.Dialogue).FirstOrDefault(x => x.Email == User.Identity.Name);
            Message message = new Message {
                Text = Text, Time = DateTime.UtcNow, Sender = user1
            };
            Dialogue     dialogue = db.Dialogues.Include(xc => xc.UserDialogues).FirstOrDefault(x => x.DialogueId == dialogueId);
            UserDialogue ud       = dialogue.UserDialogues.FirstOrDefault(x => x.UserId == user2Id);

            ud.IsRead = false;
            db.Update(ud);
            dialogue.Messages = new List <Message>();
            dialogue.Messages.Add(message);
            db.Update(dialogue);
            db.SaveChanges();
            return(RedirectToAction("DialogueWith", new { userId = user2Id }));
        }
Exemplo n.º 5
0
        public static Vampire CreateVampire(object userInput, Player player)
        {
            Vampire selectedEnemyType = (Vampire)userInput;
            var     state             = selectedEnemyType.Psychic ? VampireType.Psychic.ToString() : VampireType.Hybrid.ToString(); // ToDo: this can be replaced by the enum instead of using strings

            UserDialogue.SelectedEnemy(state, selectedEnemyType.Name);

            if (selectedEnemyType.Psychic)
            {
                selectedEnemyType.Damage += 3;

                UserDialogue.DamageIncrease(selectedEnemyType.Damage);
            }
            else if (selectedEnemyType.Hybrid)
            {
                selectedEnemyType.Armour += 3;
                UserDialogue.ArmorIncrease(selectedEnemyType.Armour);
            }

            UserDialogue.ShowEnemyStats(selectedEnemyType.Damage, selectedEnemyType.Armour, selectedEnemyType.HitPoints);
            return(selectedEnemyType);
        }
Exemplo n.º 6
0
        public ViewResult DialogueWith(int userId, int page = 1)
        {
            int pageSize = 100;

            ViewBag.UserAuth = User.Identity.IsAuthenticated;
            ViewBag.UserName = User.Identity.Name;

            User user1      = db.Users.Include(xc => xc.UserDialogues).ThenInclude(xc => xc.Dialogue).FirstOrDefault(x => x.Email == User.Identity.Name);
            User user2      = db.Users.Include(xc => xc.UserDialogues).ThenInclude(xc => xc.Dialogue).FirstOrDefault(x => x.UserId == userId);
            int  dialogueId = FindDialogueId(user1, user2);

            Dialogue       dialogue  = db.Dialogues.Include(xc => xc.Messages).ThenInclude(x => x.Sender).FirstOrDefault(x => x.DialogueId == dialogueId);
            Dialogue       dialogue2 = db.Dialogues.Include(xc => xc.UserDialogues).FirstOrDefault(x => x.DialogueId == dialogueId);
            List <Message> messages  = dialogue.Messages.OrderByDescending(x => x.Time).ToList();
            UserDialogue   ud        = dialogue2.UserDialogues.FirstOrDefault(x => x.UserId == user1.UserId);

            ud.IsRead = true;
            db.Update(ud);
            db.SaveChanges();

            var count = messages.Count();

            ViewBag.SearchCount = count;
            var           items         = messages.Skip((page - 1) * pageSize).Take(pageSize).ToList();
            PageViewModel pageViewModel = new PageViewModel(count, page, pageSize);

            DialogueViewModel d1 = new DialogueViewModel
            {
                Dialogue      = dialogue,
                User2         = user2,
                Messages      = messages,
                PageViewModel = pageViewModel
            };

            return(View(d1));
        }
    public override void OnInspectorGUI()
    {
        //draws the default inspector
        //DrawDefaultInspector();

        //get the target
        DialogueSystemScript dial = (DialogueSystemScript)target;

        //get size of array in real time
        dial.dialogueAmount = dial.dialogueList.Length;
        //get all the users that will appear in this dialogue
        allUsersAmount = dial.allUsers.Length;

        //store all the names of the users into an array, to be used in dropdown list
        string[] userChoices = new string[allUsersAmount];
        for(int i = 0; i < userChoices.Length; ++i)
        {
            userChoices[i] = dial.allUsers[i].userName;
        }

        EditorGUILayout.LabelField("DIALOGUE SYSTEM CUSTOM EDITOR", EditorStyles.boldLabel);
        Spaces(2);
        EditorGUILayout.LabelField("Users that will appear in this dialogue", EditorStyles.boldLabel);
        //list all the users in the chat
        for(int i = 0; i < dial.allUsers.Length; ++i)
        {
            dial.allUsers[i] = (DialogueUserScript)EditorGUILayout.ObjectField("User " + (i + 1), dial.allUsers[i], typeof(DialogueUserScript), false);
        }
        //buttons to handle the amount of user
        if(GUILayout.Button("Add New User"))
        {
            //add a new user, dynamically scale the array size
            allUsersAmount += 1;
            System.Array.Resize(ref dial.allUsers, allUsersAmount);
            DialogueUserScript u = new DialogueUserScript();
            dial.allUsers[allUsersAmount - 1] = u;
        }
        else if(GUILayout.Button("Remove Last User"))
        {
            //delete the final user, then decrease the size of the array
            allUsersAmount -= 1;
            dial.allUsers[allUsersAmount] = null;
            System.Array.Resize(ref dial.allUsers, allUsersAmount);
        }

        Spaces (2);
        EditorGUILayout.LabelField("Dialogue Chat", EditorStyles.boldLabel);
        for(int i = 0; i < dial.dialogueList.Length; ++i)
        {
            dial.dialogueList[i].userChoice = EditorGUILayout.Popup(dial.dialogueList[i].userChoice, userChoices);
            dial.dialogueList[i].user = dial.allUsers[dial.dialogueList[i].userChoice];
            if(dial.dialogueList[i].user.userName == "Stop")
            {
                EditorGUILayout.LabelField("Message", "-Disable the Dialogue System-", "TextField");
            }
            else
            {
                dial.dialogueList[i].message = EditorGUILayout.TextField("Message", dial.dialogueList[i].message, GUILayout.MinHeight(80), GUILayout.MaxHeight(20));
            }

            Spaces (2);
        }
        //buttons to handle the dialogues
        if(GUILayout.Button("Add New Dialogue"))
        {
            //add a new user, dynamically scale the array size
            dial.dialogueAmount += 1;
            System.Array.Resize(ref dial.dialogueList, dial.dialogueAmount);
            UserDialogue u = new UserDialogue();
            dial.dialogueList[dial.dialogueAmount - 1] = u;
        }
        else if(GUILayout.Button("Remove Last Dialogue"))
        {
            //delete the final user, then decrease the size of the array
            dial.dialogueAmount -= 1;
            dial.dialogueList[dial.dialogueAmount] = null;
            System.Array.Resize(ref dial.dialogueList, dial.dialogueAmount);
        }

        //sync with original inspector
        if(GUI.changed)
        {
            EditorUtility.SetDirty(dial);
        }
    }