minor docs change, add preserve_items to create method
This commit is contained in:
parent
de24d2646d
commit
eda361d7d6
2 changed files with 48 additions and 42 deletions
|
|
@ -5,7 +5,7 @@ Contribution by titeuf87, 2017
|
||||||
This contrib provides a wilderness map without actually creating a large number
|
This contrib provides a wilderness map without actually creating a large number
|
||||||
of rooms - as you move, you instead end up back in the same room but its description
|
of rooms - as you move, you instead end up back in the same room but its description
|
||||||
changes. This means you can make huge areas with little database use as
|
changes. This means you can make huge areas with little database use as
|
||||||
long as the rooms are relatively similar (name/desc changing).
|
long as the rooms are relatively similar (e.g. only the names/descs changing).
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|
@ -29,6 +29,9 @@ All coordinates used by the wilderness map are in the format of `(x, y)`
|
||||||
tuples. x goes from left to right and y goes from bottom to top. So `(0, 0)`
|
tuples. x goes from left to right and y goes from bottom to top. So `(0, 0)`
|
||||||
is the bottom left corner of the map.
|
is the bottom left corner of the map.
|
||||||
|
|
||||||
|
> You can also add a wilderness by defining a WildernessScript in your GLOBAL_SCRIPT
|
||||||
|
> settings. If you do, make sure define the map provider.
|
||||||
|
|
||||||
## Customisation
|
## Customisation
|
||||||
|
|
||||||
The defaults, while useable, are meant to be customised. When creating a
|
The defaults, while useable, are meant to be customised. When creating a
|
||||||
|
|
@ -37,9 +40,14 @@ python object that is smart enough to create the map.
|
||||||
|
|
||||||
The default provider, `WildernessMapProvider`, just creates a grid area that
|
The default provider, `WildernessMapProvider`, just creates a grid area that
|
||||||
is unlimited in size.
|
is unlimited in size.
|
||||||
This `WildernessMapProvider` can be subclassed to create more interesting
|
|
||||||
|
`WildernessMapProvider` can be subclassed to create more interesting
|
||||||
maps and also to customize the room/exit typeclass used.
|
maps and also to customize the room/exit typeclass used.
|
||||||
|
|
||||||
|
The `WildernessScript` also has an optional `preserve_items` property, which
|
||||||
|
when set to `True` will not recycle rooms that contain any objects. By default,
|
||||||
|
a wilderness room is recycled whenever there are no players left in it.
|
||||||
|
|
||||||
There is also no command that allows players to enter the wilderness. This
|
There is also no command that allows players to enter the wilderness. This
|
||||||
still needs to be added: it can be a command or an exit, depending on your
|
still needs to be added: it can be a command or an exit, depending on your
|
||||||
needs.
|
needs.
|
||||||
|
|
@ -94,7 +102,7 @@ class PyramidMapProvider(wilderness.WildernessMapProvider):
|
||||||
desc = "This is a room in the pyramid."
|
desc = "This is a room in the pyramid."
|
||||||
if y == 3 :
|
if y == 3 :
|
||||||
desc = "You can see far and wide from the top of the pyramid."
|
desc = "You can see far and wide from the top of the pyramid."
|
||||||
room.db.desc = desc
|
room.ndb.desc = desc
|
||||||
```
|
```
|
||||||
|
|
||||||
Now we can use our new pyramid-shaped wilderness map. From inside Evennia we
|
Now we can use our new pyramid-shaped wilderness map. From inside Evennia we
|
||||||
|
|
@ -105,9 +113,13 @@ create a new wilderness (with the name "default") but using our new map provider
|
||||||
|
|
||||||
## Implementation details
|
## Implementation details
|
||||||
|
|
||||||
When a character moves into the wilderness, they get their own room. If they
|
When a character moves into the wilderness, they get their own room. If
|
||||||
move, instead of moving the character, the room changes to match the new
|
they move, instead of moving the character, the room changes to match the
|
||||||
coordinates. If a character meets another character in the wilderness, then
|
new coordinates.
|
||||||
their room merges. When one of the character leaves again, they each get their
|
|
||||||
own separate rooms. Rooms are created as needed. Unneeded rooms are stored away
|
If a character meets another character in the wilderness, then their room
|
||||||
to avoid the overhead cost of creating new rooms again in the future.
|
merges. When one of the character leaves again, they each get their own
|
||||||
|
separate rooms.
|
||||||
|
|
||||||
|
Rooms are created as needed. Unneeded rooms are stored away to avoid the
|
||||||
|
overhead cost of creating new rooms again in the future.
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,7 @@ separate rooms.
|
||||||
|
|
||||||
Rooms are created as needed. Unneeded rooms are stored away to avoid the
|
Rooms are created as needed. Unneeded rooms are stored away to avoid the
|
||||||
overhead cost of creating new rooms again in the future.
|
overhead cost of creating new rooms again in the future.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from evennia import (
|
from evennia import (
|
||||||
|
|
@ -125,8 +126,7 @@ from evennia import (
|
||||||
from evennia.utils import inherits_from
|
from evennia.utils import inherits_from
|
||||||
from evennia.typeclasses.attributes import AttributeProperty
|
from evennia.typeclasses.attributes import AttributeProperty
|
||||||
|
|
||||||
|
def create_wilderness(name="default", mapprovider=None, preserve_items=False):
|
||||||
def create_wilderness(name="default", mapprovider=None):
|
|
||||||
"""
|
"""
|
||||||
Creates a new wilderness map. Does nothing if a wilderness map already
|
Creates a new wilderness map. Does nothing if a wilderness map already
|
||||||
exists with the same name.
|
exists with the same name.
|
||||||
|
|
@ -147,6 +147,8 @@ def create_wilderness(name="default", mapprovider=None):
|
||||||
mapprovider = WildernessMapProvider()
|
mapprovider = WildernessMapProvider()
|
||||||
script = create_script(WildernessScript, key=name)
|
script = create_script(WildernessScript, key=name)
|
||||||
script.db.mapprovider = mapprovider
|
script.db.mapprovider = mapprovider
|
||||||
|
if preserve_items:
|
||||||
|
script.preserve_items = True
|
||||||
|
|
||||||
|
|
||||||
def enter_wilderness(obj, coordinates=(0, 0), name="default"):
|
def enter_wilderness(obj, coordinates=(0, 0), name="default"):
|
||||||
|
|
@ -298,11 +300,7 @@ class WildernessScript(DefaultScript):
|
||||||
Returns:
|
Returns:
|
||||||
[Object, ]: list of Objects at coordinates
|
[Object, ]: list of Objects at coordinates
|
||||||
"""
|
"""
|
||||||
result = [
|
result = [ item for item, item_coords in self.itemcoordinates.items() if item_coords == coordinates and item is not None ]
|
||||||
item
|
|
||||||
for item, item_coords in self.itemcoordinates.items()
|
|
||||||
if item_coords == coordinates and item is not None
|
|
||||||
]
|
|
||||||
return list(result)
|
return list(result)
|
||||||
|
|
||||||
def move_obj(self, obj, new_coordinates):
|
def move_obj(self, obj, new_coordinates):
|
||||||
|
|
@ -321,6 +319,9 @@ class WildernessScript(DefaultScript):
|
||||||
# appear in its old room should that room be deleted.
|
# appear in its old room should that room be deleted.
|
||||||
obj.location = None
|
obj.location = None
|
||||||
|
|
||||||
|
# By default, we'll assume we won't be making a new room and change this flag if necessary.
|
||||||
|
create_room = False
|
||||||
|
|
||||||
# See if we already have a room for that location
|
# See if we already have a room for that location
|
||||||
if room := self.db.rooms.get(new_coordinates):
|
if room := self.db.rooms.get(new_coordinates):
|
||||||
# There is. Try to destroy the old_room if it is not needed anymore
|
# There is. Try to destroy the old_room if it is not needed anymore
|
||||||
|
|
@ -334,13 +335,7 @@ class WildernessScript(DefaultScript):
|
||||||
# Should we preserve rooms with any objects?
|
# Should we preserve rooms with any objects?
|
||||||
if self.preserve_items:
|
if self.preserve_items:
|
||||||
# Yes - check if ANY objects besides the exits are in old_room
|
# Yes - check if ANY objects besides the exits are in old_room
|
||||||
if len(
|
if len([ob for ob in old_room.contents if not inherits_from(ob, WildernessExit)]):
|
||||||
[
|
|
||||||
ob
|
|
||||||
for ob in old_room.contents
|
|
||||||
if not inherits_from(ob, WildernessExit)
|
|
||||||
]
|
|
||||||
):
|
|
||||||
# There is, so we'll create a new room
|
# There is, so we'll create a new room
|
||||||
room = self._create_room(new_coordinates, obj)
|
room = self._create_room(new_coordinates, obj)
|
||||||
else:
|
else:
|
||||||
|
|
@ -646,7 +641,6 @@ class WildernessRoom(DefaultRoom):
|
||||||
# Otherwise, use the normal description hook.
|
# Otherwise, use the normal description hook.
|
||||||
return super().get_display_desc(looker, **kwargs)
|
return super().get_display_desc(looker, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class WildernessExit(DefaultExit):
|
class WildernessExit(DefaultExit):
|
||||||
"""
|
"""
|
||||||
This is an Exit object used inside a WildernessRoom. Instead of changing
|
This is an Exit object used inside a WildernessRoom. Instead of changing
|
||||||
|
|
@ -789,7 +783,7 @@ class WildernessMapProvider(object):
|
||||||
Args:
|
Args:
|
||||||
coordinates (tuple): the coordinates as (x, y) where room is
|
coordinates (tuple): the coordinates as (x, y) where room is
|
||||||
located at
|
located at
|
||||||
caller (Object or None): the object that moved into this room
|
caller (Object): the object that moved into this room
|
||||||
room (WildernessRoom): the room object that will be used at that
|
room (WildernessRoom): the room object that will be used at that
|
||||||
wilderness location
|
wilderness location
|
||||||
Example:
|
Example:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue