private void pickupWeaponSlot(WeaponData.Slot slotType) { int count = 0; foreach (ProgressData.SlotWrapper slot in this.Slots) { if (slot.SlotType == slotType) { ++count; } } if (count < WeaponData.GetMaxSlotsByType()[slotType]) { this.Slots.Add(new ProgressData.SlotWrapper(slotType)); } else { int shots = WeaponData.GetSlotDurationsByType()[slotType]; int shotsToAdd = shots; for (int i = this.Slots.Count - 1; i >= 0; --i) { ProgressData.SlotWrapper slot = this.Slots[i]; if (slot.SlotType == slotType) { slot.AmmoRemaining += shotsToAdd; if (slot.AmmoRemaining > shots) { shotsToAdd = slot.AmmoRemaining - shots; slot.AmmoRemaining = shots; } else { break; } } } } /*bool found = false; * for (int i = 0; i < this.Slots.Length; ++i) * { * if (this.Slots[i] == WeaponData.Slot.Empty) * { * found = true; * this.Slots[i] = slotType; * _selectedSlot = i + 1 >= this.Slots.Length ? 0 : i + 1; * break; * } * } * if (!found) * { * this.Slots[_selectedSlot] = slotType; * _selectedSlot = _selectedSlot + 1 >= this.Slots.Length ? 0 : _selectedSlot + 1; * }*/ updateSlots(); }
public static void PickupSlot(int playerIndex, WeaponData.Slot slotType) { int count = 0; List <ProgressData.SlotWrapper> slots = new List <ProgressData.SlotWrapper>(WeaponSlotsByPlayer[playerIndex]); foreach (ProgressData.SlotWrapper slot in slots) { if (slot.SlotType == slotType) { ++count; } } if (count < WeaponData.GetMaxSlotsByType()[slotType]) { slots.Add(new ProgressData.SlotWrapper(slotType)); } else { int shots = WeaponData.GetSlotDurationsByType()[slotType]; int shotsToAdd = shots; for (int i = slots.Count - 1; i >= 0; --i) { ProgressData.SlotWrapper slot = slots[i]; if (slot.SlotType == slotType) { slot.AmmoRemaining += shotsToAdd; if (slot.AmmoRemaining > shots) { shotsToAdd = slot.AmmoRemaining - shots; slot.AmmoRemaining = shots; } else { break; } } } } UpdatePlayerSlots(playerIndex, slots.ToArray()); }
private void shotFired(bool ignoreExplosions) { // Update slots bool[] typesFound = { false, false, false, false }; for (int i = 0; i < this.Slots.Count;) { ProgressData.SlotWrapper slot = this.Slots[i]; if ((slot.SlotType != WeaponData.Slot.Bomb || !ignoreExplosions) && !typesFound[(int)slot.SlotType - 1]) { typesFound[(int)slot.SlotType - 1] = true; slot.AmmoRemaining -= 1; if (slot.AmmoRemaining <= 0) { slot.SlotType = WeaponData.Slot.Empty; this.Slots.RemoveAt(i); continue; } } ++i; } this.updateSlots(); }