def DetermineOutcomes(action) : global adv global char effects = {} if action == 0 : return effects action_data = adv.f['actions'][str(action)] all_outcomes = StripNonStates(action_data.keys()) try : effects.update(adv.f['actions'][str(action)]['effects']) except KeyError : pass #effects are optional if len(all_outcomes) == 1 : outcomes = all_outcomes else : evaluators = [argsolve.Solve(each) for each in action_data['evaluators']] outcomes = [x for x in all_outcomes if TestState(action_data[str(x)],evaluators)] if not outcomes : print "Nothing Happens\n" #This occurs if no outcomes match else : for outcome in outcomes : try : effects.update(adv.f['actions'][str(action)][outcome]['effects']) except KeyError : pass #effects are optional try : nonemptyprint(adv.f['actions'][action][outcome]) except KeyError : pass #text is optional try : char['Beats'] += adv.f['actions'][action][outcome]['duration'] except KeyError : pass #duration is optional return effects
def PrintAttributes(arguments) : global char global adv for attribute in char['Attributes'].keys() : firststate = (sorted(char['Attributes'][attribute][0][0] + char['Attributes'][attribute][0][1]))[0] #Merges the two state lists into 1, sorts them and takes the first numerically nonemptyprint(adv.f['attributes'][str(attribute)][str(firststate)])
def TakeAction(arguments) : action = arguments[0] nonemptyprint(adv.f['actions'][action]['outcomes'][outcome]) #Action text will be printed if it exists for effect in adv.f['actions'][action]['outcomes'][outcome]['effects'].keys() : #The line below runs the function requested by each effect of the chosen action and passes it any arguments from the Action. arguments = argparser.PrsArg(adv.f['actions'][action]['outcomes'][outcome]['effects'][effect]['variables']) eval(adv.f['actions'][action]['outcomes'][outcome]['effects'][effect]['function']+"(arguments)")
effects.append(statecheck.CheckAbilities()) for set in effects : for effect in set.keys() : effecthappened = True arguments = argsolve.Solve(set[effect]) eval("efunc."+effect+"(arguments)") if effecthappened or firstrun : firstrun = False continue #Restarts the primary loop early if an effect happens c.write() wlist = scenelist['white'] + encounterlist['white'] + abilitylist['white'] + itemlist['white'] + vitallist['white'] + attributelist['white'] blist = scenelist['black'] + encounterlist['black'] + abilitylist['black'] + itemlist['black'] + vitallist['black'] + attributelist['black'] glist = [act for act in dupremove(wlist) if act not in blist] #Creates a list which contains Whitelisted Actions (wlist) that are not Blacklisted (present in blist). These are the actions available to the player. efunc.GiveList(glist) while True : #Secondary loop. Below is run when anything is put into the prompt regardless of validity. nonemptyprint(a.f['scenes'][str(statecheck.scene)]) #Scene description will be printed if there is one for state in sorted(c['SceneStates'][str(statecheck.scene)][0] + c['SceneStates'][str(statecheck.scene)][1]) : nonemptyprint(a.f['scenes'][str(statecheck.scene)][str(state)]) nonemptyprint(a.f['encounters'][str(c['Encounters'][str(statecheck.scene)][0])]) #Encounter description will be printed if there is one for state in sorted(c['Encounters'][str(statecheck.scene)][1][0] + c['Encounters'][str(statecheck.scene)][1][1]) : nonemptyprint(a.f['encounters'][str(c['Encounters'][str(statecheck.scene)][0])][str(state)]) for vital in c['Vitals'].keys() : for state in sorted(c['Vitals'][vital][0][0] + c['Vitals'][vital][0][1]) : nonemptyprint(a.f['vitals'][vital][str(state)]) prompt = raw_input(">").strip() #The main prompt action = 0 try : #Effectively 'if input is a whole number' prompt = int(prompt) if prompt in glist : action = str(prompt) #If the input matches the UID of a valid action then take note of it's UID except ValueError : #Effectively 'if input isn't a whole number'