Exemplo n.º 1
0
def create_random_item(item_dict):
    r_category = random.choice(list(item_dict.keys()))
    r_item = random.choice(item_dict[r_category])
    item_name = list(r_item.keys())[0]
    item_desc = r_item[item_name]
    new_item = Item(
        name = item_name,
        description = item_desc,
        value = random.randint(100, 10000) 
    )
    new_item.save()
    return new_item
Exemplo n.º 2
0
 def create_items(self):
     """Create chests and their keys in pairs with matching id."""
     for i in range(self.num_chests):
         # Make a hilarious name for the pair.
         name = adj_noun()
         key_name = "Key of the " + name
         chest_name = "Chest of the " + name
         k = Item(name=key_name,
                  description=f"Maybe it opens the {chest_name}?!",
                  room=None)
         c = Container(name=chest_name,
                       description="Maybe there's treasure inside!",
                       key=k,
                       room=None)
         k.save()
         c.save()
Exemplo n.º 3
0
 def test_serialize(self):
     item = Item(
         name='thing',
         synonym_names=['object', 'thingy'],
         description='It looks like a thing',
         is_gettable=True,
     )
     serialized_item = item.serialize()
     self.assertEqual(
         serialized_item,
         {
             'name': item.name,
             'article': None,
             'synonym_names': item.synonym_names,
             'description': item.description,
             'is_gettable': item.is_gettable,
             '_identifier': item._identifier,
         }
     )
Exemplo n.º 4
0
def seed_items(num_chests, num_rooms):
    """Move keys and chests to random rooms.
    Put the treasure in the lucky chest.
    Remove keys from players.
    """
    # Create the required number of chests and keys.
    for i in range(1, num_chests):
        key = Item.objects.get(id=i)
        chest = Container.objects.get(id=i)
        key.player = None
        chest.player = None
        key.room = Room.objects.get(id=random.randint(1, num_rooms))
        chest.room = Room.objects.get(id=random.randint(1, num_rooms))
        key.save()
        chest.save()

    # Creat a treasure and hide it in a random chest.
    lucky_chest_number = random.randint(1, num_chests)
    the_treasure = Item(name="The Treasure",
                        description="That thing you want",
                        container=Container.objects.get(id=lucky_chest_number))
    the_treasure.save()
Exemplo n.º 5
0
    if 'w' in roomGraph[roomID][1]:
        rooms[roomID].connectRooms(rooms[roomGraph[roomID][1]['w']], 'w')

players = Player.objects.all()
for p in players:
    p.currentRoom = rooms[0].id
    p.save()

Item.objects.all().delete()

for i in range(0, 500):
    if random.random() > 0.7:
        t = Item(name="Small Treasure",
                 description="This is a small piece of treasure",
                 weight=2,
                 aliases="small treasure,treasure",
                 value=100,
                 itemtype="TREASURE",
                 attributes='{"default":1}',
                 room=Room.objects.get(id=i))
        t.save()

t = Item(name="boots",
         description="These are boots",
         weight=2,
         aliases="boots",
         value=100,
         itemtype="FOOTWEAR",
         attributes='{"SPEED":1}',
         room=Room.objects.get(id=0))
t.save()
r_overlook.connectRooms(r_foyer, "s")

r_foyer.connectRooms(r_narrow, "e")
r_narrow.connectRooms(r_foyer, "w")

r_narrow.connectRooms(r_treasure, "n")
r_treasure.connectRooms(r_narrow, "s")

r_treasure.connectRooms(r_hidden, "n")
r_hidden.connectRooms(r_treasure, "s")

r_hidden.connectRooms(r_lighthouse, "w")
r_lighthouse.connectRooms(r_hidden, "e")

r_lighthouse.connectRooms(r_beach, "w")
r_beach.connectRooms(r_lighthouse, "e")

players=Player.objects.all()
for p in players:
  p.currentRoom=r_outside.id
  p.save()



Item.objects.all().delete()

i_lamp = Item(name="Glowing Lamp", description="A bright and colorfully-decorated light source.", room=r_outside, player=None)
i_bread = Item(name="Bread", description="A crusty loaf of stale bread.", room=r_outside, player=None)

i_lamp.save()
i_bread.save()
Exemplo n.º 7
0
            west = new_map[lastx][lasty - 1]
            looks.append((west, 'w'))

            #         if selected_room_id != 0.0:
            #             new_map[lastx][lasty] = 2

            for vals in looks:
                intval = int(vals[0])
                if intval != 0:

                    room_to_connect = Room.objects.get(roomid=intval)
                    selected_room.connectRooms(room_to_connect, vals[1])
            isitem = random.choice([0, 0, 1])
            if isitem == 1:
                selecteditem = random.choice(items)
                itemroom = Item(name=selecteditem, room_id=selected_room.id)
                itemroom.save()

roomlist = [i for i in Room.objects.all()]

roomrand = random.choice(roomlist)
roomrand.roomtype = 3
roomrand.save()
roomlist.remove(roomrand)

for i in range(5):
    roomrand = random.choice(roomlist)
    roomrand.roomtype = 2
    roomrand.save()
    roomlist.remove(roomrand)
Exemplo n.º 8
0
 def test_set_article(self):
     item = Item('thing')
     item.article = 'foobar'
     self.assertEqual(item._article, 'foobar')
Exemplo n.º 9
0
from adventure.models import Item

items = Item.objects.all().delete()

items = {
    "Empty": "Nothing",
    "Gold": "Gold greases palms, builds empires, and instigates murder.",
    "Sword": "The razor-sharp point makes this weapon ideal to pierce your "
             "enemies and turn them into a sieve.",
    "Shield": "A lightweight shield that is easy to maneuver but strong " \
              "enough to defend off most attacks.",
    "Key": "A gleaming key with a unique design. What could it be used for?",
    "Door": "A solid oak door. You see sunlight filtering through the cracks. Unfortunately, it is locked..."
}

count = 1
for item in items.items():
    i = Item(name=item[0], description=item[1])
    i.id = count
    count += 1
    i.save()
Exemplo n.º 10
0
r_narrow = Room(title="Narrow Passage",
                description="""The narrow passage bends here from west
to north. The smell of gold permeates the air.""")

r_treasure = Room(title="Treasure Chamber",
                  description="""You've found the long-lost treasure
chamber! Sadly, it has already been completely emptied by
earlier adventurers. The only exit is to the south.""")

r_outside.save()
r_foyer.save()
r_overlook.save()
r_narrow.save()
r_treasure.save()

i_rock = Item(title="Rock",
              description="A rock that fit in the palm of your hand.")
i_rock.save()

w_sword = Weapon(title="Sword",
                 description="A standard one handed arming sword.",
                 itemAttackValue=5)
w_sword.save()

r_outside.items.add(i_rock)
r_outside.items.add(w_sword)
r_foyer.items.add(w_sword)
r_overlook.items.add(w_sword)
r_narrow.items.add(w_sword)
r_treasure.items.add(w_sword)

# Link rooms together