summaryrefslogtreecommitdiff
path: root/lib/mods/theme/core/player.lua
blob: e194b45ac0aabf90c5078882b667787da45d4ce3 (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
-- SYSTEM FILE
--
-- Lua player funtions
--

-- Gods
function deity(i)
	return deity_info[1 + i]
end

-------- skill stuff ---------

-- Easy skill access
function skill(i)
	return s_info[i + 1]
end

-- Sart a lasting spell
function player.start_lasting_spell(spl)
	player.music_extra = -spl
end

-- stat mods
function player.modify_stat(stat, inc)
	player.stat_add[1 + stat] = player.stat_add[1 + stat] + inc
end

-- powers mods
function player.add_power(pow)
	player.powers[1 + pow] = TRUE
end

-- easier inventory access
function player.inventory(i)
	return player.inventory_real[i + 1]
end

-- modify mana
-- returns TRUE if there is a pb
function increase_mana(amt)
	player.csp = player.csp + amt
	player.redraw = bor(player.redraw, PR_MANA)
	if (player.csp < 0) then
		player.csp = 0
		return TRUE
	end
	if (player.csp > player.msp) then
		player.csp = player.msp
	end
	return FALSE
end


-- Return the coordinates of the player whether in wild or not
function player.get_wild_coord()
	if player.wild_mode == TRUE then
		return player.py, player.px
	else
		return player.wilderness_y, player.wilderness_x
	end
end


--- Mkeys

-- Create a new power
__mkey_fct = {}
function add_mkey(p)
	local i

	assert(p.mkey, "No mkey mkey!")
	assert(p.fct, "No mkeey fct!")

	__mkey_fct[p.mkey] = p.fct
end

function __mkey_fct_activate(power)
	if __mkey_fct[power] then
		__mkey_fct[power]()
		return TRUE
	else
		return FALSE
	end
end

-- Register in the hook list
add_hook_script(HOOK_MKEY, "__mkey_fct_activate", "__mkey_fct_activate")


-- Subraces
function subrace(racem)
	return race_mod_info[racem + 1]
end