File: sprint.lua

package info (click to toggle)
crawl 2%3A0.33.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 95,264 kB
  • sloc: cpp: 358,145; ansic: 27,203; javascript: 9,491; python: 8,359; perl: 3,327; java: 2,667; xml: 2,191; makefile: 1,830; sh: 611; objc: 250; cs: 15; sed: 9; lisp: 3
file content (50 lines) | stat: -rw-r--r-- 1,371 bytes parent folder | download | duplicates (2)
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
-------------------
-- Functions for Sprint
-------------------

function callback.acq_on_sight_trig(data, triggerable, triggerer, marker, ev)
  if data.triggered == true then
    return
 end

  local m = dgn.find_marker_positions_by_prop("replica_name", data.replica_name)[1]
  if m ~= nil then
    local x, y = m:xy()

    if not you.see_cell(x, y) then
      return
    end

    data.triggered = true
    if type(data.acq_type) == "string" then
      dgn.create_item(x, y, "acquire " .. data.acq_type)
    else
      for i,_ in ipairs(data.acq_type) do
        dgn.create_item(x, y, "acquire " .. _)
      end
    end
  else
    crawl.mpr("marker ["..data.replica_name.."] not found")
  end
end

acq_on_sight_count = 0

function acq_on_sight(e, glyph, type)
  acq_on_sight_count = acq_on_sight_count + 1
  local m_name = "acq_on_sight_" .. acq_on_sight_count
  local tm = TriggerableFunction:new{
    func="callback.acq_on_sight_trig",
    repeated=true,
    data={triggered=false, acq_type=type, replica_name=m_name} }
  tm:add_triggerer(DgnTriggerer:new{type="player_los"})
  e.lua_marker(glyph, tm)
  e.lua_marker(glyph, function()
    return portal_desc {replica_name=m_name}
  end)
end

-- usage:
-- : acq_on_sight(_G, '_', "weapon")
-- : acq_on_sight(_G, '_', { "weapon", "weapon", "armour" })
-- You can't have multiple squares with the given glyph ('_' here).