This repository has been archived on 2022-08-05. You can view files and clone it, but cannot push or open issues or pull requests.
Lemonade/Lemonade/PlayerState.cs

76 lines
2.9 KiB
C#

using System;
using System.Collections.Generic;
namespace Lemonade
{
public class PlayerState
{
#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;
public int Budget;
public int Earnings;
public int Expenses;
public int Glasses;
public int GlassPrice;
public int Sales;
public int Signs;
public PlayerState(int number)
{
Budget = 200;
Number = number;
}
//TODO (maybe) balance, increase difficulty?
public void CalculateIncome(int signCost, int glassCost, Weather weather, Settings settings)
{
//Calculate combined expenses
Expenses = signCost * Signs + glassCost * Glasses;
//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
Budget += Earnings - Expenses;
}
}
}