| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- 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<DifficultyType, List<Vector2>> m_SpiderPosDictionary = new Dictionary<DifficultyType, List<Vector2>>()
- {
- {
- DifficultyType.Standard,new List<Vector2>()
- {
- 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<Vector2>()
- {
- 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<Vector2>()
- {
- 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<DifficultyType, List<Vector3>> m_SpiderObjTransform = new Dictionary<DifficultyType, List<Vector3>>()
- {
- { DifficultyType.Standard, new List<Vector3>(){ new Vector3(0,0.5f,6f), new Vector3(2,1,1) } },
- { DifficultyType.Advance, new List<Vector3>(){ new Vector3(0,1.75f,11f), new Vector3(3.5f,1.75f,1) } },
- { DifficultyType.Professional, new List<Vector3>(){ 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<SpiderShotTrainDifficultyData>(m_DifficultyType);
- m_ScoreData = info.GetScoreData<SpiderShotTrainScoreData>(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<GameObject>(Resources.Load<GameObject>("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<GameObject>(Resources.Load<GameObject>("Prefabs/SphereTarget"));
- curTarget = obj.GetComponent<SphereShotTarget>();
- 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;
- }
- }
- }
- }
|