Esempio n. 1
0
        /* Functions */

        /// <summary>
        /// Returns a random object from the list.
        /// </summary>
        /// <returns> object </returns>
        public Transform GetRandomObjectFromList()
        {
            if (mObjects.Count == 0)
            {
                return(null);
            }

            int randIndex = JCS_Random.Range(0, mObjects.Count);

            Transform randObj = mObjects[randIndex];

            return(randObj);
        }
Esempio n. 2
0
        //========================================
        //      Unity's function
        //------------------------------

        protected override void Awake()
        {
            base.Awake();

            // no effect happens
            if (!RandomizeCashValueEffect ||
                mRandomizeCashValue == 0)
            {
                return;
            }

            // randomize the cash value a bit.
            mCashValue += JCS_Random.Range(-mRandomizeCashValue, mRandomizeCashValue + 1);
        }
Esempio n. 3
0
        /// <summary>
        /// Do the walk action depends on possibility.
        /// </summary>
        public void WalkByPossiblity()
        {
            float possibility = JCS_Random.Range(0, 100);

            // possibility check
            if (possibility > mPossibility)
            {
                return;
            }

            // start the algorithm to see if we
            // find the direction to do,
            // if not it will just go randomly.
            WalkDirectionPossibility();
        }
        //========================================
        //      Self-Define
        //------------------------------
        //----------------------
        // Public Functions

        /// <summary>
        /// Calculate possibility and drop the item.
        /// </summary>
        public void DropItems()
        {
            if (mMinNumItemDrop > mMaxNumItemDrop)
            {
                JCS_Debug.LogError(
                    "No item drop. min max.");
                return;
            }

            // calculate and see if we do the drop action.
            float doDrop = JCS_Random.Range(0, 100);

            if (doDrop > mPossiblityDropAction)
            {
                return;
            }

            // start doing the drop action.

            int itemDrop = JCS_Random.Range(mMinNumItemDrop, mMaxNumItemDrop + 1) * mDropRate;

            bool isEven = ((itemDrop % 2) == 0) ? true : false;


            int index = 0;

            for (index = 0;
                 index < itemDrop;
                 ++index)
            {
                JCS_Item item = ItemDropped();

                if (item == null)
                {
                    continue;
                }

                DropAnItem(item, index, isEven);
            }

            // make sure the object actually drop something.
            if (index > 0)
            {
                // play drop sound.
                PlayDropSound();
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Play a random animation in the animator.
        /// </summary>
        private void RandomPlayAnimationInAnimator()
        {
            int animLength = m2DAnimator.AnimationsLength;

            if (animLength == 0)
            {
                return;
            }

            /*
             * Just pick a random animation from the animator's animation array.
             */
            int randIndex = JCS_Random.Range(0, animLength);

            // play this animation
            m2DAnimator.DoAnimation(randIndex);
        }
Esempio n. 6
0
        /// <summary>
        /// Once we do the drop item action,
        /// re-calculate the next drop time.
        /// so every time it drop is random.
        /// </summary>
        private void ResetTime()
        {
            if (!mDroped)
            {
                return;
            }

            // get the offset random time.
            float randTime = JCS_Random.Range(-mRandomTimeRange, mRandomTimeRange);

            // formula, on timing design here.
            mDropRealTime = randTime + mTimePerDrop;

            // reset timer
            mDropTimer = 0;

            mDroped = false;
        }
Esempio n. 7
0
        //----------------------
        // Protected Functions

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

        /// <summary>
        /// Calculate the range and position relationship
        /// in order to find the best destination in the
        /// navigation map.
        ///
        /// IMPORTANT(JenChieh): if the vector does not in the range,
        /// enemy will stay at the place they are, which mean enemy
        /// will do nothing...
        /// </summary>
        /// <returns> result destination </returns>
        private Vector3 CalculateRange(Vector3 targetPos)
        {
            Vector3 newTargetPos = targetPos;

            // set up the unknown angle
            // 隨機"內角"
            float angle = JCS_Random.Range(0, 360);

            // define offset
            float hypOffset = JCS_Random.Range(
                -mAdjustRangeDistance,
                mAdjustRangeDistance);

            // add offset to current distance (hyp)
            float hyp = mRangeDistance + hypOffset;

            float opp = Mathf.Sin(angle) * hyp;

            float adj = JCS_Mathf.PythagoreanTheorem(hyp, opp, JCS_Mathf.TriSides.adj);

            bool flipX = JCS_Mathf.IsPossible(50);
            bool flipZ = JCS_Mathf.IsPossible(50);


            if (flipX)
            {
                newTargetPos.x -= adj;
            }
            else
            {
                newTargetPos.x += adj;
            }

            if (flipZ)
            {
                newTargetPos.z -= opp;
            }
            else
            {
                newTargetPos.z += opp;
            }

            return(newTargetPos);
        }
Esempio n. 8
0
        //========================================
        //      Self-Define
        //------------------------------
        //----------------------
        // Public Functions

        /// <summary>
        /// Spawn a random transform.
        /// </summary>
        public void SpawnATransform()
        {
            int spawnIndex = JCS_Random.Range(0, mSpawnList.Count);

            // check null ref.
            if (mSpawnList[spawnIndex] == null)
            {
                JCS_Debug.Log(
                    "Cannot spawn a null reference. Plz check the spawn list if there are transform attach or empty slot.");
                return;
            }

            // spawn a object
            Transform objSpawned = (Transform)JCS_Utility.SpawnGameObject(
                mSpawnList[spawnIndex],
                this.transform.position);


            // randomize the position a bit.
            Vector3 randPos = JCS_Utility.ApplyRandVector3(
                // use the current spawner position.
                objSpawned.transform.position,
                new Vector3(mRandPosRangeX, mRandPosRangeY, mRandPosRangeZ),
                new JCS_Bool3(mRandPosX, mRandPosY, mRandPosZ));

            // randomize the rotation a bit.
            Vector3 randRot = JCS_Utility.ApplyRandVector3(
                // use the current spawner position.
                objSpawned.transform.eulerAngles,
                new Vector3(mRandRotRangeX, mRandRotRangeY, mRandRotRangeZ),
                new JCS_Bool3(mRandRotationX, mRandRotationY, mRandRotationZ));

            // randomize the rotation a bit.
            Vector3 randScale = JCS_Utility.ApplyRandVector3(
                // use the current spawner position.
                objSpawned.transform.localScale,
                new Vector3(mRandScaleRangeX, mRandScaleRangeY, mRandScaleRangeZ),
                new JCS_Bool3(mRandScaleX, mRandScaleY, mRandScaleZ));

            objSpawned.transform.position    = randPos;
            objSpawned.transform.eulerAngles = randRot;
            objSpawned.transform.localScale  = randScale;
        }
Esempio n. 9
0
        //========================================
        //      Self-Define
        //------------------------------
        //----------------------
        // Public Functions

        /// <summary>
        /// Randomly play one shot of sound
        /// from the audio clip pool!
        /// </summary>
        public void PlayRandomSound()
        {
            if (mAudioClips.Length == 0)
            {
                return;
            }

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

            if (mAudioClips[randIndex] == null)
            {
                JCS_Debug.LogError("JCS_SoundPoolAction", "You inlcude a null references in he audio pool...");
                return;
            }

            float soundVolume = JCS_SoundSettings.instance.GetSoundBaseOnType(mSoundSettingType);

            mSoundPlayer.PlayOneShot(mAudioClips[randIndex], soundVolume);
        }
Esempio n. 10
0
        //----------------------
        // Protected Functions

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

        /// <summary>
        /// Do the actual shake job.
        /// </summary>
        private void DoEffect()
        {
            if (!mEffect)
            {
                return;
            }

            Vector3 pos = mShakeOrigin;

            if (mJCS_2DCamera != null)
            {
                this.mShakeOrigin.x = mJCS_2DCamera.GetTargetTransform().position.x;
                this.mShakeOrigin.y = mJCS_2DCamera.GetTargetTransform().position.y;
            }

            mShakeTimer += Time.deltaTime;

            if (mShakeTimer < mShakeTime)
            {
                // shake randomly
                // shakeTime / shakeTimer = shakeRate
                pos.x += (JCS_Random.Range(-1, 1 + 1)) * mShakeMargin * (mShakeTime / mShakeTimer) / 5;
                pos.y += (JCS_Random.Range(-1, 1 + 1)) * mShakeMargin * (mShakeTime / mShakeTimer) / 5;

                // apply pos
                this.transform.position = pos;
            }
            else
            {
                // back to original position
                this.transform.position = mShakeOrigin;

                mShakeTimer = 0;
                mEffect     = false;

                // Enable the input
                if (mStopInputWhileThisEffect)
                {
                    JCS_GameManager.instance.GAME_PAUSE = false;
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Apply force in order to do hop effect.
        /// </summary>
        /// <param name="moveForce"> force to move in x axis </param>
        /// <param name="jumpForce"> force to move in y axis </param>
        /// /// <param name="depth"> include depth? </param>
        public void DoForce(float moveForce, float jumpForce, bool depth = false)
        {
            mVelocity.y     = jumpForce;
            mVelocity.x     = moveForce;
            this.mMoveForce = moveForce;
            this.mJumpForce = jumpForce;
            mEffect         = true;

            // including depth!
            if (depth)
            {
                float tempMoveForce = moveForce / 2.0f;

                // override x
                mVelocity.x = JCS_Random.Range(-tempMoveForce, tempMoveForce);

                // apply depth
                mVelocity.z = JCS_Random.Range(-tempMoveForce, tempMoveForce);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Do the lightning effect once.
        /// </summary>
        private void DoEffect()
        {
            mLimitTimer += Time.deltaTime;

            if (mLimitTime > mLimitTimer)
            {
                return;
            }

            mLimitTimer = 0;

            int randNum = JCS_Random.Range(0, 100);

            if (randNum <= mPossiblity)
            {
                DoLightning();
            }

            DoRandTime();
        }
        /* Functions */

        protected override void Awake()
        {
            base.Awake();

            mGoStraightAction = this.GetComponent <JCS_3DGoStraightAction>();

            if (mRandomAbsorbTime != 0)
            {
                mTimeToAbsorb += JCS_Random.Range(-mRandomAbsorbTime, mRandomAbsorbTime);
            }

            if (mInitLookAction == null)
            {
                mInitLookAction = this.GetComponent <JCS_2DInitLookByTypeAction>();
            }

            if (mRandomTimeToLook != 0)
            {
                mTimeToLook += JCS_Random.Range(-mRandomTimeToLook, mRandomTimeToLook);
            }
        }
        /// <summary>
        /// Do the particle algorithm here.
        /// </summary>
        private void DoParticle()
        {
            if (mParticle == null)
            {
                return;
            }

            mSequenceTimer += Time.deltaTime;

            // NOTE(jenchieh): magic number...
            float time = JCS_Random.Range(0.5f, 1.0f);

            if (time < mSequenceTimer)
            {
                // reset timer
                mSequenceTimer = 0;

                // do a sequence
                DoSequenceParticle(mDensity);
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Do the fade algorithm.
        /// </summary>
        private void DoFade()
        {
            // if faded, redefine new time zone.
            if (mFaded)
            {
                ResetTimeZone();
            }

            mTimeToChangeTimer += Time.deltaTime;

            if (mTimeToChangeTimer < mRealTimeToChange)
            {
                return;
            }

            this.mAlphaObject.TargetAlpha = JCS_Random.Range(mMinFadeValue, mMaxFadeValue);

            // set flag for time zone.
            mFaded = true;

            // reset timer.
            mTimeToChangeTimer = 0;
        }
Esempio n. 16
0
        /// <summary>
        /// Do the randomize the transform position
        /// offset algorithm.
        /// </summary>
        /// <param name="spawnPos"> position we want to apply. </param>
        /// <returns> position after applied the random offset value. </returns>
        public Vector3 RandTransform(Vector3 spawnPos)
        {
            Vector3 newPos = spawnPos;

            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;
            }

            return(newPos);
        }
Esempio n. 17
0
        /// <summary>
        /// Return the randomize engular angles.
        /// </summary>
        /// <param name="angle"> engular angles we want to randomize. </param>
        /// <returns> randomize angles. </returns>
        public Vector3 RandDegree(Vector3 angle)
        {
            Vector3 newRotation = angle;

            if (mRandDegreeX)
            {
                float randDegree = JCS_Random.Range(-mDegreeValueX, mDegreeValueX);
                newRotation.x += randDegree;
            }

            if (mRandDegreeY)
            {
                float randDegree = JCS_Random.Range(-mDegreeValueY, mDegreeValueY);
                newRotation.y += randDegree;
            }

            if (mRandDegreeZ)
            {
                float randDegree = JCS_Random.Range(-mDegreeValueZ, mDegreeValueZ);
                newRotation.z += randDegree;
            }

            return(newRotation);
        }
Esempio n. 18
0
        /// <summary>
        /// Drop an item.
        /// </summary>
        /// <param name="item"> item u want to spawn </param>
        /// <param name="index"> index to know the force this is pushing to. </param>
        /// <param name="isEven"> is the index even number? </param>
        /// <param name="isGravity"> do gravity effect. </param>
        /// <param name="spreadEffect"> do spread effect. </param>
        /// <param name="rotateDrop"> rotate while dropping. </param>
        /// <param name="waveEffect"> do wave effect while on the ground. </param>
        /// <param name="destroyFade"> while picking it up will fade and destroy. </param>
        private void DropAnItem(
            JCS_Item item,
            int index,
            bool isEven,
            bool isGravity,
            bool spreadEffect,
            bool rotateDrop,
            bool waveEffect,
            bool destroyFade)
        {
            JCS_Item newItem = (JCS_Item)JCS_Utility.SpawnGameObject(
                item,
                this.transform.position,
                this.transform.rotation);

            bool isEvenIndex = ((index % 2) == 0) ? true : false;

            if (isGravity)
            {
                JCS_OneJump oj = newItem.gameObject.AddComponent <JCS_OneJump>();

                float gapDirection = mSpreadGap;
                if (isEvenIndex)
                {
                    gapDirection = -mSpreadGap;
                }

                oj.BounceBackfromWall = BounceBackfromWall;

                float gapForce = 0;

                if (spreadEffect)
                {
                    if (isEven)
                    {
                        if (!isEvenIndex)
                        {
                            gapForce = (gapDirection * (index - 1)) + gapDirection;
                        }
                        else
                        {
                            gapForce = (gapDirection * (index)) + gapDirection;
                        }
                    }
                    // if total is odd
                    else
                    {
                        if (isEvenIndex)
                        {
                            gapForce = (gapDirection * (index));
                        }
                        else
                        {
                            gapForce = (gapDirection * (index)) + gapDirection;
                        }
                    }
                }

                float jumpForce = mJumpForce;
                if (mRandomizeJumpForce)
                {
                    jumpForce += JCS_Random.Range(-mRandomizeJumpForceForce, mRandomizeJumpForceForce);
                }

                oj.DoForce(gapForce, jumpForce, mIncludeDepth);

                if (rotateDrop)
                {
                    JCS_ItemRotation irx = newItem.gameObject.AddComponent <JCS_ItemRotation>();
                    irx.RotateSpeed     = JCS_Random.Range(-mRotateSpeed, mRotateSpeed);
                    irx.Effect          = true;
                    irx.RotateDirection = JCS_Vector3Direction.FORWARD;

                    // if z axis interact in game
                    if (mIncludeDepth)
                    {
                        // add rotation on y axis.
                        JCS_ItemRotation iry = newItem.gameObject.AddComponent <JCS_ItemRotation>();
                        iry.RotateSpeed     = JCS_Random.Range(-mRotateSpeed, mRotateSpeed);
                        iry.Effect          = true;
                        iry.RotateDirection = JCS_Vector3Direction.UP;

                        // add rotation on z axis.
                        JCS_ItemRotation irz = newItem.gameObject.AddComponent <JCS_ItemRotation>();
                        irz.RotateSpeed     = JCS_Random.Range(-mRotateSpeed, mRotateSpeed);
                        irz.Effect          = true;
                        irz.RotateDirection = JCS_Vector3Direction.RIGHT;
                    }
                }
            }

            if (waveEffect)
            {
                JCS_3DConstWaveEffect cwe = newItem.gameObject.AddComponent <JCS_3DConstWaveEffect>();
                cwe.SetObjectType(newItem.GetObjectType());
                cwe.Effect = true;
            }

            if (destroyFade)
            {
                JCS_DestroyObjectWithTime dowt = newItem.gameObject.AddComponent <JCS_DestroyObjectWithTime>();
                dowt.FadeTime    = mFadeTime;
                dowt.DestroyTime = mDestroyTime;

                Renderer[] renderers = newItem.GetComponentsInChildren <Renderer>();

                foreach (Renderer rdr in renderers)
                {
                    JCS_FadeObject fo = rdr.gameObject.AddComponent <JCS_FadeObject>();

                    dowt.FadeObjects.Add(fo);

                    // set the object type the same.
                    fo.SetObjectType(item.GetObjectType());
                    fo.UpdateUnityData();
                }
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Use to check if something possible by percentage.
        /// 0 ~ 100.
        /// </summary>
        /// <returns></returns>
        public static bool IsPossible(float val)
        {
            float possibility = JCS_Random.Range(0, 100);

            return((val > possibility) ? true : false);
        }
Esempio n. 20
0
        /// <summary>
        /// Return the range distance.
        /// </summary>
        /// <returns> Value of the range distance. </returns>
        private float GetRangeDistance()
        {
            float hypOffset = JCS_Random.Range(-mAdjustRangeDistance, mAdjustRangeDistance);

            return(mRangeDistance + hypOffset);
        }
Esempio n. 21
0
        /// <summary>
        /// Do the fade algorithm.
        /// </summary>
        private void DoRange()
        {
            float newRange = JCS_Random.Range(mMinRangeValue, mMaxRangeValue);

            this.mValueTweener.DoTween(newRange);
        }
Esempio n. 22
0
 /// <summary>
 /// Do the fade algorithm.
 /// </summary>
 private void DoFade()
 {
     this.mAlphaObject.TargetAlpha = JCS_Random.Range(mMinFadeValue, mMaxFadeValue);
 }
Esempio n. 23
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);
        }
Esempio n. 24
0
        /// <summary>
        /// Drop an item.
        /// </summary>
        /// <param name="item"> item u want to spawn </param>
        /// <param name="index"> index to know the force this is pushing to. </param>
        /// <param name="isEven"> is the index even number? </param>
        /// <param name="isGravity"> do gravity effect. </param>
        /// <param name="spreadEffect"> do spread effect. </param>
        /// <param name="rotateDrop"> rotate while dropping. </param>
        /// <param name="waveEffect"> do wave effect while on the ground. </param>
        /// <param name="destroyFade"> while picking it up will fade and destroy. </param>
        private void DropAnItem(
            JCS_Item item,
            int index,
            bool isEven,
            bool isGravity,
            bool spreadEffect,
            bool rotateDrop,
            bool waveEffect,
            bool destroyFade)
        {
            JCS_Item jcsi = (JCS_Item)JCS_Utility.SpawnGameObject(
                item,
                this.transform.position,
                this.transform.rotation);

            bool isEvenIndex = ((index % 2) == 0) ? true : false;

            if (isGravity)
            {
                JCS_OneJump jcsoj = jcsi.gameObject.AddComponent <JCS_OneJump>();

                float gapDirection = mSpreadGap;
                if (isEvenIndex)
                {
                    gapDirection = -mSpreadGap;
                }

                jcsoj.BounceBackfromWall = BounceBackfromWall;

                float gapForce = 0;

                if (spreadEffect)
                {
                    if (isEven)
                    {
                        if (!isEvenIndex)
                        {
                            gapForce = (gapDirection * (index - 1)) + gapDirection;
                        }
                        else
                        {
                            gapForce = (gapDirection * (index)) + gapDirection;
                        }
                    }
                    // if total is odd
                    else
                    {
                        if (isEvenIndex)
                        {
                            gapForce = (gapDirection * (index));
                        }
                        else
                        {
                            gapForce = (gapDirection * (index)) + gapDirection;
                        }
                    }
                }

                float jumpForce = mJumpForce;
                if (mRandomizeJumpForce)
                {
                    jumpForce += JCS_Random.Range(-mRandomizeJumpForceForce, mRandomizeJumpForceForce);
                }

                jcsoj.DoForce(gapForce, jumpForce, mIncludeDepth);

                if (rotateDrop)
                {
                    JCS_ItemRotation jcsir = jcsi.gameObject.AddComponent <JCS_ItemRotation>();
                    jcsir.RotateSpeed = mRotateSpeed;
                    jcsir.Effect      = true;

                    // if z axis interact in game
                    if (mIncludeDepth)
                    {
                        // add one more axis.
                        JCS_ItemRotation jcsir2 = jcsi.gameObject.AddComponent <JCS_ItemRotation>();
                        jcsir2.RotateSpeed     = JCS_Random.Range(-mRotateSpeed, mRotateSpeed);
                        jcsir2.Effect          = true;
                        jcsir2.RotateDirection = JCS_Vector3Direction.UP;
                    }
                }
            }

            if (waveEffect)
            {
                JCS_3DConstWaveEffect jcscw = jcsi.gameObject.AddComponent <JCS_3DConstWaveEffect>();
                jcscw.Effect = true;
            }

            if (destroyFade)
            {
                JCS_DestroyObjectWithTime jcsao = jcsi.gameObject.AddComponent <JCS_DestroyObjectWithTime>();
                jcsao.GetFadeObject().FadeTime  = mFadeTime;
                jcsao.DestroyTime = mDestroyTime;

                // set the object type the same.
                jcsao.GetFadeObject().SetObjectType(item.GetObjectType());

                jcsao.GetFadeObject().UpdateUnityData();
            }
        }
Esempio n. 25
0
        /// <summary>
        /// Get the random position within the
        /// certain range. (Circle)
        /// </summary>
        /// <param name="targetPos"> target position </param>
        /// <param name="range"> radius of circle </param>
        /// <param name="adjRange"> adjustable value? </param>
        /// <returns></returns>
        private Vector3 CalculateCirclePosition(Vector3 targetPos, float range, float adjRange = 0)
        {
            Vector3 newPos = mTargetTransform.position;

            // set up the unknown angle
            // ÀH¾÷"¤º¨¤"
            float angle = JCS_Random.Range(0, 360);

            // define offset
            float hypOffset = JCS_Random.Range(
                -adjRange,
                adjRange);

            // add offset to current distance (hyp)
            float hyp = range + hypOffset;

            float opp = Mathf.Sin(angle) * hyp;

            float adj = JCS_Mathf.PythagoreanTheorem(hyp, opp, JCS_Mathf.TriSides.adj);


            bool flipX = JCS_Mathf.IsPossible(50);

            if (flipX)
            {
                newPos.x -= adj;
            }
            else
            {
                newPos.x += adj;
            }


            bool flipY = JCS_Mathf.IsPossible(50);

            if (flipY)
            {
                newPos.y -= opp;
            }
            else
            {
                newPos.y += opp;
            }


            if (mIncludeDepth)
            {
                bool flipZ = JCS_Mathf.IsPossible(50);

                if (flipZ)
                {
                    newPos.z -= opp;
                }
                else
                {
                    newPos.z += opp;
                }
            }

            return(newPos);
        }
Esempio n. 26
0
        /// <summary>
        /// Sometimes if the algorithm cannot find which direction to go.
        /// Just use the function instead of keep finding the direction.
        ///
        /// For example, all three possiblity (Idle, Left, Right)
        /// can be set to 100 percent. Than it will always have to
        /// possiblity of direction to go, which mean the object could
        /// not decide which direction to go.
        /// </summary>
        public void WalkRandomly()
        {
            int result = JCS_Random.Range(-1, 1 + 1);

            WalkByStatus(result);
        }
Esempio n. 27
0
        /// <summary>
        /// Recusive function that will find the direction
        /// and do the walk.
        /// </summary>
        public void WalkDirectionPossibility()
        {
            // direction we are going to use next.
            Status direction = Status.IDLE;


            // if is already get attack do the mad effect.
            if (mMadEffect && mAttackRecorder != null)
            {
                Transform lastAttacker = mAttackRecorder.LastAttacker;

                // if the last attacker does not exist,
                // do nothing.
                if (lastAttacker != null)
                {
                    // if does exist, start following
                    // the attacker.
                    if (lastAttacker.position.x < this.transform.position.x)
                    {
                        direction = Status.LEFT;
                    }
                    else
                    {
                        direction = Status.RIGHT;
                    }

                    // do that direction and return.
                    WalkByStatus(direction);
                    return;
                }
            }

            // record down how what does success to go with.
            int resultCounter = 0;

            float leftPossiblity  = JCS_Random.Range(0, 100);
            float idlePossiblity  = JCS_Random.Range(0, 100);
            float rightPossiblity = JCS_Random.Range(0, 100);

            if (idlePossiblity < mToIdle)
            {
                // success to do idle
                direction = Status.IDLE;
                ++resultCounter;
            }

            if (leftPossiblity < mToLeft)
            {
                // success to do left
                direction = Status.LEFT;
                ++resultCounter;
            }

            if (rightPossiblity < mToRight)
            {
                // success to do right
                direction = Status.RIGHT;
                ++resultCounter;
            }

            // if there are multiple result do randomly
            if (resultCounter >= 2)
            {
                WalkRandomly();
            }
            // else if we successfully find the direction,
            // use the direction algorithm found.
            else
            {
                WalkByStatus(direction);
            }
        }
Esempio n. 28
0
        /// <summary>
        /// Calculate possibility and drop the item.
        /// </summary>
        /// <param name="mustDropItem"> item must drop </param>
        /// <param name="specIndex"> specific drop item index </param>
        /// <param name="only"> only drop this item. </param>
        /// <param name="count"> how many of this item u want to drop. </param>
        public void DropItems(JCS_Item mustDropItem, int specIndex = -1, bool only = false, int count = 1)
        {
            if (mustDropItem == null)
            {
                JCS_Debug.LogError("Must drop item cannot be null references");
                return;
            }

            if (count <= 0)
            {
                JCS_Debug.LogError("Cannot drop item with count less or equal to zero");
                return;
            }

            int index = 0;

            if (only)
            {
                // just
                int itemDrop = count;

                bool isEven = ((itemDrop % 2) == 0) ? true : false;

                for (index = 0;
                     index < count;
                     ++index)
                {
                    // simple assign the item.
                    JCS_Item item = mustDropItem;

                    // do drop the item.
                    DropAnItem(item, index, isEven);
                }
            }
            else
            {
                if (mMinNumItemDrop > mMaxNumItemDrop)
                {
                    JCS_Debug.LogError("No item drop. min max.");
                    return;
                }

                // calculate and see if we do the drop action.
                float doDrop = JCS_Random.Range(0, 100);
                if (doDrop > mPossiblityDropAction)
                {
                    return;
                }

                // start doing the drop action.

                int itemDrop = JCS_Random.Range(mMinNumItemDrop, mMaxNumItemDrop + 1) * mDropRate + count;

                bool isEven = ((itemDrop % 2) == 0) ? true : false;

                int randDropIndex = specIndex;


                // check index out of range.
                if (specIndex < 0 || specIndex >= itemDrop)
                {
                    randDropIndex = JCS_Random.Range(0, itemDrop);
                }

                for (index = 0; index < itemDrop; ++index)
                {
                    JCS_Item item = null;

                    if (index == randDropIndex)
                    {
                        // assign must drop item.
                        item = mustDropItem;
                    }
                    else
                    {
                        item = ItemDropped();
                    }

                    if (item == null)
                    {
                        continue;
                    }

                    DropAnItem(item, index, isEven);
                }
            }

            // make sure the object actually drop something.
            if (index > 0)
            {
                // play drop sound.
                PlayDropSound();
            }
        }
Esempio n. 29
0
        /// <summary>
        /// Fly to a direction base on possibilities.
        /// </summary>
        public void FlyDirectionByPossiblity()
        {
            // direction we are going to use next.
            StatusX directionX = StatusX.IDLE;
            StatusY directionY = StatusY.IDLE;

            // if is already get attack do the mad effect.
            if (mMadEffect && mAttackRecorder != null)
            {
                Transform lastAttacker = mAttackRecorder.LastAttacker;

                // if the last attacker does not exist,
                // do nothing.
                if (lastAttacker != null)
                {
                    // NOTE(JenChieh): if does exist, start
                    // following the attacker.

                    // X-axis
                    if (lastAttacker.position.x < this.transform.position.x)
                    {
                        directionX = StatusX.LEFT;
                    }
                    else
                    {
                        directionX = StatusX.RIGHT;
                    }

                    // Y-axis
                    if (lastAttacker.position.y < this.transform.position.y)
                    {
                        directionY = StatusY.DOWN;
                    }
                    else
                    {
                        directionY = StatusY.UP;
                    }

                    // do that direction and return.
                    FlyByStatus(directionX, directionY);
                    return;
                }
            }

            // record down how what does success to go with.
            int resultCounterX = 0;
            int resultCounterY = 0;

            float idlePossiblityX = JCS_Random.Range(0, 100);
            float leftPossiblity  = JCS_Random.Range(0, 100);
            float rightPossiblity = JCS_Random.Range(0, 100);

            if (idlePossiblityX < mToIdleVetical)
            {
                // success to do idle in x axis
                directionX = StatusX.IDLE;
                ++resultCounterX;
            }

            if (leftPossiblity < mToLeft)
            {
                // success to do left
                directionX = StatusX.LEFT;
                ++resultCounterX;
            }

            if (rightPossiblity < mToRight)
            {
                // success to do right
                directionX = StatusX.RIGHT;
                ++resultCounterX;
            }


            float idlePossiblityY = JCS_Random.Range(0, 100);
            float upPossiblity    = JCS_Random.Range(0, 100);
            float downPossiblity  = JCS_Random.Range(0, 100);

            if (idlePossiblityY < mToIdleHorizontal)
            {
                // success to do idle in y axis
                directionY = StatusY.IDLE;
                ++resultCounterY;
            }

            if (downPossiblity < mToDown)
            {
                // success to do left
                directionY = StatusY.DOWN;
                ++resultCounterY;
            }

            if (upPossiblity < mToUp)
            {
                // success to do right
                directionY = StatusY.UP;
                ++resultCounterY;
            }

            // if there are multiple result do randomly
            if (resultCounterX >= 2 &&
                resultCounterY >= 2)
            {
                FlyRandomly();
            }
            // else if we successfully find the direction,
            // use the direction algorithm found.
            else
            {
                FlyByStatus(directionX, directionY);
            }
        }