public void Initialize(int id, string name, PieceRole role, Vector2 position, Path currentPath, PieceType pType, Team team) { //Debug.Log("initialize"); //_debugStrings = new List<string>(); SetStandardStats(); _id = id; _name = name; _role = role; _team = team; _position = position; _currentPath = currentPath; if (_currentPath != null) { GetNextDestination(); } else { _destination = _position; } _type = pType; _dir = PieceDir.NONE; _moveState = PieceMoveState.NONE; CalculateStatsFromData(); if (_role == PieceRole.DEFENSE) { _coolDownTime = 1.0f; } else { _coolDownTime = 1.0f; } _ammo = new AmmoBandelier(); GenerateRandomAmmo(); SetPosition(); switch (_type) { case PieceType.GENDER_NEUTRAL_1: Anim.speed = UnityEngine.Random.Range(0.9f, 0.95f); break; case PieceType.GENDER_NEUTRAL_2: Anim.speed = UnityEngine.Random.Range(1.0f, 1.05f); break; case PieceType.MALE: Anim.speed = UnityEngine.Random.Range(0.95f, 1.0f); break; case PieceType.FEMALE: Anim.speed = UnityEngine.Random.Range(1.05f, 1.1f); break; } }
public void SetPieceFromPieceData(PieceData piece, Team redTeam, Team blueTeam) { // base data SetStandardStats(); _id = piece.player_id; _name = piece.player_name; // set team if (piece.team_name == "red") { _team = redTeam; } else { _team = blueTeam; this.gameObject.transform.localEulerAngles = new Vector3(0.0f, 180.0f, 0.0f); } // set path/position _position = new Vector2(piece.path[0].x, piece.path[0].y); SetPosition(); if (piece.path.Count > 1) { _currentPath = new Path(piece.path); _role = PieceRole.OFFENSE; } else { _currentPath = null; _role = PieceRole.DEFENSE; } if (_currentPath != null) { GetNextDestination(); } else { _destination = _position; } // set body type switch (piece.body_type) { case "gender_neutral_1": _type = PieceType.GENDER_NEUTRAL_1; Anim.speed = UnityEngine.Random.Range(0.9f, 0.95f); break; case "gender_neutral_2": _type = PieceType.GENDER_NEUTRAL_2; Anim.speed = UnityEngine.Random.Range(1.0f, 1.05f); break; case "male": _type = PieceType.MALE; Anim.speed = UnityEngine.Random.Range(0.95f, 1.0f); break; default: _type = PieceType.FEMALE; Anim.speed = UnityEngine.Random.Range(1.05f, 1.1f); break; } // stats _health = piece.health; _speed = (int)piece.speed; //_speed = UnityEngine.Random.Range(1, 5); /* * int random = UnityEngine.Random.Range(0, 2); * if (random == 0) * _speed = 0; * else * _speed = 20; * */ //_speed = 0; _range = (int)piece.range; CalcStatValues(); // initialization if (_role == PieceRole.DEFENSE) { _coolDownTime = 1.0f; } else { _coolDownTime = 1.0f; } // sprite colors int randomIndex = -1; if (piece.hair_color != null) { HairSpriteRend.color = Colors.HexToColor(piece.hair_color); } else { // no hair color found - set random hair color randomIndex = UnityEngine.Random.Range(0, Database.Instance.HairColors.Count); HairSpriteRend.color = Colors.HexToColor(Database.Instance.HairColors[randomIndex]); } if (piece.skin_color != null) { SpriteRend.color = Colors.HexToColor(piece.skin_color); } else { // random skin color randomIndex = UnityEngine.Random.Range(0, Database.Instance.SkinColors.Count); SpriteRend.color = Colors.HexToColor(Database.Instance.SkinColors[randomIndex]); } if (_team.GetColor == TeamColor.RED) { ShirtSpriteRend.color = Colors.RedShirtColor; } else { ShirtSpriteRend.color = Colors.BlueShirtColor; } //ShortsSpriteRend.color = new Color(UnityEngine.Random.Range(0.0f, 1.0f), UnityEngine.Random.Range(0.0f, 1.0f), UnityEngine.Random.Range(0.0f, 1.0f)); //ShoesSpriteRend.color = new Color(UnityEngine.Random.Range(0.0f, 1.0f), UnityEngine.Random.Range(0.0f, 1.0f), UnityEngine.Random.Range(0.0f, 1.0f)); // set ammo _ammo = new AmmoBandelier(); for (int i = 0; i < piece.ammo.Count; i++) { _ammo.AddAmmo((AmmoType)Enum.Parse(typeof(AmmoType), piece.ammo[i].ToUpper(), true)); } //GenerateRandomAmmo(); }