Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
legodude17 committed Feb 18, 2022
2 parents b706c48 + 384db77 commit 2e63051
Show file tree
Hide file tree
Showing 8 changed files with 408 additions and 3 deletions.
Binary file modified 1.3/Assemblies/VFECore.dll
Binary file not shown.
5 changes: 5 additions & 0 deletions Source/VFECore/VFECore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@
<Compile Include="Plants\Harmony\Plant_PlantCollected.cs" />
<Compile Include="UItils\UIUtility.cs" />
<Compile Include="VFECore\Comps\WorldComponents\HiringContractTracker.cs" />
<Compile Include="VFECore\Defs\BackstoryDef.cs" />
<Compile Include="VFECore\HarmonyPatches\Apparel_Patches.cs" />
<Compile Include="VFECore\HarmonyPatches\CalculatePain_Patch.cs" />
<Compile Include="VFECore\DefModExtensions\TraitExtension.cs" />
Expand Down Expand Up @@ -751,6 +752,8 @@
<Compile Include="VFECore\Lords\LordJob_SiegeCustom.cs" />
<Compile Include="VFECore\Lords\LordToilData_SiegeCustom.cs" />
<Compile Include="VFECore\Lords\LordToil_SiegeCustom.cs" />
<Compile Include="VFECore\MapExtender\MapGenerator_GenerateMap_Patch.cs" />
<Compile Include="VFECore\MapExtender\ObjectSpawnsDef.cs" />
<Compile Include="VFECore\ModCompatibilityCheck.cs" />
<Compile Include="VFECore\Needs\Need_Power.cs" />
<Compile Include="VFECore\PatchOperation\PatchOperationToggableSequence.cs" />
Expand Down Expand Up @@ -781,6 +784,8 @@
<Compile Include="VFECore\VFECore.cs" />
<Compile Include="VFECore\WorkGivers\WorkGiver_AttachTurret.cs" />
<Compile Include="VFECore\WorkGivers\WorkGiver_RepairMachine.cs" />
<Compile Include="WeatherOverlays\WeatherOverlay_Custom.cs" />
<Compile Include="WeatherOverlays\WeatherOverlay_CustomTwo.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="VFECore\Verbs\" />
Expand Down
20 changes: 17 additions & 3 deletions Source/VFECore/VFECore/Comps/ThingComps/CompShieldBubble.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public CompProperties_ShieldBubble()
public Color shieldColor = Color.white;
public float EnergyLossPerDamage = 1f;
public bool disableRotation;
public SoundDef absorbDamageSound;
public SoundDef brokenSound;
public SoundDef resetSound;
}

[StaticConstructorOnStartup]
Expand Down Expand Up @@ -287,7 +290,11 @@ public void KeepDisplaying()
}
private void AbsorbedDamage(DamageInfo dinfo)
{
SoundDefOf.EnergyShield_AbsorbDamage.PlayOneShot(new TargetInfo(this.Pawn.Position, this.Pawn.Map));
if (Props.absorbDamageSound != null)
Props.absorbDamageSound.PlayOneShot(new TargetInfo(this.Pawn.Position, this.Pawn.Map));
else
SoundDefOf.EnergyShield_AbsorbDamage.PlayOneShot(new TargetInfo(this.Pawn.Position, this.Pawn.Map));

impactAngleVect = Vector3Utility.HorizontalVectorFromAngle(dinfo.Angle);
Vector3 loc = this.Pawn.TrueCenter() + impactAngleVect.RotatedBy(180f) * 0.5f;
float num = Mathf.Min(10f, 2f + dinfo.Amount / 10f);
Expand All @@ -307,7 +314,10 @@ protected virtual void Break()
{
if (this.Pawn?.Map != null && this.Pawn.Position.InBounds(this.Pawn.Map))
{
SoundDefOf.EnergyShield_Broken.PlayOneShot(new TargetInfo(this.Pawn.Position, this.Pawn.Map));
if (Props.brokenSound != null)
Props.brokenSound.PlayOneShot(new TargetInfo(this.Pawn.Position, this.Pawn.Map));
else
SoundDefOf.EnergyShield_Broken.PlayOneShot(new TargetInfo(this.Pawn.Position, this.Pawn.Map));

FleckMaker.Static(this.Pawn.TrueCenter(), this.Pawn.Map, FleckDefOf.ExplosionFlash, 12f);
for (int i = 0; i < 6; i++)
Expand All @@ -324,7 +334,11 @@ protected virtual void Reset()
{
if (this.Pawn.Spawned)
{
SoundDefOf.EnergyShield_Reset.PlayOneShot(new TargetInfo(this.Pawn.Position, this.Pawn.Map));
if (Props.resetSound != null)
Props.resetSound.PlayOneShot(new TargetInfo(this.Pawn.Position, this.Pawn.Map));
else
SoundDefOf.EnergyShield_Reset.PlayOneShot(new TargetInfo(this.Pawn.Position, this.Pawn.Map));

FleckMaker.ThrowLightningGlow(this.Pawn.TrueCenter(), this.Pawn.Map, 3f);
}

Expand Down
132 changes: 132 additions & 0 deletions Source/VFECore/VFECore/Defs/BackstoryDef.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using HarmonyLib;
using RimWorld;
using Verse;

namespace VFECore
{
public class TraitEntryBackstory
{
public TraitDef defName;

public int degree;

public int chance;
}
public class BackstoryDef : Def
{
public override void ResolveReferences()
{
if (BackstoryDatabase.allBackstories.ContainsKey(this.saveKeyIdentifier))
{
Log.Error(this.defName + " contains a saveKeyIdentifier value " + saveKeyIdentifier + " which is used already. It won't be added as a def. Make sure that the identifier is unique.");
return;
}

Backstory backstory = new Backstory();
if (this.forcedTraits?.Any() ?? false)
{
backstory.forcedTraits = new List<TraitEntry>();
foreach (var trait in this.forcedTraits.Where(x => Rand.RangeInclusive(0, 100) < x.chance))
{
backstory.forcedTraits.Add(new TraitEntry(trait.defName, trait.degree));
}
}

if (this.disallowedTraits?.Any() ?? false)
{
backstory.disallowedTraits = new List<TraitEntry>();
foreach (var trait in this.disallowedTraits.Where(x => Rand.RangeInclusive(0, 100) < x.chance))
{
backstory.disallowedTraits.Add(new TraitEntry(trait.defName, trait.degree));
}
}

backstory.SetTitle(this.title, this.title);
if (!GenText.NullOrEmpty(this.titleShort))
{
backstory.SetTitleShort(this.titleShort, this.titleShort);
}
else
{
backstory.SetTitleShort(backstory.title, backstory.title);
}
if (!GenText.NullOrEmpty(this.baseDescription))
{
backstory.baseDesc = this.baseDescription;
}

Traverse.Create(backstory).Field("bodyTypeGlobal").SetValue(this.bodyTypeGlobal);
Traverse.Create(backstory).Field("bodyTypeMale").SetValue(this.bodyTypeMale);
Traverse.Create(backstory).Field("bodyTypeFemale").SetValue(this.bodyTypeFemale);
if (skillGains?.Any() ?? false)
{
var skillGainsDict = skillGains.ToDictionary(x => x.skill.defName, y => y.minLevel);
Traverse.Create(backstory).Field("skillGains").SetValue(skillGainsDict);
}

backstory.slot = this.slot;
backstory.shuffleable = this.shuffleable;
backstory.spawnCategories = this.spawnCategories;

if (this.workDisables.Any())
{
foreach (var workTag in this.workDisables)
{
backstory.workDisables |= workTag;
}
}
else
{
backstory.workDisables = WorkTags.None;
}

backstory.PostLoad();
backstory.ResolveReferences();
backstory.identifier = this.saveKeyIdentifier;

if (!backstory.ConfigErrors(true).Any())
{
BackstoryDatabase.AddBackstory(backstory);
}
else
{
foreach (var err in backstory.ConfigErrors(true))
{
Log.Error(backstory + " - " + err);
}
}
}

public string baseDescription;

public string bodyTypeGlobal = "";

public string bodyTypeMale = "Male";

public string bodyTypeFemale = "Female";

public string title;

public string titleShort;

public BackstorySlot slot = BackstorySlot.Childhood;

public bool shuffleable = true;

public List<WorkTags> workDisables = new List<WorkTags>();

public List<string> spawnCategories = new List<string>();

public List<SkillRequirement> skillGains;

public List<TraitEntryBackstory> forcedTraits = new List<TraitEntryBackstory>();

public List<TraitEntryBackstory> disallowedTraits = new List<TraitEntryBackstory>();

public string saveKeyIdentifier;
}
}
140 changes: 140 additions & 0 deletions Source/VFECore/VFECore/MapExtender/MapGenerator_GenerateMap_Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
using System;
using RimWorld;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Verse;
using UnityEngine;
using RimWorld.Planet;
using HarmonyLib;

// Copyright Sarg - Alpha Biomes 2020 & Taranchuck

namespace VFECore
{
[HarmonyPatch(typeof(MapGenerator), nameof(MapGenerator.GenerateMap))]
public static class MapGenerator_GenerateMap_Patch
{
public static void Postfix(Map __result)
{
DoMapSpawns(__result);
}
public static bool CanSpawnAt(IntVec3 c, Map map, ObjectSpawnsDef element)
{
if (!element.allowOnChunks)
{
foreach (var item in c.GetThingList(map))
{
if (item?.def?.thingCategories != null)
{
foreach (var category in item.def.thingCategories)
{
if (category == ThingCategoryDefOf.Chunks || category == ThingCategoryDefOf.StoneChunks)
{
return false;
}
}
}
}
}

TerrainDef terrain = c.GetTerrain(map);

bool flagAllowed = true;

foreach (string allowed in element.allowedTerrains)
{
if (terrain.defName == allowed)
{
break;
}
else flagAllowed = false;
}
if (!flagAllowed) return false;

foreach (string notAllowed in element.disallowedTerrainTags)
{
if (terrain.HasTag(notAllowed))
{
return false;
}
}

if (!element.allowOnWater && terrain.IsWater)
{
return false;
}

if (element.findCellsOutsideColony)
{
if (!OutOfCenter(c, map, 60))
{
return false;
}
}

return true;
}
public static void DoMapSpawns(Map map)
{
int spawnCounter = 0;
foreach (ObjectSpawnsDef element in DefDatabase<ObjectSpawnsDef>.AllDefs.Where(element => element.allowedBiomes.Contains(map.Biome)))
{
if (element.spawnOnlyInPlayerMaps && !map.IsPlayerHome)
{
continue;
}
IEnumerable<IntVec3> tmpTerrain = map.AllCells.InRandomOrder();
if (spawnCounter == 0)
{
spawnCounter = element.numberToSpawn.RandomInRange;
}
foreach (IntVec3 c in tmpTerrain)
{
bool canSpawn = CanSpawnAt(c, map, element);
if (canSpawn)
{
Thing thing = (Thing)ThingMaker.MakeThing(element.thingDef, null);
CellRect occupiedRect = GenAdj.OccupiedRect(c, thing.Rotation, thing.def.Size);
if (occupiedRect.InBounds(map))
{
canSpawn = true;
foreach (IntVec3 c2 in occupiedRect)
{
if (!CanSpawnAt(c2, map, element))
{
canSpawn = false;
break;
}
}
if (canSpawn)
{
if (element.randomRotation)
{
GenPlace.TryPlaceThing(thing, c, map, ThingPlaceMode.Direct, null, null, Rot4.Random);
}
else
{
GenSpawn.Spawn(thing, c, map);
}
spawnCounter--;
}
}
}

if (canSpawn && spawnCounter <= 0)
{
spawnCounter = 0;
break;
}
}
}
}

public static bool OutOfCenter(IntVec3 c, Map map, int centerDist)
{
IntVec3 CenterPoint = map.Center;
return c.x < CenterPoint.x - centerDist || c.z < CenterPoint.z - centerDist || c.x >= CenterPoint.x + centerDist || c.z >= CenterPoint.z + centerDist;
}
}
}
24 changes: 24 additions & 0 deletions Source/VFECore/VFECore/MapExtender/ObjectSpawnsDef.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using RimWorld;
using UnityEngine;
using Verse;

// Copyright Sarg - Alpha Biomes 2020 & Taranchuck

namespace VFECore
{
public class ObjectSpawnsDef : Def
{
public ThingDef thingDef;
public bool allowOnWater;
public bool allowOnChunks;
public IntRange numberToSpawn;
public List<string> allowedTerrains;
public List<string> disallowedTerrainTags;
public List<BiomeDef> allowedBiomes;
public bool findCellsOutsideColony = false;
public bool spawnOnlyInPlayerMaps = false;
public bool randomRotation;
}
}
Loading

0 comments on commit 2e63051

Please sign in to comment.