Esempio n. 1
0
        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);
                }
            }
        }
Esempio n. 2
0
        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);
            }
        }