2020-06-12 20:02:39 +02:00
|
|
|
using System;
|
2020-06-13 12:15:11 +02:00
|
|
|
using System.Collections.Generic;
|
2020-06-12 20:02:39 +02:00
|
|
|
|
|
|
|
namespace Lemonade
|
2020-06-12 20:02:04 +02:00
|
|
|
{
|
2020-06-12 20:02:39 +02:00
|
|
|
public class PlayerState
|
|
|
|
{
|
2020-06-13 12:15:11 +02:00
|
|
|
#region Autogenerated equality comparison stuff
|
|
|
|
protected bool Equals(PlayerState other) => Number == other.Number;
|
|
|
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
{
|
|
|
|
if (ReferenceEquals(null, obj)) return false;
|
|
|
|
if (ReferenceEquals(this, obj)) return true;
|
|
|
|
if (obj.GetType() != GetType()) return false;
|
|
|
|
return Equals((PlayerState) obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override int GetHashCode() => Number;
|
|
|
|
|
|
|
|
private sealed class NumberEqualityComparer : IEqualityComparer<PlayerState>
|
|
|
|
{
|
|
|
|
public bool Equals(PlayerState x, PlayerState y)
|
|
|
|
{
|
|
|
|
if (ReferenceEquals(x, y)) return true;
|
|
|
|
if (ReferenceEquals(x, null)) return false;
|
|
|
|
if (ReferenceEquals(y, null)) return false;
|
|
|
|
if (x.GetType() != y.GetType()) return false;
|
|
|
|
return x.Number == y.Number;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int GetHashCode(PlayerState obj) => obj.Number;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static IEqualityComparer<PlayerState> NumberComparer { get; } = new NumberEqualityComparer();
|
|
|
|
#endregion
|
|
|
|
public readonly int Number;
|
2020-06-12 20:02:39 +02:00
|
|
|
public int Budget;
|
2020-06-12 20:16:11 +02:00
|
|
|
public int Earnings;
|
|
|
|
public int Expenses;
|
2020-06-12 20:02:39 +02:00
|
|
|
public int Glasses;
|
|
|
|
public int GlassPrice;
|
2020-06-12 20:16:11 +02:00
|
|
|
public int Sales;
|
|
|
|
public int Signs;
|
2020-06-12 20:02:39 +02:00
|
|
|
|
|
|
|
public PlayerState(int number)
|
|
|
|
{
|
|
|
|
Budget = 200;
|
|
|
|
Number = number;
|
|
|
|
}
|
|
|
|
|
2020-06-13 12:15:11 +02:00
|
|
|
//TODO (maybe) balance, increase difficulty?
|
2020-06-12 20:02:39 +02:00
|
|
|
public void CalculateIncome(int signCost, int glassCost, Weather weather, Settings settings)
|
|
|
|
{
|
2020-06-13 12:15:11 +02:00
|
|
|
//Calculate combined expenses
|
2020-06-12 20:02:39 +02:00
|
|
|
Expenses = signCost * Signs + glassCost * Glasses;
|
2020-06-13 12:15:11 +02:00
|
|
|
//Calculate a scalar for sales between 0.2 and 1.5 based on the weather factor
|
|
|
|
double weatherFactor = (weather.Factor * 2 + 1d) / (settings.DifficultyFactor * 2d + 1d) / 2d;
|
|
|
|
//Calculate a scalar between 0.3 and (basically) 2.5 based on the amount of signs
|
|
|
|
double signFactor = 2.5d - (settings.DifficultyFactor + 0.1) * 2d / (Signs + 1d);
|
|
|
|
//Calculate a scalar between (basically) 0 and 3 based on the price of lemonades
|
|
|
|
double priceFactor = 3 / (GlassPrice / 2d + 1);
|
|
|
|
//Multiply the factors and sanitize results
|
|
|
|
Sales = (int) (weatherFactor * signFactor * priceFactor * Glasses);
|
|
|
|
//Apply weather events to Sales
|
|
|
|
if (weather.Heatwave) Sales = (int) (Sales * 1.2);
|
|
|
|
if (weather.Thunderstorm) Sales = 0;
|
|
|
|
//Sanitize sales
|
|
|
|
Sales = Math.Max(Math.Min(Sales, Glasses), 0);
|
|
|
|
//Calculate earnings from sales
|
|
|
|
Earnings = (int) Math.Floor((double) Sales * GlassPrice);
|
|
|
|
//Calculate new budget
|
2020-06-12 20:02:39 +02:00
|
|
|
Budget += Earnings - Expenses;
|
|
|
|
}
|
|
|
|
}
|
2020-06-12 20:02:04 +02:00
|
|
|
}
|