private void On_InputHolderUpdated(ItemHolder holder) { ItemProperty.Value durabilityProperty = null; if (holder.HasItem && holder.CurrentItem.HasProperty("Durability")) { durabilityProperty = holder.CurrentItem.GetPropertyValue("Durability"); } if (durabilityProperty != null && holder.CurrentItem.ItemData.IsCraftable && durabilityProperty.Float.Ratio != 1f) { if (holder.CurrentItem.ItemData.IsCraftable) { InputItem.Recipe = holder.CurrentItem.ItemData.Recipe; InputItem.DurabilityProperty = durabilityProperty; CalculateRequiredItems(InputItem.Recipe, InputItem.DurabilityProperty.Float.Ratio); InputItemReadyForRepair.SetAndForceUpdate(true); return; } } // If we're here it means the item in the input slot cannot be repaired, or it doesn't exist. //InputItem.DurabilityProperty = null; //InputItem.Recipe = null; InputItemReadyForRepair.SetAndForceUpdate(false); if (Repairing.Active) { Repairing.ForceStop(); } }
/// <summary> /// /// </summary> public virtual void On_Draw(SavableItem correspondingItem) { IsEnabled = true; CorrespondingItem = correspondingItem; LastDrawTime = Time.time; m_Durability = correspondingItem.GetPropertyValue("Durability"); Draw.Send(); }
private void StopBurning() { m_FuelTimeProperty = null; m_BurnTimeProperty = null; m_ItemResult = string.Empty; IsBurning.Set(false); if (m_BurningHandler != null) { StopCoroutine(m_BurningHandler); } m_BurningHandler = null; }
/// <summary> /// Use this if you are NOT sure the item has this property. /// </summary> public bool FindPropertyValue(string name, out ItemProperty.Value propertyValue) { propertyValue = null; if (!Initialized) { Debug.LogError("[SavableItem] - This SavableItem is not initialized, probably it was loaded and not initialized! (call OnLoad() after loading / deserializing)."); return(false); } for (int i = 0; i < m_CurrentPropertyValues.Count; i++) { if (m_CurrentPropertyValues[i].Name == name) { propertyValue = m_CurrentPropertyValues[i]; return(true); } } return(false); }
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"); } }
private void On_HolderUpdated(ItemHolder holder) { bool shouldStopBurning = false; if (FuelSlot.HasItem && InputSlot.HasItem) { // The items have the correct properties, and the burn process can begin. if (FuelSlot.CurrentItem.HasProperty("Fuel Time") && InputSlot.CurrentItem.HasProperty("Burn Time") && InputSlot.CurrentItem.HasProperty("Burn Result")) { if (IsBurning.Is(false)) { m_FuelTimeProperty = FuelSlot.CurrentItem.GetPropertyValue("Fuel Time"); m_BurnTimeProperty = InputSlot.CurrentItem.GetPropertyValue("Burn Time"); m_ItemResult = InputSlot.CurrentItem.GetPropertyValue("Burn Result").String; IsBurning.Set(true); m_BurningHandler = StartCoroutine(C_Burn()); return; } } else { shouldStopBurning = true; } } else { shouldStopBurning = true; } if (IsBurning.Is(true) && shouldStopBurning) { StopBurning(); } }
private void On_PropertyChanged(ItemProperty.Value propertyValue) { Updated.Send(this); }
private void On_PropertyChanged(ItemProperty.Value propertyValue) { PropertyChanged.Send(propertyValue); }
//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); } }