private void OnControlledCompanyWorkerAdded(LocalWorker companyWorker) { ListViewElementWorker newElement = CreateWorkerListViewElement(companyWorker); ListViewAvailableWorkers.AddControl(newElement.gameObject); SetListViewAvailableWorkersText(); }
private void OnWorkersButtonsSelectorSelectedButtonChanged(Button btn) { if (null != SelectedWorker) { UnsubscribeFromWorkerEvents(SelectedWorker); } if (null != btn) { ListViewElementWorker element = btn.GetComponent <ListViewElementWorker>(); SelectedWorker = (LocalWorker)element.Worker; SubscribeToWorkerEvents(SelectedWorker); ButtonFireWorker.interactable = true; ButtonGiveSalaryRaise.interactable = true; SliderSalaryRaiseAmount.interactable = true; SetWorkerText(); ToggleWorkerInfoText(true); } else { if (null != SelectedWorker) { UnsubscribeFromWorkerEvents(SelectedWorker); } SelectedWorker = null; ButtonFireWorker.interactable = false; ButtonGiveSalaryRaise.interactable = false; SliderSalaryRaiseAmount.interactable = false; ToggleWorkerInfoText(false); } }
private void OnControlledCompanyWorkerAdded(SharedWorker worker) { LocalWorker companyWorker = (LocalWorker)worker; CreateWorkerListViewElement(companyWorker); SetTextListViewWorkers(); }
private void OnControlledCompanyWorkerRemoved(SharedWorker worker) { LocalWorker companyWorker = (LocalWorker)worker; RemoveWorkerListViewElement(companyWorker, ListViewWorkers); SetTextListViewWorkers(); }
private void SimulateWorkerHoliday(LocalWorker companyWorker) { //What is the probability of worker going to holidays (in %) float holidayProbability = companyWorker.DaysSinceAbsent * 0.001f; float randomNumber = Random.Range(0f, 100f); if (randomNumber <= holidayProbability) { //Worker is on holidays int holidayDuration = Random.Range(LocalWorker.MIN_HOLIDAY_DURATION, LocalWorker.MAX_HOLIDAY_DURATION); holidayDuration = Mathf.Clamp(holidayDuration, 1, companyWorker.DaysOfHolidaysLeft); companyWorker.AbsenceReason = WorkerAbsenceReason.Holiday; companyWorker.DaysSinceAbsent = 0; companyWorker.DaysUntilAvailable = holidayDuration; companyWorker.DaysOfHolidaysLeft -= holidayDuration; companyWorker.Available = false; string playerNotification = string.Format("Your worker {0} {1} is on holidays now. {2} days until he will get back to work", companyWorker.Name, companyWorker.Surename, companyWorker.DaysUntilAvailable); SimulationManagerComponent.NotificatorComponent.Notify(playerNotification); #if DEVELOPMENT_BUILD || UNITY_EDITOR string debugInfo = string.Format("Worker {0} {1} (ID {2}) is on holidays\n{3} days until available\n", companyWorker.Name, companyWorker.Surename, companyWorker.ID, companyWorker.DaysUntilAvailable); Debug.Log(debugInfo); #endif } }
private void SimulateWorkerSickness(LocalWorker companyWorker) { //What is the probability of worker being sick (in %) float notSickProbability = companyWorker.DaysSinceAbsent * 0.001f; float randomNumber = Random.Range(0f, 100f); if (randomNumber <= notSickProbability) { //Worker is sick int sicknessDuration = Random.Range(LocalWorker.MIN_SICKNESS_DURATION, LocalWorker.MAX_SICKNESS_DURATION); companyWorker.AbsenceReason = WorkerAbsenceReason.Sickness; companyWorker.DaysSinceAbsent = 0; companyWorker.DaysUntilAvailable = sicknessDuration; companyWorker.Available = false; string playerNotification = string.Format("Your worker {0} {1} just got sick ! {2} days until he will get back to work", companyWorker.Name, companyWorker.Surename, companyWorker.DaysUntilAvailable); SimulationManagerComponent.NotificatorComponent.Notify(playerNotification); #if DEVELOPMENT_BUILD || UNITY_EDITOR string debugInfo = string.Format("Worker {0} {1} (ID {2}) is sick\n{3} days until available\n", companyWorker.Name, companyWorker.Surename, companyWorker.ID, companyWorker.DaysUntilAvailable); Debug.Log(debugInfo); #endif } }
/// <summary> /// Calculates satisfaction based on days since salary raise /// </summary> private void CalculateWorkerSatisfactionSalaryDays(LocalWorker companyWorker) { companyWorker.Satiscation -= WORKER_DAILY_SATISFACTION_LOSS; //Satisfaction is percent value companyWorker.Satiscation = Mathf.Clamp(companyWorker.Satiscation, 0.0f, 100.0f); float notifySatisfactionLvl = 30f; if (companyWorker.Satiscation > notifySatisfactionLvl) { for (int i = 0; i < WorkersSatisfactionNotificationSent.Count; i++) { if (companyWorker == WorkersSatisfactionNotificationSent[i]) { WorkersSatisfactionNotificationSent.RemoveAt(i); break; } } } else if (false == WorkersSatisfactionNotificationSent.Contains(companyWorker)) { string notification = string.Format("Your worker's {0} {1} satisfaction level fell below {2} %. " + "Try to increase it as soon as possible or worker will leave your company !", companyWorker.Name, companyWorker.Surename, (int)notifySatisfactionLvl); SimulationManagerComponent.NotificatorComponent.Notify(notification); WorkersSatisfactionNotificationSent.Add(companyWorker); } }
private string GetWorkerListViewElementText(LocalWorker worker) { string elementText; string absenceString = string.Empty; if (false == worker.Available) { switch (worker.AbsenceReason) { case WorkerAbsenceReason.Sickness: absenceString = "Sick"; break; case WorkerAbsenceReason.Holiday: absenceString = "On holidays"; break; default: break; } } elementText = string.Format("{0} {1}\n{2} days of expierience\n{3}", worker.Name, worker.Surename, worker.ExperienceTime, absenceString); return(elementText); }
private void UnsubscribeFromWorkerEvents(LocalWorker companyWorker) { companyWorker.AbilityUpdated -= OnCompanyWorkerAbilityUpdated; companyWorker.SatisfactionChanged -= OnCompanyWorkerSatisfactionChanged; companyWorker.DaysInCompanyChanged -= OnCompanyWorkerDaysInCompanyChanged; companyWorker.SalaryChanged -= OnCompanyWorkerSalaryChanged; companyWorker.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); }
private void SimulateWorkerSatisfaction(LocalWorker companyWorker) { CalculateWorkerSatisfactionSalaryDays(companyWorker); if (companyWorker.Satiscation < WORKER_SATISFACTION_LEAVE_TRESHOLD) { SimulationManagerComponent.ControlledCompany.RemoveWorker(companyWorker); } }
private void RemoveWorkerListViewElement(LocalWorker worker, ControlListView listView) { ListViewElementWorker element = UIWorkers.GetWorkerListViewElement(worker, listView); Button buttonComponent = element.GetComponent <Button>(); WorkersButtonsSelector.RemoveButton(buttonComponent); ListViewWorkers.RemoveControl(element.gameObject); worker.SatisfactionChanged -= OnWorkerSatisfactionChanged; }
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); }
/// <summary> /// Calculates satisfaction based on salary change amount /// </summary> private static void CalculateSatisfactionSalaryRaise(LocalWorker companyWorker) { float satisfactionChange = companyWorker.LastSalaryChange / (float)(companyWorker.Salary - companyWorker.LastSalaryChange); satisfactionChange *= 100.0f; companyWorker.Satiscation += satisfactionChange; //Satisfaction is percent value companyWorker.Satiscation = Mathf.Clamp(companyWorker.Satiscation, 0.0f, 100.0f); }
public void OnButtonGiveSalaryRaiseClicked() { int salaryRaiseAmount = (int)SliderSalaryRaiseAmount.value; Button selectedButton = WorkersButtonsSelector.GetSelectedButton(); ListViewElementWorker element = selectedButton.GetComponent <ListViewElementWorker>(); LocalWorker companyWorker = (LocalWorker)element.Worker; companyWorker.Salary = companyWorker.Salary + salaryRaiseAmount; }
public void AddWorker(LocalWorker workerToAdd) { Workers.Add(workerToAdd); workerToAdd.WorkingCompany = this; workerToAdd.DaysInCompany = 0; WorkerAdded?.Invoke(workerToAdd); #if DEVELOPMENT_BUILD || UNITY_EDITOR string debugInfo = string.Format("[{3}] Worker added to company\nName {0} {1}\nID {2}\n", workerToAdd.Name, workerToAdd.Surename, workerToAdd.ID, this.GetType().Name); Debug.Log(debugInfo); #endif }
/*Public methods*/ public void OnHireWorkerButtonClicked() { WorkersMarketComponent.RemoveWorker(SelectedWorker); LocalWorker newLocalWorker = SelectedWorker as LocalWorker; if (null == newLocalWorker) { newLocalWorker = new LocalWorker(SelectedWorker); } SimulationManagerComponent.ControlledCompany.AddWorker(newLocalWorker); }
/*Public methods*/ public void OnButtonFireWorkerClicked() { Button selectedButton = WorkersButtonsSelector.GetSelectedButton(); ListViewElementWorker element = selectedButton.GetComponent <ListViewElementWorker>(); LocalWorker workerToRemove = (LocalWorker)element.Worker; string infoWindowMsg = string.Format("Do you really want to fire {0} {1} ?", workerToRemove.Name, workerToRemove.Surename); InfoWindowComponent.ShowOkCancel(infoWindowMsg, () => { SimulationManagerComponent.ControlledCompany.RemoveWorker(workerToRemove); }, null); }
private void UpdateWorkersState() { for (int i = 0; i < SimulationManagerComponent.ControlledCompany.Workers.Count; i++) { LocalWorker companyWorker = SimulationManagerComponent.ControlledCompany.Workers[i]; companyWorker.DaysInCompany += 1; if (true == companyWorker.Available) { ++companyWorker.DaysSinceAbsent; } SimulateWorkerAbsence(companyWorker); SimulateWorkerSatisfaction(companyWorker); } }
private ListViewElementWorker CreateWorkerListViewElement(LocalWorker companyWorker) { ListViewElementWorker element = UIWorkers.CreateWorkerListViewElement(companyWorker, WorkerListViewElementPrefab, TooltipComponent); element.Text.text = GetWorkerListViewElementText(companyWorker); Button buttonComponent = element.GetComponent <Button>(); WorkersButtonsSelector.AddButton(buttonComponent); ListViewWorkers.AddControl(element.gameObject); //List view element contains information about satisfaction so it should be updated whenever it changes companyWorker.SatisfactionChanged += OnWorkerSatisfactionChanged; return(element); }
private void SimulateWorkerAbsence(LocalWorker companyWorker) { --companyWorker.DaysUntilAvailable; if (true == companyWorker.Available) { SimulateWorkerSickness(companyWorker); } if (true == companyWorker.Available && companyWorker.DaysOfHolidaysLeft > 0) { SimulateWorkerHoliday(companyWorker); } if (0 == companyWorker.DaysUntilAvailable) { companyWorker.Available = true; } }
public void RemoveWorker(LocalWorker workerToRemove) { Workers.Remove(workerToRemove); workerToRemove.WorkingCompany = null; if (null != workerToRemove.AssignedProject) { workerToRemove.AssignedProject.RemoveWorker(workerToRemove); } WorkerRemoved?.Invoke(workerToRemove); #if DEVELOPMENT_BUILD || UNITY_EDITOR string debugInfo = string.Format("[{3}] Worker removed from company\nName {0} {1}\nID {2}\n", workerToRemove.Name, workerToRemove.Surename, workerToRemove.ID, this.GetType().Name); Debug.Log(debugInfo); #endif }
public void RemoveWorker(LocalWorker projectWorker) { projectWorker.AssignedProject = null; this.Workers.Remove(projectWorker); WorkerRemoved?.Invoke(projectWorker); #if DEVELOPMENT_BUILD || UNITY_EDITOR string debugInfo = string.Format( "[{5}] Worker removed from project\n" + "PROJECT -------------------\n" + "Name: {0}\n" + "ID: {1}\n" + "WORKER -------------------\n" + "Name: {2} {3}\n" + "ID: {4}", this.Name, this.ID, projectWorker.Name, projectWorker.Surename, projectWorker.ID, this.GetType().Name); Debug.Log(debugInfo); #endif }
private void RemoveControlledCompanyWorkerRPC(int workerID, int senderID) { LocalWorker workerToRemove = this.ControlledCompany.Workers.First(x => x.ID == workerID); this.ControlledCompany.RemoveWorker(workerToRemove); PhotonPlayer sender = PhotonNetwork.playerList.FirstOrDefault(x => x.ID == senderID); string notification; notification = string.Format("Player {0} hired your worker !", //Check if player didnt disconnect since sending RPC default(PhotonPlayer) == sender ? string.Empty : sender.NickName); NotificatorComponent.Notify(notification); #if DEVELOPMENT_BUILD || UNITY_EDITOR string debugInfo = string.Format("[{3}] Player {0} (ID: {1}) removed worker ID: {2} from your company", sender.NickName, sender.ID, workerToRemove.ID, this.GetType().Name); Debug.Log(debugInfo); #endif }
private string CreateWorkerInfoString(LocalWorker companyWorker) { string workerInfo = string.Format("Name: {0}\n" + "Surename: {1}\n" + "Abilities: ", companyWorker.Name, companyWorker.Surename); foreach (KeyValuePair <ProjectTechnology, SafeFloat> workerAbility in companyWorker.Abilites) { string abilityName = EnumToString.ProjectTechnologiesStrings[workerAbility.Key]; workerInfo += string.Format("{0} {1} | ", abilityName, workerAbility.Value.Value.ToString("0.00")); } workerInfo += string.Format("\nSalary: {0}$\n" + "Satisfaction: {1}%\n" + "Days in company: {2}\n", companyWorker.Salary, companyWorker.Satiscation.ToString("0.00"), companyWorker.DaysInCompany); return(workerInfo); }
private ListViewElementWorker CreateWorkerListViewElement(LocalWorker companyWorker) { ListViewElementWorker newElement = null; if (null != WorkerListViewElementsPool) { newElement = WorkerListViewElementsPool.GetObject(); } if (null == newElement) { newElement = UIWorkers.CreateWorkerListViewElement(companyWorker, ListViewWorkerElementPrefab, TooltipComponent); UIElementDrag drag = newElement.GetComponent <UIElementDrag>(); drag.DragParentTransform = gameObject.GetComponent <RectTransform>(); } newElement.gameObject.SetActive(true); newElement.Text.text = GetWorkerListViewElementText(companyWorker); newElement.Worker = companyWorker; return(newElement); }
/// <summary> /// This method will enable or disable buttons used /// for hiring of firing workers based on which worker /// is selected (market worker or company worker) /// </summary> private void SetActionButtonsState(SharedWorker selectedWorker) { if (null != selectedWorker) { if (true == (selectedWorker is LocalWorker)) { LocalWorker selectedLocalWorker = (LocalWorker)selectedWorker; //Check if it is worker that was previously hired in this player's company //(will not be converted to SharedWorker since no need to send it through photon) if (selectedLocalWorker.WorkingCompany == null) { ButtonFireWorker.interactable = false; ButtonHireWorker.interactable = true; } else { ButtonFireWorker.interactable = true; ButtonHireWorker.interactable = false; } } else if (true == (selectedWorker is SharedWorker)) { ButtonFireWorker.interactable = false; ButtonHireWorker.interactable = true; } if (false == SimulationManagerComponent.ControlledCompany.CanHireWorker) { ButtonHireWorker.interactable = false; } } else { ButtonFireWorker.interactable = false; ButtonHireWorker.interactable = false; } }
private string GetWorkerListViewElementText(LocalWorker worker) { return(string.Format("{0} {1}\nSatisfaction {2} %\n{3} $ / Month", worker.Name, worker.Surename, worker.Satiscation.ToString("0.00"), worker.Salary)); }
public static string GetWorkerSatisfactionString(LocalWorker worker) { return(string.Format("{0} %", worker.Satiscation.ToString("0.00"))); }
private void OnCompanyWorkerAbilityUpdated(SharedWorker worker, ProjectTechnology workerAbility, float workerAbilityValue) { LocalWorker companyWorker = (LocalWorker)worker; SetWorkerAbilitiesText(); }