Ejemplo n.º 1
0
    public virtual void Editor_SetTeam(Team newTeam, Person replacing)
    {
        bool flag = false;


        Debug.Assert(replacing != null, "Can not currently make free agents");

        Person inNewPersonToHire = person;

        Team oldTeam       = inNewPersonToHire.Contract.GetTeam();
        Team replacingTeam = replacing.Contract.GetTeam();

        Debug.Assert(replacingTeam == newTeam);

        EmployeeSlot oldSlot = oldTeam.contractManager.GetSlotForPerson(inNewPersonToHire);
        EmployeeSlot newSlot = replacingTeam.contractManager.GetSlotForPerson(replacing);

        ContractPerson myOriginalContract        = new ContractPerson(this);
        ContractPerson replacingOriginalContract = new ContractPerson(replacing.Contract);

        if (oldSlot == null || newSlot == null)
        {
            MessageBoxResult result = MessageBox.Show("Currently you can only swap drivers that both have a team.", "Work in Progress", MessageBoxButton.OK, MessageBoxImage.Error);
            return;
        }

        if (!inNewPersonToHire.IsFreeAgent())
        {
            flag = oldTeam.IsPlayersTeam();
            //if (!person.IsReplacementPerson())
            //  this.PayOtherTeamTerminationCosts(team, inNewPersonToHire.contract);
            oldTeam.contractManager.FirePerson(inNewPersonToHire, Contract.ContractTerminationType.HiredBySomeoneElse);
        }
        if (!replacing.IsFreeAgent())
        {
            flag = newTeam.IsPlayersTeam();
            //if (!person.IsReplacementPerson())
            //  this.PayOtherTeamTerminationCosts(team, inNewPersonToHire.contract);
            newTeam.contractManager.FirePerson(replacing, Contract.ContractTerminationType.HiredBySomeoneElse);

            /*if (inNewPersonToHire is Mechanic)
             *  team.contractManager.HireReplacementMechanic();
             * else if (inNewPersonToHire is Engineer)
             *  team.contractManager.HireReplacementEngineer();
             * else if (inNewPersonToHire is Driver)
             *  team.contractManager.HireReplacementDriver();*/
        }


        Debug.Assert(newSlot != null);
        {
            newSlot.personHired = inNewPersonToHire;
            inNewPersonToHire.Contract.SetTeam(newTeam);
            inNewPersonToHire.Contract.SetPerson(inNewPersonToHire);
            inNewPersonToHire.Contract.SetContractState(Contract.ContractStatus.OnGoing);
            newTeam.contractManager.AddSignedContract(inNewPersonToHire.Contract);

            if (inNewPersonToHire is TeamPrincipal)
            {
                inNewPersonToHire.Contract.GetTeam().chairman.ResetHappiness();
            }
            if (inNewPersonToHire is Chairman)
            {
                (inNewPersonToHire as Chairman).ResetHappiness();
            }
        }

        Debug.Assert(oldSlot != null);
        {
            oldSlot.personHired = replacing;
            replacing.Contract.SetTeam(oldTeam);
            replacing.Contract.SetPerson(replacing);
            replacing.Contract.SetContractState(Contract.ContractStatus.OnGoing);
            oldTeam.contractManager.AddSignedContract(inNewPersonToHire.Contract);

            if (replacing is TeamPrincipal)
            {
                replacing.Contract.GetTeam().chairman.ResetHappiness();
            }
            (replacing as Chairman)?.ResetHappiness();
        }

        Mechanic newMechanic = inNewPersonToHire as Mechanic;

        if (newMechanic != null)
        {
            Mechanic oldMechanic = replacing as Mechanic;
            Debug.Assert(oldMechanic != null);

            int oldDriver = oldMechanic.driver;
            oldMechanic.driver = newMechanic.driver;
            newMechanic.driver = oldDriver;

            newMechanic.SetDefaultDriverRelationship();

            newTeam.carManager.partImprovement.mechanicOnPerformance = null;
            newTeam.carManager.partImprovement.mechanicOnReliability = null;

            newTeam.carManager.partImprovement.AssignChiefMechanics();
            if (newTeam.HasAIPitcrew)
            {
                newTeam.pitCrewController.AIPitCrew.RegenerateTaskStats();
            }

            oldMechanic.SetDefaultDriverRelationship();

            oldTeam.carManager.partImprovement.mechanicOnPerformance = null;
            oldTeam.carManager.partImprovement.mechanicOnReliability = null;

            oldTeam.carManager.partImprovement.AssignChiefMechanics();
            if (oldTeam.HasAIPitcrew)
            {
                oldTeam.pitCrewController.AIPitCrew.RegenerateTaskStats();
            }
        }

        if (inNewPersonToHire is Driver)
        {
            Driver        newDriver     = inNewPersonToHire as Driver;
            DriverManager driverManager = Game.instance.driverManager;

            // Swap some of the contract details around
            newDriver.contract.currentStatus = replacingOriginalContract.currentStatus;

            newDriver.joinsAnySeries = true;

            driverManager.AddDriverToChampionship(newDriver);

            // No longer a reserve driver after the swap
            if (myOriginalContract.currentStatus == Status.Reserve && replacingOriginalContract.currentStatus != Status.Reserve)
            {
                newTeam.AssignDriverToCar(newDriver);
                newTeam.SelectMainDriversForSession();
                newTeam.championship.standings.UpdateStandings();
            }
            else if (myOriginalContract.currentStatus != Status.Reserve && replacingOriginalContract.currentStatus == Status.Reserve)
            {
                // Switching from main driver to reserve
                driverManager.RemoveDriverEntryFromChampionship(newDriver);
                newDriver.SetCarID(-1);
                newTeam.SelectMainDriversForSession();
                newTeam.championship.standings.UpdateStandings();
            }
            Mechanic mechanicOfDriver = newTeam.GetMechanicOfDriver(newDriver);
            mechanicOfDriver?.SetDriverRelationship(0.0f, 0);


            if (newTeam.IsPlayersTeam())
            {
                newDriver.SetBeenScouted();
            }
            else
            {
                //newTeam.teamAIController.RemoveDriverFromScoutingJobs(inDriver);
                //newTeam.teamAIController.EvaluateDriverLineUp();
            }


            Driver oldDriver = replacing as Driver;
            oldDriver.joinsAnySeries = true;

            // Swap some of the contract details around
            oldDriver.contract.currentStatus = myOriginalContract.currentStatus;

            driverManager.AddDriverToChampionship(oldDriver);

            // No longer a reserve driver after the swap
            if (myOriginalContract.currentStatus != Status.Reserve && replacingOriginalContract.currentStatus == Status.Reserve)
            {
                oldTeam.AssignDriverToCar(oldDriver);
                oldTeam.SelectMainDriversForSession();
                oldTeam.championship.standings.UpdateStandings();
            }
            else if (myOriginalContract.currentStatus == Status.Reserve && replacingOriginalContract.currentStatus != Status.Reserve)
            {
                // Switching from main driver to reserve
                driverManager.RemoveDriverEntryFromChampionship(oldDriver);
                oldDriver.SetCarID(-1);
                oldTeam.SelectMainDriversForSession();
                oldTeam.championship.standings.UpdateStandings();
            }
            mechanicOfDriver = oldTeam.GetMechanicOfDriver(oldDriver);
            mechanicOfDriver?.SetDriverRelationship(0.0f, 0);

            if (oldTeam.IsPlayersTeam())
            {
                oldDriver.SetBeenScouted();
            }
            else
            {
                //newTeam.teamAIController.RemoveDriverFromScoutingJobs(inDriver);
                //newTeam.teamAIController.EvaluateDriverLineUp();
            }
        }

        if (inNewPersonToHire is Mechanic)
        {
            oldTeam.RefreshMechanics();
            newTeam.RefreshMechanics();
        }
    }