| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- 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 ObserveShotTrainHandle : BaseTrainHandle
- {
- private SphereShotTarget curTarget;
- private TimeTask m_IntervalTimer;
- private TimeTask m_ObserveTimer;
- private bool isTargetAppears;
- private ObserveShotTrainDifficultyData m_DifficultyData;
- private ObserveShotTrainScoreData m_ScoreData;
- private float scoreFormulaK;
- private float scoreFormulaB;
- 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 float totaleObserveTime;
- private float gunSoundTime;
- public ObserveShotTrainHandle(BaseTrainCallBack callBack, BaseTrainInfo info, DifficultyType difficultyType) : base(callBack, info, difficultyType)
- {
- SetShotTargetInteractiveEvent(ShotTargetInteractiveType.OnClick, OnShottedTargetEvent);
- m_DifficultyData = info.GetDifficultyData<ObserveShotTrainDifficultyData>(m_DifficultyType);
- m_ScoreData = info.GetScoreData<ObserveShotTrainScoreData>(m_DifficultyType);
- scoreFormulaK = (m_ScoreData.bestBaseScore - m_ScoreData.commonBaseScore) / (0 - 1);
- scoreFormulaB = m_ScoreData.bestBaseScore;
- }
- #region Train
- protected override void ResetTrain()
- {
- ResetTarget();
- isTargetAppears = false;
- gunSoundTime = 0;
- m_TotalHitNum = 0;
- m_MissHitNum = 0;
- totaleObserveTime = 0;
- TimerSystem.GetInstance().RemoveTimeTask(m_IntervalTimer);
- m_IntervalTimer = null;
- TimerSystem.GetInstance().RemoveTimeTask(m_ObserveTimer);
- m_ObserveTimer = null;
- }
- public override void StartTrain()
- {
- base.StartTrain();
- StartNewRound();
- }
- public override void PauseTrain()
- {
- base.PauseTrain();
- if (m_IntervalTimer != null)
- {
- m_IntervalTimer.pause = true;
- }
- if (m_ObserveTimer != null)
- {
- m_ObserveTimer.pause = true;
- }
- }
- public override void ContinueTrain()
- {
- base.ContinueTrain();
- if (m_IntervalTimer != null)
- {
- m_IntervalTimer.pause = false;
- }
- if (m_ObserveTimer != null)
- {
- m_ObserveTimer.pause = false;
- }
- }
- public override void CalculateTrainResult()
- {
- SetResultMetricsDataValue(MetricsType.ReactionTime, Math.Round(totaleObserveTime / TotalHitNum, 2));
- SetResultMetricsDataValue(MetricsType.FalseAlarms, MissHitNum);
- }
- #endregion
- #region Target
- private void OnShottedTargetEvent(BaseShotTarget target)
- {
- if (isTargetAppears)
- {
- TotalHitNum++;
- float observeTime = (gunSoundTime - m_TaskTimer.remainingTime);
- totaleObserveTime += observeTime;
- if (observeTime <= 1)
- {
- int baseS = Mathf.CeilToInt(observeTime * scoreFormulaK + scoreFormulaB);
- int comboS = Mathf.CeilToInt(baseS * comboNums * m_ScoreData.comboMul);
- IncreaseScore(baseS + comboS);
- comboNums++;
- }
- else
- {
- comboNums = 0;
- IncreaseScore(m_ScoreData.commonBaseScore);
- }
- if (m_TrainTaskFinishType == TrainTaskFinishType.Number)
- {
- CurrentNumber--;
- if (CurrentNumber <= 0)
- {
- return;
- }
- }
- StartNewRound();
- }
- else
- {
- MissHitNum++;
- IncreaseScore(m_ScoreData.bestBaseScore * -1);
- }
- }
- #endregion
- private void UpdatePrecision()
- {
- double totalShot = TotalHitNum + MissHitNum;
- double precision = 0;
- if (totalShot != 0)
- {
- precision = Math.Round(TotalHitNum / totalShot, 2);
- }
- //SetResultMetricsDataValue(MetricsType.Precision, precision);
- }
- private void GenerateShotTarget()
- {
- GameObject obj = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Prefabs/SphereTarget"));
- curTarget = obj.GetComponent<SphereShotTarget>();
- curTarget.onClickCanChangeColor = false;
- curTarget.onHoveringCanChangeColor = false;
- curTarget.defaultColor = ScreenEffectManager.GetInstance().GetTargetColor();
- curTarget.Init(1, ReduceHealthTriggerType.None, false, ReduceHealthType.Per, MotionType.None, RandomPosition());
- curTarget.IsRunning = true;
- }
- 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.distance, widthLimt, heightLimt);
- Vector3 max = ExtraTool.GetScreenOffsetPosition(ExtraTool.Sphere_Diameter1_ScreenRightTopOffset, m_DifficultyData.distance, widthLimt, heightLimt);
- return ExtraTool.RandomPosition(min, max);
- }
- private void StartNewRound()
- {
- ResetTarget();
- isTargetAppears = false;
- TimerSystem.GetInstance().RemoveTimeTask(m_ObserveTimer);
- m_ObserveTimer = null;
- TimerSystem.GetInstance().RemoveTimeTask(m_IntervalTimer);
- m_IntervalTimer = TimerSystem.GetInstance().AddTimeTask(IntervalTimerTimeOut, Random.Range(1f, 5f));
- }
- private void IntervalTimerTimeOut()
- {
- m_IntervalTimer = null;
- GenerateShotTarget();
- gunSoundTime = m_TaskTimer.remainingTime;
- isTargetAppears = true;
- m_ObserveTimer = TimerSystem.GetInstance().AddTimeTask(ObserveTimerTimeOut, 3f);
- }
- private void ResetTarget()
- {
- if (curTarget != null)
- {
- curTarget.IsRunning = false;
- GameObject.Destroy(curTarget.gameObject);
- curTarget = null;
- }
- }
- private void ObserveTimerTimeOut()
- {
- comboNums = 0;
- totaleObserveTime += 3f;
- m_ObserveTimer = null;
- if (m_TrainTaskFinishType == TrainTaskFinishType.Number)
- {
- CurrentNumber--;
- if (CurrentNumber <= 0)
- {
- return;
- }
- }
- StartNewRound();
- }
- }
- }
|