mirror of
				https://github.com/vegapnk/RJW-Genes.git
				synced 2024-08-15 00:23:31 +00:00 
			
		
		
		
	Centralized Faction Goodwill Penalties in a single Helper
This commit is contained in:
		
							parent
							
								
									f5917052ab
								
							
						
					
					
						commit
						4623333605
					
				
					 7 changed files with 49 additions and 59 deletions
				
			
		| 
						 | 
					@ -81,6 +81,7 @@ but they are meant mostly to have infectors immune against their own diseases.
 | 
				
			||||||
- Gene: Sexual Genetic Swap. Pawns have a chance to switch a random gene with their sexpartner. 
 | 
					- Gene: Sexual Genetic Swap. Pawns have a chance to switch a random gene with their sexpartner. 
 | 
				
			||||||
- (Archite) Gene: Sexual Genetic Thief. Pawns have a chance to steal a gene from their sexpartner. Genetic Disease Immunity shields against this. 
 | 
					- (Archite) Gene: Sexual Genetic Thief. Pawns have a chance to steal a gene from their sexpartner. Genetic Disease Immunity shields against this. 
 | 
				
			||||||
- Pawns will have negative thoughts about pawns with more genetic diseases than themselves. 
 | 
					- Pawns will have negative thoughts about pawns with more genetic diseases than themselves. 
 | 
				
			||||||
 | 
					- Faction Penalties for spreading diseases, stealing genes and aging pawns with age transfer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
**Fixes:**
 | 
					**Fixes:**
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										42
									
								
								Source/Common/Helpers/FactionUtility.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								Source/Common/Helpers/FactionUtility.cs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,42 @@
 | 
				
			||||||
 | 
					using RimWorld;
 | 
				
			||||||
 | 
					using System;
 | 
				
			||||||
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					using System.Text;
 | 
				
			||||||
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
 | 
					using Verse;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace RJW_Genes
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public class FactionUtility
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// Tries to change the goodwill between the factions of two pawns. 
 | 
				
			||||||
 | 
					        /// Exceptions when nothing happens:
 | 
				
			||||||
 | 
					        /// - Pawns, or Pawns Factions, are null 
 | 
				
			||||||
 | 
					        /// - The `actors` Faction is not the players faction
 | 
				
			||||||
 | 
					        /// - Both pawns have the same faction
 | 
				
			||||||
 | 
					        /// - The Event is not found
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="actor">The pawn that initiated a faction-goodwill change by his actions</param>
 | 
				
			||||||
 | 
					        /// <param name="target">The pawn that was harmed/affected by the action</param>
 | 
				
			||||||
 | 
					        /// <param name="HistoryEventDefname">The event defname, for proper reporting</param>
 | 
				
			||||||
 | 
					        /// <param name="goodWillChange">How much (positive or negative) the goodwill will change</param>
 | 
				
			||||||
 | 
					        public static void HandleFactionGoodWillPenalties(Pawn actor, Pawn target, string HistoryEventDefname, int goodWillChange, bool canSendHostileLetter=true)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if (actor == null) return;
 | 
				
			||||||
 | 
					            if (target == null) return;
 | 
				
			||||||
 | 
					            if (
 | 
				
			||||||
 | 
					                target.Faction != null && actor.Faction != null
 | 
				
			||||||
 | 
					                && target.Faction != actor.Faction
 | 
				
			||||||
 | 
					                && target.Faction != Faction.OfPlayer)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                HistoryEventDef reason = DefDatabase<HistoryEventDef>.GetNamedSilentFail(HistoryEventDefname);
 | 
				
			||||||
 | 
					                if (reason == null) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                target.Faction.TryAffectGoodwillWith(actor.Faction, goodWillChange, true, canSendHostileLetter, reason, target);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -54,23 +54,11 @@ namespace RJW_Genes
 | 
				
			||||||
                    if ((new Random()).NextDouble() < application_chance)
 | 
					                    if ((new Random()).NextDouble() < application_chance)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        partner.genes.AddGene(diseaseGeneDef, !RJW_Genes_Settings.rjw_genes_genetic_disease_as_endogenes);
 | 
					                        partner.genes.AddGene(diseaseGeneDef, !RJW_Genes_Settings.rjw_genes_genetic_disease_as_endogenes);
 | 
				
			||||||
                        HandleFactionGoodWillPenalties(infector, partner);
 | 
					                        FactionUtility.HandleFactionGoodWillPenalties(infector, partner, "rjw_genes_GoodwillChangedReason_infected_with_disease",FACTION_GOODWILL_CHANGE);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private static void HandleFactionGoodWillPenalties(Pawn infector, Pawn partner)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            if (
 | 
					 | 
				
			||||||
                partner.Faction != null && infector.Faction != null
 | 
					 | 
				
			||||||
                && partner.Faction != infector.Faction
 | 
					 | 
				
			||||||
                && partner.Faction != Faction.OfPlayer)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                HistoryEventDef reason = DefDatabase<HistoryEventDef>.GetNamedSilentFail("rjw_genes_GoodwillChangedReason_infected_with_disease");
 | 
					 | 
				
			||||||
                partner.Faction.TryAffectGoodwillWith(infector.Faction, FACTION_GOODWILL_CHANGE, true, true, reason, partner);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -51,22 +51,10 @@ namespace RJW_Genes
 | 
				
			||||||
                if ((new Random()).NextDouble() <= DiseaseHelper.LookupDiseaseInfectionChance(disease))
 | 
					                if ((new Random()).NextDouble() <= DiseaseHelper.LookupDiseaseInfectionChance(disease))
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    infected.genes.AddGene(disease, !RJW_Genes_Settings.rjw_genes_genetic_disease_as_endogenes);
 | 
					                    infected.genes.AddGene(disease, !RJW_Genes_Settings.rjw_genes_genetic_disease_as_endogenes);
 | 
				
			||||||
                    HandleFactionGoodWillPenalties(infector, infected);
 | 
					                    FactionUtility.HandleFactionGoodWillPenalties(infector, infected, "rjw_genes_GoodwillChangedReason_spread_genetic_disease", FACTION_GOODWILL_CHANGE);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private static void HandleFactionGoodWillPenalties(Pawn actor, Pawn target)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            if (
 | 
					 | 
				
			||||||
                target.Faction != null && actor.Faction != null
 | 
					 | 
				
			||||||
                && target.Faction != actor.Faction
 | 
					 | 
				
			||||||
                && target.Faction != Faction.OfPlayer)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                HistoryEventDef reason = DefDatabase<HistoryEventDef>.GetNamedSilentFail("rjw_genes_GoodwillChangedReason_spread_genetic_disease");
 | 
					 | 
				
			||||||
                target.Faction.TryAffectGoodwillWith(actor.Faction, FACTION_GOODWILL_CHANGE, true, true, reason, target);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -84,19 +84,8 @@ namespace RJW_Genes.Genes.Special
 | 
				
			||||||
                    ModLog.Message($"[Sexual Age Drainer] {receiver} was too young ({receiver.ageTracker.AgeBiologicalYears}), and remains unchanged.");
 | 
					                    ModLog.Message($"[Sexual Age Drainer] {receiver} was too young ({receiver.ageTracker.AgeBiologicalYears}), and remains unchanged.");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            HandleFactionGoodWillPenalties(receiver, giver);
 | 
					            FactionUtility.HandleFactionGoodWillPenalties(receiver, giver, "rjw_genes_GoodwillChangedReason_aged_pawn_with_sex_gene",FACTION_GOODWILL_CHANGE);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private static void HandleFactionGoodWillPenalties(Pawn actor, Pawn target)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            if (
 | 
					 | 
				
			||||||
                target.Faction != null && actor.Faction != null
 | 
					 | 
				
			||||||
                && target.Faction != actor.Faction
 | 
					 | 
				
			||||||
                && target.Faction != Faction.OfPlayer)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                HistoryEventDef reason = DefDatabase<HistoryEventDef>.GetNamedSilentFail("rjw_genes_GoodwillChangedReason_youthed_pawn_with_sex_gene");
 | 
					 | 
				
			||||||
                target.Faction.TryAffectGoodwillWith(actor.Faction, FACTION_GOODWILL_CHANGE, true, true, reason, target);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -68,14 +68,7 @@ namespace RJW_Genes
 | 
				
			||||||
            stealer.genes.AddGene(stolenGene.def, AddAsXenogene);
 | 
					            stealer.genes.AddGene(stolenGene.def, AddAsXenogene);
 | 
				
			||||||
            victim.genes.RemoveGene(stolenGene);
 | 
					            victim.genes.RemoveGene(stolenGene);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (
 | 
					            FactionUtility.HandleFactionGoodWillPenalties(stealer, victim, "rjw_genes_GoodwillChangedReason_StoleGene", FACTION_GOODWILL_CHANGE);
 | 
				
			||||||
                victim.Faction != null && stealer.Faction != null 
 | 
					 | 
				
			||||||
                && victim.Faction != stealer.Faction
 | 
					 | 
				
			||||||
                && victim.Faction != Faction.OfPlayer) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                HistoryEventDef reason = DefDatabase<HistoryEventDef>.GetNamedSilentFail("rjw_genes_GoodwillChangedReason_StoleGene");
 | 
					 | 
				
			||||||
                victim.Faction.TryAffectGoodwillWith(stealer.Faction, FACTION_GOODWILL_CHANGE, true, true, reason, victim);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -42,12 +42,12 @@ namespace RJW_Genes.Genes.Special
 | 
				
			||||||
            if (GeneUtility.IsYouthFountain(props.pawn))
 | 
					            if (GeneUtility.IsYouthFountain(props.pawn))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                ChangeAgeForPawn(props.partner, props.pawn);
 | 
					                ChangeAgeForPawn(props.partner, props.pawn);
 | 
				
			||||||
                HandleFactionGoodWillPenalties(props.pawn, props.partner);
 | 
					                FactionUtility.HandleFactionGoodWillPenalties(props.pawn, props.partner, "rjw_genes_GoodwillChangedReason_youthed_pawn_with_sex_gene",+1);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if (GeneUtility.IsYouthFountain(props.partner))
 | 
					            if (GeneUtility.IsYouthFountain(props.partner))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                ChangeAgeForPawn(props.pawn,props.partner);
 | 
					                ChangeAgeForPawn(props.pawn,props.partner);
 | 
				
			||||||
                HandleFactionGoodWillPenalties(props.partner, props.pawn);
 | 
					                FactionUtility.HandleFactionGoodWillPenalties(props.pawn, props.partner, "rjw_genes_GoodwillChangedReason_youthed_pawn_with_sex_gene", +1);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -71,17 +71,6 @@ namespace RJW_Genes.Genes.Special
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private static void HandleFactionGoodWillPenalties(Pawn actor, Pawn target)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            if (
 | 
					 | 
				
			||||||
                target.Faction != null && actor.Faction != null
 | 
					 | 
				
			||||||
                && target.Faction != actor.Faction
 | 
					 | 
				
			||||||
                && target.Faction != Faction.OfPlayer)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                HistoryEventDef reason = DefDatabase<HistoryEventDef>.GetNamedSilentFail("rjw_genes_GoodwillChangedReason_youthed_pawn_with_sex_gene");
 | 
					 | 
				
			||||||
                target.Faction.TryAffectGoodwillWith(actor.Faction, FACTION_GOODWILL_CHANGE, true, true, reason, target);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue