| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- using ShotSimulator.Target;
- using ShotSimulator.Train.Info;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Random = UnityEngine.Random;
- namespace ShotSimulator.Train
- {
- public class EnemyTideShotTrainHandle : BaseTrainHandle
- {
- private List<Vector3> originPos = new List<Vector3>()
- {
- new Vector3(-4,-2f,15),new Vector3(4,-2f,16),
- new Vector3(-4,-2f,11f),new Vector3(4,-2f,11f),
- new Vector3(-4,-2f,6f),new Vector3(4,-2f,6f),
- };
- private EnemyTideShotTrainDifficultyData m_DifficultyData;
- private EnemyTideShotTrainScoreData m_ScoreData;
- private List<AIHumanoidShotTarget> curTargets = new List<AIHumanoidShotTarget>();
- 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 Headshots;
- public EnemyTideShotTrainHandle(BaseTrainCallBack callBack, BaseTrainInfo info, DifficultyType difficultyType) : base(callBack, info, difficultyType)
- {
- SetShotTargetInteractiveEvent(ShotTargetInteractiveType.OnClick, OnShottedTargetEvent);
- m_DifficultyData = info.GetDifficultyData<EnemyTideShotTrainDifficultyData>(m_DifficultyType);
- m_ScoreData = info.GetScoreData<EnemyTideShotTrainScoreData>(m_DifficultyType);
- }
- #region Train
- protected override void ResetTrain()
- {
- ResetTarget();
- m_TotalHitNum = 0;
- m_MissHitNum = 0;
- totalKillNum = 0;
- Headshots = 0;
- }
- public override void StartTrain()
- {
- base.StartTrain();
- GenerateShotTarget();
- StartBestHitTimer();
- }
- public override void PauseTrain()
- {
- base.PauseTrain();
- for(int i = 0; i< curTargets.Count; i++)
- {
- curTargets[i].SetPause(true);
- }
- }
- public override void ContinueTrain()
- {
- base.ContinueTrain();
- for (int i = 0; i < curTargets.Count; i++)
- {
- curTargets[i].SetPause(false);
- }
- }
- public override void CalculateTrainResult()
- {
- SetResultMetricsDataValue(MetricsType.Headshots, Headshots);
- SetResultMetricsDataValue(MetricsType.TimeToKill, Math.Round(TrainInfo.duration / totalKillNum, 2));
- SetResultMetricsDataValue(MetricsType.KillTotal, totalKillNum);
- }
- #endregion
- #region Target
- private void OnShottedTargetEvent(BaseShotTarget target)
- {
- if (target != null)
- {
- HumanoidPartShotTarget part = target as HumanoidPartShotTarget;
- AIHumanoidShotTarget dependTarget = part.DependTarget as AIHumanoidShotTarget;
- int baseS = 0;
- switch (part.PartType)
- {
- case HumanoidPartType.Head:
- baseS = m_ScoreData.headHitBaseScore;
- break;
- case HumanoidPartType.Body:
- baseS = m_ScoreData.bodyHitBaseScore;
- 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);
- if (dependTarget.Health <= 0)
- {
- if (part.PartType == HumanoidPartType.Head)
- {
- Headshots++;
- }
- totalKillNum++;
- DestroyShootingTarget(dependTarget);
- if (curTargets.Count == 0)
- {
- GenerateShotTarget();
- }
- comboNums++;
- }
- TotalHitNum++;
- StartBestHitTimer();
- }
- else
- {
- MissHitNum++;
- comboNums = 0;
- int missPunitiveS = Mathf.CeilToInt(m_ScoreData.bodyHitBaseScore * m_ScoreData.missPunitiveMul);
- IncreaseScore(missPunitiveS * -1);
- }
- }
- #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
- private void GenerateShotTarget()
- {
- for (int i = 0; i < m_DifficultyData.targetNums; i++)
- {
- GameObject obj = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Prefabs/AIHumanoidShotTarget"));
- AIHumanoidShotTarget target = obj.GetComponent<AIHumanoidShotTarget>();
- target.InitHumanoidShotTarget(3, RandomPosition());
- Vector3 minBoundaryPos = new Vector3(-2f, -2f, 4.5f);
- Vector3 maxBoundaryPos = new Vector3(2f, -2f, 4.5f + m_DifficultyData.boundaryDistance);
- target.InitBoundaryPosition(minBoundaryPos, maxBoundaryPos);
- target.InitHide(originPos, m_DifficultyData.hideProbability);
- target.SetCrouchTimeProportion(m_DifficultyData.crouchTimeProportion);
- target.SetSpeed(m_DifficultyData.speed);
- curTargets.Add(target);
- }
- }
- private void DestroyShootingTarget(AIHumanoidShotTarget target)
- {
- if (target != null)
- {
- curTargets.Remove(target);
- GameObject.Destroy(target.gameObject);
- }
- }
- private Vector3 RandomPosition()
- {
- return originPos[Random.Range(0, originPos.Count)];
- }
- private void ResetTarget()
- {
- for (int i = 0; i < curTargets.Count; i++)
- {
- GameObject.Destroy(curTargets[i].gameObject);
- }
- curTargets.Clear();
- }
- }
- }
|