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 SpiderShotTrainHandle : BaseTrainHandle { private SphereShotTarget curTarget; private TimeTask m_ObserveTimer; private SpiderShotTrainDifficultyData m_DifficultyData; private SpiderShotTrainScoreData m_ScoreData; private int roundIndex; private Dictionary> m_SpiderPosDictionary = new Dictionary>() { { DifficultyType.Standard,new List() { new Vector2(0, 0f), new Vector2(-1.75f, 1.25f), new Vector2(-2.5f, 0.5f), new Vector2(-2f, -0.5f),new Vector2(-1.25f, -1f), new Vector2(1.75f, 1.25f), new Vector2(2.5f, 0.5f), new Vector2(2f, -0.5f),new Vector2(1.25f, -1f) } }, { DifficultyType.Advance,new List() { new Vector2(0, 0f), new Vector2(-3.25f, 2f), new Vector2(-4.25f, 1f), new Vector2(-4f, -0.75f),new Vector2(-2.25f, -1.5f), new Vector2(3.25f, 2f), new Vector2(4.25f, 1f), new Vector2(4f, -0.75f),new Vector2(2.25f, -1.5f) } }, { DifficultyType.Professional,new List() { new Vector2(0, 0f), new Vector2(-5f, 3.25f), new Vector2(-6.5f, 1.5f), new Vector2(-6f, -1f),new Vector2(-3.25f, -1.5f), new Vector2(5f, 3.25f), new Vector2(6.5f, 1.5f), new Vector2(6f, -1f),new Vector2(3.25f, -1.5f) } }, }; private Dictionary> m_SpiderObjTransform = new Dictionary>() { { DifficultyType.Standard, new List(){ new Vector3(0,0.5f,6f), new Vector3(2,1,1) } }, { DifficultyType.Advance, new List(){ new Vector3(0,1.75f,11f), new Vector3(3.5f,1.75f,1) } }, { DifficultyType.Professional, new List(){ new Vector3(0,3,16.5f), new Vector3(7,2.25f,1) } } }; private GameObject spiderObj; 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; public SpiderShotTrainHandle(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(); roundIndex = -1; m_TotalHitNum = 0; m_MissHitNum = 0; totalTargetNum = 0; TimerSystem.GetInstance().RemoveTimeTask(m_ObserveTimer); m_ObserveTimer = null; GameObject.Destroy(spiderObj); } public override void PrepareTrain() { base.PrepareTrain(); spiderObj = GameObject.Instantiate(Resources.Load("Prefabs/SpiderObj")); spiderObj.transform.GetChild(0).transform.localPosition = m_SpiderObjTransform[DifficultyType.Standard][0]; spiderObj.transform.GetChild(0).transform.localScale = m_SpiderObjTransform[DifficultyType.Standard][1]; } public override void StartTrain() { base.StartTrain(); GenerateShotTarget(); } public override void PauseTrain() { base.PauseTrain(); if (m_ObserveTimer != null) { m_ObserveTimer.pause = true; } } public override void ContinueTrain() { base.ContinueTrain(); if (m_ObserveTimer != null) { m_ObserveTimer.pause = false; } } public override void CalculateTrainResult() { SetResultMetricsDataValue(MetricsType.Kill_Sec, Math.Round(TotalHitNum / TrainInfo.duration, 2)); SetResultMetricsDataValue(MetricsType.Target, totalTargetNum); SetResultMetricsDataValue(MetricsType.TimeToKill, Math.Round(TrainInfo.duration / TotalHitNum, 2)); SetResultMetricsDataValue(MetricsType.ShotsPerKill, Math.Round((TotalHitNum + MissHitNum) / TotalHitNum, 2)); } #endregion #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 Target private void OnShottedTargetEvent(BaseShotTarget target) { if (target != null) { int baseS = roundIndex % 3 == 1 ? m_ScoreData.firstBaseScore : m_ScoreData.secondBaseScore; int comboS = Mathf.CeilToInt(baseS * comboNums * m_ScoreData.comboMul); int bestS = m_IsBestHit ? Mathf.CeilToInt(baseS * m_ScoreData.bestHitMul) : 0; IncreaseScore(baseS + comboS + bestS); comboNums++; TotalHitNum++; TimerSystem.GetInstance().RemoveTimeTask(m_ObserveTimer); m_ObserveTimer = null; DestroyShootTarget(target as SphereShotTarget); GenerateShotTarget(); } else { MissHitNum++; comboNums = 0; int baseS = roundIndex % 3 == 1 ? m_ScoreData.firstBaseScore : m_ScoreData.secondBaseScore; int missPunitiveS = Mathf.CeilToInt(baseS * m_ScoreData.missPunitiveMul); IncreaseScore(missPunitiveS * -1); } } #endregion private void GenerateShotTarget() { roundIndex++; GameObject obj = GameObject.Instantiate(Resources.Load("Prefabs/SphereTarget")); curTarget = obj.GetComponent(); curTarget.onClickCanChangeColor = false; curTarget.onHoveringCanChangeColor = false; curTarget.defaultColor = ScreenEffectManager.GetInstance().GetTargetColor(); Vector3 pos = RandomPosition(); pos.z = m_DifficultyData.distance; curTarget.Init(1, ReduceHealthTriggerType.OnClick, false, ReduceHealthType.Per, MotionType.None, pos); curTarget.IsRunning = true; if(roundIndex % 3 != 1) { m_ObserveTimer = TimerSystem.GetInstance().AddTimeTask(ObserveTimerTimeOut, m_DifficultyData.duration); } totalTargetNum++; StartBestHitTimer(); } private void DestroyShootTarget(SphereShotTarget target) { if (target != null) { target.IsRunning = false; GameObject.Destroy(target.gameObject); } } private void ObserveTimerTimeOut() { comboNums = 0; int baseS = roundIndex % 3 == 1 ? m_ScoreData.firstBaseScore : m_ScoreData.secondBaseScore; int missPunitiveS = Mathf.CeilToInt(baseS * m_ScoreData.timeOutPunitiveMul) + Random.Range(-3, 3); IncreaseScore(missPunitiveS * -1); m_ObserveTimer = null; DestroyShootTarget(curTarget as SphereShotTarget); GenerateShotTarget(); } private Vector2 RandomPosition() { int round = roundIndex % 4; switch (round) { case 0: case 2: return m_SpiderPosDictionary[m_DifficultyType][0]; case 1: return m_SpiderPosDictionary[m_DifficultyType][Random.Range(1, 5)]; case 3: return m_SpiderPosDictionary[m_DifficultyType][Random.Range(5, 9)]; } return Vector3.zero; } private void ResetTarget() { if (curTarget != null) { curTarget.IsRunning = false; GameObject.Destroy(curTarget.gameObject); curTarget = null; } } } }