private void OnControlledCompanyWorkerRemoved(SharedWorker worker)
        {
            LocalWorker companyWorker = (LocalWorker)worker;

            RemoveWorkerListViewElement(companyWorker, ListViewWorkers);
            SetTextListViewWorkers();
        }
Ejemplo n.º 2
0
    private SharedWorker GenerateSingleWorker()
    {
        //Randomly selected name, surename and gender for new worker
        Gender newWorkerGender = (Gender)UnityEngine.Random.Range(0, NUMBER_OF_GENDERS);

        int    nameIndex;
        string newWorkerName     = CreateWorkerName(newWorkerGender, out nameIndex);
        int    surenameIndex     = UnityEngine.Random.Range(0, WorkerData.Surenames.Count);
        string newWorkerSurename =
            WorkerData.Surenames[surenameIndex];

        SharedWorker newMarketWorker =
            new SharedWorker(newWorkerName, newWorkerSurename, newWorkerGender);

        newMarketWorker.Abilites       = CreateWorkerAbilities();
        newMarketWorker.ExperienceTime = CalculateWorkerExpierience(newMarketWorker);
        newMarketWorker.Salary         = CalculateWorkerSalary(newMarketWorker);
        newMarketWorker.ID             = MainSimulationManager.GenerateID();
        int avatarIndex;

        newMarketWorker.Avatar        = CreateWorkerAvatar(newMarketWorker, out avatarIndex);
        newMarketWorker.AvatarIndex   = avatarIndex;
        newMarketWorker.NameIndex     = nameIndex;
        newMarketWorker.SurenameIndex = surenameIndex;

        return(newMarketWorker);
    }
        private void OnControlledCompanyWorkerAdded(SharedWorker worker)
        {
            LocalWorker companyWorker = (LocalWorker)worker;

            CreateWorkerListViewElement(companyWorker);
            SetTextListViewWorkers();
        }
        private void AddWorkerListViewElement(SharedWorker playerWorker, ControlListView listView)
        {
            ListViewElementWorker element =
                UIWorkers.CreateWorkerListViewElement(playerWorker, WorkerListViewElementPrefab, TooltipComponent);

            Button buttonComponent = element.GetComponent <Button>();

            if (null == WorkerListViewMap)
            {
                WorkerListViewMap = new Dictionary <SharedWorker, ListViewElementWorker>();
            }

            if (listView == ListViewOtherPlayersWorkers)
            {
                MousePointerEvents mouseEvts = element.GetComponent <MousePointerEvents>();
                mouseEvts.PointerDoubleClick += () =>
                {
                    if (true == SimulationManagerComponent.ControlledCompany.CanHireWorker)
                    {
                        OnButtonHireWorkerClick();
                    }
                };
            }

            WorkerListViewMap.Add(playerWorker, element);
            listView.AddControl(element.gameObject);
            WorkersButtonSelector.AddButton(buttonComponent);
        }
Ejemplo n.º 5
0
        private void AddWorkerListViewElement(SharedWorker worker, ControlListView listView)
        {
            ListViewElementWorker element = UIWorkers.CreateWorkerListViewElement(worker, WorkerListViewElementPrefab, TooltipComponent);

            Button             buttonComponent = element.GetComponent <Button>();
            MousePointerEvents mousePtrEvts    = element.GetComponent <MousePointerEvents>();

            mousePtrEvts.PointerDoubleClick += () =>
            {
                if (listView == ListViewMarketWorkers &&
                    true == SimulationManagerComponent.ControlledCompany.CanHireWorker)
                {
                    OnHireWorkerButtonClicked();
                }
            };

            if (null == WorkerListViewMap)
            {
                WorkerListViewMap = new Dictionary <SharedWorker, ListViewElementWorker>();
            }

            listView.AddControl(element.gameObject);
            WorkerListViewMap.Add(worker, element);
            WorkersButtonSelector.AddButton(buttonComponent);
            worker.SalaryChanged += OnWorkerSalaryChanged;
        }
        /*Public consts fields*/

        /*Public fields*/

        /*Private methods*/

        #region Event callbacks

        private void OnDropdownPlayersListValueChanged(int index)
        {
            if (1 != PhotonNetwork.room.PlayerCount)
            {
                List <SharedWorker> playerWorkers;

                if (null != SelectedPlayer)
                {
                    playerWorkers = SimulationManagerComponent.OtherPlayersWorkers[SelectedPlayer];
                    foreach (SharedWorker worker in playerWorkers)
                    {
                        RemoveWorkerListViewElement(worker, ListViewOtherPlayersWorkers);
                    }
                }

                SelectedPlayer = PhotonNetwork.otherPlayers[index];
                SelectedWorker = null;
                playerWorkers  = SimulationManagerComponent.OtherPlayersWorkers[SelectedPlayer];
                SetTextListViewOtherPlayersWorkers();

                foreach (SharedWorker worker in playerWorkers)
                {
                    AddWorkerListViewElement(worker, ListViewOtherPlayersWorkers);
                }
            }
        }
Ejemplo n.º 7
0
 private void OnBindedProjectWorkerAdded(SharedWorker worker)
 {
     if (BindedProject.Workers.Count > 0 && false == BindedProject.Active && false == BindedProject.IsCompleted)
     {
         StartProject();
     }
 }
Ejemplo n.º 8
0
        /*Public consts fields*/

        /*Public fields*/

        /*Private methods*/

        /*Public methods*/

        public static ListViewElementWorker CreateWorkerListViewElement(SharedWorker worker, ListViewElementWorker prefab, Tooltip tooltipComponent = null)
        {
            ListViewElementWorker element = GameObject.Instantiate <ListViewElementWorker>(prefab);

            if (null != tooltipComponent)
            {
                MousePointerEvents mousePtrEvt = element.gameObject.AddComponent <MousePointerEvents>();

                mousePtrEvt.PointerEntered += () =>
                {
                    tooltipComponent.gameObject.SetActive(true);
                    tooltipComponent.Text = GetWorkerAbilitiesString(worker);
                };

                mousePtrEvt.PointerExited += () =>
                {
                    tooltipComponent.gameObject.SetActive(false);
                };
            }

            element.Text.text         = GetWorkerListViewElementText(worker);
            element.Worker            = worker;
            element.FrontImage.sprite = worker.Avatar;

            return(element);
        }
Ejemplo n.º 9
0
 private void OnBindedProjectWorkerRemoved(SharedWorker worker)
 {
     if (0 == BindedProject.Workers.Count && true == BindedProject.Active)
     {
         StopProject();
     }
 }
Ejemplo n.º 10
0
        private void OnOtherPlayerCompanyWorkerAbilityChangedRPC(int photonPlayerID, int workerID, int updatedAbility, float updatedAbilityValue)
        {
            SharedWorker updatedWorker =
                OtherPlayersWorkers.First(x => x.Key.ID == photonPlayerID).Value.First(x => x.ID == workerID);
            ProjectTechnology updatedAbilityEnum = (ProjectTechnology)updatedAbility;

            updatedWorker.UpdateAbility(updatedAbilityEnum, updatedAbilityValue);
        }
Ejemplo n.º 11
0
 private void OnControlledCompanyWorkerRemoved(SharedWorker removedWorker)
 {
     this.photonView.RPC(
         "OnControlledCompanyWorkerRemovedRPC", PhotonTargets.Others, removedWorker.ID, PhotonNetwork.player.ID);
     removedWorker.SalaryChanged          -= OnCompanyWorkerSalaryChanged;
     removedWorker.AbilityUpdated         -= OnCompanyWorkerAbilityUpdated;
     removedWorker.ExpierienceTimeChanged -= OnCompanyWorkerExpierienceTimeChanged;
 }
        private void RemoveWorkerListViewElement(SharedWorker companyWorker)
        {
            LocalWorker           worker          = (LocalWorker)companyWorker;
            ControlListViewDrop   workerListView  = (null == worker.AssignedProject) ? ListViewAvailableWorkers : ListViewAssignedWorkers;
            ListViewElementWorker listViewElement = UIWorkers.GetWorkerListViewElement(companyWorker, workerListView);

            RemoveWorkerListViewElement(listViewElement, workerListView);
        }
Ejemplo n.º 13
0
        public void HireOtherPlayerWorker(PhotonPlayer otherPlayer, SharedWorker worker)
        {
            RemoveOtherPlayerControlledCompanyWorker(otherPlayer, worker);
            LocalWorker hiredWorker = new LocalWorker(worker);

            hiredWorker.Salary         = hiredWorker.HireSalary;
            ControlledCompany.Balance -= hiredWorker.Salary;
            ControlledCompany.AddWorker(hiredWorker);
        }
        //On control removed from list view check will be peformed to check
        //if control was removed because worker was removed from project.
        //If player moved worker's control to other list if condition will be true.
        //If worker got removed for other reason (i.e level of satisfaction fell
        //below threshold) if condition will be false
        private void OnListViewAssignedWorkersControlRemoved(GameObject ctrl)
        {
            SharedWorker worker = ctrl.GetComponent <ListViewElementWorker>().Worker;

            if (true == SelectedScrum.BindedProject.Workers.Contains(worker))
            {
                SelectedScrum.BindedProject.RemoveWorker((LocalWorker)worker);
            }
        }
Ejemplo n.º 15
0
 private void OnCompanyWorkerExpierienceTimeChanged(SharedWorker companyWorker)
 {
     this.photonView.RPC("OnOtherPlayerCompanyWorkerAttirbuteChangedRPC",
                         PhotonTargets.Others,
                         PhotonNetwork.player.ID,
                         companyWorker.ID,
                         companyWorker.ExperienceTime,
                         (int)WorkerAttribute.ExpierienceTime);
 }
Ejemplo n.º 16
0
 private void OnCompanyWorkerAbilityUpdated(SharedWorker companyWorker, ProjectTechnology workerAbility, float workerAbilityValue)
 {
     this.photonView.RPC("OnOtherPlayerCompanyWorkerAbilityChangedRPC",
                         PhotonTargets.Others,
                         PhotonNetwork.player.ID,
                         companyWorker.ID,
                         (int)workerAbility,
                         workerAbilityValue);
 }
Ejemplo n.º 17
0
 private void OnCompanyWorkerSalaryChanged(SharedWorker companyWorker)
 {
     this.photonView.RPC("OnOtherPlayerCompanyWorkerAttirbuteChangedRPC",
                         PhotonTargets.Others,
                         PhotonNetwork.player.ID,
                         companyWorker.ID,
                         companyWorker.Salary,
                         (int)WorkerAttribute.Salary);
 }
        private void OnOtherPlayerWorkerAdded(SharedWorker worker, PhotonPlayer player)
        {
            if (SelectedPlayer.ID == player.ID)
            {
                AddWorkerListViewElement(worker, ListViewOtherPlayersWorkers);
                SetTextListViewOtherPlayersWorkers();
            }

            SubscribeToWorkerEvents(worker);
        }
        private void OnOtherPlayerWorkerRemoved(SharedWorker removedWorker, PhotonPlayer player)
        {
            if (SelectedPlayer.ID == player.ID)
            {
                RemoveWorkerListViewElement(removedWorker, ListViewOtherPlayersWorkers);
                SetTextListViewOtherPlayersWorkers();
            }

            UnsubscribeFromWorkerEvents(removedWorker);
        }
Ejemplo n.º 20
0
        private void RemoveWorkerListViewElement(SharedWorker worker, ControlListView listView)
        {
            ListViewElementWorker element = WorkerListViewMap.First(x => x.Key == worker).Value;
            Button buttonComponent        = element.GetComponent <Button>();

            listView.RemoveControl(element.gameObject);
            WorkerListViewMap.Remove(worker);
            WorkersButtonSelector.RemoveButton(buttonComponent);
            worker.SalaryChanged -= OnWorkerSalaryChanged;
        }
Ejemplo n.º 21
0
    private int CalculateWorkerExpierience(SharedWorker newWorker)
    {
        int workerExpierience = UnityEngine.Random.Range(0, 101);

        foreach (KeyValuePair <ProjectTechnology, SafeFloat> workerAbility in newWorker.Abilites)
        {
            workerExpierience += (int)(45 * workerAbility.Value.Value);
        }

        return(workerExpierience);
    }
        private void RemoveWorkerListViewElement(SharedWorker worker, ControlListView listView)
        {
            if (null != WorkerListViewMap)
            {
                ListViewElementWorker element = WorkerListViewMap[worker];
                Button buttonComponent        = element.Button;

                WorkerListViewMap.Remove(worker);
                WorkersButtonSelector.RemoveButton(buttonComponent);
                listView.RemoveControl(element.gameObject);
            }
        }
        /*Public methods*/

        public void OnButtonHireWorkerClick()
        {
            Button selectedWorkerButton          = WorkersButtonSelector.GetSelectedButton();
            ListViewElementWorker element        = selectedWorkerButton.GetComponent <ListViewElementWorker>();
            SharedWorker          selectedWorker = WorkerListViewMap.First(x => x.Value == element).Key;

            string infoWindowText = string.Format("Do you want to hire this worker ? It will cost you {0} $", selectedWorker.HireSalary);

            InfoWindowComponent.ShowOkCancel(infoWindowText, () =>
            {
                SimulationManagerComponent.HireOtherPlayerWorker(SelectedPlayer, selectedWorker);
            }, null);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Returns list view element representing worker
        /// </summary>
        public static ListViewElementWorker GetWorkerListViewElement(SharedWorker worker, ControlListView listView)
        {
            GameObject elementGameObject = listView.Controls.Find(
                x => x.GetComponent <ListViewElementWorker>().Worker == worker);
            ListViewElementWorker element = null;

            if (null != elementGameObject)
            {
                element = elementGameObject.GetComponent <ListViewElementWorker>();
            }

            return(element);
        }
Ejemplo n.º 25
0
    private void OnGameTimeDayChanged()
    {
        if (true == PhotonNetwork.isMasterClient && Workers.Count < MaxWorkersOnMarket)
        {
            int randomNuber = UnityEngine.Random.Range(0, 101);

            if (randomNuber <= WORKER_ADD_PROBABILITY_DAILY)
            {
                SharedWorker newWorker = GenerateSingleWorker();
                AddWorker(newWorker);
            }
        }
    }
Ejemplo n.º 26
0
        private void OnControlledCompanyWorkerAddedRPC(SharedWorker addedWorker, int photonPlayerID)
        {
            KeyValuePair <PhotonPlayer, List <SharedWorker> > workerPair = OtherPlayersWorkers.First(x => x.Key.ID == photonPlayerID);
            List <SharedWorker> workers = workerPair.Value;

            workers.Add(addedWorker);
            OtherPlayerWorkerAdded?.Invoke(addedWorker, workerPair.Key);

#if DEVELOPMENT_BUILD || UNITY_EDITOR
            string debugInfo = string.Format("[{3}] Received worker update from player {0} (ID: {1}).\n" +
                                             "Worker added (ID: {2}). Local workers collection synchronized",
                                             workerPair.Key.NickName, workerPair.Key.ID, addedWorker.ID, this.GetType().Name);
            Debug.Log(debugInfo);
#endif
        }
Ejemplo n.º 27
0
        public static string GetWorkerAbilitiesString(SharedWorker worker)
        {
            StrBuilder.Clear();

            for (int i = 0; i < worker.Abilites.Count; i++)
            {
                KeyValuePair <ProjectTechnology, SafeFloat> ability = worker.Abilites.ElementAt(i);

                StrBuilder.AppendFormat("{0} {1}\n",
                                        EnumToString.ProjectTechnologiesStrings[ability.Key],
                                        ability.Value.Value.ToString("0.00"));
            }

            return(StrBuilder.ToString());
        }
Ejemplo n.º 28
0
    private void RemoveWorkerInternalRPC(int workerID)
    {
        SharedWorker workerToRemove = null;

        for (int i = 0; i < Workers.Count; i++)
        {
            if (workerID == Workers[i].ID)
            {
                workerToRemove = Workers[i];
                Workers.RemoveAt(i);
                break;
            }
        }

        this.WorkerRemoved?.Invoke(workerToRemove);
    }
Ejemplo n.º 29
0
    public void AddWorkerInternalRPC(object workerToAdd)
    {
        SharedWorker workerObject = (SharedWorker)workerToAdd;

        this.Workers.Add(workerObject);
        this.WorkerAdded?.Invoke(workerObject);

        if (false == PhotonNetwork.isMasterClient && false == IsDataReceived)
        {
            if (this.Workers.Count == MaxWorkersOnMarket)
            {
                IsDataReceived = true;
                DataReceived?.Invoke();
            }
        }
    }
        private void OnProjectWorkerRemoved(SharedWorker companyWorker)
        {
            ListViewElementWorker element = UIWorkers.GetWorkerListViewElement(companyWorker, ListViewAssignedWorkers);

            //Check if list view element was dragged to other list view
            if (null != element)
            {
                RemoveWorkerListViewElement(element, ListViewAssignedWorkers);
                ListViewElementWorker newElement = CreateWorkerListViewElement((LocalWorker)companyWorker);
                ListViewAvailableWorkers.AddControl(newElement.gameObject);
            }

            SetListViewAssignedWorkersText();
            SetListViewAvailableWorkersText();
            SetProjectInfo();
        }