//Set the end destination for the person from the Form so that the personality is already assigned //When the destination changes (for the "selfish prick"), this method will create a new algorithm for the extinguisher as the end point public void SetDestination(Tile endPoint) { if (endPoint != null) { this.endLocation = endPoint; exitDoorColor = endLocation.colorInBitmap; } else { this.personality = PERSONALITY.SHAGGY_FROM_SCOOBY_DOO; //run in circles if no end goal } }
//THE FOLLOWING METHOD IS ONLY FOR PERFORMING UNIT TESTS //NOT USED ANYWHERE ELSE public void SWITCHPERSONALITYFORTESTING(PERSONALITY newPers) { if (this.personality != PERSONALITY.HERO_OF_MANKIND && newPers == PERSONALITY.HERO_OF_MANKIND) { this.SetDestination(GetClosestFireExtinguisher(this.currentLocation)); } else if (this.personality != PERSONALITY.PUSSY && newPers == PERSONALITY.PUSSY || personality != PERSONALITY.SELFISH_PRICK && newPers == PERSONALITY.SELFISH_PRICK) { this.SetDestination(GetClosestFireEscape(this.currentLocation)); } this.personality = newPers; }
public void ResetAllStats() { attack_point = base_attack_point; speed_point = base_speed_point; magic_point = base_magic_point; luck_point = base_luck_point; defence_point = base_defence_point; health_point = base_health_point; energy_point = base_energy_point; mood = (PERSONALITY)Random.Range(0, (int)PERSONALITY.TOTAL); MoodOnEffectingStats(); }
//Setters public void SetAllRobotStatus(float att, float spd, float mag, float luk, float def, float hp, float enrg, PERSONALITY p) { attack_point = att; speed_point = spd; magic_point = mag; luck_point = luk; defence_point = def; health_point = hp; energy_point = enrg; base_attack_point = att; base_speed_point = spd; base_magic_point = mag; base_luck_point = luk; base_defence_point = def; base_health_point = hp; base_energy_point = enrg; personality = p; mood = (PERSONALITY)Random.Range(0, (int)PERSONALITY.TOTAL); MoodOnEffectingStats(); }
//IF PERSONALITY IS "SELFISH" public void ExitOrExtinguisher() // { this.NewAlgorithm(); if (!this.exitBlocked) { this.RunForTheExit(); // run for exit until path is blocked } else if (!this.extinguisherBlocked) { if (!selfishChanged) //if the new goal (extinguisher) has not been changed, change it { this.SetDestination(GetClosestFireExtinguisher(currentLocation)); this.selfishChanged = true; } this.RunForExtinguisher(); //run for extinguisher if extinguisher is not blocked } else { this.personality = PERSONALITY.SHAGGY_FROM_SCOOBY_DOO; //run in circles } }
//------------PATHFINDING ALGORITHMS---------------- // //The appropriate method will be called on each timer tick //The method calculates the next move and calls the corresponding //method for moving from the ones above //(Up, Down, Left or Right) //IF PERSONALITY IS "PUSSY" public void RunForTheExit() { this.NewAlgorithm(); //create a new a* algorithm if (currentLocation == endLocation) { this.Save(); //person is saved return; } else if (currentLocation.onFire) { this.Die(); //person dies return; } if (blindPath != null) { if (this.blindPath.Count == 0) //if the blind path is empty { blindPath = this.A_STAR.GetFullPath(); //get a new path if (blindPath != null) { this.blindPath.RemoveAt(blindPath.Count - 1); //remove the start position this.RunForTheExit(); //call the method with a path return; } } else { //run algorithm to determine where to move Tile nextLocation; nextLocation = this.blindPath[blindPath.Count - 1]; //get the next move //check the line of sight, because it removes the tiles on fire if (nextLocation.onFire || !lineOfSight.Contains(nextLocation)) //if the next location is on fire OR if it is not in the line of sight { //find a way to go around it if possible //get the first tile which is not on fire for (int i = blindPath.Count - 1; i >= 0; i--) //go through the list { if (!blindPath[i].onFire || i == 0) //find the first tile in the list that is not on fire { nextLocation = this.CheckAvailablePath(blindPath[i]); //the next move should be in regards to going around the fire break; } else { blindPath.RemoveAt(i); //remove the tile on fire } } } //if there is no way to go around the fire if (nextLocation == null) { if (this.fireEscapes.Count > 0) //if there are other escapes { this.SetDestination(GetClosestFireEscape(currentLocation)); //change to the closest one available this.blindPath.Clear(); //empty the blind path to set a new one this.RunForTheExit(); //enter recursion to avoid staying in one place for too long return; //exit out of the recursion } else //if no exits are available { this.exitBlocked = true; //if person is a shelfish prick and the path to exit is blocked, he will run for extinguisher if (this.personality != PERSONALITY.SELFISH_PRICK) //check in case the person is not selfish (if hero or pussy) { this.personality = PERSONALITY.SHAGGY_FROM_SCOOBY_DOO; //person starts to move in circles } } } else { //move to the appropriate location if (nextLocation == currentLocation.up) { MoveUp(); } else if (nextLocation == currentLocation.left) { MoveLeft(); } else if (nextLocation == currentLocation.down) { MoveDown(); } else if (nextLocation == currentLocation.right) { MoveRight(); } else { } //if next location is the current one, stay here if (blindPath.Contains(nextLocation)) //if the next location is part of the blind path after all this { for (int i = blindPath.Count - 1; i >= 0; i--) //loop through the list in reverse (from current to end) { if (blindPath[i] != nextLocation) //if there are tiles before the next move { blindPath.RemoveAt(i); //remove them (this will put the person back on track) } else { break; //once it reaches the nextLocation, break the loop } } //finally, remove the next location from the blind Path blindPath.Remove(nextLocation); } } } } }
//Constructor with option to create a person with specified personality public Person(Tile start, List <Tile> escapes, List <Tile> extinguishers, Tile[,] grid, PERSONALITY personality) { rand = new Random((int)DateTime.Now.Ticks); this.personality = personality; //Assign a custom personality //Random check if going to leave doors open or not if (rand.Next(0, 100) < 40) { leaveDoorOpen = true; } else { leaveDoorOpen = false; } //set id this.Id = Grid.personIdCounter; Grid.personIdCounter++; //Initialize starting point and current location this.startLocation = this.currentLocation = this.previousLocation = start; //Initialize dead, saved and path blocked to false in beginning this.isDead = this.isSaved = exitBlocked = extinguisherBlocked = false; //the destination change is not yet made for the selfish prick and the hero this.selfishChanged = this.heroChanged = false; //keep track of the colour of the next Tile this.nextTileColor = start.colorInBitmap; //create the lists for exits and extinguishers and the grid fireEscapes = new List <Tile>(); fireExtinguishers = new List <Tile>(); this.grid = new List <Tile>(); //set the shared extinguishers this.sharedExtinguishers = extinguishers; //set the available exits and extinguishers foreach (Tile t in escapes) { this.fireEscapes.Add(t); } foreach (Tile t in extinguishers) { this.fireExtinguishers.Add(t); } //set the end location this.SetInitialEndPoint(start); //set the line of sight this.lineOfSight = new List <Tile>(); this.UpdateLineOfSight(); this.blindPath = new List <Tile>(); //store the grid for Dijkstra and another copy for local use foreach (Tile t in grid) { this.grid.Add(t); } currentLocation.personOnTile = true; }
//Constructor public Person(Tile start, List <Tile> escapes, List <Tile> extinguishers, Tile[,] grid) { rand = new Random((int)DateTime.Now.Ticks); //assign a pesonality trait based on the generated percentage switch (rand.Next(0, 101)) { //0 or 1 percent case int n when(n >= 0 && n < 2): personality = PERSONALITY.SHAGGY_FROM_SCOOBY_DOO; //run randomly break; //70-89 percent case int n when(n >= 70 && n < 90): personality = PERSONALITY.SELFISH_PRICK; //run for exit, if blocked, run for extinguisher break; //90-100 percent case int n when(n >= 90 && n <= 100): personality = PERSONALITY.HERO_OF_MANKIND; //run for extinguisher break; //2-69 percent default: personality = PERSONALITY.PUSSY; //run for evacuation break; } //Random check if going to leave doors open or not if (rand.Next(0, 100) < 40) { leaveDoorOpen = true; } else { leaveDoorOpen = false; } //set id this.Id = Grid.personIdCounter; Grid.personIdCounter++; //Initialize starting point and current location this.startLocation = this.currentLocation = this.previousLocation = start; //Initialize dead, saved and path blocked to false in beginning this.isDead = this.isSaved = exitBlocked = extinguisherBlocked = false; //the destination change is not yet made for the selfish prick and the hero this.selfishChanged = this.heroChanged = false; //keep track of the colour of the next Tile this.nextTileColor = start.colorInBitmap; //create the lists for exits and extinguishers and the grid fireEscapes = new List <Tile>(); fireExtinguishers = new List <Tile>(); this.grid = new List <Tile>(); //set the shared extinguishers this.sharedExtinguishers = extinguishers; //set the available exits and extinguishers foreach (Tile t in escapes) { this.fireEscapes.Add(t); } foreach (Tile t in extinguishers) { this.fireExtinguishers.Add(t); } //set the end location this.SetInitialEndPoint(start); //set the line of sight this.lineOfSight = new List <Tile>(); this.UpdateLineOfSight(); this.blindPath = new List <Tile>(); //store the grid for Dijkstra and another copy for local use foreach (Tile t in grid) { this.grid.Add(t); } currentLocation.personOnTile = true; }
public void SetMood(PERSONALITY p) { mood = p; }
public void SetPersonality(PERSONALITY p) { personality = p; }
public void RandomMood() { mood = (PERSONALITY)Random.Range(0, (int)PERSONALITY.TOTAL); MoodOnEffectingStats(); }
// Update is called once per frame void Update() { if (baseUIcs.target != null || monsterUIcs.target != null) { this_obj.SetActive(false); } else { this_obj.SetActive(true); } //左クリックした奴を顔を拡大して出す。 // 左クリックされた場所のオブジェクトを取得 // Left Click if (Input.GetMouseButtonDown(0)) { Vector2 tapPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition); Collider2D collition2d = Physics2D.OverlapPoint(tapPoint); if (collition2d && collition2d.gameObject.tag == "Robot") { //BaseUIStateがtrueだったらBaseUIを消す if (baseUIcs.target != null) { Destroy(baseUIcs.target); } else if (monsterUIcs.target != null) { Destroy(monsterUIcs.target); } //すでにRobotのUIが表示されていたら消す if (statusClone != null) { Destroy(target); Destroy(statusClone); } _getObject = collition2d.transform.gameObject; //Make clone of robot clicked //クリックしたロボットのcloneを作る //ロボットの性格を読み取る statusClone = Instantiate(_getObject, new Vector2(-40.0f, clonePotision.y), Quaternion.identity); statusClone.gameObject.tag = "clone"; robot_status = _getObject.GetComponent <Robot_Status>(); if (!deadState) { viewNum = (int)robot_status.GetMood(); } else { viewNum = 6; } target = Instantiate(viewUI[viewNum], new Vector2(clonePotision.x, clonePotision.y), Quaternion.identity); } } //scripts取得 //HP Energyリアルタイム更新 //cloneのスピード0 if (_getObject != null) { robot_status = _getObject.GetComponent <Robot_Status>(); if (statusClone != null) { clone_status = statusClone.GetComponent <Robot_Status>(); //target clone_status.speed_point = 0.0f; //hp energy test clone_status.SetHealthPoint(robot_status.GetHealthPoint()); clone_status.SetEnergyPoint(robot_status.GetEnergyPoint()); } } //ステータスリアルタイム更新 if (robot_status != null) { //Get Status Here hp_point = robot_status.GetHealthPoint(); energy_point = robot_status.GetEnergyPoint(); personality_point = robot_status.GetPersonality(); mood_point = robot_status.GetMood(); atk_point = robot_status.GetAttackPoint(); spd_point = robot_status.GetSpeedPoint(); int_point = robot_status.GetMagicPoint(); luk_point = robot_status.GetLuckPoint(); def_point = robot_status.GetDefencePoint(); uihp_point = (int)hp_point; uienergy_point = (int)robot_status.GetEnergyPoint(); if ((hp_point <= 0 || energy_point <= 0)) { textDead = "DEAD"; viewNum = 6; deadState = true; } else { textDead = personality_point.ToString(); deadState = false; } Debug.Log(viewNum); //Text statusText[(int)STATUS.PERSONALITY].text = ":" + textDead; statusText[(int)STATUS.MOOD].text = ":" + mood_point; statusText[(int)STATUS.ATK].text = "ATK:" + atk_point.ToString(); statusText[(int)STATUS.SPD].text = "SPD:" + spd_point.ToString(); statusText[(int)STATUS.INT].text = "MAG:" + int_point.ToString(); statusText[(int)STATUS.LUK].text = "LCK:" + luk_point.ToString(); statusText[(int)STATUS.DEF].text = "DEF:" + def_point.ToString(); statusText[(int)STATUS.HP].text = "HELTH" + uihp_point.ToString() + "/" + robot_status.GetBaseHealthPoint(); statusText[(int)STATUS.ENERGY].text = "ENERGY" + uienergy_point.ToString() + "/" + robot_status.GetBaseEnergyPoint(); } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { Vector2 tapPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition); Collider2D collition2d = Physics2D.OverlapPoint(tapPoint); if (collition2d && collition2d.gameObject.tag == "Robot") { if (statusClone != null) { Destroy(target); Destroy(statusClone); } _getObject = collition2d.transform.gameObject; statusClone = Instantiate(_getObject, new Vector2(-40.0f, clonePotision.y), Quaternion.identity); statusClone.gameObject.tag = "clone"; robot_status = _getObject.GetComponent <Robot_Status>(); if (!deadState) { viewNum = (int)robot_status.GetMood(); } else { viewNum = 6; } target = Instantiate(viewUI[viewNum], new Vector2(clonePotision.x, clonePotision.y), Quaternion.identity); } } //scripts取得 //HP Energyリアルタイム更新 //cloneのスピード0 if (_getObject != null) { robot_status = _getObject.GetComponent <Robot_Status>(); if (statusClone != null) { clone_status = statusClone.GetComponent <Robot_Status>(); //target clone_status.speed_point = 0.0f; //hp energy test clone_status.SetHealthPoint(robot_status.GetHealthPoint()); clone_status.SetEnergyPoint(robot_status.GetEnergyPoint()); } } //ステータスリアルタイム更新 if (robot_status != null) { //Get Status Here hp_point = robot_status.GetHealthPoint(); energy_point = robot_status.GetEnergyPoint(); personality_point = robot_status.GetPersonality(); mood_point = robot_status.GetMood(); atk_point = robot_status.GetAttackPoint(); spd_point = robot_status.GetSpeedPoint(); int_point = robot_status.GetMagicPoint(); luk_point = robot_status.GetLuckPoint(); def_point = robot_status.GetDefencePoint(); uihp_point = (int)hp_point; uienergy_point = (int)robot_status.GetEnergyPoint(); if ((hp_point <= 0 || energy_point <= 0)) { textDead = "DEAD"; viewNum = 6; deadState = true; } else { textDead = personality_point.ToString(); deadState = false; } Debug.Log(viewNum); //Text statusText[(int)STATUS.PERSONALITY].text = ":" + textDead; statusText[(int)STATUS.MOOD].text = ":" + mood_point; statusText[(int)STATUS.ATK].text = "ATK: " + atk_point.ToString(); statusText[(int)STATUS.SPD].text = "SPD: " + spd_point.ToString(); statusText[(int)STATUS.INT].text = "MAG: " + int_point.ToString(); statusText[(int)STATUS.LUK].text = "LCK: " + luk_point.ToString(); statusText[(int)STATUS.DEF].text = "DEF: " + def_point.ToString(); statusText[(int)STATUS.HP].text = "HP: " + uihp_point.ToString(); statusText[(int)STATUS.ENERGY].text = "ENE: " + uienergy_point.ToString(); } }