//This function will detect character collision and calculate damage //Return 1: keep the projectile going //Return 0: this object shouldn't be impacted //Return -1: this projectile is stopped by character public int impact_character(Body_hitbox_generic hit_box, Vector2 hit_point) { Body_generic body = hit_box.body; if (body.gameObject == activator) { return(-1); } if (local) { float heat_dmg = 0; float angle = Mathf.Atan2(aimdir.y, aimdir.x) * 180 / Mathf.PI; if (activator.GetComponent <Body_generic>().dmg_tags.Contains(body.tag)) { heat_dmg = Damage(); } Vector2 force = CONSTANTS.DAMAGE_FORCE_MULTIPLIER * aimdir.normalized * heat_dmg / 20; //If Client authoritates laser if (activator.GetComponent <Body_generic>().isPlayer&& !activator.GetComponent <Body_generic>().isServer) { activator.GetComponent <Player_controller>().add_to_shot_list(body.gameObject, heat_dmg, hit_point, force.magnitude, CONSTANTS.seed_float_to_short(angle, 360), false, 1); body.GetComponent <Rigidbody2D>().AddForceAtPosition(force, hit_point); } else//Server client || npc authoritates laser { if (heat_dmg > 0) { body.damage(activator, force, dmg_physics: CONSTANTS.heat_to_physics(heat_dmg), dmg_thermal: heat_dmg, headshot: false); if (body.isPlayer && !body.hasAuthority)//Non-server client { body.request_bleed(hit_point, angle, false); body.Rpc_add_force(force); } else//Host or npc { body.request_bleed(hit_point, angle, false); body.GetComponent <Rigidbody2D>().AddForceAtPosition(force, hit_point); } } //Friendly fire, just force else { if (body.isPlayer && !body.hasAuthority)//Non-server client { body.Rpc_add_force(force); } else//Host or npc { body.GetComponent <Rigidbody2D>().AddForceAtPosition(force, hit_point); } } } } return(-1); }
public void SubPurchase_checkout() { if (body == null) { //Debug.LogError("Purchases go to no recipant!"); return; } //Host player only send command that will modify on server-side; Client send both cmd and local modification body.GetComponent <Player_controller>().Cmd_buy(cart.ToArray(), s_cart.ToArray()); //if (!body.isServer) //{ // body.upgrade_stat(s_cart.ToArray()); //} }
//This function will detect character collision and calculate damage //Return 1: keep the projectile going //Return 0: this object shouldn't be impacted //Return -1: this projectile is stopped by character public int impact_character(Body_hitbox_generic hit_box, Vector2 hit_point) { Vector2 force = CONSTANTS.DAMAGE_FORCE_MULTIPLIER * aimdir * speed * mass / 2; Body_generic body = hit_box.body; if (body.isPlayer && !body.hasAuthority)//client player { body.Rpc_add_force(force); } else//host player & npc { body.GetComponent <Rigidbody2D>().AddForceAtPosition(force, hit_point); } if (activator.GetComponent <Body_generic>().dmg_tags.Contains(hit_box.tag)) { body.damage(activator, force: force, dmg_physics: Damage(), headshot: false); } return(-1); }
//Server pull trigger public void Pull_trigger(Body_generic body)//AI_generic ai) { if ((ammo <= 0) || (Time.time <= time_to_fire || (body.isPlayer && is_shoot_inside_wall()))) { return; } body.reloading = false; 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; body.bodyRB.AddForce(-get_aim_vec().normalized *recoil *fps_stack); //client_player.shake_screen(shake_extent, transform.rotation.eulerAngles.z+180); /* * if ((ammo <= 0) || (Time.time <= time_to_fire)) * { * return; * } * * * 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(); * * ammo -= 1; * time_to_fire = Time.time + 1 / rate_of_fire; * body.bodyRB.AddForce(-get_aim_vec().normalized * recoil);//ai.GetComponent<Rigidbody2D>().AddForce(-get_aim_vec().normalized * recoil); * body.reloading = false;//ai.reloading = false; */ if (burst_shots == 1) { if (fps_stack <= 1) { short aim_dir_bias = get_bullet_seed_single(aim_angle_float, firecone_angle); //Local shooting shoot(body.gameObject, firepoint_x, firepoint_y, aim_dir_bias, null); //Others shooting if (body.isServer && !Local_precomputation) { server_shoot(body.gameObject, firepoint_x, firepoint_y, aim_dir_bias, null, ammo <= 0); } else if (body.isPlayer && !Local_precomputation) { body.GetComponent <Player_controller>().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, body.aim_suppress, fps_stack); //Local shooting shoot(body.gameObject, firepoint_x, firepoint_y, aim_angle_short, blt_dir); //Others shooting if (body.isServer && !Local_precomputation) { server_shoot(body.gameObject, firepoint_x, firepoint_y, aim_angle_short, blt_dir, ammo <= 0); } else if (!Local_precomputation) { body.GetComponent <Player_controller>().Cmd_request_shoot_optimized(firepoint_x, firepoint_y, aim_angle_short, blt_dir, ammo <= 0); } } /* * short aim_dir_bias = get_bullet_seed_single(get_aim_dir_float(), firecone_angle); * //Local shooting * shoot(ai.gameObject, firepoint_x, firepoint_y, aim_dir_bias, null); * //Others shooting * if (!Local_precomputation) * { * server_shoot(ai.gameObject, firepoint_x, firepoint_y, aim_dir_bias, null, ammo <= 0); * } */ } else if (burst_shots >= 2) { sbyte[] blt_dir = get_bullet_seed(firecone_angle, fps_stack); //Local shooting shoot(body.gameObject, firepoint_x, firepoint_y, aim_angle_short, blt_dir); //Others shooting if (body.isServer && !Local_precomputation) { server_shoot(body.gameObject, firepoint_x, firepoint_y, aim_angle_short, blt_dir, ammo <= 0); } else if (!Local_precomputation) { body.GetComponent <Player_controller>().Cmd_request_shoot_optimized(firepoint_x, firepoint_y, aim_angle_short, blt_dir, ammo <= 0); } /* * sbyte[] blt_dir = get_bullet_seed(firecone_angle); * //Local shooting * shoot(ai.gameObject, firepoint_x, firepoint_y, aim_angle_short, blt_dir); * //Others shooting * if (!Local_precomputation) * { * server_shoot(ai.gameObject, firepoint_x, firepoint_y, aim_angle_short, blt_dir, ammo <= 0); * } */ } //--------------------------------------------------- firecone_angle = Mathf.Clamp(firecone_angle + fps_stack * (body.aim_suppress) * accuracy / bias_factor, 0, accuracy); }