public void SelectWeapon(int GunIndex) { Inventory.Add(0, Guns[currentWeapon].GetComponent <WEP_Gun>().BulletType, ClipAmount); //Put Clip ammo back in inventory Guns[currentWeapon].SetActive(false); //Make gun invisable ClipAmount = 0; //Clear clip Guns[currentWeapon].SetActive(true); //Set new weapon visable CurrentGunInfo = Guns[currentWeapon].GetComponent <WEP_Gun>(); //Set the current WEP_Gun info up }
public void AddInventoryText(IInventoryText inventoryText) { PlayerInventory.Add(inventoryText); GameObject popup = Instantiate(announcementBox, gameObject.GetComponentInParent <Transform>()); popup.GetComponentInChildren <Text>().text = "You got " + inventoryText.DisplayText; }
public override string Execute(object[] args) { // Give items string itemName = (string)args[0]; itemName = itemName.Trim(); int amount = (int)args[1]; if (amount <= 0) { return("Amount of items must be more than zero!"); } Item prefab = Item.GetItem(itemName); if (prefab == null) { return("Could not find item: '" + itemName + "'"); } PlayerInventory.Add(itemName, null, amount); CommandProcessing.Log("Gave local player '" + prefab.Name + "' x" + amount); return(null); }
public void Complete(ScriptableQuest questData) { // validate if (health.current > 0) { int index = GetQuestIndexByName(questData.name); if (index != -1) { // can complete it? (also checks inventory space for reward, if any) Quest quest = quests[index]; if (CanComplete(quest.name)) { // call quest.OnCompleted to remove quest items from // inventory, etc. quest.OnCompleted(gameObject); // gain rewards inventory.gold += quest.rewardGold; experience.current += quest.rewardExperience; if (quest.rewardItem != null) { inventory.Add(new Item(quest.rewardItem), 1); } // complete quest quest.completed = true; quests[index] = quest; } } } }
public void CmdBuyItem(int index, int amount) { // validate: close enough, npc alive and valid index? // use collider point(s) to also work with big entities if (player.state == "IDLE" && player.target != null && player.target.health.current > 0 && player.target is Npc npc && npc.trading != null && // only if Npc offers trading Utils.ClosestDistance(player, npc) <= player.interactionRange && 0 <= index && index < npc.trading.saleItems.Length) { // valid amount? Item npcItem = new Item(npc.trading.saleItems[index]); if (1 <= amount && amount <= npcItem.maxStack) { long price = npcItem.buyPrice * amount; // enough gold and enough space in inventory? if (player.gold >= price && inventory.CanAdd(npcItem, amount)) { // pay for it, add to inventory player.gold -= price; inventory.Add(npcItem, amount); } } } }
private void RpcGiveItem(GameObject player, string itemPrefab, string data) { if (player.GetComponent <NetworkIdentity>().netId == Player.Local.NetworkIdentity.netId) { PlayerInventory.Add(itemPrefab, ItemData.TryDeserialize(data), 1); } }
public void GiveLoot() { for (int x = 0; x < loot.Length; x++) { inventory.Add(loot[x]); } }
public void CmdUnlockItem(int categoryIndex, int itemIndex) { // validate: only if alive so people can't buy resurrection potions // after dieing in a PvP fight etc. if (player.health.current > 0 && 0 <= categoryIndex && categoryIndex <= config.categories.Length && 0 <= itemIndex && itemIndex <= config.categories[categoryIndex].items.Length) { Item item = new Item(config.categories[categoryIndex].items[itemIndex]); if (0 < item.itemMallPrice && item.itemMallPrice <= coins) { // try to add it to the inventory, subtract costs from coins if (inventory.Add(item, 1)) { coins -= item.itemMallPrice; Debug.Log(name + " unlocked " + item.name); // NOTE: item mall purchases need to be persistent, yet // resaving the player here is not necessary because if the // server crashes before next save, then both the inventory // and the coins will be reverted anyway. } } } }
public void Craft() { // should only be called while CRAFTING and if recipe still valid // (no one should touch 'craftingRecipe', but let's just be sure. // -> we already validated everything in CmdCraft. let's just craft. if (player.state == "CRAFTING" && currentRecipe != null && currentRecipe.result != null) { // enough space? Item result = new Item(currentRecipe.result); if (inventory.CanAdd(result, 1)) { // remove the ingredients from inventory in any case foreach (ScriptableItemAndAmount ingredient in currentRecipe.ingredients) { if (ingredient.amount > 0 && ingredient.item != null) { inventory.Remove(new Item(ingredient.item), ingredient.amount); } } // roll the dice to decide if we add the result or not // IMPORTANT: we use rand() < probability to decide. // => UnityEngine.Random.value is [0,1] inclusive: // for 0% probability it's fine because it's never '< 0' // for 100% probability it's not because it's not always '< 1', it might be == 1 // and if we use '<=' instead then it won't work for 0% // => C#'s Random value is [0,1) exclusive like most random // functions. this works fine. if (new System.Random().NextDouble() < currentRecipe.probability) { // add result item to inventory inventory.Add(new Item(currentRecipe.result), 1); TargetCraftingSuccess(); } else { TargetCraftingFailed(); } // clear indices afterwards // note: we set all to -1 instead of calling .Clear because // that would clear all the slots in host mode. // (don't clear in host mode, otherwise it clears the crafting // UI for the player and we have to drag items into it again) if (!isLocalPlayer) { for (int i = 0; i < ScriptableRecipe.recipeSize; ++i) { indices[i] = -1; } } // clear recipe currentRecipe = null; } } }
private void PickUpItem(Collider2D other) { if (other.gameObject.CompareTag("Weapon Pick Up")) { other.gameObject.SetActive(false); inventory.Add(other.gameObject.GetComponent <Weapon>()); } }
public void RpcReturnItem(string itemPrefab, string data, GameObject owner) { if (Player.Local.netId != owner.GetComponent <Player>().netId) { return; } PlayerInventory.Add(itemPrefab, ItemData.TryDeserialize(data), 1); }
void BuyBasket() { foreach (InventoryItemStack item in BasketInventory.ContainedStacks) { PlayerInventory.Add(item.ContainedItem, (uint)item.Amount); } PlayerInventory.ChangeGold(-BasketValue); BasketInventory.ContainedStacks.Clear(); Close(); }
public static void Option_RemoveUnderBarrel(InventoryItemData x, string prefab) { // Remove attachment... string old = x.Data.Get <string>("Under Barrel Attachment"); x.Data.Remove("Under Barrel Attachment"); // Give item back to player! PlayerInventory.Add(old, null, 1); }
public void Debug_Create() { GameStats = new GameStats(); Pokedex = new Pokedex(); Flags = new Flags(); Vars = new Vars(); OT = new OTInfo("Dawn", true); PlayerInventory = Inventory <InventorySlotNew> .CreatePlayerInventory(); PlayerInventory.Add(ItemType.DuskBall, 995); PlayerInventory.Add(ItemType.RockyHelmet, 42); PlayerInventory.Add(ItemType.Leftovers, 473); PlayerInventory.Add(ItemType.Potion, 123); PlayerInventory.Add(ItemType.RedScarf, 230); PlayerInventory.Add(ItemType.PokeDoll, 130); PlayerInventory.Add(ItemType.XSpDef, 120); PlayerInventory.Add(ItemType.AirBalloon, 407); PlayerInventory.Add(ItemType.PokeBall, 73); PlayerInventory.Add(ItemType.DarkGem, 69); PlayerInventory.Add(ItemType.FluffyTail, 888); PlayerInventory.Add(ItemType.OvalCharm, 1); PlayerInventory.Add(ItemType.ShinyCharm, 1); ItemData.Debug_GiveAllTMHMs(PlayerInventory); Money = 473_123; InitPlayerWithDefaultLocation(); PCBoxes = new PCBoxes(); Daycare = new Daycare(); Daycare.StorePokemon(PartyPokemon.CreatePlayerOwnedMon(PBESpecies.Blissey, 0, 47)); Daycare.StorePokemon(PartyPokemon.CreatePlayerOwnedMon(PBESpecies.Ditto, 0, 82)); PlayerParty = new Party(); { // To test evolution var evomon = PartyPokemon.CreatePlayerOwnedMon(PBESpecies.Burmy, PBEForm.Burmy_Trash, 19); evomon.Item = ItemType.Leftovers; evomon.EXP = PBEEXPTables.GetEXPRequired(BaseStats.Get(evomon.Species, evomon.Form, true).GrowthRate, 20) - 1; GivePokemon(evomon); // To pummel var victini = PartyPokemon.CreatePlayerOwnedMon(PBESpecies.Victini, 0, 67); victini.Ability = PBEAbility.Compoundeyes; victini.Item = ItemType.Leftovers; victini.Status1 = PBEStatus1.BadlyPoisoned; victini.Moveset[0].Move = PBEMove.Bounce; victini.Moveset[1].Move = PBEMove.ZenHeadbutt; victini.Moveset[2].Move = PBEMove.Surf; victini.Moveset[3].Move = PBEMove.VCreate; GivePokemon(victini); } for (int i = 0; i < 44; i++) { Debug_GiveRandomPokemon(i == 0 || i == 1 || i == 35); } Overworld.UpdateGiratinaForms(); // Not really necessary, including for debug though }
public void ReAddRecipeItems(RecipeContainer pRecipe) { PlayerInventory inventory = GameManager.Instance.Player.GetComponent <PlayerInventory>(); for (int i = 0; i < pRecipe.Amount; i++) { foreach (CraftingIngredient ingredient in pRecipe.Recipe.Ingredients) { inventory.Add(ingredient.ContainedItem, (uint)ingredient.Amount, true); } } }
private void RpcReturnAttachment(GameObject player, string prefab, string data) { if (player.GetComponent <NetworkIdentity>().netId == Player.Local.netId) { ItemData itemData = null; if (!string.IsNullOrWhiteSpace(data)) { itemData = ItemData.TryDeserialize(data); } PlayerInventory.Add(prefab, itemData, 1); } }
virtual protected void Pick() { Debug.Log("Collecting " + obj.ToString()); pInv.Add(obj); if (mBrain) { mBrain.IMadeNoise(gameObject.transform.position, 500); } EnableCanvas(false); Destroy(this.gameObject); }
public void PickUpItem(Item item) { if (item != null) { PlayerInventory.Add(item); Console.WriteLine("Taken."); } else { Console.WriteLine("I can't take that..."); } }
public void CastInteractRay() { // Cast a ray to see what the camera is looking at. var ray = new Ray(playerCameraObj.transform.position, playerCameraObj.transform.forward); var raycastHitCount = Physics.RaycastNonAlloc(ray, interactRaycastHitBuffer, maxInteractDistance); if (raycastHitCount > 0 && !playerComponent.Paused) { for (int i = 0; i < raycastHitCount; i++) { var hitInfo = interactRaycastHitBuffer[i]; var component = hitInfo.collider.GetComponentInParent <GenericObjectComponent>(); if (component != null) { if (string.IsNullOrEmpty(component.objData.name)) { return; } ShowInteractiveText(component); if (Input.GetButtonDown("Use")) { if (component is DoorComponent) { OpenDoor((DoorComponent)component); } else if (component.usable) { component.Interact(); } else if (component.pickable) { playerInventory.Add(component); } } break; } else { CloseInteractiveText(); //deactivate text if no interactable [ DOORS ONLY - REQUIRES EXPANSION ] is found } } } else { CloseInteractiveText(); //deactivate text if nothing is raycasted against } }
public override void Update() { if (!addToInventoryEventRepository.HasValue || addToInventoryEventRepository.Value.ItemId != config.Id) { return; } inventory.Add(new PlayerInventoryItem(config.Id, config.Name, config.itemImage)); Object.Destroy(gameObject); addToInventoryEventRepository.RemoveValue(); }
private void PickUp(Item item) { if (item is Weapon) { Weapon weapon = (Weapon)item; if (equipment.Weapon == null) { equipment.EquipWeapon(weapon); } else if (weapon.Attack > equipment.Weapon.Attack) { Weapon previousWeapon = equipment.EquipWeapon(weapon); if (previousWeapon != null) { inventory.Add(previousWeapon); } } } else if (item is Armor) { Armor armor = (Armor)item; if (equipment.Armor == null) { equipment.EquipArmor(armor); } else if (armor.Arm > equipment.Armor.Arm) { Armor previousArmor = equipment.EquipArmor(armor); if (previousArmor != null) { inventory.Add(previousArmor); } } } else { inventory.Add(item); } }
public void OnMouseUp() { // If player is close enough to item, put item in inventory and remove from scene GameObject player = GameObject.FindGameObjectWithTag("Player"); if (Mathf.Abs(this.transform.position.x - player.transform.position.x) < 1 && Mathf.Abs(this.transform.position.y - player.transform.position.y) < 10) { PlayerInventory inventory = player.GetComponent("PlayerInventory") as PlayerInventory; inventory.Add(this); this.active = false; } }
public void RpcSetItem(GameObject item, GameObject player) { // Called on all clients. if (this.Item != null) // IF HOLDING ITEM! { if (player.GetComponent <NetworkIdentity>().netId == Player.Local.NetworkIdentity.netId) // IF IS LOCAL PLAYER { // Put in inventory this.Item.RequestDataUpdate(); // Refresh data. PlayerInventory.Add(this.Item.Prefab, this.Item.Data, 1); } Destroy(this.Item.gameObject); // Destroy on all clients... } EquipItemLocal(item, player); }
public void OnTriggerEnter(Collider other) { if (other.CompareTag("banana")) { actionSound.PlayOneShot(item, 0.5f); PlayerInventory.Add(other.gameObject); checkAllCollected(); } else if (other.CompareTag("Bread")) { actionSound.PlayOneShot(item, 0.5f); PlayerInventory.Add(other.gameObject); checkAllCollected(); } else if (other.CompareTag("Peanut Butter")) { actionSound.PlayOneShot(item, 0.5f); PlayerInventory.Add(other.gameObject); checkAllCollected(); } else if (other.CompareTag("Hair")) { if (currentHealth != totalHealth) { actionSound.PlayOneShot(item, 0.5f); previousHealth = currentHealth; currentHealth = totalHealth; healthScript.HandleHealthGained(previousHealth, 1); // 0 is hairspray and 1 is hair other.gameObject.SetActive(false); } } else if (other.CompareTag("HairSpray")) { if (currentHealth != 3) { actionSound.PlayOneShot(item, 0.5f); previousHealth = currentHealth; currentHealth += 1; healthScript.HandleHealthGained(previousHealth, 0); // 0 is hairspray and 1 is hair other.gameObject.SetActive(false); } } else if (other.gameObject.CompareTag("DeadZone")) { dead = true; } }
public void CraftButton() { // Assume that the button is not pressed when crafting is not available. Blueprint b = Workbench.CurrentBlueprint; for (int i = 0; i < b.Requirements.Length; i++) { PlayerInventory.Remove(b.Requirements[i].Prefab, Vector2.zero, false, b.RequirementQuantities[i]); } for (int i = 0; i < b.Products.Length; i++) { PlayerInventory.Add(b.Products[i].Prefab, null, b.Quantities[i]); } PlayerInventory.inv.Inventory.Refresh = true; }
public override string Execute(object[] args) { // Give items string itemName = (string)args[0]; itemName = itemName.Trim(); int amount = 1; if (itemName.ToLower() == "all") { // Give all items. foreach (var x in Item.Items.Values) { PlayerInventory.Add(x.Prefab, null, amount); } // Give all tiles. foreach (var x in BaseTile.GetAllTiles()) { Player.Local.BuildingInventory.AddItems(x, 1000); } // Give all furnitures foreach (var x in Furniture.Loaded.Values) { Player.Local.BuildingInventory.AddItems(x, 1000); } CommandProcessing.Log("Gave local player 1 of each and every item, and 1000 of all buildables."); return(null); } Item prefab = Item.GetItem(itemName); if (prefab == null) { return("Could not find item: '" + itemName + "'"); } PlayerInventory.Add(prefab.Prefab, null, amount); CommandProcessing.Log("Gave local player '" + prefab.Name + "' x" + amount); return(null); }
public static void AddToInventory(GameObject itemGO) { PlayerInventory.Add(itemGO); if (_currentContainer != null) { _currentContainer.contents.Remove(itemGO); UIManager.CreateItemUI("inventory", itemGO); } Item newItem = itemGO.GetComponent <Item>(); if (newItem != null && newItem.increaseProg) { Globals.IncrementProgress(newItem.conviction, newItem.toStep); } }
public virtual void OnInteract() { if (!PI.IsFull()) { PI.Add(item[0]); gameObject.SetActive(false); Cleared(); Invoke("reset", ResetTime); } else if (PI.IsFull()) { EM.InventoryFull(); Debug.Log("Your inventory is full"); } }
public bool AddToInventory(Item item) { int index = inventory.Add(item); if (index != -1) { if (index < hotbarBoxes.Length) { hotbarBoxes[index].GetComponent <InventoryBoxManager>().UpdateIcon(item.icon); } else { inventoryBoxes[index - hotbarBoxes.Length].GetComponent <InventoryBoxManager>().UpdateIcon(item.icon); } return(true); } return(false); }
void PickUp() { //Debug.Log ("Picking up " + item.name); bool _bGetItem = false; PlayerInventory _inventory = player.GetComponent <PlayerInventory> (); if (_inventory != null) { _bGetItem = _inventory.Add(item); if (_bGetItem) { Destroy(gameObject); } else { Debug.Log("Inventory Full"); } } }