aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Common/Tutorial/TutorialMode.cpp
blob: 82c81598f2e2803a81e5d79ec6d193abef10160d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "stdafx.h"
#include <memory>
#include "..\..\Minecraft.h"
#include "..\..\MultiplayerLocalPlayer.h"
#include "..\..\MultiPlayerLevel.h"
#include "..\..\..\Minecraft.World\Inventory.h"
#include "..\..\..\Minecraft.World\net.minecraft.world.item.h"
#include "..\..\..\Minecraft.World\net.minecraft.world.level.h"
#include "..\..\..\Minecraft.World\net.minecraft.world.level.tile.h"
#include "TutorialMode.h"

TutorialMode::TutorialMode(int iPad, Minecraft *minecraft, ClientConnection *connection) : MultiPlayerGameMode( minecraft, connection ), m_iPad( iPad )
{
}

TutorialMode::~TutorialMode()
{
	if(tutorial != NULL)
		delete tutorial;
}

void TutorialMode::startDestroyBlock(int x, int y, int z, int face)
{
	if(!tutorial->m_allTutorialsComplete)
	{
		int t = minecraft->level->getTile(x, y, z);
		tutorial->startDestroyBlock(minecraft->player->inventory->getSelected(), Tile::tiles[t]);
	}
	MultiPlayerGameMode::startDestroyBlock( x, y, z, face );
}

bool TutorialMode::destroyBlock(int x, int y, int z, int face)
{
	if(!tutorial->m_allTutorialsComplete)
	{
		int t = minecraft->level->getTile(x, y, z);
		tutorial->destroyBlock(Tile::tiles[t]);
	}
	shared_ptr<ItemInstance> item = minecraft->player->getSelectedItem();
	int damageBefore;
	if(item != NULL)
	{
		damageBefore = item->getDamageValue();
	}
	bool changed = MultiPlayerGameMode::destroyBlock( x, y, z, face );

	if(!tutorial->m_allTutorialsComplete)
	{
		if ( item != NULL && item->isDamageableItem() )
		{		
			int max = item->getMaxDamage();
			int damageNow = item->getDamageValue();

			if(damageNow > damageBefore && damageNow > (max/2) )
			{
				tutorial->itemDamaged( item );
			}
		}
	}

	return changed;
}

void TutorialMode::tick()
{
	MultiPlayerGameMode::tick();

	if(!tutorial->m_allTutorialsComplete)
		tutorial->tick();

	/*
	if( tutorial.m_allTutorialsComplete && (tutorial.lastMessageTime + m_iTutorialDisplayMessageTime) < GetTickCount() )
	{
		// Exit tutorial
		minecraft->gameMode = new SurvivalMode( this );
		delete this;
	}
	*/
}

bool TutorialMode::useItemOn(shared_ptr<Player> player, Level *level, shared_ptr<ItemInstance> item, int x, int y, int z, int face, Vec3 *hit, bool bTestUseOnly, bool *pbUsedItem)
{
	bool haveItem = false;
	int itemCount = 0;
	if(!tutorial->m_allTutorialsComplete)
	{
		tutorial->useItemOn(level, item, x, y, z, bTestUseOnly);

		if(!bTestUseOnly)
		{	
			if(item != NULL)
			{
				haveItem = true;
				itemCount = item->count;
			}
		}
	}
	bool result = MultiPlayerGameMode::useItemOn( player, level, item, x, y, z, face, hit, bTestUseOnly, pbUsedItem );

	if(!bTestUseOnly)
	{
		if(!tutorial->m_allTutorialsComplete)
		{
			if( result && haveItem && itemCount > item->count )
			{
				tutorial->useItemOn(item);
			}
		}
	}
	return result;
}

void TutorialMode::attack(shared_ptr<Player> player, shared_ptr<Entity> entity)
{
	if(!tutorial->m_allTutorialsComplete)
		tutorial->attack(player, entity);

	MultiPlayerGameMode::attack( player, entity );
}

bool TutorialMode::isInputAllowed(int mapping)
{
	return tutorial->m_allTutorialsComplete || tutorial->isInputAllowed( mapping );
}