Ejemplo n.º 1
0
 public void NewGame()
 {
     disposed        = false;
     PlayerInventory = new Inventory();
     HatchInv        = new HatchInventory();
     PlayerInventory.AddItem(new IngotItem(KnownMetal.Iron, 1));
     HatchInv.AddItem(new CastItem(CastItem.GreatsowordCast));
     HatchInv.AddItem(new CastItem(CastItem.BroadswordCast));
     HatchInv.AddItem(new CastItem(CastItem.IngotCast));
     HatchInv.AddItem(new IngotItem(KnownMetal.Gold, 0.8f));
     HatchInv.AddItem(new IngotItem(KnownMetal.Iron, 0.7f));
     HatchInv.AddItem(new IngotItem(KnownMetal.Gold, 0.9f));
     HatchInv.AddItem(new IngotItem(KnownMetal.Copper, 1f));
     HatchInv.AddItem(new IngotItem(KnownMetal.Copper, 0.8f));
     HatchInv.AddItem(new IngotItem(KnownMetal.Copper, 1f));
     HatchInv.AddItem(new IngotItem(KnownMetal.Copper, 0.65f));
     HatchInv.AddItem(new IngotItem(KnownMetal.Bronze, 0.8f));
     HatchInv.AddItem(new IngotItem(KnownMetal.HiTinBronze, 0.9f));
     HatchInv.AddItem(new IngotItem(KnownMetal.LowTinBronze, 0.7f));
     HatchInv.AddItem(new IngotItem(KnownMetal.Tin, 0.8f));
     HatchInv.AddItem(new IngotItem(KnownMetal.Tin, 0.9f));
     FoundryIngots     = new SolidList <IngotItem> (FoundryMeshInfo.IngotAmount);
     FoundryAlloy      = new Alloy();
     AirQuality        = 25;
     CoalPercent       = 80;
     FoundryTemprature = 25;
     CastMetal         = -1;
 }
Ejemplo n.º 2
0
        public void LoadGame(Stream reader)
        {
            disposed = false;
            Console.WriteLine("Loading game!");
            PlayerInventory = new Inventory();
            PlayerInventory.LoadFromFile(reader);                                                                       //PlayerInventory
            HatchInv = new HatchInventory();
            HatchInv.LoadFromFile(reader);                                                                              //HatchInv
            if (reader.ReadByte() != 0)                                                                                 //Check if CurrentCast is not null
            {
                CurrentCast = (CastItem)StreamIO.LoadItem(reader);                                                      //CurrentCast
            }
            CastMetal = reader.ReadByte();                                                                              //CastMetal
            var buffer = new byte[sizeof(float) * 4];

            reader.Read(buffer, 0, sizeof(float) * 4);                                                                          //CastMetaPurity, CastFilling, CastingTemperature, OldFoundryAmount
            CastMetalPurity   = BitConverter.ToSingle(buffer, 0);
            CastFilling       = BitConverter.ToSingle(buffer, sizeof(float));
            CastingTemprature = BitConverter.ToSingle(buffer, 2 * sizeof(float));
            OldFoundryAmount  = BitConverter.ToSingle(buffer, 3 * sizeof(float));
            FoundryIngots     = new SolidList <IngotItem> (FoundryMeshInfo.IngotAmount);
            for (int i = 0; i < FoundryIngots.Capacity; i++)
            {
                if (reader.ReadByte() != 0)                                                             //Check if the item is not null
                {
                    FoundryIngots [i] = (IngotItem)StreamIO.LoadItem(reader);                           //Read IngotItems
                }
            }
            FoundryAlloy = StreamIO.LoadAlloy(reader);                                                                  //FoundryAlloy
            reader.Read(buffer, 0, sizeof(float) * 3);                                                                  //Read3
            AirQuality        = BitConverter.ToSingle(buffer, 0);                                                       //AirQuality
            CoalPercent       = BitConverter.ToSingle(buffer, sizeof(float));                                           //CoalPercent
            FoundryTemprature = BitConverter.ToSingle(buffer, sizeof(float) * 2);                                       //FoundryTemperature
            Console.Out.WriteLine(reader.Position);
        }
Ejemplo n.º 3
0
 public Alloy(Alloy other)
 {
     metals              = new List <MetalMass>(other.metals);
     totalAmount         = other.totalAmount;
     impurity            = other.impurity;
     color               = other.color;
     highestMeltingPoint = other.highestMeltingPoint;
 }
Ejemplo n.º 4
0
        public override void Update(Scene s)
        {
            UpdateDialog();
            if (Input.PourKeyPressed & game.TooltipHelper.GetOwner() == this)
            {
                if (game.GameStats.CurrentCast != null & game.GameStats.FoundryAlloy != null && game.GameStats.FoundryAlloy.Amount >= game.GameStats.CurrentCast.GetVolume() - 0.005f &
                    game.GameStats.CastFilling <= 0 & game.GameStats.FoundryTemprature > game.GameStats.FoundryAlloy.GetMeltingPoint())
                {
                    Alloy input = game.GameStats.FoundryAlloy;

                    float      bestPurity = 0;
                    KnownMetal bestMetal  = null;

                    foreach (KnownMetal metal in KnownMetal.Metals)
                    {
                        if (metal == null)
                        {
                            continue;
                        }
                        float newPurity = metal.GetPurityFrom(input);
                        if (newPurity > metal.GetMinimumPurity() & newPurity > bestPurity)
                        {
                            bestPurity = newPurity;
                            bestMetal  = metal;
                        }
                    }

                    if (bestMetal != null)
                    {
                        game.GameStats.CastMetal       = bestMetal.Id;
                        game.GameStats.CastMetalPurity = bestPurity;

                        game.GameStats.CastFilling       = 0.01f;
                        game.GameStats.OldFoundryAmount  = game.GameStats.FoundryAlloy.Amount;
                        game.GameStats.CastingTemprature = game.GameStats.FoundryTemprature;
                    }
                    else
                    {
                        game.ErrortipHelper.ShowError(Localization.GetLocalization("ui.error.notanalloy"), 200, 500, 2, false);
                    }
                }
            }

            if (game.GameStats.CastFilling > 0 & game.GameStats.CastFilling < 1)
            {
                game.GameStats.CastFilling += Time.Delta();
                if (game.GameStats.CastFilling >= 1)
                {
                    game.GameStats.CastFilling = 1;
                }
                game.GameStats.FoundryAlloy.SetAmount(game.GameStats.OldFoundryAmount - game.GameStats.CurrentCast.GetVolume() * game.GameStats.CastFilling);
            }

            if (game.GameStats.CastingTemprature > 25)
            {
                game.GameStats.CastingTemprature -= Time.Delta() * 150;
            }
        }
Ejemplo n.º 5
0
        public Alloy Normalized()
        {
            var output = new Alloy();

            foreach (MetalMass mm in metals)
            {
                output.AddMetal(mm.Metal, Purity, mm.Amount / totalAmount);
            }
            return(output);
        }
Ejemplo n.º 6
0
 public static void SaveAlloy(Alloy alloy, Stream writer)
 {
     if (alloy.Amount <= 0)
     {
         writer.WriteByte((byte)0);
         return;
     }
     writer.WriteByte((byte)1);
     writer.Write(BitConverter.GetBytes(alloy.Purity), 0, sizeof(float)); //Purity
     writer.WriteByte((byte)alloy.MetalCount);                            //metalCount
     for (int i = 0; i < alloy.MetalCount; i++)
     {
         writer.WriteByte((byte)alloy.GetMetalID(i));                                    //metalID
         writer.Write(BitConverter.GetBytes(alloy.GetMetalAmount(i)), 0, sizeof(float)); //metalAmount
     }
 }
Ejemplo n.º 7
0
        public float GetPurityFrom(Alloy alloy)
        {
            float purity = 0;

            foreach (Part p in parts)
            {
                for (int i = 0; i < alloy.MetalCount; i++)
                {
                    foreach (Part ip in alloy[i].parts)
                    {
                        if (p.Metal == ip.Metal)
                        {
                            purity += Math.Min(alloy.GetMetalFraction(i) * ip.Amount, p.Amount) * alloy.Purity;
                        }
                    }
                }
            }

            return(purity);
        }
Ejemplo n.º 8
0
        public static Alloy LoadAlloy(Stream reader)
        {
            var output = new Alloy();

            if (reader.ReadByte() == 0)          //The alloy is empty
            {
                return(output);
            }

            var buffer = new byte[sizeof(float)];

            reader.Read(buffer, 0, buffer.Length);
            float Purity     = BitConverter.ToSingle(buffer, 0);
            int   metalCount = reader.ReadByte();

            for (int i = 0; i < metalCount; i++)
            {
                int id = reader.ReadByte();
                reader.Read(buffer, 0, buffer.Length);
                float amount = BitConverter.ToSingle(buffer, 0);
                output.AddMetal(id, Purity, amount);
            }
            return(output);
        }