Exemple #1
0
    /// <summary>
    /// asdasdasd
    /// </summary>
    /// <param name="humanId"></param>
    /// <param name="drawAsEmployee">if true - renders as employee. Renders as worker otherwise</param>
    public void SetEntity(int humanId)
    {
        human = Humans.Get(Q, humanId);
        bool drawAsEmployee = !Humans.IsEmployed(human);

        Render(drawAsEmployee);
    }
Exemple #2
0
        public static void PlayAs(GameEntity company, GameContext GameContext)
        {
            var human = Humans.Get(GameContext, company.cEO.HumanId);

            SetPlayerControlledCompany(GameContext, company.company.Id);

            human.isPlayer = true;
        }
Exemple #3
0
    void RenderCEO()
    {
        var    human = Humans.Get(Q, SelectedCompany.cEO.HumanId).human;
        string name  = SelectedCompany.isControlledByPlayer ? "YOU" : $"{human.Name} {human.Surname}";

        CEONameLabel.text = Visuals.Link($"CEO: {name}");

        CEONameLabel.gameObject.GetComponent <LinkToHuman>().SetHumanId(human.Id);
    }
Exemple #4
0
    public void SetEntity(int humanId, WorkerRole workerRole)
    {
        var link = GetComponent <LinkToHuman>();

        var human = Humans.Get(Q, humanId);

        Human = human;

        link.SetHumanId(humanId);
        HumanPreview.SetEntity(humanId);

        if (!Humans.IsEmployed(human))
        {
            return;
        }

        var team = Teams.GetTeamOf(human, Q);

        bool isMainManager = human.worker.WorkerRole == Teams.GetMainManagerRole(team);
        bool isCompanyLead = isMainManager && human.worker.WorkerRole == WorkerRole.CEO;

        Draw(TeamLead, isMainManager);
        Draw(CompanyLead, isCompanyLead);

        var company       = Companies.Get(Q, human.worker.companyId);
        var loyaltyGrowth = Teams.GetLoyaltyChangeForManager(human, team, company);

        if (loyaltyGrowth > 0)
        {
            LoyaltyChange.sprite = Growth;
        }

        if (loyaltyGrowth == 0)
        {
            LoyaltyChange.sprite = Stall;
        }

        Hide(LoyaltyChange);

        if (loyaltyGrowth < 0)
        {
            LoyaltyChange.sprite = Decay;
            Show(LoyaltyChange);
        }

        bool hasOffers = Humans.HasCompetingOffers(human);

        var yourOffer = Teams.GetOpinionAboutOffer(human, Humans.GetCurrentOffer(human)).Sum();
        var bestOffer = human.workerOffers.Offers.Max(o => Teams.GetOpinionAboutOffer(human, o).Sum());

        bool yourOfferIsBestOffer = hasOffers && bestOffer == yourOffer;


        Draw(IsRecruitmentTarget, hasOffers);
        GetComponent <Blinker>().enabled = hasOffers && !yourOfferIsBestOffer;
    }
Exemple #5
0
    public override string GetTitle(NotificationMessageManagerRecruiting message)
    {
        var company = Companies.Get(Q, message.CompanyId);
        var human   = Humans.Get(Q, message.HumanId);

        if (message.Successful)
        {
            //return $"{Humans.GetFullName(human)} ";
            return($"Manager left your company");
        }
        return($"{company.company.Name} wants to recruit your worker");
    }
Exemple #6
0
    void RenderDisloyalManager(PopupMessageWorkerLeavesYourCompany popup)
    {
        var human = Humans.Get(Q, popup.humanId);

        var role          = Humans.GetRole(human);
        var formattedRole = Humans.GetFormattedRole(role);

        var rating = Humans.GetRating(Q, human);

        RenderUniversalPopup(
            "Manager doesn't want to work in your company anymore!",
            $"{formattedRole} {Humans.GetFullName(human)} ({rating}LVL) will leave your company.\n\n" + Visuals.Negative("Managers leave if they don't like corporate culture"),
            typeof(WorkerLeavesYourCompanyPopupButton)
            );
    }
    private void OnEnable()
    {
        var role    = (WorkerRole)GetParameter("role");
        var company = Flagship;
        var team    = company.team.Teams[SelectedTeam];

        var managers = Teams.GetCandidatesForTeam(company, team, Q)
                       .Select(id => Humans.Get(Q, id))
                       .Where(h => Humans.GetRole(h) == role)
        ;

        SetItems(managers);

        // ----------
        RoleBenefit.text = Visuals.Positive(Teams.GetRoleDescription(role, Q, true));
    }
Exemple #8
0
    public override void Execute()
    {
        var companyId = Popup.companyId;
        var humanId   = Popup.humanId;


        var company = Companies.Get(Q, companyId);
        var human   = Humans.Get(Q, humanId);

        NotificationUtils.ClosePopup(Q);


        Teams.HireManager(company, Q, human, 0);

        NavigateToHuman(humanId);
    }
Exemple #9
0
    protected override void Execute(List <GameEntity> entities)
    {
        var companies = Companies.Get(gameContext); // contexts.game.GetEntities(GameMatcher.AllOf(GameMatcher.Alive, GameMatcher.Company));
        var humans    = Humans.Get(gameContext);


        // maslov pyramid
        //
        // salary
        // interesting tasks
        // career ladder
        // feedback (i am doing useful stuff)
        // influence (become company shareholder)

        foreach (var c in companies)
        {
            //var culture = Companies.GetActualCorporateCulture(c, gameContext);

            // gain expertise and recalculate loyalty
            foreach (var t in c.team.Teams)
            {
                var managers = t.Managers.Select(m => humans.First(h => h.human.Id == m));

                foreach (var human in managers)
                {
                    bool hasTeacherInTeam = managers.Any(m1 => m1.humanSkills.Traits.Contains(Trait.Teacher) && m1.human.Id != human.human.Id);

                    // bigger the value... MORE chances to upgrade
                    var growth = Teams.GetManagerGrowthBonus(human, t, hasTeacherInTeam, gameContext).Sum();

                    var willGrow = Random.Range(0, 100) < growth;

                    if (willGrow)
                    {
                        human.humanSkills.Roles[WorkerRole.CEO]++;

                        if (!human.hasHumanUpgradedSkills)
                        {
                            human.AddHumanUpgradedSkills((int)C.PERIOD - 1);
                        }
                    }
                }
            }
        }
    }
Exemple #10
0
    public override void ViewRender()
    {
        base.ViewRender();

        var team = Flagship.team.Teams[0];

        var unhappyCoreWorkers = team.Managers.Select(humanId => Humans.Get(Q, humanId))
                                 .Any(human => human.humanCompanyRelationship.Morale < 30 && Teams.GetLoyaltyChangeForManager(human, team, Flagship) < 0);

        var unhappyTeams = Flagship.team.Teams.Any(t => t.isManagedBadly);

        Draw(Bankruptcy, Economy.IsWillBecomeBankruptOnNextPeriod(Q, MyCompany));
        Draw(UnhappyManager, unhappyCoreWorkers);
        Draw(UnhappyTeam, unhappyTeams);
        Draw(PromoteTeam, false);

        RenderIterationProgress();
    }
Exemple #11
0
    public override Dictionary <int, WorkerRole> Workers()
    {
        var c = GetCompany();

        var teamId = GetComponent <IsCoreTeam>() == null ? SelectedTeam : 0;

        var team = c.team.Teams[teamId];

        var managers = team.Managers;

        var dict = new Dictionary <int, WorkerRole>();

        foreach (var kvp in managers)
        {
            dict[kvp] = Humans.Get(Q, kvp).worker.WorkerRole;
        }

        return(dict);
    }
Exemple #12
0
    void RenderDefectedManager(PopupMessageWorkerWantsToWorkInYourCompany popup)
    {
        var human = Humans.Get(Q, popup.humanId);

        var role          = Humans.GetRole(human);
        var formattedRole = Humans.GetFormattedRole(role);

        var rating = Humans.GetRating(Q, human);

        RenderUniversalPopup(
            "You can hire new manager from your competitors!",

            $"<b>{formattedRole}</b> {Humans.GetFullName(human)} <b>({rating}LVL)</b> will join your company.\n\n" +
            Visuals.Positive("\n\nDo you want to hire?"),

            typeof(WorkerJoinsYourCompanyPopupButton),
            typeof(ClosePopupNO)
            );
    }
Exemple #13
0
    public override string GetDescription(NotificationMessageManagerRecruiting message)
    {
        var company = Companies.Get(Q, message.CompanyId);
        var human   = Humans.Get(Q, message.HumanId);

        var role   = Humans.GetRole(human);
        var rating = Humans.GetRating(human);

        if (message.Successful)
        {
            return($"{Humans.GetFormattedRole(role)} {human.human.Name} ({rating}LVL) joined your competitor: {company.company.Name}");
        }

        var offer         = human.workerOffers.Offers.Find(o => o.CompanyId == message.CompanyId);
        var dateFormatted = ScheduleUtils.GetFormattedDate(offer.DecisionDate);

        return($"\n<size=30>We need to send a counter offer until {dateFormatted}</size>" +
               $"\n\nor {Humans.GetFormattedRole(role)} {Humans.GetFullName(human)} ({rating}LVL) will join {company.company.Name}");
    }
Exemple #14
0
    public void SetEntity(int humanId)
    {
        var human = Humans.Get(Q, humanId);

        var rating = Humans.GetRating(human);
        var role   = Humans.GetRole(human);

        string[] Traits = human.humanSkills.Traits.Select(t => Visuals.Positive(ConvertTraitToString(t))).ToArray(); // new string[] { "Leader", "Teacher", "Ambitious", "Process-oriented", "Career-oriented", "Team-oriented" };

        bool employed = Humans.IsEmployed(human);

        //if (employed)
        //{
        //    Text.text = Visuals.Colorize("Works in competing company", Colors.COLOR_GOLD);
        //}
        //else
        //{
        //    Text.text = Visuals.Positive("UNEMPLOYED");
        //}

        //Text.text += "\n\n";

        var  team = Flagship.team.Teams[SelectedTeam];
        bool willCompeteWithWorker = team.Managers.Select(h => Humans.GetRole(Humans.Get(Q, h))).Count(h => h == role) > 0;

        if (WorkerRoleName != null)
        {
            WorkerRoleName.color = Visuals.GetColorPositiveOrNegative(!willCompeteWithWorker);
        }

        var min = (int)(rating + Companies.GetRandomValueInRange(0, 15, humanId, Flagship.company.Id));
        var max = (int)Mathf.Min(rating + Companies.GetRandomValueInRange(20, 55, humanId, Flagship.company.Id + 1), 100);

        Text.text = $"Potential\n{Visuals.Colorize(min, 30, max)} - {Visuals.Colorize(max, 30, max)}\n\n";

        //Text.text += string.Join("\n", Traits.Take(1)); // .Take(Random.Range(0, Traits.Length - 1))

        Hide(LoyaltyTab);

        ViewRender();
    }
Exemple #15
0
        public void Test_Humans_GetPut_AddsHumans()
        {
            string filePath = Path.GetFullPath("humans-put-test.json");

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            HttpResult resp1 = Humans.Get(filePath);

            Assert.AreEqual(System.Net.HttpStatusCode.BadRequest, resp1.StatusCode);

            Human      human1 = new() { Name = "name1", Birthday = new(1, 2, 3), FavoriteColor = "blue" };
            HttpResult resp2  = Humans.Put(filePath, human1);

            Assert.AreEqual(System.Net.HttpStatusCode.OK, resp2.StatusCode);

            Human      human2 = new() { Name = "name2", Birthday = new(4, 5, 6), FavoriteColor = "yellow" };
            HttpResult resp3  = Humans.Put(filePath, human2);

            Assert.AreEqual(System.Net.HttpStatusCode.OK, resp3.StatusCode);

            HttpResult resp4 = Humans.Put(filePath, human1);

            Assert.AreEqual(System.Net.HttpStatusCode.OK, resp4.StatusCode);

            HttpResult resp5 = Humans.Get(filePath);

            Assert.AreEqual(System.Net.HttpStatusCode.OK, resp5.StatusCode);

            Human[] humans = (Human[])resp5.Data !;
            Assert.IsNotNull(humans);
            Assert.IsNotEmpty(humans);
            Assert.AreEqual(2, humans.Length);
        }
    }
}
Exemple #16
0
    public static void Main(string[] args)
    {
        var builder = WebApplication.CreateBuilder(args);

        builder.Services.AddEndpointsApiExplorer();
        builder.Services.AddSwaggerGen();

        var app = builder.Build();

        app.UseSwagger();
        app.UseSwaggerUI();

        app.MapGet("/humans", (string filePath) => Humans.Get(filePath).AsIResult())
        .Produces <Human[]>()
        .Produces((int)System.Net.HttpStatusCode.BadRequest)
        .Produces((int)System.Net.HttpStatusCode.OK);

        app.MapPut("/humans", (string filePath, Human human) => Humans.Put(filePath, human).AsIResult())
        .Produces((int)System.Net.HttpStatusCode.BadRequest)
        .Produces((int)System.Net.HttpStatusCode.OK);

        app.Run();
    }
Exemple #17
0
    protected override void Execute(List <GameEntity> entities)
    {
        //var companies = contexts.game.GetEntities(GameMatcher.AllOf(GameMatcher.Alive, GameMatcher.Company));
        var companies = Companies.Get(gameContext);

        // maslov pyramid
        //
        // salary
        // interesting tasks
        // career ladder
        // feedback (i am doing useful stuff)
        // influence (become company shareholder)

        var date = ScheduleUtils.GetCurrentDate(gameContext);

        var playerFlagshipId = Companies.GetPlayerFlagshipID(gameContext);

        var humans = Humans.Get(gameContext);

        foreach (var c in companies)
        {
            var culture = Companies.GetActualCorporateCulture(c);

            List <int> defectedManagers  = new List <int>();
            var        recruitedManagers = new List <ExpiringJobOffer>();

            // gain expertise and recalculate loyalty
            foreach (var team in c.team.Teams)
            {
                var  managers       = team.Managers.Select(m => Humans.Get(humans, m)); //  humans.First(h => h.human.Id == m) //  Humans.Get(humans, m)
                bool tooManyLeaders = managers.Count(m => m.humanSkills.Traits.Contains(Trait.Leader)) >= 2;

                team.TooManyLeaders = tooManyLeaders;

                foreach (var human in managers)
                {
                    // var human = managers.First(m => m.human.Id == humanId);

                    var relationship = human.humanCompanyRelationship;

                    var loyaltyChange = Teams.GetLoyaltyChangeForManager(human, team, culture, c);

                    var newLoyalty    = Mathf.Clamp(relationship.Morale + loyaltyChange, 0, 100);
                    var newAdaptation = Mathf.Clamp(relationship.Adapted + 5, 0, 100);

                    human.ReplaceHumanCompanyRelationship(newAdaptation, newLoyalty);

                    // gain expertise
                    if (c.hasProduct)
                    {
                        var niche = c.product.Niche;

                        var newExpertise = 1;
                        if (human.humanSkills.Expertise.ContainsKey(niche))
                        {
                            newExpertise = Mathf.Clamp(human.humanSkills.Expertise[niche] + 1, 0, 100);
                        }

                        human.humanSkills.Expertise[niche] = newExpertise;
                    }


                    // leave company on low morale
                    if (newLoyalty <= 0)
                    {
                        defectedManagers.Add(human.human.Id);
                    }
                    else
                    {
                        // if has offers
                        // choose best one
                        var offers = human.workerOffers.Offers;

                        // has competing offers
                        if (Humans.HasCompetingOffers(human))
                        {
                            var desires = offers.Select(offer => Teams.GetOpinionAboutOffer(human, offer).Sum());

                            var maxDesire = desires.Max();

                            bool hasOneBestOffer = desires.Count(o => o >= maxDesire) == 1;

                            if (hasOneBestOffer)
                            {
                                // can choose best one
                                var bestOffer = offers.Find(e => Teams.GetOpinionAboutOffer(human, e).Sum() >= maxDesire);

                                // if best offer was made by another company
                                if (bestOffer.CompanyId != c.company.Id)
                                {
                                    // and company did nothing during one month
                                    if (bestOffer.DecisionDate < date)
                                    {
                                        recruitedManagers.Add(bestOffer);
                                        bestOffer.Accepted = true;

                                        human.workerOffers.Offers.Clear();
                                        human.workerOffers.Offers.Add(bestOffer);
                                    }
                                }
                            }
                            else
                            {
                                // otherwise, companies need to resend their offers
                                // or they will be expired
                            }
                        }
                    }
                }
            }

            // fire managers
            foreach (var humanId in defectedManagers)
            {
                bool isInPlayerFlagship = c.company.Id == playerFlagshipId;
                if (isInPlayerFlagship)
                {
                    NotificationUtils.AddPopup(gameContext, new PopupMessageWorkerLeavesYourCompany(c.company.Id, humanId));
                }
                else
                {
                    Teams.FireManager(c, gameContext, humanId);

                    // competitors need to have chances to hire this worker

                    bool worksInPlayerCompetitorCompany = Companies.IsInPlayerSphereOfInterest(c, gameContext);

                    bool wantsToWorkInYourCompany = false; // UnityEngine.Random.Range(0, 100) < 50;

                    // // NotifyPlayer
                    if (worksInPlayerCompetitorCompany && wantsToWorkInYourCompany)
                    {
                        NotificationUtils.AddPopup(gameContext, new PopupMessageWorkerWantsToWorkInYourCompany(c.company.Id, humanId));
                    }

                    // or this worker will start his own bussiness in same/adjacent sphere

                    // or will be destroyed
                }
            }

            foreach (var offer in recruitedManagers)
            {
                var human = humans.First(h => h.human.Id == offer.HumanId);

                var company         = companies.First(c1 => c1.company.Id == offer.CompanyId);
                var previousCompany = c; // companies.First(c1 => c1.company.Id == human.worker.companyId);

                Debug.Log($"Recruiting manager {Humans.GetFullName(human)} from {previousCompany.company.Name} to {company.company.Name}");

                Teams.HuntManager(human, company, gameContext, 0);
                Teams.SetJobOffer(human, company, offer.JobOffer, 0, gameContext);

                if (Companies.IsPlayerFlagship(previousCompany))
                {
                    NotificationUtils.AddNotification(gameContext, new NotificationMessageManagerRecruiting(offer.HumanId, company.company.Id, true));
                }
            }

            // clean expired offers
            foreach (var t in c.team.Teams)
            {
                foreach (var humanId in t.Managers)
                {
                    var human = humans.First(h => h.human.Id == humanId); // Humans.Get(humans, humanId);

                    human.workerOffers.Offers.RemoveAll(o => o.DecisionDate < date && !o.Accepted);
                }
            }
        }
    }
Exemple #18
0
    void HireManagers(GameEntity company, GameEntity playerFlagship)
    {
        // recruit workers from competing companies
        if (Companies.IsInPlayerSphereOfInterest(company, gameContext))
        {
            // try to recruit player workers
            var aggressiveness = 10 - company.corporateCulture.Culture[CorporatePolicy.CompetitionOrSupport];

            var wantsToRecruit = Random.Range(0, 1000) < 10 * aggressiveness;

            int teamId    = Random.Range(0, playerFlagship.team.Teams.Count);
            int managerId = Random.Range(0, playerFlagship.team.Teams[teamId].Managers.Count);

            if (teamId == 0 && managerId == 0)
            {
                return;
            }

            if (wantsToRecruit)
            {
                var humanId = playerFlagship.team.Teams[teamId].Managers[managerId];
                var worker  = Humans.Get(gameContext, humanId);

                var rating    = Humans.GetRating(worker);
                var neediness = Mathf.Clamp(Mathf.Pow(rating, 0.3f), 1f, 3f);

                var salary   = (long)(Humans.GetSalary(worker) * neediness);
                var jobOffer = new JobOffer(salary);

                if (Economy.IsCanMaintain(company, gameContext, salary))
                {
                    Teams.SendJobOffer(worker, jobOffer, company, gameContext);

                    NotificationUtils.AddNotification(gameContext, new NotificationMessageManagerRecruiting(humanId, company.company.Id, false));
                }
            }
        }

        // hire employees
        foreach (var t in company.team.Teams)
        {
            var necessaryRoles = Teams.GetMissingRoles(t);

            if (necessaryRoles.Any())
            {
                var rating = Teams.GetTeamAverageStrength(company, gameContext) + Random.Range(-2, 3);
                var salary = Teams.GetSalaryPerRating(rating);

                if (Economy.IsCanMaintain(company, gameContext, salary))
                {
                    var human = Teams.HireManager(company, gameContext, necessaryRoles.First(), t.ID);

                    Teams.SetJobOffer(human, company, new JobOffer(salary), t.ID, gameContext);
                }
                else
                {
                    break;
                }
            }
        }


        // move duplicate workers to other teams or replace weaker ones



        //var roles = Teams.GetRolesTheoreticallyPossibleForThisCompanyType(company);
        //var haveRoles = company.team.Managers.Values;

        //var needRoles = roles.Where(r => !haveRoles.Contains(r));

        //foreach (var r in needRoles)
        //{
        //    if (Economy.IsCanMaintain(company, gameContext, managerCost))
        //        Teams.HireManager(company, gameContext, r);
        //}
    }
Exemple #19
0
        public void Test_Humans_GetBadPath_Returns404()
        {
            HttpResult resp = Humans.Get("does-not-exist.json");

            Assert.AreEqual(System.Net.HttpStatusCode.BadRequest, resp.StatusCode);
        }