-
Notifications
You must be signed in to change notification settings - Fork 8
/
TaxCollector.cs
103 lines (87 loc) · 3.42 KB
/
TaxCollector.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.IO;
using System.Xml.Serialization;
using UnityEngine;
using Random = UnityEngine.Random;
namespace BagOfTricks
{
[Serializable]
public class TaxCollectorSettings
{
public bool initialLaunch = true;
public string playerTitle = "";
public DateTime saveTime;
public int textLineInitialCounter = 0;
}
public static class TaxCollector
{
public static Settings settings = Main.settings;
public static DateTime saveTimeGame = new DateTime();
public static bool isFirstVisit = true;
public static string playerTitleInput = "";
public static string resultLine0 = "";
public static int MoneyRank(int rankEconomy, int rankStability, int rankLoyalty)
{
if (rankEconomy == 0) rankEconomy = 1;
if (rankStability == 0) rankStability = 1;
if (rankLoyalty == 0) rankLoyalty = 1;
var result = rankEconomy * rankStability * rankLoyalty;
return result / 3;
}
public static int BpRank(int rankEconomy, int rankStability, int rankCommunity)
{
if (rankEconomy == 0) rankEconomy = 1;
if (rankStability == 0) rankStability = 1;
if (rankCommunity == 0) rankCommunity = 1;
var result = rankEconomy * rankStability * rankCommunity;
return result / 3;
}
public static int CollectBp(int rank, DateTime saveTime)
{
var collectTime = DateTime.Now;
var timePassed = collectTime.Subtract(saveTime);
var timeMultiplier = (int) Math.Floor(timePassed.TotalHours);
if (timeMultiplier < 1) return 0;
if (timeMultiplier > 72) timeMultiplier = 72;
var result = Mathf.RoundToInt(timeMultiplier * rank * Random.Range(0.75f, 1.5f));
return result;
}
public static int CollectMoney(int rank, int charisma, DateTime saveTime)
{
var collectTime = DateTime.Now;
var timePassed = collectTime.Subtract(saveTime);
var timeMultiplier = (int) Math.Floor(timePassed.TotalHours);
if (timeMultiplier < 1) return 0;
if (timeMultiplier > 72) timeMultiplier = 72;
var result = Mathf.RoundToInt(timeMultiplier * rank * charisma / 2 * Random.Range(0.75f, 1.5f));
return result;
}
public static void Serialize(TaxCollectorSettings tax, string filePath)
{
var serializer = new XmlSerializer(typeof(TaxCollectorSettings));
using (var stream = File.Create(filePath))
{
serializer.Serialize(stream, tax);
}
}
public static TaxCollectorSettings Deserialize(string filePath)
{
var newTax = new TaxCollectorSettings();
if (File.Exists(filePath))
try
{
using (var stream = File.OpenRead(filePath))
{
var serializer = new XmlSerializer(typeof(TaxCollectorSettings));
var save = (TaxCollectorSettings) serializer.Deserialize(stream);
return save;
}
}
catch (Exception exception)
{
Main.modLogger.Log(exception.ToString());
}
return newTax;
}
}
}