-
Notifications
You must be signed in to change notification settings - Fork 1
/
Skill.lua
151 lines (128 loc) · 4.43 KB
/
Skill.lua
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
-- Skill
Skill = Class:extend
{
-- required
id = nil,
-- Character
character = nil,
-- ---------------
-- see action_definitions.lua
definition = nil,
iconColor = nil,
nr = 0,
timeout = 0,
combatTimer = 10,
lastUsed = -100000,
-- here starts the effect/application
source = {
x = 0,
y = 0,
viewx = 0,
viewy = 0,
player = nil,
},
isCasting = function (self)
return love.timer.getTime() - self.lastUsed < self.cast_time
end,
isPossibleToUse = function (self)
return self.character.freezeCastingCounter <= 0 and
love.timer.getTime() - self.lastUsed >= self.timeout and
self.character.currentEnergy >= self.energyCosts
end,
timeTillCastFinished = function (self)
return math.max(0, self.lastUsed + self.cast_time - love.timer.getTime())
end,
timeTillPossibleToUse = function (self)
return math.max(0, self.lastUsed + self.timeout - love.timer.getTime())
end,
use = function (self, x, y, viewx, viewy, player)
if self:freezeMovementDuringCasting() then player:freezeMovement() end
--print("SKILL", self.nr, "START USING")
player.interrupted = false
self.source.x = x
self.source.y = y
-- read input can overwrite view later
self.source.viewx = viewx
self.source.viewy = viewy
self.source.player = player
self.lastUsed = love.timer.getTime()
-- start particle
--~ local p = the.app.view.factory:create(Particles, {
--~ duration = self.cast_time,
--~ attached_to_object = player,
--~ particle_color = self.definition.cast_particle_color or {255,255,255}
--~ })
local castTime = self.cast_time
local colour = self.definition.cast_particle_color or {128,128,128}
for k,v in pairs(colour) do
if k == 1 then
r = v
elseif k == 2 then
g = v
elseif k == 3 then
b = v
end
end
-- new particle system example
Effect:new{r=r, g=g, b=b, duration=castTime, follow_oid=player.oid}
if self.onUse then
gameStatsInc("times_skill_used_" .. self.definition.key)
track("skill_used", self.definition.key)
-- call use after casttime timeout
the.app.view.timer:after(self.cast_time, function()
-- finished casting
--~ the.player.selectedSkill = 1
if self:freezeMovementDuringCasting() then player:unfreezeMovement() end
if player.interrupted == false then
--print("SKILL", self.nr, "REALLY USE")
--~ playSound(self.definition.sound or '/assets/audio/missing.wav', audio.volume, 'short')
local sfx = self.definition.sound or '/assets/audio/missing.wav'
if the.characters and the.player then
for player, bool in pairs(the.characters) do
--~ print(vector.lenFromTo(the.player.x, the.player.y, player.x, player.y), config.audioRange)
local distance = vector.lenFromTo(the.player.x, the.player.y, player.x, player.y)
if distance <= config.audioRange then
local loudness = 0
--~ print("pre", distance, loudness)
loudness = utils.mapIntoRange(distance, 0, config.audioRange, 1, 0)
--~ print("post", distance, loudness)
object_manager.send(player.oid, "play_sound", sfx, loudness, the.player.oid)
end
end
end
-- update view pos
if player.readInput then
local ipt = player:readInput()
self.source.viewx = ipt.viewx
self.source.viewy = ipt.viewy
end
if self.character.freezeCastingCounter <= 0 then self:onUse() end
end
self.character.currentEnergy = self.character.currentEnergy - self.energyCosts
end)
end
end,
onNew = function (self)
self.definition = action_definitions[self.id]
if not self.definition then print("ERROR there is no skill with id", self.id) return end
self.timeout = self.definition.timeout
self.cast_time = self.definition.cast_time
self.lastUsed = -10000000
self.energyCosts = self.definition.energy
self.iconColor = self.definition.cast_particle_color or {255,255,255}
end,
freezeMovementDuringCasting = function (self)
return self.definition.on_the_run == false
end,
onUse = function (self)
local startTarget = { oid = self.character.oid,
viewx = self.source.viewx, viewy = self.source.viewy }
-- for tracking purposes
self.character.lastUsedSkill = self.definition.key
action_handling.start(self.definition.application, startTarget, self.character.oid)
--~ print("out of combat:", self:isOutOfCombat())
end,
isOutOfCombat = function (self)
return love.timer.getTime() - self.lastUsed >= self.combatTimer
end,
}