예제 #1
0
    public void Initialize(InvItemData [] shipMods, ShipBase parent)
    {
        ParentShip = parent;
        ShipMods   = new List <ShipMod>();

        //find the active mod
        int activeModIndex = -1;

        for (int i = 0; i < shipMods.Length && i < NumberOfSlots; i++)
        {
            if (shipMods[i] != null && shipMods[i].Item.GetStringAttribute("Equipment Type") == "ActiveShipMod")
            {
                activeModIndex = i;
                string className = shipMods[i].Item.GetStringAttribute("Active Mod Class Name");
                ActiveMod = (ShipMod)System.Activator.CreateInstance(System.Type.GetType(className));
                ActiveMod.Initialize(shipMods[i]);
                ShipMods.Add(ActiveMod);
                Debug.Log("Found ship mod " + ActiveMod.Type);
            }
        }

        //now add the passive mods. this ensures the active mod is always the first one in the list
        for (int i = 0; i < shipMods.Length && i < NumberOfSlots; i++)
        {
            if (shipMods[i] != null && i != activeModIndex)
            {
                ShipModType type = (ShipModType)Enum.Parse(typeof(ShipModType), shipMods[i].Item.GetStringAttribute("Ship Mod Type"));
                ShipMod     mod  = CreateShipModByType(type);
                mod.Initialize(shipMods[i]);
                ShipMods.Add(mod);
                Debug.Log("Found ship mod " + mod.Type);
            }
        }
    }
예제 #2
0
    private ShipMod CreateShipModByType(ShipModType type)
    {
        switch (type)
        {
        case ShipModType.Engine:
            return(new ShipModEngine());

        case ShipModType.Hull:
            return(new ShipModHull());

        case ShipModType.Shield:
            return(new ShipModShield());
        }

        return(null);
    }