void OnCollisionEnter2D(Collision2D col)
 {
     if (playerInCar == true && rb.velocity.magnitude > 1)
     {
         //Debug.Log ("CAR COLLIDED WITH " + col.gameObject.name);
         if (col.gameObject.GetComponent <NPCController> () == true)
         {
             NPCController npc = col.gameObject.GetComponent <NPCController> ();
             npc.knockOutNPC();
             //Debug.Log ("Dealt " + Mathf.RoundToInt (100 * rb.velocity.magnitude).ToString () + " Damage to NPC");
             npc.myHealth.dealDamage(Mathf.RoundToInt(100 * rb.velocity.magnitude), true);
         }
         else if (col.gameObject.GetComponent <DoorScript> () == true)
         {
             DoorScript ds = col.gameObject.GetComponent <DoorScript> ();
             ds.largeImpactOnDoor(100);
         }
         else if (col.gameObject.transform.parent != null && col.gameObject.transform.parent.GetComponent <WindowNew> () == true)
         {
             WindowNew wn = col.gameObject.transform.parent.GetComponent <WindowNew> ();
             wn.destroyWindow();
         }
         dealDamage(100);
     }
 }
示例#2
0
    void newMeleeDealDamage(GameObject g)
    {
        if (g.tag == this.gameObject.tag)
        {
            //Debug.Log ("hit freindly, returning");
            return;
        }


        if (currentWeapon == null)
        {
            //foreach (GameObject g in objectsRayHitInSwing) {
            PersonHealth ph = g.GetComponent <PersonHealth> ();
            if (ph == null)
            {
                if (g.tag == "Door")
                {
                    //Debug.Log ("Melee hit " + g.gameObject.name);
                    DoorScript ds = g.GetComponent <DoorScript> ();
                    if (ds == null)
                    {
                        if (g.transform.parent == null)
                        {
                            //Debug.Log ("Could not find door script in parent");
                        }
                        else
                        {
                            ds = g.transform.root.gameObject.GetComponent <DoorScript> ();
                        }
                    }


                    if (ds == null)
                    {
                        //Debug.Log ("Could not find door script");
                    }
                    else
                    {
                        ds.kickInDoor();
                    }
                    ////////Debug.Log ("Door " + ds.gameObject + " kicked in");
                    return;
                }
                else if (g.tag == "Window")
                {
                    Window w = g.GetComponent <Window> ();
                    //Debug.Log (g.name);
                    if (w == null)
                    {
                    }
                    else
                    {
                        w.smashWindow();
                    }

                    WindowNew w2 = g.GetComponentInParent <WindowNew> ();
                    if (w2 == null)
                    {
                    }
                    else
                    {
                        w2.destroyWindow();
                    }

                    return;
                }
                else if (g == this.gameObject)
                {
                    return;
                }
                else
                {
                }
            }
            else
            {
                if (g == this.gameObject || ph.healthValue <= 0)
                {
                    return;
                }

                if (g.tag != "Player")
                {
                    Inventory i = ph.gameObject.GetComponent <Inventory> ();
                    if (i.leftArm == null)
                    {
                    }
                    else
                    {
                        Item toDrop = i.leftArm;
                        i.unequipItem(toDrop);

                        i.dropItem(toDrop);
                    }

                    if (i.rightArm == null)
                    {
                    }
                    else
                    {
                        Item toDrop = i.rightArm;
                        i.unequipItem(toDrop);

                        i.dropItem(toDrop);
                    }
                }
                NPCController npc = g.GetComponent <NPCController> ();
                if (npc == null)
                {
                    ph.gameObject.GetComponent <BleedingEffect> ().bloodImpact(g.transform.position, Quaternion.Euler(0, 0, this.transform.eulerAngles.z - 90));

                    //bool inFront = detect.isTargetInFrontOfUs (this.gameObject);
                    ph.dealMeleeDamage(500, false);
                    punchNoise();
                }
                else
                {
                    ph.gameObject.GetComponent <BleedingEffect> ().bloodImpact(g.transform.position, Quaternion.Euler(0, 0, this.transform.eulerAngles.z - 90));

                    CanWeDetectTarget detect = g.GetComponent <CanWeDetectTarget> ();
                    //bool inFront = detect.isTargetInFrontOfUs (this.gameObject);
                    ph.dealMeleeDamage(500, false);
                    punchNoise();
                    if (ph.healthValue > 0)
                    {
                        if (isTargetFacingAway(npc.gameObject))
                        {
                            npc.knockOutNPC();
                        }
                        ph.setAttacked(this.gameObject);
                        npc.stunTimer = 3.0f;
                        ////////Debug.Break ();
                    }

                    //if (inFront == true) {
                    if (this.gameObject.tag == "Player")                      //TODO may need to rewrite this in the far future
                    {
                        npc.memory.peopleThatHaveAttackedMe.Add(this.gameObject);
                    }

                    //}
                    if (g.tag == "NPC")
                    {
                        npc.memory.objectThatMadeMeSuspisious = this.gameObject;
                        npc.npcB.onHostageRelease();
                    }
                }
            }
        }
        else
        {
            PersonHealth ph = g.GetComponent <PersonHealth> ();
            if (ph == null)
            {
                if (g.tag == "Door")
                {
                    //Debug.Log ("Melee hit " + g.gameObject.name);
                    DoorScript ds = g.GetComponent <DoorScript> ();
                    if (ds == null)
                    {
                        if (g.transform.parent == null)
                        {
                            //Debug.Log ("Could not find door script in parent");
                        }
                        else
                        {
                            ds = g.transform.root.gameObject.GetComponent <DoorScript> ();
                        }
                    }


                    if (ds == null)
                    {
                        //Debug.Log ("Could not find door script");
                    }
                    else
                    {
                        ds.kickInDoor();
                    }
                    ////////Debug.Log ("Door " + ds.gameObject + " kicked in");
                    return;
                }
                else if (g.tag == "Window")
                {
                    Window w = g.GetComponent <Window> ();
                    //Debug.Log (g.name);
                    if (w == null)
                    {
                    }
                    else
                    {
                        w.smashWindow();
                    }

                    WindowNew w2 = g.GetComponentInParent <WindowNew>();
                    if (w2 == null)
                    {
                    }
                    else
                    {
                        w2.destroyWindow();
                    }

                    return;
                }
                else if (g.GetComponent <PlayerCarController> () == true)
                {
                    g.GetComponent <PlayerCarController> ().dealDamage(500);
                    return;
                }
                else if (g == this.gameObject)
                {
                    return;
                }
            }
            else
            {
                if (g == this.gameObject || ph.healthValue <= 0)
                {
                    return;
                }

                NPCController npc = g.GetComponent <NPCController> ();
                if (npc == null)
                {
                    ph.gameObject.GetComponent <BleedingEffect> ().bloodImpact(g.transform.position, Quaternion.Euler(0, 0, this.transform.eulerAngles.z - 90));

                    //bool inFront = detect.isTargetInFrontOfUs (this.gameObject);
                    ph.dealMeleeDamage(currentWeapon.meleeDamage, currentWeapon.bladed);
                    punchNoise();
                }
                else
                {
                    ph.gameObject.GetComponent <BleedingEffect> ().bloodImpact(g.transform.position, Quaternion.Euler(0, 0, this.transform.eulerAngles.z - 90));

                    CanWeDetectTarget detect = g.GetComponent <CanWeDetectTarget> ();
                    //bool inFront = detect.isTargetInFrontOfUs (this.gameObject);
                    ph.dealMeleeDamage(currentWeapon.meleeDamage, currentWeapon.bladed);
                    punchNoise();
                    if (ph.healthValue > 0)
                    {
                        if (currentWeapon.bladed == false && isTargetFacingAway(npc.gameObject))
                        {
                            npc.knockOutNPC();
                        }
                        ph.setAttacked(this.gameObject);

                        ////////Debug.Break ();
                    }

                    //if (inFront == true) {
                    if (this.gameObject.tag == "Player")                      //TODO may need to rewrite this in the far future
                    {
                        npc.memory.peopleThatHaveAttackedMe.Add(this.gameObject);
                    }

                    //}
                    if (g.tag == "NPC")
                    {
                        npc.memory.objectThatMadeMeSuspisious = this.gameObject;
                        npc.npcB.onHostageRelease();
                    }
                }
                //if (g != this.gameObject) {
                //	ph.dealMeleeDamage (100, false);
                //}
            }
        }
    }
示例#3
0
    void OnCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject == null)
        {
        }
        else
        {
            if (col.gameObject.tag == "Door")
            {
                DoorScript ds = col.gameObject.GetComponent <DoorScript> ();
                if (ds == null)
                {
                }
                else
                {
                    ds.kickInDoor();
                    Instantiate(CommonObjectsStore.me.bulletImpact, this.transform.position - (transform.up / 4), this.transform.rotation);
                    Destroy(this.gameObject);
                }
                //if (ds.wayIAmLocked == lockedWith.none || ds.wayIAmLocked == lockedWith.key) {
                //	ds.locked = false;
                //	ds.interactWithDoor (this.gameObject);
                //}
            }
            else if (col.gameObject.tag == "Window")
            {
                Window w = col.gameObject.GetComponent <Window> ();
                if (w == null)
                {
                }
                else
                {
                    w.smashWindow();
                    return;
                }

                WindowNew w2 = col.gameObject.GetComponentInParent <WindowNew> ();
                if (w2 == null)
                {
                }
                else
                {
                    w2.destroyWindow();
                }
            }
            else if (col.gameObject.GetComponent <PlayerCarController> () == true)
            {
                col.gameObject.GetComponent <PlayerCarController> ().dealDamage(damage);

                if (col.gameObject.GetComponent <SpawnCopsOnCall> () == true)
                {
                    col.gameObject.GetComponent <SpawnCopsOnCall> ().spawnCops();
                    if (PoliceController.me.copsCalled == false)
                    {
                        PoliceController.me.copsCalled = true;
                    }
                }
            }

            if (col.gameObject.tag != "Bullet")
            {
                if (col.gameObject.tag == "NPC" && isAiBullet == false || col.gameObject.tag == "Player" && isAiBullet == true)
                {
                    Instantiate(CommonObjectsStore.me.bloodImpact, this.transform.position - (transform.up / 4), this.transform.rotation);
                }

                if (col.transform.root.tag != "Player" && col.transform.root.tag != "NPC")
                {
                    Instantiate(CommonObjectsStore.me.bulletImpact, this.transform.position - (transform.up / 4), this.transform.rotation);
                }

                Destroy(this.gameObject);
            }
        }
    }