Пример #1
0
    public virtual void SetupAbility()
    {
        driverPhotonView = transform.root.GetComponent <PhotonView>();
        // assign photon view to the driver
        abilityPhotonView = GetComponent <PhotonView>();
        abilityPhotonView.TransferOwnership(driverPhotonView.Owner);


        //Player gunnerPlayer = gunnerPhotonView.Owner;

        _networkPlayerVehicle = driverPhotonView.GetComponent <NetworkPlayerVehicle>();
        myVehicleManager      = driverPhotonView.GetComponent <VehicleHealthManager>();
        driverAbilityManager  = driverPhotonView.GetComponent <DriverAbilityManager>();

        if (_networkPlayerVehicle != null)
        {
            myNickName = _networkPlayerVehicle.GetDriverNickName();
            myPlayerId = _networkPlayerVehicle.GetDriverID();
            myTeamId   = _networkPlayerVehicle.teamId;
        }
        else
        {
            Debug.LogError("Ability does not belong to a valid vehicle!! Assigning owner to null");
        }

        uiCanvas      = FindObjectOfType <UiCanvasBehaviour>().GetComponent <Canvas>();
        targetOverlay = Instantiate(targetOverlayPrefab, uiCanvas.transform);
        targetOverlay.SetActive(false);
        lastTarget = transform;
        isSetup    = true;
        Invoke(nameof(GetCarList), 2f);
    }
Пример #2
0
    //-----------------------------------------------------------------------------------------------
    //-----------------------------------------------------------------------------------------------
    //-----------------------------------------------------------------------------------------------
    //-----------------------------------------------------------------------------------------------

    public virtual void SetupWeapon()
    {
        // assign photon view to the gunner
        //Player gunnerPlayer = gunnerPhotonView.Owner;

        _networkPlayerVehicle = GetComponentInParent <NetworkPlayerVehicle>();
        myVehicleManager      = GetComponentInParent <VehicleHealthManager>();
        gunnerWeaponManager   = gunnerPhotonView.GetComponent <GunnerWeaponManager>();
        if (_networkPlayerVehicle != null)
        {
            myNickName = _networkPlayerVehicle.GetGunnerNickName();
            myPlayerId = _networkPlayerVehicle.GetGunnerID();
            myTeamId   = _networkPlayerVehicle.teamId;
        }
        else
        {
            Debug.LogError("Weapon does not belong to a valid vehicle!! Assigning owner to null");
        }

        //weaponPhotonView.TransferOwnership(gunnerPlayer);

        weaponUi = FindObjectOfType <WeaponUi>();
        _playerTransformTracker = FindObjectOfType <PlayerTransformTracker>();
        if (fullSalvoOnStart)
        {
            currentSalvo = salvoSize;
        }
        isSetup = true;
    }
Пример #3
0
 // applies damage to the enemy (if we hit an enemy)
 private void DamageCollisionHandler(VehicleHealthManager hitVm, Vector3 hitpoint)
 {
     if (hitVm != null)
     {
         // call take damage rpc
         weaponDamageDetails.localHitPoint = hitVm.transform.InverseTransformPoint(hitpoint);
         hitVm.TakeDamage(weaponDamageDetails);
     }
 }
 // Start is called before the first frame update
 void Start()
 {
     if (lockCursorToWindow && FindObjectOfType <PlinthManager>() == null)
     {
         Cursor.lockState = CursorLockMode.Locked;
     }
     gamestateTracker = FindObjectOfType <GamestateTracker>();
     cam                    = GetComponentInChildren <CinemachineFreeLook>();
     firstPersonCam         = GetComponentInChildren <CinemachineVirtualCamera>();
     firstPersonCam.enabled = false;
     vehicleManager         = GetComponentInParent <VehicleHealthManager>();
     thirdPersonFocus       = cam.LookAt;
     // Give the vehicle manager time to assign teamIds
     //Invoke(nameof(AssignPriority), 3f);
     AssignPriority();
 }
Пример #5
0
    VehicleHealthManager GetVehicleHealthManagerRaycast(Transform sourceTransform)
    {
        Ray ray = new Ray(sourceTransform.position, sourceTransform.forward);
        //   RaycastHit hit; //From camera to hitpoint, not as curent
        Transform hitTransform;
        Vector3   hitVector;

        hitTransform = FindClosestHitObject(ray, out hitVector);
        Debug.Log("mark hittransform: " + hitTransform.gameObject);
        if (hitTransform.root.GetComponent <VehicleHealthManager>() != null)
        {
            VehicleHealthManager vm = hitTransform.root.GetComponent <VehicleHealthManager>();
            if (vm.GetComponent <NetworkPlayerVehicle>().GetGunnerID() != PhotonNetwork.LocalPlayer.ActorNumber)
            {
                return(vm);
            }
        }
        return(null);
    }
Пример #6
0
    VehicleHealthManager GetClosestVehicleHealthManager(Transform sourceTransform)
    {
        VehicleHealthManager[] vehs = FindObjectsOfType <VehicleHealthManager>();

        Vector3 dir = sourceTransform.forward;

        float bestAngle = 180f;

        VehicleHealthManager bestV = null;

        foreach (VehicleHealthManager v in vehs)
        {
            float angle = Vector3.Angle(sourceTransform.forward, v.transform.position - sourceTransform.position);
            if (angle < bestAngle && v != GetComponentInParent <VehicleHealthManager>())
            {
                bestAngle = angle;
                bestV     = v;
            }
        }


        return(bestV);
    }
Пример #7
0
    // Update is called once per frame
    void Update()
    {
        Debug.LogWarning("Tutorial Manager has not been ported to the new PhysX system");

        List <VehicleHealthManager> vehicles      = FindObjectsOfType <VehicleHealthManager>().ToList();
        VehicleHealthManager        playerVehicle = null;
        PlayerEntry player = gamestateTracker.players.Get((short)PhotonNetwork.LocalPlayer.ActorNumber);

        foreach (VehicleHealthManager vehicle in vehicles)
        {
            if (player.teamId == vehicle.teamId)
            {
                playerVehicle = vehicle;
                break;
            }
        }
        player.Release();

        if (playerVehicle != null)
        {
            if (playerVehicle.GetComponent <Rigidbody>().velocity.sqrMagnitude < 5)
            {
                counter += Time.deltaTime;
            }
            else
            {
                counter = 0f;
            }
        }

        if (counter >= 5f)
        {
            counter      = 0f;
            tutorials[3] = true;
        }
    }
Пример #8
0
    public void  CollisionEnter(PhysXCollision collision)
    {
        // Debug.LogError(collision.gameObject);

        Vector3 impactNormal = collision.GetContact(0).normal;

        // if we are the true projectile, then deal with game altering stuff like damage n that
        if (explosionForce > 0)
        {
            Squishing hitMeshSquisher = collision.gameObject.GetComponentInParent <Squishing>();
            if (hitMeshSquisher != null)
            {
                Vector3 explosionPoint = collision.GetContact(0).point + impactNormal * explosionOffset;
                hitMeshSquisher.ExplodeMeshAt(explosionPoint, explosionForce);
            }
        }

        Vector3 hitPoint           = collision.GetContact(0).point;
        VehicleHealthManager hitVm = collision.gameObject.GetComponentInParent <VehicleHealthManager>();

        if (hitVm != null)
        {
            if (hitVm.teamId == weaponDamageDetails.sourceTeamId)
            {
                Destroy(gameObject);
            }
        }
        if (isTrueProjectile)
        {
            DamageCollisionHandler(hitVm, hitPoint);
        }
        VisualCollisionHandler(impactNormal, hitVm != null);

        //   pooledObject.Finish();
        Destroy(gameObject);
    }
Пример #9
0
    void Update()
    {
        // fire 1
        if (Input.GetButton("Fire1"))
        {
            if (gunnerPhotonView.IsMine)
            {
                if (gunnerWeaponManager.CurrentWeaponGroupCanFire())
                {
                    Vector3 targetHitpoint;
                    if (turretController.inDeadZone)
                    {
                        targetHitpoint = CalculateTargetingHitpoint(cam);
                    }
                    else
                    {
                        targetHitpoint = CalculateTargetingHitpoint(barrelTransform);
                    }

                    gunnerWeaponManager.FireCurrentWeaponGroup(targetHitpoint);
                }
            }
        }
        // jank ram damage thing
        if (Input.GetButtonDown("Fire2"))
        {
            Debug.Log("mark fire btn press");
            if (gunnerPhotonView.IsMine)
            {
                Debug.Log("mark fire");
                VehicleHealthManager hitvm = GetClosestVehicleHealthManager(cam);
                if (hitvm != null)
                {
                    Debug.Log("mark hitvm not null");
                    NetworkPlayerVehicle npv = GetComponentInParent <NetworkPlayerVehicle>();
                    int teamId   = npv.teamId;
                    int driverId = npv.GetDriverID();
                    int gunnerId = npv.GetGunnerID();
                    // remove last mark
                    if (lastMarkedTeam != 0)
                    {
                        FindObjectOfType <PlayerTransformTracker>().GetVehicleTransformFromTeamId(lastMarkedTeam).GetComponent <PhotonView>().RPC(nameof(CollidableHealthManager.RemoveMarkedTeam_RPC), RpcTarget.All, lastMarkedTeam, driverId, gunnerId);
                    }
                    // add new mark
                    GetComponent <PhotonView>().RPC(nameof(MarkAudioPlay_RPC), RpcTarget.All);
                    hitvm.GetComponent <PhotonView>().RPC(nameof(CollidableHealthManager.MarkTeam_RPC), RpcTarget.All, teamId, driverId, gunnerId);
                    lastMarkedTeam = hitvm.gameObject.GetComponent <NetworkPlayerVehicle>().teamId;
                    Debug.Log("mark done");
                }
                if (hitvm == null)
                {
                    Debug.Log("mark is null");
                }
                if (hitvm.transform == transform.root)
                {
                    Debug.Log("mark is me");
                }
            }
        }

        if (Input.GetButtonUp("Fire1"))
        {
            if (gunnerPhotonView.IsMine)
            {
                gunnerWeaponManager.CeaseFireCurrentWeaponGroup();
            }
        }

        // // relaod
        if (Input.GetButtonDown("Reload"))
        {
            if (gunnerPhotonView.IsMine)
            {
                gunnerWeaponManager.ReloadCurrentWeaponGroup();
            }
        }

        if (Input.GetButtonDown("Ultimate"))
        {
            if (gunnerPhotonView.IsMine)
            {
                gunnerWeaponManager.SelectUltimate();
            }
        }

        if (Input.GetKey(KeyCode.Space))
        {
            camera.m_Lens.FieldOfView = Mathf.Lerp(camera.m_Lens.FieldOfView, 30, 0.1f);
        }
        else
        {
            camera.m_Lens.FieldOfView = Mathf.Lerp(camera.m_Lens.FieldOfView, 60, 0.1f);
        }

        turretController.ChangeTargetYaw(cameraSensitivity * Input.GetAxis("Mouse X") * Time.deltaTime);
        turretController.ChangeTargetPitch(-(cameraSensitivity * Input.GetAxis("Mouse Y") * Time.deltaTime));
        turretController.UpdateTargeterRotation();


        float newy = Mathf.Max(cinemachineTransposer.m_FollowOffset.y - Input.mouseScrollDelta.y * 0.2f, 1.5f);
        float newz = Mathf.Min(cinemachineTransposer.m_FollowOffset.z + Input.mouseScrollDelta.y * 0.6f, -3f);

        if (newy < maxZoomOut)
        {
            cinemachineTransposer.m_FollowOffset.y = newy;
            cinemachineTransposer.m_FollowOffset.z = newz;
        }
    }
    public void CollisionEnter(PhysXCollision collision)
    {
        // Debug.Log("crashed into: " + collision.gameObject);
        float dSpeed = myRb.velocity.magnitude;

        float impulse = collision.impulse.magnitude;

        if (collision.rigidBody != null)
        {
            dSpeed = (myRb.velocity - collision.rigidBody.velocity).magnitude;
        }
        if (myPhotonView.IsMine && collision.contactCount > 0 && dSpeed > 1.5 && collisionTimer < 0)
        {
            collisionTimer = maxCollisionRate;
            Vector3 collisionNormal = collision.GetContact(0).normal;
            Vector3 collisionForce  = collision.impulse;
            if (Vector3.Dot(collisionForce, collisionNormal) < 0)
            {
                collisionForce = -collisionForce;
            }
            collisionForce /= Time.fixedDeltaTime;
            collisionForce  = transform.InverseTransformDirection(collisionForce);

            VehicleHealthManager otherVehicleManager = collision.gameObject.GetComponent <VehicleHealthManager>();

            Vector3 collisionPoint = Vector3.zero;
            for (int i = 0; i < collision.contactCount; i++)
            {
                collisionPoint += collision.GetContact(i).point;
            }
            collisionPoint /= collision.contactCount;

            Vector3 contactDirection = transform.InverseTransformPoint(collisionPoint);
            float   damage           = CalculateCollisionDamage(collisionForce, contactDirection, otherVehicleManager != null);

            // instantiate damage sound over network
            if ((damage > crashSoundsSmallDamageThreshold || (otherVehicleManager != null)) && timeSinceLastRam > 0.25f)
            {
                PlayDamageSoundNetwork(damage);
            }

            damage = damage / rammingDamageResistance;

            if (myPhotonView.IsMine && hasHotPotatoManager && otherVehicleManager != null && timeSinceLastRam > 0.25f)
            {
                if (collisionNpv.GetDriverID() == PhotonNetwork.LocalPlayer.ActorNumber || collisionNpv.GetGunnerID() == PhotonNetwork.LocalPlayer.ActorNumber)
                {
                    // Debug.LogError("Slow down should happen");
                    hotPotatoManager.SlowedCollision();
                }
                if (collisionSparks != null)
                {
                    GameObject a = Instantiate(collisionSparks, collisionPoint, Quaternion.identity);
                    a.transform.parent = transform;
                }

                if (collisionNpv != null && !collisionNpv.botDriver)
                {
                    if (damage > 4)
                    {
                        driverCrashDetector.CrashCollisionCamera(collision, false);
                    }
                    else
                    {
                        driverCrashDetector.CrashCollisionCamera(collision, true);
                    }
                }
            }

            if (damage > 5)
            {
                if (otherVehicleManager != null)
                {
                    if (otherVehicleManager != null)
                    {
                        damage *= otherVehicleManager.rammingDamageMultiplier;
                    }
                    Weapon.WeaponDamageDetails rammingDetails = otherVehicleManager.rammingDetails;

                    rammingDetails.damage = damage;
                    if (markedByTeams.Contains(rammingDetails.sourceTeamId))
                    {
                        rammingDetails.damage *= markedTeamDamageIncrease;
                    }

                    TakeDamage(rammingDetails);
                }
                else
                {
                    TakeDamage(damage);
                }
            }
        }
        if (collision.rigidBody != null)
        {
            timeSinceLastRam = 0f;
        }
    }