Пример #1
0
    public void StartTrajectory(DiscTrajectoryParameters newTrajectory, GameObject _launcher)
    {
        objLaunch                   = _launcher;
        myRigidBody.velocity        = Vector3.zero;
        myRigidBody.angularVelocity = Vector3.zero;
        myRigidBody.isKinematic     = false;

        lastObjTouch = null;

        isAttacking = true;

        currentTrajectory = newTrajectory.trajectoryPositions;
        currentSpeed      = 0;

        transform.position = currentTrajectory[0];
        currentTrajectory.RemoveAt(0);

        accelerationDurationSystem.ChangeTimerValue(accelerationDuration);
        accelerationDurationSystem.StartTimer();

        if (!isBeingRecalled)
        {
            ShakeScriptableObjectManager.instance.LoadShake("ShakeSetting_Throw");
        }
    }
Пример #2
0
    public void UpdateThrowPreparation()
    {
        Vector3 trueTargetPosition = GetInRangeThrowTargetPosition(currentWorldMouseResult.mouseWorldPosition);
        //Vector3 trueTargetPosition = GetInRangeThrowTargetPosition(GameManager.Instance.GetDebugPos);
        DiscTrajectoryParameters trajectoryParameters =
            DiscTrajectoryFactory.GetTrajectory(throwCompetence, _player.transform.position, trueTargetPosition,
                                                DiscManager.Instance.GetAllThrowedDiscs, DiscManager.Instance.GetInRangeDiscs, aboutToThrowDisc);

        Dictionary <DiscScript, DiscTrajectoryParameters> trajectories = new Dictionary <DiscScript, DiscTrajectoryParameters>();

        trajectories.Add(aboutToThrowDisc, trajectoryParameters);
        PreviewCompetencesManager.Instance.UpdateThrowPreview(trajectories);
    }
Пример #3
0
    public void StartRecallDisc(DiscScript disc)
    {
        DiscTrajectoryParameters trajectoryParameters =
            DiscTrajectoryFactory.GetTrajectory(recallCompetence,
                                                disc.transform.position, _player.transform.position,
                                                DiscManager.Instance.GetAllThrowedDiscs, DiscManager.Instance.GetInRangeDiscs, disc);

        disc.SetIsBeingRecalled(true);
        disc.StartTrajectory(trajectoryParameters, null);
        currentlyInUseDiscs.Add(disc);
        disc.OnTrajectoryStopped += RemoveDiscFromInUse;

        OnSpecialLaunch?.Invoke();
    }
Пример #4
0
    public void UpdateRecallPreparation()
    {
        Vector3 playerPos = _player.transform.position;
        Dictionary <DiscScript, DiscTrajectoryParameters> recallTrajectoryParameters = new Dictionary <DiscScript, DiscTrajectoryParameters>();

        List <DiscScript> recallableDiscs = DiscListingFactory.GetSortedRecallableDiscs(recallCompetence, DiscManager.Instance.GetAllThrowedDiscs, DiscManager.Instance.GetInRangeDiscs);

        foreach (DiscScript discInRange in recallableDiscs)
        {
            DiscTrajectoryParameters newParams =
                DiscTrajectoryFactory.GetTrajectory(recallCompetence, discInRange.transform.position, playerPos,
                                                    DiscManager.Instance.GetAllThrowedDiscs, DiscManager.Instance.GetInRangeDiscs, discInRange);
            recallTrajectoryParameters.Add(discInRange, newParams);
        }

        PreviewCompetencesManager.Instance.UpdateRecallPreview(recallTrajectoryParameters, playerPos);
    }
Пример #5
0
    public static Dictionary <DiscScript, DiscTrajectoryParameters> GetDiscInRangeTrajectory(Vector3 targetPosition, CompetenceRecall recallCompetence)
    {
        List <DiscScript> recallableFromPosition =
            DiscListingFactory.GetSortedRecallableDiscs(recallCompetence,
                                                        DiscManager.Instance.GetAllThrowedDiscs, DiscManager.Instance.GetAllInRangeDiscsFromPosition(targetPosition));

        Dictionary <DiscScript, DiscTrajectoryParameters> allTrajParams = new Dictionary <DiscScript, DiscTrajectoryParameters>();

        foreach (DiscScript disc in recallableFromPosition)
        {
            DiscTrajectoryParameters newTrajParams =
                DiscTrajectoryFactory.GetTrajectory(recallCompetence, disc.transform.position, targetPosition,
                                                    DiscManager.Instance.GetAllThrowedDiscs, DiscManager.Instance.GetInRangeDiscs, disc);

            allTrajParams.Add(disc, newTrajParams);
        }
        return(allTrajParams);
    }
Пример #6
0
    public void LaunchThrowCompetenceForReal()
    {
        currentlyInUseDiscs = new List <DiscScript>();

        DiscScript newDisc = DiscManager.Instance.TakeFirstDiscFromPossessedDiscs();

        if (newDisc == null)
        {
            //Debug.LogWarning("NO DISK TO THROW");
            return;
        }

        DiscTrajectoryParameters trajectoryParameters =
            DiscTrajectoryFactory.GetTrajectory(throwCompetence,
                                                _player.transform.position, GetInRangeThrowTargetPosition(currentThrowPosition),
                                                DiscManager.Instance.GetAllThrowedDiscs, DiscManager.Instance.GetInRangeDiscs, newDisc);

        newDisc.SetIsBeingRecalled(false);
        newDisc.SetRetreivableByPlayer(false);
        newDisc.StartTrajectory(trajectoryParameters, currentObjLauncher);
        currentlyInUseDiscs.Add(newDisc);
        newDisc.OnTrajectoryStopped    += RemoveDiscFromInUse;
        newDisc.OnReachedTrajectoryEnd += RemoveDiscFromInUse;
    }
Пример #7
0
    public static DiscTrajectoryParameters GetTrajectory(CompetenceDisc competence, Vector3 startPosition, Vector3 targetPosition, List <DiscScript> throwedDiscs, List <DiscScript> inRangeDiscs, DiscScript currentDisc)
    {
        DiscTrajectoryParameters discTrajectoryParameters = new DiscTrajectoryParameters();

        discTrajectoryParameters.disc = currentDisc;
        List <Vector3> trajectoryPositions = new List <Vector3>();
        Vector3        totalDirection      = (targetPosition - startPosition).normalized;

        List <TrajectoryModifier> trajectoryModifiers = competence.GetTrajectoryModifiers;
        DiscsOrder linkedDiscsTrajectory        = DiscsOrder.None;
        TrajectoryModifierCurved curvedModifier = null;

        foreach (TrajectoryModifier modifier in trajectoryModifiers)
        {
            if (linkedDiscsTrajectory == DiscsOrder.None)
            {
                TrajectoryModifierLinkedDiscs linkedDiscModifier = modifier as TrajectoryModifierLinkedDiscs;
                if (linkedDiscModifier != null)
                {
                    linkedDiscsTrajectory = linkedDiscModifier.GetLinkedDiscTrajectoryType;
                }
            }

            if (curvedModifier == null)
            {
                TrajectoryModifierCurved foundCurvedModifier = modifier as TrajectoryModifierCurved;
                if (foundCurvedModifier != null)
                {
                    curvedModifier = foundCurvedModifier;
                }
            }
        }

        trajectoryPositions.Add(startPosition);

        #region Discs Link
        switch (linkedDiscsTrajectory)
        {
        case DiscsOrder.FromOldestToNewest:
            for (int i = 0; i < throwedDiscs.Count; i++)
            {
                DiscScript linkDisc = throwedDiscs[i];
                if (linkDisc != currentDisc)
                {
                    if (inRangeDiscs.Contains(linkDisc))
                    {
                        trajectoryPositions.Add(linkDisc.transform.position);
                    }
                }
            }
            break;

        case DiscsOrder.FromNewestToOldest:

            for (int i = throwedDiscs.Count - 1; i >= 0; i--)
            {
                DiscScript linkDisc = throwedDiscs[i];
                if (linkDisc != currentDisc)
                {
                    if (inRangeDiscs.Contains(linkDisc))
                    {
                        trajectoryPositions.Add(linkDisc.transform.position);
                    }
                }
            }
            break;
        }
        #endregion

        #region
        if (curvedModifier != null)
        {
            trajectoryPositions.Add(targetPosition);
            List <Vector3> curvedTrajectoryPositions = new List <Vector3>();

            for (int i = 0; i < trajectoryPositions.Count - 1; i++)
            {
                curvedTrajectoryPositions.Add(trajectoryPositions[i]);
                AddCurvedTrajectoryBetweenTwoPoints(ref curvedTrajectoryPositions, trajectoryPositions[i], trajectoryPositions[i + 1], curvedModifier);
            }

            trajectoryPositions = curvedTrajectoryPositions;
        }
        #endregion

        trajectoryPositions.Add(targetPosition);

        discTrajectoryParameters.trajectoryPositions = trajectoryPositions;

        return(discTrajectoryParameters);
    }
    public void UpdateTrajectoriesPreview(Dictionary <DiscScript, DiscTrajectoryParameters> discTrajectories)
    {
        List <DiscScript> previousDiscsUntreated = new List <DiscScript>();

        foreach (DiscScript discToTreat in hitByDiscTrajectories.Keys)
        {
            previousDiscsUntreated.Add(discToTreat);
        }


        DiscTrajectoryParameters trajParams       = default;
        List <Vector3>           treatedPositions = new List <Vector3>();

        RaycastHit[] hitResults = new RaycastHit[0];

        Vector3   checkStartPos    = Vector3.zero;
        Vector3   checkEndPos      = Vector3.zero;
        Vector3   checkMovement    = Vector3.zero;
        Vector3   discLocalCenter  = Vector3.zero;
        LayerMask checkMask        = default;
        float     checkRadius      = default;
        bool      blockedByEnemies = false;
        Transform touchedEnemy     = default;

        int counter = 0;

        foreach (DiscScript disc in discTrajectories.Keys)
        {
            if (previousDiscsUntreated.Contains(disc))
            {
                previousDiscsUntreated.Remove(disc);
            }

            if (!hitByDiscTrajectories.ContainsKey(disc))
            {
                hitByDiscTrajectories.Add(disc, new Dictionary <GameObject, EnemyBase>());
            }

            List <GameObject> previousEnemiesUntreated = new List <GameObject>();
            foreach (GameObject enemyToTreat in hitByDiscTrajectories[disc].Keys)
            {
                previousEnemiesUntreated.Add(enemyToTreat);
            }

            if (counter > currentNumberOfShownArrowPreviews)
            {
                Debug.LogWarning("WARNING : Updating more arrows than shown");
            }

            trajParams       = discTrajectories[disc];
            treatedPositions = new List <Vector3>();
            hitResults       = new RaycastHit[0];
            discLocalCenter  = trajParams.disc.GetColliderLocalCenter;
            checkMask        = trajParams.disc.GetTrajectoryCheckLayerMask;
            checkRadius      = trajParams.disc.GetColliderRadius;
            blockedByEnemies = trajParams.disc.GetBlockedByEnemies;
            touchedEnemy     = null;

            treatedPositions.Add(trajParams.trajectoryPositions[0]);
            bool goesThrough = true;
            #region Treat Positions
            for (int j = 1; j < trajParams.trajectoryPositions.Count; j++)
            {
                checkStartPos = trajParams.trajectoryPositions[j - 1] + discLocalCenter;
                checkEndPos   = trajParams.trajectoryPositions[j] + discLocalCenter;
                checkMovement = checkEndPos - checkStartPos;

                #region Test
                hitResults = Physics.SphereCastAll(checkStartPos, checkRadius, checkMovement.normalized, checkMovement.magnitude, checkMask);
                foreach (RaycastHit hitResult in hitResults.OrderBy(h => h.distance))
                {
                    GameObject hitObject = hitResult.collider.gameObject;
                    switch (hitObject.layer)
                    {
                    // Enemy
                    case (10):
                        if (!hitByDiscTrajectories[disc].ContainsKey(hitObject))
                        {
                            EnemyBase hitEnemy = hitObject.GetComponent <EnemyBase>();
                            if (hitEnemy != null)
                            {
                                hitEnemy.ShowWillBeHitIndicator();
                                hitByDiscTrajectories[disc].Add(hitObject, hitEnemy);
                            }
                        }
                        else
                        {
                            previousEnemiesUntreated.Remove(hitObject);
                        }

                        if (blockedByEnemies)
                        {
                            goesThrough = false;
                        }
                        else
                        {
                            goesThrough  = true;
                            touchedEnemy = hitResult.collider.transform;
                        }
                        break;

                    // Shield
                    case (12):
                        goesThrough = false;
                        if (hitResult.collider.transform.parent != null)
                        {
                            if (hitResult.collider.transform.parent.parent != null)
                            {
                                if (hitResult.collider.transform.parent.parent == touchedEnemy)
                                {
                                    goesThrough = true;
                                }
                            }
                        }
                        break;

                    // Obstacle
                    case (14):
                        goesThrough = false;
                        break;
                    }
                    if (!goesThrough)
                    {
                        treatedPositions.Add(hitResult.point - discLocalCenter);
                        break;
                    }
                }

                if (!goesThrough)
                {
                    break;
                }
                #endregion

                #endregion
                treatedPositions.Add(trajParams.trajectoryPositions[j]);
            }
            #endregion

            foreach (GameObject untreatedEnemy in previousEnemiesUntreated)
            {
                hitByDiscTrajectories[disc][untreatedEnemy].HideWillBeHitIndicator();
                hitByDiscTrajectories[disc].Remove(untreatedEnemy);
            }

            arrowPreviews[counter].SetPositions(treatedPositions);
            counter++;
        }

        foreach (DiscScript untreatedDisc in previousDiscsUntreated)
        {
            foreach (EnemyBase enemy in hitByDiscTrajectories[untreatedDisc].Values)
            {
                enemy.HideWillBeHitIndicator();
            }
        }
    }