Ejemplo n.º 1
0
 public void UpdateMicroResource(MaterialCommoditiesMicroResourceList mc, JournalEntry previous)
 {
     if (previous?.EventTypeID != JournalTypeEnum.ShipLocker)      // if we have a shiplocker before, its been taken off, so don't change.
     {
         MaterialCommodityMicroResourceType.EnsurePresent(Resource.Category, Resource.Name, Resource.Name_Localised);
         mc.Change(EventTimeUTC, Resource.Category, Resource.Name, Resource.Count, Price, MicroResource.ShipLocker);
     }
 }
Ejemplo n.º 2
0
 public void UpdateMicroResource(MaterialCommoditiesMicroResourceList mc, JournalEntry previous)        // Odyssey from 11/6/21 this comes after shiplocker, so don't change
 {
     if (previous?.EventTypeID != JournalTypeEnum.ShipLocker)
     {
         foreach (var m in Items.EmptyIfNull())
         {
             MaterialCommodityMicroResourceType.EnsurePresent(m.Category, m.Name, m.Name_Localised);
             mc.Change(EventTimeUTC, m.Category, m.Name, -m.Count, 0, MicroResource.ShipLocker);
         }
     }
 }
 public void UpdateMicroResource(MaterialCommoditiesMicroResourceList mc)
 {
     if (Items != null )
     {
         foreach (var m in Items)
         {
             MaterialCommodityMicroResourceType.EnsurePresent(m.Category, m.Name, m.Name_Localised);
             mc.Change(EventTimeUTC, m.Category, m.Name, -m.Count, 0, MicroResource.ShipLocker);
         }
     }
 }
        public void UpdateMicroResource(MaterialCommoditiesMicroResourceList mc)
        {
            foreach (var m in Offered.EmptyIfNull())
            {
                MaterialCommodityMicroResourceType.EnsurePresent(m.Category, m.Name, m.Name_Localised);
                mc.Change(EventTimeUTC, m.Category, m.Name, -m.Count, 0, MicroResource.ShipLocker);
            }

            if ( Received.HasChars())
            {
                MaterialCommodityMicroResourceType.EnsurePresent(Category, Received, Received_Localised);
                mc.Change(EventTimeUTC, Category, Received, Count, 0, MicroResource.ShipLocker);
            }
        }
Ejemplo n.º 5
0
        // counts/set array can be of length 1 to maximum number of counts
        // to set a value, set count/set=1 for that entry
        // to change a value, set count/set = 0 for that entry
        // to leave a value, set count=0,set=0 for that entry
        // set means set to value, else add to value
        public bool Change(DateTime utc, MaterialCommodityMicroResourceType.CatType cat, string fdname, int[] counts, bool[] set, long price)
        {
            fdname = fdname.ToLowerInvariant();

            MaterialCommodityMicroResource mc = items.GetLast(fdname);                                                   // find last entry, may return null if none stored

            if (mc == null)                                                                                              // not stored, make new
            {
                MaterialCommodityMicroResourceType mcdb = MaterialCommodityMicroResourceType.EnsurePresent(cat, fdname); // get a MCDB of this
                mc = new MaterialCommodityMicroResource(mcdb);
            }
            else
            {
                mc = new MaterialCommodityMicroResource(mc);                // copy constructor, new copy of it
            }

            double costprev  = mc.Counts[0] * mc.Price;
            double costofnew = counts[0] * price;
            bool   changed   = false;

            for (int i = 0; i < counts.Length; i++)
            {
                int newcount = set[i] ? counts[i] : Math.Max(mc.Counts[i] + counts[i], 0);       // don't let it go below zero if changing
                if (newcount != mc.Counts[i])
                {
                    changed = true;
                    //  System.Diagnostics.Debug.WriteLine("MCMRLIST {0} Gen {1} Changed {2}:{3} Entry {4} {5} -> {6} {7}", utc.ToString(), items.Generation, mc.Details.Category, mc.Details.FDName, i, mc.Counts[i], newcount, mc.Counts[i]<newcount ? "+++" : "---");
                    //   System.Diagnostics.Debug.WriteLine(Environment.StackTrace);
                    mc.Counts[i] = newcount;
                }
            }

            if (changed)                                                    // only store back a new entry if material change to counts
            {
                if (mc.Counts[0] > 0 && counts[0] > 0)                      // if bought (defensive with mc.counts)
                {
                    mc.Price = (costprev + costofnew) / mc.Counts[0];       // price is now a combination of the current cost and the new cost. in case we buy in tranches
                }
                items[fdname] = mc;                                         // and set fdname to mc - this allows for any repeat adds due to frontier data repeating stuff in things like cargo
            }
            else
            {
                // System.Diagnostics.Debug.WriteLine("{0} Not changed {1} {2}", utc.ToString(), mc.Details.FDName, mc.Count);
            }

            return(changed);
        }
Ejemplo n.º 6
0
        public void UpdateMicroResource(MaterialCommoditiesMicroResourceList mc, JournalEntry previous)
        {
            if (previous?.EventTypeID != JournalTypeEnum.ShipLocker)    // if shiplocker is before, its already updated
            {
                System.Diagnostics.Debug.WriteLine("Trade - remove offered");
                foreach (var m in Offered.EmptyIfNull())
                {
                    MaterialCommodityMicroResourceType.EnsurePresent(m.Category, m.Name, m.Name_Localised);
                    mc.Change(EventTimeUTC, m.Category, m.Name, -m.Count, 0, MicroResource.ShipLocker);
                }

                System.Diagnostics.Debug.WriteLine("Trade - add received");
                if (Received.HasChars())
                {
                    MaterialCommodityMicroResourceType.EnsurePresent(Category, Received, Received_Localised);
                    mc.Change(EventTimeUTC, Category, Received, Count, 0, MicroResource.ShipLocker);
                }
            }
        }
Ejemplo n.º 7
0
        // counts/set array can be of length 1 to maximum number of counts
        // to set a value, set count/set=1 for that entry
        // to change a value, set count/set = 0 for that entry
        // to leave a value, set count=0,set=0 for that entry
        // set means set to value, else add to value
        public void Change(DateTime utc, MaterialCommodityMicroResourceType.CatType cat, string fdname, int[] counts, bool[] set, long price)
        {
            fdname = fdname.ToLowerInvariant();

            MaterialCommodityMicroResource mc = items.GetLast(fdname);                                                   // find last entry, may return null if none stored

            if (mc == null)                                                                                              // not stored, make new
            {
                MaterialCommodityMicroResourceType mcdb = MaterialCommodityMicroResourceType.EnsurePresent(cat, fdname); // get a MCDB of this
                mc = new MaterialCommodityMicroResource(mcdb);
            }
            else
            {
                mc = new MaterialCommodityMicroResource(mc);                // copy constructor, new copy of it
            }

            double costprev  = mc.Counts[0] * mc.Price;
            double costofnew = counts[0] * price;
            bool   changed   = false;

            for (int i = 0; i < counts.Length; i++)
            {
                int newcount = set[i] ? counts[i] : Math.Max(mc.Counts[i] + counts[i], 0); // don't let it go below zero if changing
                changed     |= newcount != mc.Counts[i];                                   // have we changed? we are trying to minimise deltas to the gen dictionary, so don't add if nothing changed
                mc.Counts[i] = newcount;
            }

            if (changed)                                              // only store back a new entry if material change to counts
            {
                if (mc.Counts[0] > 0 && counts[0] > 0)                // if bought (defensive with mc.counts)
                {
                    mc.Price = (costprev + costofnew) / mc.Counts[0]; // price is now a combination of the current cost and the new cost. in case we buy in tranches
                }
                items.Add(fdname, mc);                                // and add a new fresh mc to the dictionary
                // System.Diagnostics.Debug.WriteLine("{0} Changed {1} {2} {3}", utc, items.Generation, mc.Details.FDName, mc.Count);
            }
            else
            {
                // System.Diagnostics.Debug.WriteLine("{0} Not changed {1} {2}", utc, mc.Details.FDName, mc.Count);
            }
        }
 public void UpdateMicroResource(MaterialCommoditiesMicroResourceList mc)
 {
     MaterialCommodityMicroResourceType.EnsurePresent(Resource.Category, Resource.Name, Resource.Name_Localised);
     mc.Change(EventTimeUTC, Resource.Category, Resource.Name, Resource.Count, Price, MicroResource.ShipLocker);
 }