public void ProcessTurn(IHub services)
        {
            var personService = services.Resolve<IPersonService>();

            var gameClockService = services.Resolve<IGameClockService>();

            foreach(var person in personService.People.Where(p => !personService.IsRetired(p)))
            {
                if (person.RetirementDate > gameClockService.CurrentDate)
                {
                    continue;
                }

                var currentWorkHistory = person.WorkHistory.FirstOrDefault(wh => !wh.EndDate.HasValue);

                if(currentWorkHistory != null)
                {
                    var employee = currentWorkHistory.Company.GetEmployee(person.Id);

                    if(!employee.IsFounder)
                    {
                        currentWorkHistory.EndDate = gameClockService.CurrentDate;

                        currentWorkHistory.EndingSalary = employee.Salary;
                    }
                }
            }
        }
        public void ProcessTurn(IHub services)
        {
            var companyService = services.Resolve<ICompanyService>();

            var gameClockService = services.Resolve<IGameClockService>();

            foreach(var company in companyService.Companies)
            {
                foreach(var project in company.Projects)
                {
                    if (IsProjectComplete(project))
                    {
                        CompleteProject(company, project);

                        companyService.ProcessTransaction(company, TransactionType.Project, project.Value, $"Completed {project.Definition.Name} project.");

                    }
                    else
                    {
                        var deadline = project.ExtensionDeadline.HasValue ?
                                       project.ExtensionDeadline.Value :
                                       project.Deadline;

                        if (gameClockService.CurrentDate >= deadline)
                        {
                            FailProject(company, project);
                        }
                    }
                }
            }
        }
        public IEnumerable<IActionData> GenerateData(IHub services, Company company)
        {
            var actionData = new List<IActionData>();

            var recruitAction = company.Actions.FirstOrDefault(a => a.Action.Id == (byte)ActionType.RecruitPerson);

            if (recruitAction.Count == 0)
            {
                return actionData;
            }

            var founder = company.Employees.FirstOrDefault(e => e.IsFounder);

            var configurationService = services.Resolve<IConfigurationService>();

            var fastGrowth = configurationService.GetDecimalValue(ConfigurationKey.FastCompanyGrowthValue, ConfigurationFallbackValue.FastCompanyGrowthValue);

            var growthTarget = founder.Person.GetPersonalityValue(PersonalityAttributeId.DesiredCompanyGrowth);

            var growthImportance = founder.Person.GetPersonalityValue(PersonalityAttributeId.CompanyGrowthImportance);

            var targetNumberOfProspects = fastGrowth * growthTarget;

            var maxDifferential = fastGrowth * (1m - growthImportance);

            var differential = (int)(targetNumberOfProspects - company.Prospects.Count);

            if (differential <= maxDifferential)
            {
                return actionData;
            }

            var personService = services.Resolve<IPersonService>();

            var recruitCount = recruitAction.Count;

            var recruitTargetCount = targetNumberOfProspects - maxDifferential;

            while (recruitCount-- > 0 &&
                 (company.Prospects.Count + actionData.Count) < recruitTargetCount)
            {
                var person = personService.GetUnemployedPerson();

                actionData.Add(new RecruitPersonActionData(person.Id));
            }

            return actionData;
        }
Beispiel #4
0
        public OfferResponseReason? Evaluate(IHub services, Company company, Person person, decimal amount)
        {
            var perkService = services.Resolve<IPerkService>();

            var applicablePerkCount = company.Perks.Count(cp => cp.Count > 0 && perkService.DoesPerkApplyTo(cp.Perk, person));

            var personService = services.Resolve<IPersonService>();

            var minimumPerkCount = person.GetPersonalityValue(PersonalityAttributeId.MinimumPerkCount);

            if(minimumPerkCount <= applicablePerkCount)
            {
                return null;
            }

            return OfferResponseReason.Perks;
        }
        public void ProcessTurn(IHub services)
        {
            var personService = services.Resolve<IPersonService>();

            var configurationService = services.Resolve<IConfigurationService>();

            var minimumPersonCount = configurationService.GetIntValue(ConfigurationKey.MinimumPersonCount, ConfigurationFallbackValue.MinimumPersonCount);

            var nonRetiredPersonCount = personService.People.Count(p => !personService.IsRetired(p));

            var numberOfPeopleToGenerate = minimumPersonCount - nonRetiredPersonCount;

            if(numberOfPeopleToGenerate > 0)
            {
                personService.GeneratePeople(numberOfPeopleToGenerate);
            }
        }
        public override CompanyMessage ProcessEvent(Company company, IActionData eventData, IHub services)
        {
            var data = eventData as MakeOfferActionData;

            var personService = services.Resolve<IPersonService>();

            var companyService = services.Resolve<ICompanyService>();

            var person = personService.GetPerson(data.PersonId);

            var gameClockService = services.Resolve<IGameClockService>();

            var message = new CompanyMessage
            {
                Id = Utilities.InvalidId,
                DateCreated = gameClockService.CurrentDate,
                Status = CompanyMessageStatus.UnRead,
                Source = "Human Resources"
            };

            if (personService.IsUnemployed(person))
            {
                var response = companyService.MakeOffer(company, person, data.OfferValue);

                if (response.DidAccept)
                {
                    message.Subject = "Offer Accepted";

                    message.Message = $"{person.FirstName} {person.LastName} accepted an offer of {data.OfferValue:C}.";
                }
                else
                {
                    message.Subject = "Offer Declined";

                    message.Message = $"{person.FirstName} {person.LastName} declined an offer of {data.OfferValue:C}.";
                }
            }
            else
            {
                message.Subject = "Offer Too Late";

                message.Message = $"{person.FirstName} {person.LastName} recently accepted an offer elsewhere.";
            }

            return message;
        }
        public void ProcessTurn(IHub services)
        {
            var projectService = services.Resolve<IProjectService>();

            var configurationService = services.Resolve<IConfigurationService>();

            var minimumProjectCount = configurationService.GetIntValue(ConfigurationKey.MinimumProjectCount, ConfigurationFallbackValue.MinimumProjectCount);

            var numberOfProjectsToGenerate = minimumProjectCount - projectService.Projects.Count();

            if (numberOfProjectsToGenerate > 0)
            {
                var gameService = services.Resolve<IGameService>();

                projectService.GenerateProjects(gameService.CurrentIndustry, numberOfProjectsToGenerate);
            }
        }
        public override CompanyMessage ProcessEvent(Company company, IActionData eventData, IHub services)
        {
            var data = eventData as AcceptProjectActionData;

            var projectService = services.Resolve<IProjectService>();

            var project = projectService.GetProject(data.ProjectId);

            var gameClockService = services.Resolve<IGameClockService>();

            var message = new CompanyMessage
            {
                Id = Utilities.InvalidId,
                DateCreated = gameClockService.CurrentDate,
                Source = "Project Management",
                Status = CompanyMessageStatus.UnRead
            };

            if (project != null)
            {
                if (projectService.CanAcceptProject(project, company.Reputation))
                {
                    var companyService = services.Resolve<ICompanyService>();

                    companyService.AcceptProject(company, project);

                    message.Subject = "We got the project!";

                    message.Message = $"We have been granted the {project.Definition.Name} project.";
                }
                else
                {
                    message.Subject = "We did not get the project...";

                    message.Message = $"We were deemed not reputable enough to be granted the {project.Definition.Name} project.";
                }
            }
            else
            {
                message.Subject = "We missed out on the project.";

                message.Message = $"A project we were seeking has been given to another company.";
            }

            return message;
        }
        public void ProcessTurn(IHub services)
        {
            var companyService = services.Resolve<ICompanyService>();

            foreach(var company in companyService.Companies)
            {
                var accumulations = new Dictionary<int, decimal>();

                foreach (var employee in company.Employees)
                {
                    var allocations = company.Allocations.Where(a => a.Employee == employee);

                    var skillValues = new Dictionary<int, decimal>();

                    var remainingSkillValues = new Dictionary<int, decimal>();

                    foreach (var skill in employee.Person.Skills)
                    {
                        var skillValue = CalculateEmployeeSkillValue(employee, skill);

                        skillValues.Add(skill.SkillDefinition.Id, skillValue);

                        remainingSkillValues.Add(skill.SkillDefinition.Id, skillValue);
                    }

                    foreach (var allocation in allocations)
                    {
                        foreach (var requirement in allocation.Project.Requirements)
                        {
                            if (skillValues.ContainsKey(requirement.SkillDefinition.Id))
                            {
                                var value = allocation.Percent * skillValues[requirement.SkillDefinition.Id];

                                requirement.CurrentValue += value;

                                remainingSkillValues[requirement.SkillDefinition.Id] -= value;
                            }
                        }
                    }

                    foreach (var skill in remainingSkillValues)
                    {
                        if (accumulations.ContainsKey(skill.Key))
                        {
                            accumulations[skill.Key] += skill.Value;
                        }
                        else
                        {
                            accumulations.Add(skill.Key, skill.Value);
                        }
                    }
                }

                ProcessActionAccumulations(company, accumulations);
            }
        }
        public override ActionExecutionInformation CanPerformEvent(Company company, IActionData eventData, IHub services)
        {
            var companyService = services.Resolve<ICompanyService>();

            if (!companyService.CanPerformAction(company, Type))
            {
                return new ActionExecutionInformation(false, $"Company {company.Id} cannot perform turn action {Type}.", company);
            }

            return new ActionExecutionInformation(true);
        }
Beispiel #11
0
        public OfferResponseReason? Evaluate(IHub services, Company company, Person person, decimal amount)
        {
            var personService = services.Resolve<IPersonService>();

            var expectedCompensation = personService.CalculateCompensationValue(person);

            if(amount >= expectedCompensation)
            {
                return null;
            }

            return OfferResponseReason.OfferValue;
        }
        public override ActionExecutionInformation CanPerformEvent(Company company, IActionData eventData, IHub services)
        {
            var companyService = services.Resolve<ICompanyService>();

            if (!companyService.CanPerformAction(company, Type))
            {
                return new ActionExecutionInformation(false, $"Company {company.Id} cannot perform turn action {Type}.", company);
            }

            var data = eventData as PurchasePerkActionData;

            var perkService = services.Resolve<IPerkService>();

            var perk = perkService.GetPerk(data.PerkId);

            if(!perkService.CanPurchasePerk(company, perk, data.Count))
            {
                return new ActionExecutionInformation(false, $"Company {company.Id} cannot purchase {data.Count} of perk {perk.Id}.", company, data);
            }

            return new ActionExecutionInformation(true);
        }
        public override CompanyMessage ProcessEvent(Company company, IActionData eventData, IHub services)
        {
            var data = eventData as RecruitPersonActionData;

            var personService = services.Resolve<IPersonService>();

            var companyService = services.Resolve<ICompanyService>();

            var person = personService.GetPerson(data.PersonId);

            var gameClockService = services.Resolve<IGameClockService>();

            var message = new CompanyMessage
            {
                Id = Utilities.InvalidId,
                DateCreated = gameClockService.CurrentDate,
                Status = CompanyMessageStatus.UnRead,
                Source = "Human Resources"
            };

            if(personService.IsUnemployed(person))
            {
                companyService.RecruitPerson(company, person);

                message.Subject = "Recruited Candidate";

                message.Message = $"We have successfully recruited {person.FirstName} {person.LastName}.";
            }
            else
            {
                message.Subject = "Missed a Potential Recruit";

                message.Message = $"{person.FirstName} {person.LastName} has been recently employed and cannot be recruited at this time.";
            }

            return message;
        }
        public override CompanyMessage ProcessEvent(Company company, IActionData eventData, IHub services)
        {
            var data = eventData as InterviewProspectActionData;

            var companyService = services.Resolve<ICompanyService>();

            var prospect = company.GetProspect(data.PersonId);

            var personService = services.Resolve<IPersonService>();

            var gameClockServices = services.Resolve<IGameClockService>();

            var message = new CompanyMessage
            {
                Id = Utilities.InvalidId,
                DateCreated = gameClockServices.CurrentDate,
                Status = CompanyMessageStatus.UnRead,
                Source = "Human Resources"
            };

            if(personService.IsUnemployed(prospect.Person))
            {
                companyService.InterviewProspect(company, prospect);

                message.Subject = "Interview Complete";

                message.Message = $"{prospect.Person.FirstName} {prospect.Person.LastName} has completed a round of interviews.";
            }
            else
            {
                message.Subject = "Prospect Off the Market";

                message.Message = $"{prospect.Person.FirstName} {prospect.Person.LastName} has recently accepted an offer elsewhere.";
            }

            return message;
        }
Beispiel #15
0
        public override ActionExecutionInformation CanPerformEvent(Company company, IActionData eventData, IHub services)
        {
            var companyService = services.Resolve<ICompanyService>();

            if(!companyService.CanPerformAction(company, Type))
            {
                return new ActionExecutionInformation(false, $"Company {company.Id} cannot perform turn action {Type}.", company);
            }

            var data = eventData as SellPerkActionData;

            var perkService = services.Resolve<IPerkService>();

            var perk = perkService.GetPerk(data.PerkId);

            var companyPerk = company.GetPerk(perk);

            if(companyPerk.Count < data.Count)
            {
                return new ActionExecutionInformation(false, $"Company {company.Id} cannot sell {data.Count} perks (ID: {perk.Id}).", perk, company);
            }

            return new ActionExecutionInformation(true);
        }
        public override CompanyMessage ProcessEvent(Company company, IActionData eventData, IHub services)
        {
            var data = eventData as PurchasePerkActionData;

            var perkService = services.Resolve<IPerkService>();

            var perk = perkService.GetPerk(data.PerkId);

            var companyService = services.Resolve<ICompanyService>();

            companyService.PurchasePerk(company, perk, data.Count);

            var gameClockService = services.Resolve<IGameClockService>();

            return new CompanyMessage
            {
                Id = Utilities.InvalidId,
                DateCreated = gameClockService.CurrentDate,
                Status = CompanyMessageStatus.UnRead,
                Source = "Finance",
                Subject = "Purchase Made",
                Message = $"Purchased {data.Count} {perk.Name} perks."
            };
        }
        public override CompanyMessage ProcessEvent(Company company, IActionData eventData, IHub services)
        {
            var data = eventData as AdjustSalaryActionData;

            var companyService = services.Resolve<ICompanyService>();

            var employee = company.GetEmployee(data.PersonId);

            var previousSalary = employee.Salary;

            companyService.AdjustSalary(company, employee, data.Salary);

            var gameClockService = services.Resolve<IGameClockService>();

            return new CompanyMessage
            {
                Id = Utilities.InvalidId,
                DateCreated = gameClockService.CurrentDate,
                Status = CompanyMessageStatus.UnRead,
                Source = "Human Resources",
                Subject = "Employee Salary Adjustment",
                Message = $"{employee.Person.FirstName} {employee.Person.LastName}'s salary has been adjust from {previousSalary:C} to {employee.Salary:C}."
            };
        }
        public override CompanyMessage ProcessEvent(Company company, IActionData eventData, IHub services)
        {
            var data = eventData as AdjustAllocationActionData;

            var employee = company.GetEmployee(data.PersonId);

            var project = company.GetProject(data.ProjectId);

            var companyService = services.Resolve<ICompanyService>();

            companyService.AdjustAllocation(company, employee, project, data.Percentage, data.Role);

            var gameClockService = services.Resolve<IGameClockService>();

            return new CompanyMessage
            {
                Id = Utilities.InvalidId,
                DateCreated = gameClockService.CurrentDate,
                Status = CompanyMessageStatus.UnRead,
                Source = "Project Management",
                Subject = "Employee has been reallocated.",
                Message = $"{employee.Person.FirstName} {employee.Person.LastName} has been directed to work on {project.Definition.Name} {data.Percentage:P} in a {data.Role} role."
            };
        }
        public void ProcessTurn(IHub services)
        {
            var companyService = services.Resolve<ICompanyService>();

            foreach(var company in companyService.Companies)
            {
                foreach(var employee in company.Employees)
                {
                    if (!employee.IsFounder && employee.Salary != 0)
                    {
                        companyService.ProcessTransaction(company, TransactionType.Payroll, -employee.Salary, $"Paid {employee.Person.FirstName} {employee.Person.LastName} {employee.Salary:C}.");
                    }
                }
            }
        }
        public void ProcessTurn(IHub services)
        {
            var companyService = services.Resolve<ICompanyService>();

            foreach(var company in companyService.Companies)
            {
                foreach (var perk in company.Perks)
                {
                    var cost = perk.Count * perk.Perk.RecurringCost;

                    var message = $"Charged {cost:C} for {perk.Count} {perk.Perk.Name} perks.";

                    companyService.ProcessTransaction(company, TransactionType.Perk, -cost, message);
                }
            }
        }
        public override ActionExecutionInformation CanPerformEvent(Company company, IActionData eventData, IHub services)
        {
            var companyService = services.Resolve<ICompanyService>();

            if (!companyService.CanPerformAction(company, Type))
            {
                return new ActionExecutionInformation(false, $"Company {company.Id} cannot perform turn action {Type}.", company);
            }

            var data = eventData as AdjustSalaryActionData;

            if (data.Salary < 0)
            {
                return new ActionExecutionInformation(false, $"Cannot have a negative employee value.", company, data.Salary);
            }

            return new ActionExecutionInformation(true);
        }
Beispiel #22
0
        public override ActionExecutionInformation CanPerformEvent(Company company, IActionData eventData, IHub services)
        {
            var companyService = services.Resolve<ICompanyService>();

            if (!companyService.CanPerformAction(company, Type))
            {
                return new ActionExecutionInformation(false, $"Company {company.Id} cannot perform turn action {Type}.", company);
            }

            var data = eventData as MakeOfferActionData;

            if(company.Money < data.OfferValue)
            {
                return new ActionExecutionInformation(false, $"Company {company.Id} does not have {data.OfferValue:C} for this offer.", company, data);
            }

            if (data.OfferValue < 0)
            {
                return new ActionExecutionInformation(false, $"Cannot offer negative amounts of money.", company, data);
            }

            return new ActionExecutionInformation(true);
        }
        public OfferResponseReason? Evaluate(IHub services, Company company, Person person, decimal amount)
        {
            var configurationService = services.Resolve<IConfigurationService>();

            var largeCompanySize = configurationService.GetIntValue(ConfigurationKey.LargeCompanySize, ConfigurationFallbackValue.LargeCompanySize);

            var weight = Math.Min((decimal)company.Employees.Count / (decimal)largeCompanySize, 1m);

            var desiredSize = person.GetPersonalityValue(PersonalityAttributeId.DesiredCompanySize);

            var importance = person.GetPersonalityValue(PersonalityAttributeId.CompanySizeImportance);

            var differential = Math.Abs(desiredSize - weight) * importance;

            var maxDifferential = configurationService.GetDecimalValue(ConfigurationKey.CompanySizeMaxDifferential, ConfigurationFallbackValue.CompanySizeMaxDifferential);

            if (differential <= maxDifferential)
            {
                return null;
            }

            return OfferResponseReason.CompanySize;
        }
        public OfferResponseReason? Evaluate(IHub services, Company company, Person person, decimal amount)
        {
            var configurationService = services.Resolve<IConfigurationService>();

            var fastCompanyGrowth = configurationService.GetIntValue(ConfigurationKey.FastCompanyGrowthValue, ConfigurationFallbackValue.FastCompanyGrowthValue);

            var weight = Math.Min((decimal)company.Prospects.Count / (decimal)fastCompanyGrowth, 1m);

            var desiredGrowth = person.GetPersonalityValue(PersonalityAttributeId.DesiredCompanyGrowth);

            var importance = person.GetPersonalityValue(PersonalityAttributeId.CompanyGrowthImportance);

            var differential = Math.Abs(desiredGrowth - weight) * importance;

            var maxDifferential = configurationService.GetDecimalValue(ConfigurationKey.CompanyGrowthMaxDifferential, ConfigurationFallbackValue.CompanyGrowthMaxDifferential);

            if (differential <= maxDifferential)
            {
                return null;
            }

            return OfferResponseReason.CompanyGrowth;
        }
        public OfferResponseReason? Evaluate(IHub services, Company company, Person person, decimal amount)
        {
            var workload = 0m;

            if (company.Employees.Any())
            {
                workload = (decimal)company.Projects.Count / (decimal)company.Employees.Count;
            }

            var personService = services.Resolve<IPersonService>();

            var minWorkload = person.GetPersonalityValue(PersonalityAttributeId.MinimumDesiredEmployeeWorkload);

            var maxWorkload = person.GetPersonalityValue(PersonalityAttributeId.MaximumDesiredEmployeeWorkload);

            if (workload >= minWorkload &&
                workload <= maxWorkload)
            {
                return null;
            }

            return OfferResponseReason.EmployeeWorkload;
        }
        public void ProcessTurn(IHub services)
        {
            var gameClockService = services.Resolve<IGameClockService>();

            gameClockService.ProcessTurn();
        }
Beispiel #27
0
        public static Employee GetRandomUserCompanyEmployee(IHub services, bool excludeFounder = true)
        {
            var companyService = services.Resolve<ICompanyService>();

            var company = companyService.UserCompany;

            Employee output = null;

            if(excludeFounder)
            {
                output = company.Employees.Random(e => !e.IsFounder);
            }
            else
            {
                output = company.Employees.Random();
            }

            return output;
        }
Beispiel #28
0
        public static Employee GetUserCompanyEmployee(IHub services, int personId)
        {
            var companyService = services.Resolve<ICompanyService>();

            var company = companyService.UserCompany;

            return company.GetEmployee(personId);
        }
Beispiel #29
0
        public static CompanyServiceData CreateNewGame(IHub services, int gameId, int companyCount)
        {
            var personRepository = services.Resolve<IPersonRepository>();

            var personService = services.Resolve<IPersonService>();

            var projectRepository = services.Resolve<IProjectRepository>();

            var projectService = services.Resolve<IProjectService>();

            var perkService = services.Resolve<IPerkService>();

            var companyRepository = services.Resolve<ICompanyRepository>();

            var actionService = services.Resolve<IActionService>();

            using (var transaction = new RepositoryTransaction(personRepository))
            {
                personRepository.SaveGame(gameId, new PersonServiceData
                {
                    People = new List<Person>()
                });
            }

            personService.LoadGame(new LoadGameData
            {
                GameId = gameId
            });

            using (var transaction = new RepositoryTransaction(projectRepository))
            {
                projectRepository.SaveGame(gameId, new ProjectServiceData
                {
                    Projects = new List<Project>()
                });
            }

            projectService.LoadGame(new LoadGameData
            {
                GameId = gameId
            });

            var maxThingCount = 5;

            personService.GeneratePeople(companyCount * maxThingCount);

            projectService.GenerateProjects(Industries.FirstOrDefault(), companyCount * maxThingCount);

            var companies = new List<Company>();

            for (var companyIndex = 0; companyIndex < companyCount; companyIndex++)
            {
                var cActions = GenerateCompanyActions(actionService.Actions);

                var company = new Company(cActions)
                {
                    Id = Utilities.GetRandomInt(),
                    InitialAccuracy = Utilities.GetRandomDecimal(),
                    Money = Utilities.GetRandomDecimal(0, decimal.MaxValue),
                    Name = Utilities.GetRandomString(),
                    UserId = Utilities.GetRandomInt()
                };

                if (companyIndex == 1)
                {
                    companies[0].Rival = company;
                }

                var possibleStars = Utilities.GetRandomInt(1, 1000);

                company.Reputation.PossibleStars = possibleStars;

                company.Reputation.EarnedStars = Utilities.GetRandomInt(0, possibleStars);

                GenerateCompanyEmployees(personService, company, Utilities.GetRandomInt(1, maxThingCount));

                GenerateCompanyPerks(perkService, company, Utilities.GetRandomInt(1, maxThingCount));

                GenerateCompanyProjects(projectService, company, Utilities.GetRandomInt(1, maxThingCount));

                GenerateCompanyProspects(personService, company, Utilities.GetRandomInt(1, maxThingCount));

                GenerateCompanyTransactions(company, Utilities.GetRandomInt(1, maxThingCount));

                companies.Add(company);
            }

            var output = new CompanyServiceData
            {
                Companies = companies
            };

            using (var transaction = new RepositoryTransaction(companyRepository))
            {
                companyRepository.SaveGame(gameId, output);
            }

            return output;
        }