| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- 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 ReloadShotTrainHandle : BaseTrainHandle
- {
- private SphereShotTarget curTarget;
- private ReloadShotTrainInfoDifficultyData m_DifficultyData;
- private ReloadShotTrainScoreData m_ScoreData;
- private TimeTask m_ObserveTimer;
- 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 totalKillNum;
- private double totalTargetNum;
- private double totalReloadTime;
- private double reloadNums;
- public ReloadShotTrainHandle(BaseTrainCallBack callBack, BaseTrainInfo info, DifficultyType difficultyType) : base(callBack, info, difficultyType)
- {
- SetShotTargetInteractiveEvent(ShotTargetInteractiveType.OnClick, OnShottedTargetEvent);
- m_DifficultyData = info.GetDifficultyData<ReloadShotTrainInfoDifficultyData>(m_DifficultyType);
- m_ScoreData = info.GetScoreData<ReloadShotTrainScoreData>(m_DifficultyType);
- }
- #region Train
- protected override void ResetTrain()
- {
- ResetTarget();
- m_TotalHitNum = 0;
- m_MissHitNum = 0;
- totalKillNum = 0;
- totalTargetNum = 0;
- totalReloadTime = 0;
- reloadNums = 0;
- separationMagazineTime = 0;
- TimerSystem.GetInstance().RemoveTimeTask(m_ObserveTimer);
- m_ObserveTimer = null;
- }
- 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.Target, totalTargetNum);
- SetResultMetricsDataValue(MetricsType.TimeToKill, Math.Round((m_TaskTimer.delay - m_TaskTimer.remainingTime) / totalKillNum, 2));
- SetResultMetricsDataValue(MetricsType.ReloadTime, Math.Round(totalReloadTime / reloadNums, 2));
- SetResultMetricsDataValue(MetricsType.KillTotal, totalKillNum);
- }
- #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
- public override void SeparationMagazine()
- {
- base.SeparationMagazine();
- separationMagazineTime = m_TaskTimer.remainingTime;
- }
- public override void ReloadMagazine()
- {
- base.ReloadMagazine();
-
- totalReloadTime += (separationMagazineTime - m_TaskTimer.remainingTime);
- reloadNums++;
- }
- private void OnShottedTargetEvent(BaseShotTarget target)
- {
- if (target != null)
- {
- int baseS = m_ScoreData.baseScore;
- int comboS = Mathf.CeilToInt(baseS * comboNums * m_ScoreData.comboMul);
- IncreaseScore(baseS + comboS);
- comboNums++;
- totalKillNum++;
- TotalHitNum++;
- TimerSystem.GetInstance().RemoveTimeTask(m_ObserveTimer);
- m_ObserveTimer = null;
- SphereShotTarget t = target as SphereShotTarget;
- if (t.CurHealth <= 0)
- {
- DestroyShootTarget(t);
- if (m_TrainTaskFinishType == TrainTaskFinishType.Number)
- {
- CurrentNumber--;
- if (CurrentNumber <= 0)
- {
- return;
- }
- }
-
- GenerateShotTarget();
- }
- }
- else
- {
- MissHitNum++;
- comboNums = 0;
- int baseS = m_ScoreData.baseScore;
- int missPunitiveS = Mathf.CeilToInt(baseS * m_ScoreData.missPunitiveMul) + Random.Range(-3, 3);
- IncreaseScore(missPunitiveS * -1);
- }
- }
- #endregion
- private void GenerateShotTarget()
- {
- if (!IsRunning) return;
- 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, m_DifficultyData.duration);
- totalTargetNum++;
- StartBestHitTimer();
- }
- private void ObserveTimerTimeOut()
- {
- comboNums = 0;
- int baseS = m_ScoreData.baseScore;
- int missPunitiveS = Mathf.CeilToInt(baseS * m_ScoreData.timeOutPunitiveMul) + Random.Range(-3, 3);
- IncreaseScore(missPunitiveS * -1);
- m_ObserveTimer = null;
- ResetTarget();
- if (m_TrainTaskFinishType == TrainTaskFinishType.Number)
- {
- CurrentNumber--;
- if (CurrentNumber <= 0)
- {
- return;
- }
- }
- GenerateShotTarget();
- }
- 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 DestroyShootTarget(SphereShotTarget target)
- {
- if (target != null)
- {
- GameObject.Destroy(target.gameObject);
- }
- }
- private void ResetTarget()
- {
- if (curTarget != null)
- {
- GameObject.Destroy(curTarget.gameObject);
- curTarget = null;
- }
- }
- }
- }
|