public bool CanVoteCanUsedAgainInThisVotingPeriod(VotingIncident incident) { int timesVoteCanBeUsedInVotingPeriod = VotingPeriodDays / incident.weight / 5; if (TimesVoteHasBeenWonInVotingPeriod(incident) >= timesVoteCanBeUsedInVotingPeriod) { return(false); } return(true); }
public void LogVoteIncident(VotingIncident incident) { int lastTick = Find.TickManager.TicksGame; lastID = lastID + 1; VoteIDs.Add(lastID, incident.defName); VoteHistory.Add(lastID, lastTick); previousCategory = incident.eventCategory; previousType = incident.eventType; lastFiredTick = lastTick; }
public int TimesVoteHasBeenWonInVotingPeriod(VotingIncident incident) { List <int> idsOfIncidentType = new List <int>(VoteIDs.Keys.Where(s => VoteIDs[s] == incident.defName)); if (idsOfIncidentType != null) { return(idsOfIncidentType.Count); } return(0); }
static Settings_VoteWeights() { if (ToolkitSettings.VoteWeights == null || ToolkitSettings.VoteWeights.Count < 1) { if (DefDatabase <VotingIncident> .AllDefs == null || DefDatabase <VotingIncident> .AllDefs.Count() < 0) { return; } Log.Warning("Loading brand new vote weights"); ToolkitSettings.VoteWeights = new Dictionary <string, int>(); foreach (VotingIncident vote in DefDatabase <VotingIncident> .AllDefs) { ToolkitSettings.VoteWeights.Add(vote.defName, 100); } } else { Log.Warning("Loading vote weights not saved"); List <VotingIncident> incidentsNotLoaded = DefDatabase <VotingIncident> .AllDefs.Where(s => !ToolkitSettings.VoteWeights.ContainsKey(s.defName) ).ToList(); foreach (VotingIncident vote in incidentsNotLoaded) { ToolkitSettings.VoteWeights.Add(vote.defName, 100); } } if (ToolkitSettings.VoteWeights != null && ToolkitSettings.VoteWeights.Count > 0) { Log.Warning("Loading vote weights from player settings"); foreach (KeyValuePair <string, int> pair in ToolkitSettings.VoteWeights) { VotingIncident vote = DefDatabase <VotingIncident> .AllDefs.ToList().Find(s => s.defName == pair.Key ); if (vote != null) { vote.voteWeight = pair.Value; } } } }
public virtual int CalculateVotingIncidentWeight(VotingIncident incident) { int previousWinsInVotingPeriod = voteTracker.TimesVoteHasBeenWonInVotingPeriod(incident); int initialWeight = (5 / incident.weight) * 100; int weightRemovedFromVotingPeriodWins = previousWinsInVotingPeriod * 20; int weightRemovedFromPreviousCategory = incident.eventCategory == voteTracker.previousCategory ? 50 : 0; int weightRemovedFromPreviousType = incident.eventType == voteTracker.previousType ? 50 : 0; return(Convert.ToInt32(Math.Max(initialWeight - weightRemovedFromVotingPeriodWins - weightRemovedFromPreviousCategory - weightRemovedFromPreviousType, 0) * ((float)incident.voteWeight / 100f))); }
public static void Load_VoteWeights() { if (ToolkitSettings.VoteWeights != null && ToolkitSettings.VoteWeights.Count < 1) { if (DefDatabase <VotingIncident> .AllDefs == null || DefDatabase <VotingIncident> .AllDefs.Count() < 1) { return; } } else { List <VotingIncident> incidentsNotLoaded = DefDatabase <VotingIncident> .AllDefs.Where(s => !ToolkitSettings.VoteWeights.ContainsKey(s.defName) ).ToList(); foreach (VotingIncident vote in incidentsNotLoaded) { ToolkitSettings.VoteWeights.Add(vote.defName, 100); } } if (ToolkitSettings.VoteWeights != null && ToolkitSettings.VoteWeights.Count > 0) { foreach (KeyValuePair <string, int> pair in ToolkitSettings.VoteWeights) { VotingIncident vote = DefDatabase <VotingIncident> .AllDefs.ToList().Find(s => s.defName == pair.Key ); if (vote != null) { vote.voteWeight = pair.Value; } } } }
public void LogVoteIncident(VotingIncident incident) { lastID = lastID + 1; VoteIDs.Add(lastID, incident.defName); VoteHistory.Add(lastID, Find.TickManager.TicksGame); }
public VotingIncidentEntry(VotingIncident incident, float weight) { this.incident = incident; this.weight = weight; }