void DeleteRecord()
    {
        int idxStation;
        int idxCommodityShop;

        //Find the object in the database
        StationDataObject tempSDO = dbStations.database.Find(x => x .stationID.Equals(currentlySelectedStationID));
        CommodityShopDataObject tempCSDO = dbCommodityShops.database.Find(x => x.stationID.Equals(currentlySelectedStationID));

        //Get the index
        idxStation = dbStations.database.IndexOf(tempSDO);
        idxCommodityShop = dbCommodityShops.database.IndexOf(tempCSDO);

        //Remove by index
        dbStations.database.RemoveAt(idxStation);
        dbCommodityShops.database.RemoveAt(idxCommodityShop);

        //Update the SOs
        EditorUtility.SetDirty(dbStations);
        EditorUtility.SetDirty(dbCommodityShops);

        //For clearing the form
        sdo = new StationDataObject();
        csdo = new CommodityShopDataObject();

        //Clear the flag
        currentlySelectedStationID = 0;
    }
    private void Initialize()
    {
        //Because we might not have child items for each station, we need to add in blanks to those databases in order to
        //  prepare for the eventual filling-in of the data
        bool cshopIsDirty = false;
        if (dbCommodityShops.Count < dbStations.Count)
        {
            for (int i = 0; i <= dbStations.Count - 1; i++)
            {
                int stationID = dbStations.database[i].stationID;
                CommodityShopDataObject tempCdso = dbCommodityShops.GetCommodityShopByStation(stationID);
                if (tempCdso.shopName == string.Empty)
                {
                    tempCdso = new CommodityShopDataObject(stationID, "New Commodity Shop", "This space for rent", Texture2D.whiteTexture);
                    dbCommodityShops.Add(tempCdso);

                    cshopIsDirty = true;
                }
            }
        }

        if (cshopIsDirty) { EditorUtility.SetDirty(dbCommodityShops); }

        sdo = new StationDataObject();
        csdo = new CommodityShopDataObject();
    }
    void DeleteRecord()
    {
        int idxStation;
        int idxCommodityShop;

        //Find the object in the database
        StationDataObject tempSDO = dbStations.database.Find(x => x .stationID.Equals(currentlySelectedStationID));
        CommodityShopDataObject tempCSDO = dbCommodityShops.database.Find(x => x.stationID.Equals(currentlySelectedStationID));

        //Get the index
        idxStation = dbStations.database.IndexOf(tempSDO);
        idxCommodityShop = dbCommodityShops.database.IndexOf(tempCSDO);

        //Remove by index
        dbStations.database.RemoveAt(idxStation);
        dbCommodityShops.database.RemoveAt(idxCommodityShop);

        //Update the SOs
        EditorUtility.SetDirty(dbStations);
        EditorUtility.SetDirty(dbCommodityShops);

        //For clearing the form
        sdo = new StationDataObject();
        csdo = new CommodityShopDataObject();

        //Clear the flag
        currentlySelectedStationID = 0;
    }
Example #4
0
    public StationDataObject GetStationData(int StationID)
    {
        StationDataObject sdo = DataController
                                .DataAccess
                                .stationMasterList
                                .FirstOrDefault(x => x.stationID.Equals(StationID));

        return(sdo);
    }
    public StationDataObject GetStationByID(int StationID)
    {
        StationDataObject sdo = database.Find(x => x.stationID.Equals(StationID));

        if (sdo.stationName == string.Empty)
        {
            sdo = new StationDataObject();
        }
        return(sdo);
    }
    private void Init()
    {
        StationDataObject sdo = sc.GetStationData(this.stationID);

        if (sdo != null)
        {
            stationName         = sdo.stationName;
            sdo.stationPosition = transform.position;
        }
    }
    void CreateRecord()
    {
        //Get the next StationID in sequence
        int newStationID = dbStations.database.Max(x => x.stationID) + 1;

        //Create new dummy records
        sdo = new StationDataObject(newStationID, 0, "New station");
        csdo = new CommodityShopDataObject(newStationID, "New commodity shop", "This space for rent", Texture2D.whiteTexture);

        //Add new records to database
        dbStations.Add(sdo);
        dbCommodityShops.Add(csdo);

        //Set the currently selected StationID
        currentlySelectedStationID = newStationID;
    }
    void CreateRecord()
    {
        //Get the next StationID in sequence
        int newStationID = dbStations.database.Max(x => x.stationID) + 1;

        //Create new dummy records
        sdo = new StationDataObject(newStationID, 0, "New station");
        csdo = new CommodityShopDataObject(newStationID, "New commodity shop", "This space for rent", Texture2D.whiteTexture);

        //Add new records to database
        dbStations.Add(sdo);
        dbCommodityShops.Add(csdo);

        //Set the currently selected StationID
        currentlySelectedStationID = newStationID;
    }
    private void Initialize()
    {
        //Because we might not have child items for each station, we need to add in blanks to those databases in order to
        //  prepare for the eventual filling-in of the data
        bool cshopIsDirty = false;
        if (dbCommodityShops.Count < dbStations.Count)
        {
            for (int i = 0; i <= dbStations.Count - 1; i++)
            {
                int stationID = dbStations.database[i].stationID;
                CommodityShopDataObject tempCdso = dbCommodityShops.GetCommodityShopByStation(stationID);
                if (tempCdso.shopName == string.Empty)
                {
                    tempCdso = new CommodityShopDataObject(stationID, "New Commodity Shop", "This space for rent", Texture2D.whiteTexture);
                    dbCommodityShops.Add(tempCdso);

                    cshopIsDirty = true;
                }
            }
        }

        if (cshopIsDirty) { EditorUtility.SetDirty(dbCommodityShops); }

        sdo = new StationDataObject();
        csdo = new CommodityShopDataObject();
    }
    private void EditorPopulation()
    {
        //###############################################################################################
        // New station button. Also creates a new set of child shops
        if (GUILayout.Button("New Station"))
        {
            //Create empty data buckets. Reset the currentlySelectedStation
            //currentlySelectedStationID = 0;
            CreateRecord();
        }

        //If we HAVE a currently selected station, get its data
        if (currentlySelectedStationID > 0)
        {
             sdo = dbStations.GetStationByID(currentlySelectedStationID);
             csdo = dbCommodityShops.GetCommodityShopByStation(currentlySelectedStationID);
        }

        //###############################################################################################
        //Main station input form
        //Change check: if anything in this block changes, we need to mark the DB as dirty for update.
        EditorGUI.BeginChangeCheck();
        sdo.stationName = EditorGUILayout.TextField("Name", sdo.stationName, GUILayout.Width(400));
        sdo.sectorID = EditorGUILayout.IntField("Sector", sdo.sectorID, GUILayout.Width(200));
        sdo.stationPosition = EditorGUILayout.Vector3Field("Position", sdo.stationPosition, GUILayout.Width(400));
        if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(dbStations); }

        EditorGUILayout.Space();

        foldOutCShop = EditorGUILayout.Foldout(foldOutCShop, "Commodity Shop");
        if (foldOutCShop) {

            //###############################################################################################
            //Commodity market input form

            //Change check: if anything in this block changes, we need to mark the DB as dirty for update.
            EditorGUI.BeginChangeCheck();
            csdo.shopName = EditorGUILayout.TextField("Shop Name", csdo.shopName, GUILayout.Width(350));

            EditorGUILayout.BeginHorizontal();
            csdo.shopDescription = EditorGUILayout.TextArea(csdo.shopDescription, GUILayout.Width(350), GUILayout.Height(64));
            csdo.shopkeeperPortraitTexture = (Texture2D)EditorGUILayout.ObjectField(csdo.shopkeeperPortraitTexture, typeof(Texture2D), false, GUILayout.Height(64), GUILayout.Width(64));
            EditorGUILayout.EndHorizontal();

            if (EditorGUI.EndChangeCheck()) {
                //If this doesn't have a cshop record, we need to add one
                EditorUtility.SetDirty(dbCommodityShops);
            }
        }

        EditorGUILayout.Space();

        //###############################################################################################
        // Delete this station and child shops

        EditorGUILayout.BeginHorizontal();
        okDelete = EditorGUILayout.BeginToggleGroup("Delete the station and everyone in it.", okDelete);

        //Sanity check(mark)
        if (GUILayout.Button("Delete this station", GUILayout.Width(175)) && currentlySelectedStationID > 0)
        {
            DeleteRecord();

            okDelete = false;
        }

        EditorGUILayout.EndToggleGroup();

        EditorGUILayout.EndHorizontal();
    }
Example #11
0
    /*#############################################################################################
    * Merchant NPCs should be loaded into GDC from MDS and augmented from the state file if a
    * save game has been loaded.
    * ---
    * The simulation runs on a timer, and that timer actually acts based on an interval value
    * that has a base setting defined above, and a random value for each NPC that is assigned
    * when the NPC is added to the data pool. This allows us to stagger the activity of NPCs so
    * they don't all act at the exact same time.
    *
    * When a tick happens, NPCs will:
    * * Check to see if the next action will take place in the player's current sector or not.
    *      This will determine if we only simulate or have to instantiate
    * * Simulation:
    *      If at a station, they will find a station that buys their goods for less than they
    *      paid for them, calc the route, and jump to the first sector.
    *      If in a sector on their route, they'll jump to the next sector in the route
    *      If the next sector in the route is the destination sector, they'll dock immediately
    *          at the station, sell their goods, and buy the lowest cost good that they can
    *          afford/fit into their cargo hold
    *  * Instantiation
    *  If at any time any of the sim steps coincide with the player's current sector
    *      If at a station, we instantiate the prefab at the spawn point outside of that station
    *          and assign any data we need from the data object to the component (at least the
    *          ID of the data object and the name of the pilot). We also generate the route as
    *          per the sim verion and the NPC will start their trip to the necessary gate.
    *      If in a sector, we instantiate the prefab at the gate that leads to the previous
    *          sector. The NPC will move to the gate that leads to the next sector, and the
    *          gate mechanics will take over at that point.
    *      If in the destination sector, the NPC will spawn at the inbound gate and will move
    *          to the destination station where the docking process will take over.
    * ---
    * The tick might happen before or after the player arrives in the system. In this case, the tick
    *      will be SIMULATED and will not invoke the instantiation, so the NPC will "ghost in" while
    *      the player isn't looking.
    * Certain instantiated activities will force a tick and reset the tick timer for that NPC:
    *  * Jumping out of a system - gate mechanics transfer the NPC and resets the timer
    *  * Docking at a station - triggers the buying and selling, and resets the timer
    #############################################################################################*/
    /*
     *
     */

    public void LoadNewMerchants()
    {
        //Takes the records from the DataController and puts them into the
        //  working collection for use in the game.
        List <MerchantNPCDataObject> Merchs = DataController.DataAccess.merchantMasterList;

        //But we need to set them up with initial locations and purposes.

        foreach (MerchantNPCDataObject merch in Merchs)
        {
            //Each merchant will start at a station (currently 37)
            StationDataObject sdo = (from s in DataController.DataAccess.stationMasterList orderby System.Guid.NewGuid() select s).First();

            merch.CurrentSectorID  = sdo.sectorID;
            merch.CurrentStationID = sdo.stationID;

            //Now it needs to BUY stuff from that station
            //  Go for the LOWEST PRICED ITEM
            List <CommodityShopInventoryDataObject> shopInv  = DataController.DataAccess.GetShopInventory(sdo.stationID);
            CommodityShopInventoryDataObject        csidoBuy = (from si in shopInv where si.currentPrice.Equals(shopInv.Min(s => s.currentPrice)) && si.shopBuysOrSells.Equals("S") select si).First();

            int shopQty = csidoBuy.commodityQuantity;

            //How much can we hold?
            int cargoCap = (from cgo in DataController.DataAccess.cargoHoldMasterList where cgo.iD.Equals(merch.CargoID) select cgo).FirstOrDefault().capacity;
            //Do we have anything in there already?
            int cargoNow = merch.Inventory.inventoryQuantity;

            if (cargoNow == 0)
            {
                //They can only carry one item, and since this is the only way for them to get
                //  items into their cargo hold, we assume they have something or they don't
                if (cargoNow < cargoCap)
                {
                    int canBuy = cargoCap - cargoNow;
                    if (shopQty > canBuy && (csidoBuy.currentPrice * canBuy) < merch.Wallet)
                    {
                        //Buy the canBuy amount.
                        merch.Inventory.inventoryQuantity    = canBuy;
                        merch.Inventory.inventoryObjectType  = PlayerInventoryDataObject.INVENTORY_TYPE.Commodity;
                        merch.Inventory.inventoryObjectID    = csidoBuy.commodityID;
                        merch.Inventory.inventoryObjectClass = PlayerInventoryDataObject.INVENTORY_CLASS.Commodity;
                        merch.InventoryPurchaseTotal         = (canBuy * csidoBuy.currentPrice);

                        merch.Wallet -= merch.InventoryPurchaseTotal;
                    }
                    else
                    {
                        //Need to find another low price item to buy.
                        //Need to excise the item finding part into it's own method.
                        //Also need to track the ID's of the items we've already tried.
                    }
                }
            }

            //So we have cargo (theoretically). Figure out where in the universe we can sell this crap
            CommodityShopInventoryDataObject csidoSell = (from si in DataController.DataAccess.CommodityShopInventoryList where
                                                          si.commodityID.Equals(csidoBuy.commodityID) &&
                                                          si.stationID != sdo.stationID &&
                                                          si.currentPrice > csidoBuy.currentPrice
                                                          select si).FirstOrDefault();

            //Ideally we have values. Set them
            merch.DestinationSectorID = 0; //Crap. Need to get this from the record we have in csidoSell  :(
        }
    }
 public StationDataObject GetStationByID(int StationID)
 {
     StationDataObject sdo = database.Find(x => x.stationID.Equals(StationID));
     if (sdo.stationName == string.Empty) { sdo = new StationDataObject(); }
     return sdo;
 }
 public void Remove(StationDataObject dataObject)
 {
     database.Remove(dataObject);
 }
 public void Add(StationDataObject dataObject)
 {
     database.Add(dataObject);
 }
 public void Remove(StationDataObject dataObject)
 {
     database.Remove(dataObject);
 }
    private void EditorPopulation()
    {
        //###############################################################################################
        // New station button. Also creates a new set of child shops
        if (GUILayout.Button("New Station"))
        {
            //Create empty data buckets. Reset the currentlySelectedStation
            //currentlySelectedStationID = 0;
            CreateRecord();
        }

        //If we HAVE a currently selected station, get its data
        if (currentlySelectedStationID > 0)
        {
             sdo = dbStations.GetStationByID(currentlySelectedStationID);
             csdo = dbCommodityShops.GetCommodityShopByStation(currentlySelectedStationID);
        }

        //###############################################################################################
        //Main station input form
        //Change check: if anything in this block changes, we need to mark the DB as dirty for update.
        EditorGUI.BeginChangeCheck();
        sdo.stationName = EditorGUILayout.TextField("Name", sdo.stationName, GUILayout.Width(400));
        sdo.sectorID = EditorGUILayout.IntField("Sector", sdo.sectorID, GUILayout.Width(200));
        sdo.stationPosition = EditorGUILayout.Vector3Field("Position", sdo.stationPosition, GUILayout.Width(400));
        if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(dbStations); }

        EditorGUILayout.Space();

        foldOutCShop = EditorGUILayout.Foldout(foldOutCShop, "Commodity Shop");
        if (foldOutCShop) {

            //###############################################################################################
            //Commodity market input form

            //Change check: if anything in this block changes, we need to mark the DB as dirty for update.
            EditorGUI.BeginChangeCheck();
            csdo.shopName = EditorGUILayout.TextField("Shop Name", csdo.shopName, GUILayout.Width(350));

            EditorGUILayout.BeginHorizontal();
            csdo.shopDescription = EditorGUILayout.TextArea(csdo.shopDescription, GUILayout.Width(350), GUILayout.Height(64));
            csdo.shopkeeperPortraitTexture = (Texture2D)EditorGUILayout.ObjectField(csdo.shopkeeperPortraitTexture, typeof(Texture2D), false, GUILayout.Height(64), GUILayout.Width(64));
            EditorGUILayout.EndHorizontal();

            if (EditorGUI.EndChangeCheck()) {
                //If this doesn't have a cshop record, we need to add one
                EditorUtility.SetDirty(dbCommodityShops);
            }
        }

        EditorGUILayout.Space();

        //###############################################################################################
        // Delete this station and child shops

        EditorGUILayout.BeginHorizontal();
        okDelete = EditorGUILayout.BeginToggleGroup("Delete the station and everyone in it.", okDelete);

        //Sanity check(mark)
        if (GUILayout.Button("Delete this station", GUILayout.Width(175)) && currentlySelectedStationID > 0)
        {
            DeleteRecord();

            okDelete = false;
        }

        EditorGUILayout.EndToggleGroup();

        EditorGUILayout.EndHorizontal();
    }
 public void Add(StationDataObject dataObject)
 {
     database.Add(dataObject);
 }