| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- 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 MotionTargetShotTrainHandle : BaseTrainHandle
- {
- private SphereShotTarget curTarget;
- private MotionTargetShotTrainDifficultyData m_DifficultyData;
- private MotionTargetShotTrainScoreData m_ScoreData;
- private List<Vector2> m_CurBrokenLineOffset;
- private List<Vector2> m_StandardBrokenLineOffset = new List<Vector2>()
- {
- new Vector2(0.35f,0.25f),
- new Vector2(0.4f,0.75f),
- new Vector2(0.45f,0.25f),
- new Vector2(0.5f,0.75f),
- new Vector2(0.55f,0.25f),
- new Vector2(0.6f,0.75f),
- new Vector2(0.65f,0.25f)
- };
- private List<Vector2> m_AdvanceBrokenLineOffset = new List<Vector2>()
- {
- new Vector2(0.25f,0.25f),
- new Vector2(0.3f,0.75f),
- new Vector2(0.35f,0.25f),
- new Vector2(0.4f,0.75f),
- new Vector2(0.45f,0.25f),
- new Vector2(0.5f,0.75f),
- new Vector2(0.55f,0.25f),
- new Vector2(0.6f,0.75f),
- new Vector2(0.65f,0.25f),
- new Vector2(0.7f,0.75f),
- new Vector2(0.75f,0.25f)
- };
- private List<Vector2> m_ProfessionalBrokenLineOffset = new List<Vector2>()
- {
- new Vector2(0.3f,0.75f),
- new Vector2(0.35f,0.25f),
- new Vector2(0.4f,0.75f),
- new Vector2(0.45f,0.25f),
- new Vector2(0.5f,0.75f),
- new Vector2(0.55f,0.25f),
- new Vector2(0.6f,0.75f),
- new Vector2(0.65f,0.25f),
- new Vector2(0.7f,0.75f)
- };
- private int roundIndex;
- 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 totalKillNums;
- private double totalTargetNums;
- public MotionTargetShotTrainHandle(BaseTrainCallBack callBack, BaseTrainInfo info, DifficultyType difficultyType) : base(callBack, info, difficultyType)
- {
- SetShotTargetInteractiveEvent(ShotTargetInteractiveType.OnClick, OnClickTargetEvent);
- m_DifficultyData = info.GetDifficultyData<MotionTargetShotTrainDifficultyData>(m_DifficultyType);
- m_ScoreData = info.GetScoreData<MotionTargetShotTrainScoreData>(m_DifficultyType);
- }
- private void GenerateShotTargets()
- {
- roundIndex++;
- int round = roundIndex % 2;
- 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.onHoveringColor = Color.red;
- MotionType motionType = MotionType.None;
- List<Vector3> motionPos = new List<Vector3>();
- Vector3 origin = new Vector3();
- if (round == 1)
- {
- motionType = MotionType.None;
- origin = new Vector3(0, 0, m_DifficultyData.targetDistance);
- }
- else
- {
- motionType = MotionType.PingPong;
- //switch (m_DifficultyType)
- //{
- // case DifficultyType.Standard:
- // m_CurBrokenLineOffset = m_StandardBrokenLineOffset;
- // break;
- // case DifficultyType.Advance:
- // m_CurBrokenLineOffset = m_AdvanceBrokenLineOffset;
- // break;
- // case DifficultyType.Professional:
- // m_CurBrokenLineOffset = m_ProfessionalBrokenLineOffset;
- // break;
- //}
- //for (int i = 0; i < m_CurBrokenLineOffset.Count; i++)
- //{
- // motionPos.Add(RandomPosition(i));
- //}
- for (int i = 0; i < 20; i++)
- {
- motionPos.Add(RandomPosition());
- }
- curTarget.curTargetPosIndex = Random.Range(0, motionPos.Count);
- origin = motionPos[curTarget.curTargetPosIndex];
- }
- curTarget.Init(1, ReduceHealthTriggerType.OnClick, false, ReduceHealthType.Per, motionType, origin, motionPos, m_DifficultyData.speed);
- curTarget.IsRunning = true;
- totalTargetNums++;
- StartBestHitTimer();
- }
- private Vector3 RandomPosition(int index)
- {
- 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;
- }
- return ExtraTool.GetScreenOffsetPosition(m_CurBrokenLineOffset[index], m_DifficultyData.targetDistance, widthLimt, heightLimt);
- }
- private void ResetTarget()
- {
- if (curTarget != null)
- {
- curTarget.IsRunning = false;
- GameObject.Destroy(curTarget.gameObject);
- curTarget = null;
- }
- }
- private void DestroyShootTarget(SphereShotTarget target)
- {
- if (target != null)
- {
- target.IsRunning = false;
- GameObject.Destroy(target.gameObject);
- }
- }
- 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.targetDistance, widthLimt, heightLimt);
- Vector3 max = ExtraTool.GetScreenOffsetPosition(ExtraTool.Sphere_Diameter1_ScreenRightTopOffset, m_DifficultyData.targetDistance, widthLimt, heightLimt);
- return ExtraTool.RandomPosition(min, max);
- }
- #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 Train
- protected override void ResetTrain()
- {
- ResetTarget();
- roundIndex = 0;
- m_TotalHitNum = 0;
- m_MissHitNum = 0;
- totalKillNums = 0;
- totalTargetNums = 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(totalKillNums / TrainInfo.duration, 2));
- SetResultMetricsDataValue(MetricsType.KillTotal, totalKillNums);
- SetResultMetricsDataValue(MetricsType.TimeToKill, Math.Round(TrainInfo.duration / totalKillNums, 2));
- SetResultMetricsDataValue(MetricsType.Target, totalTargetNums);
- }
- #endregion
- #region ShotTarget
- private void OnClickTargetEvent(BaseShotTarget target)
- {
- if (target != null)
- {
- SphereShotTarget t = target as SphereShotTarget;
- if (t.CurHealth <= 0)
- {
- totalKillNums++;
- DestroyShootTarget(t);
- GenerateShotTargets();
- }
- int baseS = 0;
- switch(roundIndex % 2)
- {
- case 0:
- baseS = m_ScoreData.staticBaseScore;
- break;
- case 1:
- baseS = m_ScoreData.motionBaseScore;
- 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);
- TotalHitNum++;
- comboNums++;
- }
- else
- {
- MissHitNum++;
- comboNums = 0;
- int baseS = 0;
- switch (roundIndex % 2)
- {
- case 0:
- baseS = m_ScoreData.staticBaseScore;
- break;
- case 1:
- baseS = m_ScoreData.motionBaseScore;
- break;
- }
- int missPunitiveS = Mathf.CeilToInt(baseS * m_ScoreData.missPunitiveMul);
- IncreaseScore(missPunitiveS * -1);
- }
- }
- #endregion
- }
- }
|