aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/Score.cpp
blob: 039939b14749f4b3f8428b69a8c58e99a9ccd4e0 (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
#include "stdafx.h"
#include "net.minecraft.world.scores.h"
#include "net.minecraft.world.scores.criteria.h"
#include "Score.h"

Score::Score(Scoreboard *scoreboard, Objective *objective, const wstring &owner)
{
	this->scoreboard = scoreboard;
	this->objective = objective;
	this->owner = owner;
	count = 0;
}

void Score::add(int count)
{
	//if (objective.getCriteria().isReadOnly()) throw new IllegalStateException("Cannot modify read-only score");
	setScore(getScore() + count);
}

void Score::remove(int count)
{
	//if (objective.getCriteria().isReadOnly()) throw new IllegalStateException("Cannot modify read-only score");
	setScore(getScore() - count);
}

void Score::increment()
{
	//if (objective.getCriteria().isReadOnly()) throw new IllegalStateException("Cannot modify read-only score");
	add(1);
}

void Score::decrement()
{
	//if (objective.getCriteria().isReadOnly()) throw new IllegalStateException("Cannot modify read-only score");
	remove(1);
}

int Score::getScore()
{
	return count;
}

void Score::setScore(int score)
{
	int old = count;
	count = score;
	if (old != score) getScoreboard()->onScoreChanged(this);
}

Objective *Score::getObjective()
{
	return objective;
}

wstring Score::getOwner()
{
	return owner;
}

Scoreboard *Score::getScoreboard()
{
	return scoreboard;
}

void Score::updateFor(vector<shared_ptr<Player> > *players)
{
	setScore(objective->getCriteria()->getScoreModifier(players));
}