| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- 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 HorizontalMotionShotTrainHandle : BaseTrainHandle
- {
- private SphereShotTarget curTarget;
- private HorizontalMotionShotTrainDifficultyData m_DifficultyData;
- private HorizontalMotionShotTrainScoreData m_ScoreData;
- private int baseS = 0;
- 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;
- public HorizontalMotionShotTrainHandle(BaseTrainCallBack callBack, BaseTrainInfo info, DifficultyType difficultyType) : base(callBack, info, difficultyType)
- {
- SetShotTargetInteractiveEvent(ShotTargetInteractiveType.OnClick, OnOnClickTargetEvent);
- m_DifficultyData = info.GetDifficultyData<HorizontalMotionShotTrainDifficultyData>(m_DifficultyType);
- m_ScoreData = info.GetScoreData<HorizontalMotionShotTrainScoreData>(m_DifficultyType);
- }
- private void GenerateShotTargets()
- {
- GameObject obj = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Prefabs/SphereTarget"));
- curTarget = obj.GetComponent<SphereShotTarget>();
- curTarget.IsRunning = true;
- List<Vector3> randomPos = new List<Vector3>();
- float randomY = Random.Range(ExtraTool.Sphere_Diameter1_ScreenOffsetY, 1 - ExtraTool.Sphere_Diameter1_ScreenOffsetY);
- for (int i = 0; i < 20; i++)
- {
- float randomX = Random.Range(ExtraTool.Sphere_Diameter1_ScreenOffsetX, 1 - ExtraTool.Sphere_Diameter1_ScreenOffsetX);
- Vector2 widthLimt = new Vector2(-8, 8);
- Vector2 heightLimt = new Vector2(-1.5f, 3.5f);
- randomPos.Add(ExtraTool.GetWorldPositionWithResolutionPercent(randomX, randomY, 10, widthLimt, heightLimt));
- }
- curTarget.onClickCanChangeColor = false;
- curTarget.onHoveringCanChangeColor = false;
- curTarget.defaultColor = ScreenEffectManager.GetInstance().GetTargetColor();
- curTarget.onHoveringColor = Color.green;
- curTarget.Init(3, ReduceHealthTriggerType.OnClick, true, ReduceHealthType.Per, MotionType.Foreach, randomPos[0], randomPos, m_DifficultyData.motionSpeed);
- totalTargetNum++;
- baseS = m_ScoreData.firstBaseScore;
- StartBestHitTimer();
- }
- private void DestroyShootTarget(SphereShotTarget target)
- {
- if (target != null)
- {
- target.IsRunning = false;
- GameObject.Destroy(target.gameObject);
- }
- }
- private void ResetTarget()
- {
- if (curTarget != null)
- {
- GameObject.Destroy(curTarget.gameObject);
- curTarget = null;
- }
- }
- #region Train
- protected override void ResetTrain()
- {
- ResetTarget();
- baseS = 0;
- m_TotalHitNum = 0;
- m_MissHitNum = 0;
- totalKillNum = 0;
- totalTargetNum = 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(totalKillNum / TrainInfo.duration, 2));
- SetResultMetricsDataValue(MetricsType.Target, totalTargetNum);
- SetResultMetricsDataValue(MetricsType.TimeToKill, Math.Round(TrainInfo.duration / totalKillNum, 2));
- SetResultMetricsDataValue(MetricsType.ShotsPerKill, Math.Round((TotalHitNum + MissHitNum) / totalKillNum, 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 ShotTarget
- private void OnOnClickTargetEvent(BaseShotTarget target)
- {
- if (target != null)
- {
- SphereShotTarget t = target as SphereShotTarget;
- switch (t.CurHealth)
- {
- case 0:
- baseS = m_ScoreData.thirdBaseScore;
- break;
- case 1:
- baseS = m_ScoreData.secondBaseScore;
- break;
- case 2:
- baseS = m_ScoreData.firstBaseScore;
- 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);
- comboNums++;
- if (t.CurHealth <= 0)
- {
- DestroyShootTarget(t);
- GenerateShotTargets();
- totalKillNum++;
- }
- TotalHitNum++;
- StartBestHitTimer();
- }
- else
- {
- MissHitNum++;
- comboNums = 0;
- int missPunitiveS = Mathf.CeilToInt(baseS * m_ScoreData.missPunitiveMul) + Random.Range(-2, 2);
- IncreaseScore(missPunitiveS * -1);
- }
- }
- #endregion
- }
- }
|