public static void UpdatePlayerSlots(int playerIndex, SlotWrapper[] slots) { if (!_weaponSlotsByPlayer.ContainsKey(playerIndex)) { _weaponSlotsByPlayer.Add(playerIndex, new SlotWrapper[slots.Length]); } else { _weaponSlotsByPlayer[playerIndex] = new SlotWrapper[slots.Length]; } for (int i = 0; i < slots.Length; ++i) { _weaponSlotsByPlayer[playerIndex][i] = new SlotWrapper(slots[i]); } }
public SlotWrapper(SlotWrapper other) { this.SlotType = other.SlotType; this.AmmoRemaining = other.AmmoRemaining; }
public static SmartSlot[] SmartSlotsFromWrappers(SlotWrapper[] wrappers) { SmartSlot[] smartSlots = new SmartSlot[5]; for (int i = 0; i < 4; ++i) { SmartSlot smartSlot = GetSmartSlot(wrappers, i); if (smartSlot.SlotType != WeaponData.Slot.Empty) smartSlots[(int)smartSlot.SlotType] = smartSlot; else break; } return smartSlots; }
public static SmartSlot GetSmartSlot(SlotWrapper[] slots, int slotId) { bool[] weaponTypesFound = { false, false, false, false }; int[] ammoRemaining = { 0, 0, 0, 0 }; int[] weaponLevel = { 0, 0, 0, 0 }; int numTypesFound = 0; WeaponData.Slot chosenSlotType = WeaponData.Slot.Empty; int chosenWeaponIndex = -1; for (int i = 0; i < slots.Length; ++i) { if (slots[i].SlotType == WeaponData.Slot.Empty) continue; int weaponIndex = (int)slots[i].SlotType - 1; ++weaponLevel[weaponIndex]; if (chosenSlotType == WeaponData.Slot.Empty && !weaponTypesFound[weaponIndex]) { ++numTypesFound; weaponTypesFound[weaponIndex] = true; ammoRemaining[weaponIndex] = slots[i].AmmoRemaining; if (numTypesFound > slotId) { chosenSlotType = slots[i].SlotType; chosenWeaponIndex = weaponIndex; } } } int ammo = chosenSlotType != WeaponData.Slot.Empty ? ammoRemaining[chosenWeaponIndex] : 0; int level = chosenSlotType != WeaponData.Slot.Empty ? weaponLevel[chosenWeaponIndex] : 0; return new SmartSlot(chosenSlotType, ammo, level); }
public static void UpdatePlayerSlots(int playerIndex, SlotWrapper[] slots) { if (!_weaponSlotsByPlayer.ContainsKey(playerIndex)) _weaponSlotsByPlayer.Add(playerIndex, new SlotWrapper[slots.Length]); else _weaponSlotsByPlayer[playerIndex] = new SlotWrapper[slots.Length]; for (int i = 0; i < slots.Length; ++i) { _weaponSlotsByPlayer[playerIndex][i] = new SlotWrapper(slots[i]); } }