def pocketThing(obj, item): ## if not item: return False rog.drain(obj, 'nrg', NRG_POCKET) rog.give(obj, item) rog.release_inanimate(item) rog.msg("{t}{n} pockets {i}.".format( t=obj.title,n=obj.name,i=item.name))
def drop(obj, item): if not rog.wallat(pc.x+dx,pc.y+dy): rog.drain(obj, 'nrg', NRG_RUMMAGE) rog.drop(obj,item, dx,dy) rog.msg("{t}{n} dropped {i}.".format(t=obj.title,n=obj.name,i=item.name)) return True else: return False
def funcPlayer(self, obj): xx = obj.x yy = obj.y reading = rog.radsat(xx, yy) rog.msg("The geiger counter reads '{} RADS'".format(reading)) #could do, instead: # use turns it on, activates an observer. # updates when rad damage received by player. Adds rad value to dosimeter # when you use again, you can either read it or turn it off. rog.drain(obj, 'nrg', NRG_USE)
def pocketThing(ent, item): ## if not item: return False world = rog.world() rog.drain(ent, 'nrg', NRG_POCKET) rog.give(ent, item) rog.release_inanimate(item) entn = world.component_for_entity(ent, cmp.Name) itemn = world.component_for_entity(item, cmp.Name) rog.msg("{t}{n} packs {ti}{ni}.".format( t=entn.title,n=entn.name,ti=itemn.title,ni=itemn.name))
def move(obj,dx,dy): # locomotion xto=obj.x+dx yto=obj.y+dy terrain_cost=rog.cost_move(obj.x,obj.y,xto,yto, None) if terrain_cost == 0: return False # 0 means we can't move there mult = 1.41 if (dx + dy) % 2==0 else 1 # diagonal extra cost modf=NRG_MOVE nrg_cost=round(modf*mult*terrain_cost*AVG_SPD/max(1, obj.stats.get('msp'))) rog.drain(obj, 'nrg', nrg_cost) rog.port(obj, xto, yto) return True
def inventory_pc(pc): world=Rogue.world() ## assert world.has_component(pc, cmp.Inventory), "PC missing inventory" pcInv = world.component_for_entity(pc, cmp.Inventory) pcn = world.component_for_entity(pc, cmp.Name) x=0 y=rog.view_port_y() # items menu item=rog.menu("{}{}'s Inventory".format( pcn.title,pcn.name), x,y, pcInv.items) # viewing an item if not item == -1: itemn = world.component_for_entity(item, cmp.Name) ## itemn = world.component_for_entity(item, cmp.Name) keysItems={} # get available actions for this item... if world.has_component(item, cmp.Edible): keysItems.update({"E":"Eat"}) if world.has_component(item, cmp.Quaffable): keysItems.update({"q":"quaff"}) if world.has_component(item, cmp.Equipable): keysItems.update({"e":"equip"}) # throwables - subset of equipables if world.component_for_entity(item, cmp.Equipable).equipType == EQ_MAINHAND: keysItems.update({"t":"throw"}) if world.has_component(item, cmp.Usable): keysItems.update({"u":"use"}) if world.has_component(item, cmp.Openable): keysItems.update({"o":"open"}) keysItems.update({"x":"examine"}) keysItems.update({"d":"drop"}) # opt=rog.menu( "{}".format(itemn.name), x,y, keysItems, autoItemize=False ) #print(opt) if opt == -1: return opt=opt.lower() rmg=False if opt == "drop": rmg=True; drop_pc(pc, item) elif opt == "equip": rmg=True; equip_pc(pc, item) elif opt == "throw": rmg=True; throw_pc(pc, item) elif opt == "eat": rmg=True; eat_pc(pc, item) elif opt == "quaff": rmg=True; quaff_pc(pc, item) elif opt == "use": rmg=True; use_pc(pc, item) elif opt == "examine": rmg=True; examine_pc(pc, item) if rmg: rog.drain(pc, 'nrg', NRG_RUMMAGE)
def drop(ent, item): world = rog.world() pos = world.component_for_entity(ent, cmp.Position) dx=0; dy=0; # TODO: code AI to find a place to drop item if not rog.wallat(pos.x+dx,pos.y+dy): rog.drain(ent, 'nrg', NRG_RUMMAGE) rog.drop(ent,item, dx,dy) entn = world.component_for_entity(ent, cmp.Name) itemn = world.component_for_entity(item, cmp.Name) rog.msg("{t}{n} drops {ti}{ni}.".format( t=entn.title,n=entn.name,ti=itemn.title,ni=itemn.name)) return True else: return False
def openClose(obj, xto, yto): #open containers #close containers #open doors if rog.tile_get(xto,yto) == DOORCLOSED: rog.drain(obj, 'nrg', NRG_OPEN) rog.tile_change(xto,yto, DOOROPEN) rog.msg("{n} opened a door.".format(n=obj.name)) return True #close doors if rog.tile_get(xto,yto) == DOOROPEN: rog.drain(obj, 'nrg', NRG_OPEN) rog.tile_change(xto,yto, DOORCLOSED) rog.msg("{n} closed a door.".format(n=obj.name)) return True return False
def inventory_pc(pc,pcInv): if not pc.inv: rog.alert(ALERT_EMPTYCONTAINER) return x=0 y=rog.view_port_y() # items menu item=rog.menu("{}'s Inventory".format(pc.name), x,y, pcInv.items) # viewing an item if not item == -1: keysItems={} # get available actions for this item... if rog.on(item,CANEAT): keysItems.update({"E":"Eat"}) if rog.on(item,CANQUAFF): keysItems.update({"q":"quaff"}) if rog.on(item,CANEQUIP): keysItems.update({"e":"equip"}) if rog.on(item,CANUSE): keysItems.update({"u":"use"}) if rog.on(item,CANOPEN): keysItems.update({"o":"open"}) keysItems.update({"x":"examine"}) keysItems.update({"d":"drop"}) keysItems.update({"t":"throw"}) # opt=rog.menu( "{}".format(item.name), x,y, keysItems, autoItemize=False ) #print(opt) if opt == -1: return opt=opt.lower() rmg=False if opt == "drop": rmg=True; drop_pc(pc,item) elif opt == "equip": rmg=True; equip_pc(pc,item) elif opt == "eat": rmg=True; eat_pc(pc, item) elif opt == "quaff": rmg=True; quaff_pc(pc, item) elif opt == "use": rmg=True; use_pc(pc, item) elif opt == "examine": rmg=True; examine_pc(pc, item) if rmg: rog.drain(pc, 'nrg', NRG_RUMMAGE)
def quaff(ent, drink): world = rog.world() pos = world.component_for_entity(ent, cmp.Position) quaffable=world.component_for_entity(drink, cmp.Quaffable) entn = world.component_for_entity(ent, cmp.Name) drinkn = world.component_for_entity(drink, cmp.Name) #quaff function quaffable.func(ent) # TODO: do delayed action instead of immediate action. rog.drain(ent, 'nrg', quaffable.timeToConsume) rog.givemp(ent, quaffable.hydration) #events - sight if ent == rog.pc(): rog.msg("It tastes {t}".format(t=quaffable.taste)) else: rog.event_sight(pos.x,pos.y, "{t}{n} quaffs a {p}.".format( t=entn.title, n=entn.name, p=drinkn.name)) #events - sound rog.event_sound(pos.x,pos.y, SND_QUAFF) # TODO: make sure this works... world.delete_entity(drink)
def funcMonster(self, obj): rog.drain(obj, 'nrg', NRG_USE) rog.event_sight(obj.x, obj.y, "{t}{n} looks at a geiger counter.")
def examine_pc(pc, item): rog.drain(pc, 'nrg', NRG_EXAMINE) rog.dbox(0,0,40,30, thing.DESCRIPTIONS[item.name])
def quaff(obj, drink): rog.drain(pc, 'nrg', NRG_QUAFF) drink.quaff(obj) rog.event_sight(obj.x,obj.y, "{t}{n} quaffs a {p}.".format( t=obj.title,n=obj.name,p=drink)) rog.event_sound(obj.x,obj.y, SND_QUAFF)
def create_monster(typ, x, y, col, mutate=3): # get generic monster attributes # monData = bestiary[typ] name = monData[0] monst = thing.create_creature(name, typ, x, y, col) monst.job = name i = 1 j = 0 monst.stats.hpmax = monData[i][j] j += 1 monst.stats.mpmax = monData[i][j] j += 1 monst.stats.atk = monData[i][j] j += 1 monst.stats.dmg = monData[i][j] j += 1 monst.stats.dfn = monData[i][j] j += 1 monst.stats.arm = monData[i][j] j += 1 monst.stats.spd = monData[i][j] j += 1 monst.stats.msp = monData[i][j] j += 1 monst.stats.asp = monData[i][j] j += 1 monst.stats.resfire = monData[i][j] j += 1 monst.stats.resbio = monData[i][j] j += 1 monst.stats.sight = monData[i][j] j += 1 monst.stats.hearing = monData[i][j] j += 1 monst.stats.carry = monData[i][j] j += 1 monst.mass = monData[i][j] j += 1 monst.purse = monData[i][j] j += 1 i += 1 for flag in monData[i]: rog.make(monst, flag) #flags #i+=1 #for item in monData[i]: rog.give(monst,item) #items # possibly randomly alter some attributes # times = 0 maxgainz = mutate chance = 2 while (dice.roll(10) <= chance and times < maxgainz): times += 1 r = dice.roll(6) if r == 1: rog.gain(monst, 'atk') elif r == 2: rog.gain(monst, 'dmg') elif r == 3: rog.gain(monst, 'arm') elif r == 4: rog.gain(monst, 'dfn') elif r == 5: rog.gain(monst, 'hpmax') times = 0 maxdrains = mutate chance = 2 while (dice.roll(10) <= chance and times < maxdrains): times += 1 r = dice.roll(6) if r == 1: rog.drain(monst, 'atk') elif r == 2: rog.drain(monst, 'dmg') elif r == 3: rog.drain(monst, 'arm') elif r == 4: rog.drain(monst, 'dfn') elif r == 5: rog.drain(monst, 'hpmax') # # # ai #TEMPORARY monst.ai = ai.stateless return monst