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); } }
public void createIncidentReaction(int min, int hour, int day, int month, int year, Vector3 pos) { DateTimeStore date = new DateTimeStore(); date.min = min; date.hour = hour; date.day = day; date.month = month; date.year = year; if (shouldWeReactToIncident(date) == true) { LevelIncidentController.me.reAddIncident(incidentName, pos, date); GameObject g = getRelevantGameObject(pos); GameObject toCreate = getObjectToCreate(); GameObject obj = null; if (toCreate != null) { obj = (GameObject)Instantiate(toCreate, g.transform.position, Quaternion.Euler(0, 0, g.transform.rotation.eulerAngles.z)); //create the stuff, find area for misc objects } if (incidentName == "Window") { obj.GetComponent <DoorScript> ().doorOpenSpeed = 0.0f; obj.GetComponent <DoorScript> ().doorSoundEffect = null; if (objectToCreate == null) { } else { createObject(pos); } } else if (incidentName == "FireExit" || incidentName == "GlassDoor" || incidentName == "WoodDoor") { DoorScript ds = obj.GetComponent <DoorScript> (); ds.doorOpenSpeed /= 2; if (objectToCreate == null) { } else { createObject(pos); } } else if (incidentName == "Robbery") { RoomScript r = LevelController.me.getRoomPosIsIn(pos); LightSource[] lights = FindObjectsOfType <LightSource>(); if (r == null) { foreach (GameObject g2 in optionalObjectsToCreate) { int r2 = Random.Range(0, 6); for (int x2 = 0; x2 < r2; x2++) { Vector3 pos2 = pos + new Vector3(Random.Range(-5, 5), Random.Range(-5, 5), 0); Instantiate(g2, pos2, Quaternion.Euler(0, 0, Random.Range(0.0f, 1.0f))); } } foreach (LightSource l in lights) { if (Vector2.Distance(l.transform.position, pos) < 15.0f) { l.lightOn = false; } } } else { foreach (roomRect r3 in r.rectsInRoom) { float blx = r3.bottomLeft.transform.position.x; float bly = r3.bottomLeft.transform.position.y; float trx = r3.topRight.transform.position.x; float trY = r3.topRight.transform.position.y; foreach (GameObject g2 in optionalObjectsToCreate) { int r2 = Random.Range(0, 6); for (int x2 = 0; x2 < r2; x2++) { Vector3 pos2 = new Vector3(Random.Range(blx, trx), Random.Range(bly, trY), 0); Instantiate(g2, pos2, Quaternion.Euler(0, 0, Random.Range(0.0f, 1.0f))); } } } foreach (LightSource l in lights) { RoomScript lr = LevelController.me.getRoomPosIsIn(l.transform.position); if (lr == r) { l.lightOn = false; } } } if (objectToCreate == null) { } else { createObject(pos); } } else if (incidentName == "Fire") { BuildingScript b = LevelController.me.getBuildingPosIsIn(pos); if (b == null) { } else { b.buildingClosed = true; } int r = Random.Range(3, 8); for (int x = 0; x < r; x++) { Vector3 pos2 = pos + new Vector3(Random.Range(-5, 5), Random.Range(-5, 5), 0); Instantiate(objectToCreate, pos2, Quaternion.Euler(0, 0, 0)); } if (TimeScript.me.howManyHoursHavePassed(hour, day, month, year) > 72) { foreach (GameObject g2 in optionalObjectsToCreate) { int chance = Random.Range(0, 100); if (chance < 5) { Vector3 pos2 = pos + new Vector3(Random.Range(-5, 5), Random.Range(-5, 5), 0); // Instantiate(g2, pos, Quaternion.Euler(0, 0, 0)); createObject(g, pos2); } } } } else if (incidentName == "Murder") { Instantiate(objectToCreate, pos, Quaternion.Euler(0, 0, Random.Range(0.0f, 1.0f))); BuildingScript b = LevelController.me.getBuildingPosIsIn(pos); if (b == null) { } else { b.buildingClosed = true; } } } else { //destoy save date relating to incident and the destroyed stuff is reset. if (incidentName == "Window") { GameObject g = getRelevantGameObject(pos); WindowNew wn = g.GetComponent <WindowNew> (); //stop it displaying the smashed window //re enable window script, mesh and collider wn.window.SetActive(true); wn.destroyed.SetActive(false); wn.windowDestroyed = false; wn.windowClosedCol.SetActive(true); wn.initilised = false; wn.callStart(); } else if (incidentName == "FireExit" || incidentName == "GlassDoor" || incidentName == "WoodDoor") { GameObject g = getRelevantGameObject(pos); DoorScript ds = g.GetComponent <DoorScript> (); ds.enabled = true; ds.doorMesh.SetActive(true); Destroy(g.GetComponent <SpriteRenderer> ()); ds.doorHealth = 5; Shadow s = g.GetComponent <Shadow> (); g.GetComponent <BoxCollider2D> ().enabled = true; foreach (GameObject gs in s.myShadows) { Destroy(gs.gameObject); } Destroy(s); ds.setDoorActions(); } } }
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); //} } } }
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); } } }