def __init__(self, playerstate, level, scale=1.0, L=10, item=None): self.level = level self.scale = scale L *= scale self.L = L # self.stardust = StarDust(scale) self.wireframe = WireFrame(scale) self.sky = Sky() self.player = Player(self, playerstate, Vector4D(0, 0, 0, L)) self.enemies = Enemies(self) types = [randint(0, level.types - 1)for i in xrange(level.enemy_num-1)] types += [level.types-1] for t in types: x = 6*L*(2.0*random()-1.0) y = 6*L*(2.0*random()-1.0) z = 6*L*(1.0*random()-2.0) self.enemies.add(Vector4D(0, x, y, z), t) self.stars = Stars(self, Vector4D(0.0, 0.0, -0.5*scale, L-3*scale), scale) if item is not None and item == playerstate.gun_num: self.item = Item(item, self.player.P.X+Vector4D(0, 0, 0.5*scale, -5*scale), scale) else: self.item = None self.score = 0
inventory=Inventory(capacity=0), level=Level(xp_given=35), ) troll: Actor = Actor( char="T", color=(0, 127, 0), name="Troll", ai_cls=HostileEnemy, fighter=Fighter(hp=16, defense=1, power=4), inventory=Inventory(capacity=0), level=Level(xp_given=100), ) health_potion = Item( char="!", color=(127, 0, 255), name="Health Potion", consumable=consumable.HealingConsumable(amount=4), ) lightning_scroll = Item( char="~", color=(255, 255, 0), name="Lightning Scroll", consumable=consumable.LightningDamageConsumable(damage=20, maximum_range=5), ) confusion_scroll = Item( char="~", color=(207, 63, 255), name="Confusion Scroll", consumable=consumable.ConfusionConsumable(number_of_turns=10),
def read_item(self, browser: selenium.webdriver.Chrome) -> (Item, None): """ method: Rely the supplied jd item detail page. the method format read in info and then return a item instance. :param browser: an instance of browser which includes Chrome/Edge/FireFox etc. cautiously, the browser current page must be a commodity detail page. :return: """ # TODO:有可能无货/链接无效 if not self.is_jd_detail_page(browser): logging.info("[JdDetailPageReader.read_item]" " Current page is't detail page:", browser.title) return None # 判断是否是详情页 item = Item() # 获取颜色标题及所选项目值 color_dom = self.get_color_dom(browser) if color_dom is not None and len(color_dom) != 0: color_title_str = color_dom[0].text # 获取标题 color_selected_str = color_dom[1].find_element(By.CLASS_NAME, "selected").text # 获取已选值 item.spec1 = color_title_str + '=' + color_selected_str else: # 某些单一款不需要选颜色 pass # 获取版本标题及所选项目值 edition_dom = self.get_edition_dom(browser) if edition_dom is not None and len(edition_dom) != 0: edition_title_str = edition_dom[0].text edition_selected_str = edition_dom[1].find_element(By.CLASS_NAME, "selected").text item.spec2 = edition_title_str + '=' + edition_selected_str else: # 说明不需要选择型号,或者说没有型号信息 pass # 获取商品url,可能因加载中等失败 try: item.url = browser.current_url except TimeoutException: logging.warning('Get url failed! at method:JdDetailReader.read_item()') return None # 获取价格 item.price = self.get_price(browser) if item.price == -1: logging.warning("JdDetailPageReader:Get price is -1\n" + item.url) return None # 获取plus会员价格 item.plus_price = self.get_plus_price(browser) # 领券 ticket_dom = self.get_ticket_dom(browser) if ticket_dom is not None and len(ticket_dom) != 0: ticket_str = '' for ti in ticket_dom: ticket_str += ti.text + '\n' item.ticket = ticket_str # 库存:京东不显示库存量,只有有无货之分 # 快递费:京东各省价格均不同,有货情况也不同故不做记录 # 销量 item.sales_amount = self.get_remark(browser) # 可选字段 # 生成所有字段 item.generate_all_specification() return item
def drop(self, item: Item) -> None: self.items.remove(item) item.place(self.parent.x, self.parent.y, self.gamemap) self.engine.message_log.add_message(f"You dropped the {item.name}.")
level=Level(xp_given=100), ) gunman = Actor( char="G", color=(0, 127, 0), name="Gunman", ai_cls=HostileEnemy, fighter=Fighter(hp=5, defense=0, power=1), inventory=Inventory(capacity=3), level=Level(xp_given=150), ) confusion_scroll = Item( char="~", color=(207, 63, 255), name="Stack of Money", consumable=consumable.ConfusionConsumable(number_of_turns=10), ) fireball_scroll = Item( char="~", color=(255, 0, 0), name="Molotov", consumable=consumable.FireballDamageConsumable(damage=12, radius=3), ) health_potion = Item( char="!", color=(144, 75, 6), name="A Cold One", consumable=consumable.HealingConsumable(amount=4),
orc = Actor(char="S", color=(63, 127, 63), name="Spoon", ai=HostileEnemy(), fighter=Fighter(hp=10, defense=0, power=3), inventory=Inventory(capacity=0)) troll = Actor(char="T", color=(0, 127, 0), name="Troll", ai=HostileEnemy(), fighter=Fighter(hp=16, defense=1, power=4), inventory=Inventory(capacity=0)) health_potion = Item(char="!", color=(255, 255, 255), name="HP Potion +4", consumable=HealthPotion(amount=4)) health_potion_medium = Item(char="!", color=(255, 255, 255), name="HP Potion +10", consumable=HealthPotion(amount=10)) health_potion_max = Item(char="!", color=(255, 255, 255), name="MAX HP Potion", consumable=HealthPotion(amount=100)) ConsumableItems = [health_potion, health_potion_medium, health_potion_max]
class World(object): def __init__(self, playerstate, level, scale=1.0, L=10, item=None): self.level = level self.scale = scale L *= scale self.L = L # self.stardust = StarDust(scale) self.wireframe = WireFrame(scale) self.sky = Sky() self.player = Player(self, playerstate, Vector4D(0, 0, 0, L)) self.enemies = Enemies(self) types = [randint(0, level.types - 1)for i in xrange(level.enemy_num-1)] types += [level.types-1] for t in types: x = 6*L*(2.0*random()-1.0) y = 6*L*(2.0*random()-1.0) z = 6*L*(1.0*random()-2.0) self.enemies.add(Vector4D(0, x, y, z), t) self.stars = Stars(self, Vector4D(0.0, 0.0, -0.5*scale, L-3*scale), scale) if item is not None and item == playerstate.gun_num: self.item = Item(item, self.player.P.X+Vector4D(0, 0, 0.5*scale, -5*scale), scale) else: self.item = None self.score = 0 def action(self, keys, ds): # self.player.worldline.reset() # for enemy in self.enemies: # enemy.worldline.reset() n = int(ds * 10.0) + 1 ds /= n count = 0 while count < n: self.player.action(keys, ds) self.score += self.enemies.action(ds) self.stars.hit_check(self.player.P.X) if (self.item is not None and self.player.P.X.distance_to_squared(self.item.X) < self.player.collision_radius2*4): self.player.state.gun_get() self.player.gun_get_time = self.player.time self.item = None elif self.item is not None: self.item.action(ds) count += 1 # self.player.worldline.cut() # for enemy in self.enemies: # enemy.worldline.cut() def draw(self, keys): L = Lorentz(self.player.P.U) Xp = self.player.P.X matrix = self.player.quaternion.get_RotMat() if keys.k_look_behind: matrix *= Matrix44.y_rotation(pi) matrix_i = matrix.get_inverse_rot() glDisable(GL_DEPTH_TEST) glLoadMatrixd(matrix_i.to_opengl()) self.sky.draw(matrix_i, Lorentz(-self.player.P.U)) if keys.k_map: # self.stardust.draw(Xp, L) self.wireframe.draw(Xp, L) glEnable(GL_DEPTH_TEST) self.stars.draw(Xp, L) self.enemies.draw(Xp, L) if self.item is not None: self.item.draw(Xp, L) for gun in self.player.guns: gun.bullets.draw(Xp, L) self.enemies.bullets.draw(Xp, L) glDisable(GL_DEPTH_TEST) self.player.draw_window(L) glEnable(GL_DEPTH_TEST) if keys.k_map: self.player.draw_hp() self.player.draw_gun_name() self.player.draw_booster(keys)
def drop(self, item: Item): self.items.remove(item) item.place(self.parent.x, self.parent.y, self.gamemap)
level=Level(xp_given=35), ) troll = Actor( char='T', color=(0, 255, 255), name='Troll', ai_cls=HostileEnemy, fighter=Fighter(hp=16, defense=1, power=4), inventory=Inventory(capacity=0), level=Level(xp_given=100), ) health_potion = Item( char='!', color=(127, 0, 255), name="Harboe Sport", consumable=consumable.HealingConsumable(amount=4), ) lightning_scroll = Item( char='~', color=(152, 60, 20), name="Scroll o'Lightning", consumable=consumable.LightningDamageConsumable(damage=20, maximum_range=5), ) confusion_scroll = Item( char='~', color=(207, 63, 255), name="Scroll o'Confusion",
def __init__(self, y): Item.__init__(self, y) self.animation_duration = 0.1 self.animation = 'default' self.target = 0
from components.consumable import Consumable, HealingConsumable from components.ai import BaseAI, Hostile from components.fighter import Fighter from components.inventory import Inventory from entity import Actor, Item from config import Config as CONFIG player = Actor(name="Player", ai_cls=BaseAI, fighter=Fighter(hp=30, defense=2, power=5), inventory=Inventory(capacity=CONFIG.Game.get("inventory_size"))) # TODO Magic numbers! blue = Actor(name="Blue", ai_cls=Hostile, fighter=Fighter(hp=10, defense=0, power=3), inventory=Inventory(0)) yellow = Actor(name="Yellow", ai_cls=Hostile, fighter=Fighter(hp=16, defense=1, power=4), inventory=Inventory(0)) health_potion = Item( name="Health Potion", consumable=HealingConsumable(amount=4), )
def getName(): return names.get_last_name() def getUniquePerson(): return Actor( char="T", color=(63, 127, 0), name=getName(), fighter=Fighter(energy=1), ai_cls=OtherPerson ) player = Actor( char="@", color=colors.v_dark_purp, name="Player", fighter=Fighter(energy=100), ai_cls=OtherPerson, ) food = Item( char="%", color=(127, 0, 255), name="Food", consumable=HealingConsumable(amount=7), ) # me = Entity(char="o", color=(63, 127, 63), name="You", blocks_movement=True)
def drop(self, item: Item) -> None: """Removes an item from the inventory and places it at the player's curent location""" self.items.remove(item) item.place(self.parent.x, self.parent.y, self.gamemap) self.engine.message_log.add_message(f"You dropped the {item.name}.")
######################################################################### ################################ POTIONS ################################ ######################################################################### ### Potion of healing potion_of_healing = Item( char="!", fg=(127, 0, 255), name="Potion of healing", entity_id="potion_of_healing", entity_desc="Potion of healing desc", rarity=60, #DEBUG weight=0.2, price=100, item_type=InventoryOrder.POTION, item_state=ItemState(), spawnable=True, flammable=0, droppable=True, stackable=True, throwable=throwable.NormalThrowable(break_chance=1), readable=None, quaffable=quaffable.PotionOfHealingQuaffable(amount=10), ) item_lists.append(potion_of_healing) item_rarity.append(potion_of_healing.rarity) item_identified[ potion_of_healing.entity_id] = potion_of_healing.item_state.is_identified ### Potion of paralysis
char="T", color=(0, 127, 0), name="Troll", ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(hp=16, base_defense=1, base_power=4), inventory=Inventory(capacity=0), level=Level(xp_given=100) ) # scrolls scroll_char = "?" confusion_scroll = Item( char=scroll_char, color=(207, 63, 255), name="Confusion Scroll", consumable=consumable.ConfusionConsumable(number_of_turns=10) ) magic_missile_scroll = Item( char=scroll_char, color=(85, 255, 85), name="Magic Missile Scroll", consumable=consumable.MagicMissileDamageConsumable(damage=16) ) lightning_scroll = Item( char=scroll_char, color=(255, 255, 0), name="Lightning Scroll", consumable=consumable.LightningDamageConsumable(damage=20, maximum_range=5)
level=Level(xp_given=35), ) TROLL = Actor( char="T", color=(0, 127, 0), name="Troll", ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(hp=16, base_defense=1, base_power=4), inventory=Inventory(capacity=0), level=Level(xp_given=100), ) DAGGER = Item(char="/", color=(0, 191, 255), name="Dagger", stackable=False, equippable=Dagger()) SWORD = Item(char="/", color=(0, 191, 255), name="Sword", stackable=False, equippable=Sword()) LEATHER_ARMOR = Item( char="[", color=(139, 69, 19), name="Leather Armor", stackable=False, equippable=LeatherArmor(), ) CHAIN_MAIL = Item(
class World(object): def __init__(self, level, scale, playerstate, item=None): self.level = level self.scale = scale self.playerstate = playerstate self.L = self.level.L * scale self.wireframe = WireFrame(scale=self.scale) self.sky = Sky() self.player = Player(world=self, level=level, state=playerstate, pos=Vector4D(0, 0, 0, self.L)) self.solar = SolarSystem(self, self.player.P.X, self.scale) self.enemies = Enemies(world=self) self.item = None if not level.is_travel(): self.init_set_enemy() self.init_set_item(item) self.init_set_worldline() self.score = 0 def init_set_enemy(self): types = [randint(0, self.level.types - 1)for i in xrange(self.level.enemy_num-1)] types += [self.level.types-1] for typ in types: x = 6.0 * self.L * (2.0*random()-1.0) y = 6.0 * self.L * (2.0*random()-1.0) z = 6.0 * self.L * (1.0*random()-2.0) self.enemies.add(Vector4D(0, x, y, z), typ=typ, level=self.level) def init_set_item(self, item): if item is not None and item == self.playerstate.gun_num: pos = self.player.P.X + Vector4D(0, 0, 0.5, -5.0) * self.scale self.item = Item(item, pos, self.scale) def init_set_worldline(self): self.worldline_ref = {} lis = list(self.enemies) + [self.player] for a in lis: self.worldline_ref[id(a)] = a.worldline for b in lis: if a is b: continue a.worldline.set_id(id(b.P.X)) def action(self, keys, ds): n = int(ds * 10.0) + 1 ds /= n count = 0 while count < n: self.player.action(keys, ds) self.score += self.enemies.action(ds) self.solar.hit_check(self.player.P.X) self.item_action(ds) count += 1 for wl in self.worldline_ref.itervalues(): wl.cut() def item_action(self, ds): if self.item is not None: self.item.action(ds) if self.item.check_collision(self.player.P.X, self.player.collision_radius2*4): self.player.state.gun_get() self.player.gun_get_time = self.player.time self.item = None def draw(self, keys): L = Lorentz(self.player.P.U) LL = Lorentz(-self.player.P.U) Xp = self.player.P.X matrix = self.player.quaternion.get_RotMat() if keys.k_look_behind: matrix *= Matrix44.y_rotation(pi) matrix_i = matrix.get_inverse_rot() glDisable(GL_DEPTH_TEST) glLoadMatrixd(matrix_i.to_opengl()) self.sky.draw(matrix_i, LL) if keys.k_map: self.wireframe.draw(Xp, L) glEnable(GL_DEPTH_TEST) self.solar.draw(Xp, L, LL) self.enemies.draw(Xp, L, LL, self.worldline_ref) if self.item is not None: self.item.draw(Xp, L, LL) for gun in self.player.guns: gun.bullets.draw(Xp, L) self.enemies.bullets.draw(Xp, L) if keys.k_map: glDisable(GL_DEPTH_TEST) self.player.draw_window(L) glEnable(GL_DEPTH_TEST) self.player.draw_hp() self.player.draw_gun_name() self.player.draw_booster(keys)
level=Level(xp_given=2500), ) ogre = Actor( char="O", color=(0, 127, 0), name="Ogre", ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(hp=80, base_defense=6, base_power=32), inventory=Inventory(capacity=0), level=Level(xp_given=50000), ) confusion_scroll = Item( char="~", color=(207, 63, 255), name="Confusion Scroll", consumable=consumable.ConfusionConsumable(number_of_turns=10), ) fireball_scroll = Item( char="~", color=(255, 0, 0), name="Fireball Scroll", consumable=consumable.FireballDamageConsumable(damage=12, radius=3), ) health_potion = Item( char="!", color=(127, 0, 255), name="Health Potion", consumable=consumable.HealingConsumable(amount=4), ) lightning_scroll = Item(
def init_set_item(self, item): if item is not None and item == self.playerstate.gun_num: pos = self.player.P.X + Vector4D(0, 0, 0.5, -5.0) * self.scale self.item = Item(item, pos, self.scale)
inventory=Inventory(capacity=0), level=Level(xp_given=35), ) troll = Actor( char="T", color=(0, 127, 0), name="Troll", ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(hp=15, base_defense=1, base_power=4), inventory=Inventory(capacity=0), level=Level(xp_given=100), ) health_potion = Item( char="!", color=(127, 0, 255), name="Health potion", consumable=consumable.HealingConsumable(amount=4), ) lightening_scroll = Item( char="~", color=(255, 255, 0), name="Lightening Scroll", consumable=consumable.LightningDamageConsumable(damage=20, maximum_range=5), ) confusion_scroll = Item( char="~", color=(207, 63, 255), name="Confusion Scroll", consumable=consumable.ConfusionConsumable(number_of_turns=10), )
player = Actor( char="@", color=(255, 255, 255), name="Player", ai_cls=HostileEnemy, fighter=Fighter(hp=30, defense=1, power=7), inventory=Inventory(capacity=26), level=Level(level_up_base=200), ) # small healing potions open_front_unrounded_vowel = Item( char="Ω", color=(158, 48, 87), name="Open Front Unrounded Vowel", consumable=HealingConsumable(amount=4), ) open_back_unrounded_vowel = Item( char="δ", color=(158, 48, 87), name="Open Back Unrounded Vowel", consumable=HealingConsumable(amount=5), ) # medium healing potions open_mid_front_unrounded_vowel = Item( char="∞", color=(158, 48, 87),