Example #1
0
    //Shooting mechanic: Local player shoots -> server shoots & test hit -> third-party clients shoot

    //Initialize bullet paths; Simulate local-wise; Ask server to simlulate on other clients
    public void Pull_trigger_player(Player_controller client_player)
    {
        if ((ammo <= 0) || (Time.time <= time_to_fire || is_shoot_inside_wall()))
        {
            return;
        }
        client_player.reloading = false;
        client_player.body.anim_reload(false);
        time_to_fire = Time.time + 1 / rate_of_fire;
        //Obtain bullet initial position and direction
        short firepoint_x     = (short)(fire_point.position.x * CONSTANTS.SYNC_POS_MUTIPLIER);
        short firepoint_y     = (short)(fire_point.position.y * CONSTANTS.SYNC_POS_MUTIPLIER);
        short aim_angle_short = get_aim_dir_short();
        float aim_angle_float = get_aim_dir_float();

        //Calculate additional bullet output due to low fps
        int fps_stack = (int)Mathf.Clamp(Time.deltaTime / (1.0f / rate_of_fire), 1, CONSTANTS.MAX_ROF_FRAMERATE_OVERLOAD);

        fps_stack = Mathf.Min(fps_stack, ammo);
        ammo     -= (ushort)fps_stack;
        client_player.GetComponent <Rigidbody2D>().AddForce(-get_aim_vec().normalized *recoil *fps_stack);
        //client_player.shake_screen(shake_extent, transform.rotation.eulerAngles.z+180);



        //Initialize bullet paths
        //Simulate bullet effects
        if (burst_shots == 1)
        {
            if (fps_stack <= 1)
            {
                short aim_dir_bias = get_bullet_seed_single(aim_angle_float, firecone_angle);
                //Local shooting
                shoot(client_player.gameObject, firepoint_x, firepoint_y, aim_dir_bias, null);
                //Others shooting
                if (client_player.isServer && !Local_precomputation)
                {
                    server_shoot(client_player.gameObject, firepoint_x, firepoint_y, aim_dir_bias, null, ammo <= 0);
                }
                else if (!Local_precomputation)
                {
                    client_player.Cmd_request_shoot_optimized_single(firepoint_x, firepoint_y, aim_dir_bias, ammo <= 0);
                }
            }
            else
            {
                sbyte[] blt_dir = get_bullet_seed_single_incremental(firecone_angle, client_player.body.aim_suppress, fps_stack);
                //Local shooting
                shoot(client_player.gameObject, firepoint_x, firepoint_y, aim_angle_short, blt_dir);
                //Others shooting
                if (client_player.isServer && !Local_precomputation)
                {
                    server_shoot(client_player.gameObject, firepoint_x, firepoint_y, aim_angle_short, blt_dir, ammo <= 0);
                }
                else if (!Local_precomputation)
                {
                    client_player.Cmd_request_shoot_optimized(firepoint_x, firepoint_y, aim_angle_short, blt_dir, ammo <= 0);
                }
            }
        }
        else if (burst_shots >= 2)
        {
            sbyte[] blt_dir = get_bullet_seed(firecone_angle, fps_stack);
            //Local shooting
            shoot(client_player.gameObject, firepoint_x, firepoint_y, aim_angle_short, blt_dir);
            //Others shooting
            if (client_player.isServer && !Local_precomputation)
            {
                server_shoot(client_player.gameObject, firepoint_x, firepoint_y, aim_angle_short, blt_dir, ammo <= 0);
            }
            else if (!Local_precomputation)
            {
                client_player.Cmd_request_shoot_optimized(firepoint_x, firepoint_y, aim_angle_short, blt_dir, ammo <= 0);
            }
        }

        firecone_angle = Mathf.Clamp(firecone_angle + fps_stack * (client_player.body.aim_suppress) * accuracy / bias_factor, 0, accuracy - accuracy / bias_factor);

        /*
         * firecone_angle += fps_stack * (client_player.body.aim_suppress) * accuracy / bias_factor;
         * if(firecone_angle > accuracy - accuracy / bias_factor)
         * {
         *  firecone_angle = accuracy;
         * }
         */
        /*
         * if ()
         * {
         *  firecone_angle += (client_player.body.aim_suppress) * accuracy / bias_factor;
         * }
         * else
         * {
         *
         * }
         */
    }