Beispiel #1
0
 // Start is called before the first frame update
 public Hungry(BabyModel cow) : base(cow)
 {
     m_Condition.Add(0, 0f);
     m_Condition.Add(2, 0f);      // cow starts to get hungry after 2 hours
     m_Condition.Add(4, 0.75f);   // cow starts to get hungry after 2 hours
     m_Condition.Add(7 * 24, 1f); // after seven days of starvation cow dies
 }
Beispiel #2
0
        public async void RemoveBaby(BabyModel babyModel)
        {
            if (_currentProfile != null)
            {
                DataManager  dataManager  = DataManager.Instance;
                MediaManager mediaManager = MediaManager.Instance;

                _currentProfile.Babies.Remove(babyModel);

                if (_currentProfile.CurrentBaby == babyModel)
                {
                    _currentProfile.CurrentBaby = _currentProfile.Babies.FirstOrDefault();
                }

                if (babyModel.MediaId != Guid.Empty.ToString())
                {
                    await mediaManager.Remove(babyModel.MediaId);
                }

                // Remove child from Data Manager
                Children child = new Children()
                {
                    Id = babyModel.Id,
                };

                await dataManager.RemoveChild(child);
            }
        }
Beispiel #3
0
        public BabyModel CreateBaby()
        {
            BabyModel babyModel = new BabyModel();

            babyModel.Id = Guid.NewGuid().ToString();
            babyModel.PropertyChanged += BabyModel_PropertyChanged;
            return(babyModel);
        }
Beispiel #4
0
        private void ChildFeedingList_ListedSelector_ItemSelected(object sender, EventArgs e)
        {
            if (sender is ChildListedItem childFeedingListedItem)
            {
                if (childFeedingListedItem.BindingContext is BabyModel babyModel)
                {
                    _selectedbabyModel = babyModel;

                    BtnNext.IsEnabled = true;
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Gets called when this page is about to show and performs the initialization
        /// </summary>
        public override void AboutToShow()
        {
            base.AboutToShow();

            LeftPageType = CurrentDashboard();

            if (ProfileManager.Instance.CurrentProfile != null)
            {
                ProfileManager.Instance.CurrentProfile.CurrentBaby = null;
                BtnNext.IsEnabled  = false;
                _selectedbabyModel = null;
                _childFeedingList_ListedSelector.ItemsSource  = ProfileManager.Instance.CurrentProfile.Babies;
                _childFeedingList_ListedSelector.SelectedItem = null;
                ProfileManager.Instance.CurrentProfile.Babies.ForEach(baby => baby.IsSelected = false);
            }
        }
Beispiel #6
0
        public async void AddBaby(BabyModel babyModel)
        {
            if (_currentProfile != null)
            {
                try
                {
                    DataManager  dataManager  = DataManager.Instance;
                    MediaManager mediaManager = MediaManager.Instance;
                    Media        media        = null;

                    _currentProfile.Babies.Add(babyModel);

                    // If no current baby is set, make this the current baby as well
                    if (_currentProfile.CurrentBaby == null)
                    {
                        _currentProfile.CurrentBaby = babyModel;
                    }

                    if (babyModel.Picture != null)
                    {
                        media = mediaManager.CreateImageMedia(babyModel.Picture);
                        await mediaManager.Add(media);

                        babyModel.MediaId = media.Id;
                    }

                    Children child = new Children()
                    {
                        Id       = Guid.NewGuid().ToString(),
                        Name     = babyModel.Name,
                        Birthday = DateTime.Now
                    };

                    if (media != null)
                    {
                        child.MediaId = media.Id;
                    }

                    await dataManager.AddChild(child);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("Exception in AddBaby - " + e.Message);
                }
            }
        }
Beispiel #7
0
        private async void BabyModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (_currentProfile == null)
            {
                return;
            }

            BabyModel babyModel = (BabyModel)sender;

            if (e.PropertyName == "Picture")
            {
                babyModel = _currentProfile.CurrentBaby;

                if (babyModel != null)
                {
                    MediaManager mediaManager = MediaManager.Instance;

                    Media media = mediaManager.Get(babyModel.MediaId);

                    if (media == null)
                    {
                        // Insert
                        media = mediaManager.CreateImageMedia(babyModel.Picture);
                        await mediaManager.Add(media);

                        babyModel.MediaId = media.Id;
                    }
                    else
                    {
                        // Update
                        media.Image = babyModel.Picture;
                        await mediaManager.Update(media);
                    }
                }
            }
            else if (e.PropertyName == "IsSelected")
            {
                _currentProfile.CurrentBaby = babyModel;
            }
            else if (e.PropertyName == "IsDeleteRequested")
            {
                _currentProfile.ShowBabyDeleteAlert = babyModel.IsDeleteRequested;
            }

            BabyModelPropertyChanged?.Invoke(babyModel, e.PropertyName);
        }
Beispiel #8
0
        public async Task UpdateProfile()
        {
            string currentProfileId = CurrentProfile.ProfileId;

            if (CurrentProfile.CaregiverAccountSelected)
            {
                currentProfileId = CurrentProfile.CurrentCaregiver.ProfileId;
            }

            CurrentProfile.Babies.Clear();

            IEnumerable <Children> children = await DataManager.Instance.GetChildren(currentProfileId);

            foreach (Children child in children)
            {
                BabyModel babyModel = new BabyModel()
                {
                    Id       = child.Id,
                    Name     = child.Name,
                    Birthday = child.Birthday,
                };

                Media media = MediaManager.Instance.Get(child.MediaId);

                if (media != null)
                {
                    babyModel.Picture = media.Image;
                    babyModel.MediaId = media.Id;
                }

                babyModel.PropertyChanged += BabyModel_PropertyChanged;

                _currentProfile.Babies.Add(babyModel);

                if (_currentProfile.CurrentBaby == null)
                {
                    _currentProfile.CurrentBaby = babyModel;
                }
            }

            HistoryManager.Instance.Reset();
            await HistoryManager.Instance.Sync(currentProfileId);
        }
Beispiel #9
0
    public void AddBaby()
    {
        // Instantate a new cow view
        GameObject baby_view = Instantiate(m_BabyPrefab);

        baby_view.name = "Baby";

        // for some reason persistent object can not parent the instantiated objects
        if (null == m_BabyFolder)
        {
            m_BabyFolder = GameObject.Find("Babies");
        }

        baby_view.transform.parent = m_BabyFolder.transform;
        baby_view.SetActive(true);

        // instantiate a new cow model
        BabyModel baby_eng = GameManager.m_Instance.AddBaby(baby_view);

        // link the cow model with cow view
        baby_view.GetComponent <HomeObjectView>().Init(baby_eng);
    }
Beispiel #10
0
    protected float m_MinimumTreshold  = 0f; // Return 0 if below a threshold

    // Start is called before the first frame update
    public Condition(BabyModel baby)
    {
        m_Baby = baby;
    }
Beispiel #11
0
 void ResetHungry()
 {
     m_TargetBaby.IsNannyTarget = false;
     m_TargetBaby = null;
 }
Beispiel #12
0
    public new void Update()
    {
        // If task in progress, carry on
        switch (m_CurrentTask)
        {
        case Tasks.DIAPER:
            break;

        case Tasks.FEED:
            FeedBaby();
            // catch the baby
            // find empty feeding chair
            // carry it to feeding chair
            // done
            break;

        case Tasks.HUG:
            break;

        case Tasks.REMOVE:
            // Release baby from action post
            break;

        case Tasks.SLEEP:
            break;

        case Tasks.IDLE:
            //:TODO: add here moving away from previous action post
            NannyIdle();
            break;

        case Tasks.NONE:

            if (BabyManager.m_Instance.m_Babies.Count == 0)
            {
                return;
            }

            BabyModel top_prio_baby = null;

            // scan the babies in babymanager for most urgent need
            foreach (BabyModel baby in BabyManager.m_Instance.m_Babies)
            {
                if (!baby.IsNannyTarget && baby.NeedsReleaseFromActionPost)
                {
                    // :NOTE: Prioritize releasing babies from action posts in order to avoid deadlocks
                    // :NOTE: It is basically possible that nannies still get into deadlock, if they pick tasks, and action posts become filled.
                    // Nannies should be able to cancel tasks if they can not complete them
                    top_prio_baby = baby;
                    break;
                }

                // Do not target a baby that is already handled by another nanny
                if (!baby.IsNannyTarget && !baby.IsCarried && baby.m_Happy.GetState() < 0.5f && (top_prio_baby == null || baby.m_Happy.GetState() < top_prio_baby.m_Happy.GetState()))
                {
                    top_prio_baby = baby;
                }
            }

            // When baby selected pick a task
            if (null != top_prio_baby)
            {
                top_prio_baby.IsNannyTarget = true;

                m_TargetBaby = top_prio_baby;

                // Analyze the problem with this baby

                switch (top_prio_baby.m_CurrentPrimaryAction)
                {
                case BabyModel.PrioritizedPrimaryAction.ATTACK:
                    m_CurrentTask = Tasks.HUG;
                    break;

                case BabyModel.PrioritizedPrimaryAction.DRINK:
                    m_CurrentTask = Tasks.FEED;
                    break;

                case BabyModel.PrioritizedPrimaryAction.EAT:
                    m_CurrentTask = Tasks.FEED;
                    break;

                case BabyModel.PrioritizedPrimaryAction.ESCAPE:
                    m_CurrentTask = Tasks.HUG;
                    break;

                case BabyModel.PrioritizedPrimaryAction.SLEEP:
                    m_CurrentTask = Tasks.SLEEP;
                    break;

                case BabyModel.PrioritizedPrimaryAction.DIAPER:
                    m_CurrentTask = Tasks.DIAPER;
                    break;

                default:
                    m_TargetBaby.IsNannyTarget = false;
                    break;
                }
            }
            else
            {
                m_CurrentTask = Tasks.NONE;
            }
            break;
        }
    }
Beispiel #13
0
 public Pain(BabyModel cow) : base(cow)
 {
     m_Condition.Add(0, 0);
     m_Condition.Add(1, 1);
 }
Beispiel #14
0
        public async Task Sync()
        {
            User user = await DataManager.Instance.GetUser();

            //Profile profile = await DataManager.Instance.GetUserProfiles(LoginManager.Instance.UserId);
            Profile profile = await DataManager.Instance.GetUserProfiles(user.DefaultProfileId);

            MediaManager mediaManager = MediaManager.Instance;

            if ((user != null) && (profile != null))
            {
                IEnumerable <Children> children = await DataManager.Instance.GetChildren(profile.Id);

                BabyModel babyModel;
                string    userName = (user.Name != null) ? user.Name : Name;

                // These will be grabbed from LoginManager once it is finished
                if (_currentProfile == null)
                {
                    _currentProfile = new ProfileModel()
                    {
                        Name      = userName,
                        Email     = UserEmail,
                        ProfileId = profile.Id
                    };
                    _currentProfile.PropertyChanged += _currentProfile_PropertyChanged;

                    ProfilePropertyChanged?.Invoke(_currentProfile, nameof(CurrentProfile));
                }
                else if (_currentProfile.Name != userName || _currentProfile.Email != UserEmail)
                {
                    _currentProfile.Name             = userName;
                    _currentProfile.Email            = UserEmail;
                    _currentProfile.ProfileId        = profile.Id;
                    _currentProfile.PropertyChanged += _currentProfile_PropertyChanged;

                    ProfilePropertyChanged?.Invoke(_currentProfile, nameof(CurrentProfile));
                }

                foreach (Children child in children)
                {
                    var existing = _currentProfile.Babies.Where(c => c.Id == child.Id).FirstOrDefault();

                    if (existing == null)
                    {
                        babyModel = new BabyModel()
                        {
                            Id       = child.Id,
                            Name     = child.Name,
                            Birthday = child.Birthday,
                        };

                        Media media = mediaManager.Get(child.MediaId);

                        if (media != null)
                        {
                            babyModel.Picture = media.Image;
                            babyModel.MediaId = media.Id;
                        }

                        babyModel.PropertyChanged += BabyModel_PropertyChanged;

                        _currentProfile.Babies.Add(babyModel);

                        if (_currentProfile.CurrentBaby == null)
                        {
                            _currentProfile.CurrentBaby = babyModel;
                        }
                    }
                }

                await UpdateCaregivers();
            }
        }
 public void MoveBaby(BabyModel baby)
 {
     babies[baby.ID].transform.position = new Vector3(baby.Transform.X, baby.Transform.Y, baby.Transform.Z);
 }
Beispiel #16
0
 // Start is called before the first frame update
 public Lonely(BabyModel cow) : base(cow)
 {
     m_Condition.Add(0, 0f);
     m_Condition.Add(1800f, 1f);      // cow starts to get hungry after 2 hours
 }
Beispiel #17
0
 // Start is called before the first frame update
 public Happy(BabyModel baby) : base(baby)
 {
     m_Condition.Add(0, 0f);
     m_Condition.Add(1, 1f);      // cow starts to get hungry after 2 hours
 }
Beispiel #18
0
 // Start is called before the first frame update
 public Bored(BabyModel cow) : base(cow)
 {
     m_Condition.Add(0, 0f);
     m_Condition.Add(10, 1f);      // cow starts to get hungry after 2 hours
 }
    public void InstantiateBaby(BabyModel baby)
    {
        GameObject tmpBaby = Object.Instantiate(BabyPrefab, new Vector3(baby.Transform.X, baby.Transform.Y, baby.Transform.Z), Quaternion.identity, this.transform);

        babies[baby.ID] = tmpBaby;
    }