Exemplo n.º 1
0
    public void OnInstallButtonClick()
    {
        ShipStats shipStats = GameManager.Inst.ItemManager.AllShipStats[CurrentLoadout.ShipID];

        if (_selectedWeaponItem != null && _selectedWeaponItem.Item.Type == ItemType.Weapon)
        {
            bool slotFound = false;
            //find the first available weapon slot that >= weapon item's class
            for (int i = 0; i < shipStats.WeaponJoints.Count; i++)
            {
                if (CurrentLoadout.WeaponJoints[shipStats.WeaponJoints[i].JointID] == null && shipStats.WeaponJoints[i].Class >= _selectedWeaponItem.Item.GetIntAttribute("Weapon Class"))
                {
                    CurrentLoadout.SetWeaponInvItem(shipStats.WeaponJoints[i].JointID, _selectedWeaponItem);
                    slotFound = true;
                    break;
                }
            }

            if (!slotFound)
            {
                GameManager.Inst.UIManager.ErrorMessagePanel.DisplayMessage("NO WEAPON SLOTS AVAILABLE");
            }
            else
            {
                CurrentLoadout.CargoBayItems.Remove(_selectedWeaponItem);
                ClearSelections();
                Refresh();
            }
        }
        else if (_selectedWeaponItem != null && _selectedWeaponItem.Item.Type == ItemType.Defensives)
        {
            bool slotFound = false;
            for (int i = 0; i < CurrentLoadout.Defensives.Count; i++)
            {
                if (CurrentLoadout.Defensives[i] == null)
                {
                    //load the weapon
                    CurrentLoadout.Defensives[i] = _selectedWeaponItem;
                    slotFound = true;
                }
            }

            if (!slotFound)
            {
                GameManager.Inst.UIManager.ErrorMessagePanel.DisplayMessage("NO DEFENSIVE SLOTS AVAILABLE");
            }
            else
            {
                CurrentLoadout.CargoBayItems.Remove(_selectedWeaponItem);
                ClearSelections();
                Refresh();
            }
        }
    }