Esempio n. 1
0
    //This function will detect object collision
    //projectile will stop no matter what
    public void impact_object(GameObject obj, Vector2 hit_point)
    {
        float heat = Damage();

        if (obj.tag == "structure")//Structure
        {
            if (local && heat > 0)
            {
                Body_generic activator_body = activator.GetComponent <Body_generic>();
                if (activator_body.dmg_tags.Contains(obj.tag) && activator.layer != obj.layer)
                {
                    float angle = Mathf.Atan2(aimdir.y, aimdir.x) * 180 / Mathf.PI;
                    //If Client authoritates laser
                    if (activator_body.isPlayer && !activator_body.isServer)
                    {
                        activator_body.player_controller.add_to_shot_list(obj, heat, hit_point, 0, CONSTANTS.seed_float_to_short(angle, 360), false, 1);
                    }
                    else//Server client || npc authoritates laser
                    {
                        obj.GetComponent <Structure_generic>().health -= CONSTANTS.heat_to_physics(heat);
                    }
                    if (activator_body.isLocalPlayer)
                    {
                        activator_body.player_controller.hit_mark();
                    }
                }
            }
        }
        if (obj.GetComponent <Rigidbody2D>() != null)
        {
            Vector2 force = CONSTANTS.DAMAGE_FORCE_MULTIPLIER * (end - start).normalized * heat / 20;
            obj.GetComponent <Rigidbody2D>().AddForceAtPosition(force, hit_point);
        }
    }
Esempio n. 2
0
    //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);
    }