File: QuestConditionalDrop.py

package info (click to toggle)
crossfire-maps 1.75.0%2Bdfsg1-1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 275,656 kB
  • sloc: python: 7,711; sql: 92; sh: 73; makefile: 7
file content (45 lines) | stat: -rw-r--r-- 1,257 bytes parent folder | download
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
# -*- coding: utf-8 -*-
# QuestConditionalDrop.py - A script to let items be dropped only if a quest
# reached a certain step.
#
# This script should be called for the 'death' event of a living thing.
# Each item in inventory will be checked for a 'drop_if_quest' key, which format is:
# - quest name
# - a list of steps, either single value (x) or range (x-y)
# If any matches, then the item will be dropped, else it won't.
# Items without the 'drop_if_quest' key are not affected.

import Crossfire

whoami = Crossfire.WhoAmI()
killer = Crossfire.WhoIsActivator()

def matches(rule):
    if rule == '':
        return True
    args = rule.split()

    if type(killer) != Crossfire.Player:
        return False

    currentstep = killer.QuestGetState(args[0])
    for rule in args[1:]:
        if rule.find("-") == -1:
            startstep = int(rule)
            endstep = startstep
        else:
            startstep = int(rule.split("-")[0])
            endstep= int(rule.split("-")[1])
        if currentstep >= startstep and currentstep <= endstep:
            return True

    return False


inv = whoami.Inventory
while inv != None:
    key = inv.ReadKey('drop_if_quest')
    if not matches(key):
        inv.GodGiven = True
    inv = inv.Below