Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.51 KB | None | 0 0
  1. import random
  2. random.seed()
  3.  
  4. class loot():
  5.  
  6. def __init__(self,item,Qty,drop_chance):
  7. self.item=item
  8. self.Qty=Qty
  9. self.drop_chance=drop_chance
  10.  
  11. class new_area():
  12.  
  13. def __init__(self):
  14. self.enemy_list=[]
  15. self.extra_zone=""
  16. def name(self,name):
  17. self.name=name
  18. def tooltip(self,tooltip):
  19. self.tooltip=tooltip
  20. def faction(self,faction):
  21. self.faction=faction
  22. def total_enemies(self,total_enemies):
  23. self.total_enemies=total_enemies
  24. def add_enemy(self,enemy):
  25. self.enemy_list.append(enemy)
  26. def add_extra_zone(self,zone,chance):
  27. self.extra_zone=zone
  28. self.extra_zone_chance=chance
  29. def add_extra_loot(self,item,Qty):
  30. self.extra_item=item
  31. self.extra_item_Qty=Qty
  32.  
  33. def mission(self,*user_database):
  34. encounter=0
  35. final_loot=[]
  36. enemies_slain=[]
  37. display_enemies_slain=[]
  38. display_final_loot=[]
  39. while encounter<self.total_enemies:
  40.  
  41. for enemies_found in range(len(self.enemy_list)):
  42. random_chance=random.uniform(0,100)
  43. if random_chance<=self.enemy_list[enemies_found].spawn_chance:
  44. encounter+=1
  45. if not enemies_slain: #enemies_slain is empty
  46. enemies_slain.append([self.enemy_list[enemies_found],1])
  47. display_enemies_slain.append([self.enemy_list[enemies_found].name,1])
  48. else:
  49. checked=False
  50. for elements in range(len(enemies_slain)):
  51. if enemies_slain[elements][0].name==self.enemy_list[enemies_found].name:
  52. checked=True
  53. enemies_slain[elements][1]+=1
  54. display_enemies_slain[elements][1]+=1
  55. if checked==False:
  56. enemies_slain.append([self.enemy_list[enemies_found],1])
  57. display_enemies_slain.append([self.enemy_list[enemies_found].name,1])
  58.  
  59. ## loot
  60. aux_loot=self.enemy_list[enemies_found].loot_bag
  61. for row in range(len(aux_loot)):
  62. random_chance=random.uniform(0,100)
  63. if random_chance<=aux_loot[row].drop_chance:
  64. if not final_loot: #final_loot is empty
  65. final_loot.append([aux_loot[row].item,aux_loot[row].Qty])
  66. display_final_loot.append([aux_loot[row].item.name,aux_loot[row].Qty])
  67. else:
  68. checked=False
  69. for elements in range(len(final_loot)):
  70. if final_loot[elements][0].name==aux_loot[row].item.name:
  71. checked=True
  72. final_loot[elements][1]+=aux_loot[row].Qty
  73. display_final_loot[elements][1]+=aux_loot[row].Qty
  74. if checked==False:
  75. final_loot.append([aux_loot[row].item,aux_loot[row].Qty])
  76. display_final_loot.append([aux_loot[row].item.name,aux_loot[row].Qty])
  77. ##main zone completed
  78.  
  79. print(display_enemies_slain)
  80. #print(enemies_slain)
  81. print(display_final_loot)
  82. #print(final_loot) #save this in user inventory
  83.  
  84. ##extra zone found ##
  85.  
  86. if self.extra_zone: # no empty
  87. random_chance=random.uniform(0,100)
  88. if random_chance<=self.extra_zone_chance:
  89. print("you found a new area: ",self.extra_zone.name)
  90. if self.extra_zone.total_enemies!=0:
  91. self.extra_zone.mission()
  92. else: #if theres no enemy that means is a Treasure room or chest or whatever
  93. item=self.extra_zone.extra_item #save this in user inventory
  94. Qty=self.extra_zone.extra_item_Qty
  95. print("you got %s %s"%(item.name,Qty))
  96.  
  97.  
  98. class new_enemy():
  99.  
  100. def __init__(self):
  101. self.loot_bag=[]
  102. def name(self,name):
  103. self.name=name
  104. def spawn_chance(self,spawn_chance):
  105. self.spawn_chance=spawn_chance
  106. def id(self,id_):
  107. self.id=id_
  108. def add_loot(self,item,Qty,drop_chance):
  109. #self.loot.append([item,Qty,drop_chance])
  110. self.loot_bag.append(loot(item,Qty,drop_chance))
  111. def get_loot(self):
  112. return self.loot_bag
  113.  
  114. class new_item():
  115. def name(self,name):
  116. self.name=name
  117. def id(self,id_):
  118. self.id=id_
  119. def craftable(self,craftable):
  120. self.craftable=craftable
  121. def rarity(self,rarity):
  122. self.rarity=rarity
  123. def damage(self,damage):
  124. self.damage=damage
  125. def defense(self,defense):
  126. self.defense=defense
  127. def tooltip(self,tooltip):
  128. self.tooltip=tooltip
  129.  
  130. crystal = new_item()
  131. crystal.name="Crystal"
  132. crystal.id="0"
  133. crystal.craftable=True
  134.  
  135. metal = new_item()
  136. metal.name="Metal"
  137. metal.id="1"
  138. metal.craftable=True
  139.  
  140. steel = new_item()
  141. steel.name="Steel"
  142. steel.id="2"
  143. steel.craftable=True
  144.  
  145. pirate = new_enemy()
  146. pirate.spawn_chance=100
  147. pirate.name="pirate"
  148. pirate.add_loot(crystal,5,100)
  149. pirate.add_loot(metal,10,100)
  150.  
  151. pirate_champion = new_enemy()
  152. pirate_champion.spawn_chance=50
  153. pirate_champion.name="pirate champion"
  154. pirate_champion.add_loot(crystal,15,100)
  155. pirate_champion.add_loot(metal,20,100)
  156.  
  157. pirate_capitan = new_enemy()
  158. pirate_capitan.spawn_chance=100
  159. pirate_capitan.name="pirate capitan 'Jack Sparrow' "
  160. pirate_capitan.add_loot(crystal,500,100)
  161.  
  162. earth = new_area()
  163. earth.add_enemy(pirate)
  164. earth.add_enemy(pirate_champion)
  165.  
  166. pirate_base_sub = new_area()
  167. pirate_base_sub.name = "treasure Room"
  168. pirate_base_sub.total_enemies=0
  169. pirate_base_sub.add_extra_loot(crystal,1000)
  170.  
  171. earth_sub_area = new_area()
  172. earth_sub_area.total_enemies=1
  173. earth_sub_area.name="Pirate Base"
  174. earth_sub_area.add_enemy(pirate_capitan)
  175. earth_sub_area.add_extra_zone(pirate_base_sub,50)
  176.  
  177. earth.name="earth"
  178. earth.total_enemies=20
  179. earth.add_extra_zone(earth_sub_area,50)
  180. earth.mission()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement