Debian Codegraph @

python/quests/QuestConditionalDrop.py

raw
1 # -*- coding: utf-8 -*-
2 # QuestConditionalDrop.py - A script to let items be dropped only if a quest
3 # reached a certain step.
4 #
5 # This script should be called for the 'death' event of a living thing.
6 # Each item in inventory will be checked for a 'drop_if_quest' key, which format is:
7 # - quest name
8 # - a list of steps, either single value (x) or range (x-y)
9 # If any matches, then the item will be dropped, else it won't.
10 # Items without the 'drop_if_quest' key are not affected.
11
12 import Crossfire
13
14 whoami = Crossfire.WhoAmI()
15 killer = Crossfire.WhoIsActivator()
16
17 def matches(rule):
18 if rule == '':
19 return True
20 args = rule.split()
21
22 if type(killer) != Crossfire.Player:
23 return False
24
25 currentstep = killer.QuestGetState(args[0])
26 for rule in args[1:]:
27 if rule.find("-") == -1:
28 startstep = int(rule)
29 endstep = startstep
30 else:
31 startstep = int(rule.split("-")[0])
32 endstep= int(rule.split("-")[1])
33 if currentstep >= startstep and currentstep <= endstep:
34 return True
35
36 return False
37
38
39 inv = whoami.Inventory
40 while inv != None:
41 key = inv.ReadKey('drop_if_quest')
42 if not matches(key):
43 inv.GodGiven = True
44 inv = inv.Below
45