Created
October 28, 2012 19:13
-
-
Save EnterTheNameHere/3969523 to your computer and use it in GitHub Desktop.
Custom task for Zafehouse: Diaries
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
/* | |
* Created by SharpDevelop. | |
* User: EnterTheNameHere | |
* Date: 25.10. 2012 | |
* Time: 15:53 | |
* | |
*/ | |
using System; | |
using System.Collections.Generic; | |
using System.Windows.Forms; | |
using Zafehouse2; | |
using RIASECPriority = Zafehouse2.SurvivorManager.SurvivorPersonality.RIASECPriority; | |
public class ZafehouseScript_Task_BuryDeadSurvivor | |
{ | |
private static TaskTracker m_Tracker = null; | |
private static string m_TrackerKeySurvivorBuried = "SurvivorsBuried"; | |
private static string[] m_InitialTrackerVariables = new string[] | |
{ | |
m_TrackerKeySurvivorBuried | |
}; | |
// REQUIRED METHOD | |
// Setup the task. | |
// Called only once on the start of the game. | |
public static void Task_BuryDeadSurvivor_Initialise( ref int tickInterval, ref SurvivorManager.SurvivorPersonality personalityRequirements, ref SurvivorManager.Survivor.SurvivorStatistics statisticsRequirements, ref bool isIdleTask, ref Dictionary<string, object> extraParameters ) | |
{ | |
// How often do You want to "fire" DoSimulationTick() event, in minutes | |
// 60 = once per hour (turn) | |
// 30 = twice per hour (turn) | |
// 60 = 60 times per hour (turn) | |
tickInterval = 60; | |
// The ideal personality for a person to do this task => having most possible stars | |
// RIASEC = realistic, investigative, artistic, social, enterprising, conventional | |
personalityRequirements | |
= new SurvivorManager.SurvivorPersonality( | |
// const. params | |
RIASECPriority.High, | |
RIASECPriority.None, | |
RIASECPriority.None, | |
RIASECPriority.Medium, | |
RIASECPriority.None, | |
RIASECPriority.Medium | |
); | |
// The ideal statistics for a person to do this task (vigour, acumen, wits, grit) | |
statisticsRequirements = new SurvivorManager.Survivor.SurvivorStatistics( 1, 0, 0, 2, null ); | |
// Idle task - survivor do this when You don't set a task to do for him/her, like drink, play chess | |
// Active task - You have to assign this task to the survivor Yourself, like watch for zombie | |
// or send survivor on investigation | |
isIdleTask = false; | |
// You can set additional Task properties as extraParameters ( "propertyName", it's value ) | |
// Used when reporting what survivors are doing, like: | |
// "John and Jane are getting better after they were burying dead survivor." | |
extraParameters.Add( "Gerund", "Burying dead survivors" ); | |
// Shown in tooltip when hovering above "disabled" task | |
extraParameters.Add( "ConditionsText", "Requires dead survivor." ); | |
// How much energy the task drains | |
extraParameters.Add( "ExertionLevel", SurvivorManager.Survivor.ExertionLevels.Moderate ); | |
#if WANT_TO_DEBUG | |
MessageBox.Show( "BuryDeadSurvivor task initialised." ); | |
#endif | |
} | |
// REQUIRED METHOD | |
// Return true, if task can be performed, or false. | |
// (Barricading can be done only if there are barricading items.) | |
// (Meal can be done only if there are enough ingredients etc.) | |
// If false, task is "disabled" on the selection screen. | |
public static bool Task_BuryDeadSurvivor_Conditions( ref TaskManager.Task task ) | |
{ | |
// Safety check | |
if( task == null || task.Location == null || task.Location.DeadSurvivors == null ) | |
return false; | |
m_Tracker = Trackers.GetTaskTracker( task ); | |
// Safety check | |
if( m_Tracker == null ) | |
return false; | |
for( int i = 0; i < m_InitialTrackerVariables.Length; i++ ) | |
{ | |
m_Tracker.IncrementTaskVariable( m_InitialTrackerVariables[i], 0 ); | |
} | |
bool returnValue = task.Location.DeadSurvivors.Count > 0; | |
// | |
// // kill someone for testing | |
// if( task.Location.Survivors.Count > 3 && task.Location.DeadSurvivors.Count == 0 ) | |
// { | |
// task.Location.Survivors[0].Kill(); | |
// task.Location.Survivors[1].Kill(); | |
// task.Location.Survivors[2].Kill(); | |
// } | |
// | |
return returnValue; | |
} | |
// REQUIRED METHOD | |
// Return the task text like "Clean corpses" or "Modify items" You can | |
// click on the task selection screen to assign a task to survivor. | |
public static string Task_BuryDeadSurvivor_Status( ref TaskManager.Task task ) | |
{ | |
// Safety checks | |
if( task == null || task.Location == null || task.Location.DeadSurvivors == null ) | |
return ""; | |
// We're creating "Bury {name}." or "No dead survivors to bury." | |
string text = ""; | |
if( task.Location.DeadSurvivors.Count > 0 ) | |
{ | |
text += "Bury "; | |
for( int i = task.Location.DeadSurvivors.Count - 1; i >= 0; i-- ) | |
{ | |
text += task.Location.DeadSurvivors[i].FirstName; | |
if( i > 1 ) | |
{ | |
text += ", "; | |
} | |
else if( i == 1 ) | |
{ | |
text += " and "; | |
} | |
} | |
text += "."; | |
} | |
else | |
{ | |
text += "No dead survivors to bury."; | |
} | |
return text; | |
} | |
// REQUIRED METHOD | |
// Fired on the end of turn | |
// Can be used to display progress, relationship changes... | |
public static void Task_BuryDeadSurvivor_OnTurnTick( ref TaskManager.Task task ) | |
{ | |
// Safety checks | |
if( task == null || task.Location == null ) | |
return; | |
EntryBuilder entryBuiler = new EntryBuilder( task.Location ); | |
entryBuiler.AddString( TaskRelationshipReporter.GetRelationshipChangesSinceLastTurn( task ) ); | |
entryBuiler.WriteToDiary(); | |
} | |
// REQUIRED METHOD | |
// Fired based on tickInterval, see task Initialise method | |
// Do Your task work here | |
public static bool Task_BuryDeadSurvivor_OnSimulationTick( ref TaskManager.Task task ) | |
{ | |
// Safety checks | |
if( task == null | |
|| task.AssignedSurvivors == null | |
|| task.Location == null | |
|| task.Location.DeadSurvivors == null ) | |
{ | |
return false; | |
} | |
Random random = new Random(); | |
foreach( SurvivorManager.Survivor graveDiggerSurvivor in task.AssignedSurvivors ) | |
{ | |
if( task.Location.DeadSurvivors != null && task.Location.DeadSurvivors.Count > 0 ) | |
{ | |
TaskCalculator taskCalculator = new TaskCalculator( task, 25.0f, 95.0f, 1.0f ); | |
taskCalculator.AddSurvivorEffectivenessBonus( graveDiggerSurvivor, 0.0f ); | |
taskCalculator.AddRelationshipPenalty( 0.5f ); | |
// If there is negative experience between survivors during digging, don't "finish" the job | |
if( taskCalculator.RollAndAdjustRelationshipsOnSurvivor( graveDiggerSurvivor, -1.0f, -1.0f ) ) | |
{ | |
SurvivorManager.Survivor deadSurvivor = task.Location.DeadSurvivors[0]; | |
// Add a diary entry | |
List<string> lines = new List<string> | |
{ | |
"To show respect, {gravedigger_first_name} buried {dead_first_name}. Rest in peace, {dead_first_name}.", | |
"We buried {dead_first_name} today.", | |
"At burial of {dead_first_name} we come to realise how much we have already lost.", | |
"We buried {dead_first_name}'s lucky paw with {him_her}. Maybe {he_she} will have more luck in {his_her} afterlife.", | |
"We put a little cross to resemble the {dead_first_name}'s resting place.", | |
"{gravedigger_first_name} carried out {dead_first_name}'s last wish to be buried under {his_her} favourite tree.", | |
}; | |
string text = lines[random.Next( 0, lines.Count )]; | |
text = text.Replace( "{dead_first_name}", deadSurvivor.FirstName ); | |
text = text.Replace( "{he_she}", deadSurvivor.HeShe().ToLower() ); | |
text = text.Replace( "{his_her}", deadSurvivor.HisHer().ToLower() ); | |
text = text.Replace( "{him_her}", deadSurvivor.HimHer().ToLower() ); | |
text = text.Replace( "{gravedigger_first_name}", graveDiggerSurvivor.FirstName ); | |
EntryBuilder entryBuilder = new EntryBuilder( task.Location ); | |
entryBuilder.AddString( text ); | |
entryBuilder.WriteToDiary(); | |
task.Location.DeadSurvivors.Remove( deadSurvivor ); | |
m_Tracker.IncrementTaskVariable( m_TrackerKeySurvivorBuried, 1 ); | |
} | |
} | |
} | |
if( task.Location.DeadSurvivors.Count == 0 ) | |
{ | |
EntryBuilder entryBuilder = new EntryBuilder( task.Location ); | |
entryBuilder.AddString( "All dead survivors were buried." ); | |
entryBuilder.WriteToDiary(); | |
task.AssignedSurvivors.Clear(); | |
} | |
return false; | |
} | |
// REQUIRED METHOD | |
// Fired everytime task is started by some survivor. | |
// (when nobody was assigned on the task last turn, no "resume") | |
// (also no "resume", it will be fired even if some survivor | |
// was doing the task in past and You just assigned someone to continue) | |
public static void Task_BuryDeadSurvivor_OnFirstRun( ref TaskManager.Task task ) | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment