Esempio n. 1
0
        /// <summary>
        /// This method starts the calculation of the mission progress.
        /// It also notifies ProgressChanged event listeners.
        /// </summary>
        /// <param name="step"></param>
        private void OnTimeStep(int step)
        {
            if (mission.Paused)
            {
                return;
            }

            int completedSkills = mission.Progress.Count(s => s.Value >= 1f);

            foreach (var employee in employees)
            {
                List <SkillDefinition> skills = new List <SkillDefinition>(mission.Progress.Keys);
                foreach (var skill in skills)
                {
                    var value = mission.Progress[skill];
                    if (value >= 1.0f)
                    {
                        // Skill is already fulfilled
                        continue;
                    }

                    var newValue = WorkOnSkill(employee, skill, value, completedSkills);

                    mission.Progress[skill] = newValue;
                    mission.ProgressChanged.Invoke(new KeyValuePair <SkillDefinition, float>(skill, newValue));
                }
            }

            testMissionHooks();

            if (mission.Completed())
            {
                mission.Finish();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// This method is called when a mission finishes.
        /// It determines whether the mission is completed successfully or has failed.
        /// It also handles the payout as well as a possible reappearing of the mission.
        /// </summary>
        /// <param name="mission"></param>
        private void missionFinished(Mission mission)
        {
            data.InProgress.Remove(mission);
            InProgressMissionsChanged.Raise();
            missionWorkers[mission].Cleanup();
            missionWorkers.Remove(mission);
            mission.Cleanup();

            if (mission.Completed())
            {
                // Mission has completed successfully
                data.Completed.Add(mission);
                CompletedMissionsChanged.Raise();

                //Notification
                if (mission.GetSuccessText() != null && mission.GetSuccessText() != "")
                {
                    notificationManager.Success($"Mission: {mission.GetName()} completed! " +
                                                $"{mission.GetSuccessText()} You've earned: {mission.RewardMoney}$.");
                }
                else
                {
                    notificationManager.Success($"Mission: {mission.GetName()} completed! You've earned: {mission.RewardMoney}$.");
                }

                // Payout
                ContentHub.Instance.bank.Income(mission.RewardMoney);
            }
            else
            {
                // Mission has failed
                List <string> failedSkills = new List <string>();
                foreach (var skill in mission.Progress)
                {
                    if (skill.Value < 1f)
                    {
                        failedSkills.Add(skill.Key.skillName);
                    }
                }

                string failedSkillsText;
                if (failedSkills.Count > 1)
                {
                    failedSkillsText = "Skills ";

                    for (int i = 0; i < failedSkills.Count; i++)
                    {
                        if (i == failedSkills.Count - 1)
                        {
                            failedSkillsText += failedSkills[i] + " ";
                        }
                        else
                        {
                            failedSkillsText += failedSkills[i] + ", ";
                        }
                    }

                    failedSkillsText += "have failed.";
                }
                else
                {
                    failedSkillsText = "Skill " + failedSkills.First() + " has failed.";
                }

                //Notification
                if (mission.GetFailedText() != null && mission.GetFailedText() != "")
                {
                    notificationManager.Success($"Mission: {mission.GetName()} failed! " +
                                                $"{mission.GetFailedText()} " + failedSkillsText);
                }
                else
                {
                    notificationManager.Success($"Mission: {mission.GetName()} failed! " + failedSkillsText);
                }


                if (mission.Definition.Reappear)
                {
                    data.Available.Add(mission);
                }
            }
        }