public void processFlowerSell(uint flowerId) { player.money += getFlowerValue(flowerId); string flowerIdS = flowerId.ToString("X8"); for (int i = 0; i < 4; i++) { int partId = System.Uri.FromHex(flowerIdS[i * 2]); int newIndex = Random.Range(0, partsEconomy[i, partId].targetIndex);//swap with a random lower value part for (int j = 0; j < 16; j++) { if (partsEconomy[i, j].targetIndex == newIndex) { swap(partsEconomy[i, partId], partsEconomy[i, j]); break; } } } for (int i = 0; i < 4; i++)//update vals { List <FlowerPart> toSwap = new List <FlowerPart>(); for (int j = 0; j < 16; j++) { if (partsEconomy[i, j].jump())//if reached target val { toSwap.Add(partsEconomy[i, j]); } } for (int k = 0; k < toSwap.Count; k++)//find a random part to swap with { int index = Random.Range(0, 16); while (!partsEconomy[i, index].canBePicked()) { index = Random.Range(0, 16); } swap(partsEconomy[i, index], toSwap[k]); } } GameJoltAPIHelper.IncDataStoreKey(GameJoltAPIHelper.flowers_sold); }
// Update is called once per frame void Update() { isFrozen = uIControllerS.isViewingFlower || uIControllerS.isPaused || isViewingHomeBase || isOnOnlinePlanet; if (Input.GetKeyDown(KeyCode.Mouse0) && !isFrozen)//left click { RaycastHit hit; Ray ray = mainCamera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2)); if (Physics.Raycast(ray, out hit, 4.0f, placeableLayer, QueryTriggerInteraction.Collide))//check for flower { //string[] flowerGridPos = hit.transform.gameObject.name.Split(' ');//this should be changed selectorBoxDimensions = hit.collider.bounds.size; selectorBoxPos = hit.collider.bounds.center + hit.transform.position; Placeable currentObj = hit.transform.gameObject.GetComponent <Placeable>(); if (currentObj != null) { //This is stuff to test William's inventory UI /*uint hitIndex = WorldManager.instance.flowerGrid[int.Parse(flowerGridPos[0]), int.Parse(flowerGridPos[1])].getFlowerIndex(); * if ((long)hitIndex < 0) * { * print("WHOAH: " + (long)hitIndex); * }*/ bool canPickUp = uIControllerS.inventoryHasRoom(currentObj); if (canPickUp) { Debug.Log("picking up: " + hit.transform.gameObject.name); uint id = currentObj.id; bool isFlower = currentObj.isFlower; if (isFlower) { HomeInventoryData.instance.addToKnownFlowers(id.ToString("X8")); GameJoltAPIHelper.IncDataStoreKey(GameJoltAPIHelper.flowers_picked); } currentObj.clearPos(); uIControllerS.inventoryPushItem(currentObj); Destroy(hit.transform.gameObject); flowerMemory.Remove(id); int[] flowerGridLoc = WorldManager.instance.worldPointToFlowerGrid(hit.point);//find what grid the point is in questStuff(id, isFlower, flowerGridLoc[0], flowerGridLoc[1], false); if (id == 102 && !isFlower && WarpDriveController.instance.currentPlanetID != Galaxy.HOME_PLANET_ID) { //Removing flag from alien planet WarpDriveController.instance.GetCurrentPlanet().setName(""); } } else { uIControllerS.flashInventorySlots(); } } } } if (Input.GetKeyDown(KeyCode.Mouse1) && !isFrozen) //right click { //New RaycastHit hit; Ray ray = mainCamera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2)); if (Physics.Raycast(ray, out hit, 4.0f, world, QueryTriggerInteraction.Collide)) { int[] flowerGridLoc = WorldManager.instance.worldPointToFlowerGrid(hit.point); //find what grid the point is in if (uIControllerS.inventoryHasItemToPlace() && uIControllerS.inventoryPeekItem().canBePlaced(hit)) //do we have an item at the selected slot, is there nothing there { if (!uIControllerS.inventoryPeekItem().isFlower&& WarpDriveController.instance.currentPlanetID != Galaxy.HOME_PLANET_ID && uIControllerS.inventoryPeekItem().id != 102) //if it's a decoration and on alien planet and it's not a flag { uIControllerS.flashInventorySlots(); } else { //Peek the flower, clone it, and then pop it //Because popping it will destroy the object and it can't be cloned after it's destroyed Placeable itemToPlace = uIControllerS.inventoryPeekItem(); WorldManager.instance.removeFromFlowerList(flowerGridLoc[0], flowerGridLoc[1]); GameObject placedFlower = itemToPlace.cloneObj(uIControllerS.inventoryPeekItem().gameObject, itemToPlace, hit); if (itemToPlace.isFlower) { //WorldManager.instance.RecalcAfterAdd(flowerGridLoc[0], flowerGridLoc[1]);//tell flower grid there's a new flower //Rotate the flower to match the player's rotation placedFlower.transform.localRotation = Quaternion.Euler(0, transform.rotation.eulerAngles.y - 90f, 0); questStuff(itemToPlace.id, itemToPlace.isFlower, flowerGridLoc[0], flowerGridLoc[1], true); GameJoltAPIHelper.IncDataStoreKey(GameJoltAPIHelper.flowers_planted); } if (itemToPlace.id == 102 && !itemToPlace.isFlower && WarpDriveController.instance.currentPlanetID != Galaxy.HOME_PLANET_ID) { //Planting flag on alien planet! uIControllerS.namePlanet(); } uIControllerS.inventoryPopItem(); //Pulls the item out of the inventory at the selected slot } } } //New } //Control throwing away flowers with the "Q" key if (Input.GetKeyDown(KeyCode.Q) && !isFrozen && uIControllerS.inventoryPeekItem() != null) { if (WarpDriveController.instance.currentPlanetID == Galaxy.HOME_PLANET_ID) { HomeInventoryData.instance.addToInventory(uIControllerS.inventoryPeekItem()); uIControllerS.inventoryPopItem(); if (uIControllerS.currentQuestId == 1 && uIControllerS.isEmpty()) { uIControllerS.completeQuest(); } } else { uIControllerS.flashInventorySlots(); } } //Control mouse scrolling to select the index if (Input.GetAxis("Mouse ScrollWheel") < 0f) //Scroll down { selectedIndex += 1; if (selectedIndex >= inventorySize) { selectedIndex -= inventorySize; } //Tell the UIController to update the selected index uIControllerS.updateSelectedSlot(selectedIndex); } if (Input.GetAxis("Mouse ScrollWheel") > 0f) //Scroll up { selectedIndex -= 1; if (selectedIndex < 0) { selectedIndex += inventorySize; } //Tell the UIController to update the selected index uIControllerS.updateSelectedSlot(selectedIndex); } //Control keyboard pressing to select the index //Loop through 0-9 for (int ii = 0; ii < 10; ii += 1) { //If the number is pressed if (Input.GetKey("" + ii)) { //Convert 0 to 9 so 0 will select the last slot //This is to make the UI match the keyboard selectedIndex = ii - 1; if (selectedIndex < 0) { selectedIndex += inventorySize; } //Tell the UIController to update the selected index uIControllerS.updateSelectedSlot(selectedIndex); } } RaycastHit hitGrid; Ray rayGrid = mainCamera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2)); if (Physics.Raycast(rayGrid, out hitGrid, 4.0f, world, QueryTriggerInteraction.Collide)) { int[] gridPos = WorldManager.instance.worldPointToFlowerGrid(hitGrid.point); if (WorldManager.instance.placableGrid[gridPos[0], gridPos[1]] == null || !(WorldManager.instance.placableGrid[gridPos[0], gridPos[1]] is Unplacable)) { //Check to see if it's a hover block object before activating the selector if (!gridSelector.activeSelf) { gridSelector.SetActive(true); } gridSelector.transform.position = WorldManager.instance.worldPointToGridOrgin(hitGrid.point) + new Vector3(0, hitGrid.point.y, 0); } else if (gridSelector.activeSelf) { gridSelector.SetActive(false); } } else if (gridSelector.activeSelf) { gridSelector.SetActive(false); } Ray rayFlower = mainCamera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2)); if (Physics.Raycast(rayFlower, out hitGrid, 4.0f, placeableLayer, QueryTriggerInteraction.Collide))//check for flower { //If it's not the same hovered placeable as last frame if (hoveredPlaceable != hitGrid.transform.gameObject) { //Tell the hovered placeable that it is no longer hovered if (hoveredPlaceable != null) { if (hoveredPlaceable.GetComponent <Placeable>() != null) { hoveredPlaceable.GetComponent <Placeable>().setHover(false); } else if (hoveredPlaceable.GetComponent <HomeBaseScreenController>() != null) { hoveredPlaceable.GetComponent <HomeBaseScreenController>().setHover(false); } } if (hitGrid.transform.gameObject.layer != LayerMask.NameToLayer("HoverBlock")) { hoveredPlaceable = hitGrid.transform.gameObject; if (!flowerSelector.activeSelf) { flowerSelector.SetActive(true); } //flowerSelector.transform.position = new Vector3(hitGrid.transform.position.x, hitGrid.transform.position.y + (hitGrid.collider.bounds.size.y / 2), hitGrid.transform.position.z); //flowerSelector.transform.localScale = hitGrid.collider.bounds.size; flowerSelector.GetComponentInChildren <FlowerSelectorController>().fitToGameObject(hitGrid.transform.gameObject); if (hitGrid.transform.gameObject.GetComponent <Placeable>() != null) { hitGrid.transform.gameObject.GetComponent <Placeable>().setHover(true); } else if (hitGrid.transform.gameObject.GetComponent <HomeBaseScreenController>() != null) { hitGrid.transform.gameObject.GetComponent <HomeBaseScreenController>().setHover(true); } } else { hoveredPlaceable = null; if (flowerSelector.activeSelf) { flowerSelector.SetActive(false); } } } } else if (flowerSelector.activeSelf) { //Tell the hovered placeable that it is no longer hovered if (hoveredPlaceable != null) { if (hoveredPlaceable.GetComponent <Placeable>() != null) { hoveredPlaceable.GetComponent <Placeable>().setHover(false); } else if (hoveredPlaceable.GetComponent <HomeBaseScreenController>() != null) { hoveredPlaceable.GetComponent <HomeBaseScreenController>().setHover(false); } } hoveredPlaceable = null; flowerSelector.SetActive(false); } if (Input.GetKeyDown(KeyCode.Return)) { if (uIControllerS.currentQuestId == 5 || uIControllerS.currentQuestId == 16 || uIControllerS.currentQuestId == 19) { uIControllerS.completeQuest(); } } }