Пример #1
0
        /// <summary>
        /// Save friendrequest reply state.
        /// </summary>
        /// <param name="reply">User reply for a friend request.</param>
        public ComplexFriendRequest ReplyToRequest(FriendRequestReply reply)
        {
            ComplexFriendRequest updatedRequest = SaveReplyState(reply);

            var registrationService = RegistrationService.Instance;
            var targetId            = reply.Request.TargetAccount.Id;
            var requesterId         = reply.Request.RequesterAccount.Id;

            var targetAcc    = registrationService.FindById(targetId);
            var requesterAcc = registrationService.FindById(requesterId);

            if (targetAcc == null)
            {
                throw new InvalidOperationException($"Target account '{ targetId }' not found");
            }
            if (requesterAcc == null)
            {
                throw new InvalidOperationException($"Requester account '{ requesterId }' not found");
            }

            var friendship = new FriendshipModel
            {
                ParentId          = reply.Request.RequesterAccount.Id,
                NavigationParent  = reply.Request.RequesterAccount.ToComplex(),
                AcceptorAccountId = reply.Request.TargetAccount.Id,
                AcceptorAccount   = reply.Request.TargetAccount.ToComplex(),
                Established       = updatedRequest.DecisionDate,
            };

            friendshipService.SaveFriendship(friendship);

            return(updatedRequest);
        }
Пример #2
0
        /// <summary>Get raw debug data to display for this subject.</summary>
        /// <param name="metadata">Provides metadata that's not available from the game data directly.</param>
        public override IEnumerable <IDebugField> GetDebugFields(Metadata metadata)
        {
            NPC target = this.Target;
            Pet pet    = target as Pet;

            // pinned fields
            yield return(new GenericDebugField("facing direction", (FacingDirection)target.FacingDirection, pinned: true));

            yield return(new GenericDebugField("walking towards player", target.IsWalkingTowardPlayer, pinned: true));

            if (Game1.player.friendships.ContainsKey(target.name))
            {
                FriendshipModel friendship = DataParser.GetFriendshipForVillager(Game1.player, target, metadata);
                yield return(new GenericDebugField("friendship", $"{friendship.Points} (max {friendship.MaxPoints})", pinned: true));
            }
            if (pet != null)
            {
                yield return(new GenericDebugField("friendship", $"{pet.friendshipTowardFarmer} of {Pet.maxFriendship})", pinned: true));
            }

            // raw fields
            foreach (IDebugField field in this.GetDebugFieldsFrom(target))
            {
                yield return(field);
            }
        }
        public async Task LookupFriendshipAsync(IUserModel user)
        {
            IFriendshipModel model = StorageService.GetCachedFriendship(user.ScreenName);

            if (model == null)
            {
                var option = Const.GetDictionary();
                option.Add(Const.USER_ID, user.Id);
                var friendships = await tokens.Friendships.LookupAsync(option);

                if (friendships != null && friendships.Count != 0)
                {
                    model = new FriendshipModel(friendships[0]);
                }
            }
            if (model == null)
            {
                return;
            }

            var connections = model.Connections.Select(c => c.ToLower()).ToList();

            user.IsFollowing  = connections.Contains(Const.FOLLOWING);
            user.IsFollowedBy = connections.Contains(Const.FOLLOWED_BY);

            StorageService.AddOrUpdateCachedFriendship(model);
        }
Пример #4
0
        /*********
        ** Private methods
        *********/
        /*****
        ** Data fields
        ****/
        /// <summary>Get the fields to display for a child.</summary>
        /// <param name="child">The child for which to show info.</param>
        /// <remarks>Derived from <see cref="Child.dayUpdate"/>.</remarks>
        private IEnumerable <ICustomField> GetDataForChild(Child child)
        {
            // birthday
            SDate birthday = SDate.Now().AddDays(-child.daysOld.Value);

            yield return(new GenericField(this.GameHelper, L10n.Npc.Birthday(), this.Text.Stringify(birthday, withYear: true)));

            // age
            {
                ChildAge stage      = (ChildAge)child.Age;
                int      daysOld    = child.daysOld.Value;
                int      daysToNext = this.GetDaysToNextChildGrowth(stage, daysOld);
                bool     isGrown    = daysToNext == -1;
                int      daysAtNext = daysOld + (isGrown ? 0 : daysToNext);

                string ageDesc = isGrown
                    ? L10n.NpcChild.AgeDescriptionGrown(label: stage)
                    : L10n.NpcChild.AgeDescriptionPartial(label: stage, count: daysToNext, nextLabel: stage + 1);

                yield return(new PercentageBarField(this.GameHelper, L10n.NpcChild.Age(), child.daysOld.Value, daysAtNext, Color.Green, Color.Gray, ageDesc));
            }

            // friendship
            if (Game1.player.friendshipData.ContainsKey(child.Name))
            {
                FriendshipModel friendship = this.GameHelper.GetFriendshipForVillager(Game1.player, child, Game1.player.friendshipData[child.Name]);
                yield return(new CharacterFriendshipField(this.GameHelper, L10n.Npc.Friendship(), friendship, this.Text));

                yield return(new GenericField(this.GameHelper, L10n.Npc.TalkedToday(), this.Stringify(Game1.player.friendshipData[child.Name].TalkedToToday)));
            }
        }
Пример #5
0
        /// <summary>
        /// Save the friendship to database.
        /// </summary>
        /// <param name="friendship">Friendship model.</param>
        public void SaveFriendship(FriendshipModel friendship)
        {
            ValidateModel(friendship);

            using (var context = new FriendshipContext())
            {
                var existingModel =
                    context
                    .Objects
                    .FirstOrDefault(model =>
                                    model.ParentId == friendship.ParentId &&
                                    model.AcceptorAccountId == friendship.AcceptorAccountId);

                if (existingModel == null)
                {
                    context.Objects.Add(friendship);
                }
                else
                {
                    string message = $"Friendship between {existingModel.NavigationParent.Name} and { existingModel.AcceptorAccount.Name } already exists";
                    throw new InvalidOperationException(message);
                }

                context.SaveChanges();

                CacheIncomingFriendship(friendship);
                CacheOutgoingFriendship(friendship);
            }
        }
Пример #6
0
        /// <summary>Get the fields to display for a villager NPC.</summary>
        /// <param name="npc">The NPC for which to show info.</param>
        private IEnumerable <ICustomField> GetDataForVillager(NPC npc)
        {
            // social fields (birthday, friendship, gifting, etc)
            if (this.GameHelper.IsSocialVillager(npc))
            {
                // birthday
                if (npc.Birthday_Season != null)
                {
                    SDate birthday = new SDate(npc.Birthday_Day, npc.Birthday_Season);
                    yield return(new GenericField(this.GameHelper, L10n.Npc.Birthday(), this.Text.Stringify(birthday)));
                }

                // friendship
                if (Game1.player.friendshipData.ContainsKey(npc.Name))
                {
                    // friendship/romance
                    FriendshipModel friendship = this.GameHelper.GetFriendshipForVillager(Game1.player, npc, Game1.player.friendshipData[npc.Name]);
                    yield return(new GenericField(this.GameHelper, L10n.Npc.CanRomance(), friendship.IsSpouse ? L10n.Npc.CanRomanceMarried() : friendship.IsHousemate ? L10n.Npc.CanRomanceHousemate() : this.Stringify(friendship.CanDate)));

                    yield return(new CharacterFriendshipField(this.GameHelper, L10n.Npc.Friendship(), friendship, this.Text));

                    // talked/gifted today
                    yield return(new GenericField(this.GameHelper, L10n.Npc.TalkedToday(), this.Stringify(friendship.TalkedToday)));

                    yield return(new GenericField(this.GameHelper, L10n.Npc.GiftedToday(), this.Stringify(friendship.GiftsToday > 0)));

                    // kissed/hugged today
                    if (friendship.IsSpouse || friendship.IsHousemate)
                    {
                        yield return(new GenericField(this.GameHelper, friendship.IsSpouse ? L10n.Npc.KissedToday() : L10n.Npc.HuggedToday(), this.Stringify(npc.hasBeenKissedToday.Value)));
                    }

                    // gifted this week
                    if (!friendship.IsSpouse && !friendship.IsHousemate)
                    {
                        yield return(new GenericField(this.GameHelper, L10n.Npc.GiftedThisWeek(), L10n.Generic.Ratio(value: friendship.GiftsThisWeek, max: NPC.maxGiftsPerWeek)));
                    }
                }
                else
                {
                    yield return(new GenericField(this.GameHelper, L10n.Npc.Friendship(), L10n.Npc.FriendshipNotMet()));
                }

                // gift tastes
                IDictionary <GiftTaste, GiftTasteModel[]> giftTastes = this.GetGiftTastes(npc);
                yield return(this.GetGiftTasteField(L10n.Npc.LovesGifts(), giftTastes, GiftTaste.Love));

                yield return(this.GetGiftTasteField(L10n.Npc.LikesGifts(), giftTastes, GiftTaste.Like));

                yield return(this.GetGiftTasteField(L10n.Npc.NeutralGifts(), giftTastes, GiftTaste.Neutral));

                if (this.ProgressionMode || this.HighlightUnrevealedGiftTastes)
                {
                    yield return(this.GetGiftTasteField(L10n.Npc.DislikesGifts(), giftTastes, GiftTaste.Dislike));

                    yield return(this.GetGiftTasteField(L10n.Npc.HatesGifts(), giftTastes, GiftTaste.Hate));
                }
            }
        }
        /// <summary>Get the fields to display for a villager NPC.</summary>
        /// <param name="npc">The NPC for which to show info.</param>
        /// <param name="metadata">Provides metadata that's not available from the game data directly.</param>
        private IEnumerable <ICustomField> GetDataForVillager(NPC npc, Metadata metadata)
        {
            if (!metadata.Constants.AsocialVillagers.Contains(npc.Name))
            {
                // birthday
                if (npc.Birthday_Season != null)
                {
                    SDate birthday = new SDate(npc.Birthday_Day, npc.Birthday_Season);
                    yield return(new GenericField(this.GameHelper, L10n.Npc.Birthday(), this.Text.Stringify(birthday)));
                }

                // friendship
                if (Game1.player.friendshipData.ContainsKey(npc.Name))
                {
                    // friendship/romance
                    FriendshipModel friendship = this.GameHelper.GetFriendshipForVillager(Game1.player, npc, Game1.player.friendshipData[npc.Name], metadata);
                    yield return(new GenericField(this.GameHelper, L10n.Npc.CanRomance(), friendship.IsSpouse ? L10n.Npc.CanRomanceMarried() : this.Stringify(friendship.CanDate)));

                    yield return(new CharacterFriendshipField(this.GameHelper, L10n.Npc.Friendship(), friendship, this.Text));

                    // talked/gifted today
                    yield return(new GenericField(this.GameHelper, L10n.Npc.TalkedToday(), this.Stringify(friendship.TalkedToday)));

                    yield return(new GenericField(this.GameHelper, L10n.Npc.GiftedToday(), this.Stringify(friendship.GiftsToday > 0)));

                    // kissed today
                    if (friendship.IsSpouse)
                    {
                        yield return(new GenericField(this.GameHelper, L10n.Npc.KissedToday(), this.Stringify(npc.hasBeenKissedToday.Value)));
                    }

                    // gifted this week
                    if (!friendship.IsSpouse)
                    {
                        yield return(new GenericField(this.GameHelper, L10n.Npc.GiftedThisWeek(), L10n.Generic.Ratio(value: friendship.GiftsThisWeek, max: NPC.maxGiftsPerWeek)));
                    }
                }
                else
                {
                    yield return(new GenericField(this.GameHelper, L10n.Npc.Friendship(), L10n.Npc.FriendshipNotMet()));
                }

                // gift tastes
                var giftTastes = this.GetGiftTastes(npc, metadata);
                yield return(new CharacterGiftTastesField(this.GameHelper, L10n.Npc.LovesGifts(), giftTastes, GiftTaste.Love));

                yield return(new CharacterGiftTastesField(this.GameHelper, L10n.Npc.LikesGifts(), giftTastes, GiftTaste.Like));

                yield return(new CharacterGiftTastesField(this.GameHelper, L10n.Npc.NeutralGifts(), giftTastes, GiftTaste.Neutral));
            }
        }
Пример #8
0
        private void ValidateModel(FriendshipModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            if (model.ParentId == Guid.Empty)
            {
                throw new InvalidOperationException();
            }
            if (model.AcceptorAccountId == Guid.Empty)
            {
                throw new InvalidOperationException();
            }

            model.PrepareMappedProps();
        }
Пример #9
0
 public ActionResult Index()
 {
     if (ModelState.IsValid)
     {
         try
         {
             var friendModelList    = GetFriendships();
             var requesterModelList = GetRequests();
             var model = new FriendshipModel {
                 Friends = friendModelList, FriendRequests = requesterModelList
             };
             return(View(model));
         }
         catch (Exception e)
         {
             return(View("Error", new ErrorModel {
                 Exception = e
             }));
         }
     }
     return(RedirectToAction("Index", "Profile"));
 }
Пример #10
0
        private static void CacheFriendship(Dictionary <Guid, List <FriendshipModel> > cache, FriendshipModel realFriendship, Guid userId)
        {
            if (!cache.ContainsKey(userId))
            {
                cache.Add(userId, new List <FriendshipModel>());
            }

            var friendships = cache[userId];

            if (!friendships.Contains(realFriendship))
            {
                friendships.Add(realFriendship);
            }
        }
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="label">A short field label.</param>
 /// <param name="friendship">The player's current friendship data with the NPC.</param>
 /// <param name="translations">Provides translations stored in the mod folder.</param>
 public CharacterFriendshipField(string label, FriendshipModel friendship, ITranslationHelper translations)
     : base(label, hasValue: true)
 {
     this.Friendship   = friendship;
     this.Translations = translations;
 }
Пример #12
0
 private static void CacheIncomingFriendship(FriendshipModel realFriendship)
 {
     CacheFriendship(incomingFriendships, realFriendship, realFriendship.AcceptorAccountId);
 }
Пример #13
0
 private static void CacheOutgoingFriendship(FriendshipModel realFriendship)
 {
     CacheFriendship(outgoingFriendships, realFriendship, realFriendship.ParentId);
 }
        //User accepts or rejects admin's request
        public async Task InviteHomeAcceptAsync(UserModel user, int invitedHomeId, bool isAccepted)
        {
            Task <InformationModel> firstNameInfo = _informationRepository.GetInformationByInformationNameAsync("FirstName");
            Task <InformationModel> lastNameInfo  = _informationRepository.GetInformationByInformationNameAsync("LastName");

            if (user.Position != (int)UserPosition.HasNotHome)
            {
                CustomException errors = new CustomException((int)HttpStatusCode.BadRequest);
                errors.AddError("User Has Home", "User can not accept invite requests while already has home");
                errors.Throw();
            }

            HomeModel home = await _homeRepository.GetByIdAsync(invitedHomeId, true);

            if (home == null)
            {
                CustomException errors = new CustomException((int)HttpStatusCode.BadRequest);
                errors.AddError("Invalid Home Id", "Home not exist");
                errors.Throw();
            }

            if (isAccepted == true)
            {
                user.Position = (int)UserPosition.HasHome;

                UserInformationModel userFirstName = await _userInformationRepository.GetUserInformationByIdAsync(user.Id, (await firstNameInfo).Id);

                UserInformationModel userLastName = await _userInformationRepository.GetUserInformationByIdAsync(user.Id, (await lastNameInfo).Id);

                List <UserBaseModel> friendsBaseModels = new List <UserBaseModel>();
                UserBaseModel        userBaseModel     = new UserBaseModel(user.Id, user.Username, user.Position, userFirstName.Value, userLastName.Value, 0);

                FCMModel fcmUser = new FCMModel(user.DeviceId, type: "AllFriends");

                foreach (var friend in home.Users)
                {
                    FriendshipModel friendship       = new FriendshipModel(user, friend, 0);
                    Task            insertFriendship = _friendshipRepository.InsertAsync(friendship);

                    //Sends notification to all friends
                    FCMModel fcmFriend = new FCMModel(friend.DeviceId, new Dictionary <string, object>());

                    fcmFriend.notification.Add("title", "Yeni Ev Arkadaşı");
                    fcmFriend.notification.Add("body", String.Format("{0} {1}({2}) evinize katıldı", userFirstName.Value, userLastName.Value, user.Username));

                    await _fcmService.SendFCMAsync(fcmFriend);

                    //Sends notification to all friends
                    fcmFriend = new FCMModel(friend.DeviceId, new Dictionary <string, object>(), "NewFriend");
                    fcmFriend.data.Add("Friend", userBaseModel);

                    await _fcmService.SendFCMAsync(fcmFriend);

                    //Sends all friends to requester
                    UserInformationModel friendFirstName = await _userInformationRepository.GetUserInformationByIdAsync(friend.Id, (await firstNameInfo).Id);

                    UserInformationModel friendLastName = await _userInformationRepository.GetUserInformationByIdAsync(friend.Id, (await lastNameInfo).Id);

                    friendsBaseModels.Add(new UserBaseModel(friend.Id, friend.Username, friend.Position, friendFirstName.Value, friendLastName.Value, 0));

                    await insertFriendship;
                }

                home.Users.Add(user);
                _homeRepository.Update(home);

                user.Home = home;
                _userRepository.Update(user);

                fcmUser.data.Add("NumberOfFriends", home.Users.Count - 1);
                fcmUser.data.Add("Friends", friendsBaseModels);
                await _fcmService.SendFCMAsync(fcmUser);
            }
        }
        //Admin accepts or rejects user's request
        public async Task JoinHomeAcceptAsync(UserModel user, int requesterId, bool isAccepted)
        {
            Task <UserModel>        getAdmin      = _userRepository.GetByIdAsync(user.Id, true);
            Task <InformationModel> firstNameInfo = _informationRepository.GetInformationByInformationNameAsync("FirstName");
            Task <InformationModel> lastNameInfo  = _informationRepository.GetInformationByInformationNameAsync("LastName");

            if (user.Position != (int)UserPosition.Admin)
            {
                CustomException errors = new CustomException((int)HttpStatusCode.BadRequest);
                errors.AddError("Authorisation Constraint", "You are not authorized for this request, you must be administrator of home");
                errors.Throw();
            }

            UserModel requester = await _userRepository.GetByIdAsync(requesterId);

            if (requester == null)
            {
                CustomException errors = new CustomException((int)HttpStatusCode.BadRequest);
                errors.AddError("Invalid User Id", "User not exist");
                errors.Throw();
            }

            if (requester.Position != (int)UserPosition.HasNotHome)
            {
                CustomException errors = new CustomException((int)HttpStatusCode.BadRequest);
                errors.AddError("Requester Has Home", "Requester has already home");
                errors.Throw();
            }

            user = await getAdmin;

            if (isAccepted == true)
            {
                requester.Position = (int)UserPosition.HasHome;

                UserInformationModel requesterFirstName = await _userInformationRepository.GetUserInformationByIdAsync(requester.Id, (await firstNameInfo).Id);

                UserInformationModel requesterLastName = await _userInformationRepository.GetUserInformationByIdAsync(requester.Id, (await lastNameInfo).Id);

                HomeModel home = await _homeRepository.GetByIdAsync(user.Home.Id, true);

                FCMModel fcmRequester = new FCMModel(requester.DeviceId, new Dictionary <string, object>());

                fcmRequester.notification.Add("title", "Eve Katılma İsteği");
                fcmRequester.notification.Add("body", "Eve katılma isteğiniz ev yöneticisi tarafından kabul edildi.");

                await _fcmService.SendFCMAsync(fcmRequester);

                List <UserBaseModel> friendsBaseModels  = new List <UserBaseModel>();
                UserBaseModel        requesterBaseModel = new UserBaseModel(requester.Id, requester.Username, requester.Position, requesterFirstName.Value, requesterLastName.Value, 0);

                foreach (var friend in home.Users)
                {
                    FriendshipModel friendship       = new FriendshipModel(requester, friend, 0);
                    Task            insertFriendship = _friendshipRepository.InsertAsync(friendship);

                    //Sends notification to all friends
                    FCMModel fcmFriend = new FCMModel(friend.DeviceId, new Dictionary <string, object>());

                    fcmFriend.notification.Add("title", "Yeni Ev Arkadaşı");
                    fcmFriend.notification.Add("body", String.Format("{0} {1}({2}) evinize katıldı.", requesterFirstName.Value, requesterLastName.Value, requester.Username));

                    await _fcmService.SendFCMAsync(fcmFriend);

                    //Sends notification to all friends
                    fcmFriend = new FCMModel(friend.DeviceId, type: "NewFriend");
                    fcmFriend.data.Add("Friend", requesterBaseModel);

                    await _fcmService.SendFCMAsync(fcmFriend);

                    //Sends all friends to requester
                    UserInformationModel friendFirstName = await _userInformationRepository.GetUserInformationByIdAsync(friend.Id, (await firstNameInfo).Id);

                    UserInformationModel friendLastName = await _userInformationRepository.GetUserInformationByIdAsync(friend.Id, (await lastNameInfo).Id);

                    friendsBaseModels.Add(new UserBaseModel(friend.Id, friend.Username, friend.Position, friendFirstName.Value, friendLastName.Value, 0));

                    await insertFriendship;
                }

                home.Users.Add(requester);
                _homeRepository.Update(home);

                requester.Home = home;
                _userRepository.Update(requester);

                fcmRequester = new FCMModel(requester.DeviceId, type: "AllFriends");

                fcmRequester.data.Add("NumberOfFriends", home.Users.Count - 1);
                fcmRequester.data.Add("Friends", friendsBaseModels);
                await _fcmService.SendFCMAsync(fcmRequester);
            }
        }
Пример #16
0
        public async Task <ActionResult> RemoveFriend(int UserID, int FriendID)
        {
            FriendshipModel deletedFriendship = await coopQueue.PostRemoveFriend(UserID, FriendID);

            return(Json(new { success = true }));
        }
        //User gives money to his/her friend
        public async Task TransferMoneyToFriendAsync(UserModel from, UserModel to, double givenMoney)
        {
            if (to == null)
            {
                CustomException errors = new CustomException((int)HttpStatusCode.BadRequest);
                errors.AddError("Friend Not Found", "Friend not found for lend");
                errors.Throw();
            }

            if (from.Position == (int)UserPosition.HasNotHome || to.Position == (int)UserPosition.HasNotHome)
            {
                CustomException errors = new CustomException((int)HttpStatusCode.BadRequest);
                errors.AddError("Home Not Exist", "User is not member of a home");
                errors.Throw();
            }

            FriendshipModel friendship = await _friendshipRepository.GetFriendshipByIdAsync(from.Id, to.Id);

            if (friendship == null)
            {
                CustomException errors = new CustomException((int)HttpStatusCode.BadRequest);
                errors.AddError("Friendship Not Found", "Friendship not found for lend");
                errors.Throw();
            }

            if (friendship.User1.Id == from.Id)
            {
                friendship.Debt -= givenMoney;
                Task update = _friendshipRepository.UpdateAsync(friendship);

                FCMModel fcmFrom = new FCMModel(from.DeviceId, type: "GiveMoney");
                fcmFrom.data.Add("ToId", to.Id);
                fcmFrom.data.Add("NewDebt", friendship.Debt);
                Task sendFCMFrom = _fcmService.SendFCMAsync(fcmFrom);

                FCMModel fcmTo = new FCMModel(to.DeviceId, type: "TakeMoney");
                fcmTo.data.Add("FromId", from.Id);
                fcmTo.data.Add("NewDebt", -friendship.Debt);

                await _fcmService.SendFCMAsync(fcmTo);

                await sendFCMFrom;
                await update;
            }
            else
            {
                friendship.Debt += givenMoney;
                Task update = _friendshipRepository.UpdateAsync(friendship);

                FCMModel fcmFrom = new FCMModel(from.DeviceId, type: "GiveMoney");
                fcmFrom.data.Add("ToId", to.Id);
                fcmFrom.data.Add("NewDebt", -friendship.Debt);
                Task sendFCMFrom = _fcmService.SendFCMAsync(fcmFrom);

                FCMModel fcmTo = new FCMModel(to.DeviceId, type: "TakeMoney");
                fcmTo.data.Add("FromId", from.Id);
                fcmTo.data.Add("NewDebt", friendship.Debt);

                await _fcmService.SendFCMAsync(fcmTo);

                await sendFCMFrom;
                await update;
            }
        }
        /// <summary>Draw the value (or return <c>null</c> to render the <see cref="GenericField.Value"/> using the default format).</summary>
        /// <param name="spriteBatch">The sprite batch being drawn.</param>
        /// <param name="font">The recommended font.</param>
        /// <param name="position">The position at which to draw.</param>
        /// <param name="wrapWidth">The maximum width before which content should be wrapped.</param>
        /// <returns>Returns the drawn dimensions, or <c>null</c> to draw the <see cref="GenericField.Value"/> using the default format.</returns>
        public override Vector2?DrawValue(SpriteBatch spriteBatch, SpriteFont font, Vector2 position, float wrapWidth)
        {
            FriendshipModel friendship = this.Friendship;

            // draw status
            float leftOffset = 0;

            {
                string  statusText = this.Translations.Get(L10n.For(friendship.Status));
                Vector2 textSize   = spriteBatch.DrawTextBlock(font, statusText, new Vector2(position.X + leftOffset, position.Y), wrapWidth - leftOffset);
                leftOffset += textSize.X + DrawHelper.GetSpaceWidth(font);
            }

            // draw hearts
            for (int i = 0; i < friendship.TotalHearts; i++)
            {
                // get icon
                Color     color;
                Rectangle icon;
                if (friendship.LockedHearts >= friendship.TotalHearts - i)
                {
                    icon  = Sprites.Icons.FilledHeart;
                    color = Color.Black * 0.35f;
                }
                else if (i >= friendship.FilledHearts)
                {
                    icon  = Sprites.Icons.EmptyHeart;
                    color = Color.White;
                }
                else
                {
                    icon  = Sprites.Icons.FilledHeart;
                    color = Color.White;
                }

                // draw
                spriteBatch.DrawSprite(Sprites.Icons.Sheet, icon, position.X + leftOffset, position.Y, color, Game1.pixelZoom);
                leftOffset += Sprites.Icons.FilledHeart.Width * Game1.pixelZoom;
            }

            // draw stardrop (if applicable)
            if (friendship.HasStardrop)
            {
                leftOffset += 1;
                float zoom = (Sprites.Icons.EmptyHeart.Height / (Sprites.Icons.Stardrop.Height * 1f)) * Game1.pixelZoom;
                spriteBatch.DrawSprite(Sprites.Icons.Sheet, Sprites.Icons.Stardrop, position.X + leftOffset, position.Y, Color.White * 0.25f, zoom);
                leftOffset += Sprites.Icons.Stardrop.Width * zoom;
            }

            // get caption text
            string caption = null;

            if (this.Friendship.EmptyHearts == 0 && this.Friendship.LockedHearts > 0)
            {
                caption = $"({this.Translations.Get(L10n.Npc.FriendshipNeedBouquet)})";
            }
            else
            {
                int pointsToNext = this.Friendship.GetPointsToNext();
                if (pointsToNext > 0)
                {
                    caption = $"({this.Translations.Get(L10n.Npc.FriendshipNeedPoints, new { count = pointsToNext })})";
                }
            }

            // draw caption
            {
                float   spaceSize = DrawHelper.GetSpaceWidth(font);
                Vector2 textSize  = Vector2.Zero;
                if (caption != null)
                {
                    textSize = spriteBatch.DrawTextBlock(font, caption, new Vector2(position.X + leftOffset + spaceSize, position.Y), wrapWidth - leftOffset);
                }

                return(new Vector2(Sprites.Icons.FilledHeart.Width * Game1.pixelZoom * this.Friendship.TotalHearts + textSize.X + spaceSize, Math.Max(Sprites.Icons.FilledHeart.Height * Game1.pixelZoom, textSize.Y)));
            }
        }
        //User request to quit home
        public async Task LeaveHomeAsync(UserModel user, int newAdminId)
        {
            if (user.Position == (int)UserPosition.HasNotHome)
            {
                CustomException errors = new CustomException((int)HttpStatusCode.BadRequest);
                errors.AddError("Home Not Exist", "User is not member of a home");
                errors.Throw();
            }

            Task <InformationModel> firstNameInfo = _informationRepository.GetInformationByInformationNameAsync("FirstName");
            Task <InformationModel> lastNameInfo  = _informationRepository.GetInformationByInformationNameAsync("LastName");

            user = await _userRepository.GetByIdAsync(user.Id, true);

            HomeModel home = await _homeRepository.GetByIdAsync(user.Home.Id, true);

            UserInformationModel userFirstName = await _userInformationRepository.GetUserInformationByIdAsync(user.Id, (await firstNameInfo).Id);

            UserInformationModel userLastName = await _userInformationRepository.GetUserInformationByIdAsync(user.Id, (await lastNameInfo).Id);

            List <UserExpenseModel> userExpenses = await _userExpenseRepository.GetAllUserExpenseByUserIdAsync(user.Id);

            foreach (var ue in userExpenses)
            {
                _userExpenseRepository.Delete(ue);
            }

            if (home.Users.Count != 1)
            {
                if (user.Position == (int)UserPosition.Admin)
                {
                    UserModel newAdmin = await _userRepository.GetByIdAsync(newAdminId);

                    if (newAdmin == null || newAdmin.Home.Id != user.Home.Id)
                    {
                        CustomException errors = new CustomException((int)HttpStatusCode.BadRequest);
                        errors.AddError("Friendship Not Found", "Friendship not found for admin assignment");
                        errors.Throw();
                    }
                    newAdmin.Position = (int)UserPosition.Admin;
                    home.Admin        = newAdmin;
                }

                home.Users.Remove(user);
                user.Home     = null;
                user.Position = (int)UserPosition.HasNotHome;

                _homeRepository.Update(home);
                _userRepository.Update(user);

                //Home friends notification
                foreach (var u in home.Users)
                {
                    FriendshipModel friendship = await _friendshipRepository.GetFriendshipByIdAsync(user.Id, u.Id);

                    FCMModel fcm = new FCMModel(u.DeviceId, new Dictionary <string, object>());
                    fcm.notification.Add("title", "Evden Ayrılma");

                    if (friendship.User1.Id == user.Id)
                    {
                        if (friendship.Debt > 0)
                        {
                            fcm.notification.Add("body", String.Format("{0} {1} evden ayrılıyor. Alacağınız : {2:c}", userFirstName.Value,
                                                                       userLastName.Value,
                                                                       friendship.Debt));
                        }
                        else if (friendship.Debt == 0)
                        {
                            fcm.notification.Add("body", String.Format("{0} {1} evden ayrılıyor. Borcunuz veya alacağınız bulunmamaktadır.", userFirstName.Value,
                                                                       userLastName.Value));
                        }
                        else
                        {
                            fcm.notification.Add("body", String.Format("{0} {1} evden ayrılıyor. Borcunuz : {2:c}", userFirstName.Value,
                                                                       userLastName.Value,
                                                                       -friendship.Debt));
                        }
                    }
                    else
                    {
                        if (friendship.Debt > 0)
                        {
                            fcm.notification.Add("body", String.Format("{0} {1} evden ayrılıyor. Borcunuz : {2:c}", userFirstName.Value,
                                                                       userLastName.Value,
                                                                       friendship.Debt));
                        }
                        else if (friendship.Debt == 0)
                        {
                            fcm.notification.Add("body", String.Format("{0} {1} evden ayrılıyor. Borcunuz veya alacağınız bulunmamaktadır.", userFirstName.Value,
                                                                       userLastName.Value));
                        }
                        else
                        {
                            fcm.notification.Add("body", String.Format("{0} {1} evden ayrılıyor. Alacağınız : {2:c}", userFirstName.Value,
                                                                       userLastName.Value,
                                                                       -friendship.Debt));
                        }
                    }

                    await _fcmService.SendFCMAsync(fcm);

                    fcm = new FCMModel(u.DeviceId, type: "LeaveHome");

                    fcm.data.Add("LeaverId", user.Id);
                    await _fcmService.SendFCMAsync(fcm);

                    _friendshipRepository.Delete(friendship);
                }
            }
            else
            {
                ShoppingListModel shoppingList = await _shoppingListRepository.GetShoppingListByHomeIdAsync(user.Home.Id);

                List <NotepadModel> notepad = await _notepadRepository.GetAllNoteByHomeIdAsync(user.Home.Id);

                List <ExpenseModel> expenses = await _expenseRepository.GetAllExpensesByHomeIdAsync(user.Home.Id);

                _shoppingListRepository.Delete(shoppingList);

                foreach (var note in notepad)
                {
                    _notepadRepository.Delete(note);
                }

                foreach (var expense in expenses)
                {
                    _expenseRepository.Delete(expense);
                }

                user.Home     = null;
                user.Position = (int)UserPosition.HasNotHome;

                _userRepository.Update(user);
                _homeRepository.Delete(home);
            }
        }
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="label">A short field label.</param>
 /// <param name="friendship">The player's current friendship data with the NPC.</param>
 public CharacterFriendshipField(string label, FriendshipModel friendship)
     : base(label, hasValue: true)
 {
     this.Friendship = friendship;
 }
Пример #21
0
        /// <summary>Get the data to display for this subject.</summary>
        /// <param name="metadata">Provides metadata that's not available from the game data directly.</param>
        public override IEnumerable <ICustomField> GetData(Metadata metadata)
        {
            NPC npc = this.Target;

            switch (this.TargetType)
            {
            case TargetType.Villager:
                // special NPCs like Gunther
                if (metadata.Constants.AsocialVillagers.Contains(npc.name))
                {
                    // no data
                }

                // children
                else if (npc is Child child)
                {
                    // birthday
                    SDate birthday = SDate.Now().AddDays(-child.daysOld);
                    yield return(new GenericField(this.Text.Get(L10n.Npc.Birthday), this.Text.Stringify(birthday, withYear: true)));

                    // age
                    {
                        ChildAge stage      = (ChildAge)child.age;
                        int      daysOld    = child.daysOld;
                        int      daysToNext = this.GetDaysToNextChildGrowth(stage, daysOld);
                        bool     isGrown    = daysToNext == -1;
                        int      daysAtNext = daysOld + (isGrown ? 0 : daysToNext);

                        string ageLabel = this.Translate(L10n.NpcChild.Age);
                        string ageName  = this.Translate(L10n.For(stage));
                        string ageDesc  = isGrown
                                ? this.Translate(L10n.NpcChild.AgeDescriptionGrown, new { label = ageName })
                                : this.Translate(L10n.NpcChild.AgeDescriptionPartial, new { label = ageName, count = daysToNext, nextLabel = this.Text.Get(L10n.For(stage + 1)) });

                        yield return(new PercentageBarField(ageLabel, child.daysOld, daysAtNext, Color.Green, Color.Gray, ageDesc));
                    }

                    // friendship
                    if (Game1.player.friendships.ContainsKey(child.name))
                    {
                        FriendshipModel friendship = DataParser.GetFriendshipForVillager(Game1.player, child, metadata);
                        yield return(new CharacterFriendshipField(this.Translate(L10n.Npc.Friendship), friendship, this.Text));

                        yield return(new GenericField(this.Translate(L10n.Npc.TalkedToday), this.Stringify(Game1.player.friendships[child.name][2] == 1)));
                    }
                }

                // villagers
                else
                {
                    // birthday
                    if (npc.birthday_Season != null)
                    {
                        SDate birthday = new SDate(npc.birthday_Day, npc.birthday_Season);
                        yield return(new GenericField(this.Text.Get(L10n.Npc.Birthday), this.Text.Stringify(birthday)));
                    }

                    // friendship
                    if (Game1.player.friendships.ContainsKey(npc.name))
                    {
                        FriendshipModel friendship = DataParser.GetFriendshipForVillager(Game1.player, npc, metadata);
                        yield return(new GenericField(this.Translate(L10n.Npc.CanRomance), friendship.IsSpouse ? this.Translate(L10n.Npc.CanRomanceMarried) : this.Stringify(npc.datable)));

                        yield return(new CharacterFriendshipField(this.Translate(L10n.Npc.Friendship), friendship, this.Text));

                        yield return(new GenericField(this.Translate(L10n.Npc.TalkedToday), this.Stringify(Game1.player.friendships[npc.name][2] == 1)));

                        yield return(new GenericField(this.Translate(L10n.Npc.GiftedToday), this.Stringify(Game1.player.friendships[npc.name][3] > 0)));

                        if (!friendship.IsSpouse)
                        {
                            yield return(new GenericField(this.Translate(L10n.Npc.GiftedThisWeek), this.Translate(L10n.Generic.Ratio, new { value = Game1.player.friendships[npc.name][1], max = NPC.maxGiftsPerWeek })));
                        }
                    }
                    else
                    {
                        yield return(new GenericField(this.Translate(L10n.Npc.Friendship), this.Translate(L10n.Npc.FriendshipNotMet)));
                    }

                    // gift tastes
                    var giftTastes = this.GetGiftTastes(npc, metadata);
                    yield return(new CharacterGiftTastesField(this.Translate(L10n.Npc.LovesGifts), giftTastes, GiftTaste.Love));

                    yield return(new CharacterGiftTastesField(this.Translate(L10n.Npc.LikesGifts), giftTastes, GiftTaste.Like));
                }
                break;

            case TargetType.Pet:
                Pet pet = (Pet)npc;
                yield return(new CharacterFriendshipField(this.Translate(L10n.Pet.Love), DataParser.GetFriendshipForPet(Game1.player, pet), this.Text));

                yield return(new GenericField(this.Translate(L10n.Pet.PettedToday), this.Stringify(this.Reflection.GetField <bool>(pet, "wasPetToday").GetValue())));

                break;

            case TargetType.Monster:
                // basic info
                Monster monster = (Monster)npc;
                yield return(new GenericField(this.Translate(L10n.Monster.Invincible), this.Translate(L10n.Generic.Seconds, new { count = this.Reflection.GetField <int>(monster, "invincibleCountdown").GetValue() }), hasValue: monster.isInvincible()));

                yield return(new PercentageBarField(this.Translate(L10n.Monster.Health), monster.health, monster.maxHealth, Color.Green, Color.Gray, this.Translate(L10n.Generic.PercentRatio, new { percent = Math.Round((monster.health / (monster.maxHealth * 1f) * 100)), value = monster.health, max = monster.maxHealth })));

                yield return(new ItemDropListField(this.Translate(L10n.Monster.Drops), this.GetMonsterDrops(monster), this.Text, defaultText: this.Translate(L10n.Monster.DropsNothing)));

                yield return(new GenericField(this.Translate(L10n.Monster.Experience), this.Stringify(monster.experienceGained)));

                yield return(new GenericField(this.Translate(L10n.Monster.Defence), this.Stringify(monster.resilience)));

                yield return(new GenericField(this.Translate(L10n.Monster.Attack), this.Stringify(monster.damageToFarmer)));

                // Adventure Guild quest
                AdventureGuildQuestData adventureGuildQuest = metadata.GetAdventurerGuildQuest(monster.name);
                if (adventureGuildQuest != null)
                {
                    int kills = adventureGuildQuest.Targets.Select(p => Game1.stats.getMonstersKilled(p)).Sum();
                    yield return(new GenericField(this.Translate(L10n.Monster.AdventureGuild), $"{this.Translate(kills >= adventureGuildQuest.RequiredKills ? L10n.Monster.AdventureGuildComplete : L10n.Monster.AdventureGuildIncomplete)} ({this.Translate(L10n.Monster.AdventureGuildProgress, new { count = kills, requiredCount = adventureGuildQuest.RequiredKills })})"));
                }
                break;
            }
        }
Пример #22
0
        /// <summary>Get the data to display for this subject.</summary>
        /// <param name="metadata">Provides metadata that's not available from the game data directly.</param>
        public override IEnumerable <ICustomField> GetData(Metadata metadata)
        {
            NPC npc = this.Target;

            switch (this.TargetType)
            {
            case TargetType.Villager:
                if (!metadata.Constants.AsocialVillagers.Contains(npc.name))
                {
                    var giftTastes = this.GetGiftTastes(npc, metadata);

                    // birthday
                    GameDate birthday = new GameDate(npc.birthday_Season, npc.birthday_Day, Game1.year, metadata.Constants.DaysInSeason);
                    yield return(new GenericField(this.Text.Get(L10n.Npc.Birthday), this.Text.Stringify(birthday)));

                    // friendship
                    if (Game1.player.friendships.ContainsKey(npc.name))
                    {
                        FriendshipModel friendship = DataParser.GetFriendshipForVillager(Game1.player, npc, metadata);
                        yield return(new GenericField(this.Translate(L10n.Npc.CanRomance), friendship.IsSpouse ? this.Translate(L10n.Npc.CanRomanceMarried) : this.Stringify(npc.datable)));

                        yield return(new CharacterFriendshipField(this.Translate(L10n.Npc.Friendship), friendship, this.Text));

                        yield return(new GenericField(this.Translate(L10n.Npc.TalkedToday), this.Stringify(Game1.player.friendships[npc.name][2] == 1)));

                        yield return(new GenericField(this.Translate(L10n.Npc.GiftedToday), this.Stringify(Game1.player.friendships[npc.name][3] > 0)));

                        if (!friendship.IsSpouse)
                        {
                            yield return(new GenericField(this.Translate(L10n.Npc.GiftedThisWeek), this.Translate(L10n.Generic.Ratio, new { value = Game1.player.friendships[npc.name][1], max = NPC.maxGiftsPerWeek })));
                        }
                    }
                    else
                    {
                        yield return(new GenericField(this.Translate(L10n.Npc.Friendship), this.Translate(L10n.Npc.FriendshipNotMet)));
                    }
                    yield return(new CharacterGiftTastesField(this.Translate(L10n.Npc.LovesGifts), giftTastes, GiftTaste.Love));

                    yield return(new CharacterGiftTastesField(this.Translate(L10n.Npc.LikesGifts), giftTastes, GiftTaste.Like));
                }
                break;

            case TargetType.Pet:
                Pet pet = (Pet)npc;
                yield return(new CharacterFriendshipField(this.Translate(L10n.Pet.Love), DataParser.GetFriendshipForPet(Game1.player, pet), this.Text));

                yield return(new GenericField(this.Translate(L10n.Pet.PettedToday), this.Stringify(this.Reflection.GetPrivateValue <bool>(pet, "wasPetToday"))));

                break;

            case TargetType.Monster:
                // basic info
                Monster monster = (Monster)npc;
                yield return(new GenericField(this.Translate(L10n.Monster.Invincible), this.Translate(L10n.Generic.Seconds, new { count = this.Reflection.GetPrivateValue <int>(monster, "invincibleCountdown") }), hasValue: monster.isInvincible()));

                yield return(new PercentageBarField(this.Translate(L10n.Monster.Health), monster.health, monster.maxHealth, Color.Green, Color.Gray, this.Translate(L10n.Generic.PercentRatio, new { percent = Math.Round((monster.health / (monster.maxHealth * 1f) * 100)), value = monster.health, max = monster.maxHealth })));

                yield return(new ItemDropListField(this.Translate(L10n.Monster.Drops), this.GetMonsterDrops(monster), this.Text, defaultText: this.Translate(L10n.Monster.DropsNothing)));

                yield return(new GenericField(this.Translate(L10n.Monster.Experience), this.Stringify(monster.experienceGained)));

                yield return(new GenericField(this.Translate(L10n.Monster.Defence), this.Stringify(monster.resilience)));

                yield return(new GenericField(this.Translate(L10n.Monster.Attack), this.Stringify(monster.damageToFarmer)));

                // Adventure Guild quest
                AdventureGuildQuestData adventureGuildQuest = metadata.GetAdventurerGuildQuest(monster.name);
                if (adventureGuildQuest != null)
                {
                    int kills = adventureGuildQuest.Targets.Select(p => Game1.stats.getMonstersKilled(p)).Sum();
                    yield return(new GenericField(this.Translate(L10n.Monster.AdventureGuild), $"{this.Translate(kills >= adventureGuildQuest.RequiredKills ? L10n.Monster.AdventureGuildComplete : L10n.Monster.AdventureGuildIncomplete)} ({this.Translate(L10n.Monster.AdventureGuildProgress, new { count = kills, requiredCount = adventureGuildQuest.RequiredKills })})"));
                }
                break;
            }
        }
Пример #23
0
        /// <summary>Get the data to display for this subject.</summary>
        /// <param name="metadata">Provides metadata that's not available from the game data directly.</param>
        public override IEnumerable <ICustomField> GetData(Metadata metadata)
        {
            NPC npc = this.Target;

            switch (this.TargetType)
            {
            case TargetType.Villager:
                // special NPCs like Gunther
                if (metadata.Constants.AsocialVillagers.Contains(npc.Name))
                {
                    // no data
                }

                // children
                else if (npc is Child child)
                {
                    // birthday
                    SDate birthday = SDate.Now().AddDays(-child.daysOld.Value);
                    yield return(new GenericField(this.GameHelper, L10n.Npc.Birthday(), this.Text.Stringify(birthday, withYear: true)));

                    // age
                    {
                        ChildAge stage      = (ChildAge)child.Age;
                        int      daysOld    = child.daysOld.Value;
                        int      daysToNext = this.GetDaysToNextChildGrowth(stage, daysOld);
                        bool     isGrown    = daysToNext == -1;
                        int      daysAtNext = daysOld + (isGrown ? 0 : daysToNext);

                        string ageDesc = isGrown
                                ? L10n.NpcChild.AgeDescriptionGrown(label: stage)
                                : L10n.NpcChild.AgeDescriptionPartial(label: stage, count: daysToNext, nextLabel: stage + 1);

                        yield return(new PercentageBarField(this.GameHelper, L10n.NpcChild.Age(), child.daysOld.Value, daysAtNext, Color.Green, Color.Gray, ageDesc));
                    }

                    // friendship
                    if (Game1.player.friendshipData.ContainsKey(child.Name))
                    {
                        FriendshipModel friendship = this.GameHelper.GetFriendshipForVillager(Game1.player, child, Game1.player.friendshipData[child.Name], metadata);
                        yield return(new CharacterFriendshipField(this.GameHelper, L10n.Npc.Friendship(), friendship, this.Text));

                        yield return(new GenericField(this.GameHelper, L10n.Npc.TalkedToday(), this.Stringify(Game1.player.friendshipData[child.Name].TalkedToToday)));
                    }
                }

                // villagers
                else
                {
                    // birthday
                    if (npc.Birthday_Season != null)
                    {
                        SDate birthday = new SDate(npc.Birthday_Day, npc.Birthday_Season);
                        yield return(new GenericField(this.GameHelper, L10n.Npc.Birthday(), this.Text.Stringify(birthday)));
                    }

                    // friendship
                    if (Game1.player.friendshipData.ContainsKey(npc.Name))
                    {
                        // friendship/romance
                        FriendshipModel friendship = this.GameHelper.GetFriendshipForVillager(Game1.player, npc, Game1.player.friendshipData[npc.Name], metadata);
                        yield return(new GenericField(this.GameHelper, L10n.Npc.CanRomance(), friendship.IsSpouse ? L10n.Npc.CanRomanceMarried() : this.Stringify(friendship.CanDate)));

                        yield return(new CharacterFriendshipField(this.GameHelper, L10n.Npc.Friendship(), friendship, this.Text));

                        // talked/gifted today
                        yield return(new GenericField(this.GameHelper, L10n.Npc.TalkedToday(), this.Stringify(friendship.TalkedToday)));

                        yield return(new GenericField(this.GameHelper, L10n.Npc.GiftedToday(), this.Stringify(friendship.GiftsToday > 0)));

                        // kissed today
                        if (friendship.IsSpouse)
                        {
                            yield return(new GenericField(this.GameHelper, L10n.Npc.KissedToday(), this.Stringify(npc.hasBeenKissedToday.Value)));
                        }

                        // gifted this week
                        if (!friendship.IsSpouse)
                        {
                            yield return(new GenericField(this.GameHelper, L10n.Npc.GiftedThisWeek(), L10n.Generic.Ratio(value: friendship.GiftsThisWeek, max: NPC.maxGiftsPerWeek)));
                        }
                    }
                    else
                    {
                        yield return(new GenericField(this.GameHelper, L10n.Npc.Friendship(), L10n.Npc.FriendshipNotMet()));
                    }

                    // gift tastes
                    var giftTastes = this.GetGiftTastes(npc, metadata);
                    yield return(new CharacterGiftTastesField(this.GameHelper, L10n.Npc.LovesGifts(), giftTastes, GiftTaste.Love));

                    yield return(new CharacterGiftTastesField(this.GameHelper, L10n.Npc.LikesGifts(), giftTastes, GiftTaste.Like));

                    yield return(new CharacterGiftTastesField(this.GameHelper, L10n.Npc.NeutralGifts(), giftTastes, GiftTaste.Neutral));
                }
                break;

            case TargetType.Pet:
                Pet pet = (Pet)npc;
                yield return(new CharacterFriendshipField(this.GameHelper, L10n.Pet.Love(), this.GameHelper.GetFriendshipForPet(Game1.player, pet), this.Text));

                yield return(new GenericField(this.GameHelper, L10n.Pet.PettedToday(), this.Stringify(this.Reflection.GetField <bool>(pet, "wasPetToday").GetValue())));

                break;

            case TargetType.Monster:
                // basic info
                Monster monster        = (Monster)npc;
                bool    canRerollDrops = Game1.player.isWearingRing(Ring.burglarsRing);

                yield return(new GenericField(this.GameHelper, L10n.Monster.Invincible(), L10n.Generic.Seconds(count: this.Reflection.GetField <int>(monster, "invincibleCountdown").GetValue()), hasValue: monster.isInvincible()));

                yield return(new PercentageBarField(this.GameHelper, L10n.Monster.Health(), monster.Health, monster.MaxHealth, Color.Green, Color.Gray, L10n.Generic.PercentRatio(percent: (int)Math.Round((monster.Health / (monster.MaxHealth * 1f) * 100)), value: monster.Health, max: monster.MaxHealth)));

                yield return(new ItemDropListField(this.GameHelper, L10n.Monster.Drops(), this.GetMonsterDrops(monster), fadeNonGuaranteed: true, crossOutNonGuaranteed: !canRerollDrops, defaultText: L10n.Monster.DropsNothing()));

                yield return(new GenericField(this.GameHelper, L10n.Monster.Experience(), this.Stringify(monster.ExperienceGained)));

                yield return(new GenericField(this.GameHelper, L10n.Monster.Defence(), this.Stringify(monster.resilience.Value)));

                yield return(new GenericField(this.GameHelper, L10n.Monster.Attack(), this.Stringify(monster.DamageToFarmer)));

                // Adventure Guild quest
                AdventureGuildQuestData adventureGuildQuest = metadata.GetAdventurerGuildQuest(monster.Name);
                if (adventureGuildQuest != null)
                {
                    int kills = adventureGuildQuest.Targets.Select(p => Game1.stats.getMonstersKilled(p)).Sum();
                    yield return(new GenericField(this.GameHelper, L10n.Monster.AdventureGuild(), $"{(kills >= adventureGuildQuest.RequiredKills ? L10n.Monster.AdventureGuildComplete() : L10n.Monster.AdventureGuildIncomplete())} ({L10n.Monster.AdventureGuildProgress(count: kills, requiredCount: adventureGuildQuest.RequiredKills)})"));
                }
                break;
            }
        }
Пример #24
0
        //Gets user full information
        public async Task <UserFullInformationModel> GetUserFullInformationAsync(int id)
        {
            Task <InformationModel> firstNameInfo   = _informationRepository.GetInformationByInformationNameAsync("FirstName");
            Task <InformationModel> lastNameInfo    = _informationRepository.GetInformationByInformationNameAsync("LastName");
            Task <InformationModel> emailInfo       = _informationRepository.GetInformationByInformationNameAsync("Email");
            Task <InformationModel> phoneNumberInfo = _informationRepository.GetInformationByInformationNameAsync("PhoneNumber");

            UserModel user = await GetUserByIdAsync(id);

            Task <UserInformationModel> firstName   = _userInformationRepository.GetUserInformationByIdAsync(user.Id, (await firstNameInfo).Id);
            Task <UserInformationModel> lastName    = _userInformationRepository.GetUserInformationByIdAsync(user.Id, (await lastNameInfo).Id);
            Task <UserInformationModel> email       = _userInformationRepository.GetUserInformationByIdAsync(user.Id, (await emailInfo).Id);
            Task <UserInformationModel> phoneNumber = _userInformationRepository.GetUserInformationByIdAsync(user.Id, (await phoneNumberInfo).Id);

            UserFullInformationModel fullInfo = new UserFullInformationModel();

            fullInfo.User.Id       = user.Id;
            fullInfo.User.Username = user.Username;
            fullInfo.User.Position = user.Position;
            fullInfo.User.Debt     = 0;
            fullInfo.Token         = user.Token;

            fullInfo.User.FirstName = (await firstName).Value;
            fullInfo.User.LastName  = (await lastName).Value;
            fullInfo.Email          = (await email).Value;
            fullInfo.PhoneNumber    = (await phoneNumber).Value;

            if (user.Position == (int)UserPosition.HasNotHome)
            {
                fullInfo.NumberOfFriends = 0;
                fullInfo.Friends         = null;
                fullInfo.HomeName        = null;
            }
            else
            {
                user = await GetUserByIdAsync(id, true);

                HomeModel home = await _homeRepository.GetByIdAsync(user.Home.Id, true);

                fullInfo.HomeName        = home.Name;
                fullInfo.NumberOfFriends = home.Users.Count - 1;

                foreach (var friend in home.Users)
                {
                    if (friend.Equals(user))
                    {
                        continue;
                    }

                    string friendFirstName = (await _userInformationRepository.GetUserInformationByIdAsync(friend.Id, (await firstNameInfo).Id)).Value;
                    string friendLastName  = (await _userInformationRepository.GetUserInformationByIdAsync(friend.Id, (await lastNameInfo).Id)).Value;

                    double          debt       = 0;
                    FriendshipModel friendship = await _friendshipRepository.GetFriendshipByIdAsync(user.Id, friend.Id);

                    if (friendship == null)
                    {
                        CustomException errors = new CustomException();
                        errors.AddError("Unexpected Error Occured", "Friendship does not exist");
                        errors.Throw();
                    }

                    if (friendship.User1.Id == user.Id)
                    {
                        debt = friendship.Debt;
                    }
                    else
                    {
                        debt = -friendship.Debt;
                    }

                    fullInfo.Friends.Add(new UserBaseModel(friend.Id, friend.Username, friend.Position, friendFirstName, friendLastName, debt));
                }
            }

            return(fullInfo);
        }