public void Collect(GameObject o, bool muted = false)
    {
//		Debug.Log("Adding "+o+" to slot "+this.name);
        // was AddItemToSlot
        // Note that ITEM is the 2D item we see in inventory
        // and ITEM3D is the item that still exists in the game world but is now deactivated.
        PickUppableObject pip = o.GetComponent <PickUppableObject>();

        pip.OnInventoryCollect(muted);
        NumberInfo ni            = o.GetComponent <NumberInfo>();
        GameObject inventoryItem = (GameObject)Instantiate(Inventory.inst.itemPrefab);

        // Removing hand
        if (ni)
        {
            // Make the inventory icon for NumberInfos only.
            inventoryItem.GetComponent <InventoryItem>().SetUpDigits(ni);
        }
        else if (pip.inventoryIcon != null)
        {
            inventoryItem.GetComponent <Image>().sprite = pip.inventoryIcon;
            if (pip.useColor == true)
            {
                inventoryItem.GetComponent <Image>().color = pip.inventoryIconColor;
            }
        }
        inventoryItem.transform.SetParent(transform, false);        //parent = emptySlot.transform;
        inventoryItem.GetComponent <InventoryItem>().item3d = o;
        foreach (IMyPickupable im in o.GetComponents(typeof(IMyPickupable)))
        {
            im.OnPlayerPickup();
        }
        o.SetActive(false);
    }
Exemple #2
0
    public GameObject AmmoCloseby(float maxPickupRange)
    {
        // was there ammo right in front of me and I was pointing at it?
        RaycastHit hit = new RaycastHit();
        Ray        ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward);

        //		Debug.Log("ray:"+ray);
        if (Physics.Raycast(ray, out hit, maxPickupRange))
        {
            //			Debug.Log("hit:"+hit.collider.name);
            GameObject        o   = hit.collider.gameObject;
            PickUppableObject pip = o.GetComponent <PickUppableObject>();
            if (pip && pip.CanPickUp)
            {
                // don't allow us to pick up items too far over our own head.
                if (o.transform.position.y > Player.inst.transform.position.y + 4)
                {
                    return(null);
                }
                if (CanCollectItem(o))
                {
                    return(o);
                }
            }
        }
        return(null);
    }
Exemple #3
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!");
        }
    }
    void Die()
    {
        dead = true;
        transform.root.GetComponentInChildren <ResourceDrop>().DropResource();
        // commented Debug.Log("Dying now.");
        foreach (NumberInfo ni in myBlocks)
        {
            if (ni != null)
            {
                if (transform.root.GetComponentInChildren <LevelMonster_Shield>())
                {
                    Destroy(transform.root.GetComponentInChildren <LevelMonster_Shield>().gameObject);
                }

                ni.transform.parent = null;
                if (!ni.gameObject.GetComponent <Rigidbody>())
                {
                    ni.gameObject.AddComponent <Rigidbody>();
                    ni.GetComponent <Rigidbody>().mass = 4;
                    ni.GetComponent <Rigidbody>().drag = .2f;
                }
                ni.gameObject.GetComponent <Collider>().isTrigger = false;
                if (ni.GetComponent <Rigidbody>())
                {
                    ni.GetComponent <Rigidbody>().isKinematic = false;
                    ni.GetComponent <Rigidbody>().useGravity  = true;
                }
//				ni.pickupFlag = true; // todo: Make inventory recognize cube numbers as well.
                ni.gameObject.layer   = LayerMask.NameToLayer("Default");
                ni.greaterThanCombine = 0;
                ni.lessThanCombine    = 1;
//				if (ni.transform.transform.localScale.x > 3) // crit block scale is 4 and other block scale is 2.6

                PickUppableObject pip = ni.gameObject.AddComponent <PickUppableObject>();
                pip.heldScale = 1.5f;                 //2 / ni.transform.localScale.x;

//				}
//				pip.heldScale
//				rocketLauncher.gameObject.AddComponent<Rigidbody>();
                rocketLauncher.transform.parent = null;
                TimedObjectDestructor tod = rocketLauncher.gameObject.AddComponent <TimedObjectDestructor>();
            }
        }
        Destroy(transform.root.gameObject);
    }
Exemple #5
0
    public GameObject GadgetCloseby(float maxPickupRange)
    {
        // was there ammo right in front of me and I was pointing at it?
        RaycastHit hit = new RaycastHit();
        Ray        ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward);

        //		Debug.Log("ray:"+ray);
        if (Physics.Raycast(ray, out hit, maxPickupRange))
        {
            GameObject        o   = hit.collider.gameObject;
            PickUppableObject pip = o.GetComponent <PickUppableObject>();
            Gadget            g   = o.GetComponent <Gadget>();
            if (pip && pip.CanPickUp && g)
            {
                return(o);
            }
        }
        return(null);
    }
Exemple #6
0
    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()
    }
Exemple #7
0
    public virtual void SetProperties(SimpleJSON.JSONClass N)
    {
//		return;
//		Debug.Log("set prop:"+N.ToString());
        if (N.GetKeys().Contains(uuidKey))
        {
            SetUuid("setprop", N[uuidKey].AsInt);
//			Debug.Log("just set my uuid key:"+N[uuidKey].AsInt);
        }
        ResourceDrop rd = GetComponentInChildren <ResourceDrop>();

        if (rd && N.GetKeys().Contains(ResourceDrop.key))
        {
//			Debug.Log("set prop resource:"+N.ToString());
            rd.SetProperties(N);
        }
        if (N.GetKeys().Contains(JsonUtil.scaleKey))
        {
//			Debug.Log("set scale on: "+myName+", "+N[JsonUtil.scaleKey].AsInt);
//			name += " scaled.";
            transform.localScale     = JsonUtil.GetScaleFromInt(N[JsonUtil.scaleKey].AsInt);
            scaleSetFromInstanceLoad = true;
        }
        UEO_ScaleManipulator cs = GetComponentInChildren <UEO_ScaleManipulator>();

        if (cs && N.GetKeys().Contains(UEO_ScaleManipulator.key))
        {
            int x = MathUtils.IntParse(N[UEO_ScaleManipulator.key][UEO_ScaleManipulator.keyX].Value);
            int y = MathUtils.IntParse(N[UEO_ScaleManipulator.key][UEO_ScaleManipulator.keyY].Value);
            int z = MathUtils.IntParse(N[UEO_ScaleManipulator.key][UEO_ScaleManipulator.keyZ].Value);
            cs.transform.localScale = new Vector3(x, y, z);
            cs.UpdateSize(x, y, z);
            //			if (cloneObject) cloneObject.transform.localScale = transform.localScale;
        }

        if (N.GetKeys().Contains(UEO_ColorCycler.colorManipulatorKey))
        {
            UEO_ColorCycler cc = GetComponentInChildren <UEO_ColorCycler>();
            if (cc)
            {
                cc.SetProperties(N);
            }
        }


        if (N.GetKeys().Contains(UEO_ObjectCycler.objectIndexKey))
        {
            UEO_ObjectCycler cc = GetComponentInChildren <UEO_ObjectCycler>();
            if (cc)
            {
                cc.SetProperties(N);
            }
        }

        if (N.GetKeys().Contains(tagsKey))
        {
            if (N[tagsKey].Value.Length > 0)
            {
                myTags.AddRange(N[tagsKey].Value.Split(','));
//				Debug.Log("<color=#f0f>addtag:</color>"+N[tagsKey].Value);
            }
//			Debug.Log("tags!:"+tags+", json val:"+N[tagsKey].ToString());
        }
        else
        {
//			print("no tagskey on:"+myName);
        }

        PickUppableObject pip = GetComponent <PickUppableObject>();

        if (pip)
        {
            // Vadim todo add Interface IMySetProperties?
            pip.SetProperties(N);
        }
    }
    override public void UpdateAmmoGraphics(bool redraw = false)
    {
        //		// commented Debug.Log("update:"+numberHeld);
        //		if (PlayerGadgetController.inst.currentWeapon != this) return; // don't mess with graphics if this weapon isn't selected.
        base.UpdateAmmoGraphics();
        if (ammoGraphics)
        {
            UnityEngine.Object.Destroy(ammoGraphics);
        }
        //		if (ammoGraphics) UnityEngine.Object.Destroy(ammoGraphics);
        //		// commented Debug.Log("modifying throw gfx");
        if (numberHeld)
        {
            //			// commented Debug.Log ("number held:"+numberHeld);
            //			// commented Debug.Log ("number held:"+numberHeld.GetComponent<NumberInfo>().fraction);

            //			// commented Debug.Log ("throw static");
            NumberInfo ni = numberHeld.GetComponent <NumberInfo>();
            if (ni)
            {
                // for numbers we do want to keep certain scripts on them as ammo, such as alwaysfaceplayer
                ammoGraphics = NumberManager.inst.CreateNumberAmmo(ni.fraction, ni.myShape);
            }
            else
            {
//				Debug.Log("no ni");
            }

//			Debug.Log("ammograph:"+ammoGraphics);
            CleanComponentsForAmmo(ammoGraphics);

            PickUppableObject pip = numberHeld.GetComponent <PickUppableObject>();
            ammoGraphics.transform.parent = gadgetGraphics.transform;

            ammoGraphics.transform.localScale *= 0.3f;

            Transform m1 = ammoGraphics.transform.Find("mesh");
            if (m1)
            {
                m1.localScale = Vector3.one * 0.5f;
                //				// commented Debug.Log ("set to 0.5");
            }
            Transform m2 = ammoGraphics.transform.Find("mesh2");
            if (m2)
            {
                m2.localScale = playerHoldingScale * Vector3.one;
            }

            ammoGraphics.transform.localPosition = new Vector3(0.173f, 0.348f, -0.506f);           // = gadgetGraphics.transform.position + Vector3.up * 5;// new Vector3(.3f,.078f,-.1f);

            ammoGraphics.SetActive(true);
            ni = ammoGraphics.GetComponent <NumberInfo>();
            if (ni)
            {
                ni.InitSinGrowAttributes(.100f);
                ni.SinGrowOnce();
            }
        }
        else
        {
//			Debug.Log("update ammo num null");
            numberHeld = null;
        }
    }
    override public void UpdateAmmoGraphics(bool redraw = false)
    {
//		// commented Debug.Log("update:"+numberHeld);
//		if (PlayerGadgetController.inst.currentWeapon != this) return; // don't mess with graphics if this weapon isn't selected.
        base.UpdateAmmoGraphics();
        if (ammoGraphics)
        {
            UnityEngine.Object.Destroy(ammoGraphics);
        }
//		if (ammoGraphics) UnityEngine.Object.Destroy(ammoGraphics);
        //		// commented Debug.Log("modifying throw gfx");
        if (numberHeld)
        {
//			// commented Debug.Log ("number held:"+numberHeld);
            //			// commented Debug.Log ("number held:"+numberHeld.GetComponent<NumberInfo>().fraction);

            //			// commented Debug.Log ("throw static");
            NumberInfo ni = numberHeld.GetComponent <NumberInfo>();
            if (ni)
            {
                // for numbers we do want to keep certain scripts on them as ammo, such as alwaysfaceplayer
                ammoGraphics = NumberManager.inst.CreateNumberAmmo(ni.fraction, ni.myShape);
                // Did the oriignal number info have soap bubbles? (bad place for this to be? lol)
                if (ni.IsSoapable() && ni.soapFx.activeSelf)
                {
                    GameObject soapCopy = (GameObject)GameObject.Instantiate(ni.soapFx, ammoGraphics.transform.position, ammoGraphics.transform.rotation);
                    soapCopy.transform.parent = ammoGraphics.transform;
                    ParticleSystem             ps  = soapCopy.GetComponentInChildren <ParticleSystem>();
                    ParticleSystem.ShapeModule pss = ps.shape;
                    pss.radius *= 0.5f;
//					ps.sh
                }
            }
            else
            {
                // otherwise, do not duplicate/strip the ammo, intead reconstruct it from scratch.
                ammoGraphics = Utils.ConstructFakeCopyOfAmmo(numberHeld);

                ammoGraphics.transform.rotation = Quaternion.identity;
            }
//			(GameObject)UnityEngine.Object.Instantiate(numberHeld);

//			if (ueo) ueo.isSerializeableForSceneInstance = false;

//			ammoGraphics.name = "ammo graphics";
            CleanComponentsForAmmo(ammoGraphics);

            PickUppableObject pip = numberHeld.GetComponent <PickUppableObject>();
            ammoGraphics.transform.parent = PlayerGadgetController.inst.GetPlayerLocationForGadget(gadgetLocationOnPlayer);
            if (pip)
            {
                ammoGraphics.transform.localScale *= pip.heldScale;
            }
            else
            {
                ammoGraphics.transform.localScale = Vector3.one * 0.5f;                // * 0.5f; // * Player.inst.transform.localScale.x
            }
            Transform m1 = ammoGraphics.transform.Find("mesh");
            if (m1)
            {
                m1.localScale = Vector3.one * 0.5f;
                //				// commented Debug.Log ("set to 0.5");
            }
            Transform m2 = ammoGraphics.transform.Find("mesh2");
            if (m2)
            {
                m2.localScale = playerHoldingScale * Vector3.one;
            }

            ammoGraphics.transform.localPosition = playerHoldingPos;            // Vector3.zero;// new Vector3(.3f,.078f,-.1f);
            if (pip.alwaysFacePlayerAsAmmo)
            {
                ammoGraphics.AddComponent <AlwaysFacePlayer>();
            }
//			ammoGraphics.transform.LookAt(Player.inst.transform);
//			ammoGraphics.transform.rotation = Utils.FlattenRotation(ammoGraphics.transform.rotation);
            ammoGraphics.SetActive(true);
            ni = ammoGraphics.GetComponent <NumberInfo>();
            if (ni)
            {
                ni.InitSinGrowAttributes(.100f);
                ni.SinGrowOnce();
            }
//			// commented Debug.Log("ammogrpahics:"+ammoGraphics.transform.localPosition+", playerhod:"+playerHoldingPos);
//			// commented Debug.Log ("setting ammograph localpos to:"+ammoGraphics.transform.localPosition+", but player hollding pos was;"+playerHoldingPos);
//			// commented Debug.Log ("moved to:"+ammoGraphics.transform.localPosition);
//			ammoGraphics.transform.localRotation = Quaternion.identity;
//			ammoGraphics.SendMessage("OnPlayerEquip",SendMessageOptions.DontRequireReceiver);
        }
        else
        {
            numberHeld = null;

            MascotAnimatorController.inst.HoldRightArm(false);
        }
    }
Exemple #10
0
    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);
    }