Skip to content

Commit

Permalink
Add helper class for handling the child's behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
kabili207 committed Jan 9, 2019
1 parent 3cc0d48 commit 10e1b7d
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 2 deletions.
76 changes: 76 additions & 0 deletions src/ChildBehaviorHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Zyrenth.Zora
{
/// <summary>
/// Various helper functions for use with the child's behavior
/// </summary>
public static class ChildBehaviorHelper
{
/// <summary>
/// Gets the value of the child's behavior based on reponses to questions asked
/// </summary>
/// <param name="name">The name of the child</param>
/// <param name="region">The region of the game</param>
/// <returns></returns>
public static byte GetValue(string name, GameRegion region)
{
Encoding encoding = region.GetEncoding();
byte[] bytes = encoding.GetBytes(name);
int value = 0;

foreach (byte a in bytes)
{
value += ( a & 0xF );
}

do { value -= 3; } while (value > -1);
return (byte)( value + 4 );
}


/// <summary>
/// Gets the value of the child's behavior based on reponses to questions asked
/// </summary>
/// <param name="name">The name of the child</param>
/// <param name="region">The region of the game</param>
/// <param name="rupeesGiven">The number of rupees given</param>
/// <param name="sleepMethod">The method used to help the child sleep</param>
/// <returns></returns>
public static byte GetValue(string name, GameRegion region, RupeesGiven rupeesGiven, SleepMethod sleepMethod)
{
return (byte)( GetValue(name, region) + (int)rupeesGiven + (int)sleepMethod );
}

/// <summary>
/// Gets the value of the child's behavior based on reponses to questions asked
/// </summary>
/// <param name="name">The name of the child</param>
/// <param name="region">The region of the game</param>
/// <param name="rupeesGiven">The number of rupees given</param>
/// <param name="sleepMethod">The method used to help the child sleep</param>
/// <param name="childsQuestion">The response to the child's question</param>
/// <param name="kindOfChild">Kind of child the player was</param>
/// <returns></returns>
public static byte GetValue(string name, GameRegion region, RupeesGiven rupeesGiven, SleepMethod sleepMethod, ChildQuestion childsQuestion, KindOfChild kindOfChild)
{
return (byte)( GetValue(name, region, rupeesGiven, sleepMethod) + (int)childsQuestion + (int)kindOfChild);
}

/// <summary>
/// Gets the child's behavior based on the byte value supplied
/// </summary>
/// <param name="value">The raw behavior value</param>
/// <returns></returns>
public static ChildBehavior GetPersonality(byte value)
{
if (value == 0) return ChildBehavior.None;
if (value < 6) return ChildBehavior.Curious;
if (value < 11) return ChildBehavior.Shy;
return ChildBehavior.Hyperactive;
}
}
}
69 changes: 69 additions & 0 deletions src/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,73 @@ public enum Rings : long
[RingInfo("Protection Ring", "Damage taken is always one Heart")]
ProtectionRing = unchecked((long)0x8000000000000000L)
}

/// <summary>
/// The calculated behavior of the child
/// </summary>
public enum ChildBehavior
{
None,
Curious,
Shy,
Hyperactive
}

/// <summary>
/// The number of rupees given to Blossom
/// </summary>
public enum RupeesGiven
{
/// <summary>
/// 1 Rupee
/// </summary>
_1 = 0,
/// <summary>
/// 10 Rupees
/// </summary>
_10 = 2,
/// <summary>
/// 50 Rupees
/// </summary>
_50 = 5,
/// <summary>
/// 150 Rupees
/// </summary>
_150 = 8
}

/// <summary>
/// How Blossom should help the child go to sleep
/// </summary>
public enum SleepMethod
{
Sing = 0,
Play = 10,
}

/// <summary>
/// Response to question about what kind of child the player was
/// </summary>
public enum KindOfChild
{
None = 0,
Weird = 1,
Quiet = 5,
Hyperactive = 8,
}

/// <summary>
/// Response to the child's question
/// </summary>
public enum ChildQuestion
{
/// <summary>
/// Either No or Egg, depending on the question asked
/// </summary>
NoOrEgg = 0,
/// <summary>
/// Either Yes or Chicken, depending on the question asked
/// </summary>
YesOrChicken = 4,
}
}
16 changes: 16 additions & 0 deletions src/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,21 @@ internal static string ReversedSubstring(this string value, int start, int lengt
return val;
}

/// <summary>
/// Gets the <seealso cref="System.Text.Encoding"/> associated with the specified <paramref name="region"/>
/// </summary>
/// <param name="region">The region of the game</param>
/// <returns></returns>
public static Encoding GetEncoding(this GameRegion region)
{
if (region == GameRegion.US)
{
return new USEncoding();
}
else
{
return new JapaneseEncoding();
}
}
}
}
5 changes: 3 additions & 2 deletions src/ZoraSharp.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -52,6 +52,7 @@
<Compile Include="USEncoding.cs" />
<Compile Include="InvalidChecksumException.cs" />
<Compile Include="UnknownMemoryException.cs" />
<Compile Include="ChildBehaviorHelper.cs" />
</ItemGroup>
<!-- Allow projects to override or extend project configuration -->
<Import Project="$(SolutionDir)Extra.targets" Condition="exists('$(SolutionDir)Extra.targets')" />
Expand All @@ -65,4 +66,4 @@
</Properties>
</MonoDevelop>
</ProjectExtensions>
</Project>
</Project>

0 comments on commit 10e1b7d

Please sign in to comment.