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();
 }
Ejemplo n.º 2
0
    public virtual void PlayerHitObject(GameObject hitObj)
    {
        if (PlayerTouched != null)
        {
            PlayerTouched(hitObj);
//			// commented Debug.Log ("delegate fired");
        }
        hitObj.SendMessage("PlayerTouched", SendMessageOptions.DontRequireReceiver);
        if (hitObj == thrownNumber && thrownNumberTimeout > 0)
        {
//			// commented Debug.Log("hit thrown no.");
            return;
        }

        PickUppableObject pip = hitObj.GetComponent <PickUppableObject>();

        if (pip && pip.CanPickUp)
        {
            MonsterAIRevertNumber mairn = hitObj.GetComponent <MonsterAIRevertNumber>();
            if (!mairn || !mairn.bNeedsRevert)
            {
                Inventory.inst.OnPlayerTouchedObject(hitObj);
            }
        }

        if (hitObj.GetComponent <SoapedNumber>())
        {
            PlayerNowMessage.inst.Display("You can't pick up soapy numbers!");
        }
    }
    public override void PostModifyNumber(Fraction original, NumberInfo ni)
    {
        base.PostModifyNumber(original, ni);
        MonsterAIRevertNumber revert = ni.GetComponent <MonsterAIRevertNumber>();

        if (revert)
        {
            revert.SetNumber(ni.fraction);
        }
    }
Ejemplo n.º 4
0
    public void SetNumber(Fraction frac, bool sinGrow = false, bool allowRevert = true)
    {
        frac = Fraction.ReduceFully(frac);

        if (numberChanged != null)
        {
            numberChanged(frac);
        }

        if (numberChangedDelegate != null)
        {
            numberChangedDelegate(this);
        }
        if (frac == null)
        {
            return;
        }
        if (frac.numerator == 0 && destroyIfZero)
        {
//			DestroyedFX();
            ZeroFX(transform.position);
//			if (myShape == NumberShape.Cube){
            Destroy(gameObject);

            GemFX();

            return;
        }
        if (sinGrow)
        {
            SinGrowOnce();
        }

//		if (!transform) return; //? WTF?
        fraction = frac;
        UpdateNumberText();

        SetColor();

        if (!allowRevert)
        {
            MonsterAIRevertNumber mairn = GetComponent <MonsterAIRevertNumber>();
            if (mairn)
            {
                mairn.SetNumber(frac);
            }
            else
            {
            }
        }
        else
        {
        }
    }
Ejemplo n.º 5
0
//	float timeCreatedInSeconds = -1;
//	public float TimeCreatedInSeconds { // since unix epoch
//		get {
//			return timeCreatedInSeconds;
//		}
//		set {
//			timeCreatedInSeconds = value;
//		}
//	}

//	public virtual bool Exclude() { return false; }


    virtual public void CleanObjectForSerialization()
    {
        MonsterAIRevertNumber mairn = GetComponentInChildren <MonsterAIRevertNumber>();

        if (mairn)
        {
            if (mairn.bNeedsRevert)
            {
                mairn.RevertNumber();
            }
        }
    }
Ejemplo n.º 6
0
    [System.NonSerialized] public bool usedThisFrame = false;     // a stop-gap measure to help sheep and machines not eat the same number twice in the same frame.
    public override SimpleJSON.JSONClass GetProperties()
    {
        // TODO: could have an inspector that only looks at what properties are not shared class properites
        SimpleJSON.JSONClass  N     = base.GetProperties();    //new SimpleJSON.JSONClass();
        Fraction              fr    = fraction;
        MonsterAIRevertNumber mairn = GetComponent <MonsterAIRevertNumber>();

        if (mairn.bNeedsRevert)
        {
            fr = mairn.GetOriginalFraction();
        }
        N = JsonUtil.ConvertFractionToJson(Fraction.fractionKey, fr);
        N[JsonUtil.scaleKey].AsInt = JsonUtil.GetScaleAsInt(transform);

        return(N);
    }
Ejemplo n.º 7
0
    void Update()
    {
        t -= Time.deltaTime;
        if (t < 0)
        {
            t = interval + Random.Range(0.1f, 0.4f);            // add random offset to prevent many lights from checking at one frame
            List <NumberInfo> rm = new List <NumberInfo>();
//			Collider[] cols = Physics.OverlapSphere(transform.position,transform.localScale.x/2f);
//			foreach(Collider col in cols){
//				NumberInfo ni = col.GetComponent<NumberInfo>();
//				if (ni) nums.Add(ni);
//			}
            foreach (NumberInfo ni in nums)
            {
                if (!ni)
                {
                    rm.Add(ni);
                }
                else
                {
                    if (Fraction.Equals(ni.fraction, lampNumber.fraction))
                    {
                        ni.SetColor();
                        ni.gameObject.layer = LayerMask.NameToLayer("Default");
//						ni.greaterThanCombine = 1; // don't allow further combinations.
//						ni.lessThanCombine = 0;
                        MonsterAIRevertNumber mairn = ni.GetComponent <MonsterAIRevertNumber>();
                        if (mairn)
                        {
                            mairn.SetNumber(lampNumber.fraction);                             //
                            mairn.RevertNumber();
                        }
                    }
                    else
                    {
                        ni.SetColor(true);                         // transparentify
                        ni.gameObject.layer = LayerMask.NameToLayer("TransparentNumber");
                    }
                }
            }
            foreach (NumberInfo ni in rm)
            {
                nums.Remove(ni);
            }
        }
    }
    void InitiateMyBlocks()
    {
//		Debug.Log ("init.");
        myBlocks = GetComponentsInChildren <NumberInfo>();
        for (int i = 0; i < myBlocks.Length; i++)
        {
            Fraction f = frac;
//			if (i % 2 == 0) {
////				f = Fraction.Multiply(frac,factor); // every other block will be different.
//			}
            NumberInfo ni = myBlocks[i];
            ni.SetNumber(f);
            MonsterAIRevertNumber mr = ni.gameObject.GetComponent <MonsterAIRevertNumber>();

            mr.SetNumber(f);
//			Debug.Log("setting mr;"+f);
        }
    }
 virtual public void SetFraction(Fraction f)
 {
     frac = f;
     frac = Fraction.ReduceFully(f);
     foreach (KeyValuePair <int, GameObject> kvp in createdNumbers)
     {
         if (kvp.Value)
         {
             Fraction ff = GetFractionFromIndex(kvp.Key);
             MonsterAIRevertNumber mairn = kvp.Value.GetComponent <MonsterAIRevertNumber>();
             if (mairn)
             {
                 mairn.SetNumber(ff);
             }
             kvp.Value.GetComponent <NumberInfo>().SetNumber(ff);
         }
     }
     SetSkyCamText();
 }
    public override void SetProperties(SimpleJSON.JSONClass N)
    {
//		// commented Debug.Log("setprop:"+N.ToString());
        base.SetProperties(N);
        if (N.GetKeys().Contains(Fraction.fractionKey))
        {
            foreach (NumberInfo ni in spikeyChildren)
            {
                Fraction f = JsonUtil.ConvertJsonToFraction(Fraction.fractionKey, N);
                frac = f;
                ni.SetNumber(f);
                MonsterAIRevertNumber mairn = ni.GetComponent <MonsterAIRevertNumber>();
                if (mairn)
                {
                    mairn.SetNumber(f);
                }
//				// commented Debug.Log("set spikey num;"+ni.fraction);
            }
        }
    }
    virtual public GameObject MakeSingleBrick(int i, GameObject wallBrick = null)
    {
        Fraction   f      = GetFractionFromIndex(i);
        Quaternion rot    = GetRotationFromIndex(i);
        Vector3    pos    = GetPositionFromIndex(i);
        bool       pickup = false;

        NumberShape shape = NumberShape.Cube;
        // index -> xyz

//		Vector3 pos = PositionFromIndex(i);

        NumberManager nm;


        // // commented Debug.Log("making single brick:"+frac);
        bool numNeedsSet = false;

        if (wallBrick != null)
        {
            numNeedsSet = true;
            wallBrick.transform.position = pos;
        }
        else
        {
            wallBrick = NumberManager.inst.CreateNumber(
                f,
                pos,
                shape);
        }
//		// commented Debug.Log("single brick made:"+wallBrick.name+", frac;"+wallBrick.GetComponent<NumberInfo>().fraction);
        if (!createdNumbers.ContainsKey(i))
        {
            createdNumbers.Add(i, wallBrick);
//			// commented Debug.Log("added to craeted key:"+pos+", craeted ct;"+createdNumbers.Count);
        }
        else
        {
//			// commented Debug.Log("dict key exists!:"+pos+" on :"+name+" for i:"+i);
        }
        NumberInfo ni = wallBrick.GetComponent <NumberInfo>();

        if (numNeedsSet)
        {
            ni.SetNumber(f);
        }
        if (autoRevert)
        {
            MonsterAIRevertNumber mairn = wallBrick.GetComponent <MonsterAIRevertNumber>();
            if (!mairn)
            {
                mairn = wallBrick.AddComponent <MonsterAIRevertNumber>();
            }
        }
        else
        {
            MonsterAIRevertNumber mairn = wallBrick.GetComponent <MonsterAIRevertNumber>();
            if (mairn)
            {
                mairn.enabled = false;
            }
        }

        wallBrick.transform.parent        = transform;
        wallBrick.transform.localRotation = rot;
        wallBrick.transform.localScale    = new Vector3(brickScale, brickScale, brickScale) + fixZFighting;



        NumberInfoDefaults nid = new NumberInfoDefaults(ni, ni.fraction, i);

        if (numbers.Count <= i)
        {
            numbers.Add(nid);
        }
        else
        {
            numbers[i] = nid;
        }

//		// commented Debug.Log("made:"+wallBrick);
        return(wallBrick);
    }
Ejemplo n.º 12
0
    IEnumerator StartAnimationSequenceE(NumberInfo ni)
    {
        yield return(new WaitForSeconds(0.01f));

//		ni.gameObject.SetActive(false);
        ni.enabled = false;
        ni.childMeshRenderer.gameObject.SetActive(false);

        int count = Mathf.RoundToInt(ni.fraction.GetAsFloat());

        List <Fraction> factors = ni.fraction.GetFactors();

        int   factor1 = 0;
        int   factor2 = 0;
        bool  square  = false;
        float result  = Mathf.Sqrt(ni.fraction.GetAsFloat());

        //		// commented Debug.Log ("result:" + result);
        if (Mathf.Round(result) == result)
        {
            factor1 = (int)result;
            factor2 = (int)result;
            square  = true;
        }
        else
        {
            int delta = (int)Mathf.Pow(2, 15);
            for (int i = 0; i < factors.Count - 1; i += 2)
            {
                int d1 = factors[i + 1].numerator - factors[i].numerator;
                //				// commented Debug.Log ("i:"+i+"...." +factors[i].numerator+","+factors[i+1].numerator);
                if (d1 < delta)
                {
                    delta   = factors[i + 1].numerator - factors[i].numerator;
                    factor1 = factors[i].numerator;
                    factor2 = factors[i + 1].numerator;
                }
            }
        }


        float scale = 3.5f;
        Dictionary <GameObject, Vector3> poss = EffectsManager.NumberGrid(factor1, factor2, ni.transform, scale);

        List <GameObject> toCombine = new List <GameObject>();

        foreach (KeyValuePair <GameObject, Vector3> kvp in poss)
        {
            toCombine.Add(kvp.Key);
        }

        //		float scale = 3.5f;
        //		for (int i=0;i<factor1;i++){
        //			for (int j=0;j<factor2;j++){
        //				GameObject one = NumberManager.inst.CreateNumber(new Fraction(1,1),ni.transform.position);
        //				Destroy(one.GetComponent<Rigidbody>());
        //				Destroy(one.GetComponent<Collider>());
        //				one.transform.parent = combineParent.transform;
        //				Vector3 newPos = new Vector3((i-(i/2f))*scale,(j-(j/2f))*scale,0);
        //				toCombine.Add (one);
        //				poss.Add (one,newPos);
        //			}
        //		}



        Transform combineParent = toCombine[0].transform.parent;

        combineParent.transform.parent = ni.transform;
        foreach (GameObject o in toCombine)
        {
            Vector3 dest = ni.transform.position + combineParent.TransformVector(poss[o]);
            SMW_GF.inst.MoveObjTo(o, dest, 3);
        }

        // wait for stuff to get moved
        yield return(new WaitForSeconds(2));

        if (!combineParent)
        {
            yield break;
        }
        if (square)
        {
            GameObject squareGraphic = GameObject.CreatePrimitive(PrimitiveType.Cube);

            squareGraphic.GetComponent <Renderer>().material = squareMat;
            squareGraphic.transform.parent        = combineParent.transform;
            squareGraphic.transform.localPosition = new Vector3(scale * (factor1 - 1) / 4f, scale * (factor2 - 1) / 4f, 0);
            squareGraphic.transform.LookAt(Camera.main.transform);
            squareGraphic.transform.localRotation = Quaternion.identity;


            squareGraphic.transform.localScale = new Vector3(factor1 * 2, factor2 * 2, .1f);
//			squareGraphic.transform.parent = ni.transform;
            AudioManager.inst.PlayComboWin();
            yield return(new WaitForSeconds(2));

            for (int i = 0; i < factor1; i++)
            {
                toCombine[i].GetComponent <NumberInfo>().childMeshRenderer.GetComponent <Renderer>().material.color = new Color(0, 1, 0);
                AudioManager.inst.PlayComboPlus();
                yield return(new WaitForSeconds(0.4f));
            }
            yield return(new WaitForSeconds(1.5f));


            for (int i = factor1; i < toCombine.Count; i++)
            {
                Destroy(toCombine[i]);
            }
            yield return(new WaitForSeconds(0.7f));


            for (int i = 0; i < toCombine.Count; i++)
            {
                if (toCombine[i] != null)
                {
                    SMW_GF.inst.MoveObjTo(toCombine[i], ni.transform.position, 3);
                }
            }
            yield return(new WaitForSeconds(1f));

            ni.enabled = true;
            ni.childMeshRenderer.gameObject.SetActive(true);
            ni.SetNumber(new Fraction(result, 1));
            MonsterAIRevertNumber rev = ni.gameObject.GetComponent <MonsterAIRevertNumber>();
            if (rev)
            {
                rev.SetNumber(new Fraction(result, 1));
            }
        }
        else
        {
            yield return(new WaitForSeconds(2));

            AudioManager.inst.PlayWrongAnswerError(transform.position, 1, 1);
            foreach (GameObject o in toCombine)
            {
                SMW_GF.inst.MoveObjTo(o, ni.transform.position, 3);
            }
            yield return(new WaitForSeconds(2));

            // commented Debug.Log ("4");
            if (combineParent)
            {
                Destroy(combineParent.gameObject);
            }
            ni.enabled = true;
            ni.childMeshRenderer.gameObject.SetActive(true);
        }
        if (combineParent)
        {
            Destroy(combineParent.gameObject);
        }
    }
    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);
    }