Ejemplo n.º 1
0
    public Projectile CreateProjectile(GameObject prefab, Vector2 creationPoint, Vector2 targetPoint,
                                       float projectileSpeed, float damage, float stun, float projectileDuration, Vector2 knockback,
                                       bool fixedKnockback = true, ElementType element = ElementType.PHYSICAL)
    {
        Vector2    cOff   = (m_physics == null) ? creationPoint : m_physics.OrientVectorToDirection(creationPoint);
        Vector3    newPos = transform.position + (Vector3)cOff;
        GameObject go;

        if (prefab != null)
        {
            go = GameObject.Instantiate(prefab, newPos, Quaternion.identity);
        }
        else
        {
            go = GameObject.Instantiate(HitboxList.Instance.StandardProjectile, newPos, Quaternion.identity);
        }
        Projectile newProjectile = go.GetComponent <Projectile>();

        newProjectile.Damage           = damage;
        newProjectile.Duration         = projectileDuration;
        newProjectile.Knockback        = (m_physics == null) ? knockback : m_physics.OrientVectorToDirection(knockback);
        newProjectile.IsFixedKnockback = fixedKnockback;
        newProjectile.Stun             = stun;
        newProjectile.AddElement(element);
        newProjectile.Creator         = gameObject;
        newProjectile.Faction         = Faction;
        newProjectile.AimPoint        = (m_physics == null) ? targetPoint : m_physics.OrientVectorToDirection(targetPoint);
        newProjectile.ProjectileSpeed = projectileSpeed;

        ExecuteEvents.Execute <ICustomMessageTarget> (gameObject, null, (x, y) => x.OnHitboxCreate(newProjectile));
        newProjectile.Init();
        return(newProjectile);
    }
Ejemplo n.º 2
0
    public Projectile CreateProjectile(GameObject prefab, Vector2 creationPoint, Vector2 targetPoint,
                                       WeaponStats wps)
    {
        float       projectileSpeed = wps.speed;
        float       damage = wps.damage;
        float       stun = 0f;
        float       projectileDuration = wps.duration;
        Vector2     knockback = wps.knockbackMult * Vector2.right;
        bool        fixedKnockback = false;
        ElementType element = ElementType.PHYSICAL;
        Vector3     newPos; Quaternion newRot;

        if (GetComponent <BasicMovement>().IsCurrentPlayer)
        {
            newPos = transform.GetChild(0).GetChild(0).position + wps.Offset;
            newRot = transform.GetChild(0).transform.rotation;
        }
        else
        {
            Vector2 cOff = (GetComponent <Orientation>() == null) ? creationPoint : GetComponent <Orientation>().OrientVectorToDirection2D(creationPoint);
            newPos = transform.position + (Vector3)cOff;
            newRot = Quaternion.identity;
        }

        GameObject go;

        if (prefab == null)
        {
            return(null);
        }
        go = GameObject.Instantiate(prefab, newPos, newRot);
        Projectile newProjectile = go.GetComponent <Projectile>();

        newProjectile.Damage           = damage;
        newProjectile.Duration         = projectileDuration;
        newProjectile.OriginWeapon     = Weapon;
        newProjectile.PenetrativePower = wps.pierce;
        if (fixedKnockback)
        {
            newProjectile.Knockback = (GetComponent <Orientation>() == null) ? knockback : GetComponent <Orientation>().OrientVectorToDirection2D(knockback);
        }
        else
        {
            float angle = Mathf.Atan2(targetPoint.y, targetPoint.x);
            newProjectile.Knockback = new Vector2(Mathf.Cos(angle) * knockback.x, Mathf.Sin(angle) * knockback.x);
        }

        newProjectile.IsFixedKnockback = fixedKnockback;
        newProjectile.Stun             = stun;
        newProjectile.AddElement(element);
        newProjectile.Creator = gameObject;
        GetComponent <FactionHolder>().SetFaction(go);
        newProjectile.ProjectileSpeed = projectileSpeed;
        newProjectile.SetAimPoint(targetPoint); // (m_physics == null) ? targetPoint : m_physics.OrientVectorToDirection(targetPoint);
        newProjectile.Init();
        newProjectile.GravityScale  = wps.GravityScale;
        newProjectile.timeToGravity = wps.timeToGravity;
        newProjectile.Deflector     = wps.deflector;
        OnDeathDrop odi = go.AddComponent <OnDeathDrop>();

        odi.DeathItems = wps.OnDeathCreate;
        return(newProjectile);
    }