-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd0bacb
commit fd08e61
Showing
12 changed files
with
743 additions
and
20 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{0BD0B28D-9672-4ADD-9558-2317673C52DA}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>FarmAnimals</RootNamespace> | ||
<AssemblyName>FarmAnimals</AssemblyName> | ||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<Deterministic>true</Deterministic> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="0Harmony-1.2"> | ||
<HintPath>..\external\0Harmony-1.2.dll</HintPath> | ||
</Reference> | ||
<Reference Include="0Harmony12"> | ||
<HintPath>..\external\UnityModManager\0Harmony12.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Assembly-CSharp"> | ||
<HintPath>..\external\Assembly-CSharp.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Assembly-CSharp-firstpass"> | ||
<HintPath>..\external\Assembly-CSharp-firstpass.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="UnityEngine"> | ||
<HintPath>..\external\UnityEngine.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.AnimationModule"> | ||
<HintPath>..\external\UnityEngine.AnimationModule.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.AudioModule"> | ||
<HintPath>..\external\UnityEngine.AudioModule.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.CoreModule"> | ||
<HintPath>..\external\UnityEngine.CoreModule.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.ImageConversionModule"> | ||
<HintPath>..\external\UnityEngine.ImageConversionModule.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.IMGUIModule"> | ||
<HintPath>..\external\UnityEngine.IMGUIModule.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.ParticleSystemModule"> | ||
<HintPath>..\external\UnityEngine.ParticleSystemModule.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.PhysicsModule"> | ||
<HintPath>..\external\UnityEngine.PhysicsModule.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.TextRenderingModule"> | ||
<HintPath>..\external\UnityEngine.TextRenderingModule.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.UI"> | ||
<HintPath>..\external\UnityEngine.UI.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.UIModule"> | ||
<HintPath>..\external\UnityEngine.UIModule.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.UnityWebRequestAudioModule"> | ||
<HintPath>..\external\UnityEngine.UnityWebRequestAudioModule.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.UnityWebRequestModule"> | ||
<HintPath>..\external\UnityEngine.UnityWebRequestModule.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.UnityWebRequestWWWModule"> | ||
<HintPath>..\external\UnityEngine.UnityWebRequestWWWModule.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityModManager"> | ||
<HintPath>..\external\UnityModManager\UnityModManager.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Main.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="Settings.cs" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<PropertyGroup> | ||
<PostBuildEvent>call $(SolutionDir)copyDll.bat FarmAnimals</PostBuildEvent> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
using Harmony12; | ||
using Pathea; | ||
using Pathea.ACT; | ||
using Pathea.ModuleNs; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using Pathea.ActorNs; | ||
using UnityEngine; | ||
using UnityModManagerNet; | ||
using static Pathea.ActorMotor; | ||
using Pathea.AnimalFarmNs; | ||
using Pathea.HomeNs; | ||
using Hont.ExMethod.Collection; | ||
using Pathea.TipsNs; | ||
|
||
namespace FarmAnimals | ||
{ | ||
public class Main | ||
{ | ||
public static Settings settings { get; private set; } | ||
|
||
public static bool enabled; | ||
|
||
private static readonly bool isDebug = true; | ||
|
||
public static void Dbgl(string str = "", bool pref = true) | ||
{ | ||
if (isDebug) | ||
Debug.Log((pref ? "FarmAnimals " : "") + str); | ||
} | ||
|
||
private static void Load(UnityModManager.ModEntry modEntry) | ||
{ | ||
settings = Settings.Load<Settings>(modEntry); | ||
|
||
modEntry.OnGUI = OnGUI; | ||
modEntry.OnSaveGUI = OnSaveGUI; | ||
modEntry.OnToggle = OnToggle; | ||
|
||
var harmony = HarmonyInstance.Create(modEntry.Info.Id); | ||
harmony.PatchAll(Assembly.GetExecutingAssembly()); | ||
} | ||
|
||
// Called when the mod is turned to on/off. | ||
static bool OnToggle(UnityModManager.ModEntry modEntry, bool value /* active or inactive */) | ||
{ | ||
enabled = value; | ||
return true; // Permit or not. | ||
} | ||
private static void OnSaveGUI(UnityModManager.ModEntry modEntry) | ||
{ | ||
settings.Save(modEntry); | ||
} | ||
|
||
private static void OnGUI(UnityModManager.ModEntry modEntry) | ||
{ | ||
GUILayout.Label(string.Format("Animal Growth Speed: <b>{0:F1}</b>", settings.AnimalGrowthSpeed), new GUILayoutOption[0]); | ||
settings.AnimalGrowthSpeed = GUILayout.HorizontalSlider(settings.AnimalGrowthSpeed * 10f, 1f, 1000f, new GUILayoutOption[0]) / 10f; | ||
GUILayout.Space(10f); | ||
GUILayout.Label(string.Format("Max Animal Growth: <b>{0:F1}%</b>", settings.MaxAnimalGrowthPercent), new GUILayoutOption[0]); | ||
settings.MaxAnimalGrowthPercent = GUILayout.HorizontalSlider(settings.MaxAnimalGrowthPercent, 1f, 300f, new GUILayoutOption[0]); | ||
GUILayout.Space(10f); | ||
GUILayout.Label(string.Format("Base Pregnancy Chance: <b>{0:F1}%</b>", settings.BasePregnancyChance), new GUILayoutOption[0]); | ||
settings.BasePregnancyChance = GUILayout.HorizontalSlider(settings.BasePregnancyChance, 1f, 100f, new GUILayoutOption[0]); | ||
GUILayout.Space(10f); | ||
} | ||
|
||
[HarmonyPatch(typeof(AnimalData), nameof(AnimalData.GetDataByDataId))] | ||
static class AnimalData_GedDataByDataId | ||
{ | ||
static void Prefix(List<AnimalData> ___datas) | ||
{ | ||
if (!enabled) | ||
return; | ||
if (___datas == null) | ||
{ | ||
SqliteDataReader sqliteDataReader = LocalDb.cur.ReadFullTable("AnimalFarm_Animal"); | ||
if (sqliteDataReader == null) | ||
{ | ||
return; | ||
} | ||
___datas = DbReader.Read<AnimalData>(sqliteDataReader, 20); | ||
} | ||
for(int i = 0; i < ___datas.Count; i++) | ||
{ | ||
typeof(AnimalData).GetProperty("TotalPoint").SetValue(___datas[i],(int)Math.Round(___datas[i].StandardPoint * settings.MaxAnimalGrowthPercent / 100f), null); | ||
string name = TextMgr.GetStr(___datas[i].NameId, -1); | ||
Dbgl($"{name} max points set to {___datas[i].TotalPoint}"); | ||
} | ||
} | ||
} | ||
|
||
[HarmonyPatch(typeof(AnimalinFarm), "AddAgeChange")] | ||
static class AnimalinFarm_AddAgeChange | ||
{ | ||
static void Prefix(ref float foodNum) | ||
{ | ||
if (!enabled) | ||
return; | ||
foodNum *= settings.AnimalGrowthSpeed; | ||
} | ||
|
||
[HarmonyPatch(typeof(AnimalFarmUnit), "Reproduction")] | ||
static class AnimalFarmUnit_Reproduction | ||
{ | ||
private static bool Prefix(ref AnimalFarmUnit __instance) | ||
{ | ||
if (!enabled) | ||
return false; | ||
if (__instance.Animals.Count >= __instance.HouseData.AnimalMax) | ||
{ | ||
Dbgl($"farm already full, cancelling"); | ||
return false; | ||
} | ||
|
||
int tipsId; | ||
|
||
Dictionary<int, List<AnimalinFarm>> aifs = new Dictionary<int, List<AnimalinFarm>>(); | ||
foreach(AnimalinFarm aif in __instance.Animals) | ||
{ | ||
if (aif.Age >= aif.Data.StandardPoint) | ||
{ | ||
if (aifs.ContainsKey(aif.Data.Id)) | ||
{ | ||
aifs[aif.Data.Id].Add(aif); | ||
} | ||
else | ||
{ | ||
aifs.Add(aif.Data.Id, new List<AnimalinFarm>() { aif }); | ||
} | ||
} | ||
} | ||
|
||
Dictionary<int, int> newAnimals = new Dictionary<int, int>(); | ||
foreach(KeyValuePair<int,List<AnimalinFarm>> kvp in aifs) | ||
{ | ||
newAnimals.Add(kvp.Key, 0); | ||
} | ||
|
||
while(aifs.Keys.Count > 0) | ||
{ | ||
if (__instance.Animals.Count >= __instance.HouseData.AnimalMax) | ||
{ | ||
Dbgl($"farm filled up, breaking"); | ||
break; | ||
} | ||
int idx = aifs.Keys.ToArray()[UnityEngine.Random.Range(0, aifs.Count - 1)]; | ||
if(aifs[idx].Count < 2) | ||
{ | ||
aifs.Remove(idx); | ||
} | ||
else | ||
{ | ||
List<AnimalinFarm> aifl = aifs[idx]; | ||
List<AnimalinFarm> matureAnimals = aifl.FindAll((AnimalinFarm a) => a.Age >= a.Data.StandardPoint); | ||
if(matureAnimals.Count < 2) | ||
{ | ||
aifs.Remove(idx); | ||
} | ||
else | ||
{ | ||
int a = UnityEngine.Random.Range(0, matureAnimals.Count-1); | ||
AnimalinFarm aa = matureAnimals[a]; | ||
matureAnimals.RemoveAt(a); | ||
int b = UnityEngine.Random.Range(0, matureAnimals.Count-1); | ||
AnimalinFarm ab = matureAnimals[a]; | ||
matureAnimals.RemoveAt(b); | ||
float chancea = settings.BasePregnancyChance + (100 - settings.BasePregnancyChance) * ((aa.Age - aa.Data.StandardPoint) / aa.Data.StandardPoint); | ||
float chanceb = settings.BasePregnancyChance + (100 - settings.BasePregnancyChance) * ((ab.Age - ab.Data.StandardPoint) / ab.Data.StandardPoint); | ||
float chance = (chancea + chanceb) / 2f; | ||
Dbgl($"type: {idx} age: {aa.Age} {ab.Age} preg chance: {chance}"); | ||
if (UnityEngine.Random.Range(0, 100) <= chance) | ||
{ | ||
Dbgl($"birthing"); | ||
__instance.AddAnimal(idx, out tipsId); | ||
typeof(AnimalinFarm).GetField("age", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(aa, aa.Data.StandardPoint); | ||
typeof(AnimalinFarm).GetField("age", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(ab, ab.Data.StandardPoint); | ||
newAnimals[idx]++; | ||
} | ||
aifs[idx].Remove(aa); | ||
aifs[idx].Remove(ab); | ||
} | ||
} | ||
} | ||
foreach(KeyValuePair<int,int> kvp in newAnimals) | ||
{ | ||
if(kvp.Value > 0) | ||
{ | ||
string name = TextMgr.GetStr(AnimalData.GetDataByDataId(kvp.Key).NameId, -1); | ||
Dbgl($"sending tips ui"); | ||
Singleton<TipsMgr>.Instance.SendSystemTip($"A {name} gave birth!"); | ||
} | ||
} | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using UnityModManagerNet; | ||
|
||
namespace FarmAnimals | ||
{ | ||
public class Settings : UnityModManager.ModSettings | ||
{ | ||
public float AnimalGrowthSpeed { get; set; } = 1.0f; | ||
public float MaxAnimalGrowthPercent { get; set; } = 200.0f; | ||
public float BasePregnancyChance { get; set; } = 10.0f; | ||
|
||
public override void Save(UnityModManager.ModEntry modEntry) | ||
{ | ||
Save(this, modEntry); | ||
} | ||
} | ||
} |
Oops, something went wrong.