Exemple #1
0
    public string Day()
    {
        var energyProvidedForTheDay = Providers.Sum(p => p.EnergyOutput);

        this.TotalEnergyStored += energyProvidedForTheDay;
        double mineableForTheDay       = 0;
        double energyConsumedForTheDay = 0;

        switch (this.HarvesterMode)
        {
        case "Full":
            mineableForTheDay       = Harvesters.Sum(h => h.OreOutput);
            energyConsumedForTheDay = Harvesters.Sum(h => h.EnergyRequirement);
            break;

        case "Half":
            mineableForTheDay       = 0.5 * Harvesters.Sum(h => h.OreOutput);
            energyConsumedForTheDay = 0.6 * Harvesters.Sum(h => h.EnergyRequirement);
            break;
        }
        if (TotalEnergyStored >= energyConsumedForTheDay)
        {
            this.TotalMinedStored  += mineableForTheDay;
            this.TotalEnergyStored -= energyConsumedForTheDay;
        }
        else
        {
            mineableForTheDay = 0;
        }

        return
            ($"A day has passed.\r\nEnergy Provided: {energyProvidedForTheDay}\r\nPlumbus Ore Mined: {mineableForTheDay}");
    }
    public string RegisterHarvester(List <string> arguments)
    {
        var toReturn = string.Empty;

        try
        {
            if (arguments[0] == "Sonic")
            {
                Harvester harvester =
                    new SonicHarvester(arguments[1], double.Parse(arguments[2]), double.Parse(arguments[3]), int.Parse(arguments[4]));
                Harvesters.Add(harvester);
                toReturn = $"Successfully registered Sonic Harvester - {arguments[1]}";
            }
            else
            {
                Harvester harvester =
                    new HammerHarvester(arguments[1], double.Parse(arguments[2]), double.Parse(arguments[3]));
                Harvesters.Add(harvester);
                toReturn = $"Successfully registered Hammer Harvester - {arguments[1]}";
            }
        }
        catch (ArgumentException e)
        {
            toReturn = e.Message;
        }
        return(toReturn);
    }
Exemple #3
0
    public string Day()
    {
        double
            dayEnergyOutput,
            dayEnergyRequired,
            dayMinedOre,
            eventualDayMinedOre;



        //calculate day needs and capabilities
        dayEnergyOutput     = 0;
        dayMinedOre         = 0;
        eventualDayMinedOre = 0;
        dayEnergyRequired   = 0;

        dayEnergyOutput    = Providers.Sum(p => p.EnergyOutput);
        totalEnergyStored += dayEnergyOutput;


        if (workingMode != "Energy")
        {
            dayEnergyRequired = Harvesters.Sum(h => h.EnergyRequirement);

            if (workingMode == "Full")
            {
                eventualDayMinedOre = Harvesters.Sum(h => h.OreOutput);
            }
            else if (workingMode == "Half")
            {
                dayEnergyRequired   = dayEnergyRequired * 0.6; //consume 60 % of their energy requirements
                eventualDayMinedOre = Harvesters.Sum(h => h.OreOutput) * 0.5;

                //produce 50 % of their ore output
            }
        }
        else
        {
            dayEnergyRequired = 0;
            dayMinedOre       = 0;
        }

        if (totalEnergyStored >= dayEnergyRequired)
        {
            dayMinedOre        = eventualDayMinedOre;
            totalEnergyStored -= dayEnergyRequired;
            totalMinedOre     += dayMinedOre;
        }

        return(string.Format(Messages.DayHasPassed,
                             Environment.NewLine, dayEnergyOutput,
                             Environment.NewLine, dayMinedOre));//Environment.NewLine, summedEnergyOutput, Environment.NewLine, summedOreOutput
    }
Exemple #4
0
    public string Check(List <string> arguments)
    {
        string checkThisId = arguments[0];

        Unit unit = (Unit)Harvesters.FirstOrDefault(h => h.Id == checkThisId) ?? Providers.FirstOrDefault(p => p.Id == checkThisId);

        if (unit != null)
        {
            return(unit.ToString());
        }
        //return $"No element found with id - {checkThisId}";
        return(string.Format(Messages.UnitNotFound, checkThisId));
    }
    public string Check(List <string> arguments)
    {
        var id        = arguments[0];
        var harvester = Harvesters.FirstOrDefault(h => h.Id == id);
        var provider  = Providers.FirstOrDefault(p => p.Id == id);

        if (harvester != null)
        {
            return(harvester.ToString());
        }
        else if (provider != null)
        {
            return(provider.ToString());
        }

        return($"No element found with id - {id}");
    }
    public string RegisterHarvester(List <string> arguments)
    {
        Harvester harvester;
        var       type              = arguments[0];
        var       id                = arguments[1];
        var       oreOutput         = double.Parse(arguments[2]);
        var       energyRequirement = double.Parse(arguments[3]);

        if (CheckIdUniqueness("harvester", id))
        {
            if (type == "Sonic")
            {
                var sonicFactor = int.Parse(arguments[4]);
                try
                {
                    harvester = HarvesterFactory.CreateSonic(id, oreOutput, energyRequirement, sonicFactor);
                }
                catch (Exception e)
                {
                    return(e.Message);
                }
            }
            else
            {
                try
                {
                    harvester = HarvesterFactory.CreateHammer(id, oreOutput, energyRequirement);
                }
                catch (Exception e)
                {
                    return(e.Message);
                }
            }
            Harvesters.Add(harvester);
            return($"Successfully registered {type} Harvester - {id}");
        }
        return("Harvester is not registered, because of it's id");
    }
Exemple #7
0
 public void Harvest(ServerConfig server)
 {
     Harvesters.ForEach(x => Logger.WithLogSection(x.GetType().Name, () => x.Harvest(server)));
 }