Exemplo n.º 1
0
    public void Shoot(Shooter p_shooter, Vector2 p_target, Vector2 p_direction)
    {
        m_shot      = true;
        m_start     = transform.position;
        m_target    = p_target;
        m_direction = p_direction;
        m_shooter   = p_shooter;

        if (m_info.m_faceAtTarget)
        {
            transform.rotation = Quaternion.AngleAxis(Mathf.Atan2(m_direction.y, m_direction.x) * Mathf.Rad2Deg + m_info.m_spriteRotation, Vector3.forward);
        }

        CollisionRelay relay = m_shooter.m_entity.m_collisionRelay;

        if (relay)
        {
            Physics2D.IgnoreCollision(GetComponent <BoxCollider2D>(), relay.GetComponent <BoxCollider2D>());
        }

        gameObject.SetActive(true);
        m_info.m_fireAudioEvent.Play(p_shooter.m_entity.m_audioSource);

        m_behaviourManager.Init(this);
        Game.m_projPool.AddProjectileToJob(this);
    }
Exemplo n.º 2
0
    void OnCollisionEnter2D(Collision2D p_collision)
    {
        Collider2D collider = p_collision.collider;

        bool hitEntity = false;

        if (collider.gameObject != gameObject)
        {
            CollisionRelay relay = collider.GetComponent <CollisionRelay>();

            if (relay != null && m_shooter != null && relay.m_entity.tag != m_shooter.tag)
            {
                m_shooter.Damage(this, relay.m_entity);

                hitEntity = true;
            }
        }

        if (m_info.m_piercing && hitEntity)
        {
            Physics2D.IgnoreCollision(p_collision.otherCollider, collider);
        }
        if (!m_info.m_piercing || !hitEntity)
        {
            Disable(true);
        }
    }
Exemplo n.º 3
0
    void OnCollisionEnter2D(Collision2D p_collision)
    {
        Collider2D collider = p_collision.collider;
        bool       hit      = false;

        if (collider.gameObject != gameObject)
        {
            CollisionRelay relay = collider.GetComponent <CollisionRelay>();

            if (relay != null && m_shooter)
            {
                m_shooter.Damage(this, relay.m_damageable);

                hit = true;
            }
        }

        if (m_info.m_piercing && hit && collider.transform.parent.tag == "NoProjCollision")
        {
            Disable(true);
        }
        if (m_info.m_piercing && hit)
        {
            Physics2D.IgnoreCollision(p_collision.otherCollider, collider);
        }
        if (collider.tag != "NoProjCollision" && (!m_info.m_piercing || !hit))
        {
            Disable(true);
        }
    }
Exemplo n.º 4
0
    public void OnTriggerEnter2D(Collider2D col)
    {
        Entity         e     = col.GetComponent <Entity> ();
        CollisionRelay relay = col.GetComponent <CollisionRelay> ();
        CircuitNode    i     = null;  //TODO bullet activated circuit node
        Destructable   d     = col.GetComponent <Destructable> ();

        if (relay != null && e == null)
        {
            e = relay.LogCollision(this);
        }

        if (e != null)
        {
            if (faction != e.GetFaction())
            {
                Entity.DamageEntity(e, source, damage, DamageType);
                OnHit(col, e);
                if (destroyOnHit)
                {
                    OnDeath();
                }
            }
        }
        else if (i != null)
        {
            OnHit(col);
//			i.OnInteract (damageType);
        }
        else if (d != null)
        {
            OnHit(col);
            d.ApplyDamage(damage);
        }
        else if (col.tag == "Indes")
        {
            OnHit(col);
            OnDeath();
        }
    }
Exemplo n.º 5
0
    public void Init(Entity p_entity, float p_destroyTime)
    {
        m_relay = p_entity.m_collisionRelay;
        m_relay.m_damageable = this;
        m_type                       = p_entity.m_type;
        m_defense                    = p_entity.m_stats.GetBaseStatWithGear(Stats.DEF);
        m_feedbackTemplate           = p_entity.m_feedbackTemplate;
        m_feedbackPositionRandomness = p_entity.m_feedbackPositionRandomness;

        m_health = gameObject.AddComponent <HealthInfo>();
        m_health.m_useLocalHealth = true;
        m_health.m_maxHealth      = Constants.CORPSE_HEALTH_BASE +
                                    Mathf.RoundToInt(p_entity.m_health.GetMaxHealth() * Constants.CORPSE_HEALTH_PERCENTAGE);
        m_health.m_healthBarTemplate = p_entity.m_health.m_healthBarTemplate;
        m_health.m_healthBarOffset   = p_entity.m_health.m_healthBarOffset;
        m_health.m_damageEvent       = new UnityEvent();
        m_health.m_deathEvent        = new UnityEvent();
        m_health.Init(this);

        m_defaultCollider = GetComponent <BoxCollider2D>();
        BoxCollider2D interactBounds = gameObject.AddComponent <BoxCollider2D>();
        BoxCollider2D innerCollider  = m_relay.GetComponent <BoxCollider2D>();

        interactBounds.size      = innerCollider.size += new Vector2(0.25f, 0.25f);
        interactBounds.offset    = innerCollider.offset;
        interactBounds.isTrigger = true;

        m_container = gameObject.AddComponent <Container>();
        m_container.m_interactBounds  = interactBounds;
        m_container.m_onInteractEvent = p_entity.m_interactCorpseEvent;
        m_container.m_autoLootable    = true;
        m_container.m_corpse          = this;
        innerCollider.isTrigger       = false;

        m_container.m_inventory = p_entity.m_inventory;

        if (!p_entity.m_dropInventoryOnDeath)
        {
            m_container.m_inventory.Clear();
        }

        if (p_entity.m_dropInventoryOnDeath && p_entity.m_equipment)
        {
            for (int i = 0; i < p_entity.m_equipment.m_items.Length; i++)
            {
                if (p_entity.m_equipment.m_items[i].m_item)
                {
                    m_container.m_inventory.Add(p_entity.m_equipment.m_items[i]);
                }
            }
        }

        if (p_entity.m_lootTable != null && p_entity.m_lootTable.m_items.Count > 0)
        {
            p_entity.m_lootTable.Drop(m_container.m_inventory);
        }

        m_renderer = p_entity.GetComponent <SpriteRenderer>();
        FadeCorpse(p_entity);

        if (p_destroyTime > 0)
        {
            StartCoroutine(DestroyLater(p_destroyTime));
        }
    }