Example #1
0
 def restrict_pos(self):
     x1 = rog.view_port_x()
     x2 = x1 + rog.view_w() - 1
     y1 = rog.view_port_y()
     y2 = y1 + rog.view_h() - 1
     self.x = maths.restrict(self.x, x1, x2)
     self.y = maths.restrict(self.y, y1, y2)
Example #2
0
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.")
Example #3
0
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)
Example #4
0
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)
Example #5
0
 def refresh(self):
     libtcod.console_blit(self.con, self.view.x, self.view.y, self.view.w,
                          self.view.h, rog.con_final(), rog.view_port_x(),
                          rog.view_port_y())
     rog.refresh()
Example #6
0
def dialogue(ent:int, style=0):
    ''' wrapper dialogue function
        Greet, introduce self if first time meeting,
        Then choose a dialogue type and execute the dialogue.
    '''
    world=rog.world()
    if not world.has_component(ent,cmp.Speaks):
        return False
    dispcompo=world.component_for_entity(ent,cmp.Disposition)
    personality=world.component_for_entity(ent,cmp.Personality).personality
    entn = world.component_for_entity(ent,cmp.Name)

    # greetings / rejections
    reaction = greet(ent, style=style)
    dispcompo.disposition += reaction
    if reaction < 0: # refuse to chat
        rejection(ent, personality, dispcompo.disposition, style=style)
        return False
    
        # introductions
    if not world.has_component(ent,cmp.Introduced):
        response,success = talk_introduce(
            ent,personality,dispcompo.disposition,style=style)
    else:
        # greet (haven't seen you in a bit)
        # TODO: once they've greeted you, add Greeted component
        #   then they no longer say anything when you press the
        #   chat key on them. Greeted component could be a status
        #   that wears off in an hour or so.
        response,success = talk_greeting(
            ent,personality,dispcompo.disposition,style=style)
    say(ent, response)
    
    # dialogue menu
    menu={"*" : "goodbye"}
    _menu={}
    for k,v in PERSUASION.items():
        if k==TALK_GREETING: continue
        menu[v[0]] = v[1]
        _menu[v[1]] = k
    opt = rog.menu(
        "{}{}".format(TITLES[entn.title],entn.name),
        rog.view_port_x(),rog.view_port_y(),
        menu,
        autoItemize=False
        )
    if opt==-1:
        return False
    if opt=="goodbye":
        return False
    result = _menu[opt]
    
    # perceived value for use by _talk function
    value = 0
    if result==TALK_ASKFAVOR:
        # TODO: implement favor dialogue menu
        value,npc_offer = _ask_favor(ent)
    elif result==TALK_BARTER:
        # TODO: implement trading dialogue menu
        value,pc_offer,npc_offer = _get_trade(ent)
    elif result==TALK_BRIBERY:
        type_gift,val = _get_gift_for(ent)
        if type_gift=="money": # val is a quantity of $
            value = val//MULT_VALUE
        elif type_gift=="item": # val is an item
            value = rog.get_value(val)
    
    # execute the dialogue
    response,success = _FUNCS[result](
        ent, personality, dispcompo.disposition,
        value=value, style=style
        )
    say(ent,response,result,success)
    return True
Example #7
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.")