def electrify(obj, dmg): res = obj.stats.reselec dmg = int(dmg * (1 - (res / 100)) / 10) if dmg: rog.hurt(obj, dmg) rog.sap(obj, dmg) if dmg >= 5: rog.paralyze(obj, ELEC_PARALYZETIME) # paralysis from high damage
def fight(attkr,dfndr,adv=0): ## TODO: when you attack, look at your weapon entity to get: #-material of weapon #-element of weapon #-flags of weapon world = rog.world() cstats = world.component_for_entity(attkr, cmp.CombatStats) dpos = world.component_for_entity(dfndr, cmp.Position) element = ELEM_PHYS #****TEMPORARY!!!! has_component... nrg_cost = round( NRG_ATTACK*AVG_SPD/max(1, cstats.asp) ) cstats.ap -= nrg_cost die=COMBATROLL acc=cstats.atk dv=cstats.dfn hit = False rol = dice.roll(die + acc + adv - dv) - dice.roll(die) if (rol >= 0): # HIT!!! hit = True #type of damage dealt depends on the element attacker is using if element == ELEM_PHYS: #high attack values can pierce armor ## if rol > ATK_BONUS_DMG_CUTOFF: ## pierce = int( (rol - ATK_BONUS_DMG_CUTOFF)/2 ) ## else: ## pierce = 0 armor = dfndr.stats.get('arm') #max(0, dfndr.stats.get('arm') - pierce) dmg = max(0, attkr.stats.get('dmg') - armor) rog.hurt(dfndr, dmg) elif element == ELEM_FIRE: rog.burn(dfndr, dmg) elif element == ELEM_BIO: rog.disease(dfndr, dmg) elif element == ELEM_ELEC: rog.electrify(dfndr, dmg) elif element == ELEM_CHEM: rog.exposure(dfndr, dmg) elif element == ELEM_RADS: rog.irradiate(dfndr, dmg) killed = rog.on(dfndr,DEAD) #...did we kill it? # message = True a=attkr.name; n=dfndr.name; t1=attkr.title; t2=dfndr.title; x='.'; # make a message describing the fight if message: if hit==False: v="misses" elif dmg==0: v="cannot penetrate"; x="'s armor!" elif killed: v="defeats" else: v="hits" rog.event_sight( dfndr.x,dfndr.y, "{t1}{a} {v} {t2}{n}{x}".format(a=a,v=v,n=n,t1=t1,t2=t2,x=x) ) rog.event_sound(dpos.x,dpos.y, SND_FIGHT)
def exposure(obj, dmg): res = obj.stats.resbio #increase exposure meter dmg = int(dmg * (1 - (res / 100))) obj.stats.expo += max(0, dmg) if obj.stats.expo >= 100: obj.stats.expo = 0 #reset exposure meter rog.hurt(obj, CHEM_DAMAGE) #instant damage when expo meter fills _random_chemical_effect(obj) #inflict chem status effect
def pickup_pc(pc): rog.alert("Pick up what?{d}".format(d=dirStr)) args=rog.get_direction() if not args: rog.alert() return dx,dy,dz=args xx,yy=pc.x + dx, pc.y + dy things=rog.thingsat(xx,yy) if pc in things: things.remove(pc) choice=None if len(things) > 1: rog.alert("There are multiple things here. Pick up which item?") choices = [] #["all",] #should player be able to pickup multiple things at once? Maybe could be a delayed action? for thing in things: choices.append(thing) choice=rog.menu( "pick up", rog.view_port_x()+2, rog.view_port_y()+2, choices ) else: if things: choice=things[0] if (choice and not choice == "all"): if choice == K_ESCAPE: return #thing is creature! You can't pick up creatures :( if choice.isCreature: rog.alert("You can't pick that up!") return #thing is on fire! What are you doing trying to pick it up?? if rog.on(choice,FIRE): answer="" while True: answer=rog.prompt(0,0,rog.window_w(),1,maxw=1, q="That thing is on fire! Are you sure? y/n", mode='wait',border=None) answer=answer.lower() if answer == "y" or answer == " " or answer == K_ENTER: rog.alert("You burn your hands!") rog.burn(pc, FIRE_BURN) rog.hurt(pc, FIRE_HURT) break elif answer == "n" or answer == K_ESCAPE: return # put in inventory pocketThing(pc, choice) #elif choice == "all": # else: rog.alert("There is nothing there to pick up.")
def fight(attkr,dfndr,adv=0): nrg_cost = round( NRG_ATTACK*AVG_SPD/max(1, attkr.stats.get('asp')) ) attkr.stats.nrg -= nrg_cost die=COMBATROLL acc=attkr.stats.get('atk') dv=dfndr.stats.get('dfn') hit = False rol = dice.roll(die + acc + adv - dv) - dice.roll(die) if (rol >= 0): # HIT!!! hit = True #type of damage dealt depends on the element attacker is using if attkr.stats.element == ELEM_PHYS: #high attack values can pierce armor ## if rol > ATK_BONUS_DMG_CUTOFF: ## pierce = int( (rol - ATK_BONUS_DMG_CUTOFF)/2 ) ## else: ## pierce = 0 armor = dfndr.stats.get('arm') #max(0, dfndr.stats.get('arm') - pierce) dmg = max(0, attkr.stats.get('dmg') - armor) rog.hurt(dfndr, dmg) elif attkr.stats.element == ELEM_FIRE: rog.burn(dfndr, dmg) elif attkr.stats.element == ELEM_BIO: rog.disease(dfndr, dmg) elif attkr.stats.element == ELEM_ELEC: rog.electrify(dfndr, dmg) elif attkr.stats.element == ELEM_CHEM: rog.exposure(dfndr, dmg) elif attkr.stats.element == ELEM_RADS: rog.irradiate(dfndr, dmg) killed = rog.on(dfndr,DEAD) #...did we kill it? # message = True a=attkr.name; n=dfndr.name; t1=attkr.title; t2=dfndr.title; x='.'; # make a message describing the fight if message: if hit==False: v="misses" elif dmg==0: v="cannot penetrate"; x="'s armor!" elif killed: v="defeats" else: v="hits" rog.event_sight( dfndr.x,dfndr.y, "{t1}{a} {v} {t2}{n}{x}".format(a=a,v=v,n=n,t1=t1,t2=t2,x=x) ) rog.event_sound(dfndr.x,dfndr.y, SND_FIGHT)
def _tick(self, obj, status, time): if status == SICK: pass elif status == SPRINT: pass #chance to trip while sprinting ## if dice.roll(100) < SPRINT_TRIP_CHANCE: ## rog.knockdown(obj) elif status == FIRE: if obj.stats.get('temp') < FIRE_TEMP: #cooled down too much to keep burning self.remove(obj, status) print("removing fire due to low temp for {} at {},{}".format(obj.name,obj.x,obj.y)) return #damage is based on temperature of the object dmg = max( 1, int(obj.stats.get('temp') / 100) ) rog.hurt(obj, dmg) #create a fire at the location of burning things if rog.on(obj,ONGRID): rog.set_fire(obj.x,obj.y) elif status == ACID: #damage is based on time remaining, more time = more dmg dmg = max( 1, dice.roll(2) - 2 + math.ceil(math.sqrt(time-1)) ) rog.hurt(obj, dmg) elif status == IRRIT: pass elif status == PARAL: if dice.roll(20) <= PARAL_ROLLSAVE: self.remove(obj, status) elif status == COUGH: pass #chance to stop in a coughing fit (waste your turn) ## if dice.roll(20) <= COUGH_CHANCE: ## rog.queue_action(obj, action.cough) elif status == VOMIT: pass #chance to stop in a vomiting fit (waste your turn) ## if dice.roll(20) <= VOMIT_CHANCE: ## rog.queue_action(obj, action.cough) elif status == BLIND: pass elif status == DEAF: pass
def explosion(bomb): con=libtcod.console_new(ROOMW, ROOMH) rog.msg("{t}{n} explodes!".format(t=bomb.title, n=bomb.name)) fov=rog.fov_init() libtcod.map_compute_fov( fov, bomb.x,bomb.y, bomb.r, light_walls = True, algo=libtcod.FOV_RESTRICTIVE) for x in range(bomb.r*2 + 1): for y in range(bomb.r*2 + 1): xx=x + bomb.x - bomb.r yy=y + bomb.y - bomb.r if not libtcod.map_is_in_fov(fov, xx,yy): continue if not rog.is_in_grid(xx,yy): continue dist=maths.dist(bomb.x,bomb.y, xx,yy) if dist > bomb.r: continue thing=rog.thingat(xx, yy) if thing: if rog.on(thing,DEAD): continue if thing.isCreature: decay=bomb.dmg/bomb.r dmg= bomb.dmg - round(dist*decay) - thing.stats.get('arm') rog.hurt(thing, dmg) if dmg==0: hitName="not damaged" elif rog.on(thing,DEAD): hitName="killed" else: hitName="hit" rog.msg("{t}{n} is {h} by the blast.".format( t=thing.title,n=thing.name,h=hitName) ) else: # explode any bombs caught in the blast if (thing is not bomb and hasattr(thing,'explode') and dist <= bomb.r/2 ): thing.timer=0
def pickup_pc(pc): world = rog.world() pos = world.component_for_entity(pc, cmp.Position) pcx = pos.x pcy = pos.y rog.alert("Pick up what?{d}".format(d=dirStr)) args=rog.get_direction() if not args: rog.alert() return dx,dy,dz=args xx,yy = pcx + dx, pcy + dy things=rog.thingsat(xx,yy) if pc in things: #can't pick yourself up. things.remove(pc) choice=None if len(things) > 1: rog.alert("There are multiple things here. Pick up which item?") choices = [] #["all",] #should player be able to pickup multiple things at once? Maybe could be a delayed action? for thing in things: choices.append(thing) choice=rog.menu( "pick up", rog.view_port_x()+2, rog.view_port_y()+2, choices ) else: if things: choice=things[0] if (choice and not choice == "all"): if choice == K_ESCAPE: return #thing is creature! You can't pick up creatures :( or can you...? if world.has_component(choice, cmp.Creature): rog.alert("You can't pick that up!") return #thing is on fire, prompt user & burn persistent rogues if rog.on(choice,FIRE): answer="" while True: answer=rog.prompt(0,0,rog.window_w(),1,maxw=1, q="That thing is on fire! Are you sure? y/n", mode='wait',border=None) answer=answer.lower() if answer == "y" or answer == " " or answer == K_ENTER: rog.alert("You burn your hands!") rog.burn(pc, FIRE_BURN) rog.hurt(pc, FIRE_HURT) break elif answer == "n" or answer == K_ESCAPE: return # put in inventory pocketThing(pc, choice) ## elif choice == "all": ## for tt in things: ## pocketThing(pc, tt) else: rog.alert("There is nothing there to pick up.")