public override int GetHashCode() { int hash = 1; if (typeCase_ == TypeOneofCase.Poi) { hash ^= Poi.GetHashCode(); } if (typeCase_ == TypeOneofCase.Trace) { hash ^= Trace.GetHashCode(); } if (typeCase_ == TypeOneofCase.Landmark) { hash ^= Landmark.GetHashCode(); } if (typeCase_ == TypeOneofCase.PotionIngredient) { hash ^= PotionIngredient.GetHashCode(); } if (typeCase_ == TypeOneofCase.Weather) { hash ^= Weather.GetHashCode(); } if (typeCase_ == TypeOneofCase.EnvironmentTags) { hash ^= EnvironmentTags.GetHashCode(); } hash ^= (int)typeCase_; if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public void addIngredient(PotionIngredient ingredient) { for (int i = 0; i < ingredientsNeeded.Length; i++) { if (ingredientsNeeded[i] == ingredient) { ingredientSlots[i].color = new Color(.5f, .5f, .5f, .25f); bool done = true; for (int j = 0; j < ingredientsNeeded.Length; j++) { if (ingredientsNeeded[j].state != PotionIngredient.State.Used) { done = false; } } if (done) { setState(State.Victory); } return; } } setState(State.Failure); }
public void MergeFrom(GameEntity other) { if (other == null) { return; } switch (other.TypeCase) { case TypeOneofCase.Poi: if (Poi == null) { Poi = new global::WUProtos.Data.Client.ClientMapPoi(); } Poi.MergeFrom(other.Poi); break; case TypeOneofCase.Trace: if (Trace == null) { Trace = new global::WUProtos.Data.Client.ClientMapTrace(); } Trace.MergeFrom(other.Trace); break; case TypeOneofCase.Landmark: if (Landmark == null) { Landmark = new global::WUProtos.Data.Client.ClientMapLandmark(); } Landmark.MergeFrom(other.Landmark); break; case TypeOneofCase.PotionIngredient: if (PotionIngredient == null) { PotionIngredient = new global::WUProtos.Data.Client.ClientMapPotionIngredient(); } PotionIngredient.MergeFrom(other.PotionIngredient); break; case TypeOneofCase.Weather: if (Weather == null) { Weather = new global::WUProtos.Data.Client.ClientWeather(); } Weather.MergeFrom(other.Weather); break; case TypeOneofCase.EnvironmentTags: if (EnvironmentTags == null) { EnvironmentTags = new global::WUProtos.Data.Client.ClientEnvironmentTags(); } EnvironmentTags.MergeFrom(other.EnvironmentTags); break; } _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); }
public PotionIngredient[] createPool(int count) { shuffleIngredients(); PotionIngredient[] createdIngredients = new PotionIngredient[count]; for (int i = 0; i < count; i++) { createdIngredients[i] = (Instantiate(ingredients[i]) as GameObject).GetComponent <PotionIngredient>(); } return(createdIngredients); }
void resetIngredients() { int inglen = ingredients.Length; int index; int[] skiparray = new int[inglen]; for (int i = 0; i < inglen; i++) { Transform spawn = ingredientSpawn.GetChild(i % ingredientSpawn.childCount); Vector3 position = spawn.position + new Vector3(Random.Range(-.5f * spawn.localScale.x, .5f * spawn.localScale.z), 0f, 0f); ingredients[i].transform.position = new Vector3(position.x, position.y, ingredients[i].transform.position.z); ingredients[i].pot = this; ingredients[i].transform.parent = potionPool.transform; ingredients[i].state = PotionIngredient.State.Idle; if (i > 0 && ingredients[i].theCollider.gameObject.activeSelf) { for (int j = i - 1; j >= 0; j--) { if (ingredients[j].theCollider.gameObject.activeSelf) { skiparray[j] = 0; Physics2D.IgnoreCollision(ingredients[i].theCollider, ingredients[j].theCollider, true); } else { skiparray[j]++; } } } } int ingredientSlotCount = ingredientSlots.Length; ingredientsNeeded = new PotionIngredient[ingredientSlotCount]; List <PotionIngredient> availableIngredients = new List <PotionIngredient>(ingredients); for (int i = 0; i < ingredientSlotCount; i++) { index = Random.Range(0, availableIngredients.Count); ingredientsNeeded[i] = availableIngredients[index]; ingredientSlots[i].sprite = ingredientsNeeded[i].spriteRenderer.sprite; ingredientSlots[i].color = Color.white; availableIngredients.RemoveAt(index); } orderIngredients(); }
void resetIngredients() { ingredients = new PotionIngredient[ingredientCount]; List <PotionIngredient> availableIngredients = new List <PotionIngredient>(allIngredients); int index; for (int i = 0; i < ingredients.Length; i++) { index = Random.Range(0, availableIngredients.Count); ingredients[i] = availableIngredients[index]; availableIngredients.RemoveAt(index); ingredientPool.getObjectFromPool(ingredients[i].gameObject); //Transform spawn = ingredientSpawn.GetChild(Random.Range(0, ingredientSpawn.childCount)); Transform spawn = ingredientSpawn.GetChild(i % ingredientSpawn.childCount); Vector3 position = spawn.position + new Vector3(Random.Range(-.5f * spawn.localScale.x, .5f * spawn.localScale.z), 0f, 0f); ingredients[i].transform.position = new Vector3(position.x, position.y, ingredients[i].transform.position.z); ingredients[i].pot = this; ingredients[i].name = "Ingredient " + i.ToString(); ingredients[i].state = PotionIngredient.State.Idle; } for (int i = 0; i < ingredients.Length; i++) { for (int j = i + 1; j < ingredients.Length; j++) { if (ingredients[i].theCollider.gameObject.activeSelf && ingredients[j].theCollider.gameObject.activeSelf) { Physics2D.IgnoreCollision(ingredients[i].theCollider, ingredients[j].theCollider, true); } } } availableIngredients = new List <PotionIngredient>(allIngredients); ingredientsNeeded = new PotionIngredient[ingredientSlots.Length]; for (int i = 0; i < ingredientSlots.Length; i++) { index = Random.Range(0, availableIngredients.Count); ingredientsNeeded[i] = availableIngredients[index]; ingredientSlots[i].sprite = ingredientsNeeded[i].spriteRenderer.sprite; ingredientSlots[i].color = Color.white; availableIngredients.RemoveAt(index); } orderIngredients(); }
public void moveToFront(PotionIngredient ingredient) { int index = 0; PotionIngredient hold = ingredient; for (int i = 0; i < ingredients.Length; i++) { if (ingredients[i] == ingredient) { index = i; i = ingredients.Length; } } for (int i = index - 1; i >= 0; ingredients[i + 1] = ingredients[i], i--) { ; } ingredients[0] = hold; orderIngredients(); }
/// Author: JT /// Date: 2/16/2021 /// <summary> /// Remove the item from inventory. /// </summary> /// <param name="item">The item to remove.</param> /// Edit: Chase O'Connor /// Function was restructred to work with our current system rather than the /// system that was made following the tutorial. /// FURTHER NOTICE /// This function might need to be restructed again based on how the dropping /// of items from our inventory is handled as the system from the tutorial is /// still vastly different from the one we have. More planning will be done to /// deal with this. /// ///Change the way that items are dropped. public void RemoveItem(Collectable item) { //checks if the item is stackable if (item is PotionIngredient) { PotionIngredient ingredientInInven = null; //for each loop that removes the item from the stack of existing items foreach (Collectable invenItem in itemList) { if (invenItem is PotionIngredient ingredient && invenItem.GetType() == item.GetType()) { if (ingredient.amountInInv > 1) { Vector3 dropPos = RandDropPos(); dropPos.y = 0.7f; UnityEngine.Object.Instantiate(ingredient.gameObject, dropPos, Quaternion.identity).SetActive(true); } ingredient.amountInInv--; ingredientInInven = ingredient; } } //if the item isn't in the inventory and the amount is <= 0 removes it from the itemList if (ingredientInInven != null && ingredientInInven.amountInInv <= 0) { DropItem(item); } } //if the item isn't stackable it removes it from the inventroy itemList else { DropItem(item); } OnItemListChanged?.Invoke(this, EventArgs.Empty); #region Internal Functions ///Internal function to drop the item. void DropItem(Collectable droppedItem) { droppedItem.transform.parent = null; Vector3 dropPos = RandDropPos(); //Vector3 dropDelta = Player.Instance.transform.position - dropPos; //Debug.Log("Drop Pos mag: " + dropDelta.magnitude); dropPos.y = 0.7f; droppedItem.transform.position = dropPos; droppedItem.gameObject.SetActive(true); itemList.Remove(droppedItem); droppedItem.DropLogic(); } Vector3 RandDropPos() { System.Random rand = new System.Random(); Vector3 dropPos = Vector3.zero; while (true) { int dropMod = rand.Next(0, 2) == 0 ? -1 : 1; float dropX = Mathf.Clamp((float)rand.NextDouble(), 0.5f, 1f) * 2f * dropMod; dropMod = rand.Next(0, 2) == 0 ? -1 : 1; float dropZ = Mathf.Clamp((float)rand.NextDouble(), 0.5f, 1f) * 2f * dropMod; dropPos = Player.Instance.transform.position + new Vector3(dropX, 0f, dropZ); Ray ray = Camera.main.ViewportPointToRay(Camera.main.WorldToViewportPoint(dropPos)); int layerMask = ~((1 << 30) | (1 << 0) | (1 << 15)); Physics.Raycast(ray, out RaycastHit hit, 1000f, layerMask); Debug.Log(hit.collider.gameObject.layer); if (hit.collider.gameObject.layer == 31) { Debug.Log("Nothing here, placing object."); break; } else { Debug.Log("Making another pass to avoid stacking."); } } //return Player.Instance.transform.position + new Vector3(dropX, 0f, dropZ); return(dropPos); } #endregion }
public void MergeFrom(VaultItem other) { if (other == null) { return; } if (other.Id.Length != 0) { Id = other.Id; } if (other.Cap != 0L) { Cap = other.Cap; } if (other.RelativeValue != 0) { RelativeValue = other.RelativeValue; } if (other.VaultCategoryGmtId.Length != 0) { VaultCategoryGmtId = other.VaultCategoryGmtId; } switch (other.VaultItemTypeCase) { case VaultItemTypeOneofCase.CurrencyItem: if (CurrencyItem == null) { CurrencyItem = new global::WUProtos.Data.CurrencyVaultItem(); } CurrencyItem.MergeFrom(other.CurrencyItem); break; case VaultItemTypeOneofCase.StaminaItem: if (StaminaItem == null) { StaminaItem = new global::WUProtos.Data.StaminaVaultItem(); } StaminaItem.MergeFrom(other.StaminaItem); break; case VaultItemTypeOneofCase.DetectorItem: if (DetectorItem == null) { DetectorItem = new global::WUProtos.Data.DarkDetectorVaultItem(); } DetectorItem.MergeFrom(other.DetectorItem); break; case VaultItemTypeOneofCase.ContainerItem: if (ContainerItem == null) { ContainerItem = new global::WUProtos.Data.ContainerVaultItem(); } ContainerItem.MergeFrom(other.ContainerItem); break; case VaultItemTypeOneofCase.RunestoneItem: if (RunestoneItem == null) { RunestoneItem = new global::WUProtos.Data.RunestoneVaultItem(); } RunestoneItem.MergeFrom(other.RunestoneItem); break; case VaultItemTypeOneofCase.PotionItem: if (PotionItem == null) { PotionItem = new global::WUProtos.Data.Potion.PotionVaultItem(); } PotionItem.MergeFrom(other.PotionItem); break; case VaultItemTypeOneofCase.PotionIngredient: if (PotionIngredient == null) { PotionIngredient = new global::WUProtos.Data.Potion.PotionIngredientVaultItem(); } PotionIngredient.MergeFrom(other.PotionIngredient); break; case VaultItemTypeOneofCase.EnergyItem: if (EnergyItem == null) { EnergyItem = new global::WUProtos.Data.EnergyVaultItem(); } EnergyItem.MergeFrom(other.EnergyItem); break; case VaultItemTypeOneofCase.CauldronTimeItem: if (CauldronTimeItem == null) { CauldronTimeItem = new global::WUProtos.Data.CauldronTimeItem(); } CauldronTimeItem.MergeFrom(other.CauldronTimeItem); break; } _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); }
public override int GetHashCode() { int hash = 1; if (Id.Length != 0) { hash ^= Id.GetHashCode(); } if (vaultItemTypeCase_ == VaultItemTypeOneofCase.CurrencyItem) { hash ^= CurrencyItem.GetHashCode(); } if (vaultItemTypeCase_ == VaultItemTypeOneofCase.StaminaItem) { hash ^= StaminaItem.GetHashCode(); } if (vaultItemTypeCase_ == VaultItemTypeOneofCase.DetectorItem) { hash ^= DetectorItem.GetHashCode(); } if (vaultItemTypeCase_ == VaultItemTypeOneofCase.ContainerItem) { hash ^= ContainerItem.GetHashCode(); } if (vaultItemTypeCase_ == VaultItemTypeOneofCase.RunestoneItem) { hash ^= RunestoneItem.GetHashCode(); } if (vaultItemTypeCase_ == VaultItemTypeOneofCase.PotionItem) { hash ^= PotionItem.GetHashCode(); } if (vaultItemTypeCase_ == VaultItemTypeOneofCase.PotionIngredient) { hash ^= PotionIngredient.GetHashCode(); } if (vaultItemTypeCase_ == VaultItemTypeOneofCase.EnergyItem) { hash ^= EnergyItem.GetHashCode(); } if (vaultItemTypeCase_ == VaultItemTypeOneofCase.CauldronTimeItem) { hash ^= CauldronTimeItem.GetHashCode(); } if (Cap != 0L) { hash ^= Cap.GetHashCode(); } if (RelativeValue != 0) { hash ^= RelativeValue.GetHashCode(); } if (VaultCategoryGmtId.Length != 0) { hash ^= VaultCategoryGmtId.GetHashCode(); } hash ^= (int)vaultItemTypeCase_; if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }