Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save EnterTheNameHere/3948279 to your computer and use it in GitHub Desktop.
Save EnterTheNameHere/3948279 to your computer and use it in GitHub Desktop.
Custom dilemma event for Zafehouse: Diaries
/*
* Created by SharpDevelop.
* User: EnterTheNameHere
* Date: 16.10. 2012
* Time: 16:48
*
*/
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Windows.Forms;
using Zafehouse2;
public class ZafehouseScript_Dilemma_BoobyTrap
{
private static SurvivorManager.Survivor m_SurvivorOnBoobyTrap = null;
private static SurvivorManager.Survivor m_SurvivorWhoTryToDisarmTrap = null;
private static LocationManager.Location m_Location = null;
private static bool m_SurvivorIsAthlete = false;
private static bool m_TrapIsFunctional = false;
private static bool m_SmallExplosion = false;
private static int m_SurvivorWhoTryToDisarmTrapAbility = 0;
private static bool m_MoreThanThreeSurvivorsInLocation = false;
private static bool SmallExplosion = true;
private static bool MediumExplosion = false;
private static bool ShouldDie = true;
public static List<string> Dilemma_BoobyTrap_Initialise( ref EventsManager.Dilemma dillema )
{
GameState.Globals["BoobyTrap_LastOccurrence", null] = GameManager.StartDate;
GameState.Globals["BoobyTrap_HoursCoolOff", null] = (double)GameManager.Random.Next( 24, 36 );
dillema.ValidGameModes.Add( GameManager.GameModes.Classic );
return new List<string>
{
"BoobyTrapAnswer1",
"BoobyTrapAnswer2",
"BoobyTrapAnswer3"
};
}
public static bool Dilemma_BoobyTrap_Conditions( ref EventsManager.Dilemma dillema )
{
TimeSpan timeSpan = GameManager.CurrentDate - (DateTime)GameState.Globals["BoobyTrap_LastOccurrence", null];
//* Comment out to start the dilemma immediately
if( timeSpan.TotalHours < ((double)GameState.Globals["BoobyTrap_HoursCoolOff"]) )
return false;
//*/
m_SurvivorOnBoobyTrap = null;
m_SurvivorWhoTryToDisarmTrap = null;
m_Location = null;
m_SurvivorIsAthlete = false;
m_TrapIsFunctional = false;
m_SmallExplosion = false;
m_MoreThanThreeSurvivorsInLocation = false;
// Check if any survivor is searching the location
foreach( SurvivorManager.Survivor survivor in GameState.Survivors.LivingSurvivors )
{
if( survivor != null
&& survivor.Location != null
&& survivor.AssignedToActiveTask == true
&& survivor.AssignedToTask.Name == "SearchRooms" )
{
if( survivor.Location.Survivors.Count > 1 )
{
m_SurvivorOnBoobyTrap = survivor;
m_Location = survivor.Location;
GameState.Globals["BoobyTrap_LastOccurrence", null] = GameManager.CurrentDate;
GameState.Globals["BoobyTrap_HoursCoolOff", null] = (double)GameManager.Random.Next( 24, 36 );
return true;
}
}
}
return false;
}
public static string Dilemma_BoobyTrap_ShortDescription( ref EventsManager.Dilemma dillema )
{
return "BoobyTrap";
}
public static string Dilemma_BoobyTrap_LongDescription( ref EventsManager.Dilemma dillema )
{
// Prepare variables shared in all answers
Random random = new Random();
// Is trap functional?
// for now, we roll for number between <0;100) and if it's lower than 50, explode
m_TrapIsFunctional = random.Next( 0, 100 ) < 50;
//m_TrapIsFunctional = true;
// Will the explosion be small, or big?
m_SmallExplosion = random.Next( 0, 100 ) < 50;
//m_SmallExplosion = false;
// Is survivor an athlete?
// HACK: Little hack here, we look if survivor is Athlete for now, till we
// find out how to check for stamina and condition of the survivor.
m_SurvivorIsAthlete = m_SurvivorOnBoobyTrap.Occupation.Name == "Athlete";
// Who will try to disarm?
SurvivorManager.SurvivorCollection survivorsOnPlace = new SurvivorManager.SurvivorCollection();
survivorsOnPlace.AddRange( m_Location.Survivors );
if( survivorsOnPlace.Contains( m_SurvivorOnBoobyTrap ) )
survivorsOnPlace.Remove( m_SurvivorOnBoobyTrap );
// HACK: Little hack, get the best survivor with Modify capability, before we
// know how to get best survivor based on custom parameters like guns and stamina etc.
survivorsOnPlace = survivorsOnPlace.SortBy( SurvivorManager.SurvivorCollection.SortMethods.Effectiveness, TaskManager.TaskDatabase["Modify"], SurvivorManager.SurvivorCollection.SortOrders.Descending );
m_SurvivorWhoTryToDisarmTrap = survivorsOnPlace[0];
// Survivors ability to disarm the trap
m_SurvivorWhoTryToDisarmTrapAbility = (int)( TaskManager.CalculateSurvivorEffectivenessForTask( TaskManager.TaskDatabase["Modify"], m_SurvivorWhoTryToDisarmTrap ) * 100 );
// Number of survivors in Location (used in text)
m_MoreThanThreeSurvivorsInLocation = ( m_Location.Survivors.Count > 2 );
string text = "While searching the location, {first_name} stepped on a booby trap somebody "
+ "planted in one of the rooms.\n\nWhat should we do?";
text = text.Replace( "{first_name}", m_SurvivorOnBoobyTrap.FirstName );
#if WANT_TO_DEBUG
text += "\nWho: " + m_SurvivorOnBoobyTrap.Name.ToString();
text += " Athlete: " + m_SurvivorIsAthlete.ToString();
text += "\nDisarm: " + m_SurvivorWhoTryToDisarmTrap.Name.ToString();
text += " Ability: " + m_SurvivorWhoTryToDisarmTrapAbility.ToString();
text += "\nFunctional: " + m_TrapIsFunctional.ToString();
text += " SmallExplosion: " + m_SmallExplosion.ToString();
text += "\nMoreThanThree: " + m_MoreThanThreeSurvivorsInLocation.ToString();
#endif
return text;
}
public static string Dilemma_BoobyTrap_OnClick( ref EventsManager.Dilemma dillema )
{
return null;
}
public static string Dilemma_BoobyTrapAnswer1_ShortDescription( ref EventsManager.Dilemma dillema )
{
string text = "Tell {0} that {1} should try to jump as far as {1} can.";
return string.Format( text, m_SurvivorOnBoobyTrap.FirstName, m_SurvivorOnBoobyTrap.HeShe().ToLower() );
}
public static string Dilemma_BoobyTrapAnswer1_OnClick( ref EventsManager.Dilemma dillema )
{
// If survivor is athlete, then as a bonus medium explosion "will be only small instead"
// If trap is functional, do explosion. Otherwise ok.
// TODO: think of a better way to give bonus than "medium" to "small explosion"
if( m_TrapIsFunctional )
{
if( m_SmallExplosion )
{
Helper_DoTheExplosion( SmallExplosion, m_Location );
Helper_CauseInjuriesFromExplosion( SmallExplosion, m_SurvivorOnBoobyTrap );
}
else
{
Helper_DoTheExplosion( MediumExplosion, m_Location );
// even Athlete can't get from big explosion easily
Helper_CauseInjuriesFromExplosion( MediumExplosion, m_SurvivorOnBoobyTrap );
}
if( m_SurvivorOnBoobyTrap.Dead )
HelperFunctions.AdjustRelationshipsOnDeath( m_Location.Survivors, m_SurvivorOnBoobyTrap );
string text = "While searching the location, {first_name} stepped on a booby "
+ "trap somebody planted in one of the rooms.\n\nWe thought jumping as far from the trap "
+ "as {he_she} can would be the best thing to do. We wished {him_her} luck and hid in "
+ "next room.\n\n"
+ ( m_SmallExplosion? "Small " : "Big " )
+ "explosion echoed through the building... We rushed to help {first_name}, ";
if( m_SurvivorOnBoobyTrap.Dead )
{
text += "but there was nothing we could do for {him_her}. We won't forget You...";
}
else
{
if( m_SurvivorIsAthlete && m_SmallExplosion )
text += "maybe that {he_she} is an Athlete helped {him_her} that ";
text += "{his_her} injuries are ";
if( m_SurvivorIsAthlete )
text += "only ";
text += Helper_GetAllInjuriesInString( m_SurvivorOnBoobyTrap ) + ". ";
text += ( m_SmallExplosion? "We're happy {he_she} is allright." : "Hopefully {he_she} will recover." );
}
text = text.Replace( "{first_name}", m_SurvivorOnBoobyTrap.FirstName );
text = text.Replace( "{he_she}", m_SurvivorOnBoobyTrap.HeShe().ToLower() );
text = text.Replace( "{him_her}", m_SurvivorOnBoobyTrap.HimHer().ToLower() );
text = text.Replace( "{his_her}", m_SurvivorOnBoobyTrap.HisHer().ToLower() );
Helper_AddStaticDiaryEntry( text, m_Location );
}
else
{
HelperFunctions.ApplyPositiveExperienceOnSurvivor( m_Location.Survivors, m_SurvivorOnBoobyTrap, 3.0f, null );
string text = "While searching the location, {first_name} stepped on a booby "
+ "trap somebody planted in one of the rooms.\n\nWe thought jumping as far from the trap "
+ "as {he_she} can would be the best thing to do. We wished {him_her} luck and hid in "
+ "next room.\n\nWe all were relived when {first_name} walked out of the room, telling us "
+ "it didn't explode. We all feel lucky today and we feel more close together.";
text = text.Replace( "{first_name}", m_SurvivorOnBoobyTrap.FirstName );
text = text.Replace( "{he_she}", m_SurvivorOnBoobyTrap.HeShe().ToLower() );
text = text.Replace( "{him_her}", m_SurvivorOnBoobyTrap.HimHer().ToLower() );
Helper_AddStaticDiaryEntry( text, m_Location );
}
return null;
}
public static string Dilemma_BoobyTrapAnswer2_ShortDescription( ref EventsManager.Dilemma dillema )
{
string text = "{0} should try to disarm the trap.";
return string.Format( text, m_SurvivorWhoTryToDisarmTrap.FirstName );
}
public static string Dilemma_BoobyTrapAnswer2_OnClick( ref EventsManager.Dilemma dillema )
{
// If trap is functional, see if can be disarmed. If not, do explosion. Otherwise ok.
// let's get the effectiveness of the survivor who is trying to and if random number
// will be greater, he/she wasn't successful...
// probably need to tweak that, if he/she would be too good
Random random = new Random();
if( random.Next( 150 ) < m_SurvivorWhoTryToDisarmTrapAbility
|| !m_TrapIsFunctional )
{
HelperFunctions.ApplyPositiveExperienceOnSurvivor( m_Location.Survivors, m_SurvivorWhoTryToDisarmTrap, 3.0f, null );
string text = "While searching the location, {survivor_first_name} stepped on a booby "
+ "trap somebody planted in one of the rooms.\n\n"
+ "{disarm_first_name} decided {disarm_he_she} will try to disarm the trap.\n\n"
+ ( m_MoreThanThreeSurvivorsInLocation? "We wished the two luck and hid in other room. " : "" )
+ "{disarm_first_name} observed the trap closely, took a deep breath and... "
+ "Disarmed the trap.\n\n{survivor_first_name} embraced {disarm_first_name}, the hero of the day.";
text = text.Replace( "{disarm_first_name}", m_SurvivorWhoTryToDisarmTrap.FirstName );
text = text.Replace( "{disarm_he_she}", m_SurvivorWhoTryToDisarmTrap.HeShe().ToLower() );
text = text.Replace( "{survivor_first_name}", m_SurvivorOnBoobyTrap.FirstName );
Helper_AddStaticDiaryEntry( text, m_Location );
}
else
{
if( m_SmallExplosion )
{
Helper_DoTheExplosion( SmallExplosion, m_Location );
Helper_CauseInjuriesFromExplosion( SmallExplosion, m_SurvivorOnBoobyTrap );
Helper_CauseInjuriesFromExplosion( SmallExplosion, m_SurvivorWhoTryToDisarmTrap );
}
else
{
Helper_DoTheExplosion( MediumExplosion, m_Location );
Helper_CauseInjuriesFromExplosion( MediumExplosion, m_SurvivorOnBoobyTrap );
Helper_CauseInjuriesFromExplosion( MediumExplosion, m_SurvivorWhoTryToDisarmTrap );
}
if( m_SurvivorOnBoobyTrap.Dead )
HelperFunctions.AdjustRelationshipsOnDeath( m_Location.Survivors, m_SurvivorOnBoobyTrap );
if( m_SurvivorWhoTryToDisarmTrap.Dead )
HelperFunctions.AdjustRelationshipsOnDeath( m_Location.Survivors, m_SurvivorWhoTryToDisarmTrap );
else
// we like the one who tried to disarm the trap for his heroism
HelperFunctions.ApplyPositiveExperienceOnSurvivor( m_Location.Survivors, m_SurvivorWhoTryToDisarmTrap );
string text = "While searching the location, {survivor_first_name} stepped on a booby "
+ "trap somebody planted in one of the rooms.\n\n"
+ "{disarm_first_name} decided {disarm_he_she} will try to disarm the trap.\n\n"
+ ( m_MoreThanThreeSurvivorsInLocation? "We wished the two luck and hid in other room. " : "" )
+ "{disarm_first_name} observed the trap closely, took a deep breath and... "
+ ( m_SmallExplosion? "Small explosion shook the building.\n\n" : "Big explosion shook the building.\n\n" )
+ "{disarm_first_name} efforts ";
if( m_SurvivorWhoTryToDisarmTrap.Dead )
{
text += "cost {disarm_him_her} {disarm_his_her} life.\n";
}
else
{
text += "caused {disarm_him_her} "
+ Helper_GetAllInjuriesInString( m_SurvivorWhoTryToDisarmTrap ) + ".\n";
}
if( m_SurvivorOnBoobyTrap.Dead )
{
text += "Unfortunately {disarm_his_her} effort didn't save {survivor_first_name}. ";
}
else
{
text += "However {survivor_first_name} is alive, but with "
+ Helper_GetAllInjuriesInString( m_SurvivorOnBoobyTrap ) + ". ";
}
if( m_SurvivorOnBoobyTrap.Dead && m_SurvivorWhoTryToDisarmTrap.Dead )
{
text += "We will miss them.";
}
else if( m_SurvivorOnBoobyTrap.Dead )
{
text += "We will miss {survivor_first_name}.";
}
else if( m_SurvivorWhoTryToDisarmTrap.Dead )
{
text += "We will miss {disarm_first_name}.";
}
text = text.Replace( "{survivor_first_name}", m_SurvivorOnBoobyTrap.FirstName );
text = text.Replace( "{disarm_first_name}", m_SurvivorWhoTryToDisarmTrap.FirstName );
text = text.Replace( "{disarm_he_she}", m_SurvivorWhoTryToDisarmTrap.HeShe().ToLower() );
text = text.Replace( "{disarm_him_her}", m_SurvivorWhoTryToDisarmTrap.HimHer().ToLower() );
text = text.Replace( "{disarm_his_her}", m_SurvivorWhoTryToDisarmTrap.HisHer().ToLower() );
Helper_AddStaticDiaryEntry( text, m_Location );
}
return null;
}
public static string Dilemma_BoobyTrapAnswer3_ShortDescription( ref EventsManager.Dilemma dillema )
{
return "Put some objects around the booby trap and pray it will weaken the explosion.";
}
public static string Dilemma_BoobyTrapAnswer3_OnClick( ref EventsManager.Dilemma dillema )
{
// If trap is functional, kill survivor, otherwise ok
if( m_TrapIsFunctional )
{
// Do the Explosion
Helper_DoTheExplosion( MediumExplosion, m_Location );
Helper_CauseInjuriesFromExplosion( MediumExplosion, m_SurvivorOnBoobyTrap, ShouldDie );
HelperFunctions.AdjustRelationshipsOnDeath( m_Location.Survivors, m_SurvivorOnBoobyTrap );
string text = "While searching the location, {first_name} stepped on a booby "
+ "trap somebody planted in one of the rooms.\n\n"
+ "We put objects around the booby trap, "
+ "hoping it will weaken the explosion, but we couldn't be "
+ "more wrong.\n\nExlosion wasn't so big, but it seems the objects "
+ "we put around the booby trap made the explosion more lethal. "
+ "At least {first_name} died fast, hopefully without any pain. "
+ "We will miss {him_her}.";
text = text.Replace( "{first_name}", m_SurvivorOnBoobyTrap.FirstName );
text = text.Replace( "{him_her}", m_SurvivorOnBoobyTrap.HimHer().ToLower() );
Helper_AddStaticDiaryEntry( text, m_Location );
}
else
{
HelperFunctions.ApplyPositiveExperienceOnSurvivor( m_Location.Survivors, m_SurvivorOnBoobyTrap, 3.0f, null );
string text = "While searching the location, {first_name} stepped on a booby "
+ "trap somebody planted in one of the rooms.\n\n"
+ "We put objects around the booby trap, "
+ "hoping it will weaken the explosion. We wished {first_name} "
+ "luck and hid in the next room.\n\nWhile awaiting explosion we "
+ "all were surprised when {first_name} run through doors happily "
+ "yelling \"It didn't explode!\".\n\nWe all hugged and everyone is "
+ "feeling more close now.";
text = text.Replace( "{first_name}", m_SurvivorOnBoobyTrap.FirstName );
Helper_AddStaticDiaryEntry( text, m_Location );
}
return null;
}
public static void Helper_CauseInjuriesFromExplosion( bool smallExplosion, SurvivorManager.Survivor survivor )
{
Helper_CauseInjuriesFromExplosion( smallExplosion, survivor, false );
}
public static void Helper_CauseInjuriesFromExplosion( bool smallExplosion, SurvivorManager.Survivor survivor, bool shouldBeFatal )
{
// To add some randomness to the left/right hand/leg injuries
Random random = new Random();
string injuryName = "";
if( !smallExplosion )
{
injuryName = "Broken ";
injuryName += ( random.Next(2) > 0 ? "left " : "right " );
injuryName += ( random.Next(2) > 0 ? "leg" : "ankle" );
survivor.Inflict( SurvivorManager.InjuryDatabase[injuryName], false );
injuryName = "Broken ";
injuryName += ( random.Next(2) > 0 ? "left " : "right " );
injuryName += ( random.Next(2) > 0 ? "leg" : "hand" );
survivor.Inflict( SurvivorManager.InjuryDatabase[injuryName], false );
}
injuryName = "Lacerations";
survivor.Inflict( SurvivorManager.InjuryDatabase[injuryName], false );
injuryName = "Contusions";
survivor.Inflict( SurvivorManager.InjuryDatabase[injuryName], false );
if( shouldBeFatal )
survivor.Kill();
}
public static void Helper_DoTheExplosion( bool smallExplosion, LocationManager.Location location )
{
if( smallExplosion )
m_Location.MakeNoise( MapManager.Loudness.Low );
else
m_Location.MakeNoise( MapManager.Loudness.Medium );
}
public static void Helper_AddStaticDiaryEntry( string text, LocationManager.Location location )
{
DiaryManager.AddEntry( new DiaryManager.StaticDiaryEntry( text, location, DiaryManager.DiaryEntry.DiaryEntryPriorities.AlwaysLast ) );
}
public static string Helper_GetAllInjuriesInString( SurvivorManager.Survivor survivor )
{
string text = "";
List<SurvivorManager.Injury> injuries = survivor.GetInjuriesOrderedByMagnitude(true);
for( int i = injuries.Count - 1; i >= 0; --i )
{
text += injuries[i].Description.TrimEnd('.').ToLower();
if( i > 1 )
text += ", ";
else if( i == 1 )
text += " and ";
}
return text;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment