public bool Stack(ItemController item) { if (item is ConsumableItem) { ConsumableItem consumable = (item as ConsumableItem); ItemController itContrl = GetItemByName(consumable.Stats.ItemName); if (itContrl != null && itContrl is ConsumableItem) { ConsumableItem alreadyInInventary = (itContrl as ConsumableItem); int max = alreadyInInventary.getConsumableStats().MaxUnits; if (max == alreadyInInventary.Units) { return(true); } int totalUnits = alreadyInInventary.Units + consumable.Units; int difference = (totalUnits - max); alreadyInInventary.Units = (difference > 0 ? max : totalUnits); consumable.Units = (difference > 0 ? difference : 0); if (consumable.Units <= 0) { ConsumableItem.Destroy(consumable.gameObject); return(true); } } } return(false); }
private void FixedUpdate() { if (invItem != null) { if (invItem is ConsumableItem) { ConsumableItem it = (invItem as ConsumableItem); if (Text != null) { Text.text = it.Units + "/" + it.getConsumableStats().MaxUnits; } countDown.fillAmount = it.GetActualUseState(); } else if (invItem is GunController) { GunController it = (invItem as GunController); if (Text != null) { Text.text = it.FireState.mode + "\n" + it.ActualAmmo + "/" + it.getGunStats().maxClip; } } } }
private void FixedUpdate() { deltaTime += Time.deltaTime; if (reloading != null && reloading.GetActualUseState() >= 0.99) { reloading.usingChar.ik.DisableLeftHand = !reloading.getConsumableStats().DisableLeftHand; reloading.usingChar.ik.DisableRightHand = !reloading.getConsumableStats().DisableRightHands; reloading = null; } }
public override void Use(CharController character) { InventaryGroup g = character.inventary.GetGroup("Ammo"); if (g != null) { ItemController it = g.GetItemByName(getGunStats().ammoName); if (it != null && it is ConsumableItem) { ConsumableItem consumable = (it as ConsumableItem); int lack = (this.getGunStats().maxClip - ActualAmmo); if (lack <= 0) { return; } else { int getUnits = (consumable.Units < lack ? consumable.Units : lack); reloading = consumable; consumable.Use(character); consumable.Units -= getUnits; ActualAmmo += getUnits; int index = character.anim.GetLayerIndex(Stats.animLayer); character.anim.Play(Stats.animation, index); character.anim.SetLayerWeight(index, 1); character.ik.DisableLeftHand = consumable.getConsumableStats().DisableLeftHand; character.ik.DisableRightHand = consumable.getConsumableStats().DisableRightHands; Debug.Log(Stats.animation); Debug.Log(index); } } } base.Use(character); }
private void ItemsControl() { Collider[] checking = Physics.OverlapSphere(LookAt.position, 2f, LayerMask.GetMask("Item")); if (states.Inventary) { Collider[] checkingArround = Physics.OverlapSphere(this.tr.position, 2f, LayerMask.GetMask("Item")); inventary.inventaryViewer.SceneViewer.ShowItems(checkingArround); } if (checking.Length > 0) { float near = 2f; Collider nearest = null; foreach (Collider c in checking) { Vector3 collisionpos = c.ClosestPoint(LookAt.position); float distance = Vector3.Distance(collisionpos, LookAt.position); if (distance < near) { nearest = c; near = distance; } } if (nearest != null) { ItemController item = nearest.GetComponent <ItemController>(); if (item != null) { if (Player) { inventary.ItemViewer.DrawItemViewer(item.Stats, item.mTransform, cam); } if (states.Interacting) { if (item.Stats.IsPickeable) { Take(item); } else { item.Use(this); } ///take MULTI// inventary.AddItem(this, item); } } } } else { if (this.Player) { inventary.ItemViewer.HideViewer(); } } if (!states.Throwing) { this.GunControl(); } else { this.ThrowControl(); } if (states.Consuming) { ItemController selectedMed = inventary.GetSelectedAt("Meds"); if (selectedMed != null) { if (selectedMed is ConsumableItem) { ConsumableItem consumable = selectedMed as ConsumableItem; consumable.Use(this); } } } }