File: sell_punisher.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 (76 lines) | stat: -rw-r--r-- 2,418 bytes parent folder | download | duplicates (3)
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
# -*- coding: utf-8 -*-
# sell_punisher.py - Punish players for selling items
#
# Copyright (C) 2010 Nicolas Weege
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
# This script punishes players trying to sell the item it is linked to.
# The item is then not sold.
#
# It should be called from a "selling" event.
#
# An optional "punish_sell_in" key can be put in the item (not the event)
# to specify a base path to punish selling it in maps which path starts with that value.
# For instance, to restrict selling to Scorn, use "punish_sell_in /scorn/".
#
# If no key is defined, trying to sell is punished in the whole world.

import Crossfire
import random

def sell_is_restricted():
    map = Crossfire.WhoAmI().ReadKey("punish_sell_in")
    if map == "":
        return 1

    current = Crossfire.WhoIsActivator().Map.Path

    if len(current) < len(map):
        return 0

    if map == current[0:len(map)]:
        return 1

    return 0

def handle_sell():
    if not sell_is_restricted():
        return

    guard = None

    map = Crossfire.WhoIsActivator().Map
    for h in range(0, map.Height):
        for w in range(0, map.Width):
            top = map.ObjectAt(w, h)
            while top != None:
                if top.Type == 69:
                    count = random.randint(2, 8)
                    while count > 0:
                        guard = Crossfire.CreateObjectByName("guard")
                        guard.StandStill = 0
                        guard.Unaggressive = 0
                        map.InsertAround(guard, w, h)
                        count = count - 1
                    break
                top = top.Above

    if guard != None:
        Crossfire.WhoIsActivator().Message("You thief!")
    Crossfire.SetReturnValue(1)

handle_sell()