示例#1
0
    public override void Activate(MonsterCharacter character, int index)
    {
        //would result in illegal normalization, need a direction to dash into
        if (character.physicsBody.velocity == Vector2.zero)
        {
            return;
        }

        //need 65% of full power at minimum
        if (character.ChargePoints < (ChargeCost * .65f))
        {
            Sounds.CreateSound(FailSound);
            Messaging.GUI.ScreenMessage.Invoke("NOT ENOUGH CHARGE", Color.red);
            return;
        }

        if (character.SkillCooldowns[index] > 0)
        {
            Sounds.CreateSound(FailSound);
            return;
        }

        Sounds.CreateSound(ActivationSound);

        character.SkillCooldowns[index] = Cooldown;

        float strength = Strength;

        if (character.ChargePoints < ChargeCost)
        {
            strength *= (float)character.ChargePoints / ChargeCost;
            character.ChargePoints = 0;
        }
        else
        {
            character.ChargePoints -= ChargeCost;
        }

        DashSkill d = Instantiate(this, LevelLoader.DynamicObjects);

        d.Strength        = strength;
        d.direction       = character.physicsBody.velocity.normalized;
        d.targetCharacter = character;
        d.timer           = ActiveTime;

        if (AttachmentEffect != null)
        {
            foreach (string attachPoint in AttachmentPoints)
            {
                GameObject effect = Instantiate(AttachmentEffect);

                GenericTimer e = effect.AddComponent <GenericTimer>();
                e.LifeTime = ActiveTime * 5;
                e.OnTimer.AddListener(() =>
                {
                    TrailRenderer tr = effect.GetComponentInChildren <TrailRenderer>();
                    if (tr != null)
                    {
                        tr.emitting = false;
                    }
                });

                DestroyAfterTime t = effect.AddComponent <DestroyAfterTime>();
                t.LifeTime = ActiveTime * 10;

                effect.transform.SetParent(character.GetAttachmentPoint(attachPoint), false);
            }
        }
    }
示例#2
0
    private void Update()
    {
        timer += Time.deltaTime;

        if (timer >= Cooldown)
        {
            Destroy(gameObject);
        }

        if (!animationReturn && timer > AnimationDelay)
        {
            targetCharacter.CallAnimation(targetCharacter.CurrentWeaponAnimation);
            animationReturn = true;
        }

        if (!thrown && timer > Delay)
        {
            thrown = true;

            if (!ThingDesignator.Designations.ContainsKey(GrenadeDesignation))
            {
                Debug.LogError("GrenadeSkill \"" + gameObject.name + "\" grenade designation \"" + GrenadeDesignation + "\" not found in designator");
                return;
            }

            GameObject prefab        = ThingDesignator.Designations[GrenadeDesignation];
            Grenade    GrenadePrefab = prefab.GetComponent <Grenade>();
            if (GrenadePrefab == null)
            {
                Debug.LogError("GrenadeSkill \"" + gameObject.name + "\" grenade designation \"" + GrenadeDesignation + "\" has no <Grenade> component");
                return;
            }

            Grenade grenade = Instantiate(GrenadePrefab, LevelLoader.DynamicObjects);
            grenade.owner           = targetCharacter;
            grenade.Damage          = Damage;
            grenade.damageType      = damageType;
            grenade.Force           = Force;
            grenade.LifeTime        = LifeTime;
            grenade.ArmDistance     = ArmDistance;
            grenade.ArmTimeRange    = ArmTimeRange;
            grenade.Speed           = speed;
            grenade.ExplosionRadius = ExplosionRadius;

            //make a special raycasting move from character to barrel
            grenade.transform.position = targetCharacter.GetAttachmentPoint(AttachmentPoint).position;

            Mouse.UpdateWorldPosition();
            Vector2 AttackDirection = Mouse.WorldPosition - targetCharacter.transform.position;

            if (AttackDirection == Vector2.zero)
            {
                grenade.transform.rotation = targetCharacter.LookDirection;
            }
            else
            {
                grenade.transform.rotation = Quaternion.Euler(0, 0, Mathf.Atan2(AttackDirection.y, AttackDirection.x) * Mathf.Rad2Deg);
            }

            //add spread
            float firstRoll  = Random.Range(-spread, spread);
            float secondRoll = Random.Range(-spread, spread);
            grenade.transform.rotation *= Quaternion.Euler(0, 0, Mathf.Abs(firstRoll) < Mathf.Abs(secondRoll) ? firstRoll : secondRoll);

            grenade.GetComponent <SaveGameObject>().SpawnName = GrenadeDesignation;
        }
    }