Example #1
0
    public void Hit(HitArguments hit)
    {
        //print("was hit");
        this.GetComponentInChildren <Collider>().isTrigger = true;
        Rigidbody myRigid = this.GetComponent <Rigidbody>();

        GameObject spawn;

        if (gibs)
        {
            spawn = (GameObject)GameObject.Instantiate(gibs, transform.position, transform.rotation);
        }
        else if (transform.childCount == 1)
        {
            // We use the child instead (much faster than creating a new object)
            spawn = transform.GetChild(0).gameObject;
            spawn.transform.parent = null;
            spawn.SetActive(true);
        }
        else
        {
            Debug.LogError("You did not have any gibs assigned! Make a child and disable it, or assign a prefab!");
            return;
        }
        Vector3 myVelocity = myRigid.velocity;

        foreach (Rigidbody r in spawn.GetComponentsInChildren <Rigidbody>())
        {
            r.velocity = myRigid.GetPointVelocity(r.transform.position);
        }
        GameObject.Destroy(this.gameObject);
    }
Example #2
0
 public void AddEffect(HitArguments hit)
 {
     if (hit.effect != Effects.none)
     {
         RpcAddEffect(hit);
     }
 }
Example #3
0
    public void RpcAddEffect(HitArguments hit)
    {
        GameObject eff    = GameObject.Instantiate(effectTypes[(int)hit.effect - 1], transform);
        Effect     effect = eff.GetComponent <Effect> ();

        effect.duration     = hit.effectDuration;
        effect.sourcePlayer = hit.sourcePlayer;
    }
Example #4
0
    public void Hit(HitArguments hit)
    {
        if (hasDeath)
        {
            return;
        }
        if (hit.sourcePlayerTeam != teamIndex || teamIndex == -1)
        {
            if (hit.sourcePlayer.GetComponent <BasePlayer> ())
            {
                int playerId = hit.sourcePlayer.GetComponent <PlayerInput>().GetPlayerId();
                lastHitPlayerId = playerId;
                RpcSetDeathTarget(playerId);
                //myBase.myInput.deathTarget = hit.sourcePlayer.GetComponent<PlayerInput>().deathTargetMe;
            }
            else
            {
                // Hazard
                //lastHitPlayerId = this.GetComponent<PlayerInput> ().GetPlayerId ();
            }
        }
        lastHitTime = Time.time;
        changeHealth(-1 * hit.damage);
        if (hit.effect != PlayerEffects.Effects.none)
        {
            myBase.myEffects.AddEffect(hit);
        }

        // Direction hit animations
        //print(hit.sourcePlayer + " " + hit.hitSameTeam);

        if (myBase == null || myBase.myAnimator == null || ((teamIndex == -1 ? hit.sourcePlayer == this.gameObject : hit.sourcePlayerTeam == teamIndex) && !hit.hitSameTeam) || Time.time - hurtCooldown < 0.1f)
        {
            // Ignore these animations
        }
        else if (hit.sourcePosition.x == 0 && hit.sourcePosition.y == 0)
        {
            // Default to forwards
            RpcHurtDirection(0, -1f);
            hurtCooldown = Time.time;
        }
        else
        {
            Vector3 diffPosition = Vector3.Normalize(transform.InverseTransformPoint(new Vector3(hit.sourcePosition.x, transform.position.y, hit.sourcePosition.y)));
            //print ("Position difference: " + diffPosition);
            //Debug.DrawLine(transform.position, transform.position + new Vector3(hit.sourcePosition.x, 0, hit.sourcePosition.y), Color.blue, 10f);
            RpcHurtDirection(diffPosition.x, diffPosition.z * -1);
            hurtCooldown = Time.time;
        }
    }
Example #5
0
    public static void HitClientside(HitVerificationMethod verificationMethod, HitArguments args)
    {
        PlayerStats myPlayerStats = args.sourcePlayer.GetComponent <PlayerStats>();

        //NetworkBehaviour targetBehavior;
        if ((/*targetBehavior = */ args.target.GetComponentInParent <NetworkBehaviour>()))
        {
            if (myPlayerStats.isLocalPlayer)
            {
                // Call network event through server
                myPlayerStats.CmdApplyDamage(verificationMethod, args);
            }
        }
        else
        {
            // This is an object that may or may not exist on all clients, so we will handle collision locally
            args.target.GetComponentInParent <IHittable>().Hit(args);
        }
    }
Example #6
0
    public void CmdApplyDamage(HitManager.HitVerificationMethod ver, HitArguments hit)
    {
        //print("applying damage");
        PlayerStats targetStats;

        if (hit.sourcePlayerTeam != -1 && (targetStats = hit.target.GetComponentInParent <PlayerStats>()))
        {
            if (targetStats.teamIndex == this.teamIndex && !hit.hitSameTeam)
            {
                Debug.LogWarning("Same team, not registering hit on target " + hit.target);
                return;
            }
        }
        if (HitManager.VerifyHit(ver, hit) && hit.target != null && hit.target.GetComponentInParent <IHittable>() != null)
        {
            hit.target.GetComponentInParent <IHittable>().Hit(hit);
            if (hit.target.GetComponentInParent <PlayerStats>() && hit.target != this.gameObject)
            {
                RpcConfirmHit(hit.damage);
            }
        }
    }
Example #7
0
    public static bool VerifyHit(HitVerificationMethod verificationMethod, HitArguments args)
    {
        bool verified = false;

        switch (verificationMethod)
        {
        case HitVerificationMethod.none:
            verified = true;
            break;

        case HitVerificationMethod.melee:
            verified = true;
            break;

        case HitVerificationMethod.projectile:
            verified = true;

            break;

        case HitVerificationMethod.hitscan:
            verified = true;

            break;

        default:
            break;
        }
        if (verified)
        {
            // Apply damage
            return(true);
        }
        else
        {
            /* consider kicking the violator */
            return(false);
        }
    }
Example #8
0
 public static void HitClientside(HitArguments args)
 {
     HitClientside(HitVerificationMethod.none, args);
 }