Exemplo n.º 1
0
        public string CommanderUpdateShip(int shipId, string type, EliteDangerousCore.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);
        }
Exemplo n.º 2
0
        public void ModuleRetrieve(JournalModuleRetrieve e)
        {
            string sid = Key(e.ShipFD, e.ShipId);

            ShipInformation sm = EnsureShip(sid);       // this either gets current ship or makes a new one.

            sm = sm.SetShipDetails(e.Ship, e.ShipFD);   // shallow copy if changed
            if (e.SwapOutItem.Length > 0)
            {
                StoredModules = StoredModules.StoreModule(e.SwapOutItem, e.SwapOutItemLocalised);
            }

            Ships[sid] = sm.AddModule(e.Slot, e.SlotFD, e.RetrievedItem, e.RetrievedItemFD, e.RetrievedItemLocalised);

            StoredModules = StoredModules.RemoveModule(e.RetrievedItem);
            VerifyList();
        }
Exemplo n.º 3
0
        public bool Equals(ShipInformation si)
        {
            if (si == null)
            {
                return(false);
            }

            return(si.Sold == this.Sold &&
                   si.ShipType == this.ShipType &&
                   si.ShipFD == this.ShipFD &&
                   si.ShipUserName == this.ShipUserName &&
                   si.ShipUserIdent == this.ShipUserIdent &&
                   si.FuelLevel == this.FuelLevel &&
                   si.FuelCapacity == this.FuelCapacity &&
                   si.SubVehicle == this.SubVehicle &&
                   si.Modules.SequenceEqual(this.Modules));
        }
Exemplo n.º 4
0
        public void StoredShips(StoredShipInformation[] ships)
        {
            foreach (var i in ships)
            {
                string sid = Key(i.ShipTypeFD, i.ShipID);
                //System.Diagnostics.Debug.WriteLine(sid + " Stored info " + i.StarSystem + ":" + i.StationName + " transit" + i.InTransit);

                ShipInformation sm = EnsureShip(sid);                                 // this either gets current ship or makes a new one.
                sm = sm.SetShipDetails(i.ShipType, i.ShipTypeFD, i.Name, hot: i.Hot); // set up minimum stuff we know about it

                if (!i.InTransit)                                                     // if in transit, we don't know where it is, ignore
                {
                    sm = sm.Store(i.StationName, i.StarSystem);                       // ship is not with us, its stored, so store it.
                }
                Ships[sid] = sm;
            }
            VerifyList();
        }
Exemplo n.º 5
0
        public ShipInformation ShallowClone()          // shallow clone.. does not clone the ship modules, just the dictionary
        {
            ShipInformation sm = new ShipInformation(this.ID);

            sm.Sold          = this.Sold;
            sm.ShipType      = this.ShipType;
            sm.ShipFD        = this.ShipFD;
            sm.ShipUserName  = this.ShipUserName;
            sm.ShipUserIdent = this.ShipUserIdent;
            sm.FuelLevel     = this.FuelLevel;
            sm.FuelCapacity  = this.FuelCapacity;
            sm.SubVehicle    = this.SubVehicle;
            sm.HullValue     = this.HullValue;
            sm.ModulesValue  = this.ModulesValue;
            sm.Rebuy         = this.Rebuy;
            sm.Modules       = new Dictionary <string, JournalLoadout.ShipModule>(this.Modules);
            return(sm);
        }
Exemplo n.º 6
0
        public void ModuleStore(JournalModuleStore e)
        {
            string sid = Key(e.ShipFD, e.ShipId);

            ShipInformation sm = EnsureShip(sid);            // this either gets current ship or makes a new one.

            if (e.ReplacementItem.Length > 0)
            {
                Ships[sid] = sm.AddModule(e.Slot, e.SlotFD, e.ReplacementItem, e.ReplacementItemFD, e.ReplacementItemLocalised);
            }
            else
            {
                Ships[sid] = sm.RemoveModule(e.Slot, e.StoredItem);
            }

            StoredModules = StoredModules.StoreModule(e.StoredItem, e.StoredItemLocalised);
            currentid     = sid;       // must be in it to do this
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        public ShipInformation AddModule(string slot, string slotfd, string item, string itemfd, string itemlocalised)
        {
            if (!Modules.ContainsKey(slot) || Modules[slot].Item.Equals(item) == false)       // if does not have it, or item is not the same..
            {
                ShipInformation sm = this.ShallowClone();
                sm.Modules[slot] = new ShipModule(slot, slotfd, item, itemfd, itemlocalised);
                //System.Diagnostics.Debug.WriteLine("Slot add " + 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);
        }
Exemplo n.º 11
0
        public ShipInformation ShallowClone()          // shallow clone.. does not clone the ship modules, just the dictionary
        {
            ShipInformation sm = new ShipInformation(this.ID);

            sm.Sold                   = this.Sold;
            sm.ShipType               = this.ShipType;
            sm.ShipFD                 = this.ShipFD;
            sm.ShipUserName           = this.ShipUserName;
            sm.ShipUserIdent          = this.ShipUserIdent;
            sm.FuelLevel              = this.FuelLevel;
            sm.FuelCapacity           = this.FuelCapacity;
            sm.SubVehicle             = this.SubVehicle;
            sm.HullValue              = this.HullValue;
            sm.ModulesValue           = this.ModulesValue;
            sm.Rebuy                  = this.Rebuy;
            sm.StoredAtStation        = this.StoredAtStation;
            sm.StoredAtSystem         = this.StoredAtSystem;
            sm.TransferArrivalTimeUTC = this.TransferArrivalTimeUTC;
            sm.Hot     = this.Hot;
            sm.Modules = new Dictionary <string, ShipModule>(this.Modules);
            return(sm);
        }
Exemplo n.º 12
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;
                }

                //System.Diagnostics.Debug.WriteLine(ship + " " + sm.FuelCapacity + " " + sm.FuelLevel);
                return(sm);
            }

            return(this);
        }
        public ShipInformation SetFuelLevel(double fuellevel, double reserve)
        {
            if (fuellevel != 0 && (Math.Abs(FuelLevel - fuellevel) > 0.01 || Math.Abs(ReserveFuelCapacity - reserve) > 0.01))
            {
                //System.Diagnostics.Debug.WriteLine("Update ship fuel to " + fuellevel + " " + reserve);

                ShipInformation sm = this.ShallowClone();

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

                return(sm);
            }

            return(this);
        }
Exemplo n.º 14
0
        private ShipInformation EnsureShip(string 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[Key(sm.ShipFD, newsoldid++)] = sm;                      // okay, we place this information on 30000+  all Ids of this will now refer to new entry
                }
            }

            int i;

            id.Substring(id.IndexOf(":") + 1).InvariantParse(out i);
            ShipInformation smn = new ShipInformation(i);

            Ships[id] = smn;
            return(smn);
        }
Exemplo n.º 15
0
        private ShipInformation EnsureShip(string id)      // ensure we have an ID of this type..
        {
            if (Ships.ContainsKey(id))
            {
                ShipInformation sm = Ships[id];
                if (sm.State == ShipInformation.ShipState.Owned)               // if owned, ok
                {
                    return(sm);
                }
                else
                {
                    Ships[Key(sm.ShipFD, newsoldid++)] = sm;              // okay, we place this information on back ID list+  all Ids of this will now refer to new entry
                }
            }

            //System.Diagnostics.Debug.WriteLine("Made new ship " + id);

            ulong           i   = id.Substring(id.IndexOf(":") + 1).InvariantParseULong(0);
            ShipInformation smn = new ShipInformation(i);

            Ships[id] = smn;
            return(smn);
        }
Exemplo n.º 16
0
 public void UpdateShipInformation(ShipInformation si)       // something externally updated SI
 {
     ShipInformation = si;
 }
        public ShipInformation SetShipDetails(string ship, string shipfd, string name = null, string ident = null,
                                              double fuellevel   = 0, double fueltotal      = 0,
                                              long hullvalue     = 0, long modulesvalue     = 0, long rebuy = 0,
                                              double unladenmass = 0, double reservefuelcap = 0, double hullhealth = 0, bool?hot = null)
        {
            if (ShipFD != shipfd || ship != ShipType || (name != null && name != ShipUserName) ||
                (ident != null && ident != ShipUserIdent) ||
                (fuellevel != 0 && fuellevel != FuelLevel) ||
                (fueltotal != 0 && fueltotal != FuelCapacity) ||
                (hullvalue != 0 && hullvalue != HullValue) ||
                (modulesvalue != 0 && modulesvalue != ModulesValue) ||
                (rebuy != 0 && rebuy != Rebuy) ||
                (unladenmass != 0 && unladenmass != UnladenMass) ||
                (reservefuelcap != 0 && reservefuelcap != ReserveFuelCapacity) ||
                (hullhealth != 0 && HullHealthAtLoadout != hullhealth) ||
                (hot != null && hot.Value != Hot)
                )
            {
                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;
                }
                if (hullvalue != 0)
                {
                    sm.HullValue = hullvalue;
                }
                if (modulesvalue != 0)
                {
                    sm.ModulesValue = modulesvalue;
                }
                if (rebuy != 0)
                {
                    sm.Rebuy = rebuy;
                }
                if (unladenmass != 0)
                {
                    sm.UnladenMass = unladenmass;
                }
                if (reservefuelcap != 0)
                {
                    sm.ReserveFuelCapacity = reservefuelcap;
                }
                if (hullhealth != 0)
                {
                    sm.HullHealthAtLoadout = hullhealth;
                }

                if (hot != null)
                {
                    sm.Hot = hot.Value;
                }

                //System.Diagnostics.Debug.WriteLine(ship + " " + sm.FuelCapacity + " " + sm.FuelLevel + " " + sm.ReserveFuelCapacity);

                return(sm);
            }

            return(this);
        }