예제 #1
0
        /// <summary>
        /// Reflect the bullet by turning the degree.
        /// </summary>
        /// <param name="bullet"> bullet reflecting. </param>
        private void ReflectBullet(JCS_Bullet bullet)
        {
            // if object cannot be reflected, end function call
            if (!bullet.Reflectable)
            {
                return;
            }

            float randDegree = JCS_Random.Range(-mRandomReflectDegree, mRandomReflectDegree);

            Vector3 rotation = bullet.transform.eulerAngles;

            rotation.z += (180 + randDegree);      // plus 180 so it goes other direction.
            bullet.transform.eulerAngles = rotation;

            // apply the force.
            bullet.MoveSpeed += mReflectForce;

            // play sound from sound pool
            mSoundPoolAction.PlayRandomSound();

            // do random teleport effect
            RandomPosEffect(bullet);

            // apply position offset
            bullet.transform.position += mPosOffset;
        }
        /// <summary>
        /// Randomly pick one attack animation.
        /// </summary>
        /// <returns> animation index to attack state. </returns>
        private JCS_AttackState GetRandomAttackState()
        {
            // apply a random attack animation.
            int attackAnimIndex = JCS_Random.Range(1, mAttackAnimationCount + 1);

            switch (attackAnimIndex)
            {
            case 1:
                return(JCS_AttackState.ATTACK_01);

            case 2:
                return(JCS_AttackState.ATTACK_02);

            case 3:
                return(JCS_AttackState.ATTACK_03);

            case 4:
                return(JCS_AttackState.ATTACK_04);

            case 5:
                return(JCS_AttackState.ATTACK_05);
            }

            JCS_Debug.LogError("This shouldn't happens");

            // this sould not happens.
            return(JCS_AttackState.ATTACK_01);
        }
예제 #3
0
        private void RandomPosEffect(JCS_Bullet bullet)
        {
            Vector3 newPos = bullet.transform.position;

            if (mRandPosX)
            {
                float effectRange = JCS_Random.Range(-mRandPosRangeX, mRandPosRangeX);
                newPos.x += effectRange;
            }

            if (mRandPosY)
            {
                float effectRange = JCS_Random.Range(-mRandPosRangeY, mRandPosRangeY);
                newPos.y += effectRange;
            }

            if (mRandPosZ)
            {
                float effectRange = JCS_Random.Range(-mRandPosRangeZ, mRandPosRangeZ);
                newPos.z += effectRange;
            }

            // apply result
            bullet.transform.position = newPos;
        }
예제 #4
0
 private void Start()
 {
     if (mStartRandomJumpForce)
     {
         mJumpForce += JCS_Random.Range(-mRandomJumpForceRange, mRandomJumpForceRange);
     }
 }
예제 #5
0
        /// <summary>
        /// After a cetain time we target a new vector value to do
        /// tweener effect.
        /// </summary>
        private void TargetNewVectorValue()
        {
            // Do nothing if not done tweening.
            //if (!mTransformTweener.IsDoneTweening)
            //    return;

            Vector3 newVal = mTransformTweener.GetSelfTransformTypeVector3();

            // x
            if (!mFreeze.check1)
            {
                newVal.x = JCS_Random.Range(mMinVectorRange.x, mMaxVectorRange.x);
            }
            // y
            if (!mFreeze.check2)
            {
                newVal.y = JCS_Random.Range(mMinVectorRange.y, mMaxVectorRange.y);
            }
            // z
            if (!mFreeze.check3)
            {
                newVal.z = JCS_Random.Range(mMinVectorRange.z, mMaxVectorRange.z);
            }

            mTransformTweener.DoTween(newVal);

#if (UNITY_EDITOR)
            targetValue = newVal;
#endif
        }
예제 #6
0
        /// <summary>
        /// When player get hit.
        /// </summary>
        public override void Hit()
        {
            if (!mHitEffect)
            {
                JCS_Debug.LogError(
                    "You call the function without checking the hit effect?");

                return;
            }

            ExitClimbing(0);

            int randDirection = JCS_Random.Range(0, 2);        // 0 ~ 1

            // if 0 push right, else if 1 push left
            float pushVel = (randDirection == 0) ? mHitVelX : -mHitVelX;

            // apply force as velocity
            this.mVelocity.x += pushVel;

            // hop a bit. (velcotiy y axis)
            this.mVelocity.y += mHitVelY;


            DoAnimation(JCS_LiveObjectState.STAND);
        }
예제 #7
0
        /// <summary>
        /// Generate the next new point but not the same as last point.
        /// </summary>
        private void GetNextPoint()
        {
            if (mRandom)
            {
                int len      = mPoints.Count;
                int newIndex = JCS_Random.RangeInclude(0, len - 1);

                if (newIndex == mTargetPointIndex && len != 1)
                {
                    GetNextPoint();
                }
                else
                {
                    mTargetPointIndex = newIndex;
                }
            }
            else
            {
                ++mTargetPointIndex;

                if (mTargetPointIndex >= mPoints.Count)
                {
                    mTargetPointIndex = 0;
                }
            }
        }
예제 #8
0
        /// <summary>
        /// Add random value to Vector3
        /// </summary>
        /// <param name="trans"> transfrorm u want to apply. </param>
        /// <param name="randVec"> value for each axis. </param>
        /// <param name="checks"> check for eaxh axis. </param>
        /// <returns> transform result. </returns>
        public static Vector3 ApplyRandVector3(Vector3 trans, Vector3 randVec, JCS_Bool3 checks)
        {
            Vector3 tempVec = trans;

            if (checks.check1)
            {
                float val = JCS_Random.Range(-randVec.x, randVec.x);
                tempVec = IncVecX(tempVec, val);
            }

            if (checks.check2)
            {
                float val = JCS_Random.Range(-randVec.y, randVec.y);
                tempVec = IncVecY(tempVec, val);
            }

            if (checks.check3)
            {
                float val = JCS_Random.Range(-randVec.z, randVec.z);
                tempVec = IncVecZ(tempVec, val);
            }

            trans = tempVec;

            return(tempVec);
        }
        /// <summary>
        /// Make a particle fit the setting.
        /// </summary>
        /// <param name="particle"> particle to change and fit the setting. </param>
        private void SetParticleBySetting(JCS_Particle particle)
        {
            // get this particle info.
            Vector3 newPos = particle.transform.position;

            if (mSetToSamePositionWhenActive)
            {
                // set position to the same position as particle
                // system's position.
                particle.transform.position = this.transform.position;
            }

            // after we have set the position to current
            // particle system's position. Next step is to
            // apply the random value to the newer position.
            newPos.x += JCS_Random.Range(-mRandPosX, mRandPosX);
            newPos.y += JCS_Random.Range(-mRandPosY, mRandPosY);
            newPos.z += JCS_Random.Range(-mRandPosZ, mRandPosZ);
            particle.transform.position = newPos;

            // set rotation depend on wind speed

            /**
             * NOTE(jenchieh):
             *                      ------- Set the scale from
             *                      ↓      the original particle,
             *                      ↓      so the euler angles won't
             *                  ↓-------↓  get stack up.              */
            Vector3 newRot = mParticle.transform.localEulerAngles;

            newRot.z = mWindSpeed;

            // apply wind speed.
            newRot.z += JCS_Random.Range(-mRandAngleX, mRandAngleX);

            // apply random rotation.
            newRot.x += JCS_Random.Range(-mRandAngleX, mRandAngleX);
            newRot.y += JCS_Random.Range(-mRandAngleY, mRandAngleY);
            newRot.z += JCS_Random.Range(-mRandAngleZ, mRandAngleZ);
            particle.transform.localEulerAngles = newRot;

            /**
             * NOTE(jenchieh):
             *                      ------- Set the scale from
             *                      ↓      the original particle,
             *                      ↓      so the scale won't
             *                  ↓-------↓  get stack up.              */
            Vector3 newScale = mParticle.transform.localScale;

            newScale.x += JCS_Random.Range(-mRandScaleX, mRandScaleX);
            newScale.y += JCS_Random.Range(-mRandScaleY, mRandScaleY);
            newScale.z += JCS_Random.Range(-mRandScaleZ, mRandScaleZ);
            if (mAlwaysTheSameScale)
            {
                // set the scale the same.
                newScale.y = newScale.x;
                newScale.z = newScale.x;
            }
            particle.transform.localScale = newScale;
        }
예제 #10
0
        private void Test()
        {
            if (JCS_Input.GetKeyDown(KeyCode.N))
            {
                // Testing helper function so spawn sequence of damage
                // Showing u can get the damage from ite
                const int   x_count        = 10;
                const float x_distance     = 3f;
                const float y_randDistance = 0.8f;

                for (int count = 0;
                     count < x_count;
                     ++count)
                {
                    DamageTextSpawnerSimple(
                        0,
                        9999,
                        new Vector2(
                            x_distance * count,
                            JCS_Random.Range(-y_randDistance, y_randDistance)),
                        6,
                        30,
                        0);
                }
            }
        }
예제 #11
0
 private void Start()
 {
     if (mStartRandomWalkSpeed)
     {
         mWalkSpeed += JCS_Random.Range(-mRandomWalkSpeedRange, mRandomWalkSpeedRange);
     }
 }
예제 #12
0
        /// <summary>
        /// Apply deviate effect.
        /// </summary>
        /// <param name="target"></param>
        public void DeviationEffect(Transform target)
        {
            Vector3 newAngles = target.localEulerAngles;

            if (mDeviationEffectX)
            {
                float effectDegree = JCS_Random.Range(-mDeviationRangeX, mDeviationRangeX);

                newAngles.x += effectDegree;
            }

            if (mDeviationEffectY)
            {
                float effectDegree = JCS_Random.Range(-mDeviationRangeY, mDeviationRangeY);
                newAngles.y += effectDegree;
            }

            if (mDeviationEffectZ)
            {
                float effectDegree = JCS_Random.Range(-mDeviationRangeZ, mDeviationRangeZ);
                newAngles.z += effectDegree;
            }

            target.localEulerAngles = newAngles;
        }
예제 #13
0
        /// <summary>
        /// Algorithm to calculate the time to do
        /// fly action include direction.
        /// </summary>
        private void ResetTimeZone()
        {
            float adjustTime = JCS_Random.Range(-mAdjustTimeZone, mAdjustTimeZone);
            mRealTimeZone = mTimeZone + adjustTime;

            mFlyed = false;
            mTimer = 0;
        }
예제 #14
0
        /// <summary>
        /// Chance to occurs trigger lightning effect.
        /// </summary>
        private void DoRandTime()
        {
            // set it back to original time
            mLimitTime = mRecordTime;

            // add new rand time.
            mLimitTime += JCS_Random.Range(-mRandomTime, mRandomTime);
        }
예제 #15
0
        /* Functions */

        private void Start()
        {
            // randomize speed?
            if (mRandomizeSpeedAtStart)
            {
                this.MoveSpeed += JCS_Random.Range(-mRandomSpeedValue, mRandomSpeedValue);
            }
        }
예제 #16
0
        /// <summary>
        /// Get a random vector as unit vector. (direction)
        /// </summary>
        /// <returns>
        /// Random unit vector.
        /// </returns>
        private Vector3 GetRandomVec()
        {
            float xVec = JCS_Random.RangeInclude(-1.0f, 1.0f);
            float yVec = 0.0f;  // no direction on y axis.
            float zVec = JCS_Random.RangeInclude(-1.0f, 1.0f);

            return(new Vector3(xVec, yVec, zVec).normalized);
        }
        /*******************************************/
        /*              Self-Define                */
        /*******************************************/
        //----------------------
        // Public Functions

        /// <summary>
        /// Calculate the time to do event once.
        /// </summary>
        public void ResetTimeZone()
        {
            float adjustTime = JCS_Random.Range(-mAdjustTimeZone, mAdjustTimeZone);
            mRealTimeZone = mTimeZone + adjustTime;

            mDidAction = false;
            mTimer = 0;
        }
예제 #18
0
        /// <summary>
        /// Randomize the rotate direction.
        /// </summary>
        private void RandomizeTheRotateDirection()
        {
            // NOTE(jenchieh): see JCS_Vector3Direction.cs enum.
            // there are 0 ~ 26 options.
            int directionSize = JCS_Random.Range(0, 26);

            mRotateDirection = (JCS_Vector3Direction)directionSize;
        }
예제 #19
0
        /// <summary>
        /// Randomize the value.
        /// </summary>
        /// <param name="value"> how much it randomize. </param>
        private void RandomizeTheRotateSpeed(float value)
        {
            // NOTE(jenchieh): this make sure the min/max are fit.
            float val = JCS_Mathf.ToPositive(value);

            // add up he randomize value.
            mRotateSpeed += JCS_Random.Range(-val, val);
        }
예제 #20
0
        /// <summary>
        /// Reset real time fade to change value base on
        /// the setting.
        /// </summary>
        private void ResetTimeZone()
        {
            mRealTimeToChange = mTimeToChange + JCS_Random.Range(-mAdjustTimeToChange, mAdjustTimeToChange);

            // reset timer.
            mTimeToChangeTimer = 0;

            mFaded = false;
        }
예제 #21
0
        /// <summary>
        /// Randomize a bit of frequency value.
        /// </summary>
        private void RandomizeFrequency()
        {
            if (mRandomizeFrequencyAtStart == 0.0f)
            {
                return;
            }

            mFrequency += JCS_Random.Range(-mRandomizeFrequencyAtStart, mRandomizeFrequencyAtStart);
        }
예제 #22
0
        //----------------------
        // Protected Functions

        //----------------------
        // Private Functions

        /// <summary>
        /// Randomize a bit of amplitude value.
        /// </summary>
        private void RandomizeAmplitude()
        {
            if (mRandomizeAmplitudeAtStart == 0.0f)
            {
                return;
            }

            mAmplitude += JCS_Random.Range(-mRandomizeAmplitudeAtStart, mRandomizeAmplitudeAtStart);
        }
예제 #23
0
        /// <summary>
        /// Reset the timer.
        /// </summary>
        private void ResetTimeZone()
        {
            float adjustTime = JCS_Random.Range(-mAdjustTimeZone, mAdjustTimeZone);

            mRealTimeZone = mDelayTime + adjustTime;

            mShooted    = false;
            mDelayTimer = 0;
        }
예제 #24
0
        /// <summary>
        /// Re-calculate the real time zone.
        /// </summary>
        private void ResetTimeZone()
        {
            float adjustTime = JCS_Random.Range(-mRandomizeSpawnTime, mRandomizeSpawnTime);

            mRealSpawnTime = mSpawnTime + adjustTime;

            mSpawned    = false;
            mSpawnTimer = 0;
        }
예제 #25
0
        /// <summary>
        /// Decide what item to drop base on
        /// the array list we have!
        /// </summary>
        /// <returns> item to drop. </returns>
        private JCS_Item ItemDropped()
        {
            JCS_Item item = null;

            float totalChance = 0;

            // add all possiblity chance together.
            for (int index = 0; index < mItemSet.Length; ++index)
            {
                totalChance += mItemSet[index].dropRate;
            }

            float dropIndex = JCS_Random.Range(0, totalChance + 1);

            float accumMaxDropRate = 0;
            float accumMinDropRate = 0;

            for (int index = 0; index < mItemSet.Length; ++index)
            {
                accumMaxDropRate += mItemSet[index].dropRate;

                if (index == 0)
                {
                    if (JCS_Utility.WithInRange(0, mItemSet[0].dropRate, dropIndex))
                    {
                        item = mItemSet[0].item;
                        break;
                    }

                    continue;
                }

                // 比如: 10, 20, 30, 40

                // Loop 1: 0 ~ 10
                // Loop 2: 20(30-10) ~ 30
                // Loop 3: 30(60-30) ~ 60
                // Loop 4: 40(100-60) ~ 100     每個都減掉上一個的Drop Rate!
                if (JCS_Utility.WithInRange(accumMinDropRate, accumMaxDropRate, dropIndex))
                {
                    item = mItemSet[index].item;
                    break;
                }

                accumMinDropRate += mItemSet[index].dropRate;
            }

            // meaning the last one.
            if (item == null &&
                mItemSet.Length != 0 &&
                mItemSet[mItemSet.Length - 1].dropRate != 0)
            {
                item = mItemSet[mItemSet.Length - 1].item;
            }

            return(item);
        }
예제 #26
0
        /// <summary>
        /// Add the off distance.
        /// </summary>
        /// <param name="targetPos"> Target position use to calculate. </param>
        /// <returns>
        /// Return new position with off distance added.
        /// </returns>
        private Vector3 AddOffDistance(Vector3 targetPos)
        {
            Vector3 randVec = GetRandomVec();

            float magnitude = JCS_Random.RangeInclude(mMinOffDistance, mMaxOffDistance);

            randVec *= magnitude;

            return(targetPos + randVec);
        }
예제 #27
0
        /// <summary>
        /// Calculate the result x and y axis by pass passing
        /// -1, 0, 1 in order to process Fly Action base on Status
        /// enum class.
        /// </summary>
        public void FlyRandomly()
        {
            // get the result -1 ~ 1
            int resultX = JCS_Random.Range(-1, 1 + 1);
            int resultY = JCS_Random.Range(-1, 1 + 1);

            // Porcess by status!
            // 0 idle, -1 left/down, 1 right/up
            FlyByStatus(resultX, resultY);
        }
예제 #28
0
        //----------------------
        // Protected Variables

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

        //========================================
        //      Unity's function
        //------------------------------

        //========================================
        //      Self-Define
        //------------------------------
        //----------------------
        // Public Functions

        /// <summary>
        /// Get a transform from the pool randomly.
        /// </summary>
        /// <returns> transform value. </returns>
        public Transform GetRandomObject()
        {
            if (mTransPool.Length == 0)
            {
                return(null);
            }

            int randIndex = JCS_Random.Range(0, mTransPool.Length);

            return(mTransPool[randIndex]);
        }
예제 #29
0
        /* Functions */

        /// <summary>
        /// Get an audio clip from the pool randomly.
        /// </summary>
        /// <returns></returns>
        public AudioClip GetRandomSound()
        {
            if (mAudioClips.Length == 0)
            {
                return(null);
            }

            int randIndex = JCS_Random.Range(0, mAudioClips.Length);

            return(mAudioClips[randIndex]);
        }
예제 #30
0
        //========================================
        //      Self-Define
        //------------------------------
        //----------------------
        // Public Functions

        /// <summary>
        /// Do the jump by possibility.
        /// </summary>
        public void JumpByPossibility()
        {
            float possibility = JCS_Random.Range(0, 100);

            if (possibility > mPossibility)
            {
                return;
            }

            Jump();
        }