def __init__(self, draw_fn, map_obj, skill: Skill, species_id: int, reproduction_chance: int): assert (reproduction_chance <= BASE_CHANCE) this = self self._exists = True map_obj.add_species_member(species_id) #member thread keeps moving until killed def member_thread(): while self._exists: # If we were killed while sleeping then exit thread. with map_obj.lock: if not self._exists: # If we were killed while waiting for lock then exit thread. break if map_obj.is_game_over: # If the game is over and we're not dead then exit thread. break this.move(map_obj) map_obj.check_game_over() max_sleep_int = 10-this.skill.speed if 10-this.skill.speed > 0 \ else 0 min_sleep_int = 10-this.skill.speed-2 if 10-this.skill.speed-2 \ > 0 else 0 #length of sleep before next move based on member speed sleep(uniform(min_sleep_int, max_sleep_int) / SIM_SPEED_MULT) self._thread = Thread(target=member_thread) self._draw_fn = draw_fn #stored for reproduced species to have same initial skill self.init_skill = skill.copy() self.skill = skill.copy() self.species_id = species_id self.repr_chc = reproduction_chance self.moves = [(1, 0), (-1, 0), (0, 1), (0, -1)]
def approveSkillAuth(): email = request.form['email'] skillname = request.form['skillname'] Skill.approveSkill(conn, email, skillname) return redirect(url_for('admin'))
def backgroundCheckAuth(): if not session.get('account'): return redirect(url_for('index')) email = session['account']['email'] skills = request.form.getlist('skill') for skill in skills: Skill.applySkill(conn, email, skill) return redirect(url_for('backgroundCheck'))
def backgroundCheck(): session['message'] = None if (session.get("account") is None or session['account']['accounttype'] != "WORKER"): return render_template('error.html') remainingSkills = Skill.getRemainingSkills(conn, session['account']['email']) pendingSkills = Skill.getPendingSkills(conn, session['account']['email']) approvedSkills = Skill.getApprovedSkills(conn, session['account']['email']) return render_template('backgroundcheck.html', remainingSkills=remainingSkills, pendingSkills=pendingSkills, approvedSkills=approvedSkills)
def cast(self): if (self.cooldown_timer >= self.cooldown): self.cooldown_timer = 0 skill = Skill(self) return skill else: return False
def __init__(self, radiu, unit, index): self.kind = Skill.AFTER_TAKE_DAMAGE() self.unit = unit self.range = unit.AI.NEAR_RANGE(radiu)#攻击范围 self.index = index#技能在角色身上的欄位索引 self.coolDown = 4.0 self.cdTime = 0#当前技能的剩余冷却时间
def __init__(self,radiu,unit,index): self.kind=Skill.AFTER_SKILL() self.attack=True#是否是角色的基本攻击 self.range=unit.AI.FAR_RANGE(radiu)#攻击范围 self.unit=unit self.index=index#技能在角色身上的欄位索引 self.traget=None
def max_skill(self, method="xp"): ninf = -float("inf") max_skill = Skill("attack", xp=ninf, rank=ninf) for skill in self.skills.values(): if getattr(skill, method) > getattr(max_skill, method): max_skill = skill return max_skill
def max_skill(self, method='xp'): ninf = -float('inf') max_skill = Skill('attack', xp=ninf, rank=ninf) for skill in self.skills.values(): if getattr(skill, method) > getattr(max_skill, method): max_skill = skill return max_skill
def min_skill(self, method='xp'): inf = float('inf') min_skill = Skill('attack', xp=inf, rank=inf) for skill in self.skills.values(): if getattr(skill, method) < getattr(min_skill, method): min_skill = skill return min_skill
def closest_skill(self): closest = Skill('attack') closest_xp_tnl = float('inf') for skill in self.skills.values(): if skill.xp_tnl() < closest_xp_tnl: closest_xp_tnl, closest = skill.xp_tnl(), skill return closest
def add_to_character_library(library, list_name, n): l = file_cache.get("LIST: " + list_name) if not l: return skills = json.loads(l) for skill in skills: s = Skill.from_dict(skill) library[s.get_name(n)] = list_name
def __init__(self,radiu,unit,index): self.coolDown=5.0#技能冷却时间 self.cdLeft=0#当前技能的剩余冷却时间 self.kind=Skill.ACTIVE() self.attack=True#是否是角色的基本攻击 self.range=unit.AI.NEAR_RANGE(radiu)#攻击范围 self.unit=unit self.index=index#技能在角色身上的欄位索引
def min_skill(self, method="xp"): inf = float("inf") min_skill = Skill("attack", xp=inf, rank=inf) for skill in self.skills.values(): if getattr(skill, method) < getattr(min_skill, method): min_skill = skill return min_skill
def main(): # print ("start") pygame.init() # print("start init") pygame.display.set_caption(Constant.GAME_NAME) # print("start caption") font = pygame.font.Font(Constant.FONT_NAME, Constant.FONT_SIZE) # print("start font") screen = pygame.display.set_mode( (Constant.SCREEN_WIDTH, Constant.SCREEN_HEIGHT)) screen.fill(Constant.WHITE) villager_images = [] # load all skill images group them with image name and image object skill_images = {(image_file_name.split("/")[-1]).split(".")[0]: pygame.image.load(image_file_name) for image_file_name in Constant.SKILL_IMAGES} # print(skill_images.items()) skills = {} debug_print(str(skill_images)) # load all villager's image, girl and boy for image in Constant.VILLAGER_IMAGES: villager_images.append(pygame.image.load(image)) # load player's image player_image = pygame.image.load(Constant.PLAYER_IMAGE) # load monster's image monster_image = pygame.image.load(Constant.MONSTER_IMAGE) # set the clock in pygame, so later on we could adjust the Frame Rate Per Second clock = pygame.time.Clock() # each villager is is a thread to consuming their own JSON data villager_connections = [] # start visualization listening socket listener = ConnectionListener(villager_connections) listener.daemon = True listener.start() index = 0 for skill_name, skill_image in skill_images.items(): # discard the suffix skills[skill_name.split(".")[0]] = Skill( skill_name.split(".")[0], skill_image, Constant.SCREEN_WIDTH - (((skill_image.get_rect().size)[0] * Constant.SKILL_IMAGE_SCALE) / 2), 50 + index * ((skill_image.get_rect().size)[0] * Constant.SKILL_IMAGE_SCALE), Constant.SKILL_IMAGE_SCALE, applied=False, greyed=False) index += 1 player = Player(player_image, Constant.SAGE_POSITION[0], Constant.SAGE_POSITION[1]) surface = pygame.Surface((Constant.SCREEN_WIDTH, Constant.SCREEN_HEIGHT)) start_game(screen, font, villager_images, monster_image, skills, skill_images, clock, villager_connections, player, surface) listener.close_socket()
def set_skills_to_hero(hero, db): t = pypika.Table('skills_on_chars') q = pypika.Query.from_(t).select('*').where(t.char_ == hero.id).get_sql() q = '''SELECT s.id, s.name, s.cost, s.dmg, s.on_self, s.lvl_impr, s.type, s.duration, s.asset FROM skills as s JOIN skills_on_chars as skc on s.id = skc.skill WHERE skc.char_=''' + str( hero.id) res = db.select(q) for r in res: hero.skills.append( Skill(r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], make_pygame_image(r[8])))
def load(self) -> LoadedSkills: skills = list( map( lambda skill: Skill( skill["id"], skill["name"], list( map( lambda skill_rank: SkillRank( skill_rank["id"], skill_rank["skill"], skill_rank["skillName"], skill_rank["level"]), skill["ranks"]))), self.raw_json)) return LoadedSkills({skill.id: skill for skill in skills})
def use_skill(self, index): skill_ID = self.skills[index] if database(skill_ID, "Name") == "诅咒": if "幽灵" in self.系: channel = 0 else: channel = 1 else: channel = 0 self._parent_game.enemy_of(self) skill = Skill(self._parent_game, skill_ID, self, channel) self._parent_game.send_skill(self, skill)
def __init__(self,radiu,unit,index): #客制化属性 self.coolDown=1.5#技能冷却时间 self.cdLeft=1.5#当前技能的剩余冷却时间 self.damageKind=Damage.MAGIC_DAMAGE() self.damageNum=10 self.missileSpeed=5 #固有代码 self.kind=Skill.ACTIVE() self.attack=True#是否是角色的基本攻击 self.range=unit.AI.FAR_RANGE(radiu)#攻击范围 self.unit=unit self.index=index#技能在角色身上的欄位索引
def __init__(self,radiu,unit,index): #子类别客制化属性 self.coolDown=1.0#技能冷却时间 self.cdLeft=1.0#当前技能的剩余冷却时间 self.damageKind=Damage.NORMAL_DAMAGE() self.damageNum=10 self.timeBefore=0.2 #固有代码 self.kind=Skill.ACTIVE() self.attack=True#是否是角色的基本攻击 self.range=unit.AI.NEAR_RANGE(radiu)#攻击范围 self.unit=unit self.index=index#技能在角色身上的欄位索引
def create_world(): global player, tile, background, bullets, portal, mushes, skill, mushskills, restart restart = Restart() mushes = [Mush() for i in range(5)] mushskills = Mushskill() skill = Skill() portal = Portal() player = Player() player.life = temp.player_life tile = Tile() background = Background() bullets = list() player.x, player.y = 50, 210
def jobBoard(): session['message'] = None #Only WORKER can access the job board if (session.get("account") is None or session['account']['accounttype'] != "WORKER"): return render_template('error.html') email = session['account']['email'] approvedSkills = Skill.getApprovedSkills(conn, email) jobs = None return render_template('jobboard.html', jobs=jobs, approvedSkills=approvedSkills)
def init_map(self): '''Creates members of each species, with random attributes characteristic to each species. Places members and resources on the map.''' for i in range(self.num_members): #Creates members of species user is rooting for. skill= Skill(strength=self.user_strength, speed=self.user_speed) m = Member( draw_fn=self.draw, map_obj=self.map_obj, skill=skill, species_id=0, reproduction_chance=BASE_CHANCE//10) pos = choice(list(self.pos_set)) self.pos_set.remove(pos) self.map_obj.add(m, pos) for i in range(1, self.num_species): for j in range(self.num_members): skill=Skill(strength=uniform(0,10), speed=uniform(0,3)) m = Member( draw_fn=self.draw, map_obj=self.map_obj, skill=skill, species_id=i, reproduction_chance=BASE_CHANCE//10) pos = choice(list(self.pos_set)) self.pos_set.remove(pos) self.map_obj.add(m, pos) for _ in range(self.num_resources): r = Resource( strength=1+random.random(), speed=1+random.random()) #Add extra types of skills to the resource at random if random.random() > 0.75: r.add_to_bag() pos = choice(list(self.pos_set)) self.pos_set.remove(pos) self.map_obj.add(r, pos)
def __init__(self): # Public properties self.name = input('Enter your character name: ') self.attack_damage = random.randint(8, 12) self.heal_amount = random.randint(8, 12) self.max_health = 100 self.health = self.max_health self.max_mana = 50 self.mana = self.max_mana self.level = 1 self.experience_point = 0 self.max_experience_point = 100 self.inventory = Inventory() self.skill = Skill(self)
def __init__( self, sp_name: str, sp_ele_type: str, wpn_type: str, skills: Sequence[dict], ): self.sp_name = sp_name self.sp_ele_type = sp_ele_type self.wpn_type = wpn_type self.skills = list(map(lambda skill: Skill(**skill), skills)) # assert sp_name assert (self.wpn_type in ('left', 'right')) assert (self.sp_ele_type in ('light', 'shadow', 'fire', 'water', 'no-element'))
def add_agent(self, idx, agent, verbose=False): skills = [ Skill(_id=skill['id'], exp=skill['exp'], mot=skill['mot']) for skill in agent['skillset'] ] mbti = agent['mbti'] if 'mbti' in agent else None initial_frustration = agent[ 'initial_frustration'] if 'initial_frustration' in agent else None self.agents.append( Agent(_id=idx, mbti=mbti, initial_frustration=initial_frustration, skillset=skills, verbose=verbose))
def _set_data(self): offset = 3 # first three are rank, total level, and total xp self.rank, self.total_level, self.total_xp = [ self._api_response[i] for i in range(offset) ] self.skills = {} for i in range(1, const.SKILLS_AMT + 1): index = offset * i skill, rank, level, xp = (const.SKILLS[i - 1], self._api_response[index], self._api_response[index + 1], self._api_response[index + 2]) self.skills[skill] = Skill(skill, rank, level, xp)
def add_skill(self, skill_name): """ Add skill Object to player's skill list :param skill_name: str """ skill_num = len(self.skills) image = self.skill_images[skill_name] # each row render four skill, then go up one_skill = Skill( skill_name, image, self.x - self.width / 2 - ((image.get_rect().size)[0] * Constant.SKILL_IMAGE_SCALE_VILLAGER) / 2, (self.y + self.height / 2) - (int(skill_num) * int( (image.get_rect().size)[1] * Constant.SKILL_IMAGE_SCALE_VILLAGER)), Constant.SKILL_IMAGE_SCALE_VILLAGER, False) self.skills.append(one_skill)
def searchJobAuth(): if not session.get('account'): return redirect(url_for('index')) email = session['account']['email'] approvedSkills = Skill.getApprovedSkills(conn, email) if ('jobType' not in request.form): return render_template('jobboard.html', jobs=None, approvedSkills=approvedSkills) if ('jobState' not in request.form): return render_template('jobboard.html', jobs=None, approvedSkills=approvedSkills) jobType = request.form['jobType'] jobState = request.form['jobState'] jobs = Job.getJobSearchResult(conn, jobType, jobState, email) return render_template('jobboard.html', jobs=jobs, approvedSkills=approvedSkills)
def __init__(self, name, duration = 0, cooldownPeriod = 0): Skill.__init__(self, name, cooldownPeriod) self.duration = duration
def skills(self): my_skills = Skill(self) my_skills.show_skills()
def update(self): Skill.update(self) if self.active: self.duration = self.duration - 1 if self.duration == 0: self.deactivate()