using System; using System.Collections; using System.Text; using UnityEngine; public class MedScanMinigame : Minigame { private static readonly string[] ColorNames = new string[] { "Red", "Blue", "Green", "Pink", "Orange", "Yellow", "Black", "White", "Purple", "Brown", "Cyan", "Lime" }; private static readonly string[] BloodTypes = new string[] { "O-", "A-", "B-", "AB-", "O+", "A+", "B+", "AB+" }; public TextRenderer text; public TextRenderer charStats; public HorizontalGauge gauge; private MedScanSystem medscan; public float ScanDuration = 10f; public float ScanTimer; private string completeString; public AudioClip ScanSound; public AudioClip TextSound; private Coroutine walking; private MedScanMinigame.PositionState state; private enum PositionState { None, WalkingToPad, WalkingToOffset } public override void Begin(PlayerTask task) { base.Begin(task); this.medscan = (ShipStatus.Instance.Systems[SystemTypes.MedBay] as MedScanSystem); this.gauge.Value = 0f; base.transform.position = new Vector3(100f, 0f, 0f); GameData.PlayerInfo data = PlayerControl.LocalPlayer.Data; int playerId = (int)data.PlayerId; int colorId = (int)data.ColorId; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("ID: "); stringBuilder.Append(MedScanMinigame.ColorNames[colorId].Substring(0, 3).ToUpperInvariant()); stringBuilder.Append("P" + playerId); stringBuilder.Append(new string(' ', 8)); stringBuilder.Append("HT: 3' 6\""); stringBuilder.Append(new string(' ', 8)); stringBuilder.Append("WT: 92lb"); stringBuilder.AppendLine(); stringBuilder.Append("C: "); stringBuilder.Append(MedScanMinigame.ColorNames[colorId].PadRight(17)); stringBuilder.Append("BT: "); stringBuilder.Append(MedScanMinigame.BloodTypes[playerId * 3 % MedScanMinigame.BloodTypes.Length]); this.completeString = stringBuilder.ToString(); this.charStats.Text = string.Empty; ShipStatus.Instance.RpcRepairSystem(SystemTypes.MedBay, playerId | 128); this.walking = base.StartCoroutine(this.WalkToOffset()); } private IEnumerator WalkToOffset() { this.state = MedScanMinigame.PositionState.WalkingToOffset; PlayerPhysics myPhysics = PlayerControl.LocalPlayer.MyPhysics; Vector2 vector = ShipStatus.Instance.MedScanner.transform.position; Vector2 a = Vector2.left.Rotate((float)(PlayerControl.LocalPlayer.PlayerId * 36)); vector += a / 2f; Camera.main.GetComponent().Locked = false; yield return myPhysics.WalkPlayerTo(vector, 0.001f); yield return new WaitForSeconds(0.1f); Camera.main.GetComponent().Locked = true; this.walking = null; yield break; } private IEnumerator WalkToPad() { this.state = MedScanMinigame.PositionState.WalkingToPad; PlayerPhysics myPhysics = PlayerControl.LocalPlayer.MyPhysics; Vector2 worldPos = ShipStatus.Instance.MedScanner.transform.position; worldPos.x += 0.14f; worldPos.y += 0.1f; Camera.main.GetComponent().Locked = false; yield return myPhysics.WalkPlayerTo(worldPos, 0.001f); yield return new WaitForSeconds(0.1f); Camera.main.GetComponent().Locked = true; this.walking = null; yield break; } private void FixedUpdate() { if (this.MyNormTask.IsComplete) { return; } byte playerId = PlayerControl.LocalPlayer.PlayerId; if (this.medscan.CurrentUser != playerId) { if (this.medscan.CurrentUser == 255) { this.text.Text = "Scan requested"; return; } GameData.PlayerInfo playerById = GameData.Instance.GetPlayerById(this.medscan.CurrentUser); this.text.Text = "Waiting for " + playerById.PlayerName; return; } else { if (this.state != MedScanMinigame.PositionState.WalkingToPad) { if (this.walking != null) { base.StopCoroutine(this.walking); } this.walking = base.StartCoroutine(this.WalkToPad()); return; } if (this.walking != null) { return; } if (this.ScanTimer == 0f) { PlayerControl.LocalPlayer.RpcSetScanner(true); SoundManager.Instance.PlaySound(this.ScanSound, false, 1f); } this.ScanTimer += Time.fixedDeltaTime; this.gauge.Value = this.ScanTimer / this.ScanDuration; int num = (int)(Mathf.Min(1f, this.ScanTimer / this.ScanDuration * 1.25f) * (float)this.completeString.Length); if (num > this.charStats.Text.Length) { this.charStats.Text = this.completeString.Substring(0, num); if (this.completeString[num - 1] != ' ') { SoundManager.Instance.PlaySoundImmediate(this.TextSound, false, 0.7f, 0.3f); } } if (this.ScanTimer >= this.ScanDuration) { PlayerControl.LocalPlayer.RpcSetScanner(false); this.text.Text = "Scan complete"; this.MyNormTask.NextStep(); ShipStatus.Instance.RpcRepairSystem(SystemTypes.MedBay, (int)(playerId | 64)); base.StartCoroutine(base.CoStartClose(0.75f)); return; } this.text.Text = "Scan complete in: " + (int)(this.ScanDuration - this.ScanTimer); return; } } public override void Close() { base.StopAllCoroutines(); byte playerId = PlayerControl.LocalPlayer.PlayerId; SoundManager.Instance.StopSound(this.TextSound); SoundManager.Instance.StopSound(this.ScanSound); PlayerControl.LocalPlayer.RpcSetScanner(false); ShipStatus.Instance.RpcRepairSystem(SystemTypes.MedBay, (int)(playerId | 64)); Camera.main.GetComponent().Locked = false; base.Close(); } }