using ShotSimulator.Screen; using ShotSimulator.Target; using ShotSimulator.Tool; using ShotSimulator.Train.Info; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using Random = UnityEngine.Random; namespace ShotSimulator.Train { public class SixTargetsShotTrainHandle : BaseTrainHandle { private int maxTargetNum = 6; private SixTargetsShotDifficultyData m_DifficultyData; private SixTargetsShotScoreData m_ScoreData; private double m_TotalHitNum; private double TotalHitNum { get { return m_TotalHitNum; } set { m_TotalHitNum = value; UpdatePrecision(); } } private double m_MissHitNum; private double MissHitNum { get { return m_MissHitNum; } set { m_MissHitNum = value; UpdatePrecision(); } } private double totalTargetNum; private List curTargets = new List(); public SixTargetsShotTrainHandle(BaseTrainCallBack callBack, BaseTrainInfo info, DifficultyType difficultyType) : base(callBack, info, difficultyType) { SetShotTargetInteractiveEvent(ShotTargetInteractiveType.OnClick, OnShottedTargetEvent); m_DifficultyData = info.GetDifficultyData(m_DifficultyType); m_ScoreData = info.GetScoreData(m_DifficultyType); } #region Train protected override void ResetTrain() { ResetTarget(); m_TotalHitNum = 0; m_MissHitNum = 0; totalTargetNum = 0; } public override void StartTrain() { base.StartTrain(); GenerateShootTargets(); } public override void CalculateTrainResult() { SetResultMetricsDataValue(MetricsType.Kill_Sec, Math.Round(TotalHitNum / TrainInfo.duration, 2)); SetResultMetricsDataValue(MetricsType.KillTotal, TotalHitNum); SetResultMetricsDataValue(MetricsType.Target, totalTargetNum); SetResultMetricsDataValue(MetricsType.TimeToKill, Math.Round(TrainInfo.duration / TotalHitNum, 2)); } #endregion #region ShootTarget private void OnShottedTargetEvent(BaseShotTarget target) { if (target != null) { int comboS = Mathf.CeilToInt(m_ScoreData.baseScore * comboNums * m_ScoreData.comboMul); int bestS = m_IsBestHit ? Mathf.CeilToInt(m_ScoreData.baseScore * m_ScoreData.bestHitMul) : 0; IncreaseScore(m_ScoreData.baseScore + comboS + bestS); TotalHitNum++; DestroyShootTarget(target as SphereShotTarget); GenerateShootTargets(); } else { MissHitNum++; comboNums = 0; int missPunitiveS = Mathf.CeilToInt(m_ScoreData.baseScore * m_ScoreData.missPunitiveMul); IncreaseScore(missPunitiveS * -1); } } #endregion private void GenerateShootTargets() { int num = maxTargetNum - curTargets.Count; for (int i = 0; i < num; i++) { GameObject obj = GameObject.Instantiate(Resources.Load("Prefabs/SphereTarget")); SphereShotTarget target = obj.GetComponent(); target.IsRunning = true; target.onClickCanChangeColor = false; target.onHoveringCanChangeColor = false; target.defaultColor = ScreenEffectManager.GetInstance().GetTargetColor(); target.Init(1, ReduceHealthTriggerType.OnClick, false, ReduceHealthType.Per, MotionType.None, RandomPosition()); curTargets.Add(target); totalTargetNum++; } StartBestHitTimer(); } private void DestroyShootTarget(SphereShotTarget target) { if (target != null) { curTargets.Remove(target); target.IsRunning = false; GameObject.Destroy(target.gameObject); } } private Vector3 RandomPosition() { List positions = curTargets.GetGameObjectWorldPosition(); Vector2 widthLimt = Vector2.zero; Vector2 heightLimt = Vector2.zero; switch (m_DifficultyType) { case DifficultyType.Standard: widthLimt = new Vector2(-12, 12); heightLimt = new Vector2(-1.5f, 4f); break; case DifficultyType.Advance: widthLimt = new Vector2(-12, 12); heightLimt = new Vector2(-1.5f, 6f); break; case DifficultyType.Professional: widthLimt = new Vector2(-12, 12); heightLimt = new Vector2(-1.5f, 7f); break; } Vector3 min = ExtraTool.GetScreenOffsetPosition(ExtraTool.Sphere_Diameter1_ScreenLeftBottomOffset, m_DifficultyData.distance, widthLimt, heightLimt); Vector3 max = ExtraTool.GetScreenOffsetPosition(ExtraTool.Sphere_Diameter1_ScreenRightTopOffset, m_DifficultyData.distance, widthLimt, heightLimt); if(ExtraTool.TryGetNonOverlapRamdonPos(positions, min, max, 1, out Vector3 ramdonPos, true)) { return ramdonPos; } else { return new Vector3(0, 0, m_DifficultyData.distance); } } private void ResetTarget() { for (int i = 0; i < curTargets.Count; i++) { curTargets[i].IsRunning = false; GameObject.Destroy(curTargets[i].gameObject); } curTargets.Clear(); } #region TrainResult private void UpdatePrecision() { double totalShot = TotalHitNum + MissHitNum; double precision = 0; if (totalShot != 0) { precision = Math.Round(TotalHitNum / totalShot, 2); } SetResultMetricsDataValue(MetricsType.Precision, precision); } #endregion } }