Exemple #1
0
        public ActionResult Invite(UserPet userpet, int id)
        {
            var user_inv = dba.Users.Where(x => x.UserName == userpet.user_name || x.UserName == userpet.user_email);

            if (user_inv.Count() == 1)
            {
                if (db.UserPets.Where(x => x.pet_id == id && x.isaccepted == true && (x.user_name == userpet.user_name || x.user_email == userpet.user_name)).Count() == 1)
                {
                    return(RedirectToAction("Invite", "Home", new { id = id, message = "Użytkownik (" + userpet.user_name + ") jest już właścicielem Twojego pupila." }));
                }
                else
                {
                    if (db.UserPets.Where(x => x.pet_id == id && x.isaccepted == false && (x.user_name == userpet.user_name || x.user_email == userpet.user_name)).Count() == 1)
                    {
                        return(RedirectToAction("Invite", "Home", new { id = id, message = "Użytkownik (" + userpet.user_name + ") został już zaproszony." }));
                    }
                    else
                    {
                        var up = db.UserPets.Add(new UserPet {
                            pet_id = id, user_id = user_inv.First().Id, user_name = user_inv.First().UserName, user_email = user_inv.First().Email, ismain = false, isaccepted = false
                        });
                        db.SaveChanges();
                        return(RedirectToAction("PetDetails", "Home", new { id = id }));
                    }
                }
            }
            else
            {
                return(RedirectToAction("Invite", "Home", new { id = id, message = "Podany użytkownik (" + userpet.user_name + ") nie istnieje." }));
            }
        }
Exemple #2
0
        /// <summary>
        /// 添加宠物
        /// </summary>
        /// <param name="info"></param>
        /// <param name="group"></param>
        /// <param name="account"></param>
        /// <param name="sex"></param>
        /// <param name="nickName"></param>
        public async Task <UserPet> AddPetAsync(PetInfo info, string group, string account, Gender sex, string nickName)
        {
            // 初始化宠物信息
            var pet = new UserPet()
            {
                Account   = account,
                Age       = 1,
                Attack    = info.Attack,
                Enable    = true,
                Face      = info.Face,
                Healthy   = 100,
                Group     = group,
                Intellect = info.Intellect,
                Mood      = 100,
                Quality   = RandQuality(),
                Sex       = sex,
                PetId     = info.Id,
                Name      = info.Name,
                NickName  = nickName
            };

            // 根据品质增长属性值
            IncrementPropByQuality(pet);

            // 添加信息
            PetContext.UserPets.Add(pet);

            // 保存信息
            await PetContext.SaveChangesAsync();

            return(pet);
        }
        /// <summary>
        /// Get all the actions done on a UserPet
        /// </summary>
        /// <param name="userPet">UserPet object</param>
        /// <returns>List of Action Objects</returns>

        public async Task <List <Action> > GetActionsListByUserPet(UserPet userPet)
        {
            if (userPet == null)
            {
                Console.WriteLine($"{nameof(ActionRepository)} - GetActionListByUserPet - BadRequest - Null UserPet");
                return(null);
            }

            return(await petGameDb.Actions.Where(a => a.UserPet == userPet).ToListAsync());
        }
 private UserPetModel CreateUserPetModel(UserPet userPet)
 {
     return(new UserPetModel
     {
         Id = userPet.Id,
         AnimalName = userPet.Pet.Name,
         DateOfBirth = userPet.DateOfBirth,
         Happiness = userPet.Happiness,
         Hunger = userPet.Hunger
     });
 }
Exemple #5
0
        public ActionResult AcceptInv(int id)
        {
            var userid = User.Identity.GetUserId();

            if (db.UserPets.Where(x => x.id == id && x.user_id == userid).Count() == 0)
            {
                return(RedirectToAction("Index", "Home"));
            }

            UserPet userpet = db.UserPets.Where(x => x.id == id).First();

            userpet.isaccepted = true;
            db.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
Exemple #6
0
        /// <summary>
        /// Updates the hunger and happiness values of a pet based on the last time it was updated and the feeding and stroking values.
        /// </summary>
        /// <param name="pet">Object of the UserPet</param>
        /// <param name="feedingValue">Int value to decrease the Hunger of the pet.</param>
        /// <param name="strokingValue">Int value to increase the Happiness of the pet.</param>
        /// <returns>Updated object of the UserPet</returns>
        public async Task <UserPet> UpdatePetStatus(UserPet pet, int feedingValue, int strokingValue)
        {
            if (pet == null)
            {
                Console.WriteLine($"{nameof(UserPetService)} - UpdatePetStatus - Pet is null.");
                return(null);
            }

            var minutesSinceLastUpdate = (int)DateTimeOffset.UtcNow.Subtract(pet.LastUpdate).TotalMinutes;;

            pet.Hunger    = CalculatePetHunger(minutesSinceLastUpdate, pet.Pet.HungerRatio, feedingValue, pet.Hunger);
            pet.Happiness = CalculatePetHappiness(minutesSinceLastUpdate, pet.Pet.HappinessRatio, strokingValue,
                                                  pet.Happiness);

            return(await userPetRepo.UpdateUserPet(pet));
        }
        /// <summary>
        /// Create a new action on the database.
        /// </summary>
        /// <param name="userPet">UserPet object</param>
        /// <param name="actionType">ActionType enum</param>
        /// <returns>Object for the created action</returns>
        public async Task <Action> CreateAction(UserPet userPet, ActionTypeEnum actionType)
        {
            if (userPet == null)
            {
                Console.WriteLine($"{nameof(ActionRepository)} - CreateAction - BadRequest - Null UserPet");
                return(null);
            }

            var action = new Action {
                ActionType = actionType, UserPet = userPet, Date = DateTimeOffset.UtcNow
            };

            await petGameDb.Actions.AddAsync(action);

            await petGameDb.SaveChangesAsync();

            return(action);
        }
Exemple #8
0
        public ActionResult CancelInv(int id, int petid = 0)
        {
            var userid = User.Identity.GetUserId();

            if (db.UserPets.Where(x => x.id == id && x.user_id == userid).Count() == 0)
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (db.UserPets.Where(x => x.id == id && x.ismain == true).Count() == 1)
            {
                return(RedirectToAction("PetDetails", "Home", new { id = petid, message = "Aby opuścić pupila, musisz najpierw zmienić głównego właściciela." }));
            }

            UserPet userpet = db.UserPets.Where(x => x.id == id).First();

            db.UserPets.Remove(userpet);
            db.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
        public void Given_an_existing_User_and_Pet_UserPets_can_be_persisted_and_retrieved()
        {
            //Arrange
            var sutProvider  = new DataProvider <UserPet>(_config, UserPet.ToDomainConverter);
            var columns      = sutProvider.LoadAllColumns();
            var sutPersister = new UserPetPersister(columns, _config);

            //Database row dependencies
            var animal = TestData.Animals.Chihuahua;
            var user   = TestData.Users.NewMeJulie;

            ErrorMessage error;

            if (!PersistAnimal(out error, ref animal))
            {
                Assert.Fail(error.Message);
            }

            if (!PersistUser(out error, ref user))
            {
                Assert.Fail(error.Message);
            }

            var pet = new Pet(animal.AnimalId, "Princess");

            if (!PersistPet(out error, ref pet))
            {
                Assert.Fail(error.Message);
            }

            //Create the user pet join with the returned foreign keys
            var userPetRecord = new UserPet(user.UserId, pet.PetId, DateTime.UtcNow);
            var persistResult = sutPersister.TryPersist(ref userPetRecord, out error);

            //Assert
            Assert.IsTrue(persistResult);
            Assert.IsNull(error);
            var readResult = sutProvider.LoadAll().First();

            Assert.AreEqual(userPetRecord, readResult);
        }
        /// <summary>
        /// Creates a new UserPet.
        /// </summary>
        /// <param name="user">Object of the User</param>
        /// <param name="pet">Object of the Pet</param>
        /// <returns>Object of the created UserPet</returns>
        public async Task <UserPet> CreateUserPet(User user, Pet pet)
        {
            if (user == null || pet == null)
            {
                return(null);
            }

            var userPet = new UserPet
            {
                DateOfBirth = DateTimeOffset.UtcNow,
                Happiness   = 100,
                Hunger      = 0,
                LastUpdate  = DateTimeOffset.UtcNow,
                User        = user,
                Pet         = pet
            };

            await petGameDb.UserPets.AddAsync(userPet);

            await petGameDb.SaveChangesAsync();

            return(userPet);
        }
        /// <summary>
        /// Saves into the database an update of a UserPet
        /// </summary>
        /// <param name="userPetModified">Object of UserPet</param>
        /// <returns>Saved object of the UserPet</returns>
        public async Task <UserPet> UpdateUserPet(UserPet userPetModified)
        {
            if (userPetModified.User == null || userPetModified.Pet == null)
            {
                return(null);
            }

            var userPet = await petGameDb.UserPets.FirstOrDefaultAsync(u => u.Id == userPetModified.Id);

            petGameDb.UserPets.Attach(userPet);
            if (userPet == null)
            {
                return(null);
            }

            userPet.Happiness  = userPetModified.Happiness;
            userPet.Hunger     = userPetModified.Hunger;
            userPet.LastUpdate = DateTimeOffset.UtcNow;

            petGameDb.Entry(userPet).State = EntityState.Modified;
            await petGameDb.SaveChangesAsync();

            return(userPet);
        }
Exemple #12
0
 /// <summary>
 /// 根据品质增长属性
 /// </summary>
 /// <param name="userPet"></param>
 private UserPet IncrementPropByQuality(UserPet userPet)
 {
     userPet.Attack    = userPet.Quality + _random.Next(userPet.Quality * 10);
     userPet.Intellect = userPet.Quality + _random.Next(userPet.Quality * 5);
     return(userPet);
 }
Exemple #13
0
        /// <summary>
        /// Creates an action.
        /// </summary>
        /// <param name="actionType">Action Type</param>
        /// <param name="userPet">Object of the UserPet</param>
        /// <returns>Object of the created Action</returns>
        public async Task <Domain.Entity.Action> CreateAction(ActionTypeEnum actionType, UserPet userPet)
        {
            if (userPet == null)
            {
                Console.WriteLine($"{nameof(ActionService)} - CreateAction - User Pet is null");
                return(null);
            }

            return(await actionRepo.CreateAction(userPet, actionType));
        }
Exemple #14
0
        static void Main(string[] args)
        {
            #region Intro
            // Creates a loop to first run the intro, then breaks the loop once it is over
            do
            {
                Console.WriteLine("Virtual Spouse: Welcome ho-- what in the holy blazes is THAT thing?");
                Console.WriteLine("Virtual Spouse: You brought home a... pet? A Camogatchi? Is that something Japanese?");
                Console.WriteLine("Virtual Spouse: Whatever, I'm not taking care of it. What will you name it, anyways?");

                // Assigns the user input to the userPetName string
                userPetName = Console.ReadLine();

                Console.WriteLine("Virtual Spouse: Well... just take care of your " + userPetName + ".");

                introDone = true;
            } while (introDone == false);
            #endregion


            // creates a new instance of the class UserPet using only the name modifier
            UserPet yourPet = new UserPet(userPetName);
            // Declares an array of strings for the menu options
            string[] options        = new string[] { "1. Feed", "2. Send Outside", "3. Play Together", "4. Do Nothing", "5. Exit" };
            int      pointOfLifeNum = 0;
            string   pointOfLifeStr = String.Empty;

            #region Menu Loop
            // creates an infinite loop that introduces menu options and runs them
            for (int i = 1; i < (i + 2); i++)
            {
                //Sets the point of life to the variable i
                pointOfLifeNum = i;

                // Caps the hunger of the pet to 100
                if (yourPet.Hunger > 100)
                {
                    yourPet.Hunger = 100;
                }

                // Caps the waste of the pet to 0
                if (yourPet.Waste < 0)
                {
                    yourPet.Waste = 0;
                }

                // Caps the play of the pet to 100
                if (yourPet.Play > 100)
                {
                    yourPet.Play = 100;
                }

                if (pointOfLifeNum >= 0 & pointOfLifeNum <= 33)
                {
                    pointOfLifeStr = yourPet.PointOfLife[0];
                }

                else if (pointOfLifeNum >= 34 & pointOfLifeNum <= 66)
                {
                    pointOfLifeStr = yourPet.PointOfLife[1];
                }

                else if (pointOfLifeNum >= 65)
                {
                    pointOfLifeStr = yourPet.PointOfLife[2];
                }



                // Menu options are stated
                Console.WriteLine("What will you do? Choose a number:");
                Console.WriteLine(userPetName + " a is a " + pointOfLifeStr + ".");
                Console.WriteLine("Hunger = " + yourPet.Hunger);
                Console.WriteLine("waste = " + yourPet.Waste);
                Console.WriteLine("Boredom = " + yourPet.Play);

                // Writes to the console each element of the array options
                foreach (string option in options)
                {
                    Console.WriteLine(option);
                }

                // Collects the users input
                int userChoice = int.Parse(Console.ReadLine());

                #region ChoiceSwitches
                // Creates a switch of conditions that run depending on the users response
                switch (userChoice)
                {
                case 1:
                    Console.WriteLine("You fed " + userPetName + "a delicious meal! They seem rather happy.");
                    yourPet.Feed();
                    break;

                case 2:
                    Console.WriteLine("You took " + userPetName + "outside to relieve themself. They seem much more comfortable!");
                    yourPet.Relieve();
                    break;

                case 3:
                    Console.WriteLine("You played with " + userPetName + "for a few hours. They seem highly amused!");
                    yourPet.Entertain();
                    break;

                case 4:
                    Console.WriteLine("You decide to leave " + userPetName + "alone for now. They look quite confused.");
                    yourPet.Nothing();
                    break;

                case 5:
                    Console.WriteLine("Exiting Virtual Pet Camogatchi. Good-Bye!");
                    Console.ReadKey();
                    exitConsole = true;
                    break;

                default:
                    Console.WriteLine("That is not an option. Choose one next time.");
                    yourPet.Nothing();
                    break;
                }
                #endregion


                if (exitConsole == true)
                {
                    break;
                }
                // Runs the UserPet Even method
                else if (i % 2 == 0)
                {
                    yourPet.Event();
                }
            }
            #endregion
        }