//Method to create new prefab with the proposal details ProposalPrefabView InitializePrefabView(GameObject viewGameObject, ProposalEvent model, string name) { ProposalPrefabView view = new ProposalPrefabView(viewGameObject.transform); view.proposalEvent = model; view.name = name; view.initialTime = model._timeToLive; view.summary.text = model._description; view.slider.value = 1f; return(view); }
//public method to update the prefab with the attached propsal event public void setEvent(ProposalEvent attachedEvent) { string str = attachedEvent._description; string mainDescriptionLine = new System.IO.StringReader(str).ReadLine(); Summary.text = mainDescriptionLine; PotentialReward.text = "Potential Reward = $" + attachedEvent._reward + "k"; ProposedBy.text = "Proposed by:"; if (attachedEvent._name.Count == 1) { ProposedBy.text = "Proposed by: " + attachedEvent._name[0]; } else { ProposedBy.text = "Proposed by: Many Employees"; } }
//Main get proposal event, randomly generates an event public ProposalEvent getActualProposalEvent(List <string> employees) { int eventRisk = Random.Range(1, 10); int eventReward = Random.Range(1, 10); int eventTeam = Random.Range(0, 3); int eventSkill = Random.Range(0, 3); //Main project description string[] projectArray = new string[] { "Release new innovative project.", "Outsource all phone opperations.", "Redesign current products.", "Horizontal intergration through buy out.", "Sell assets for temporary gain, aquire new assets later.", "Invest in research for potential future products.", "Sell stocks, raise funds.", "Temporary partnership with company in same sector." }; string eventDescription = ""; eventDescription += projectArray[Random.Range(0, projectArray.Length)] + "\n"; float eventChance = Random.Range(0f, 1f); GameObject controller = GameObject.Find("ControllerObject"); Controller controllerScript = (Controller)controller.GetComponent(typeof(Controller)); // Chance of failure if (eventChance <= 0.33f) { eventDescription += "this is low risk project with a low chance of failure"; } else if (eventChance > 0.33f && eventChance <= 0.66f) { eventDescription += "this is moderatly risky project with a good chance of failing"; } else { eventDescription += "this is a very risky project, the chances of failure are high"; } eventDescription += "\n"; //------------------------------------------------------------------------------------------ if (eventRisk <= 3) { eventDescription += "Failure of this project will result in minor damages"; } else if (eventRisk > 3 && eventRisk <= 6) { eventDescription += "Failure of this project will deal considerable damage to the Comapny"; } else { eventDescription += "Failure of this project is detrimental to the company"; } eventDescription += "\n"; //------------------------------------------------------------------------------------------- //Chance of sucess based on teamwork ability if (eventTeam == 2) { eventDescription += "The success of this project will require employees to have high teamwork"; if (controllerScript.teamWorkAve > 7) { eventChance += 0.2f; } else { eventChance -= 0.2f; } } else if (eventTeam == 1) { eventDescription += "The success of this project will require employees to have moderate teamwork"; if (controllerScript.teamWorkAve > 4) { eventChance += 0.1f; } else { eventChance -= 0.1f; } } else { eventDescription += "The success of this project is not affected by teamwork"; } eventDescription += "\n"; //------------------------------------------------------------------------------------------- // Chance of success based of ability if (eventSkill == 2) { eventDescription += "The success of this project will require employees to have high skill"; if (controllerScript.skillAve > 7) { eventChance += 0.2f; } else { eventChance -= 0.2f; } } else if (eventSkill == 1) { eventDescription += "The success of this project will require employees to have moderate skill"; if (controllerScript.skillAve > 4) { eventChance += 0.1f; } else { eventChance -= 0.1f; } } else { eventDescription += "The success of this project is not affected by skill"; } eventDescription += "\n"; //------------------------------------------------------------------------------------------- //Describe event risk's effect to the company if (eventRisk <= 3) { eventDescription += "Failure of this project will result in minor damages"; } else if (eventRisk > 3 && eventRisk <= 6) { eventDescription += "Failure of this project will deal considerable damage to the Comapny"; } else { eventDescription += "Failure of this project is detrimental to the company"; } eventDescription += "\n"; //------------------------------------------------------------------------------------------- //Name who is it proposed by eventDescription += "Proposed by:"; int count = 0; foreach (string employee in employees) { if (count == 0) { eventDescription += " " + employee; } else { eventDescription += ", " + employee; } count++; } eventDescription += "\n"; //Name the potential reward/ loss eventDescription += "Estimated reward: $" + eventReward + "k\n"; eventDescription += "Estimated loss: $" + eventRisk + "k\n"; //Create and return the new event ProposalEvent pEvent = new ProposalEvent(employees, eventDescription, eventRisk, eventReward, eventChance, 35.0f, 10.0f); return(pEvent); }