public override void HandleResource(InputState input, ResourceBuilding resourceBuilding) { Control control = Controls.Selection; if ((control != null && control.Name.Contains("Unload")) || ((input.IsNewKeyPress(Keys.F, null)) || (input.IsNewKeyPress(Keys.C, null)))) { _parachuteBox.HandleInput(Position); IsWithinTargetRange = false; if (_parachuteBox.Bounds.Intersects(resourceBuilding.Bounds)) { /*Color[] buildingTextureData = new Color[resourceBuilding.Texture.Width * resourceBuilding.Texture.Height]; resourceBuilding.Texture.GetData(buildingTextureData); if (IntersectPixels(_parachuteBox.Bounds, _parachuteBox.TextureData, resourceBuilding.Bounds, buildingTextureData)) */{ IsWithinTargetRange = true; } } } base.HandleResource(input, resourceBuilding); }
public virtual void LoadResource(string resourceType, ResourceBuilding resourceBuilding) { PropertyInfo resourceProperty = resourceBuilding.GetType().GetProperty(resourceType); PropertyInfo resourceCargoProperty = GetType().GetProperty(resourceType + "Cargo"); int resourceValue = (int) (resourceProperty.GetValue(resourceBuilding, null)); int resourceCargoValue = (int)(resourceCargoProperty.GetValue(this, null)); if (FoodCargo + MedicineCargo < Capacity && resourceValue >= AmountPerCargo) { resourceCargoProperty.SetValue(this, Convert.ChangeType(resourceCargoValue + 1, resourceCargoProperty.PropertyType), null); resourceProperty.SetValue(resourceBuilding, Convert.ChangeType(resourceValue - AmountPerCargo, resourceProperty.PropertyType), null); } }
public virtual void UnloadResource(string resourceType, ResourceBuilding resourceBuilding) { PropertyInfo resourceProperty = resourceBuilding.GetType().GetProperty(resourceType); PropertyInfo resourceCargoProperty = GetType().GetProperty(resourceType + "Cargo"); int resourceValue = (int)(resourceProperty.GetValue(resourceBuilding, null)); int resourceCargoValue = (int)(resourceCargoProperty.GetValue(this, null)); if (resourceCargoValue > 0 && resourceBuilding.IsAlive) { if (IsWithinTargetRange) { resourceCargoProperty.SetValue(this, Convert.ChangeType(resourceCargoValue - 1, resourceCargoProperty.PropertyType), null); resourceProperty.SetValue(resourceBuilding, Convert.ChangeType(resourceValue + AmountPerCargo, resourceProperty.PropertyType), null); } } }
public virtual void HandleResource(InputState input, ResourceBuilding resourceBuilding) { Control control = Controls.Selection; if ((control != null && control.Name == "LoadFood") || (input.CurrentKeyboardStates[1].IsKeyDown(Keys.LeftControl) && input.IsNewKeyPress(Keys.F, null))) { LoadResource("Food", resourceBuilding); _sfxLoading.Play(); } else if ((control != null && control.Name == "LoadMedicine") || (input.CurrentKeyboardStates[1].IsKeyDown(Keys.LeftControl) && input.IsNewKeyPress(Keys.C, null))) { LoadResource("Medicine", resourceBuilding); _sfxLoading.Play(); } else if ((control != null && control.Name == "UnloadFood") || (input.IsNewKeyPress(Keys.F, null))) { UnloadResource("Food", resourceBuilding); _sfxUnloading.Play(); } else if ((control != null && control.Name == "UnloadMedicine") || (input.IsNewKeyPress(Keys.C, null))) { UnloadResource("Medicine", resourceBuilding); _sfxUnloading.Play(); } if (control != null) control.IsSelected = false; }