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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
|
import Crossfire
import random
#import CFLog
Crossfire.SetReturnValue( 1 )
whoami=Crossfire.WhoAmI()
who = Crossfire.WhoIsActivator()
def do_help():
help = ''
help += 'Usage: say <test name>\nAvailable tests:\n'
help += ' - arch: archetypes-related tests\n'
help += ' - maps: maps-related tests\n'
help += ' - party: party-related tests\n'
help += ' - region: party-related tests\n'
help += ' - ref: some checks on objects references\n'
help += ' - mark: marked item\n'
help += ' - memory: storage-related tests\n'
help += ' - time: time of day tests\n'
help += ' - timer: timer activation test\n'
help += ' - timer_kill: kill specified timer\n'
help += ' - misc: other tests\n'
help += ' - exp\n'
help += ' - const: constants and such\n'
help += ' - move\n'
help += ' - bed\n'
help += ' - readkey\n'
help += ' - writekey\n'
help += ' - speed\n'
help += ' - owner\n'
help += ' - friendlylist\n'
help += ' - create\n'
help += ' - directory\n'
help += ' - event\n'
help += ' - light\n'
help += ' - attacktype\n'
help += ' - players\n'
help += ' - checkinv\n'
help += ' - face\n'
help += ' - anim\n'
help += ' - hook\n'
help += ' - checkinventory\n'
help += ' - nosave\n'
help += ' - move_to\n'
help += ' - attr: object-attribute tests'
whoami.Say(help)
def do_arch():
archs = Crossfire.GetArchetypes()
whoami.Say('%d archetypes'%len(archs))
which = random.randint(0,len(archs))
arch = archs[which]
whoami.Say('random = %s'%arch.Name)
head = ''
more = ''
next = ''
if (arch.Head):
head = arch.Head.Name
if (arch.More):
more = arch.More.Name
if (arch.Next):
next = arch.Next.Name
whoami.Say(' head = %s, more = %s, clone = %s, next = %s'%(head, more, arch.Clone.Name, next))
arch = who.Archetype
whoami.Say('your archetype is %s'%arch.Name)
def do_maps():
whoami.Say('Current map is %s'%who.Map.Name)
maps = Crossfire.GetMaps()
whoami.Say('%d maps loaded'%len(maps))
for map in maps:
whoami.Say('%s [%d] -> %d players'%(map.Name, map.Unique, map.Players))
#activator=Crossfire.WhoIsActivator()
whoami.Say('this map is %s, size %d, %d'%(whoami.Map.Name, whoami.Map.Width, whoami.Map.Height))
if (len(topic) > 1):
flag = 0
if len(topic) > 2:
flag = int(topic[2])
ready = Crossfire.ReadyMap(topic[1], flag)
if (ready):
whoami.Say('ok, loaded %d map %s'%(flag,ready.Name))
else:
whoami.Say('can\'t load %d map %s'%(flag,topic[1]))
def do_party():
parties = Crossfire.GetParties()
whoami.Say('%d parties'%len(parties))
for party in parties:
whoami.Say('%s (%s)'%(party.Name, party.Password))
players = party.GetPlayers()
for player in players:
whoami.Say(' %s'%player.Name)
if len(parties) >= 2:
who.Party = parties[1]
whoami.Say('changed your party!')
def do_region():
msg = 'Known regions, region for current map is signaled by ***\n'
cur = whoami.Map.Region
msg += 'This map\'s region is %s (msg: %s)\n'%(cur.Name, cur.Message)
regions = Crossfire.GetRegions()
msg += ('%d regions\n'%len(regions))
for region in regions:
if cur == region:
msg += ('*** %s - %s\n'%(region.Name,region.Longname))
else:
msg += ('%s - %s\n'%(region.Name,region.Longname))
parent = cur.GetParent()
if parent:
msg += ('Parent is %s\n'%parent.Name)
else:
msg += ('Region without parent\n')
msg += "Jail: %s (%d,%d)"%(cur.JailPath, cur.JailX, cur.JailY)
whoami.Say(msg)
def do_activator():
who2 = Crossfire.WhoIsOther()
who3 = Crossfire.WhoAmI()
who = 0
who2 = 0
who3 = 0
whoami.Say('let\'s hope no reference crash!')
def do_marker():
obj = who.MarkedItem
if obj:
whoami.Say(' your marked item is: %s'%obj.Name)
mark = obj.Below
else:
whoami.Say(' no marked item')
mark = who.Inventory
while (mark) and (mark.Invisible):
mark = mark.Below
who.MarkedItem = mark
whoami.Say('Changed marked item!')
def do_memory():
whoami.Say('Value save test')
dict = Crossfire.GetPrivateDictionary()
if 's' in dict:
x = dict['s']
whoami.Say(' x was %d'%x)
x = x + 1
else:
x = 0
whoami.Say(' new x')
dict['s'] = x
def do_resist():
whoami.Say('Resistance test')
for r in range(25):
whoami.Say(' %d -> %d'%(r,who.GetResist(r)))
def do_basics():
msg = 'Basic test\n'
msg += ' your type is %d\n'%who.Type
msg += ' your race is %s\n'%who.Race
msg += ' your level is %d\n'%who.Level
msg += ' your nrof is %d\n'%who.Quantity
msg += ' your weight is %d\n'%who.Weight
msg += ' your name is %s\n'%who.Name
msg += ' your archname is %s\n'%who.ArchName
msg += ' your title is %s\n'%who.Title
msg += ' your ip is %s\n'%who.IP
msg += ' my name is %s\n'%whoami.Name
whoami.Say(msg)
def do_time():
cftime = Crossfire.GetTime()
whoami.Say('Year: %d'%cftime[0])
whoami.Say('Month: %d'%cftime[1])
whoami.Say('Day: %d'%cftime[2])
whoami.Say('Hour: %d'%cftime[3])
whoami.Say('Minute: %d'%cftime[4])
whoami.Say('Day of week: %d'%cftime[5])
whoami.Say('Week of year: %d'%cftime[6])
whoami.Say('Season: %d'%cftime[7])
def do_timer():
id = whoami.CreateTimer(3,1)
if id >= 0:
whoami.Say('The countdown started with a 3 second delay, timerid = %d'%id)
else:
whoami.Say('Timer failure: %d'%id)
def do_timer_kill():
if ( len(topic) < 2 ):
whoami.Say('Kill which timer?')
else:
timer = int(topic[1])
res = Crossfire.DestroyTimer(timer)
whoami.Say('Timer %d removed with code %d'%(timer,res))
def do_misc():
inv = whoami.Inventory
if inv != 0:
whoami.Say("First inv = %s"%inv.Name)
whoami.Say("Inv.Env = %s"%inv.Env.Name)
else:
whoami.Say("Empty inv??")
if len(topic) > 1:
map = Crossfire.MapHasBeenLoaded(topic[1])
if map:
whoami.Say('map %s is loaded, size = %d, %d'%(map.Name, map.Width, map.Height))
else:
whoami.Say('map %s is not loaded'%topic[1])
def do_inventory():
whoami.Say('You have:')
inv = who.Inventory
while inv:
whoami.Say('%s (type = %d, subtype = %d)'%(inv.Name, inv.Type, inv.Subtype))
inv = inv.Below
def do_exp():
if ( len(topic) < 2 ):
whoami.Say("Your exp is %d, perm is %d, mult is %d"%(who.Exp, who.PermExp, who.ExpMul))
whoami.Say("Syntax is: exp <value> [option] [skill]")
else:
value = int(topic[1])
skill = ""
arg = 0
if ( len(topic) > 2 ):
arg = int(topic[2])
if ( len(topic) > 3):
i = 3
while ( i < len(topic) ):
skill = skill + topic[i] + ' '
i = i + 1
skill = skill.rstrip()
who.AddExp(value, skill, arg)
whoami.Say("ok, added %d exp to %s"%(value,skill))
def do_const():
ret = '\n'
ret += "%s => %d\n"%(Crossfire.DirectionName[Crossfire.Direction.NORTH],Crossfire.Direction.NORTH)
ret += "Player type => %d\n"%Crossfire.Type.PLAYER
ret += "Move Fly High => %d\n"%Crossfire.Move.FLY_HIGH
ret += "MessageFlag NDI_BLUE => %d\n"%Crossfire.MessageFlag.NDI_BLUE
ret += "CostFlag F_NO_BARGAIN => %d\n"%Crossfire.CostFlag.NOBARGAIN
ret += "AttackMovement PETMOVE => %d\n"%Crossfire.AttackMovement.PETMOVE
whoami.Say(ret)
def dump_move(title, move):
moves = [
Crossfire.Move.WALK,
Crossfire.Move.FLY_LOW,
Crossfire.Move.FLY_HIGH,
Crossfire.Move.FLYING,
Crossfire.Move.SWIM,
Crossfire.Move.BOAT ]
s = title + ':'
for t in moves:
if move & t:
s = s + ' ' + Crossfire.MoveName[t]
return s
def do_move():
whoami.Say(dump_move("movetype", who.MoveType))
def do_bed():
whoami.Say("bed = %s at (%d, %d)"%(who.BedMap, who.BedX, who.BedY))
whoami.Say("changing to +1 -1")
who.BedX = who.BedX + 1
who.BedY = who.BedY - 1
whoami.Say("bed = %s at (%d, %d)"%(who.BedMap, who.BedX, who.BedY))
whoami.Say("resetting.")
who.BedX = who.BedX - 1
who.BedY = who.BedY + 1
def do_readkey():
if (len(topic) < 2):
whoami.Say('read what key?')
return
whoami.Say('key %s = %s'%(topic[1], who.ReadKey(topic[1])))
def do_writekey():
if (len(topic) < 3):
whoami.Say('syntax is writekey key add_update [value]')
return
val = ''
if (len(topic) > 3):
val = topic[3]
whoami.Say('writekey returned %d'%who.WriteKey(topic[1], val, int(topic[2])))
def do_speed():
whoami.Say('Your speed is %f and your speed_left %f'%(who.Speed, who.SpeedLeft))
# who.Speed = 0.2
who.SpeedLeft = -50
whoami.Say('Changed your speed, now %f and %f'%(who.Speed, who.SpeedLeft))
def do_owner():
whoami.Say('Not implemented.')
def do_friendlylist():
friends = Crossfire.GetFriendlyList()
for ob in friends:
if (ob.Owner):
n = ob.Owner.Name
else:
n = ''
whoami.Say(' - %s (%s)'%(ob.Name, n))
def do_create():
first = Crossfire.CreateObjectByName('gem')
if (first):
whoami.Say('created gem: %s'%first.Name)
first.Teleport(whoami.Map, 2, 2)
second = Crossfire.CreateObjectByName('diamond')
if (second):
whoami.Say('created diamond: %s'%second.Name)
second.Teleport(whoami.Map, 2, 2)
def do_directory():
whoami.Say('map = %s'%Crossfire.MapDirectory())
whoami.Say('unique = %s'%Crossfire.UniqueDirectory())
whoami.Say('temp = %s'%Crossfire.TempDirectory())
whoami.Say('config = %s'%Crossfire.ConfigDirectory())
whoami.Say('local = %s'%Crossfire.LocalDirectory())
whoami.Say('player = %s'%Crossfire.PlayerDirectory())
whoami.Say('data = %s'%Crossfire.DataDirectory())
whoami.Say('scriptname = %s'%Crossfire.ScriptName())
def do_event():
whoami.Say('event title = %s' %Crossfire.WhatIsEvent().Title)
whoami.Say('event slaying = %s' %Crossfire.WhatIsEvent().Slaying)
whoami.Say('event msg = %s' %Crossfire.WhatIsEvent().Message)
def do_light():
whoami.Say('current light: %d'%whoami.Map.Light)
if (len(topic) > 1):
chg = int(topic[1])
whoami.Map.ChangeLight(chg)
whoami.Say('new light: %d'%whoami.Map.Light)
def do_attacktype():
att = [ Crossfire.AttackType.FIRE, Crossfire.AttackType.COLD, Crossfire.AttackType.ELECTRICITY ]
whoami.Say('Your attacktype are:')
for at in att:
if ( at & Crossfire.WhoIsActivator().AttackType == at):
whoami.Say(Crossfire.AttackTypeName[ at ])
def do_players():
players = Crossfire.GetPlayers()
whoami.Say('Players logged in:')
for pl in players:
whoami.Say(' - %s'%pl.Name)
def do_checkinv():
if len(topic) > 1:
what = topic[1]
else:
what = 'force'
find = who.CheckInventory(what)
if find:
whoami.Say('Found %s in your inventory.'%find.Name)
else:
whoami.Say('Can\'t find %s in your inventory.'%what)
def do_face():
obj = whoami.Map.ObjectAt(4, 4)
if len(topic) == 1:
whoami.Say('Face is %s'%obj.Face)
return
face = topic[1]
try:
obj.Face = face
whoami.Say('Face changed to %s'%face)
except:
whoami.Say('Invalid face %s'%face)
def do_anim():
obj = whoami.Map.ObjectAt(4, 4).Above
if len(topic) == 1:
whoami.Say('Animation is %s'%obj.Anim)
return
anim = topic[1]
try:
obj.Anim = anim
whoami.Say('Animation changed to %s'%anim)
except:
whoami.Say('Invalid animation %s'%anim)
def do_hook():
item = whoami.Map.CreateObject('food', 0, 0)
whoami.Say('Created item.')
item2 = whoami.Map.ObjectAt(0, 0)
while item2.Above:
item2 = item2.Above
if item != item2:
whoami.Say('Not the same items!')
item.Remove()
whoami.Say('Trying to access removed item, exception coming')
try:
item2.Quantity = 1
whoami.Say('No exception! Error!')
except:
whoami.Say('Exception came, ok')
def do_check_inventory():
if len(topic) == 1:
whoami.Say('use: checkinventory <item''s name>')
return
what = ' '.join(topic[1:])
item = who.CheckInventory(what)
if item != None:
whoami.Say('found item: ' + item.Name)
else:
whoami.Say('did not find anything matching ' + what)
def do_no_save():
item = whoami.Map.CreateObject('food', 2, 1)
item.NoSave = 1
whoami.Say('no_save set, the food should not be saved')
def do_move_to():
if whoami.X == 2 and whoami.Y == 2:
whoami.WriteKey('dest_x', '0', 1)
whoami.WriteKey('dest_y', '4', 1)
else:
whoami.WriteKey('dest_x', '2', 1)
whoami.WriteKey('dest_y', '2', 1)
def do_attr():
if len(topic) < 2:
whoami.Say('Usage: attr name [value], if value is omitted display the value')
return
if len(topic) == 2:
val = getattr(whoami, topic[1])
# Not sure of the value of the attribute, so just use Python's type conversion by forcing to str
whoami.Say('my %s is %s'%(topic[1], str(val)))
return
try:
setattr(whoami, topic[1], topic[2])
except:
try:
setattr(whoami, topic[1], int(topic[2]))
except:
try:
setattr(whoami, topic[1], float(topic[2]))
except:
whoami.Say("sorry, I don't know how to set this attribute...")
def handle_say():
if whoami.ReadKey('dest_x') != '' or whoami.ReadKey('dest_y') != '':
return
topic = Crossfire.WhatIsMessage().split()
#whoami.Say('topic = %s'%topic)
#whoami.Say('topic[0] = %s'%topic[0])
if topic[0] == 'arch':
do_arch()
elif topic[0] == 'maps':
do_maps()
elif topic[0] == 'party':
do_party()
elif topic[0] == 'region':
do_region()
elif topic[0] == 'mark':
do_marker()
elif topic[0] == 'ref':
do_activator()
elif topic[0] == 'memory':
do_memory()
elif topic[0] == 'resist':
do_resist()
elif topic[0] == 'basics':
do_basics()
elif topic[0] == 'time':
do_time()
elif topic[0] == 'timer':
do_timer()
elif topic[0] == 'timer_kill':
do_timer_kill()
elif topic[0] == 'misc':
do_misc()
elif topic[0] == 'exp':
do_exp()
elif topic[0] == 'const':
do_const()
elif topic[0] == 'move':
do_move()
elif topic[0] == 'inv':
do_inventory()
elif topic[0] == 'bed':
do_bed()
elif topic[0] == 'readkey':
do_readkey()
elif topic[0] == 'writekey':
do_writekey()
elif topic[0] == 'speed':
do_speed()
elif topic[0] == 'owner':
do_owner()
elif topic[0] == 'friendlylist':
do_friendlylist()
elif topic[0] == 'create':
do_create()
elif topic[0] == 'directory':
do_directory()
elif topic[0] == 'event':
do_event()
elif topic[0] == 'light':
do_light()
elif topic[0] == 'attacktype':
do_attacktype()
elif topic[0] == 'players':
do_players()
elif topic[0] == 'checkinv':
do_checkinv()
elif topic[0] == 'anim':
do_anim()
elif topic[0] == 'face':
do_face()
elif topic[0] == 'hook':
do_hook()
elif topic[0] == 'checkinventory':
do_check_inventory()
elif topic[0] == 'nosave':
do_no_save()
elif topic[0] == 'move_to':
do_move_to()
elif topic[0] == 'attr':
do_attr()
else:
do_help()
def handle_time():
x = whoami.ReadKey('dest_x')
y = whoami.ReadKey('dest_y')
if x == '' or y == '':
return
x = int(x)
y = int(y)
result = whoami.MoveTo(x, y)
if (result == 0):
whoami.WriteKey('dest_x', '', 1)
whoami.WriteKey('dest_y', '', 1)
whoami.Say("I'm there")
elif (result == 2):
whoami.Say('blocked...')
event = Crossfire.WhatIsEvent()
if event.Subtype == Crossfire.EventType.SAY:
topic = Crossfire.WhatIsMessage().split()
handle_say()
elif event.Subtype == Crossfire.EventType.TIME:
handle_time()
|