def detect_enemy(): # enemy detected? enemy = None if random() > 0.2: enemy_odds = [] for k, v in gamestate._enemies.items(): #print k, v.keys(), v["appear_prob"] if v.get("location", ident("random"))() == "random": odds_vec = [k] * int(v.get("appear_prob", 0) * 100) enemy_odds.extend(odds_vec) enemy_type = sample(enemy_odds, 1)[0] enemy_d = gamestate._enemies[enemy_type] enemy = Actor(enemy_type, enemy_d) return enemy
def detect_enemy() : # enemy detected? enemy = None if random() > 0.2 : enemy_odds = [] for k,v in gamestate._enemies.items() : #print k, v.keys(), v["appear_prob"] if v.get("location",ident("random"))() == "random" : odds_vec = [k]*int(v.get("appear_prob",0)*100) enemy_odds.extend(odds_vec) enemy_type = sample(enemy_odds,1)[0] enemy_d = gamestate._enemies[enemy_type] enemy = Actor(enemy_type,enemy_d) return enemy
def __str__(self): if self.defeated: return actor_d.get("dead", ident(""))() return actor_d.get("description", ident(""))()
import time, sys, art from random import random, randint, sample import gamestate from util import prompt, ident _enemies = {} _enemy_odds_list = [] _enemy_defaults = { "location": None, "hp": 0, "base_damage": 0, "value": 0, "article": "", "art": ident("UNKNOWN"), "appear_prob": 0, "dead": "Whatever it is, it's dead." } class Actor(object): def __init__(self, name, actor_d): self.name = name for k, v in _enemy_defaults.items(): setattr(self, k, actor_d.get(k, v)) self.art = eval("art.%s" % self.art()) self.defeated = self.hp <= 0 def hit(self, damage): self.hp -= damage if self.hp <= 0:
def __str__(self) : if self.defeated : return actor_d.get("dead",ident(""))() return actor_d.get("description",ident(""))()
import time, sys, art from random import random, randint, sample import gamestate from util import prompt, ident _enemies = {} _enemy_odds_list = [] _enemy_defaults = { "location": None , "hp": 0 , "base_damage": 0 , "value": 0 , "article": "" , "art": ident("UNKNOWN") , "appear_prob": 0 , "dead": "Whatever it is, it's dead." } class Actor(object) : def __init__(self,name,actor_d) : self.name = name for k,v in _enemy_defaults.items() : setattr(self,k,actor_d.get(k,v)) self.art = eval("art.%s"%self.art()) self.defeated = self.hp <= 0 def hit(self,damage) : self.hp -= damage if self.hp <= 0 :