示例#1
0
        public string CommanderUpdateShip(int shipId, string type, EDDiscovery.EliteDangerous.ShipInformation shipinfo = null, int cargoqty = -1)
        {
            if (!IsApiKeySet)
            {
                return(null);
            }

            string query;

            query = "update-ship?commanderName=" + HttpUtility.UrlEncode(commanderName) + "&apiKey=" + apiKey;
            query = query + "&shipId=" + shipId.ToString();
            query = query + "&type=" + Uri.EscapeDataString(type);

            if (shipinfo != null)
            {
                int cargocap = shipinfo.CargoCapacity();
                if (cargocap != 0)
                {
                    query += "&cargoCapacity=" + cargocap.ToString();
                }
                if (cargoqty >= 0)
                {
                    query += "&cargoQty=" + cargoqty.ToString();
                }
                double fuelcap = shipinfo.FuelCapacity;
                if (fuelcap != 0)
                {
                    query += "&fuelMainCapacity=" + fuelcap.ToString();
                }
                double fuellevel = shipinfo.FuelLevel;
                if (fuellevel != 0)
                {
                    query += "&fuelMainLevel=" + fuellevel.ToString();
                }
                string ident = shipinfo.ShipUserIdent;
                if (!string.IsNullOrWhiteSpace(ident))
                {
                    query += "&shipIdent=" + Uri.EscapeDataString(ident);
                }
                string name = shipinfo.ShipUserName;
                if (!string.IsNullOrWhiteSpace(name))
                {
                    query += "&shipName=" + Uri.EscapeDataString(name);
                }
                string paintjob = shipinfo.Modules.ContainsKey("Paint Job") ? shipinfo.Modules["Paint Job"].ItemFD : null;
                if (!string.IsNullOrWhiteSpace(paintjob))
                {
                    query += "&paintJob=" + Uri.EscapeDataString(paintjob);
                }
            }

            var response = RequestGet("api-commander-v1/" + query, handleException: true);

            if (response.Error)
            {
                return(null);
            }

            return(response.Body);
        }
示例#2
0
        private ShipInformation EnsureShip(int id)      // ensure we have an ID of this type..
        {
            if (Ships.ContainsKey(id))
            {
                ShipInformation sm = Ships[id];
                if (!sm.Sold)               // if not sold, ok
                {
                    return(sm);
                }
                else
                {
                    Ships[newsoldid++] = sm;                      // okay, we place this information on 30000+  all Ids of this will now refer to new entry
                }
            }

            ShipInformation smn = new ShipInformation(id);

            Ships[id] = smn;
            return(smn);
        }
示例#3
0
        public ShipInformation RemoveModule(string slot, string item)
        {
            if (Modules.ContainsKey(slot))       // if has it..
            {
                ShipInformation sm = this.ShallowClone();
                sm.Modules.Remove(slot);

                if (item.Contains("Fuel Tank") && item.IndexOf("Class ") != -1)
                {
                    sm.FuelCapacity = sm.GetFuelCapacity();
                    if (sm.FuelLevel > sm.FuelCapacity)
                    {
                        sm.FuelLevel = sm.FuelCapacity;
                    }
                }

                return(sm);
            }
            return(this);
        }
示例#4
0
        public ShipInformation AddModule(string slot, string slotfd, string item, string itemfd, string itemlocalised)
        {
            if (!Modules.ContainsKey(slot) || !Modules[slot].Same(item))       // if does not have it, or item is not the same..
            {
                ShipInformation sm = this.ShallowClone();
                sm.Modules[slot] = new JournalLoadout.ShipModule(slot, slotfd, item, itemfd, itemlocalised);

                if (item.Contains("Fuel Tank") && item.IndexOf("Class ") != -1)
                {
                    sm.FuelCapacity = sm.GetFuelCapacity();
                    if (sm.FuelLevel > sm.FuelCapacity)
                    {
                        sm.FuelLevel = sm.FuelCapacity;
                    }
                }

                return(sm);
            }
            return(this);
        }
示例#5
0
        public ShipInformation SetFuelLevel(double fuellevel)
        {
            if (fuellevel != 0 && fuellevel != FuelLevel)
            {
                ShipInformation sm = this.ShallowClone();

                if (fuellevel != 0)
                {
                    sm.FuelLevel = fuellevel;
                }
                if (fuellevel > sm.FuelCapacity)
                {
                    sm.FuelCapacity = fuellevel;
                }

                return(sm);
            }

            return(this);
        }
示例#6
0
        public ShipInformation Set(string ship, string shipfd, string name = null, string ident = null, double fuellevel = 0, double fueltotal = 0)
        {
            if (ship != ShipType || (name != null && name != ShipUserName) ||
                (ident != null && ident != ShipUserIdent) ||
                (fuellevel != 0 && fuellevel != FuelLevel) ||
                (fueltotal != 0 && fueltotal != FuelCapacity))
            {
                ShipInformation sm = this.ShallowClone();

                sm.ShipType = ship;
                sm.ShipFD   = shipfd;
                if (name != null)
                {
                    sm.ShipUserName = name;
                }
                if (ident != null)
                {
                    sm.ShipUserIdent = ident;
                }
                if (fuellevel != 0)
                {
                    sm.FuelLevel = fuellevel;
                }
                if (fueltotal == 0 && fuellevel > sm.FuelCapacity)
                {
                    sm.FuelCapacity = fuellevel;
                }
                if (fueltotal != 0)
                {
                    sm.FuelCapacity = fueltotal;
                }

                return(sm);
            }

            return(this);
        }
示例#7
0
        public void ModuleBuy(JournalModuleBuy e)
        {
            ShipInformation sm = EnsureShip(e.ShipId);              // this either gets current ship or makes a new one.

            if (e.StoredItem.Length > 0)                            // if we stored something
            {
                StoredModules = StoredModules.StoreModule(e.StoredItem, e.StoredItemLocalised);
            }

            // if we sold it, who cares?
            Ships[e.ShipId] = sm.AddModule(e.Slot, e.SlotFD, e.BuyItem, e.BuyItemFD, e.BuyItemLocalised); // replace the slot with this

            itemlocalisation[e.BuyItem] = e.BuyItemLocalised;                                             // record any localisations
            if (e.SellItem.Length > 0)
            {
                itemlocalisation[e.SellItem] = e.SellItemLocalised;
            }
            if (e.StoredItem.Length > 0)
            {
                itemlocalisation[e.StoredItem] = e.StoredItemLocalised;
            }

            currentid = e.ShipId;           // must be in it to do this
        }