the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include <string>
3#include <unordered_map>
4#include "..\..\Minecraft.h"
5#include "..\..\MultiplayerLocalPlayer.h"
6#include "Tutorial.h"
7#include "TutorialConstraints.h"
8#include "ChoiceTask.h"
9#include "..\..\..\Minecraft.World\Material.h"
10#include "..\..\Windows64\KeyboardMouseInput.h"
11
12ChoiceTask::ChoiceTask(Tutorial *tutorial, int descriptionId, int promptId /*= -1*/, bool requiresUserInput /*= false*/,
13 int iConfirmMapping /*= 0*/, int iCancelMapping /*= 0*/,
14 eTutorial_CompletionAction cancelAction /*= e_Tutorial_Completion_None*/, ETelemetryChallenges telemetryEvent /*= eTelemetryTutorial_NoEvent*/)
15 : TutorialTask( tutorial, descriptionId, false, NULL, true, false, false )
16{
17 if(requiresUserInput == true)
18 {
19 constraints.push_back( new InputConstraint( iConfirmMapping ) );
20 constraints.push_back( new InputConstraint( iCancelMapping ) );
21 }
22 m_iConfirmMapping = iConfirmMapping;
23 m_iCancelMapping = iCancelMapping;
24 m_bConfirmMappingComplete = false;
25 m_bCancelMappingComplete = false;
26
27 m_cancelAction = cancelAction;
28
29 m_promptId = promptId;
30 tutorial->addMessage( m_promptId );
31
32 m_eTelemetryEvent = telemetryEvent;
33}
34
35bool ChoiceTask::isCompleted()
36{
37 Minecraft* pMinecraft = Minecraft::GetInstance();
38 if (!pMinecraft || !pMinecraft->player)
39 return false;
40
41 int xboxPad = pMinecraft->player->GetXboxPad();
42
43 if( m_bConfirmMappingComplete || m_bCancelMappingComplete )
44 {
45 sendTelemetry();
46 enableConstraints(false, true);
47 return true;
48 }
49
50 if(ui.GetMenuDisplayed(tutorial->getPad()))
51 {
52 // If a menu is displayed, then we use the handleUIInput to complete the task
53 }
54 else
55 {
56 // If the player is under water then allow all keypresses so they can jump out
57 if (pMinecraft->localplayers[tutorial->getPad()]->isUnderLiquid(Material::water)) return false;
58#ifdef _WINDOWS64
59 if (!m_bConfirmMappingComplete &&
60 (InputManager.GetValue(xboxPad, m_iConfirmMapping) > 0
61 || KMInput.IsKeyDown(VK_RETURN)))
62#else
63 if (!m_bConfirmMappingComplete &&
64 InputManager.GetValue(xboxPad, m_iConfirmMapping) > 0)
65#endif
66 {
67 m_bConfirmMappingComplete = true;
68 }
69
70#ifdef _WINDOWS64
71 if (!m_bCancelMappingComplete &&
72 (InputManager.GetValue(xboxPad, m_iCancelMapping) > 0
73 || KMInput.IsKeyDown('B')))
74#else
75 if (!m_bCancelMappingComplete &&
76 InputManager.GetValue(xboxPad, m_iCancelMapping) > 0)
77#endif
78 {
79 m_bCancelMappingComplete = true;
80 }
81
82 if (m_bConfirmMappingComplete || m_bCancelMappingComplete)
83 {
84 sendTelemetry();
85 enableConstraints(false, true);
86 }
87 return m_bConfirmMappingComplete || m_bCancelMappingComplete;
88 }
89}
90
91eTutorial_CompletionAction ChoiceTask::getCompletionAction()
92{
93 if(m_bCancelMappingComplete)
94 {
95 return m_cancelAction;
96 }
97 else
98 {
99 return e_Tutorial_Completion_None;
100 }
101}
102
103int ChoiceTask::getPromptId()
104{
105 if( m_bShownForMinimumTime )
106 return m_promptId;
107 else
108 return -1;
109}
110
111void ChoiceTask::setAsCurrentTask(bool active /*= true*/)
112{
113 enableConstraints( active );
114 TutorialTask::setAsCurrentTask(active);
115}
116
117void ChoiceTask::handleUIInput(int iAction)
118{
119 if(bHasBeenActivated && m_bShownForMinimumTime)
120 {
121 if( iAction == m_iConfirmMapping)
122 {
123 m_bConfirmMappingComplete = true;
124 }
125 else if(iAction == m_iCancelMapping)
126 {
127 m_bCancelMappingComplete = true;
128 }
129 }
130}
131
132void ChoiceTask::sendTelemetry()
133{
134 Minecraft *pMinecraft = Minecraft::GetInstance();
135
136 if( m_eTelemetryEvent != eTelemetryChallenges_Unknown )
137 {
138 bool firstPlay = true;
139 // We only store first play for some of the events
140 switch(m_eTelemetryEvent)
141 {
142 case eTelemetryTutorial_TrialStart:
143 firstPlay = !tutorial->getCompleted( eTutorial_Telemetry_TrialStart );
144 tutorial->setCompleted( eTutorial_Telemetry_TrialStart );
145 break;
146 case eTelemetryTutorial_Halfway:
147 firstPlay = !tutorial->getCompleted( eTutorial_Telemetry_Halfway );
148 tutorial->setCompleted( eTutorial_Telemetry_Halfway );
149 break;
150 };
151
152 TelemetryManager->RecordEnemyKilledOrOvercome(pMinecraft->player->GetXboxPad(), 0, 0, 0, 0, 0, 0, m_eTelemetryEvent);
153 }
154}