Beispiel #1
0
    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();
    }
Beispiel #2
0
    private void updateSlotHelper(WeaponData.Slot slotType, int ammoRemaining, int weaponLevel)
    {
        configureSprite(slotType);

        if (slotType != WeaponData.Slot.Empty)
        {
            SlotObject.sprite = this.UnlockedSlotSprite;

            if (this.BaseAmmo != null && !this.BaseAmmo.activeInHierarchy)
            {
                this.BaseAmmo.SetActive(true);
            }
            if (this.AmmoBar != null)
            {
                this.AmmoBar.UpdateLength(ammoRemaining, WeaponData.GetSlotDurationsByType()[slotType]);
            }

            if (this.TierText != null)
            {
                if (weaponLevel == WeaponData.GetMaxSlotsByType()[slotType])
                {
                    this.TierText.text = "MAX";
                }
                else
                {
                    this.TierText.text = "Lv." + weaponLevel;
                }
            }
        }
        else
        {
            if (this.AmmoBar != null)
            {
                this.AmmoBar.EmptyCompletely();
            }
            if (this.BaseAmmo != null)
            {
                this.BaseAmmo.SetActive(false);
            }
            if (this.TierText != null)
            {
                this.TierText.text = "";
            }
            SlotObject.sprite = this.LockedSlotSprite;
        }
    }
Beispiel #3
0
    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());
    }
Beispiel #4
0
 public void OnCollide(LocalEventNotifier.Event localEvent)
 {
     foreach (GameObject hit in ((CollisionEvent)localEvent).Hits)
     {
         if (((1 << hit.layer) & this.PickupLayer) != 0)
         {
             WeaponPickup pickup = hit.GetComponent <WeaponPickup>();
             if (pickup != null)
             {
                 if (pickup.PickupContents.Type == WeaponPickup.PickupType.WeaponSlot)
                 {
                     WeaponData.Slot          slotType   = (WeaponData.Slot)pickup.PickupContents.Parameter;
                     ProgressData.SmartSlot[] smartSlots = ProgressData.SmartSlotsFromWrappers(this.Slots.ToArray());
                     bool ok = true;
                     for (int i = 0; i < smartSlots.Length; ++i)
                     {
                         if (smartSlots[i].SlotType == slotType)
                         {
                             ok = smartSlots[i].Level < WeaponData.GetMaxSlotsByType()[slotType] || smartSlots[i].Ammo < WeaponData.GetSlotDurationsByType()[slotType];
                             break;
                         }
                     }
                     if (ok)
                     {
                         pickupWeaponSlot(slotType);
                         Destroy(hit);
                     }
                 }
                 else
                 {
                     if (_damagable.Health < ProgressData.MAX_HEALTH)
                     {
                         _damagable.Heal(pickup.PickupContents.Parameter);
                         Destroy(hit);
                     }
                 }
             }
         }
     }
 }
Beispiel #5
0
    private void menuSelection(LocalEventNotifier.Event e)
    {
        MenuElementSelectedEvent menuSelectionEvent = e as MenuElementSelectedEvent;

        if (menuSelectionEvent.Element == _menuElement)
        {
            if (this.SlotType != WeaponData.Slot.Empty)
            {
                if (ProgressData.GetPointsForPlayer(this.PlayerIndex) >= _cost)
                {
                    ProgressData.SmartSlot[] smartSlots = ProgressData.GetSmartSlots(this.PlayerIndex);
                    bool ok = true;
                    for (int i = 0; i < smartSlots.Length; ++i)
                    {
                        if (smartSlots[i].SlotType == this.SlotType)
                        {
                            ok = smartSlots[i].Level < WeaponData.GetMaxSlotsByType()[this.SlotType] || smartSlots[i].Ammo < WeaponData.GetSlotDurationsByType()[this.SlotType];
                            break;
                        }
                    }
                    if (ok)
                    {
                        this.SelectionImage.color = _normalColor;
                        ProgressData.ApplyPointsDeltaForPlayer(this.PlayerIndex, -_cost);
                        ProgressData.PickupSlot(this.PlayerIndex, this.SlotType);
                        GlobalEvents.Notifier.SendEvent(new PlayerPointsReceivedEvent(this.PlayerIndex, -_cost));
                        updateDisplay();
                    }
                    else
                    {
                        this.SelectionImage.color = this.NotEnoughColor;
                    }
                }
                else
                {
                    this.SelectionImage.color = this.NotEnoughColor;
                }
            }
            else if (ProgressData.GetHealthForPlayer(this.PlayerIndex) < ProgressData.MAX_HEALTH && ProgressData.GetPointsForPlayer(this.PlayerIndex) >= _cost)
            {
                this.SelectionImage.color = _normalColor;
                ProgressData.SetHealthForPlayer(this.PlayerIndex, ProgressData.GetHealthForPlayer(this.PlayerIndex) + 1);
                ProgressData.ApplyPointsDeltaForPlayer(this.PlayerIndex, -_cost);
                GlobalEvents.Notifier.SendEvent(new PlayerPointsReceivedEvent(this.PlayerIndex, -_cost));
                updateDisplay();
            }
            else
            {
                this.SelectionImage.color = this.NotEnoughColor;
            }
        }
    }
Beispiel #6
0
 public SlotWrapper(WeaponData.Slot slotType)
 {
     this.SlotType      = slotType;
     this.AmmoRemaining = WeaponData.GetSlotDurationsByType()[slotType];
 }