Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.72 KB | None | 0 0
  1. # you made a couple of different choices to select stats. but how to work from them?
  2. # So your NPC had a stat choice like "Bad (10,10,10,10,10,8)"  or random
  3. # first of all lets make it a bit more readable/handy
  4. # choices are:
  5. CHOICES = ['Bad', "Medium", "Random"]
  6.  
  7. # lets make a second dictionary with what that means
  8. STAT_CHOICES = {
  9.     "Bad": [10, 10, 10, 10, 10, 8],
  10.     "Medium": [14, 12, 12, 10, 10, 8],
  11.     "Random": True,
  12. }
  13.  
  14. # as you can see stats for not random is pretty straight forward, it list 6 stats in order
  15. # now how to assign them? Lets work from an npc thats been created
  16. import json
  17.  
  18. with open("NPC/location/name.json", 'r') as f:
  19.     npc = json.loads(f.read())
  20.    
  21.    
  22. stats = STAT_CHOICES[npc['ARRAY']]
  23. # what this does is load the stats from STAT_CHOICES from the value! of npc['ARRAY']
  24. # meaning npc['ARRAY'] returns 'Bad'
  25. # so the actual lookup is STAT_CHOICES['Bad']
  26. # so returns: [10, 10, 10, 10, 10, 8]
  27. # now you can come up with a way to assign the stats to an npc (hint you can also look at class
  28.  
  29. # remember lists and index?  lets put stats to a npc
  30. npc['STATS'] = {
  31.     "strength": stats[0],
  32.     "dexterity": stats[3],
  33.     "constitution": stats[4],
  34. }
  35.  
  36. # however this leaves us with Random. Those dont have stats, so how do we do this?
  37. # conditions come in handy here
  38. # before you start 'assigning' stats, it might be a good idea to check what you are dealing with
  39. # so lets go back to stats
  40. def get_random_stats():
  41.     import random
  42.     # come up with a way to get 6 random stats.
  43.     # random.randint(number, higher_number)  returns a value between number and higher number
  44.  
  45. if npc['ARRAY'] == "Random":
  46.     stats = get_random_stats()
  47. else:
  48.     stats = STAT_CHOICES[npc['ARRAY']]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement