public static void TrySetRoomEnergyConsumption(SpecialRoom room, int energy, Ship ship) { if (room.Stat.CurrentEnergyLimit >= energy && energy >= 0 && ship.Alignment == Alignment.Player && ship.Stats.CurrentEnergy >= energy - room.Stat.CurrentEnergy && room.Type != RoomType.Generator) { ship.Stats.CurrentEnergy -= energy - room.Stat.CurrentEnergy; room.Stat.CurrentEnergy = energy; } }
public static void UpgradeRoom(SpecialRoom room, GameModel gameModel) { if (room.Stat.CurrentEnergyLimit < room.Stat.MaxEnergyLimit) { int price; if (room.Type == RoomType.Generator) { price = (room.Stat.CurrentEnergyLimit + 1) * 15; } else { price = (room.Stat.CurrentEnergyLimit + 1) * 30; } if (price <= gameModel.Money) { room.Stat.CurrentEnergyLimit++; gameModel.Money -= price; } } }
public EnergyBar(SpecialRoom room, Ship ship) { InitializeComponent(); this.ship = ship; if (!allBars.ContainsKey(room)) { allBars[room] = new List <EnergyBar>(); } allBars[room].Add(this); Max = room.Stat.MaxEnergyLimit; Unlocked = room.Stat.CurrentEnergyLimit; Active = room.Stat.CurrentEnergy; if (room.Type == RoomType.Generator) { Active = ship.Stats.FullEnergy - ship.Stats.CurrentEnergy; } this.room = room; var t = new TableLayoutPanel(); table = t; //this.BackColor = Color.Transparent; t.ColumnCount = Max; for (int i = 0; i < Max; i++) { t.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, (float)(1.0 / Max + 0.1))); } t.RowCount = 1; t.RowStyles.Add(new RowStyle(SizeType.Percent, 100)); t.Dock = DockStyle.Fill; //this.Padding = new Padding(0, 0, 0, 0); //t.BackColor = Color.Transparent; //t.BackColor = Color.Black; for (int i = 0; i < Max; i++) { var cell = new EnergyCell(); var j = i + 1; cell.Click += (s, e) => { if (cells[j - 1].state == 2 && ((j < Max && cells[j].state != 2) || (j == Max))) { PlayerCommands.TrySetRoomEnergyConsumption(room, j - 1, ship); } else { PlayerCommands.TrySetRoomEnergyConsumption(room, j, ship); } foreach (var bar in ship.SpecialRooms.SelectMany(r => allBars[r])) { bar.Invalidate(); } }; cell.Dock = DockStyle.Fill; cell.Margin = new Padding(0, 0, 0, 0); cell.Padding = new Padding(0, 0, 0, 0); cells.Add(cell); t.Controls.Add(cell, i, 0); } t.Margin = new Padding(0, 0, 0, 0); t.Padding = new Padding(0, 0, 0, 0); this.Padding = new Padding(0, 0, 0, 0); this.Margin = new Padding(0, 0, 0, 0); Controls.Add(t); }