本文整理汇总了Python中src.utils.create.create_object函数的典型用法代码示例。如果您正苦于以下问题:Python create_object函数的具体用法?Python create_object怎么用?Python create_object使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_object函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_physical_loot
def generate_physical_loot(self):
if self.db.boss_mob is True:
loot_generator = create.create_object("game.gamesrc.objects.world.generators.LootGenerator")
loot_item = loot_generator.create_rare_lootset()
loot_item.move_to(self, quiet=True)
loot_generator.delete()
return
rn = random.random()
if self.db.rating in 'hero':
if rn < AVCONFIG['hero_mob_rare_loot_rate']:
num_of_items = random.randrange(1,2)
loot_generator = create.create_object("game.gamesrc.objects.world.generators.LootGenerator")
loot = loot_generator.create_loot_set(loot_rating='rare', number_of_items=num_of_items, item_type='mixed')
for item in loot:
item.move_to(self, quiet=True)
loot_generator.delete()
if rn < AVCONFIG['mob_physical_loot_drop_rate']:
num_of_items = random.randrange(1,3)
loot_generator = create.create_object("game.gamesrc.objects.world.generators.LootGenerator")
ratings = ['uncommon', 'average', 'rare']
rating = random.choice(ratings)
loot = loot_generator.create_loot_set(loot_rating=rating, number_of_items=num_of_items, item_type='mixed')
for item in loot:
item.move_to(self, quiet=True)
loot_generator.delete()
示例2: generate_boss_mob
def generate_boss_mob(self):
if 'crypt' in self.db.dungeon_type:
self.db.boss_names = ['Skeletal Lich', 'Frostbourne Witch']
boss_name = random.choice(self.db.boss_names)
boss_mob = create.create_object("game.gamesrc.objects.world.mob.Mob", key="%s" % boss_name, location=self.location)
boss_mob.aliases = ['boss_mob']
boss_mob.db.level = self.location.db.level
boss_mob.db.rating = 'hero'
boss_mob.db.boss_mob = True
boss_mob.generate_stats()
boss_mob.generate_rewards()
boss_mob.generate_physical_loot()
boss_mob.generate_skillset()
boss_mob.update_stats()
return boss_mob
if 'ruins' in self.db.dungeon_type:
self.db.boss_names = ['Pygmy Lord', 'Ghastly Ghoul', 'Spider Queen']
boss_name = random.choice(self.db.boss_names)
boss_mob = create.create_object("game.gamesrc.objects.world.mob.Mob", key="%s" % boss_name, location=self.location)
boss_mob.aliases = ['boss_mob']
boss_mob.db.level = self.location.db.level
boss_mob.db.rating = 'hero'
boss_mob.db.boss_mob = True
boss_mob.generate_stats()
boss_mob.generate_rewards()
boss_mob.generate_physical_loot()
boss_mob.generate_skillset()
boss_mob.update_stats()
return boss_mob
示例3: create_objects
def create_objects():
"""
Creates the #1 player and Limbo room.
"""
print " Creating objects (Player #1 and Limbo room) ..."
# Set the initial User's account object's username on the #1 object.
# This object is pure django and only holds name, email and password.
god_user = get_god_user()
# Create a Player 'user profile' object to hold eventual
# mud-specific settings for the bog standard User object. This is
# accessed by user.get_profile() and can also store attributes.
# It also holds mud permissions, but for a superuser these
# have no effect anyhow.
character_typeclass = settings.BASE_CHARACTER_TYPECLASS
# Create the Player object as well as the in-game god-character
# for user #1. We can't set location and home yet since nothing
# exists. Also, all properties (name, email, password, is_superuser)
# is inherited from the user so we don't specify it again here.
god_player = create.create_player(god_user.username, None, None, user=god_user)
god_character = create.create_object(character_typeclass, key=god_user.username)
god_character.id = 1
god_character.db.desc = _('This is User #1.')
god_character.locks.add("examine:perm(Immortals);edit:false();delete:false();boot:false();msg:all();puppet:false()")
god_character.permissions = "Immortals"
god_character.save()
god_player.set_attribute("_first_login", True)
god_player.set_attribute("_last_puppet", god_character)
god_player.db._playable_characters.append(god_character)
# Limbo is the default "nowhere" starting room
room_typeclass = settings.BASE_ROOM_TYPECLASS
limbo_obj = create.create_object(room_typeclass, _('Limbo'))
limbo_obj.id = 2
string = " ".join([
"Welcome to your new {wEvennia{n-based game. From here you are ready to begin development.",
"Visit http://evennia.com if you should need help or would like to participate in community discussions.",
"If you are logged in as User #1 you can create a demo/tutorial area with '@batchcommand contrib.tutorial_world.build'.",
"Log out and create a new non-admin account at the login screen to play the tutorial properly."])
string = _(string)
limbo_obj.db.desc = string
limbo_obj.save()
# Now that Limbo exists, try to set the user up in Limbo (unless
# the creation hooks already fixed this).
if not god_character.location:
god_character.location = limbo_obj
if not god_character.home:
god_character.home = limbo_obj
示例4: on_use
def on_use(self, caller):
manager = caller.db.spellbook
spells = manager.db.spells
if self.db.level_requirement is not None:
if caller.db.attributes['level'] < self.db.level_requirement:
caller.msg("{RYou are not high enough level to learn this spell.{n")
return
if 'heal' in self.db.spell:
if 'heal' not in spells.keys():
healing_spell_obj = create.create_object("game.gamesrc.objects.world.spells.Heal", key="Heal")
healing_spell_obj.db.character = caller
manager.add_item(healing_spell_obj.name.title(), healing_spell_obj)
caller.msg("{CYou have learned the spell: {G%s{n{C.{n" % healing_spell_obj.name)
else:
caller.msg("You already know that spell.")
if 'fireball' in self.db.spell:
if 'fireball' not in spells.keys():
fireball_spell_obj = create.create_object("game.gamesrc.objects.world.spells.Fireball", key="Fireball")
fireball_spell_obj.db.character = caller
manager.add_item(fireball_spell_obj.name, fireball_spell_obj)
caller.msg("{CYou have learned the spell: {G%s{n{C.{n" % fireball_spell_obj.name)
else:
caller.msg("You already know that spell.")
if 'mageshield' in self.db.spell:
if 'mage shield' not in spells.keys():
mageshield_spell_obj = create.create_object("game.gamesrc.objects.world.spells.MageShield", key="Mage Shield")
mageshield_spell_obj.db.character = caller
manager.add_item(mageshield_spell_obj.name, mageshield_spell_obj)
caller.msg("{CYou have learned the spell:{n {G%s{n{C.{n" % mageshield_spell_obj.name)
else:
caller.msg("You already know that spell.")
elif 'strength' in self.db.spell:
if 'strength of the bear' not in spells.keys():
strength_spell = create.create_object("game.gamesrc.objects.world.spells.StrOfBear", key="Strength Of The Bear")
strength_spell.db.character = caller
manager.add_item(strength_spell.name, strength_spell)
caller.msg("{CYou have learned the spell:{n {G%s{C.{n" % strength_spell.name)
else:
caller.msg("You alredy know that spell.")
elif 'magic missile' in self.db.spell:
if 'magic missile' not in spells.keys():
mm_spell = create.create_object("game.gamesrc.objects.world.spells.MagicMissile", key="Magic Missile")
mm_spell.db.character = caller
manager.add_item(mm_spell.name, mm_spell)
caller.msg("{CYou have learned the spell:{n {G%s{C.{n" % mm_spell.name)
else:
caller.msg("You alreadyg know that spell.")
caller.db.spellbook = manager
示例5: copy_object
def copy_object(self, original_object, new_key=None,
new_location=None, new_player=None, new_home=None,
new_permissions=None, new_locks=None, new_aliases=None, new_destination=None):
"""
Create and return a new object as a copy of the original object. All will
be identical to the original except for the arguments given specifically
to this method.
original_object (obj) - the object to make a copy from
new_key (str) - name the copy differently from the original.
new_location (obj) - if not None, change the location
new_home (obj) - if not None, change the Home
new_aliases (list of strings) - if not None, change object aliases.
new_destination (obj) - if not None, change destination
"""
# get all the object's stats
typeclass_path = original_object.typeclass_path
if not new_key:
new_key = original_object.key
if not new_location:
new_location = original_object.location
if not new_home:
new_home = original_object.home
if not new_player:
new_player = original_object.player
if not new_aliases:
new_aliases = original_object.aliases
if not new_locks:
new_locks = original_object.db_lock_storage
if not new_permissions:
new_permissions = original_object.permissions
if not new_destination:
new_destination = original_object.destination
# create new object
from src.utils import create
from src.scripts.models import ScriptDB
new_object = create.create_object(typeclass_path, key=new_key, location=new_location,
home=new_home, player=new_player, permissions=new_permissions,
locks=new_locks, aliases=new_aliases, destination=new_destination)
if not new_object:
return None
# copy over all attributes from old to new.
for attr in original_object.get_all_attributes():
new_object.set_attribute(attr.key, attr.value)
# copy over all cmdsets, if any
for icmdset, cmdset in enumerate(original_object.cmdset.all()):
if icmdset == 0:
new_object.cmdset.add_default(cmdset)
else:
new_object.cmdset.add(cmdset)
# copy over all scripts, if any
for script in original_object.scripts.all():
ScriptDB.objects.copy_script(script, new_obj=new_object.dbobj)
return new_object
示例6: setUp
def setUp(self):
"sets up testing environment"
self.room1 = create.create_object("src.objects.objects.Room", key="Room%i"%self.CID)
self.room1.db.desc = "room_desc"
self.room2 = create.create_object("src.objects.objects.Room", key="Room%ib"%self.CID)
self.obj1 = create.create_object("src.objects.objects.Object", key="Obj%i"%self.CID, location=self.room1, home=self.room1)
self.obj2 = create.create_object("src.objects.objects.Object", key="Obj%ib"%self.CID, location=self.room1, home=self.room1)
self.player = create.create_player("TestPlayer%i"%self.CID, "[email protected]", "testpassword", typeclass=TestPlayer, create_character=False)
self.caller = create.create_player("Caller%i"%self.CID, "[email protected]", "testpassword", player_dbobj=self.player.dbobj,
character_typeclass="src.objects.objects.Character",
permissions=["Immortals"], character_home=self.room1, character_location=self.room1)
self.caller.player = self.player
self.char = create.create_player("Char%i"%self.CID, "[email protected]", "testpassword2", typeclass=TestPlayer,
character_typeclass="src.objects.objects.Character",
permissions=["Immortals"], character_home=self.room1, character_location=self.room1)
self.char = create.create_script("src.scripts.scripts.Script", key="Script%i"%self.CID)
示例7: func
def func(self):
"create the new character"
player = self.player
if not self.args:
self.msg("Usage: @charcreate <charname> [= description]")
return
key = self.lhs
desc = self.rhs
if not player.is_superuser and \
(player.db._playable_characters and
len(player.db._playable_characters) >= MAX_NR_CHARACTERS):
self.msg("You may only create a maximum of %i characters." % MAX_NR_CHARACTERS)
return
# create the character
from src.objects.models import ObjectDB
start_location = ObjectDB.objects.get_id(settings.START_LOCATION)
default_home = ObjectDB.objects.get_id(settings.DEFAULT_HOME)
typeclass = settings.BASE_CHARACTER_TYPECLASS
permissions = settings.PERMISSION_PLAYER_DEFAULT
new_character = create.create_object(typeclass, key=key,
location=start_location,
home=default_home,
permissions=permissions)
# only allow creator (and immortals) to puppet this char
new_character.locks.add("puppet:id(%i) or pid(%i) or perm(Immortals) or pperm(Immortals)" %
(new_character.id, player.id))
player.db._playable_characters.append(new_character)
if desc:
new_character.db.desc = desc
elif not new_character.db.desc:
new_character.db.desc = "This is a Player."
self.msg("Created new character %s. Use {[email protected] %s{n to enter the game as this character." % (new_character.key, new_character.key))
示例8: debug_object_scripts
def debug_object_scripts(obj_path, caller):
"""
Create an object and test all its associated scripts
independently.
"""
try:
string = "\n Testing scripts on {w%s{n ... " % obj_path
obj = create.create_object(obj_path)
obj.location = caller.location
obj = obj.dbobj
string += "{gOk{n."
except Exception:
string += trace()
try: obj.delete()
except: pass
return string
scripts = obj.scripts.all()
if scripts:
string += "\n Running tests on %i object scripts ... " % (len(scripts))
for script in scripts:
string += "\n {wTesting %s{n ..." % script.key
path = script.typeclass_path
string += debug_script(path, obj=obj)
#string += debug_run_script(path, obj=obj)
else:
string += "\n No scripts defined on object."
try:
obj.delete()
except:
string += trace()
return string
示例9: _create_character
def _create_character(session, new_player, typeclass, start_location, home, permissions):
"""
Helper function, creates a character based on a player's name.
This is meant for Guest and MULTISESSION_MODE < 2 situations.
"""
try:
if not start_location:
start_location = home # fallback
new_character = create.create_object(typeclass, key=new_player.key,
location=start_location, home=home,
permissions=permissions)
# set playable character list
new_player.db._playable_characters.append(new_character)
# allow only the character itself and the player to puppet this character (and Immortals).
new_character.locks.add("puppet:id(%i) or pid(%i) or perm(Immortals) or pperm(Immortals)" %
(new_character.id, new_player.id))
# If no description is set, set a default description
if not new_character.db.desc:
new_character.db.desc = "This is a Player."
# We need to set this to have @ic auto-connect to this character
new_player.db._last_puppet = new_character
except Exception, e:
session.msg("There was an error creating the Character:\n%s\n If this problem persists, contact an admin." % e)
logger.log_trace()
return False
示例10: generate_contents
def generate_contents(self):
loot_generator = create.create_object("game.gamesrc.objects.world.generators.LootGenerator", location=self)
rn = random.random()
if rn < .05:
rare_item = loot_generator.create_rare_lootset()
else:
rn = random.randrange(1,4)
loot_set = loot_generator.create_loot_set(item_type='mixed', number_of_items=rn, loot_rating='average')
for item in loot_set:
item.move_to(self, quiet=True)
loot_generator.delete()
示例11: setUp
def setUp(self):
"sets up testing environment"
settings.DEFAULT_HOME = "#2"
# print "creating player %i: %s" % (self.CID, self.__class__.__name__)
self.player = create.create_player(
"TestPlayer%i" % self.CID, "[email protected]", "testpassword", typeclass=TestPlayerClass
)
self.player2 = create.create_player(
"TestPlayer%ib" % self.CID, "[email protected]", "testpassword", typeclass=TestPlayerClass
)
self.room1 = create.create_object("src.objects.objects.Room", key="Room%i" % self.CID, nohome=True)
self.room1.db.desc = "room_desc"
self.room2 = create.create_object("src.objects.objects.Room", key="Room%ib" % self.CID)
self.obj1 = create.create_object(TestObjectClass, key="Obj%i" % self.CID, location=self.room1, home=self.room1)
self.obj2 = create.create_object(TestObjectClass, key="Obj%ib" % self.CID, location=self.room1, home=self.room1)
self.char1 = create.create_object(
TestCharacterClass, key="Char%i" % self.CID, location=self.room1, home=self.room1
)
self.char1.permissions.add("Immortals")
self.char2 = create.create_object(
TestCharacterClass, key="Char%ib" % self.CID, location=self.room1, home=self.room1
)
self.char1.player = self.player
self.char2.player = self.player2
self.script = create.create_script("src.scripts.scripts.Script", key="Script%i" % self.CID)
self.player.permissions.add("Immortals")
# set up a fake session
global SESSIONS
session = ServerSession()
session.init_session("telnet", ("localhost", "testmode"), SESSIONS)
session.sessid = self.CID
SESSIONS.portal_connect(session.get_sync_data())
SESSIONS.login(SESSIONS.session_from_sessid(self.CID), self.player, testmode=True)
示例12: generate_zone_manager
def generate_zone_manager(self):
self.db.dungeon_type_picked = random.choice(self.db.dungeon_types)
zone = create.create_object('game.gamesrc.objects.world.rooms.Zone', key="%s Zone Manager" % self.db.dungeon_type_picked.title())
zone.db.zone_type = self.db.dungeon_type_picked
mg = zone.db.mob_generator
mg.db.dungeon_type = self.db.dungeon_type_picked
zone.db.mob_generator = mg
zone.aliases = ['zone_runner']
zone.db.zone_name = '%s' % self.db.dungeon_type_picked.title()
zone.db.is_dungeon = True
zone.db.quest_items = ['Deity Seal']
self.db.zone = zone
self.refresh_level()
zone.db.zone_level = "%s;%s" % (self.db.level, (self.db.level + 3))
示例13: at_start
def at_start(self):
self.obj.db.in_combat = True
self.db.unbalanced_message_sent = False
cm = create.create_object("game.gamesrc.objects.world.combat.CombatManager", key="%s_combat_manager" % self.obj.name)
if self.obj.db.cmd_id is not None:
cm = self.obj.db.cm_id
cm.delete()
self.obj.db.cm_id = cm
cm.db.rounds = 0
cm.attacker = self.obj
cm.attacker_queue = self.obj.db.combat_queue
cm.defender = self.obj.db.target
cm.defender_queue = cm.defender.db.combat_queue
cm.generate_texts()
示例14: at_repeat
def at_repeat(self):
rn = random.random()
check = self.obj.search("Treasure Chest", global_search=False)
if check is None:
pass
else:
return
if self.db.chest_spawn_attempt is False:
if rn < AVCONFIG['chest_spawn_rate']:
chest = create.create_object("game.gamesrc.objects.world.storage.StorageItem", key="Treasure Chest")
chest.location = self.obj
chest.generate_contents()
self.db.chest_spawn_attempt = True
else:
self.db.chest_spawn_attempt = False
示例15: new_player
def new_player(name, email, password, request):
"""
Easier front-end for creating a new player. Also sends reg email.
"""
player = create_player(key=name, email=email, password=password,
permissions=settings.PERMISSION_PLAYER_DEFAULT,
typeclass=settings.BASE_PLAYER_TYPECLASS)
player.is_active = False
player.save()
character = create_object(typeclass=settings.BASE_CHARACTER_TYPECLASS, key=name,
permissions=settings.PERMISSION_PLAYER_DEFAULT, home=settings.CHARACTER_DEFAULT_HOME)
character.db.spirit = player
player.db.avatar = character
player.db._last_puppet = character
player.db._playable_characters = [ character ]
character.locks.add("puppet:id(%i) or pid(%i) or perm(Immortals) or pperm(Immortals)" % (character.id, player.id))
character.new_character()
send_activation_email(player, request)