Exemple #1
0
        //----------------------
        // Protected Variables

        //========================================
        //      setter / getter
        //------------------------------

        //========================================
        //      Unity's function
        //------------------------------
        protected override void Awake()
        {
            base.Awake();

            mTrackAction           = this.GetComponent <JCS_2DTrackAction>();
            mTrackAction.Following = false;


            mGoStraightAction         = this.GetComponent <JCS_3DGoStraightAction>();
            mGoStraightAction.enabled = true;
        }
Exemple #2
0
        /// <summary>
        /// Shoot a bullet.
        /// </summary>
        /// <param name="bulletSpeed"></param>
        /// <param name="pos"></param>
        /// <param name="direction"></param>
        /// <param name="damages"></param>
        /// <param name="index"></param>
        /// <param name="inSequence"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        public JCS_Bullet Shoot(float bulletSpeed, Vector3 pos, bool direction, int[] damages, int index = 0, bool inSequence = false, Transform target = null)
        {
            if (mPlayer != null)
            {
                if (mPlayer.CharacterState != JCS_2DCharacterState.NORMAL)
                {
                    return(null);
                }
            }

            int hit = damages.Length;

            Vector3 spawnPos = pos + mSpanwPointOffset;

            spawnPos = RandTransform(spawnPos);

            JCS_Bullet bullet = (JCS_Bullet)JCS_Utility.SpawnGameObject(mBullet, spawnPos, mSpawnPoint.rotation);

            // no object spawns
            if (bullet == null)
            {
                return(null);
            }

            // set the attacker.
            SetAttackerInfo(bullet);

            float tempBulletSpeed = bulletSpeed;

            // default: facing left
            if (!direction)
            {
                tempBulletSpeed = -tempBulletSpeed;
            }

            // set bullet speed
            bullet.MoveSpeed = tempBulletSpeed;

            // Do devication Effect
            DeviationEffect(bullet.transform);

            if (bullet is JCS_2DBullet)
            {
                bullet.GetComponent <JCS_3DGoStraightAction>().MoveSpeed = bulletSpeed;
            }


            if (mTrackSoot &&
                target != null)
            {
                JCS_2DTrackAction ta = bullet.GetComponent <JCS_2DTrackAction>();
                if (ta != null)
                {
                    ta.TargetTransform = target;

                    // set to center
                    float newIndex = index - (hit / 2.0f);

                    // apply effect
                    ta.Index = newIndex;
                }
            }

            if (mAbilityFormat != null)
            {
                JCS_ApplyDamageTextToLiveObjectAction adta = bullet.GetComponent <JCS_ApplyDamageTextToLiveObjectAction>();
                if (adta != null)
                {
                    // set the Ability Format
                    adta.AbilityFormat = mAbilityFormat;
                    adta.Hit           = hit;

                    adta.DamageApplying = damages;

                    // if hit equal to 0,
                    // meaning this bullet is in the sequence
                    if (inSequence)
                    {
                        adta.InSequence = true;
                    }

                    adta.TargetTransform = target;
                }
            }

            // part of the SFX
            mRandomMultiSoundAction.PlayRandomSound();

            return(bullet);
        }
Exemple #3
0
        private void OnTriggerEnter(Collider other)
        {
            if (mIsDestroyed)
            {
                return;
            }

            // do not target itself.
            if (other.transform == mAttackerInfo.Attacker)
            {
                return;
            }


            if (mInSequence)
            {
                if (mDestroyByThisAction)
                {
                    if (mTargetTransform == other.transform)
                    {
                        Destroy(this.gameObject);
                    }
                }

                return;
            }

            JCS_2DLiveObject liveObject = other.GetComponent <JCS_2DLiveObject>();

            // doing the lock on effect
            if (mOnlyWithTarget)
            {
                // if the target isn't what we want ignore than.
                if (mTargetTransform != other.transform)
                {
                    return;
                }
                else
                {
                    if (liveObject != null)
                    {
                        JCS_2DTrackAction tact = this.GetComponent <JCS_2DTrackAction>();

                        // only the last bullet in sequence will check dead.
                        if (tact != null)
                        {
                            if (tact.OrderIndex == Hit)
                            {
                                liveObject.BeenTarget = false;
                                liveObject.CheckDie();
                            }
                        }
                    }

                    DestroyWithAction();
                }
            }
            // if not in sequence
            else
            {
                if (liveObject == null)
                {
                    return;
                }

                if (!liveObject.CanDamage)
                {
                    return;
                }

                // liveObject is already dead.
                if (liveObject.IsDead())
                {
                    //DestroyWithAction();
                    return;
                }
            }

            Transform attacker = mAttackerInfo.Attacker;

            if (attacker != null)
            {
                JCS_2DLiveObject owenerLiveObject = mAttackerInfo.Attacker.GetComponent <JCS_2DLiveObject>();
                if (owenerLiveObject != null)
                {
                    if (!JCS_GameSettings.instance.TRIBE_DAMAGE_EACH_OTHER)
                    {
                        // if both player does not need to add in to list.
                        // or if both enemy does not need to add in to list.
                        if (liveObject.IsPlayer == owenerLiveObject.IsPlayer)
                        {
                            return;
                        }
                    }
                }
            }

            if (mAbilityFormat != null)
            {
                mMinDamage      = mAbilityFormat.GetMinDamage();
                mMaxDamage      = mAbilityFormat.GetMaxDamage();
                mCriticalChance = mAbilityFormat.GetCriticalChance();
            }
            else
            {
                JCS_Debug.LogReminder(
                    "You sure to not using any \"JCS_AbilityFormat\"?");
            }

            Vector3 currentPos = liveObject.transform.position + mDamageTextPositionOffset;

            if (mRandPos)
            {
                AddRandomPosition(ref currentPos);
            }

            if (mPreCalculateEffect)
            {
                liveObject.ApplyDamageText(
                    this.mAttackerInfo.Attacker,
                    mDamageApplying,
                    currentPos,
                    mCriticalChance,
                    mHitSound);

                mHit = this.mDamageApplying.Length;
            }
            else
            {
                liveObject.ApplyDamageText(
                    this.mAttackerInfo.Attacker,
                    mMinDamage,
                    mMaxDamage,
                    currentPos,
                    mHit,
                    mCriticalChance,
                    mHitSound);
            }

            // only if there is only one hit need to do this.
            if (mHit == 1)
            {
                liveObject.BeenTarget = false;
            }

            liveObject.CheckDie();

            DestroyWithAction();
        }