public override void Shoot() { Missile missile = missilePool.Retrieve(); missile.Initialize(missileInitialBurnTarget.position - missileSpawnPoint.transform.position, missileSpawnPoint.position, this, enemiesInRange[0]); PowerGrid.ConsumePower(PowerDraw); }
public override double ServerUpdateIntervalSeconds => double.MaxValue; // never public static void ServerOnBaseMerged(ILogicObject areasGroupFrom, ILogicObject areasGroupTo) { var fromState = GetPrivateState(areasGroupFrom); var toState = GetPrivateState(areasGroupTo); PowerGrid.ServerOnPowerGridMerged(fromState.PowerGrid, toState.PowerGrid); var fromContainer = fromState.ItemsContainer; if (fromContainer.OccupiedSlotsCount != 0) { var toContainer = toState.ItemsContainer; Server.Items.TryMoveAllItems(fromContainer, toContainer, onlyToExistingStacks: true); var slotsNeeded = fromContainer.OccupiedSlotsCount; if (slotsNeeded > 0) { Server.Items.SetSlotsCount(toContainer, Math.Max(ItemsContainerLandClaimSafeStorage.ServerSafeItemsSlotsCapacity, (byte)(toContainer.OccupiedSlotsCount + slotsNeeded))); Server.Items.TryMoveAllItems(fromContainer, toContainer, onlyToExistingStacks: false); } Logger.Important($"Bases merged: moved all safe storage items from {fromContainer} to {toContainer}"); } }
private void Awake() { Inventory.Initialize(resourceTypes, initialResourceAmounts); PowerGrid.Initialize(initialPowerCapacity); stateMachine = new StateMachine(this, states); enemyPool = new ObjectPool <Enemy>(enemyPrefab); }
private void RefreshSafeStorageAndPowerGrid() { var objectPublicState = this.landClaimWorldObject.GetPublicState <ObjectLandClaimPublicState>(); var area = objectPublicState.LandClaimAreaObject; var areasGroup = LandClaimArea.GetPublicState(area).LandClaimAreasGroup; var areasGroupPrivateState = LandClaimAreasGroup.GetPrivateState(areasGroup); // setup power grid var powerGrid = areasGroupPrivateState.PowerGrid; var oldViewModelPowerGridState = this.ViewModelPowerGridState; this.ViewModelPowerGridState = new ViewModelPowerGridState(PowerGrid.GetPublicState(powerGrid)); oldViewModelPowerGridState?.Dispose(); // setup safe storage this.DisposeViewModelItemsContainerExchange(); this.ViewModelItemsContainerExchange = new ViewModelItemsContainerExchange( areasGroupPrivateState.ItemsContainer, callbackTakeAllItemsSuccess: () => { }, enableShortcuts: this.IsSafeStorageAvailable) { IsContainerTitleVisible = false, }; this.ViewModelItemsContainerExchange.Container.SlotsCountChanged += this.SafeStorageSlotsChangedHandler; this.ViewModelItemsContainerExchange.Container.ItemsReset += this.SafeStorageSlotsChangedHandler; }
public string SolveFirstPart() { var powerGrid = new PowerGrid(serialNumber); var cellGrid = powerGrid.FindHighestLevelCellGrid(3); return($"{cellGrid.X},{cellGrid.Y}"); }
public override void Shoot() { Bullet bullet = bulletPool.Retrieve(); bullet.Initialize(muzzle.position, this, enemiesInRange[0]); PowerGrid.ConsumePower(PowerDraw); }
private static void ServerBaseBrokenHandler(ILogicObject areasGroup, List <ILogicObject> newAreaGroups) { var fromPowerGrid = GetPrivateState(areasGroup).PowerGrid; var toPowerGrids = newAreaGroups.Select(g => GetPrivateState(g).PowerGrid).ToList(); PowerGrid.ServerOnPowerGridBroken(fromPowerGrid, toPowerGrids); }
public string Execute( double chargePercent = 100, [CurrentCharacterIfNull] ICharacter character = null) { var chargeFraction = MathHelper.Clamp(chargePercent / 100, min: 0, max: 1); using var tempLandClaims = Api.Shared.GetTempList <ILogicObject>(); LandClaimSystem.SharedGetAreasInBounds( new RectangleInt(character.TilePosition, (1, 1)), tempLandClaims, addGracePadding: false); var landClaim = tempLandClaims.AsList().FirstOrDefault(); if (landClaim is null) { return("No power grid exist near " + character.Name); } var landClaimAreasGroup = LandClaimSystem.SharedGetLandClaimAreasGroup(landClaim); var powerGrid = LandClaimAreasGroup.GetPrivateState(landClaimAreasGroup).PowerGrid; var powerGridState = PowerGrid.GetPublicState(powerGrid); powerGridState.ElectricityAmount = powerGridState.ElectricityCapacity * chargeFraction; return($"Charge amount of the power grid modified to {chargeFraction * 100}%"); }
public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, ILogger logger) { logger.LogInformation("PowerGridFunction processing request"); try { string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject(requestBody); var input = data.ToObject <Input>(); var message = new PowerGrid(input.GridConfig) .BestLinkStationForPositionMessage(new Position(input.Position[0], input.Position[1])); var result = new JObject { { "message", message } }; return(new OkObjectResult(result)); } catch (Exception exception) { var error = new JObject { { "message", "An error occurred: " + exception.Message } }; return(new BadRequestObjectResult(error)); } }
public async Task Part2() { var grid = new PowerGrid(300, 300, Input); var best = await grid.EvaluateBestDynamicLocation(); Assert.Equal((236, 268, 11), best); }
public void Part1() { var grid = new PowerGrid(300, 300, Input); var best = grid.EvaluateBestLocation(); Assert.Equal((21, 54), best); }
public override void Run() { if (PowerGrid.PowerIsAvailable(Miner.GetPowerDraw() * Time.deltaTime)) { Miner.Mine(); } }
private CellGrid(CellGrid cellGrid) { X = cellGrid.X; Y = cellGrid.Y; Size = cellGrid.Size; PowerLevel = cellGrid.PowerLevel; powerGrid = cellGrid.powerGrid; }
public CellGrid(PowerGrid powerGrid, int x, int y, int size) { X = x; Y = y; Size = size; this.powerGrid = powerGrid; PowerLevel = SumCellPowerLevels(powerGrid.Cells, x, y, size); }
public string SolveSecondPart() { var powerGrid = new PowerGrid(serialNumber); var splitPowerGrid = new SplitPowerGrid(powerGrid); var cellGrid = splitPowerGrid.FindHighestLevelCellGrid(); return($"{cellGrid.X},{cellGrid.Y},{cellGrid.Size}"); }
public void Power_grid_constructor_should_create_any_empty_grid_for_an_empty_config() { var gridConfig = new List <List <double> >(); var powerGrid = new PowerGrid(gridConfig); Assert.AreEqual(0, powerGrid.NumberOfLinkStations()); }
public async Task PowerGridShouldEvaluateBestDynamicLocation( int width, int height, int serialNumber, int expectedX, int expectedY, int expectedDimension) { var grid = new PowerGrid(width, height, serialNumber); var best = await grid.EvaluateBestDynamicLocation(); Assert.Equal((expectedX, expectedY, expectedDimension), best); }
public override void Shoot() { if (spawnedLaser == null) { FireLaser(); } EventCoordinator.FireEvent(new DamageEvent(this, enemiesInRange[0], AttackDamage, Health.DamageType.Energy)); PowerGrid.ConsumePower(PowerDraw); }
public bool PlugIn(PowerRelated powerRelated, PowerGrid powerGrid) { if (powerRelated == null) { throw new ArgumentNullException("powerRelated"); } return(powerGrid != null && powerGrid.PlugIn(powerRelated)); }
public void Identify_most_suitable_link_station_for_position_should_return_empty_if_there_are_no_link_stations() { var gridConfiguration = new List <List <double> >(); var powerGrid = new PowerGrid(gridConfiguration); var linkStationWithPower = powerGrid.IdentifyMostSuitableLinkStationForPosition(new Position(0, 0)); Assert.AreEqual(default((LinkStation, double)), linkStationWithPower); }
public void Init() { powerGrid = new PowerGrid(); Type powerGridType = typeof(PowerGrid); FieldInfo field = powerGridType.GetField("powerGrid", BindingFlags.NonPublic | BindingFlags.Instance); Assert.IsNotNull(field); gridHashSet = field.GetValue(powerGrid) as HashSet <PowerRelated>; Assert.IsNotNull(gridHashSet); }
public void Identify_most_suitable_link_station_for_position_should_throw_argument_exception_if_no_position_is_supplied() { var gridConfiguration = new List <List <double> >(); gridConfiguration.Add(new List <double>() { 0, 0, 1 }); var powerGrid = new PowerGrid(gridConfiguration); powerGrid.IdentifyMostSuitableLinkStationForPosition(null); }
public SplitPowerGrid(PowerGrid powerGrid) { size = 1; cellGrids = new CellGrid[301, 301]; for (var i = 1; i <= 301 - size; ++i) { for (var j = 1; j <= 301 - size; ++j) { cellGrids[i, j] = powerGrid.GetCellGrid(i, j, size); } } }
public void Best_link_station_for_position_message_should_throw_argument_exception_if_no_position_is_supplied() { var gridConfiguration = new List <List <double> >(); gridConfiguration.Add(new List <double>() { 0, 0, 1 }); var powerGrid = new PowerGrid(gridConfiguration); powerGrid.BestLinkStationForPositionMessage(null); }
private void Refresh() { var oldViewModel = this.ViewModelPowerGridState; var powerGrid = this.privateState.PowerGrid; this.ViewModelPowerGridState = powerGrid is null ? null : new ViewModelPowerGridState(PowerGrid.GetPublicState(powerGrid)); oldViewModel?.Dispose(); }
public void Puzzle1_FindHighestPower3x3() { var grid = new PowerGrid(Input.Day11); var(x, y, _) = grid.FindHighestPower3x3(); (x, y).Should().Be((235, 38)); // var sums = grid.GetSumTable(); // File.WriteAllText(@"C:\projects\adventofcode\2018\sumtable.txt", sums); // var sums = grid.GetPowers(); // File.WriteAllText(@"C:\projects\adventofcode\2018\power.txt", sums); }
public void Mine() { if (resourcesInRange.Count > 0) { for (int i = 0; i < resourcesInRange.Count; i++) { Resource.ResourceType resourceType = resourcesInRange[i].GetResourceType(); float amountOfResourceMined = miningEfficiency[resourceType] * Time.deltaTime; Inventory.AddResourceToInventory(resourceType, amountOfResourceMined); } PowerGrid.ConsumePower(powerDraw * Time.deltaTime); } }
public override void Run() { counter += Time.deltaTime; if (counter >= rateOfFire && Turret.HasEnemyInRange() && PowerGrid.PowerIsAvailable(Turret.PowerDraw)) { counter = 0; Turret.Shoot(); roundsInCurrentClip--; if (roundsInCurrentClip <= 0) { stateMachine.TransitionTo <TurretReloadState>(); } } }
public void Unplug(PowerRelated powerRelated, PowerGrid powerGrid) { if (powerRelated == null) { throw new ArgumentNullException("powerRelated"); } if (powerGrid == null) { throw new ArgumentNullException("powerGrid"); } powerGrid.Unplug(powerRelated); }
public bool IsPluggedIn(PowerRelated powerRelated, out PowerGrid powerGrid) { if (powerRelated == null) { throw new ArgumentNullException("powerRelated"); } if (IsEmpty) { powerGrid = null; return(false); } powerGrid = powerGrids.FirstOrDefault(grid => grid.IsPluggedIn(powerRelated)); return(powerGrid != null); }