public bool CheckEqual(LoadableItem other) { // Assert.IsTrue( prefabSrc.Length > 0 ); // Assert.IsTrue( other.prefabSrc.Length > 0 ); // print( prefabSrc + " " + other.prefabSrc ); return(prefabSrc == other.prefabSrc); }
private void ExportEngineRun() { List <TaskActivity> appropriateActivities = new List <TaskActivity>(); TimeSpan totalDays = _endDateAndTime - _startDateAndTime; for (int day = 0; day <= totalDays.Days; day++) { DateTime date = _startDateAndTime.AddDays(day); Collection <TaskActivity> allActivities = AppContext.Current.TaskActivitiesProvider.LoadActivities(date); foreach (TaskActivity activity in allActivities) { if (_selectedTaskDescriptions.Contains(activity.TaskDescription)) { if ((activity.StartDate >= _startDateAndTime) && (activity.StartDate <= _endDateAndTime)) { appropriateActivities.Add(activity); } } } } LoadableItem loadableItem = _selectedExporter; if (loadableItem != null) { if (loadableItem.CreateInstance() is PluginExporter exporter) { exporter.AcceptData(_startDateAndTime, _endDateAndTime, appropriateActivities.ToArray(), null); exporter.BeforeExecuteSummary(); exporter.Execute(); } } Close(); }
// Returns leftover items. public virtual int TryStackItem(LoadableItem item, int quantity = 1) { // if( CheckExisting( item ) ) if (quantity > 0) { foreach (var slot in slots) { int space = slot.GetMaxStackSize() - slot.CountItems(); var stackRemoveSize = Mathf.Min(quantity, space); if (slot.CanStack(item, stackRemoveSize) || slot.CountItems() < 1) { if (slot.TrySetItem(item, stackRemoveSize)) { quantity -= stackRemoveSize; } // quantity -= space; if (quantity < 1) { break; } } } } return(quantity); }
// copy other's data into this public void Copy(LoadableItem other) { prefabSrc = other.prefabSrc; TryLoadPrefab(); invName = other.invName; invDesc = other.invDesc; }
public bool CanStack(LoadableItem item, int quantity = 1) { return(this.item != null && item.CheckEqual(this.item) && nItems < maxStackSize && item.GetPrefab().GetComponent <WeaponBase>() == null && this.item.GetPrefab().GetComponent <WeaponBase>() == null && quantity + CountItems() <= maxStackSize); }
// true if success false if full // public bool TryAddItem( LoadableItem item ) // { // bool full = true; // foreach( var slot in slots ) // { // if( slot.TrySetItem( item ) ) // { // full = false; // RefreshSlot(); // break; // } // } // // return( !full ); // } public override bool TryAddItem(LoadableItem item) { bool added = base.TryAddItem(item); if (added) { RefreshSlot(); } return(added); }
// Try to increase item stack, return false if same item not in hotbar. // public bool TryStackItem( LoadableItem item ) // { // foreach( var slot in slots ) // { // // if( slot.GetItem() == item ) // if( slot.TrySetItem( item ) ) // { // // slot.AddItem( item ); // RefreshSlot(); // return( true ); // } // } // // return( false ); // } public override int TryStackItem(LoadableItem item, int quantity = 1) { int leftover = base.TryStackItem(item, quantity); if (leftover != quantity) { RefreshSlot(); } return(leftover); }
public override bool TryConsumeItem(LoadableItem item, int quantity = 1) { bool consumed = false; consumed = hotbar.TryConsumeItem(item, quantity); if (!consumed) { consumed = base.TryConsumeItem(item, quantity); } return(consumed); }
// true if success false if full public virtual bool TryAddItem(LoadableItem item) { foreach (var slot in slots) { if (slot.TrySetItem(item)) { return(true); } } return(false); }
public bool CheckExisting(LoadableItem checkItem) { foreach (var slot in slots) { if (slot.GetItem().CheckEqual(checkItem) && slot.GetItem() != checkItem) { return(true); } } return(false); }
// true if success false if full public bool AddItem(LoadableItem item) { bool full = true; // try stacking item in hotbar, then inventory, before creating new stack // if( hotbar.TryStackItem( item ) < 1 || TryStackItem( item ) < 1 ) // { // full = false; // } if (hotbar.CheckExisting(item) && hotbar.TryStackExisting(item) < 1) { full = false; } else if (CheckExisting(item) && TryStackExisting(item) < 1) { full = false; } if (full) { if (hotbar.CheckExisting(item) && hotbar.TryStackItem(item) < 1) { full = false; } else if (CheckExisting(item) && TryStackItem(item) < 1) { full = false; } } if (full && hotbar.TryAddItem(item)) { full = false; } if (full) { // foreach( var slot in slots ) // { // if( slot.TrySetItem( item ) ) // { // full = false; // break; // } // } full = TryAddItem(item); } return(!full); }
public void SetPickup(LoadableItem prefab) { if (prefab != null) { if (pickupPrefab == null) { pickupPrefab = gameObject.AddComponent <LoadableItem>(); } pickupPrefab.Copy(prefab); var actualPickup = Instantiate(pickupPrefab.GetPrefab().transform.GetChild(0).gameObject, transform); actualPickup.transform.position = transform.Find("WeaponHoldPos").position; } }
bool CheckSpotMatch(LoadableItem desired, InventorySlot slot, int quantity) { if (desired == null || slot == null) { return(true); } else { return((desired.GetSrc() == slot.GetItem().GetSrc() && slot.CountItems() >= quantity) || (desired.GetComponent <WeaponBase>() != null && slot.GetPrefab().GetComponent <WeaponBase>() != null && desired.GetComponent <PotionBase>() != null && slot.GetPrefab().GetComponent <PotionBase>() != null)); } }
// Return true if quantity exists of item and was consumed. public virtual bool TryConsumeItem(LoadableItem item, int quantity = 1) { bool consumable = false; foreach (var slot in slots) { if (slot.GetItem().CheckEqual(item) && slot.CountItems() >= quantity) { consumable = true; slot.RemoveItem(quantity); break; } } return(consumable); }
public int TryStackExisting(LoadableItem item, int quantity = 1) { foreach (var slot in slots) { int space = slot.GetMaxStackSize() - slot.CountItems(); var stackRemoveSize = Mathf.Min(quantity, space); if (slot.CanStack(item, stackRemoveSize) /* || slot.CountItems() < 1*/) { if (slot.TrySetItem(item, stackRemoveSize)) { quantity -= stackRemoveSize; } if (quantity < 1) { break; } } } return(quantity); }
// void OnDestroy() // { // string idStr = ""; // foreach( var c in gameObject.name ) // { // if( char.IsNumber( c ) ) idStr += c; // } // int id = ( idStr.Length > 0 ? int.Parse( idStr ) : 0 ); // // var storage = transform.parent.name; // // print( storage + " " + id ); // } public void AddItem(LoadableItem item, int quantity = 1) { Assert.IsTrue(nItems + quantity <= maxStackSize); Assert.IsTrue(quantity > 0); nItems += quantity; Assert.IsTrue(item != null); Assert.IsTrue(this.item != null); Assert.IsNotNull(item.GetPrefab()); if (this.item.GetPrefab() == null) { // heldPrefab = prefab; // heldItem = Instantiate( prefab.transform.GetChild( 0 ).gameObject,itemPos ); // this.item = item; // this.item = GetComponent<LoadableItem>(); this.item.Copy(item); heldModel = Instantiate(item.GetPrefab().transform.GetChild(0).gameObject, itemPos); heldModel.transform.localPosition = new Vector3(-16.6f, -16.7f, -0.8f); heldModel.transform.localScale *= itemScaleFactor; heldModel.transform.localEulerAngles = new Vector3(39.2f, 70.5f, -12.6f); if (this.item.GetPrefab().GetComponent <WeaponBase>() == null) { heldModel.transform.localPosition += Vector3.right * (-2.6f + 16.6f); heldModel.transform.localPosition += Vector3.up * (-0.6f + 16.6f); heldModel.transform.localEulerAngles += Vector3.forward * (-58.0f - 12.6f); } var meshRend = heldModel.transform.GetComponentInChildren <MeshRenderer>(); meshRend.gameObject.layer = uiLayer; meshRend.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; } // else { UpdateCounter(); } }
// swaps this's data with other public void Swap(LoadableItem other) { var tempPrefSrc = prefabSrc; prefabSrc = other.prefabSrc; other.prefabSrc = tempPrefSrc; var tempPrefab = prefab; prefab = other.prefab; other.prefab = tempPrefab; var tempName = invName; invName = other.invName; other.invName = tempName; var tempDesc = invDesc; invDesc = other.invDesc; other.invDesc = tempDesc; }
// return true if success in setting item, false if already full public bool TrySetItem(LoadableItem item, int quantity = 1) { Assert.IsTrue(item != null); bool canSwap = true; // if( heldItem != null ) print( prefab.name + " " + heldPrefab.name ); // if( this.item.GetPrefab() != null ) // { // if( !item.CheckEqual( this.item ) || // nItems >= maxStackSize || // item.GetPrefab().GetComponent<WeaponBase>() != null || // this.item.GetPrefab().GetComponent<WeaponBase>() != null ) // { // canSwap = false; // } // } if (!CanStack(item, quantity)) { canSwap = false; } if (this.item.GetPrefab() == null) { canSwap = true; } // print( item.GetPrefab().GetComponent<WeaponBase>() ); // print( this.item ); if (canSwap) { AddItem(item, quantity); } return(canSwap); }
void AddInSlot(LoadableItem item, int quantity, int slot) { Assert.IsTrue(slots[slot].GetItem().GetPrefab() == null); slots[slot].AddItem(item, quantity); }