| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- using ShotSimulator.Target;
- using ShotSimulator.Train.Info;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Random = UnityEngine.Random;
- using ShotSimulator.Tool;
- using ShotSimulator.Screen;
- namespace ShotSimulator.Train
- {
- public class ReactionShotTrainHandle : BaseTrainHandle
- {
- private SphereShotTarget curTarget;
- private TimeTask m_ObserveTimer;
- private TimeTask m_IntervalTimer;
- private bool current_IsFar;
- private ReactionShotTrainDifficultyData m_DifficultyData;
- private ReactionShotTrainScoreData 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();
- }
- }
- protected float totalReactionTime;
- public ReactionShotTrainHandle(BaseTrainCallBack callBack, BaseTrainInfo info, DifficultyType difficultyType) : base(callBack, info, difficultyType)
- {
- SetShotTargetInteractiveEvent(ShotTargetInteractiveType.OnClick, OnShottedTargetEvent);
- m_DifficultyData = info.GetDifficultyData<ReactionShotTrainDifficultyData>(m_DifficultyType);
- m_ScoreData = info.GetScoreData<ReactionShotTrainScoreData>(m_DifficultyType);
- }
- #region Train
- protected override void ResetTrain()
- {
- ResetTarget();
- m_TotalHitNum = 0;
- m_MissHitNum = 0;
- totalReactionTime = 0;
- TimerSystem.GetInstance().RemoveTimeTask(m_ObserveTimer);
- m_ObserveTimer = null;
- TimerSystem.GetInstance().RemoveTimeTask(m_IntervalTimer);
- m_IntervalTimer = null;
- }
- public override void StartTrain()
- {
- base.StartTrain();
- GenerateShotTarget();
- }
- public override void PauseTrain()
- {
- base.PauseTrain();
- if (m_ObserveTimer != null)
- {
- m_ObserveTimer.pause = true;
- }
- if (m_IntervalTimer != null)
- {
- m_IntervalTimer.pause = true;
- }
- }
- public override void ContinueTrain()
- {
- base.ContinueTrain();
- if (m_ObserveTimer != null)
- {
- m_ObserveTimer.pause = false;
- }
- if (m_IntervalTimer != null)
- {
- m_IntervalTimer.pause = false;
- }
- }
- public override void CalculateTrainResult()
- {
- SetResultMetricsDataValue(MetricsType.ReactionTime, Math.Round(totalReactionTime / (TotalHitNum + MissHitNum), 2));
- SetResultMetricsDataValue(MetricsType.Kill_Sec, Math.Round(TotalHitNum / TrainInfo.duration, 2));
- SetResultMetricsDataValue(MetricsType.KillTotal, TotalHitNum);
- }
- #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)
- {
- TotalHitNum++;
- totalReactionTime += m_ObserveTimer.delay - m_ObserveTimer.remainingTime;
- TimerSystem.GetInstance().RemoveTimeTask(m_ObserveTimer);
- m_ObserveTimer = null;
- DestroyShootTarget(target as SphereShotTarget);
- int baseS = current_IsFar ? m_ScoreData.farBaseScore : m_ScoreData.nearBaseScore;
- 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++;
- }
- else
- {
- MissHitNum++;
- comboNums = 0;
- int baseS = current_IsFar ? m_ScoreData.farBaseScore : m_ScoreData.nearBaseScore;
- int missPunitiveS = Mathf.CeilToInt(baseS * m_ScoreData.missPunitiveMul);
- IncreaseScore(missPunitiveS * -1);
- }
- }
- #endregion
- private void GenerateShotTarget()
- {
- StartBestHitTimer();
- 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.OnClick, false, ReduceHealthType.Per, MotionType.None, RandomPosition());
- curTarget.IsRunning = true;
- m_ObserveTimer = TimerSystem.GetInstance().AddTimeTask(ObserveTimerTimeOut, 2.5f);
- }
- private void DestroyShootTarget(SphereShotTarget target)
- {
- if (target != null)
- {
- target.IsRunning = false;
- GameObject.Destroy(target.gameObject);
- }
- m_IntervalTimer = TimerSystem.GetInstance().AddTimeTask(IntervalTimerTimeOut, 2f);
- }
- private void IntervalTimerTimeOut()
- {
- GenerateShotTarget();
- }
- private void ObserveTimerTimeOut()
- {
- comboNums = 0;
- int baseS = current_IsFar ? m_ScoreData.farBaseScore : m_ScoreData.nearBaseScore;
- int missPunitiveS = Mathf.CeilToInt(baseS * m_ScoreData.missPunitiveMul);
- IncreaseScore(missPunitiveS * -1);
- m_ObserveTimer = null;
- totalReactionTime += 2.5f;
- DestroyShootTarget(curTarget as SphereShotTarget);
- }
- private Vector3 RandomPosition()
- {
- current_IsFar = ExtraTool.IsProbabolityInclusive(m_DifficultyData.farProbability);
- Vector2 widthLimt = Vector2.zero;
- Vector2 heightLimt = Vector2.zero;
- if (current_IsFar)
- {
- switch (m_DifficultyType)
- {
- case DifficultyType.Standard:
- widthLimt = new Vector2(-8, 8);
- heightLimt = new Vector2(-1.5f, 3.5f);
- break;
- case DifficultyType.Advance:
- widthLimt = new Vector2(-8, 8);
- heightLimt = new Vector2(-1.5f, 5f);
- break;
- case DifficultyType.Professional:
- widthLimt = new Vector2(-8, 8);
- heightLimt = new Vector2(-1.5f, 5f);
- break;
- }
- }
- else
- {
- widthLimt = new Vector2(-4, 4);
- heightLimt = new Vector2(-1.5f, 1.5f);
- }
- Vector3 min = ExtraTool.GetScreenOffsetPosition(ExtraTool.Sphere_Diameter1_ScreenLeftBottomOffset, current_IsFar ? m_DifficultyData.farDistance : m_DifficultyData.nearDistance, widthLimt, heightLimt);
- Vector3 max = ExtraTool.GetScreenOffsetPosition(ExtraTool.Sphere_Diameter1_ScreenRightTopOffset, current_IsFar ? m_DifficultyData.farDistance : m_DifficultyData.nearDistance, widthLimt, heightLimt);
- return ExtraTool.RandomPosition(min, max);
- }
- private void ResetTarget()
- {
- if (curTarget != null)
- {
- curTarget.IsRunning = false;
- GameObject.Destroy(curTarget.gameObject);
- curTarget = null;
- }
- }
- }
- }
|