示例#1
0
    public void OnInstallButtonClick()
    {
        if (_selectedItem != null)
        {
            if (_selectedItemContainer == CargoEquipmentInventory)
            {
                //check if available power is larger or equal to the _selectedItem
                if (_availablePower < _selectedItem.Item.GetFloatAttribute("Power Required"))
                {
                    //issue an error
                    GameManager.Inst.UIManager.ErrorMessagePanel.DisplayMessage("CANNOT INSTALL EQUIPMENT. NOT ENOUGH POWER");
                    return;
                }

                //remove the invItemData from cargo and assign it to the slot in loadout
                //determine the slot by "EquipmentType" attribute of the item

                string equipmentType = _selectedItem.Item.GetStringAttribute("Equipment Type");

                if (equipmentType != "PassiveShipMod" && equipmentType != "ActiveShipMod")
                {
                    //if is shield, check shield class
                    if (equipmentType == "Shield")
                    {
                        ShieldClass itemShieldClass = (ShieldClass)Enum.Parse(typeof(ShieldClass), _selectedItem.Item.GetStringAttribute("Shield Class"));
                        if (itemShieldClass != GameManager.Inst.ItemManager.AllShipStats[CurrentLoadout.ShipID].ShieldClass)
                        {
                            //issue an error
                            GameManager.Inst.UIManager.ErrorMessagePanel.DisplayMessage("SHIELD CLASS DOES NOT MATCH CURRENT SHIP");
                            return;
                        }
                    }

                    if (CurrentLoadout.CargoBayItems.Contains(_selectedItem))
                    {
                        CurrentLoadout.CargoBayItems.Remove(_selectedItem);
                    }

                    InvItemData tempItem = CurrentLoadout.GetInvItemFromEquipmentType(equipmentType);
                    if (tempItem != null)
                    {
                        CurrentLoadout.CargoBayItems.Add(tempItem);
                    }

                    CurrentLoadout.SetEquipmentInvItem(_selectedItem, equipmentType);
                    _selectedItem = null;
                    tempItem      = null;
                }
                else
                {
                    //check if dependency mod is equiped
                    string dependency = _selectedItem.Item.GetStringAttribute("Dependency");
                    if (dependency != "" && CurrentLoadout.GetShipModFromID(dependency) == null)
                    {
                        GameManager.Inst.UIManager.ErrorMessagePanel.DisplayMessage("CANNOT INSTALL SHIP MOD. DEPENDENCY REQUIRED");
                        return;
                    }

                    //try to install the mod
                    bool result = CurrentLoadout.SetShipModInvItem(_selectedItem, equipmentType);
                    if (result == false)
                    {
                        GameManager.Inst.UIManager.ErrorMessagePanel.DisplayMessage("NO SHIP MOD SLOTS AVAILABLE");
                        return;
                    }
                    else
                    {
                        if (CurrentLoadout.CargoBayItems.Contains(_selectedItem))
                        {
                            CurrentLoadout.CargoBayItems.Remove(_selectedItem);
                        }
                    }

                    _selectedItem = null;
                }



                Refresh();
            }
        }
    }