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 MotionTargetShotTrainHandle : BaseTrainHandle { private SphereShotTarget curTarget; private MotionTargetShotTrainDifficultyData m_DifficultyData; private MotionTargetShotTrainScoreData m_ScoreData; private List m_CurBrokenLineOffset; private List m_StandardBrokenLineOffset = new List() { new Vector2(0.35f,0.25f), new Vector2(0.4f,0.75f), new Vector2(0.45f,0.25f), new Vector2(0.5f,0.75f), new Vector2(0.55f,0.25f), new Vector2(0.6f,0.75f), new Vector2(0.65f,0.25f) }; private List m_AdvanceBrokenLineOffset = new List() { new Vector2(0.25f,0.25f), new Vector2(0.3f,0.75f), new Vector2(0.35f,0.25f), new Vector2(0.4f,0.75f), new Vector2(0.45f,0.25f), new Vector2(0.5f,0.75f), new Vector2(0.55f,0.25f), new Vector2(0.6f,0.75f), new Vector2(0.65f,0.25f), new Vector2(0.7f,0.75f), new Vector2(0.75f,0.25f) }; private List m_ProfessionalBrokenLineOffset = new List() { new Vector2(0.3f,0.75f), new Vector2(0.35f,0.25f), new Vector2(0.4f,0.75f), new Vector2(0.45f,0.25f), new Vector2(0.5f,0.75f), new Vector2(0.55f,0.25f), new Vector2(0.6f,0.75f), new Vector2(0.65f,0.25f), new Vector2(0.7f,0.75f) }; private int roundIndex; 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 totalKillNums; private double totalTargetNums; public MotionTargetShotTrainHandle(BaseTrainCallBack callBack, BaseTrainInfo info, DifficultyType difficultyType) : base(callBack, info, difficultyType) { SetShotTargetInteractiveEvent(ShotTargetInteractiveType.OnClick, OnClickTargetEvent); m_DifficultyData = info.GetDifficultyData(m_DifficultyType); m_ScoreData = info.GetScoreData(m_DifficultyType); } private void GenerateShotTargets() { roundIndex++; int round = roundIndex % 2; GameObject obj = GameObject.Instantiate(Resources.Load("Prefabs/SphereTarget")); curTarget = obj.GetComponent(); curTarget.onClickCanChangeColor = false; curTarget.onHoveringCanChangeColor = false; curTarget.defaultColor = ScreenEffectManager.GetInstance().GetTargetColor(); curTarget.onHoveringColor = Color.red; MotionType motionType = MotionType.None; List motionPos = new List(); Vector3 origin = new Vector3(); if (round == 1) { motionType = MotionType.None; origin = new Vector3(0, 0, m_DifficultyData.targetDistance); } else { motionType = MotionType.PingPong; //switch (m_DifficultyType) //{ // case DifficultyType.Standard: // m_CurBrokenLineOffset = m_StandardBrokenLineOffset; // break; // case DifficultyType.Advance: // m_CurBrokenLineOffset = m_AdvanceBrokenLineOffset; // break; // case DifficultyType.Professional: // m_CurBrokenLineOffset = m_ProfessionalBrokenLineOffset; // break; //} //for (int i = 0; i < m_CurBrokenLineOffset.Count; i++) //{ // motionPos.Add(RandomPosition(i)); //} for (int i = 0; i < 20; i++) { motionPos.Add(RandomPosition()); } curTarget.curTargetPosIndex = Random.Range(0, motionPos.Count); origin = motionPos[curTarget.curTargetPosIndex]; } curTarget.Init(1, ReduceHealthTriggerType.OnClick, false, ReduceHealthType.Per, motionType, origin, motionPos, m_DifficultyData.speed); curTarget.IsRunning = true; totalTargetNums++; StartBestHitTimer(); } private Vector3 RandomPosition(int index) { Vector2 widthLimt = Vector2.zero; Vector2 heightLimt = Vector2.zero; switch (m_DifficultyType) { case DifficultyType.Standard: widthLimt = new Vector2(-4, 4); heightLimt = new Vector2(-1.5f, 1.5f); break; case DifficultyType.Advance: widthLimt = new Vector2(-8, 8); heightLimt = new Vector2(-1.5f, 3.5f); break; case DifficultyType.Professional: widthLimt = new Vector2(-8, 8); heightLimt = new Vector2(-1.5f, 5f); break; } return ExtraTool.GetScreenOffsetPosition(m_CurBrokenLineOffset[index], m_DifficultyData.targetDistance, widthLimt, heightLimt); } private void ResetTarget() { if (curTarget != null) { curTarget.IsRunning = false; GameObject.Destroy(curTarget.gameObject); curTarget = null; } } private void DestroyShootTarget(SphereShotTarget target) { if (target != null) { target.IsRunning = false; GameObject.Destroy(target.gameObject); } } private Vector3 RandomPosition() { Vector2 widthLimt = Vector2.zero; Vector2 heightLimt = Vector2.zero; switch (m_DifficultyType) { case DifficultyType.Standard: widthLimt = new Vector2(-4, 4); heightLimt = new Vector2(-1.5f, 1.5f); break; case DifficultyType.Advance: widthLimt = new Vector2(-8, 8); heightLimt = new Vector2(-1.5f, 3.5f); break; case DifficultyType.Professional: widthLimt = new Vector2(-8, 8); heightLimt = new Vector2(-1.5f, 5f); break; } Vector3 min = ExtraTool.GetScreenOffsetPosition(ExtraTool.Sphere_Diameter1_ScreenLeftBottomOffset, m_DifficultyData.targetDistance, widthLimt, heightLimt); Vector3 max = ExtraTool.GetScreenOffsetPosition(ExtraTool.Sphere_Diameter1_ScreenRightTopOffset, m_DifficultyData.targetDistance, widthLimt, heightLimt); return ExtraTool.RandomPosition(min, max); } #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 #region Train protected override void ResetTrain() { ResetTarget(); roundIndex = 0; m_TotalHitNum = 0; m_MissHitNum = 0; totalKillNums = 0; totalTargetNums = 0; } public override void StartTrain() { base.StartTrain(); GenerateShotTargets(); } public override void PauseTrain() { base.PauseTrain(); curTarget.IsRunning = false; } public override void ContinueTrain() { base.ContinueTrain(); curTarget.IsRunning = true; } public override void CalculateTrainResult() { SetResultMetricsDataValue(MetricsType.Kill_Sec, Math.Round(totalKillNums / TrainInfo.duration, 2)); SetResultMetricsDataValue(MetricsType.KillTotal, totalKillNums); SetResultMetricsDataValue(MetricsType.TimeToKill, Math.Round(TrainInfo.duration / totalKillNums, 2)); SetResultMetricsDataValue(MetricsType.Target, totalTargetNums); } #endregion #region ShotTarget private void OnClickTargetEvent(BaseShotTarget target) { if (target != null) { SphereShotTarget t = target as SphereShotTarget; if (t.CurHealth <= 0) { totalKillNums++; DestroyShootTarget(t); GenerateShotTargets(); } int baseS = 0; switch(roundIndex % 2) { case 0: baseS = m_ScoreData.staticBaseScore; break; case 1: baseS = m_ScoreData.motionBaseScore; break; } int comboS = Mathf.CeilToInt(baseS * comboNums * m_ScoreData.comboMul); int bestS = m_IsBestHit ? Mathf.CeilToInt(baseS * m_ScoreData.bestHitMul) : 0; IncreaseScore(baseS + comboS + bestS); TotalHitNum++; comboNums++; } else { MissHitNum++; comboNums = 0; int baseS = 0; switch (roundIndex % 2) { case 0: baseS = m_ScoreData.staticBaseScore; break; case 1: baseS = m_ScoreData.motionBaseScore; break; } int missPunitiveS = Mathf.CeilToInt(baseS * m_ScoreData.missPunitiveMul); IncreaseScore(missPunitiveS * -1); } } #endregion } }