def func(self): caller = self.caller opts = self.opts if opts.loc: location = caller.search(opts.loc, global_search=True) if not location: caller.msg("Destination not found.") return else: location = caller.location existing = search_script("EnvScript", obj=location) if opts.type == "init": if len(existing) > 0: caller.msg("An EnvScript already exists.") return script = create_script(EnvScript, obj=location, key="EnvScript") elif len(existing) == 1: script = existing[0] elif len(existing) == 0: caller.msg("No script found.") return else: caller.msg("Error: multiple scripts found.") return if opts.type == "init" or opts.type == "edit": def _env_load(caller): return "\n".join(script.db.messages) def _env_save(caller, buffer): script.db.messages = buffer.splitlines() caller.msg("Messages saved.") return caller.msg("Please place one message on each line.") EvEditor(caller, loadfunc=_env_load, savefunc=_env_save, key="Save messages: :w") if opts.type == "status": caller.msg("The script is operational.") if opts.type == "rm": script.delete() caller.msg("Script deleted.")
def find(iString, statclass=''): """ find Returns a list of data scripts which begin with iString. If statclass is specified the list is restricted to those whose type begins with statclass. """ d = search_script_tag('dictionary_data')[0] if not hasattr(d, 'dictionary'): d.at_start() matches = [] if iString.lower() in d.dictionary: stats = d.dictionary[iString.lower()] for stat in stats: typeclass = stat[1][0:len(statclass)].lower() if statclass == '': matches.append(search_script('#' + str(stat[2]))[0]) elif typeclass == statclass.lower(): matches.append(search_script('#' + str(stat[2]))[0]) return matches
def editted(request): user = request.user if user.is_staff: if request.method == 'POST': form = editForm(request.POST) if form.is_valid(): n = form.cleaned_data['link'] try: dictionary = search_script_tag('dictionary_data')[0] except IndexError: raise Http404("I couldn't find a character with that ID.") stats = [] for item in dictionary.dictionary[n]: if item[1] == 'devotion': script = search_script('#' + str(item[2]))[0] stats.append(script) if len(stats) == 0: return render(request, 'devotions/error.html', { 'message': len(data) + ' No matching devotions: ' + n }) if len(stats) > 1: return render(request, 'devotions/error.html', {'message': 'Too many matching devotions'}) devotion = stats[0] app = devotion.update( longname=form.cleaned_data['longname'], cost=int(form.cleaned_data['cost']), prereq=form.cleaned_data['prereq'], reference=form.cleaned_data['reference'], info=form.cleaned_data['info'], restricted=form.cleaned_data['restricted']) return HttpResponseRedirect('/devotions/view/' + quote(n)) else: return render(request, 'devotions/error.html', {'message': 'Invalid form'}) else: return render(request, 'devotions/error.html', {'message': 'Not POST'}) else: return render(request, 'devotions/error.html', {'message': 'Not staff'})
def sheet(request, object_id): object_id = unquote(object_id).lower() try: dictionary = search_script_tag('dictionary_data')[0] except IndexError: raise Http404("I couldn't find a character with that ID.") data = [] for item in dictionary.dictionary[object_id]: if item[1] == 'devotion': script = search_script('#' + str(item[2]))[0] data.append(script) stats = [] for stat in data: if stat.db.longname[0:len(object_id)].lower() == object_id.lower(): stats.append(stat) if len(stats) == 0: return render(request, 'devotions/error.html', {'message': 'No matching devotions: ' + object_id}) if len(stats) > 1: return render(request, 'devotions/error.html', {'message': 'Too many matching devotions'}) devotion = devotion_class() longname = stats[0].db.longname cost = stats[0].db.cost prereq = stats[0].db.prereq reference = stats[0].db.reference if stats[0].db.info: info = stats[0].db.info.replace('|/', '\n') else: info = chr(160) restricted = stats[0].db.restricted devotion.update(longname, cost, prereq, reference, info, restricted) if request.method == 'POST': return render(request, 'devotions/error.html', {'message': 'POST'}) return render(request, 'devotions/sheet.html', { 'devotion': devotion, 'request': request, 'id': quote(object_id) })
def editor(request, object_id): object_id = unquote(object_id).lower() try: dictionary = search_script_tag('dictionary_data')[0] except IndexError: raise Http404("I couldn't find a character with that ID.") data = [] for item in dictionary.dictionary[object_id]: if item[1] == 'devotion': script = search_script('#' + str(item[2]))[0] data.append(script) stats = [] for stat in data: if stat.db.longname[0:len(object_id)].lower() == object_id.lower(): stats.append(stat) if len(stats) == 0: return render(request, 'devotions/error.html', {'message': 'No matching devotions'}) if len(stats) > 1: return render(request, 'devotions/error.html', {'message': 'Too many matching devotions'}) devotion = stats[0] starting_data = { 'longname': devotion.db.longname, 'cost': devotion.db.cost, 'prereq': devotion.db.prereq, 'reference': devotion.db.reference, 'info': devotion.db.info, 'restricted': devotion.db.restricted, 'link': object_id } form = editForm(initial=starting_data) return render(request, 'devotions/editor.html', { 'form': form, 'devotion_id': object_id })
def func(self): args = self.args.strip().split() if not args: self.caller.msg("Craft what?") return items = list() action = args.pop(0).lower() if action not in ["add", "remove", "recipe", "cancel"]: self.caller.msg("Invalid syntax.") return if action in ["add", "remove"]: args = " ".join(args).split(",") for item in args: items.append(item.strip()) self.items = items self.action = action caller = self.caller recipe_script = search_script("recipescript", typeclass="world.recipescript.RecipeScript") try: recipe_script = recipe_script[0] except IndexError: recipe_script = create_script(key="recipescript", typeclass="world.recipescript.RecipeScript") if self.action == "add": for _item in self.items: item = caller.search(_item, location=caller) if not item: continue if item.tags.get(category="craftable"): caller.db.craft_stack.append(item) caller.msg("Added '%s' to the crafting stack..." % item) elif self.action == "remove": pass elif self.action == "cancel": pass elif self.action == "recipe": inv = [] recipe_name = self.args.strip() for item in caller.db.craft_stack: tag = item.tags.get(category="craftable") if type(tag) is type(""): inv.append(tag.lower()) elif type(tag) is type([]): inv.extend(t.lower() for t in tag) found_recipe = None for recipe in recipe_script.recipes: for recipe_key in recipe.keys(): if recipe_key == recipe_name: found_recipe = recipe break if found_recipe: break if not found_recipe: caller.msg("No such recipe.") recipe = found_recipe missing = [] for comp in recipe["components"]: for needed_count in recipe["components"][comp] inv_count = inv.count(comp) if inv_count < needed_count: # missing ingredients missing.append((comp, needed_count - inv_count)) else: # we have all we need of this ingredient pass if len(missing) > 0: for row in missing: caller.msg("You are missing %s %s." % row) return for component in recipe['components']: for c in range(recipe['components'][component]): # remove component from caller for item in self.caller.db.craft_stack: if item.tags.get(component, category="crafting"): caller.db.craft_stack.remove(item) # item.delete() # _item = caller.search("#%i" % item.id, use_dbref=True, quiet=True) # if _item: # _item.pop().delete() obj = create_object(key=recipe_name, typeclass=recipe['typeclass'], location=caller) caller.msg("You crafted %s." % obj)