/// <summary> /// /// </summary> public virtual void On_Draw(SavableItem correspondingItem) { IsEnabled = true; CorrespondingItem = correspondingItem; LastDrawTime = Time.time; m_Durability = correspondingItem.GetPropertyValue("Durability"); Draw.Send(); }
public override void On_Draw(SavableItem correspondingItem) { base.On_Draw(correspondingItem); //m_AmmoProperty = correspondingItem.GetPropertyValue("Ammo Type"); if (correspondingItem && correspondingItem.HasProperty("Ammo Type")) { m_AmmoProperty = correspondingItem.GetPropertyValue("Ammo Type"); } if (correspondingItem && correspondingItem.HasProperty("Ammo Capacity")) { m_AmmoProperty = correspondingItem.GetPropertyValue("Ammo Capacity"); } if (correspondingItem && correspondingItem.HasProperty("Ammo")) { m_AmmoProperty = correspondingItem.GetPropertyValue("Ammo"); } }
//reload Ammo public bool LoadAmmo(Slot initialSlot, SavableItem itemUnderPointer) { bool canLoadAmmo = ( //make sure that the item that you drag and the item in the slot are exixcte itemUnderPointer && m_DraggedItem && //make sure that both items have the property ammo type , so you dont get null values m_DraggedItem.HasProperty("Ammo Type") && itemUnderPointer.HasProperty("Ammo Type") && //make sure that the weapon and the ammo have the same Ammo type m_DraggedItem.GetPropertyValue("Ammo Type").String == itemUnderPointer.GetPropertyValue("Ammo Type").String&& //make sure that only the drager item is an Ammo and not the item already in the slot m_DraggedItem.HasProperty("Is Ammo") && m_DraggedItem.GetPropertyValue("Is Ammo").Bool&& !itemUnderPointer.HasProperty("Is Ammo") && itemUnderPointer.HasProperty("Ammo Capacity") && itemUnderPointer.HasProperty("Ammo ")); if (canLoadAmmo) { //define out variables //pick up amm stock size int ammostack = m_DraggedItem.CurrentInStack; //current ammo m_AmmoAmount = itemUnderPointer.GetPropertyValue("Ammo"); var ammo = m_AmmoAmount.Int; //capacity m_AmmoCapacity = itemUnderPointer.GetPropertyValue("Ammo Capacity"); //make sure taht the gun is not already full loaded if (m_AmmoAmount.Int.Current < m_AmmoCapacity.Int.Current) { //check if there ammo in object we pick up if (ammostack > 0) { int needAmmo = m_AmmoCapacity.Int.Current - m_AmmoAmount.Int.Current; //if you need more mmothan what is the enter stack we consule all the ammo if (needAmmo >= ammostack) { //reload the gun ammo.Current += ammostack;//has to be correct type m_AmmoAmount.SetValue(ItemProperty.Type.Int, ammo); GameController.LocalPlayer.Reload.Try(needAmmo); //destroy Ammo Destroy(m_DraggedItemRT.gameObject); m_DraggedItem = null; m_Dragging = false; initialSlot.Refresh(); return(true); } //else we will use all the ammo we can and return what is left else { ammo.Current += needAmmo;//has to correct type m_AmmoAmount.SetValue(ItemProperty.Type.Int, ammo); int remainingAmmo = ammostack - needAmmo; m_DraggedItem.CurrentInStack = remainingAmmo; GameController.LocalPlayer.Reload.Try(needAmmo); //put what it left in our ammo stack where we pick it up PutItemBack(initialSlot); initialSlot.Refresh(); //destroy the ammo(because we already put it back) Destroy(m_DraggedItemRT.gameObject); m_DraggedItem = null; m_Dragging = false; return(true); } } else { return(false); } } else { //Gun is full /put the bullet back PutItemBack(initialSlot); initialSlot.Refresh(); //destroy the ammo(because we already put it back) Destroy(m_DraggedItemRT.gameObject); m_DraggedItem = null; m_Dragging = false; return(true); } } else { return(false); } }