public Vector3 SimulateDefense(Vector3 _position, bool _influenceBall = true) { m_ballPoint = _position; GoalCamera.instance.m_shotEndPoint = m_ballPoint; m_grabTime = 0f; string sufix = MakeAnimSufix(_position); m_ballCasilla = sufix; if (sufix == "") { return(_position); } sufix += "_01"; string animName = "P_Par" + sufix; AnimationDescriptorsResource.AnimationDescriptorResource descriptor = m_animationDescriptorsResource.GetByName(animName); if (descriptor == null) { animName = "P_Dpj" + sufix; descriptor = m_animationDescriptorsResource.GetByName(animName); } m_ballReady = true; if (m_gestureReady) { GetGrab(m_defensePoint); } Vector3 preResult = transform.position + descriptor.m_grabDiff; preResult.z = -1 * InputManager.planeGoalClose.distance; simAnimTime = descriptor.m_grabTime; if (_influenceBall) { m_ballPoint = preResult; GoalCamera.instance.m_shotEndPoint = m_ballPoint; } else { m_ballPoint = _position; return(_position); } return(preResult); }
public Vector3 GetGrab(DefenseInfo _info) { bool playingGoalkeeper = ServiceLocator.Request <IGameplayService>().GetGameMode() == GameMode.GoalKeeper; m_ready = false; ClearBall = false; GrabBall = false; if (_info.Result == GKResult.Idle) { return(_info.Target); } transform.position = new Vector3(0, 0, -49.5f); bool success = true; string sufix = MakeAnimSufix(_info.Target); if (sufix == "") { m_animName = ""; m_animIdle = ""; return(_info.Target); } if (!GameplayService.IsGoalkeeper()) { lastResult = GKResult.IAFail; } float precision = Mathf.Clamp01(Vector3.Distance(_info.Target, m_ballPoint) / ServiceLocator.Request <IDifficultyService>().GetSuccessRadius(_info.Target)); if (m_debugTrace) { Debug.Log("PRECISION: " + precision); kickEffects.instance.DebugCircle(_info.Target, ServiceLocator.Request <IDifficultyService>().GetPerfectRadius() * 2f, new Color(1, 0.5f, 0)); kickEffects.instance.DebugCircle(_info.Target, ServiceLocator.Request <IDifficultyService>().GetSuccessRadius(_info.Target) * 2f, Color.cyan); kickEffects.instance.DebugTarget(m_ballPoint); } if (!GameplayService.networked && !playingGoalkeeper) { precision = Random.Range(0f, 1f); } #region powerup reflejo if (PowerupService.instance.IsPowerActive(Powerup.Reflejo)) { int casillaX = (int)GetCasilla(_info.Target).x; if (casillaX == 7) { casillaX = 6; } else if (casillaX == 0) { casillaX = 1; } Vector3[] targets = { GetCasillaPosition(casillaX + 1, 0), GetCasillaPosition(casillaX, 0), GetCasillaPosition(casillaX - 1, 0), GetCasillaPosition(casillaX + 1, 1), GetCasillaPosition(casillaX, 1), GetCasillaPosition(casillaX - 1, 1), GetCasillaPosition(casillaX + 1, 2), GetCasillaPosition(casillaX, 2), GetCasillaPosition(casillaX - 1, 2) }; /*Vector3[] targets = {GetCasillaPosition(0,0), GetCasillaPosition(1,0), GetCasillaPosition(2,0), GetCasillaPosition(3,0), GetCasillaPosition(4,0), GetCasillaPosition(5,0), GetCasillaPosition(6,0), GetCasillaPosition(7,0), * GetCasillaPosition(0,1), GetCasillaPosition(1,1), GetCasillaPosition(2,1), GetCasillaPosition(3,1), GetCasillaPosition(4,1), GetCasillaPosition(5,1), GetCasillaPosition(6,1), GetCasillaPosition(7,1), * GetCasillaPosition(0,2), GetCasillaPosition(1,2), GetCasillaPosition(2,2), GetCasillaPosition(3,2), GetCasillaPosition(4,2), GetCasillaPosition(5,2), GetCasillaPosition(6,2), GetCasillaPosition(7,2) * };*/ /*Vector3[] targets = {GetCasillaPosition(0,0), GetCasillaPosition(1,0), GetCasillaPosition(2,0), * GetCasillaPosition(0,1), GetCasillaPosition(1,1), GetCasillaPosition(2,1), * GetCasillaPosition(0,2), GetCasillaPosition(1,2), GetCasillaPosition(2,2) * };*/ Time.timeScale = 0.5f; for (int i = 0; i < targets.Length; i++) { Vector3 mirrorTarget = targets[i];//new Vector3(_info.Target.x * -1f , _info.Target.y, _info.Target.z); float precision2 = Mathf.Clamp01(Vector3.Distance(mirrorTarget, m_ballPoint) / ServiceLocator.Request <IDifficultyService>().GetSuccessRadius(mirrorTarget)); Vector3 mirrorPos = _info.Target; if (precision2 < precision) { mirrorPos = _info.Target; precision = precision2; sufix = MakeAnimSufix(mirrorTarget); _info.Target = mirrorTarget; } else { mirrorPos = mirrorTarget; } GameObject doppelganger = Instantiate(FieldControl.instance.goalKeeperPrefab[FieldControl.instance.doppelgangerindex], Goalkeeper.instance.transform.position, Goalkeeper.instance.transform.rotation) as GameObject; Destroy(doppelganger.GetComponent <Goalkeeper>());//.enabled = false; string mirrorAnimName = MakeAnimSufix(mirrorPos); mirrorAnimName += "_01"; mirrorAnimName = "P_Dpj" + mirrorAnimName; doppelganger.GetComponent <Animation>()[mirrorAnimName].speed = m_animationDescriptorsResource.GetByName(mirrorAnimName).m_grabTime / m_ballTime; Doppelganger comp = doppelganger.AddComponent <Doppelganger>(); comp.m_balltime = m_ballTime; comp.m_animName = mirrorAnimName; doppelganger.GetComponent <Animation>().Play(mirrorAnimName); kickEffects.instance.DoDoppelganger(doppelganger); } } #endregion if (playingGoalkeeper) { //if(m_ballCasilla == sufix) success = true; if (precision < successPrecision) { success = true; } else { success = false; } } else { success = _info.Result == GKResult.Good || _info.Result == GKResult.Perfect; } if (success) { sufix = m_ballCasilla; } sufix += "_01"; m_animName = "P_Dpj" + sufix; m_descriptor = m_animationDescriptorsResource.GetByName(m_animName); bool possiblePerfect = false; lastPerfect = false; if (playingGoalkeeper) { SetGrabTime(m_descriptor.m_grabTime); if (m_animTime <= 0f && !(lastResult == GKResult.Early)) //para comprobar que no se haya hecho la defensa antes incluso de chutar, da 0 en ese caso { lastResult = GKResult.Late; success = false; } else if (m_animTime >= 1f) { lastResult = GKResult.Early; success = false; m_animTime = 0.1f; } else if (m_animTime <= 0.2f && success) { possiblePerfect = true; success = true; } else if (m_animTime <= 0.4f && success) { success = true; } else if (!success) { lastResult = GKResult.Fail; m_animTime = 0f; } } m_animIdle = "P_Idle01"; ClearBall = success; //preparar el perfect float precisionDist = ServiceLocator.Request <IDifficultyService>().GetPerfectRadius(); bool perfectRadius = Vector3.Distance(_info.Target, m_ballPoint) <= precisionDist; float precisionRatio = precisionDist / ServiceLocator.Request <IDifficultyService>().GetSuccessRadius(_info.Target); if (PowerupService.instance.IsPowerActive(Powerup.Resbaladiza) && success) { float max = successPrecision - precisionRatio; float transfProb = (precision - precisionRatio); float finalProb = 0f; if (transfProb < 0f) { finalProb = 0.25f; } else if (transfProb > max) { finalProb = 0.55f; } else { finalProb = 0.4f * (transfProb / max) + 0.1f; } bool forcedFail = finalProb > Random.Range(0f, 1f); BallPhysics.instance.noCatch = forcedFail; Debug.Log("GreasyBall prob = " + finalProb); } if (BallPhysics.instance.state != BallPhysics.BallState.Idle) { if ((playingGoalkeeper && success && perfectRadius) || (!playingGoalkeeper && _info.Result == GKResult.Perfect)) { if (possiblePerfect || !playingGoalkeeper) { AnimationDescriptorsResource.AnimationDescriptorResource tempDescriptor = m_animationDescriptorsResource.GetByName("P_Par" + sufix); if (tempDescriptor != null) { m_animName = "P_Par" + sufix; m_animIdle = "P_IdleCB01"; m_descriptor = tempDescriptor; GrabBall = true; } } } else { possiblePerfect = false; } } if (playingGoalkeeper && possiblePerfect) { lastResult = GKResult.Perfect; lastPrecision = 0; GeneralSounds.instance.perfect(); possiblePerfect = true; } else if (playingGoalkeeper && success) { if (precision < 0.2) { lastPrecision = 1; } else if (precision < 0.45) { lastPrecision = 2; } else { lastPrecision = 3; } lastResult = GKResult.Good; possiblePerfect = false; } lastPerfect = possiblePerfect; forceWin = success; if (playingGoalkeeper && success) { AdjustAnimation(); } Vector3 preResult = transform.position + m_descriptor.m_grabDiff; //preResult.z = InputManager.planeGoalClose.distance; return(preResult); }