public override void OnDriverOff()
    {
        DebugMsg("OnDriverOff");
        base.OnDriverOff();
        this.m_characterController.enabled = false;

        if (!isTouchingGround && hasWaterBelow())
        {
            MoveBoatDownToClosestWaterBlock();
            CreateDummyBoat();

            if (!CustomVehiclesUtils.IsLandInBounds(new Bounds(this.position, new Vector3(5f, 1f, 5f))))
            {
                // random on water tooltips
                //GameManager.ShowTooltip(this.player, randomDriverOffToolTips[Random.Range(0, randomDriverOffToolTips.Length-1)]);
                GameManager.ShowTooltip(this.player, randomDriverOffToolTips[lastRandomDriverOffToolTipIndex]);
                lastRandomDriverOffToolTipIndex += 1;
                if (lastRandomDriverOffToolTipIndex > randomDriverOffToolTips.Length - 1)
                {
                    lastRandomDriverOffToolTipIndex = 0;
                }
            }

            this.nativeBoxCollider.center = new Vector3(0, 0.5f, -3.37f);
            this.nativeBoxCollider.size   = new Vector3(2, 2, 1);
        }
        else
        {
            this.nativeBoxCollider.center = vehicleActivationCenter;
            this.nativeBoxCollider.size   = vehicleActivationSize;
        }
    }
Exemple #2
0
    public static void PrintSceneAtlases()
    {
        GameObject nguiRoot2D = GameObject.Find("/NGUI Root (2D)");

        if (nguiRoot2D == null)
        {
            DebugMsg("StartGame_additions: Cannot find 'NGUI Root (2D)'");
            return;
        }

        GameObject root = CustomVehiclesUtils.GetRootTransform(nguiRoot2D.transform).gameObject;

        Component[] transforms = root.GetComponentsInChildren <Transform>();
        DebugMsg("PrintSceneAtlases: Scene Atlases:");
        foreach (Transform transform in transforms)
        {
            if (transform.name.ToLower().Contains("atlas"))
            {
                DebugMsg("- " + transform.name);
                Component[] comps = transform.gameObject.GetComponents <Component>();
                DebugMsg("Components:");
                foreach (Component comp in comps)
                {
                    DebugMsg("\t- " + comp.name + " | type = " + comp.GetType().ToString());
                    if (comp.GetType() == typeof(UIAtlas) || comp.GetType().IsSubclassOf(typeof(UIAtlas)))
                    {
                        DebugMsg("\t- atlas: " + transform.name + " | comp = " + comp.name + " | type = " + comp.GetType().ToString());
                    }
                }
            }
        }
    }
    public virtual void CreateDummyBoat()
    {
        // Create Dummy boat Block
        BlockValue newBlockValue = Block.GetBlockValue("smallBoatDummyBlock");
        int        rot           = CustomVehiclesUtils.EularYRotToBlockYRot(this.transform.forward);

        newBlockValue.rotation = (byte)rot;
        DebugMsg("EntityCustomBoat Create Dummy Boat: rot = " + rot.ToString());

        bHasBoatDummy = true;

        if (Steam.Network.IsServer)
        {
            GameManager.Instance.World.SetBlockRPC(boatDummyPos, newBlockValue);
        }
    }
    public bool _FindSetAndOffsetAssignedBoat(int _cIdx, Vector3i _blockPos, BlockValue _blockValue, ref EntityCustomBoat _assignedBoat)
    {
        // Try to find closest Boat
        _assignedBoat = GetClosestBoat(_blockPos);
        if (_assignedBoat != null)
        {
            if (!_assignedBoat.bHasBoatDummy)
            {
                DebugMsg("BlockDummyBoat _FindSetAndOffsetAssignedBoat: Found closest Boat but it is not flagged to have a Dummy Boat Block, skipping: _blockPos = " + _blockPos.ToString() + " | Boat pos = " + _assignedBoat.position.ToString("0.000"));
                return(false);
            }
            if (_assignedBoat.bHasBoatDummy && _assignedBoat.boatDummyBlockEntityData != null && _assignedBoat.boatDummyPos != _blockPos)
            {
                DebugMsg("BlockDummyBoat _FindSetAndOffsetAssignedBoat: Found closest Boat but it already as an assigned Dummy Boat Block, skipping: _blockPos = " + _blockPos.ToString() + " | Boat pos = " + _assignedBoat.position.ToString("0.000"));
                return(false);
            }

            float closestBoatDistance = Vector3.Distance(_blockPos.ToVector3(), _assignedBoat.position);
            if (closestBoatDistance > 3 && _assignedBoat.boatDummyPos != _blockPos)
            {
                DebugMsg("BlockDummyBoat _FindSetAndOffsetAssignedBoat: Found closest Boat but it's too far, skipping: _blockPos = " + _blockPos.ToString() + " | Boat pos = " + _assignedBoat.position.ToString("0.000"));
                return(false);
            }

            DebugMsg("BlockDummyBoat _FindSetAndOffsetAssignedBoat: Found closest Boat: _blockPos = " + _blockPos.ToString() + " | Boat pos = " + _assignedBoat.position.ToString("0.000"));

            _assignedBoat.boatDummyPos = _blockPos;

            // Rotate boat to block
            Quaternion newQuat = Quaternion.AngleAxis(CustomVehiclesUtils.BlockYRotToEularYRot((int)_blockValue.rotation), Vector3.up);
            _assignedBoat.transform.rotation = newQuat;
            _assignedBoat.SetRotation(newQuat.eulerAngles);

            return(true);
        }
        else
        {
            DebugMsg("BlockDummyBoat FindSetAndOffsetAssignedBoat: Could not find closest Boat: _blockPos = " + _blockPos.ToString());
        }

        return(false);
    }
Exemple #5
0
    void FixedUpdate()
    {
        if (entityHelico == null)
        {
            InitController();
            return;
        }

        if (!entityHelico.hasDriver || !entityHelico.HasFuel())
        {
            EngineForce -= 0.5f;
            if (EngineForce < 0)
            {
                EngineForce = 0;
            }
            entityHelico.headlight_rot.localRotation = Quaternion.identity;
            return;
        }

        EngineForceRatio    = CustomVehiclesUtils.GetRatio(Mathf.Clamp(EngineForce, 10f, MaxEngineForce), 10f, MaxEngineForce);
        AdjEngineForceRatio = (EngineForceRatio * 4f) + 1f;

        LiftProcess();
        MoveProcess();
        TiltProcess();
        HeadlightMovement();

        if (showDebugLog && Time.time - updatesDebugPrintDelay > lastDebugPrintTime)
        {
            DebugMsg("Engine force = " + EngineForce.ToString("0.000"));
            DebugMsg("Adjusted Engine force Ratio = " + AdjEngineForceRatio.ToString("0.000"));
            DebugMsg("Adjusted ForwardForce = " + (ForwardForce * AdjEngineForceRatio).ToString("0.000"));
            DebugMsg("IsOnGround = " + IsOnGround.ToString());
            DebugMsg("velocity = " + HelicopterModel.velocity.magnitude.ToString("0.000"));
            lastDebugPrintTime = Time.time;
        }
    }
    void Update()
    {
        if (GameManager.IsDedicatedServer)
        {
            return;
        }

        if (entityVehicle == null || entityVehicle.player == null || entityVehicle.cameraOffset == null)
        {
            InitController();
            return;
        }

        LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(entityVehicle.player);

        //if (!entityVehicle.hasDriver || GameManager.Instance.IsPaused() || GameManager.Instance.m_GUIConsole.isInputActive || entityVehicle.uiforPlayer.windowManager.IsModalWindowOpen())
        if (!entityVehicle.hasDriver || GameManager.Instance.IsPaused() || GameManager.Instance.m_GUIConsole.isInputActive || uiforPlayer.windowManager.IsModalWindowOpen())
        {
            return;
        }

        // toggle 1st-3rd person view
        if (Input.GetKey(KeyCode.Home) && Time.time - 1.0f > lastCamToggle)
        {
            if (is3rdPersonView)
            {
                ToggleFirstAnd3rdPersonView(true, true);
            }
            else
            {
                ToggleFirstAnd3rdPersonView(false, true);
            }
        }

        // 3rd person view Zoom in-out
        if (is3rdPersonView && entityVehicle.player != null)
        {
            if (Input.GetAxis("Mouse ScrollWheel") > 0f) // forward
            {
                if (newThirdPcameraOffset.z >= entityVehicle.cameraOffset.z)
                {
                    newThirdPcameraOffset.z += Mathf.Lerp(1.0f, 0.02f, thirdPcamLerpMult);
                }
                else
                {
                    newThirdPcameraOffset.z += Mathf.Lerp(1.0f, 5.0f, thirdPcamLerpMult);
                }
                //DebugMsg("thirdPcamLerpMult = " + thirdPcamLerpMult.ToString("0.0000"));
            }
            else if (Input.GetAxis("Mouse ScrollWheel") < 0f) // backwards
            {
                if (newThirdPcameraOffset.z >= entityVehicle.cameraOffset.z)
                {
                    newThirdPcameraOffset.z -= Mathf.Lerp(1.0f, 0.2f, thirdPcamLerpMult);
                }
                else
                {
                    newThirdPcameraOffset.z -= Mathf.Lerp(1.0f, 5.0f, thirdPcamLerpMult);
                }
                //DebugMsg("thirdPcamLerpMult = " + thirdPcamLerpMult.ToString("0.0000"));
            }

            if (newThirdPcameraOffset.z > entityVehicle.cameraOffset.z / 3.0f)
            {
                newThirdPcameraOffset.z = entityVehicle.cameraOffset.z / 3.0f;
            }

            if (newThirdPcameraOffset.z >= entityVehicle.cameraOffset.z)
            {
                thirdPcamLerpMult       = CustomVehiclesUtils.GetRatio(Mathf.Clamp(newThirdPcameraOffset.z, entityVehicle.cameraOffset.z, entityVehicle.cameraOffset.z / 3.0f), entityVehicle.cameraOffset.z, entityVehicle.cameraOffset.z / 3.0f);
                newThirdPcameraOffset.y = Mathf.Lerp(entityVehicle.cameraOffset.y, entityVehicle.cameraOffset.y + Mathf.Clamp(Mathf.Abs(entityVehicle.cameraOffset.y) * 2.0f, 0.5f, 2.0f), thirdPcamLerpMult);
            }
            else
            {
                thirdPcamLerpMult       = 1f - CustomVehiclesUtils.GetRatio(Mathf.Clamp(newThirdPcameraOffset.z, -50.0f, entityVehicle.cameraOffset.z), -50.0f, entityVehicle.cameraOffset.z);
                newThirdPcameraOffset.y = Mathf.Lerp(entityVehicle.cameraOffset.y, entityVehicle.cameraOffset.y + 15.0f, thirdPcamLerpMult);
            }

            entityVehicle.player.vp_FPCamera.Position3rdPersonOffset = newThirdPcameraOffset;
        }
    }
Exemple #7
0
    public void FindAndKillSurroundingEntities()
    {
        //if (entityDamage == 0 || entityVehicle.lastControllerVelocityMagnitude < 5f || Time.time - entityHitAgainDelay < lastEntityHitTime)
        if (entityDamage == 0 || lastControllerVelocityMagnitude < entityHitMinSpeed)
        {
            //DebugMsg("NOT damaging entity: entityDamage = " + entityDamage.ToString() + " | lastControllerVelocityMagnitude = " + entityVehicle.lastControllerVelocityMagnitude.ToString("0.000"));
            return;
        }
        else
        {
            //DebugMsg("lastControllerVelocityMagnitude = " + entityVehicle.lastControllerVelocityMagnitude.ToString("0.000"));
        }

        // Try-catch for now because of an error with Bandits and survivors
        try
        {
            Vector3    b = new Vector3(0f, entityVehicle.m_characterController.height / 2f, 0f);
            RaycastHit raycastHit;
            //if (Physics.CapsuleCast(entityVehicle.position - b, entityVehicle.position + b, destructionRadius, entityVehicle.motion.normalized, out raycastHit, entityVehicle.motion.magnitude, -1) && raycastHit.collider != null)
            if (Physics.CapsuleCast(entityVehicle.position - b, entityVehicle.position + b, destructionRadius, entityVehicle.motion.normalized, out raycastHit, destructionRadius + 1, -1) && raycastHit.collider != null)
            {
                RootTransformRefEntity component = raycastHit.collider.gameObject.GetComponent <RootTransformRefEntity>();
                if (component)
                {
                    EntityAlive entityAlive = component.RootTransform.GetComponent <Entity>() as EntityAlive;
                    //if (entityAlive != null && entityAlive != entityVehicle.AttachedEntities && entityAlive.Spawned && !entityAlive.IsDead())
                    if (entityAlive != null && entityAlive != entityVehicle.AttachedEntities && !entityAlive.IsDead() && !(entityAlive.entityId == lastHitEntityId && Time.time - entityHitAgainDelay < lastEntityHitTime))
                    {
                        int damage = entityDamage;
                        entityHitSpeedRatio = CustomVehiclesUtils.GetRatio(Mathf.Clamp(lastControllerVelocityMagnitude, entityHitMinSpeed, 18f), entityHitMinSpeed, 18f) + 1f;
                        entityHitDamage     = Mathf.RoundToInt((float)damage * entityHitSpeedRatio);
                        bool isCritical = lastControllerVelocityMagnitude > entityCriticalHitMinSpeed;
                        // Doing this in order to properly kill entities. Otherwise they die instantly without animation, and animal corpses disappear.
                        if (entityHitDamage > entityAlive.Health)
                        {
                            entityHitDamage = entityAlive.Health;
                            isCritical      = true;
                        }
                        DamageSourceEntity damageSourceEntity;
                        if (isCritical)
                        {
                            damageSourceEntity = new DamageSourceEntity(EnumDamageSourceType.Melee, entityVehicle.player.entityId, -raycastHit.normal);
                        }
                        else
                        {
                            damageSourceEntity = new DamageSourceEntity(EnumDamageSourceType.Melee, entityVehicle.player.entityId, -raycastHit.normal, raycastHit.transform.name, raycastHit.point, Vector2.zero);
                        }
                        //DamageSourceEntity damageSourceEntity = new DamageSourceEntity(EnumDamageSourceType.Melee, entityVehicle.player.entityId, -raycastHit.normal, raycastHit.transform.name, raycastHit.point, Vector2.zero);
                        lastHitEntityId = entityAlive.entityId;
                        entityAlive.DamageEntity(damageSourceEntity, entityHitDamage, isCritical, isCritical? 3f : 2f);

                        //DebugMsg("Damage Entity: " + entityAlive.entityId + " | lastControllerVelocityMagnitude = " + lastControllerVelocityMagnitude.ToString("0.000") + " (hit speed ratio = " + entityHitSpeedRatio.ToString("0.000")
                        //    + ") | damage = " + entityHitDamage.ToString("0.000") + " (" + entityAlive.Health.ToString() + "/" + entityAlive.GetMaxHealth().ToString() + ") | hit transform name = " + raycastHit.transform.name + " | critical = " + isCritical.ToString());

                        float vehDmg = (((float)entityAlive.GetMaxHealth()) / 3000.0f) * vehicleDamageFactor_entities * entityHitSpeedRatio;
                        DamageVehicle(vehDmg, 2f);
                        lastEntityHitTime = Time.time;
                    }
                }
            }
        }
        catch (System.Exception e)
        {
            Debug.LogError("An error occurred: " + e);
        }
    }
    public override void GetVehicleBones()
    {
        base.GetVehicleBones();

        List <Transform> childrenList        = new List <Transform>();
        List <int>       childrenInstanceIds = new List <int>();

        childrenList.Add(this.transform);
        childrenInstanceIds.Add(this.transform.GetInstanceID());
        CustomVehiclesUtils.GetAllChildTransforms(this.transform, ref childrenList, ref childrenInstanceIds);

        foreach (Transform child in childrenList)
        {
            switch (child.name)
            {
            case "Origin":
                if (Origin == null)
                {
                    Origin = child;
                }
                else
                {
                    Origin2 = child;
                }
                break;

            case "handlebar_joint":
                if (handlebar_joint == null)
                {
                    handlebar_joint = child;
                }
                else
                {
                    handlebar_joint2 = child;
                }
                break;

            case "chassis_joint":
                if (chassis_joint == null)
                {
                    chassis_joint = child;
                }
                else
                {
                    chassis_joint2 = child;
                }
                break;

            case "loader_joint":
                if (loader_joint == null)
                {
                    loader_joint = child;
                }
                else
                {
                    loader_joint2 = child;
                }
                break;

            case "bucket_joint":
                if (bucket_joint == null)
                {
                    bucket_joint = child;
                }
                else
                {
                    bucket_joint2 = child;
                }
                break;
            }
        }

        // Was for testing additional colliders with a custom script. May reuse later...

        /*if (Origin != null)
         * {
         *  BoxCollider bc = Origin.gameObject.GetComponent<BoxCollider>();
         *  if (bc != null)
         *  {
         *      bc.enabled = true;
         *      clc = Origin.gameObject.GetComponent<CustomLoaderControl>();
         *      if (clc == null)
         *      {
         *          DebugMsg("Adding CustomLoaderControl script.");
         *          clc = Origin.gameObject.AddComponent<CustomLoaderControl>();
         *      }
         *      clc.enabled = true;
         *  }
         * }*/

        if (handlebar_joint == null || chassis_joint == null || loader_joint == null || bucket_joint == null)
        {
            if (allBonesSet1Found)
            {
                allBonesSet1Found = false;
            }
            Debug.LogError(this.ToString() + " : Some bones could not be found for set 1. Custom Car will not be fully functionnal.");
        }
        else
        {
            if (allBonesSet1Found)
            {
                allBonesSet1Found = true;
                DebugMsg(this.ToString() + " : All bones set 1 found.");
            }

            lastLoaderRot = loader_joint.localRotation.eulerAngles;
            if (lastLoaderRot.x > 180)
            {
                lastLoaderRot.x -= 360;
            }
        }

        if (handlebar_joint2 == null || chassis_joint2 == null || loader_joint2 == null || bucket_joint2 == null)
        {
            if (allBonesSet2Found)
            {
                allBonesSet2Found = false;
            }
            DebugMsg(this.ToString() + " : Some bones could not be found for set 2. (this is harmless)");
        }
        else
        {
            if (allBonesSet2Found)
            {
                allBonesSet2Found = true;
                DebugMsg(this.ToString() + " : All bones set 2 found.");
            }

            lastLoaderRot = loader_joint2.localRotation.eulerAngles;
            if (lastLoaderRot.x > 180)
            {
                lastLoaderRot.x -= 360;
            }
        }
    }
    public override void GetVehicleBones()
    {
        base.GetVehicleBones();

        List <Transform> childrenList        = new List <Transform>();
        List <int>       childrenInstanceIds = new List <int>();

        childrenList.Add(this.transform);
        childrenInstanceIds.Add(this.transform.GetInstanceID());
        CustomVehiclesUtils.GetAllChildTransforms(this.transform, ref childrenList, ref childrenInstanceIds);

        foreach (Transform child in childrenList)
        {
            switch (child.name)
            {
            case "rotor_joint":
                if (rotor_joint1 == null)
                {
                    rotor_joint1 = child;
                }
                else
                {
                    rotor_joint2 = child;
                }
                break;

            case "back_rotor_joint":
                if (back_rotor_joint1 == null)
                {
                    back_rotor_joint1 = child;
                }
                else
                {
                    back_rotor_joint2 = child;
                }
                break;

            case "headlight":
                if (headlight_rot1 == null)
                {
                    headlight_rot1 = child;
                }
                else
                {
                    headlight_rot2 = child;
                }
                break;
            }
        }

        if (rotor_joint1 == null || back_rotor_joint1 == null || headlight_rot1 == null)
        {
            if (allBonesSet1Found)
            {
                allBonesSet1Found = false;
            }
            Debug.LogError(this.ToString() + " : Some bones could not be found for set 1. Custom Helicopter will not be fully functionnal.");
        }
        else
        {
            if (allBonesSet1Found)
            {
                allBonesSet1Found = true;
                DebugMsg(this.ToString() + " : All bones set 1 found.");
            }
        }

        if (rotor_joint2 == null || back_rotor_joint2 == null || headlight_rot2 == null)
        {
            if (allBonesSet2Found)
            {
                allBonesSet2Found = false;
            }
            DebugMsg(this.ToString() + " : Some bones could not be found for set 2. (this is harmless)");
        }
        else
        {
            if (allBonesSet2Found)
            {
                allBonesSet2Found = true;
                DebugMsg(this.ToString() + " : All bones set 2 found.");
            }
        }

        if (allBonesSet2Found)
        {
            rotor_joint      = rotor_joint2;
            back_rotor_joint = back_rotor_joint2;
            headlight_rot    = headlight_rot2;
        }
        else if (allBonesSet1Found)
        {
            rotor_joint      = rotor_joint1;
            back_rotor_joint = back_rotor_joint1;
            headlight_rot    = headlight_rot1;
        }
        else
        {
            DebugMsg("No Bones sets found, cannot initiate Helicopter.");
        }
    }
Exemple #10
0
    public override void GetVehicleBones()
    {
        base.GetVehicleBones();

        List <Transform> childrenList        = new List <Transform>();
        List <int>       childrenInstanceIds = new List <int>();

        childrenList.Add(this.transform);
        childrenInstanceIds.Add(this.transform.GetInstanceID());
        CustomVehiclesUtils.GetAllChildTransforms(this.transform, ref childrenList, ref childrenInstanceIds);

        foreach (Transform child in childrenList)
        {
            switch (child.name)
            {
            case "handlebar_joint":
                if (handlebar_joint == null)
                {
                    handlebar_joint = child;
                }
                else
                {
                    handlebar_joint2 = child;
                }
                break;

            case "frontWheel_joint_yaw":
                if (frontWheel_joint_yaw == null)
                {
                    frontWheel_joint_yaw = child;
                }
                else
                {
                    frontWheel_joint_yaw2 = child;
                }
                break;

            case "frontWheel_joint":
                if (frontWheel_joint == null)
                {
                    frontWheel_joint = child;
                }
                else
                {
                    frontWheel_joint2 = child;
                }
                break;

            case "right_frontWheel_joint_yaw":
                if (right_frontWheel_joint_yaw == null)
                {
                    right_frontWheel_joint_yaw = child;
                }
                else
                {
                    right_frontWheel_joint_yaw2 = child;
                }
                break;

            case "right_frontWheel_joint":
                if (right_frontWheel_joint == null)
                {
                    right_frontWheel_joint = child;
                }
                else
                {
                    right_frontWheel_joint2 = child;
                }
                break;
            }
        }

        if (handlebar_joint == null || frontWheel_joint_yaw == null || frontWheel_joint == null || right_frontWheel_joint_yaw == null || right_frontWheel_joint == null)
        {
            if (allBonesSet1Found)
            {
                allBonesSet1Found = false;
            }
            Debug.LogError(this.ToString() + " : Some bones could not be found for set 1. Custom Car will not be fully functionnal.");
        }
        else
        {
            if (allBonesSet1Found)
            {
                allBonesSet1Found = true;
                DebugMsg(this.ToString() + " : All bones set 1 found.");
            }
        }

        if (handlebar_joint2 == null || frontWheel_joint_yaw2 == null || frontWheel_joint2 == null || right_frontWheel_joint_yaw2 == null || right_frontWheel_joint2 == null)
        {
            if (allBonesSet2Found)
            {
                allBonesSet2Found = false;
            }
            DebugMsg(this.ToString() + " : Some bones could not be found for set 2. (this is harmless)");
        }
        else
        {
            if (allBonesSet2Found)
            {
                allBonesSet2Found = true;
                DebugMsg(this.ToString() + " : All bones set 2 found.");
            }
        }
    }