Exemplo n.º 1
0
 public virtual void OnTriggerEnter2D(Collider2D collision)
 {
     /*if (collisionTag != "" && collisionTag != null)
      * {*/
     foreach (string collisionTag in collisionTags)
     {
         if (collision.gameObject.CompareTag(collisionTag) && collision.isTrigger)
         {
             //     print(collision.name);
             GenericHealth temp = collision.GetComponent <GenericHealth>();
             if (temp)
             {
                 //print(temp.currentHealth);
                 if (statistics == null || !(statistics is Atacking))
                 {
                     temp.Damage(damage);
                     //print(damage);
                 }
                 else
                 {
                     Atacking atacking = (Atacking)statistics;
                     temp.Damage(atacking.GetAttack());
                     //print(atacking.GetAttack());
                 }
                 //print(damage);
                 //print(temp.currentHealth);
             }
         }
     }
 }
Exemplo n.º 2
0
 void OnTriggerEnter(Collider other)
 {
     if (canExplose)
     {
         if (layerMask.ContainsLayer(other.gameObject.layer))
         {
             Debug.Log("Detect");
             if (impactEffect)
             {
                 GameObject goEffect = Instantiate(impactEffect, transform.position, Quaternion.identity);
                 Destroy(goEffect, 2f);
                 Collider[] hitColliders = Physics.OverlapSphere(transform.position, exploseRadius, layerMask);
                 foreach (Collider col in hitColliders)
                 {
                     GenericHealth health = col.gameObject.GetComponent <GenericHealth>();
                     if (health && dealDamages)
                     {
                         //Debug.Log( col.gameObject.name + Damages);
                         health.TakeDamage(damages, this.gameObject);
                     }
                 }
                 Destroy(gameObject, .1f);
             }
         }
     }
 }
Exemplo n.º 3
0
    public void init()
    {
        pos          = Map.grid.grid_to_world(Map.grid.world_to_grid(transform.position));
        current_node = Map.grid.get_node(Map.grid.world_to_grid(pos));

        controller = GetComponent <PlatformCollision>();
        controller.init();
        player_movement = GetComponent <PlayerMovement>();
        player_movement.init();

        Transform weapon_obj = transform.parent.FindChild("weapon");

        if (weapon_obj == null)
        {
            Debug.LogError("'weapon' object cannot be found in player parent's children");
        }
        weapon_inventory = weapon_obj.GetComponent <WeaponInventory>();
        weapon_inventory.init(this);
        weapon_control = weapon_obj.GetComponent <PlayerWeaponControl>();
        weapon_control.init();

        grappling_hook = GetComponent <GrapplingHook>();
        grappling_hook.init();
        health = GetComponent <GenericHealth>();
        health.init(this);
    }
Exemplo n.º 4
0
    void CmdFire()
    {
        RaycastHit hit;

        if (Physics.Raycast(PlayerCamera.transform.position, PlayerCamera.transform.forward, out hit))
        {
            Debug.Log(hit.transform.name);

            //damage anything with this script on it
            GenericHealth damage = hit.transform.GetComponent <GenericHealth> ();

            //Damage other players
            Health cause = hit.transform.GetComponent <Health> ();

            if (damage != null)
            {
                damage.Damaged();
            }

            if (cause != null)
            {
                cause.TakeDamage(5);
            }
        }

        GameObject Bullet = Instantiate(HitAffect, hit.point, Quaternion.LookRotation(hit.normal));

        NetworkServer.Spawn(Bullet);
        Destroy(Bullet, 2.0f);
    }
Exemplo n.º 5
0
    public virtual void Start()
    {
        mySprite = GetComponent <SpriteRenderer>();

        health       = GetComponentInChildren <GenericHealth>();
        currentState = EnemyState.idle;
        thisLoot     = enemyStatistics.lootTable;
    }
Exemplo n.º 6
0
 protected override void Start()
 {
     base.Start();
     ghoustBasic      = gameObject.transform.parent.GetComponentInChildren <GhoustBasic>();
     deathEffect      = ghoustBasic.deathEffect;
     deathEffectDelay = ghoustBasic.deathEffectDelay;
     genericHealth    = transform.parent.transform.Find("Health").GetComponent <GenericHealth>();
 }
Exemplo n.º 7
0
    void OnTriggerEnter(Collider collision)
    {
        GenericHealth health = collision.gameObject.GetComponent <GenericHealth>();

        if (health)
        {
            health.TakeDamage(enemyAttack.attackDamages, gameObject);
        }
    }
Exemplo n.º 8
0
    public override void OnTriggerEnter2D(Collider2D collision)
    {
        base.OnTriggerEnter2D(collision);
        GenericHealth temp = collision.GetComponent <GenericHealth>();

        if (temp)
        {
            //  StartCoroutine(CoStag());
        }
    }
 public void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.CompareTag(_otherTag) && other.isTrigger)
     {
         GenericHealth component = other.GetComponent <GenericHealth>();
         if (component)
         {
             component.Damage(_damage);
         }
     }
 }
Exemplo n.º 10
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.CompareTag(otherTag) && collision.isTrigger)
     {
         GenericHealth temp = collision.gameObject.GetComponent <GenericHealth>();
         if (temp)
         {
             temp.Damage(damage);
         }
     }
 }
Exemplo n.º 11
0
 public void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.CompareTag(otherTag) && other.isTrigger)
     {
         GenericHealth temp = other.GetComponent <GenericHealth>();
         if (temp)
         {
             temp.Damage(damage);
         }
     }
 }
Exemplo n.º 12
0
    //public Resorce res;
    public override void OnTriggerEnter2D(Collider2D collision)
    {
        foreach (string collisionTag in collisionTags)
        {
            if (collision.gameObject.CompareTag(collisionTag) && collision.isTrigger)
            {
                GenericHealth temp = collision.GetComponent <GenericHealth>();
                if (temp)
                {
                    //print(temp.currentHealth);

                    switch (collisionTag)
                    {
                    case "Stone":
                        if (statistics == null || !(statistics is PlayerStatistics))
                        {
                            temp.Damage(damage);
                            gui.ModifyStone(1);
                            //print(damage);
                        }
                        else
                        {
                            PlayerStatistics player = (PlayerStatistics)statistics;
                            temp.Damage(player.stoneDamage.Value);
                            gui.ModifyStone((int)player.stoneGetting.Value);
                            //  print(player.stoneDamage.Value);
                        }

                        break;

                    case "Tree":
                        if (statistics == null || !(statistics is PlayerStatistics))
                        {
                            temp.Damage(damage);
                            gui.ModifyWood(1);
                            //print(damage);
                        }
                        else
                        {
                            PlayerStatistics player = (PlayerStatistics)statistics;
                            temp.Damage(player.woodDamage.Value);
                            gui.ModifyWood((int)player.woodGetting.Value);
                            // print(player.woodDamage.Value);
                        }

                        break;

                    default:
                        break;
                    }
                }
            }
        }
    }
Exemplo n.º 13
0
    void Start()
    {
        planks = planksParent.GetComponentsInChildren <Transform>().ToList();
        planks.Remove(planksParent);
        doorHealth         = gameObject.GetComponent <GenericHealth>();
        lifePointsPerPlank = (float)doorHealth.maxHealth / planks.Count;

        for (int i = 0; i < planks.Count; i++)
        {
            planks[i].gameObject.SetActive(true);
        }
    }
Exemplo n.º 14
0
        private void OnCollisionEnter2D(Collision2D col)
        {
            if (CollidingLayers.is_layer_in_mask(col.gameObject.layer, colliders))
            {
                GenericHealth health = col.gameObject.GetComponent <GenericHealth>();
                if (health != null)
                {
                    health.take_damage(damage);
                }

                destroy_all();
            }
        }
Exemplo n.º 15
0
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.CompareTag(otherString))
     {
         //Check if there is health
         GenericHealth temp = other.gameObject.GetComponent <GenericHealth>();
         if (temp)
         {
             temp.Damage(damage);
         }
         Destroy(this.gameObject);
     }
 }
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.CompareTag(otherString))
     {
         // First check to see if there is health
         GenericHealth temp = other.gameObject.GetComponent <GenericHealth>();
         if (temp)
         {
             temp.Damage(damage);
         }
         this.transform.gameObject.SetActive(false);
         //this.transform.parent.gameObject.SetActive(false);
         // Destroy(this.gameObject);
     }
 }
Exemplo n.º 17
0
        private void explode()
        {
            Collider2D[] cols = Physics2D.OverlapCircleAll(transform.position, explosion_radius, explode_layers);
            foreach (Collider2D col in cols)
            {
                GenericHealth health = col.gameObject.GetComponent <GenericHealth>();
                if (health != null)
                {
                    Instantiate((GameObject)Resources.Load("particles/explosion"),
                                new Vector3(transform.position.x, transform.position.y, -20), Quaternion.identity);

                    float dist = Vector2.Distance(col.transform.position, transform.position);
                    dist = Mathf.Min(dist, explosion_radius);
                    float damage = ((explosion_radius - dist) / explosion_radius) * max_damage;
                    health.take_damage(damage);
                }
            }
        }
Exemplo n.º 18
0
    private void Start()
    {
        //make sure the enemy contains at least one ai logic
        if (GetComponents<AILogicBase>().Length == 0)
        {
            Debug.LogError("No AILogicBase component can be found on enemy gameobject (" + name + ")");
        }

        Transform weapon_obj = transform.parent.FindChild("weapon");
        if (weapon_obj == null) Debug.LogError("'weapon' object cannot be found in enemy parent's children");
        weapon_inventory = weapon_obj.GetComponent<WeaponInventory>();
        weapon_inventory.init(this);
        weapon_control = weapon_obj.GetComponent<EnemyWeaponControl>();
        weapon_control.init(this);

        health = GetComponent<GenericHealth>();
        health.init(this);
    }
Exemplo n.º 19
0
    public void init()
    {
        pos = Map.grid.grid_to_world(Map.grid.world_to_grid(transform.position));
        current_node = Map.grid.get_node(Map.grid.world_to_grid(pos));

        controller = GetComponent<Controller2D>();
        controller.init();
        player_movement = GetComponent<PlayerMovement>();
        player_movement.init();

        Transform weapon_obj = transform.parent.FindChild("weapon_base");
        if (weapon_obj == null) Debug.LogError("'weapon_base' object cannot be found in player parent's children");
        inventory = weapon_obj.GetComponent<WeaponInventory>();
        inventory.init(this);
        weapon_control = weapon_obj.GetComponent<PlayerWeaponControl>();
        weapon_control.init();

        grappling_hook = GetComponent<GrapplingHook>();
        grappling_hook.init();
        health = GetComponent<GenericHealth>();
        health.init(this);
    }
Exemplo n.º 20
0
    private void Start()
    {
        //make sure the enemy contains at least one ai logic
        if (GetComponents <AILogicBase>().Length == 0)
        {
            Debug.LogError("No AILogicBase component can be found on enemy gameobject (" + name + ")");
        }

        Transform weapon_obj = transform.parent.FindChild("weapon");

        if (weapon_obj == null)
        {
            Debug.LogError("'weapon' object cannot be found in enemy parent's children");
        }
        weapon_inventory = weapon_obj.GetComponent <WeaponInventory>();
        weapon_inventory.init(this);
        weapon_control = weapon_obj.GetComponent <EnemyWeaponControl>();
        weapon_control.init(this);

        health = GetComponent <GenericHealth>();
        health.init(this);
    }
Exemplo n.º 21
0
    void OnCollisionEnter(Collision collider)
    {
        if (collisionMask.ContainsLayer(collider.gameObject.layer))
        {
            Vector3 impactPosition = transform.position;
            if (impactEffect)
            {
                if (impactOnFloor)
                {
                    impactPosition.y = collider.transform.position.y; //TODO Improve height calculation
                }
                GameObject goEffect = Instantiate(impactEffect, impactPosition, Quaternion.identity);
                Destroy(goEffect, 2f);
            }
            if (exploseProjetcile)
            {
                Collider[] hitColliders = Physics.OverlapSphere(impactPosition, exploseRadius, collisionMask);
                foreach (Collider col in hitColliders)
                {
                    GenericHealth health = col.gameObject.GetComponent <GenericHealth>();
                    if (health && dealDamages)
                    {
                        //Debug.Log( col.gameObject.name + Damages);
                        health.TakeDamage(damages, this.gameObject);
                    }
                }
                Destroy(gameObject, .1f);
            }

            GenericHealth genericHealth = collider.gameObject.GetComponent <GenericHealth>();
            if (genericHealth && dealDamages)
            {
                genericHealth.TakeDamage(damages, this.gameObject);
                Destroy(gameObject);
            }
        }
    }
Exemplo n.º 22
0
        public void init(float angle, float damage, float max_distance, LayerMask colliders)
        {
            this.angle        = angle;
            this.damage       = damage;
            this.max_distance = max_distance;
            this.colliders    = colliders;

            RaycastHit2D hit = Physics2D.Raycast(transform.position, new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)),
                                                 max_distance, colliders);
            float dist          = hit.transform == null ? max_distance : hit.distance;
            float num_particles = dist / PARTICLE_SEP;

            Vector3 pos = transform.position;

            pos.z = -20;
            GameObject railgun_particle = (GameObject)Resources.Load("particles/railgun_lightning");

            for (int n = 0; n < num_particles; ++n)
            {
                pos.x += Mathf.Cos(angle) * PARTICLE_SEP;
                pos.y += Mathf.Sin(angle) * PARTICLE_SEP;
                GameObject obj = (GameObject)Instantiate(railgun_particle, pos, Quaternion.identity);

                //check if any colliders are overlapping with a circle raycast
                Collider2D col = Physics2D.OverlapCircle(pos, PARTICLE_SEP, colliders);
                if (col)
                {
                    //if the gameobject has a health component, deal damage to them
                    GenericHealth health = col.gameObject.GetComponent <GenericHealth>();
                    if (health != null)
                    {
                        health.take_damage(damage);
                    }
                }
            }
        }
Exemplo n.º 23
0
 // Start is called before the first frame update
 void Start()
 {
     health       = spriteZoneObject.GetComponent <GenericHealth>();
     spriteInZone = spriteZoneObject.GetComponent <Light2D>();
     lightInZone  = lightInZoneObject.GetComponent <Light2D>();
 }
Exemplo n.º 24
0
 void Start()
 {
     health = gameObject.GetComponent <GenericHealth>();
 }
Exemplo n.º 25
0
 // Start is called before the first frame update
 void Start()
 {
     target      = GameObject.FindGameObjectWithTag("house").transform;
     rigidbody2D = gameObject.GetComponent <Rigidbody2D>();
     healt       = gameObject.transform.Find("Health").GetComponent <GenericHealth>();
 }
Exemplo n.º 26
0
 private void Start()
 {
     connectedFence = GetComponentInParent <GenericHealth>();
 }
Exemplo n.º 27
0
    public override void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag != "Untagged")
        {
            if (other.gameObject.CompareTag(otherTag) && other.isTrigger)
            {
                GenericHealth temp = other.GetComponent <GenericHealth>();

                if (temp)
                {
                    bool isCritical = false;

                    if (tech.category == TechCategory.Physical)
                    {
                        float powerTemp = powerValue(tech, tech.power);
                        // Debug.Log(tech.power + " : " + powerTemp);
                        DamageCalc(thisMonster.GetComponent <MonsterStats>().currentLevel.RuntimeValue,
                                   tech.techType, powerTemp, thisMonster.GetComponentInParent <MonsterStats>().AttackStat,
                                   other.GetComponentInParent <MonsterStats>().DefenceStat);

                        float multiplier = moveEffectiveness(tech, other);
                        float final      = multiplier * damage;
                        final = Random.Range(final * 0.9f, final * 1.1f);
                        temp.Damage((int)final);
                        //Debug.Log("Damage: " + (int)final);
                        DamagePopup.Create(other.transform.position, (int)final, isCritical);
                    }
                    else if (tech.category == TechCategory.Magical)
                    {
                        float powerTemp = powerValue(tech, tech.power);
                        // Debug.Log(tech.power + " : " + powerTemp);
                        DamageCalc(thisMonster.GetComponent <MonsterStats>().currentLevel.RuntimeValue,
                                   tech.techType,
                                   powerTemp, thisMonster.GetComponentInParent <MonsterStats>().MagicStat,
                                   other.GetComponentInParent <MonsterStats>().WillpowerStat);

                        float multiplier = moveEffectiveness(tech, other);
                        float final      = multiplier * damage;
                        final = Random.Range(final * 0.9f, final * 1.1f);
                        temp.Damage((int)final);
                        //  Debug.Log("Damage: " + (int)final);
                        DamagePopup.Create(other.transform.position, (int)final, isCritical);
                    }

                    float powerValue(GenericTech tech, float power)
                    {
                        if (tech.techType != MonsterType.Neutral)
                        {
                            if (tech.techType == thisMonster.GetComponent <MonsterStats>().thisMonster.type1 ||
                                tech.techType == thisMonster.GetComponent <MonsterStats>().thisMonster.type2)
                            {
                                power = power * 1.5f;
                            }
                        }
                        return(power);
                    }

                    float moveEffectiveness(GenericTech tech, Collider2D otherMon)
                    {
                        float result = MonsterData.TypeEffectiveness[tech.techType.ToString()]
                                       [other.GetComponentInParent <MonsterStats>().thisMonster.type1.ToString()];

                        if (other.GetComponentInParent <MonsterStats>().thisMonster.type2.ToString() != "Neutral")
                        {
                            result *= MonsterData.TypeEffectiveness[tech.techType.ToString()]
                                      [other.GetComponentInParent <MonsterStats>().thisMonster.type2.ToString()];
                        }
                        return(result);
                    }
                }
            }
        }
    }