void AttemptToFireNumber(NumberInfo fireNumber) { grabbingNumber = null; if (fireNumber.fraction.IsMultipleOf(cannonFrac)) //.numerator % cannonNumber == 0 && fireNumber.fraction.denominator == 1){ // success! Fire the number. { GameObject rocket = SMW_GF.inst.FireRocketFromTo(firePos.position, firePos.forward, fireNumber.fraction, 1, 18, 200, null, true); ScaleUpAndStop sup = rocket.AddComponent <ScaleUpAndStop>(); sup.stopScale = Vector3.one * 3.5f; EffectsManager.inst.CreateSmokePuffBig(firePos.position, firePos.forward); Destroy(fireNumber.gameObject); } else { if (!ignoredNumbers.Contains(fireNumber)) { ignoredNumbers.Add(fireNumber); checkIgnoredTimer = Random.Range(1.5f, 2.5f); } fireNumber.GetComponent <Rigidbody>().isKinematic = false; fireNumber.GetComponent <Collider>().enabled = true; fireNumber.transform.position = startPos.position; float fireForce = 3000f; fireNumber.GetComponent <Rigidbody>().AddForce((-startPos.forward + startPos.right * 1.5f) * fireForce); // reject number off and to the right. This prevents it rejecing into the next incoming number AudioManager.inst.PlayWrongAnswerError(firePos.position, 1, 1); AudioManager.inst.PlayDepressingCannonSound(firePos.position, 1f); EffectsManager.inst.CreateSmokePuffBig(startPos.position, -startPos.forward); if (Vector3.Distance(Player.inst.transform.position, transform.position) < 20f) { PlayerNowMessage.inst.Display("This cannon can only use multiples of 10, like 10, 20, or 30."); } } }
void Trigger(GameObject other) { if (grabbing) { return; } NumberInfo ni = other.GetComponent <NumberInfo>(); if (ni) { if (ignoredNumbers.Contains(ni)) { return; } AudioManager.inst.PlayCartoonEat(ni.transform.position, 0.85f, 0.2f); ni.transform.position = startPos.position; ni.GetComponent <Rigidbody>().isKinematic = true; ni.GetComponent <Collider>().enabled = false; grabbingNumber = ni; grabbing = true; grabTimer = 0; } }
void FreezeNumber(NumberInfo ni, float x) { ni.GetComponent <Rigidbody>().velocity = Vector3.zero; ni.GetComponent <Rigidbody>().useGravity = false; ghosts.Add(ni.gameObject.GetComponent <Collider>()); ni.SetNumber(new Fraction((int)x, 1)); // Integer result detected, allow it to stay (set number to its square root result ni.gameObject.SendMessage("StopDying", SendMessageOptions.DontRequireReceiver); }
void Update() { if (grabbing) { grabTimer += Time.deltaTime; grabbingNumber.transform.position = Vector3.Lerp(grabbingNumber.transform.position, endPos.position, Time.deltaTime * grabSpeed); if (grabTimer > grabDuration) { Fraction result1 = Fraction.Divide(grabbingNumber.fraction, new Fraction(2, 1)); float spitForce = 200; grabbingNumber.GetComponent <NumberInfo>().SetNumber(result1); GameObject leftNum = (GameObject)Instantiate(grabbingNumber.gameObject, outputLeft.transform.position, grabbingNumber.transform.rotation); GameObject rightNum = (GameObject)Instantiate(grabbingNumber.gameObject, outputRight.transform.position, grabbingNumber.transform.rotation); // leftNum.GetComponent<NumberInfo>().SetNumber(result1); // half value per split so total "number" is preserved. // rightNum.GetComponent<NumberInfo>().SetNumber(result1); leftNum.GetComponent <Collider>().enabled = true; rightNum.GetComponent <Collider>().enabled = true; leftNum.GetComponent <Rigidbody>().isKinematic = false; rightNum.GetComponent <Rigidbody>().isKinematic = false; leftNum.GetComponent <Rigidbody>().AddForce(outputLeft.transform.forward * spitForce); rightNum.GetComponent <Rigidbody>().AddForce(outputRight.transform.forward * spitForce); if (!grabbingNumber.GetComponent <Animal>()) { float range = 8f; // Check for numbers nearby (not animals tho). Greedily combine with them for Pascal. foreach (Collider c in Physics.OverlapSphere(leftNum.transform.position, range)) { if (c == leftNum.GetComponent <Collider>()) { continue; } if (c.GetComponent <NumberInfo>() && c.GetComponent <GameObject>() != rightNum) { leftNum.GetComponent <NumberInfo>().Eat(c.GetComponent <NumberInfo>()); } } foreach (Collider c in Physics.OverlapSphere(rightNum.transform.position, range)) { if (c == rightNum.GetComponent <Collider>()) { continue; } if (c.GetComponent <NumberInfo>() && c.GetComponent <GameObject>() != leftNum) { rightNum.GetComponent <NumberInfo>().Eat(c.GetComponent <NumberInfo>()); } } } Destroy(grabbingNumber.gameObject); // grabbingNumber.transform.position = firePos.position; grabbing = false; // AttemptToFireNumber(grabbingNumber); } } }
void FreezeAndDestroy(NumberInfo ni) { ni.GetComponent <Rigidbody>().useGravity = false; // ni.GetComponent<Rigidbody>().isKinematic = true; ni.GetComponent <Collider>().enabled = false; ni.GetComponent <Rigidbody>().drag = 10.5f; StartCoroutine(NumberGlowRedAndDie(ni)); }
bool CombineTestEat(NumberInfo a, NumberInfo b) { // if ((a.GetComponent<EnergyBall>() && !b.GetComponent<EnergyBall>()) || (!a.GetComponent<EnergyBall>() && b.GetComponent<EnergyBall>())) { // return false; // } if (a.GetComponent <EnergyBall>() || b.GetComponent <EnergyBall>()) { if (!(a.GetComponent <EnergyBall>() && b.GetComponent <EnergyBall>())) { return(false); } } if (a.GetComponent <AlgebraInfo>() || b.GetComponent <AlgebraInfo>()) { if (!(a.GetComponent <AlgebraInfo>() && b.GetComponent <AlgebraInfo>())) { return(false); } } if (b.combineLayer > a.greaterThanCombine && b.combineLayer < a.lessThanCombine && a.combineLayer > b.greaterThanCombine && a.combineLayer < b.lessThanCombine) { return(true); } return(false); // List<CombineTest> greaterCheck = new List<CombineTest> { CombineTest.Always,CombineTest.Greater,CombineTest.GreaterOrEqual,CombineTest.NotEqual }; // List<CombineTest> lesserCheck = new List<CombineTest> { CombineTest.Always,CombineTest.Less,CombineTest.LessOrEqual,CombineTest.NotEqual }; // List<CombineTest> equalCheck = new List<CombineTest> { CombineTest.Always,CombineTest.LessOrEqual,CombineTest.GreaterOrEqual,CombineTest.Equal }; // if (a.combineLayer > b.combineLayer) { // if (lesserCheck.Contains(a.combineTest) && greaterCheck.Contains(b.combineTest)) { // return true; //// } else { // } // } // if (a.combineLayer < b.combineLayer){ // if (greaterCheck.Contains(a.combineTest) && lesserCheck.Contains(b.combineTest)) { // return true; // } else { // } // } // // if (a.combineLayer == b.combineLayer){ // if (equalCheck.Contains(a.combineTest) && greaterCheck.Contains(b.combineTest)) { // return true; // } else { // } // } // return false; }
public bool CheckValidTarget(AnimalTargetPreferenceRel tpr, Animal an, NumberInfo targetNi, bool careAboutRigidbodies = true) // Transform target) { { if (targetNi.myShape == NumberShape.Tetrahedron || targetNi.myShape == NumberShape.Ghost) { return(false); } if (careAboutRigidbodies && !targetNi.GetComponent <Animal>()) { if (targetNi.GetComponent <Rigidbody>()) { if (targetNi.GetComponent <Rigidbody>().isKinematic) { return(false); } } else if (!targetNi.transform.parent) // if we found a non-rigidbody with no parent ignore it { return(false); } else if (!targetNi.transform.parent.GetComponent <LevelMachinePrefab_NumberFlower>()) // if the parent was a flower, let it be targeted, else return false { return(false); } } // Debug.Log("here1"); Animal selfCheck = targetNi.GetComponent <Animal>(); if (selfCheck) { if (selfCheck == an) { return(false); } } if (!targetNi) { return(false); } // Debug.Log("here2"); Fraction targetFrac; // if (targetNi.transform.tag == "Player"){ // targetFrac = Player.inst.PlayerHoldingNumberInfo(); // } else { targetFrac = targetNi.fraction; // } if (!tpr.cannibalize && TargetAndAnimalAreSameType(an, targetNi.transform)) { return(false); // Debug.Log("!! here2"); } // Debug.Log("here"); return(CheckValidTarget(tpr, an, targetFrac)); }
public override void ModifyAmmo(NumberModifier.ModifyOperation fn) { if (numberHeld) { NumberInfo ni = numberHeld.GetComponent <NumberInfo>(); if (!ni) { return; } Fraction fracc = fn(ni.fraction); // commented Debug.Log("set ni:"+fracc); ni.SetNumber(fracc); MonsterAIRevertNumber mairn = ni.GetComponent <MonsterAIRevertNumber>(); if (mairn) { mairn.SetNumber(ni.fraction); } if (fracc.numerator == 0) { DropAmmo(true); NullifyAmmo(); } UpdateAmmoGraphics(true); // commented Debug.Log("modified! "); } // RecalcInfoText(); }
void Trigger(GameObject other) { // if (grabbing) return; NumberInfo ni = other.GetComponent <NumberInfo>(); if (ni) { AudioManager.inst.PlayCartoonEat(ni.transform.position, 0.8f); ni.transform.position = startPos.position; ni.GetComponent <Rigidbody>().isKinematic = true; ni.GetComponent <Collider>().enabled = false; grabbingNumbers.Add(ni); grabTimer = 0; } }
void EatNumbers() { eating = true; numberLeft.GetComponent <Collider>().enabled = false; numberRight.GetComponent <Collider>().enabled = false; AudioManager.inst.PlayCartoonEat(transform.position, 1, .8f); eatTimer = 1.5f; }
public static bool IsCombineable(NumberInfo ni) { // A special case check for resource numbers and Schur puzzle numbers, which still use NumberInfos but are not modifyable or combineable (to each other or gadgets..). if (ni == null) { return(false); } if (ni.GetComponent <ResourceNumber>()) { return(false); } if (ni.GetComponent <CauldronNumber>()) { return(false); } return(true); }
void OnCollisionEnter(Collision hit) { NumberInfo ni = hit.collider.GetComponent <NumberInfo>(); if (ni && !ni.GetComponent <ResourceNumber>()) { transform.root.GetComponent <LevelMachine_DanMeyerCubes>().TrySolve(ni); } }
public void TrySolve(NumberInfo ni) { if (cubeState == CubeState.Ready) { StartCoroutine(Solving(ni.fraction)); float kickForce = 400f; // get thatwrong answer away from me! ni.GetComponent <Rigidbody>().AddForce((ni.transform.position - editorCameraParent.position) * kickForce); } }
public override void PostModifyNumber(Fraction original, NumberInfo ni) { base.PostModifyNumber(original, ni); MonsterAIRevertNumber revert = ni.GetComponent <MonsterAIRevertNumber>(); if (revert) { revert.SetNumber(ni.fraction); } }
void SetUpNumberGraphics(NumberInfo ni) { if (ni.GetComponent <PickUppableObject>().inventoryIcon != null) { // commented Debug.Log("inv icon not null"); GetComponent <Image>().sprite = ni.GetComponent <PickUppableObject>().inventoryIcon; return; } // // commented Debug.Log("ni getcomp playerpickup invicon null on;"+ni); if (ni.fraction.numerator > 0) { GetComponent <Image>().sprite = ni.myShape == NumberShape.Sphere ? Inventory.inst.sprites.posNumSphere : Inventory.inst.sprites.posNumCube; } else { GetComponent <Image>().sprite = ni.myShape == NumberShape.Sphere ? Inventory.inst.sprites.negNumSphere : Inventory.inst.sprites.negNumCube; } }
void FinishStack(NumberStack ns) { NumberInfo ni = ns.stackingNumber; MonsterAIBase maib = ni.GetComponent <MonsterAIBase>(); if (maib) { maib.enabled = true; } foreach (Renderer r in ns.hiddenRends) { r.enabled = true; } if (ni.GetComponent <Rigidbody>()) { ni.GetComponent <Rigidbody>().isKinematic = ns.kinematic; ni.GetComponent <Rigidbody>().useGravity = ns.useGravity; } PickUppableObject pip = ni.GetComponent <PickUppableObject>(); if (pip) { pip.enabled = true; } ns.stackingNumber.SetNumber(Fraction.Multiply(ns.stackingNumber.fraction, new Fraction(ns.stackHeight, 1)), true); EffectsManager.inst.RevertSparks(ns.stackingNumber.transform.position, 2); AudioManager.inst.PlayCrystalThump1(ns.stackingNumber.transform.position); // if (ni.GetComponent<Rigidbody>()) ni.GetComponent<Rigidbody>().isKinematic = false; // ni.GetComponent<Collider>().enabled = true; ni.enabled = true; foreach (GameObject o in ns.stackedGhosts) { foreach (IMuteDestroySound mute in o.GetComponents(typeof(IMuteDestroySound))) { mute.MuteDestroy(); } Destroy(o); } // note the stack is not destroyed here beacuse this method is called in an iterator blcok over the list // can't take one out int he middle of iteration, so it's taken care of after the loop finishes in update() }
public override bool CanCollectNumber(NumberInfo ni) { if (ni) { if (ni.GetComponent <ResourceNumber>()) { return(false); } } // // commented Debug.Log ("ammo: "+rocketAmmo.Count); return(compounderAmmo == null); }
// public Transform excludeRootFromRocketExplosion; public void OnTouchedSomething(Collider other) { NumberInfo ni = other.gameObject.GetComponent <NumberInfo>(); if (ni && ni.enabled && enabled) { if (!GetComponent <DoesExplodeOnImpact>() && !ni.GetComponent <DoesExplodeOnImpact>()) { AttemptCombine(ni); } } }
bool IsValidTarget(NumberInfo ni) { if (ni.GetComponent <BlobNumber>()) { return(false); } if (ni.GetComponent <MonsterSnail>()) { return(false); } float attackRange = 35f; if (Vector3.Distance(ni.transform.position, transform.position) < attackRange) { // Debug.Log("Is valid:"+ni+","+ni.myName+",val;"+ni.fraction+"?"); // Debug.Log("range"); if (type == SnailType.Multiples) { foreach (NumberInfo n2 in blobNumbers) { if (ni.fraction.IsMultipleOf(n2.fraction)) { return(true); } } } else if (type == SnailType.Factors) { foreach (NumberInfo n2 in blobNumbers) { if (n2.fraction.IsMultipleOf(ni.fraction)) { return(true); } } } } return(false); }
void OnTriggerEnter(Collider other) { if (LevelBuilder.inst.levelBuilderIsShowing) { return; } NumberInfo ni = other.GetComponent <NumberInfo>(); if (ni && ni.fraction.denominator == 1 && !ni.GetComponent <BlobNumber>()) { if (blobNumbers.Contains(ni)) { return; } else { List <NumberInfo> numsToAdd = new List <NumberInfo>(); bool allowedToAddThisNumber = false; foreach (NumberInfo n2 in blobNumbers) { Fraction result = Fraction.Add(ni.fraction, n2.fraction); if (type == SnailType.Factors && n2.fraction.IsMultipleOf(ni.fraction) && !allowedToAddThisNumber) { allowedToAddThisNumber = true; // break; } else if (type == SnailType.Multiples && ni.fraction.IsMultipleOf(n2.fraction) && !allowedToAddThisNumber) { allowedToAddThisNumber = true; // break; } // } } if (allowedToAddThisNumber) { numsToAdd.Add(ni); } foreach (NumberInfo numToAdd in numsToAdd) { AddNumberToBlob(numToAdd); } } } }
public override bool CanCollectNumber(NumberInfo ni) { // Collecting same number already loaded? Then reload. if (!ni) { return(false); } if (ni.GetComponent <ResourceNumber>()) { return(false); } if (bulletAmmo.Count > 0) { if (Fraction.Equals(bulletAmmo[0].ammoValue, ni.fraction) && bulletAmmo.Count != maxAmmo) { ClearAmmo(); return(true); } } // else only load new number if empty. return(bulletAmmo.Count <= 0); }
public void OnTriggerEnter(Collider other) { // if(Network.isClient) { return; } NumberInfo ni = other.GetComponent <NumberInfo>(); if (ni && ni.enabled) { // if(touched.Contains(ni)) { return; } // touched.Add(ni); if (Fraction.Subtract(ni.fraction, waveFrac1).numerator == 0) { Rigidbody rb = ni.GetComponent <Rigidbody>(); if (ni.myShape == NumberShape.Sphere && !rb) { rb = ni.gameObject.AddComponent <Rigidbody>(); } if (rb) { float bounceForce = 10000f; rb.AddForce(transform.forward * bounceForce); EffectsManager.inst.CreateSmallPurpleExplosion(ni.transform.position, 1, 1); AudioManager.inst.PlayCrystalThump1(other.transform.position); } // Destroy(ni.gameObject); } else { // Debug.Log("hit frac:"+ni.fraction+" with wave:"+waveFrac1); } // ni.SetNumber(ni.fraction); } }
void AddNumberToBlob(NumberInfo ni) { ni.greaterThanCombine = 0; ni.lessThanCombine = 1; // re-allow combos Animal a = ni.GetComponent <Animal>(); if (a) { a.animalDisabled = true; // disable animal for consumption, but don't "destroy" or change it. } targetCheckTimer = Random.Range(2f, 4f); if (type == SnailType.Multiples) { bool proceed = false; // only proceed if we matched a number. Other numbers will be deconstructed. foreach (NumberInfo n2 in blobNumbers) { if (Fraction.Equals(Fraction.GetAbsoluteValue(n2.fraction), Fraction.GetAbsoluteValue(ni.fraction))) { proceed = true; break; } } if (!proceed) // This happens when a larger multiple was broken down into smaller ones. We stop the checking process, break it up, and eat each piece. // Debug.Log("donot"); { List <NumberInfo> numsToAdd = new List <NumberInfo>(); foreach (NumberInfo n2 in blobNumbers) { if (ni.fraction.IsMultipleOf(n2.fraction)) { int count = Mathf.Abs(Fraction.Divide(ni.fraction, n2.fraction).numerator); ni.SetNumber(n2.fraction); // important to set the number before instantiation because cctext will lose mesh / mesh 0 vertices if you reverse this // Debug.Log("set"); for (int i = 0; i < count; i++) { // if an 8 is eaten by a Multiple Snal, it makes 4 2's in front of it and eats them one by one. GameObject newNum = (GameObject)Instantiate(ni.gameObject, ni.transform.position + transform.forward * i * 3f, Quaternion.identity); NumberInfo ni3 = newNum.GetComponent <NumberInfo>(); numsToAdd.Add(ni3); newNum.GetComponent <Rigidbody>().useGravity = false; ni3.greaterThanCombine = 1; // prevent combos. ni3.lessThanCombine = 0; // eatingNumbers.Add(ni); // ni.GetComponent<Collider>().enabled = false; // Debug.Log("add:"+newNum); } NumberManager.inst.DestroyOrPool(ni); break; } } foreach (NumberInfo n3 in numsToAdd) { AddNumberToBlob(n3); // Debug.Log("adding;"+n3); } return; // after a dconstruction don't add anything to blob, add all the deconstructed pieces individualy in the for loop above. } } eatingNumbers.Add(ni); ni.GetComponent <Collider>().enabled = false; ni.transform.parent = transform; ni.InitSinGrowAttributes(0.5f, true); Rigidbody rb = ni.GetComponent <Rigidbody>(); if (ni.GetComponent <PickUppableObject>()) { Destroy(ni.gameObject.GetComponent <PickUppableObject>()); } if (!rb) { rb = ni.gameObject.AddComponent <Rigidbody>(); } rb.isKinematic = false; rb.drag = 3f; ni.gameObject.AddComponent <BlobNumber>(); rb.useGravity = false; // if ( blobNumbers.Add(ni); }
IEnumerator SplitNumberE(NumberInfo ni, NumberInfo fin) { ni.GetComponent <Rigidbody>().useGravity = false; // ni.GetComponent<Rigidbody>().isKinematic = true; ni.GetComponent <Rigidbody>().drag = 1.5f; float t = 0; float floatTime = 0.5f; float floatSpeed = 4f; float minDistToGround = 10f; while (t < floatTime) { t += Time.deltaTime; if (!ni) { yield break; } if (Physics.Raycast(ni.transform.position, Vector3.down, minDistToGround, ~LayerMask.NameToLayer("Terrain"))) { ni.transform.position += Vector3.up * Time.deltaTime * floatSpeed; // // commented Debug.Log ("up!"); } yield return(new WaitForSeconds(Time.deltaTime)); } ni.GetComponent <Collider>().enabled = false; Destroy(ni.gameObject); t = 0; float splitTime = 1.2f; float splitSpeed = 1.3f; // float splitForce = 50; int splitQty = fin.fraction.numerator; //Fraction.Divide(ni.fraction,f).numerator; Dictionary <GameObject, Vector3> splitNums = new Dictionary <GameObject, Vector3>(); Vector3 newSplitDir = transform.right; if (splitDirDict.ContainsKey(ni) && splitDirDict[ni] == transform.right) { newSplitDir = transform.up; } for (int i = 0; i < splitQty; i++) { if (!ni) { yield break; } GameObject newNum = NumberManager.inst.CreateNumber(Fraction.Divide(ni.fraction, fin.fraction), ni.transform.position); SMW_GF.inst.DrawLineFromTo(fin.transform, ni.transform, Color.yellow); newNum.transform.localScale = Vector3.one * 3; newNum.GetComponent <Rigidbody>().useGravity = false; // newNum.GetComponent<Rigidbody>().isKinematic = true; newNum.GetComponent <Rigidbody>().drag = 2.5f; newNum.GetComponent <Collider>().enabled = false; newNum.transform.parent = transform; Destroy(newNum.GetComponent <PickUppableObject>()); splitNums.Add(newNum, Quaternion.AngleAxis(360f / splitQty * i, transform.forward) * newSplitDir); splitDirDict.Add(newNum.GetComponent <NumberInfo>(), newSplitDir); } bool colsFlipped = false; while (t < splitTime) { t += Time.deltaTime; foreach (KeyValuePair <GameObject, Vector3> kvp in splitNums) { if (kvp.Key != null) { if (Physics.Raycast(kvp.Key.transform.position, Vector3.down, minDistToGround, LayerMask.NameToLayer("Terrain"))) { kvp.Key.transform.position += Vector3.up * Time.deltaTime * floatSpeed; // // commented Debug.Log ("up2!"); } kvp.Key.transform.position += kvp.Value * Time.deltaTime * splitSpeed; if (t > splitTime / 3f && !colsFlipped) { colsFlipped = true; kvp.Key.GetComponent <Collider>().enabled = true; } // kvp.Key.GetComponent<Rigidbody>().velocity = kvp.Value * Time.deltaTime * splitSpeed; } } yield return(new WaitForSeconds(Time.deltaTime)); } foreach (KeyValuePair <GameObject, Vector3> kvp in splitNums) { if (kvp.Key) { kvp.Key.GetComponent <Rigidbody>().useGravity = true; // kvp.Key.GetComponent<Rigidbody>().isKinematic = false; kvp.Key.GetComponent <Collider>().enabled = true; kvp.Key.AddComponent <PickUppableObject>(); // StartCoroutine(ReduceDragAfterSeconds(kvp.Key.GetComponent<Rigidbody>(),2f)); } } ClearDeadSplitDirDict(); // ClearAffectedNumbers(); }
float numberStackFXDuration = 6f; // the total length of time the stack lasts (regardless of how close the "ghost "numbers are together in the end) public void CreateNumberStack(NumberInfo ni, int stackHeight) { NumberStack newStack = new NumberStack(); ni.enabled = false; PickUppableObject pip = ni.GetComponent <PickUppableObject>(); if (pip) { pip.enabled = false; } MonsterAIBase maib = ni.GetComponent <MonsterAIBase>(); if (maib) { maib.enabled = false; } // the stack of fx numbers will be positive or negative depending on the result. int resultSign = ni.fraction.numerator * stackHeight > 0 ? 1 : -1; Fraction resultFrac = Fraction.Multiply(Fraction.GetAbsoluteValue(ni.fraction), new Fraction(resultSign, 1)); // Debug.Log("stack:"+stackHeight+", restul;"+resultFrac+", ni frac;"+ni.fraction+", resultsign:"+resultSign); for (int i = 0; i < Mathf.Abs(stackHeight); i++) { GameObject numberAmmo = (GameObject)Instantiate(ni.gameObject); numberAmmo.GetComponentInChildren <NumberInfo>().SetNumber(resultFrac); // destroys if zero. Rigidbody rb = numberAmmo.GetComponent <Rigidbody>(); if (rb) { Destroy(rb); } Collider c = numberAmmo.GetComponent <Collider>(); if (c) { Destroy(c); } Vector3 fixzfighting = UnityEngine.Random.insideUnitSphere * .01f; numberAmmo.transform.position = ni.transform.position + Vector3.up * i * Utils.RealHeight(ni.transform) * 1.14f + fixzfighting; // ni.transform.localScale.x; newStack.stackedGhosts.Add(numberAmmo); } foreach (Renderer r in ni.GetComponentsInChildren <Renderer>()) { if (r.enabled) { r.enabled = false; newStack.hiddenRends.Add(r); } } newStack.stackTime = numberStackFXDuration; newStack.stackingNumber = ni; newStack.stackHeight = stackHeight; newStack.sign = stackHeight > 0 ? 1 : -1; if (ni.GetComponent <Rigidbody>()) { newStack.kinematic = ni.GetComponent <Rigidbody>().isKinematic; newStack.useGravity = ni.GetComponent <Rigidbody>().useGravity; ni.GetComponent <Rigidbody>().useGravity = false; ni.GetComponent <Rigidbody>().isKinematic = true; } // if (ni.GetComponent<Rigidbody>()) ni.GetComponent<Rigidbody>().isKinematic = true; // ni.GetComponent<Collider>().enabled = false; // Debug.Log("added newstack. ghosts;"+newStack.stackedGhosts[0]); numberStacks.Add(newStack); }
void CutInHalf(Collider collider) { // // commented Debug.Log ("cut1. swinging:"+swinging+", hitnumberonthisswing:"+hitNumberOnThisSwing); if (swinging && !hitNumberOnThisSwing) // && bNeedsSphereCheck){ // // commented Debug.Log ("cut12"); { hitNumberOnThisSwing = true; AnalyticsManager.inst.RecordEvent(AnalyticsManager.Keys.numberChopped, 1); //++; GameObject other = collider.gameObject; NumberInfo ni = other.GetComponent <NumberInfo>(); if (ni) { // // commented Debug.Log ("cut13"); // if (ni.myShapes if (IsValidSwordTarget(other)) { // // commented Debug.Log ("cut14"); other.SendMessage("OnCutInHalf", SendMessageOptions.DontRequireReceiver); other.SendMessage("OnDestroy", SendMessageOptions.DontRequireReceiver); // // commented Debug.Log("hit ni wihtout kin:"+ni.gameObject.name); Fraction result = Fraction.Multiply(ni.fraction, new Fraction(1, 2), true); // Calculate the resulting fraction as half of the original ni.SetNumber(result); if (!ni.gameObject.GetComponent <SwordChoppedNumber>()) { ni.gameObject.AddComponent <SwordChoppedNumber>(); // when cloned, both left and right nums will have this, which prevents them from combining with other sword chopped numbers for a hile. } ni.GetComponent <Rigidbody>().drag = 1; // Fraction result2 = Fraction.Subtract(ni.fraction, result1, true); // // commented Debug.Log ("frac subtract 1/2048, 1/4096:"+ NumberShape numShape = ni.myShape; float splitDistance = ni.transform.localScale.x / 1.4f; // 1.5f; // if (ni.numberIsAlive) splitDistance += ni.transform.localScale.x; Vector3 rightDir = Player.inst.transform.right * splitDistance; Vector3 rightPos = other.transform.position + rightDir + Vector3.up; // new locations are just "player relative" left and right of the original object (slices resulting from being sliced in half should be in positions that "make sense" and or "feel right") Vector3 leftPos = other.transform.position + -rightDir + Vector3.up; GameObject numLeft = (GameObject)Instantiate(ni.gameObject, leftPos, Quaternion.identity); GameObject numRight = (GameObject)Instantiate(ni.gameObject, rightPos, Quaternion.identity); // NumberManager.inst.CreateNumber(result2,rightPos,numShape,true, ni.isPercent); // weird unresolved bug todo vadim // When sword breaks a 1 into 1/2, the 1/2 is not rendered in resulting spheres // If you chop the 1/2 it does render 1/4 in the resulting spheres // if you combine two 1/4 to 1/2 it does render // debug yields that vertex count of cctext when its not being rendered is zero // probably due to instantiating the object and messing with cctext in the same frame, something is not getting initialized. // solution?? interestingly, set the number BEFORE instantiating the copies. e.g. when you chop a 1, set the 1 to 1/2, then instantiate two copies of it and destroy the original // something about instantiating and THEN setting the number was causing CCText to product empty vertex arrays for the text object ni.GetComponent <Collider>().enabled = false; // foreach(CCText t in ni.GetComponentsInChildren<CCText>()){ //// t.enabled = true; // } // // commented Debug.Log ("result 1, 2: "+result1+","+result2); // numLeft.GetComponent<NumberInfo>().SetNumber(result1); // numRight.GetComponent<NumberInfo>().SetNumber(result2); // numLeft.transform.localScale = Vector3.one * ni.transform.localScale.x; // numRight.transform.localScale = Vector3.one *ni.transform.localScale.x; // if (ni.numberIsAlive){ // numLeft.name += "--Left"; // numRight.name += "--Right"; // //// float extraSpace=15; // numLeft.transform.localScale = ni.transform.localScale*0.79370052598f; // the half-volume radius // numRight.transform.localScale = ni.transform.localScale*0.79370052598f; // // Make that number seek its partner and attempt to re-combine into one spikey. //// NumberManager.inst.TurnNumberIntoMonster(numLeft,ni.mt); //// NumberManager.inst.TurnNumberIntoMonster(numRight,ni.mt); // // numLeft.transform.parent=ni.transform.parent; // numRight.transform.parent=ni.transform.parent; // //// NumberInfo ni1 = numLeft.GetComponent<NumberInfo>(); //// NumberInfo ni2 = numRight.GetComponent<NumberInfo>(); //// ni1.SetMatchingPartner(numRight); //// ni2.SetMatchingPartner(numLeft); //// ni1.SetMaxNumber(ni.maxNumber); //// ni2.SetMaxNumber(ni.maxNumber); // TODO: This should be refactored? It's a way for spikeys to keep track of whether or not they should //// ni1.seekPartner=true; //// ni2.seekPartner=true; // // seek partners and try to recombine with other spikeys with the same number or not. // // // Set MARN to the original NI value, so that after it combines adn is no longer "seeking", it will not MARN back to the half value. //// MonsterAIRevertNumber marn1 = numLeft.GetComponent<MonsterAIRevertNumber>(); //// MonsterAIRevertNumber marn2 = numRight.GetComponent<MonsterAIRevertNumber>(); //// if (marn1) { marn1.origFrac=ni.fraction; marn1.bNeedsRevert=false; } //// if (marn2) { marn2.origFrac=ni.fraction; marn2.bNeedsRevert=false; } // //// // commented Debug.Log("num left ("+numLeft.name+") origfrac: "+numLeft.GetComponent<MonsterAIRevertNumber>().origFrac); // // // } collected = false; collectedFrac = new Fraction(2, 1); // make the numbers roll away from each other a bit after chopping float rollForce = 300f; // if (ni.numberIsAlive) rollForce*=2; numLeft.GetComponent <Rigidbody>().AddForce(-rightDir * rollForce); numRight.GetComponent <Rigidbody>().AddForce(rightDir * rollForce); // if(Network.isServer) { // ni.NetworkDestroy(); // } // else { NumberManager.inst.DestroyOrPool(ni); // } } } } }
void AddNumberToCauldron(NumberInfo ni) { // Debug.Log("Collecting:"+ni.fraction); List <NumberInfo> conflictingNumbers = GetConflictingNumbers(ni); if (conflictingNumbers.Count > 0) { // freeze puzzle FindObjectOfType <LevelMachineCauldronManager>().puzzleFrozen = true; // destroy other numbers foreach (LevelMachineCauldron lmc in FindObjectsOfType <LevelMachineCauldron>()) { lmc.ConflictDetected(conflictingNumbers); } // raise two numbers and new conflicting number up risingNumbers.AddRange(conflictingNumbers); Destroy(ni.GetComponent <Collider>()); Destroy(ni.GetComponent <Rigidbody>()); risingNumbers.Add(ni); foreach (NumberInfo nii in risingNumbers) { // nii.transform.localScale = Vector3.one * 3.5f; nii.SinGrowOnce(); } // lightning fx SMW_GF.inst.CreateLightning(risingNumbers[0].transform, risingNumbers[2].transform, 5.5f, true); SMW_GF.inst.CreateLightning(risingNumbers[1].transform, risingNumbers[2].transform, 5.5f, true); // both numbers break StartCoroutine(BreakOffendingNumbersAfterSeconds(5.6f)); // explosion // reset cauldron StartCoroutine(ResetPuzzleAfterSeconds(5.7f)); } else { float sqrDist = Vector3.SqrMagnitude(ni.transform.position - surfaceCenter.transform.position); if (ni.GetComponent <PickUppableObject>()) { Destroy(ni.GetComponent <PickUppableObject>()); } if (sqrDist > 10) { // if the number is far away from the cauldron (e.g. was just thrown in at the edge), add a bit to the yvalue to avoid the number clipping through the lip of the caudrlon ni.transform.position = new Vector3(ni.transform.position.x, surfaceCenter.position.y + 0.6f, ni.transform.position.z); } // Debug.Log("name:"+name+" send on col mes:"); FindObjectOfType <NumberFaucetSequential>().OnNumberCollectedIntoCauldron(); CollectedNumber cald = new CollectedNumber(); cald.ni = ni; cald.dest = GetRandomTargetPos(); Destroy(ni.GetComponent <CauldronNumber>()); ni.transform.localScale = Vector3.one * 1.5f; collectedNumbers.Add(cald); //ni,GetRandomTargetPos()); ni.gameObject.layer = LayerMask.NameToLayer("DontCollideWithPlayer"); ni.GetComponent <Rigidbody>().useGravity = false; ni.GetComponent <Rigidbody>().velocity = Vector3.zero; ni.GetComponent <Rigidbody>().drag = 1; } }
void CreateTowerPiece(int i) { Fraction fr = baseFraction; if (info.type == NumberTowerType.Simple) { // fr is always base fraction. } if (info.type == NumberTowerType.Addition) { fr = Fraction.Add(baseFraction, Fraction.Multiply(new Fraction(i, 1), baseFraction)); } else if (info.type == NumberTowerType.Multiplication) { fr = new Fraction(Mathf.Pow(baseFraction.numerator, i), baseFraction.denominator); } GameObject towerPiece = null; if (i == towerHeightMin - 1) { // Debug.Log("fr:"+fr); if (info.type == NumberTowerType.Simple) { towerPiece = NumberManager.inst.CreateNumber(fr, transform.position, NumberShape.Face); } else if (info.type == NumberTowerType.Addition) { towerPiece = NumberManager.inst.CreateNumber(fr, transform.position, NumberShape.SimpleHat); } else if (info.type == NumberTowerType.Multiplication) { towerPiece = NumberManager.inst.CreateNumber(fr, transform.position, NumberShape.Hat); } } else { towerPiece = NumberManager.inst.CreateNumber(fr, transform.position, NumberShape.Sphere); } towerPiece.GetComponent <NumberInfo>().numberChangedDelegate += ChildChanged; towerPiece.GetComponent <NumberInfo>().numberDestroyedDelegate += RemoveChildChanged; towerPiece.transform.parent = transform; UserEditableObject ueo = towerPiece.GetComponent <UserEditableObject>(); ueo.isSerializeableForSceneInstance = false; NumberInfo ni = towerPiece.GetComponent <NumberInfo>(); Destroy(ni.GetComponent <PickUppableObject>()); ni.GetComponent <Rigidbody>().isKinematic = true; ni.GetComponent <Rigidbody>().useGravity = false; ni.transform.localScale = Vector3.one * pieceSize; MonsterAIRevertNumber mairn = towerPiece.AddComponent <MonsterAIRevertNumber>(); mairn.SetNumber(ni.fraction); if (towerPieces.ContainsKey(i)) { // if (towerPieces[i] && towerPieces[i].gameObject){ // Destroy(towerPieces[i].gameObject); // } } towerPieces.Add(i, ni); float pitch = 0.5f + 0.5f * ((i + 1f) / (towerHeightMin)); // Debug.Log("pitch "+pitch+" for i:"+i); if (!LevelBuilder.inst.levelBuilderIsShowing) { AudioManager.inst.PlayBubblePop(transform.position, pitch); } // ni.childMeshRenderer.enabled = false; // ni.outlineMesh.enabled = false; // these are invisible by default, we want to enable them SetPositionForTowerPiece(i); EffectsManager.inst.RevertSparks(ni.transform.position, 2); }
bool IsValidInput(NumberInfo ni) { return(!ni.GetComponent <DoesExplodeOnImpact>() && !ni.GetComponent <ShrinkAndDisappear>()); }
static void ResolveCollision(CollisionPair pair) { if (pair.a == null || pair.b == null || pair.a.gameObject == null || pair.b.gameObject == null) { return; } NumberInfo a = pair.a; NumberInfo b = pair.b; if (a.transform.parent == b.transform.parent && b.transform.parent != null) { return; } // don't combine from same generator // if (a.transform.parent.GetComponent<AISpikeyGenerator>() && b.tran if (a.destroyedThisFrame || b.destroyedThisFrame) { return; } if (a.GetComponent <SoapedNumber>() && b.GetComponent <SoapedNumber>()) { return; } // soaped number don't combine with each other. if (a.GetComponent <TemporaryPreventCombine>() || b.GetComponent <TemporaryPreventCombine>()) { return; } // numbers chopped with sword won't recombine. This behavior is destoyed on player pickup. if (a.GetComponent <BlobNumber>() || b.GetComponent <BlobNumber>()) { // if (a.GetComponent<MonsterSnail>() || b.GetComponent<MonsterSnail>()) { return; } // blob monsters if (a.GetComponent <BlobNumber>() && b.GetComponent <Rigidbody>() && !b.GetComponent <Rigidbody>().isKinematic) { a.Eat(b); } else if (b.GetComponent <BlobNumber>() && a.GetComponent <Rigidbody>() && !a.GetComponent <Rigidbody>().isKinematic) { b.Eat(a); } } else if (a.GetComponent <MonsterAISpikey1>() || b.GetComponent <MonsterAISpikey1>()) { if (a.GetComponent <MonsterAISpikey1>() && b.GetComponent <MonsterAISpikey1>()) { return; } // spikey' dont eat each other else if (!a.GetComponent <Rigidbody>() || !b.GetComponent <Rigidbody>()) { return; } // spikeys dont interact with non rigidbodies else if (a.GetComponent <Rigidbody>() && a.GetComponent <Rigidbody>().isKinematic) { return; } // spikeys dont eat kinematics. else if (b.GetComponent <Rigidbody>() && b.GetComponent <Rigidbody>().isKinematic) { return; } // spikeys dont eat kinematics. else if (a.GetComponent <MonsterAISpikey1>() && !b.GetComponent <MonsterAISpikey1>()) { a.Eat(b); } // spikeys eat regular num else if (!a.GetComponent <MonsterAISpikey1>() && b.GetComponent <MonsterAISpikey1>()) { b.Eat(a); } } else if (a.fraction.numerator == -b.fraction.numerator && a.fraction.denominator == b.fraction.denominator) { // DestroyedFX(a.transform,b.tran); // b.DestroyedFX(); a.ZeroFX(a.transform.position); a.GemFX(); b.ZeroFX(b.transform.position); b.GemFX(); Destroy(a.gameObject); //if (a.myShape == NumberShape.Cube) NumberPool.inst.DestroyOrPool (a); // else Destroy(a.gameObject); Destroy(b.gameObject); //if (b.myShape == NumberShape.Cube) NumberPool.inst.DestroyOrPool (b); // else Destroy(b.gameObject); SMW_FX.CreateSmallPurpleExplosion(a.transform.position); //,1.5f,.5f); SMW_FX.CreateWhiteFlash(a.transform.position); //,20f,.3f); SMW_FX.CreateShards(a.transform.position); SMW_FX.CreateTextEffect(a.transform.position, "zero"); a.destroyedThisFrame = true; b.destroyedThisFrame = true; // a.DestroyedFX(); // AudioManager.inst.PlayNumberShatter(a.transform.position); return; } else if (a.myShape == NumberShape.Cube && b.myShape == NumberShape.Sphere) { a.Eat(b); } else if (a.myShape == NumberShape.Sphere && b.myShape == NumberShape.Cube) { b.Eat(a); } else if (a.myShape == NumberShape.Cube && b.myShape == NumberShape.Cube) { if (a.gameObject.GetComponent <Rigidbody>() && !b.gameObject.GetComponent <Rigidbody>()) { b.Eat(a); } else if (b.gameObject.GetComponent <Rigidbody>() && !a.gameObject.GetComponent <Rigidbody>()) { a.Eat(b); } } else if (a.gameObject.GetComponent <Rigidbody>() && a.gameObject.GetComponent <Rigidbody>().isKinematic) { a.Eat(b); } else if (b.gameObject.GetComponent <Rigidbody>() && b.gameObject.GetComponent <Rigidbody>().isKinematic) { b.Eat(a); } else if (a.neverEats) { b.Eat(a); } else if (b.neverEats) { a.Eat(b); } else if (a.combineLayer > b.combineLayer) { a.Eat(b); } else if (a.combineLayer < b.combineLayer) { b.Eat(a); } else if (a.gameObject == PlayerGadgetController.inst.thrownNumber) { b.Eat(a); } else if (b.gameObject == PlayerGadgetController.inst.thrownNumber) { a.Eat(b); } else if (a.GetComponent <SoapedNumber>() && !b.GetComponent <SoapedNumber>()) { a.Eat(b); } else if (b.GetComponent <SoapedNumber>() && !a.GetComponent <SoapedNumber>()) { b.Eat(a); } else if (a.gameObject.GetComponent <Rigidbody>() && b.gameObject.GetComponent <Rigidbody>()) { float velA = a.gameObject.GetComponent <Rigidbody>().velocity.sqrMagnitude; float velB = b.gameObject.GetComponent <Rigidbody>().velocity.sqrMagnitude; if (velA < velB) { a.Eat(b); } else { b.Eat(a); } } else if (Fraction.AbsGreater(a.fraction, b.fraction)) { a.Eat(b); } else if (Fraction.AbsGreater(b.fraction, a.fraction)) { b.Eat(a); } }