コード例 #1
0
        /// <summary>
        /// Get the interaction of the user with the group
        /// </summary>
        /// <param name="user">The user who wants to join to the group</param>
        /// <param name="group">The group where the user wants to join</param>
        /// <returns>The interaction of the user with the group</returns>
        private interactionType checkInteractions(User user, Group group)
        {
            List <GroupInteraction> interactions = _context.GroupInteractions.Where(ginteraction => ginteraction.userid == user.id && ginteraction.groupid == group.id).ToList();

            if (interactions.Count() == 0)
            {
                return(interactionType.NONE);
            }

            GroupInteraction gi = interactions.First();

            if (gi.dateLeave.AddDays(7) < DateTime.Now)
            {
                return(interactionType.NONE);
            }

            if (gi.kicked)
            {
                return(interactionType.KICKED);
            }
            else
            {
                return(interactionType.LEAVED);
            }
        }
コード例 #2
0
        /// <summary>
        /// Manages the interaction of a user with a group
        /// </summary>
        /// <param name="user">The user who has interacted with the group</param>
        /// <param name="group">The group</param>
        /// <param name="type">The interaction id</param>
        /// <param name="dbContext">The database context</param>
        public static void manageInteraction(User user, Group group, interactionType type, ApplicationDBContext dbContext)
        {
            List <GroupInteraction> interactions = dbContext.GroupInteractions.Where(gi => gi.groupid == group.id && gi.userid == user.id).ToList();
            bool leftTheGroup          = type == interactionType.LEAVED ? true : false;
            bool wasKickedFromTheGroup = type == interactionType.KICKED ? true : false;

            try
            {
                if (interactions.Count() != 1)
                {
                    GroupInteraction gi = new GroupInteraction
                    {
                        Group  = group,
                        User   = user,
                        kicked = wasKickedFromTheGroup,
                        leaved = leftTheGroup
                    };
                    dbContext.Add(gi);
                }
                else
                {
                    GroupInteraction gi = interactions.First();
                    gi.dateLeave = DateTime.Now;
                    gi.kicked    = wasKickedFromTheGroup;
                    gi.leaved    = leftTheGroup;
                }
                dbContext.SaveChanges();
            }
            catch (Exception) { }
        }
コード例 #3
0
    /**Updates the current interacting groups as soon as any player sends a triggerEnter event with another player*/
    public void GroupInteractionOnPlayerCollisionEnter(Player player1, Player player2)
    {
        CreateInteraction groupInteraction1 = FindPlayerInGroups(player1);

        if (groupInteraction1 != null)
        {
            CreateInteraction groupInteraction2 = FindPlayerInGroups(player2);
            if (groupInteraction2 != null)
            {
                if (groupInteraction1 == groupInteraction2)
                {
                    //both players are in the same group
                    return;
                }


                if (groupInteraction1.players.Length == 2 && groupInteraction1.players.Length == 2)
                {
                    //merge 4 players from two groups of two
                    foreach (Player player in groupInteraction2.players)
                    {
                        groupInteraction1.AddPlayer(player);
                        RemoveCreateInteraction(groupInteraction2);
                    }
                }
                else
                {
                    //more than four players
                    //TODO: handle this or do nothing
                }
            }
            else
            {
                //player1 is part of a group. player2 has to be added.
                if (groupInteraction1.players.Length < 4)
                {
                    groupInteraction1.AddPlayer(player2);
                }
            }
        }
        else
        {
            GroupInteraction groupInteraction2 = FindPlayerInGroups(player2);
            if (groupInteraction2 != null)
            {
                //player2 is part of a group. player1 has to be added.
                if (groupInteraction2.players.Length < 4)
                {
                    groupInteraction2.AddPlayer(player1);
                }
            }
            else
            {
                //none is part of a group. new Group has to be added.
                CreateInteraction newCreateInteraction = Instantiate(CIPrefab);
                newCreateInteraction.AddPlayer(player1);
                newCreateInteraction.AddPlayer(player2);
                createInteractionList.Add(newCreateInteraction);
            }
        }
    }