private void LoadContent()
        {
            //Load each projectile from the de-serialized projectile data
            foreach (var item in GameData.Instance.projectileData.projectileSpecifications)
            {
                string path       = item.pathToTexture;
                var    tex        = content.Load <Texture2D>(path);
                var    scale      = Utils.scaleForTexture(tex);
                Sprite appearance = new Sprite(tex, scale, Color.White);

                Projectile prefab = null;

                //More projectile types could be added here.
                switch (item.type)
                {
                case ProjectileType.fireball:
                    prefab = new FireballProjectile(appearance, Vector2.Zero, item.speed, item.damage);
                    break;

                default:
                    break;
                }

                prefabs[item.type] = prefab;
            }
        }
示例#2
0
    private IEnumerator BeginBehaviour()
    {
        StartEffects();

        yield return(new WaitForSeconds(delay));

        Entity ent = GetComponentInParent <Entity>();

        if (fireballProjectile != null)
        {
            FireballProjectile p = Instantiate(fireballProjectile);
            p.transform.position = transform.position;

            if (ent != null)
            {
                p.ignoredLayers = 1 << ent.gameObject.layer;
                InputSystem inputSystem = ent.gameObject.GetComponent <InputSystem>();
                if (inputSystem != null)
                {
                    p.direction = inputSystem.GetLookDir();
                }
            }
            p.source       = ent;
            p.damageAmount = damages;
        }
    }
示例#3
0
    void LaunchProjectile()
    {
        var instance = FireballProjectile.Launch(fireballPrefab, this.launchPoint.position, direction);

        // If this object has a collider, the projectile shall not collide with it
        if (!ReferenceEquals(_collider, null))
        {
            Physics2D.IgnoreCollision(instance.Collider, _collider);
        }
    }
示例#4
0
    /**
     * <summary>
     * Instantiates a fireball projectile at a certain spawn point and launches into a given direction.
     * It will also play sounds etc.
     * </summary>
     */
    public static FireballProjectile Launch(FireballProjectile prefab, Vector3 spawnPoint, Vector2 direction)
    {
        var instance = Instantiate(prefab, spawnPoint, Quaternion.identity);

        // rotate projectile into direction of flight
        instance.transform.up = -direction;
        instance._direction   = direction;
        instance._audioSource.Play();

        return(instance);
    }
    public void Cast(Wizard caster)
    {
        var target            = caster.runtime.RightTarget;
        var targetPos         = target?.GetTargetPosition() ?? caster.spritePosition + new Vector2(1, 1);
        var projectileDetails = new FireballProjectile()
        {
            direction = caster.Position.GetDirectionTo(target.GetTargetPosition()),
            start     = caster.spritePosition
        };

        caster.CreateProjectile(projectileDetails);
    }
    public override void UseSpell()
    {
        FireballProjectile newProjectile = projectile.Instance() as FireballProjectile;

        newProjectile.Position = GlobalPosition;

        newProjectile.LinearVelocity = new Vector2(owner.GetForward().Position - Position).Normalized() * projectileSpeed;
        if (game.CheckHeat() > 0)
        {
            newProjectile.Damage = (int)(damage * (1 + (game.CheckHeat() / 100f)));
        }
        else
        {
            newProjectile.Damage = damage;
        }

        // TODO: Increase fireball radius with Heat
        //newProjectile.GetNode("Explosion/ExplosionArea") as CollisionShape2D.Shape as CircleShape2D).Radius = 180 * ((game.CheckHeat() / 100) + 1);

        GetNode("/root/World").AddChild(newProjectile);

        game.AddHeat(5);
    }
    public override void Tick()
    {
        if (!alert)
        {
            if (decisionTime > 0f)
            {
                decisionTime -= Time.deltaTime;
                return;
            }
            decisionTime = Random.Range(.4f, .6f);

            int distance = AxMath.WeightedDistance(owner.cell, GameManager.Instance.Player[0].cell);
            if (distance > SeeDistance)
            {
                return;
            }

            if (Random.value <= NearSoundChanceSleeping)
            {
                if (mc.NearSounds.Length > 0)
                {
                    if (!mc.audioSource.isPlaying)
                    {
                        mc.audioSource.clip = mc.NearSounds[Random.Range(0, mc.NearSounds.Length)];
                        mc.audioSource.Play();
                    }
                }
            }

            if (SeePlayerRay())
            {
                alert        = true;
                decisionTime = 0f;
            }

            if (!alert)
            {
                return;
            }
        }

        if (painFrame)
        {
            mc.moveVector = Vector3.zero;
            painFrame     = false;
            attackTime    = 0f;
            decisionTime  = 0f;
            return;
        }

        if (attackTime > 0f)
        {
            attackTime -= Time.deltaTime;

            Vector3 aimAt = (GameManager.Instance.Player[0].transform.position - mc.transform.position).normalized;
            //mc.transform.rotation = Quaternion.LookRotation(Vector3.Lerp(mc.transform.forward, new Vector3(aimAt.x, 0, aimAt.z), Time.deltaTime * mc.turnSpeed), Vector3.up);
            //instantenous rotation towards target
            mc.transform.rotation = Quaternion.LookRotation(new Vector3(aimAt.x, 0, aimAt.z), Vector3.up);

            if (attackTime < AttackHappenTime && !attacked)
            {
                attacked = true;

                float distance = (owner.transform.position + Vector3.up * AttackHeight - GameManager.Instance.Player[0].transform.position).magnitude;
                if (distance < meleeAttackRange)
                {
                    if (CanMeleeRay(distance))
                    {
                        if (mc.AttackSounds.Length > 0)
                        {
                            GameManager.Create3DSound(mc.transform.position, mc.AttackSounds[1], 5f);
                        }

                        Damageable d = GameManager.Instance.Player[0].GetComponent <Damageable>();
                        if (d != null)
                        {
                            d.Damage(Random.Range(MeleeDamageMin, MeleeDamageMax + 1), DamageType.Generic, owner.gameObject);
                        }
                    }
                }
                else
                {
                    if (mc.AttackSounds.Length > 0)
                    {
                        GameManager.Create3DSound(mc.transform.position, mc.AttackSounds[0], 5f);
                    }

                    if (mc.AttackProjectile != null)
                    {
                        FireballProjectile fireball = GameObject.Instantiate(mc.AttackProjectile).GetComponent <FireballProjectile>();
                        if (fireball != null)
                        {
                            fireball.transform.position = owner.transform.position + Vector3.up * AttackHeight;
                            fireball.owner = owner.gameObject;
                            fireball.transform.LookAt(GameManager.Instance.Player[0].transform.position + Random.insideUnitSphere * AttackSpread + Vector3.up * TargetHeightAimFix);
                            fireball.transform.SetParent(GameManager.Instance.TemporaryObjectsHolder);
                        }
                    }
                }
            }

            return;
        }

        if (wantDirection != Vector3.zero)
        {
            mc.transform.rotation = Quaternion.LookRotation(Vector3.Lerp(mc.transform.forward, wantDirection, Time.deltaTime * mc.turnSpeed), Vector3.up);
        }

        if (decisionTime > 0f)
        {
            decisionTime -= Time.deltaTime;
            return;
        }

        if (Random.value <= PokeChance)
        {
            Ray        ray = new Ray(owner.transform.position + Vector3.up, owner.transform.forward);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 2, ~((1 << 9) | (1 << 11)), QueryTriggerInteraction.Ignore))
            {
                Pokeable lc = hit.collider.gameObject.GetComponent <Pokeable>();
                if (lc != null)
                {
                    if (lc.AllowMonsters())
                    {
                        lc.Poke(owner.gameObject);
                    }
                }
            }
        }

        if (Random.value <= NearSoundChanceAwake)
        {
            if (mc.NearSounds.Length > 0)
            {
                if (!mc.audioSource.isPlaying)
                {
                    mc.audioSource.clip = mc.NearSounds[Random.Range(0, mc.NearSounds.Length)];
                    mc.audioSource.Play();
                }
            }
        }

        decisionTime  = Random.Range(.4f, .6f);
        wantDirection = Vector3.zero;

        bool aggro = false;

        {
            float distance = (owner.transform.position + Vector3.up * AttackHeight - GameManager.Instance.Player[0].transform.position).magnitude;
            if (distance < meleeAttackRange)
            {
                wantMove     = false;
                aggro        = true;
                attacked     = false;
                attackTime   = .7f;
                decisionTime = 0f;
                mc.InitAttackAnimation();
                mc.frametime = .2f;
            }
            else if (Random.value < AggroChance)
            {
                Ray toPlayer;
                if (SeePlayerRay(out toPlayer))
                {
                    wantDirection = new Vector3(toPlayer.direction.x, 0, toPlayer.direction.z);
                    wantMove      = false;
                    aggro         = true;
                    attacked      = false;
                    attackTime    = 1f;
                    decisionTime  = 0f;
                    mc.InitAttackAnimation();
                }
            }
        }

        if (!aggro)
        {
            float moveRoll = Random.value;
            if (moveRoll < randomMoveChance)
            {
                MoveToRandomNearbyCell();
            }
            else if (moveRoll < closestMoveChance)
            {
                if (!MoveToRandomClosestBreath())
                {
                    MoveToRandomNearbyCell();
                }
            }
            else
            {
                if (!MoveTowardsBreath())
                {
                    if (!MoveToRandomClosestBreath())
                    {
                        MoveToRandomNearbyCell();
                    }
                }
            }
        }

        if (Random.value < IdleChance)
        {
            wantMove = false;
        }

        if (wantMove)
        {
            mc.moveVector.x = 1;
        }
        else
        {
            mc.moveVector.x = 0;
        }
    }