//---------------------- // Protected Functions //---------------------- // Private Functions /// <summary> /// Only check when the item start dropping. /// </summary> /// <param name="other"> collider detected. </param> private void TriggerDropping(Collider other) { if (mVelocity.y > 0) { return; } // meet ignore object JCS_ItemIgnore jcsii = other.GetComponent <JCS_ItemIgnore>(); if (jcsii != null) { return; } JCS_Item otherItem = this.GetComponent <JCS_Item>(); // if itself it a item, we check other is a item or not. if (otherItem != null) { otherItem = other.GetComponent <JCS_Item>(); // if both are item then we dont bother // each other action. if (otherItem != null) { return; } } #if (UNITY_EDITOR) // if is debug mode print this out. // in order to know what does item touched and // stop this movement. if (JCS_GameSettings.instance.DEBUG_MODE) { JCS_Debug.PrintName(other.transform); } #endif mVelocity.y = 0; mEffect = false; mFixCollider = other; // TODO(JenChieh): not all the object we get set are // box collider only. BoxCollider beSetBox = other.GetComponent <BoxCollider>(); // set this ontop of the other box(ground) if (beSetBox != null) { JCS_Physics.SetOnTopOfBoxWithSlope(mBoxCollider, beSetBox); } // enable the physic once on the ground JCS_PlayerManager.instance.IgnorePhysicsToAllPlayer(this.mBoxCollider, false); }
/// <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); }
/// <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> private void DropAnItem(JCS_Item item, int index, bool isEven) { DropAnItem( item, index, isEven, mIsGravity, mSpreadEffect, mRotateWhileDropping, mConstWaveEffect, mDestroyFadeOutEffect); }
//======================================== // 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(); } }
/// <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(); } } }
/// <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(); } }
/// <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(); } }