def order(cmd):
    # Whatever the player inputs after the move command itself.
    target = utilities.flatten_tokens(cmd.tokens[1:])

    # If the player doesn't input anything after the order command.
    if target == None or len(target) == 0:
        response = "What do you want to order?"
        return response

    # Match the desired order to an Item object using the item_map array in the config file, then store it here.
    desired_order = config.item_map.get(target)

    # If the desired order identifier can't be matched to an Item object in the item_map array.
    if desired_order == None:
        response = "That is not a valid item."
        return response
    else:
        # Check to see if the player can buy the found item.
        if desired_order.value is not None and desired_order.vendor is not None:
            # Get the player's data.
            player_data = player.Player()

            # If the player is in the location of the vendor selling the item.
            if desired_order.vendor != player_data.location:
                response = "You cannot buy that item here."
                return response

            # If the player does not have enough slime to buy the desired order.
            if desired_order.value > player_data.slimes:
                response = "You do not have enough slime to order this item! A {order} costs {price}, and you only have {slimes}!".format(
                    order=desired_order.name,
                    price=desired_order.value,
                    slimes=player_data.slimes)
                return response
            else:
                # Spend the slime necessary to buy the item.
                player_data.slimes -= desired_order.value
                player_data.persist()

                # Actually create the item.
                item.create_item(desired_order)

                response = "You order a {item}!".format(
                    item=desired_order.name,
                    description=desired_order.description)
                return response
def newItem_submit(rdb, user_id, event_id, task_id):
    result = item.create_item(rdb, user_id, event_id, task_id)
    #   result = (user_id , event_id, task_id)
    if result:
        redirect('/task/%s/%s/%s' % result)
    #item created
    else:
        #failed to create event
        return "Failed to add item"
Exemple #3
0
 def check_born(self):
     import misc.timer
     now = misc.timer.gtimer.current()
     
     if now - self.last_time < self.TimeDelta:
         return
     
     self.last_time = now
     
     import random
     global BornPosition
     i = random.randint(0, len(BornPosition) - 1)
     p = BornPosition[i]
     
     if self.find_item_near(p[0], p[1], 2):
         return
     
     import item, constants
     item.create_item(constants.ItemBarrel, p[0], p[1])
Exemple #4
0
								def _yes(*a,**k):
									self.shop_other.pick_up(self.selected_item)
									del self.selected_item.parent.inventory[self.selected_item.parent.inventory.index(self.selected_item)]
									self.selected_item.reparent(self.shop_other)
									
									
									self.ship.inventory.append(item.create_item(absroot, "money", self.ship))
									self.ship.inventory[-1].count=cost
									self.ship.try_stack(self.ship.inventory[-1])
									self.selected_item=None
									self.first_start()
Exemple #5
0
	def __call__(self, x=0, y=0, with_equip=1, ai=True):
		s = Ship(self.root, self.image, self.id_string, self.name, self.hull, self.mass, self.cost, self.cargo,\
			self.start_speed, self.reactor_max, self.reactor_regen, self.hardpoints, self.engine_sources, self.shields,
			self.rarity, self.max_speed, self.turn_rate, self.systems, self.config, x, y, use_ai=ai)
		if with_equip:
			for i in self.start_equip:
				io=item.create_item(self.root, i["item_name"], s, i["equipped"])
				if "count" in i:
					io.count=i["count"]
				s.inventory.append(io)
		return s
Exemple #6
0
 def __call__(self, x=0, y=0, with_equip=1, ai=True):
     s = Ship(self.root, self.image, self.id_string, self.name, self.hull, self.mass, self.cost, self.cargo,\
      self.start_speed, self.reactor_max, self.reactor_regen, self.hardpoints, self.engine_sources, self.shields,
      self.rarity, self.max_speed, self.turn_rate, self.systems, self.config, x, y, use_ai=ai)
     if with_equip:
         for i in self.start_equip:
             io = item.create_item(self.root, i["item_name"], s,
                                   i["equipped"])
             if "count" in i:
                 io.count = i["count"]
             s.inventory.append(io)
     return s
 def on_click(self):
     if self.state.widgets[self.config["delete_old"]].state:
         del self.root.state_manager.states["game"].player.inventory[
             self.root.state_manager.states["game"].player.inventory.index(
                 self.root.state_manager.states["game"].player.
                 get_item_in_hardpoint(
                     int(self.state.widgets[self.config["equip"]].text)))]
     myitem = item.create_item(
         self.root, self.state.widgets[self.config["id"]].text,
         self.root.state_manager.states["game"].player,
         int(self.state.widgets[self.config["equip"]].text))
     myitem.count = int(self.state.widgets[self.config["count"]].text)
     self.root.state_manager.states["game"].player.inventory.append(myitem)
Exemple #8
0
 def run_in_default(self, *a, **k):
     for key in k:
         exec key + "=k[key]"
     pcount = self.config.get("count", None)
     if pcount is not None:
         if isinstance(pcount, basestring):
             if pcount.startswith("*"):
                 pcount = eval(pcount[1:])
     self.root.state_manager.states["game"].player.pick_up(
         item.create_item(self.root, self.config["id"],
                          self.root.state_manager.states["game"].player,
                          self.config.get("equipped", -1), pcount))
     debug("Gave the player " + self.config["id"])
Exemple #9
0
	def run_in_default(self, *a, **k):
		for key in k:
			exec key+"=k[key]"
		pcount=self.config.get("count", None)
		if pcount is not None:
			if isinstance(pcount, basestring):
				if pcount.startswith("*"):
					pcount=eval(pcount[1:])
		self.root.state_manager.states["game"].player.pick_up(
			item.create_item(self.root, self.config["id"], self.root.state_manager.states["game"].player,
			 self.config.get("equipped", -1),
			 pcount)
		)
		debug("Gave the player "+self.config["id"])
Exemple #10
0
def index_item_and_store_item(item):
    item_description_mormalized = normalizator().normalize(item.title)
    phrase_encoded = normalizator().as_base_64(item_description_mormalized)
    index_db_key = db.Key.from_path("Index",phrase_encoded)
    index = db.get(index_db_key)
    if index==None:
        index = Index(key_name=phrase_encoded,index=item_description_mormalized)
    new_item = create_item(item,phrase_encoded)
    db.put(new_item)
    increase_item_counter()
    if not(new_item.key() in index.items):
        index.num_items=+1;
        index.items.append(new_item.key())
    db.put(index)
Exemple #11
0
                                def _yes(*a, **k):
                                    self.shop_other.pick_up(self.selected_item)
                                    del self.selected_item.parent.inventory[
                                        self.selected_item.parent.inventory.
                                        index(self.selected_item)]
                                    self.selected_item.reparent(
                                        self.shop_other)

                                    self.ship.inventory.append(
                                        item.create_item(
                                            absroot, "money", self.ship))
                                    self.ship.inventory[-1].count = cost
                                    self.ship.try_stack(
                                        self.ship.inventory[-1])
                                    self.selected_item = None
                                    self.first_start()
Exemple #12
0
def whatToSpawn(xposition, yposition, item):
    global coin_s
    global mushroom_s
    global oneUP_s
    global star_s
    global flower_s
    global multicoin_s
    if item == 'A':
        itemClass.create_item("coin", xposition, yposition + 1)
        coin_s = True
        Entity(model='cube',
               color=color.white,
               collision=True,
               collider=None,
               ignore=False,
               always_on_top=True,
               position=(xposition, yposition),
               texture=Texture("textures/deadblock1.png"),
               scale=(1, 1))

    elif item == 'B':
        if player.health == 1:
            itemClass.create_item("mushroom", xposition, yposition + 1)
            mushroom_s = True
            Entity(model='cube',
                   color=color.white,
                   collision=True,
                   collider=None,
                   ignore=False,
                   always_on_top=True,
                   position=(xposition, yposition),
                   texture=Texture("textures/deadblock1.png"),
                   scale=(1, 1))
        elif player.health == 2 or player.health == 3:
            # spawn a mushroom, but change the player if they run into it at 2 or 3 health.
            itemClass.create_item("flower", xposition, yposition + 1)
            flower_s = True
            Entity(model='cube',
                   color=color.white,
                   collision=True,
                   collider=None,
                   ignore=False,
                   always_on_top=True,
                   position=(xposition, yposition),
                   texture=Texture("textures/deadblock1.png"),
                   scale=(1, 1))
    elif item == 'C':
        #spawn star
        itemClass.create_item("star", xposition, yposition + 1)
        star_s = True
        Entity(model='cube',
               color=color.white,
               collision=True,
               collider=None,
               ignore=False,
               always_on_top=True,
               position=(xposition, yposition),
               texture=Texture("textures/deadblock1.png"),
               scale=(1, 1))
    elif item == 'D':
        itemClass.create_item("1up", xposition, yposition + 1)
        oneUP_s = True
        Entity(model='cube',
               color=color.white,
               collision=True,
               collider=None,
               ignore=False,
               always_on_top=True,
               position=(xposition, yposition),
               texture=Texture("textures/deadblock1.png"),
               scale=(1, 1))
    elif item == 'E':
        itemClass.create_item("coin", xposition, yposition + 1)
        coin_s = True
        Entity(model='cube',
               color=color.white,
               collision=True,
               collider=None,
               ignore=False,
               always_on_top=True,
               position=(xposition, yposition),
               texture=Texture("textures/deadblock1.png"),
               scale=(1, 1))
    elif item == 'F':
        if player.health == 1:
            itemClass.create_item("mushroom", xposition, yposition + 1)
            mushroom_s = True
            Entity(model='cube',
                   color=color.white,
                   collision=True,
                   collider=None,
                   ignore=False,
                   always_on_top=True,
                   position=(xposition, yposition),
                   texture=Texture("textures/deadblock1.png"),
                   scale=(1, 1))
        elif player.health == 2 or player.health == 3:
            itemClass.create_item("flower", xposition, yposition + 1)
            flower_s = True
            Entity(model='cube',
                   color=color.white,
                   collision=True,
                   collider=None,
                   ignore=False,
                   always_on_top=True,
                   position=(xposition, yposition),
                   texture=Texture("textures/deadblock1.png"),
                   scale=(1, 1))
    elif item == 'G':
        #spawn star
        itemClass.create_item("star", xposition, yposition + 1)
        star_s = True
        Entity(model='cube',
               color=color.white,
               collision=True,
               collider=None,
               ignore=False,
               always_on_top=True,
               position=(xposition, yposition),
               texture=Texture("textures/deadblock1.png"),
               scale=(1, 1))
    elif item == 'H':
        itemClass.create_item("1up", xposition, yposition + 1)
        oneUP_s = True
        Entity(model='cube',
               color=color.white,
               collision=True,
               collider=None,
               ignore=False,
               always_on_top=True,
               position=(xposition, yposition),
               texture=Texture("textures/deadblock1.png"),
               scale=(1, 1))
    elif item == 'c':
        #block can be broken/disapear
        Entity(model='cube',
               color=color.light_gray,
               collision=False,
               collider=None,
               ignore=True,
               always_on_top=True,
               position=(xposition, yposition),
               scale=(1, 1))
    elif item == 'd':
        #multicoin block
        itemClass.create_item("multicoin", xposition, yposition + 1)
        multicoin_s = True
        Entity(model='cube',
               color=color.white,
               collision=True,
               collider=None,
               ignore=False,
               always_on_top=True,
               position=(xposition, yposition),
               texture=Texture("textures/deadblock1.png"),
               scale=(1, 1))
    elif item == 'e':
        if player.health == 1:
            itemClass.create_item("mushroom", xposition, yposition + 1)
            mushroom_s = True
            Entity(model='cube',
                   color=color.white,
                   collision=True,
                   collider=None,
                   ignore=False,
                   always_on_top=True,
                   position=(xposition, yposition),
                   texture=Texture("textures/deadblock1.png"),
                   scale=(1, 1))

        elif player.health == 2 or player.health == 3:
            itemClass.create_item("flower", xposition, yposition + 1)
            flower_s = True
            Entity(model='cube',
                   color=color.white,
                   collision=True,
                   collider=None,
                   ignore=False,
                   always_on_top=True,
                   position=(xposition, yposition),
                   texture=Texture("textures/deadblock1.png"),
                   scale=(1, 1))

    elif item == 'f':
        #spawn star
        itemClass.create_item("star", xposition, yposition + 1)
        star_s = True
        Entity(model='cube',
               color=color.white,
               collision=True,
               collider=None,
               ignore=False,
               always_on_top=True,
               position=(xposition, yposition),
               texture=Texture("textures/deadblock1.png"),
               scale=(1, 1))
    elif item == 'g':
        itemClass.create_item("1up", xposition, yposition + 1)
        oneUP_s = True
        Entity(model='cube',
               color=color.white,
               collision=True,
               collider=None,
               ignore=False,
               always_on_top=True,
               position=(xposition, yposition),
               texture=Texture("textures/deadblock1.png"),
               scale=(1, 1))
    elif item == 'l':
        #block can be broken/disapear
        Entity(model='cube',
               color=color.light_gray,
               collision=False,
               collider=None,
               ignore=True,
               always_on_top=True,
               position=(xposition, yposition),
               scale=(1, 1))
    elif item == 'm':
        #multicoin block
        itemClass.create_item("multicoin", xposition, yposition + 1)
        multicoin_s = True
        Entity(model='cube',
               color=color.white,
               collision=True,
               collider=None,
               ignore=False,
               always_on_top=True,
               position=(xposition, yposition),
               texture=Texture("textures/deadblock2.png"),
               scale=(1, 1))
    elif item == 'n':
        if player.health == 1:
            itemClass.create_item("mushroom", xposition, yposition + 1)
            mushroom_s = True
            Entity(model='cube',
                   color=color.white,
                   collision=True,
                   collider=None,
                   ignore=False,
                   always_on_top=True,
                   position=(xposition, yposition),
                   texture=Texture("textures/deadblock2.png"),
                   scale=(1, 1))

        elif player.health == 2 or player.health == 3:
            itemClass.create_item("flower", xposition, yposition + 1)
            flower_s = True
            Entity(model='cube',
                   color=color.white,
                   collision=True,
                   collider=None,
                   ignore=False,
                   always_on_top=True,
                   position=(xposition, yposition),
                   texture=Texture("textures/deadblock2.png"),
                   scale=(1, 1))

    elif item == 'o':
        #spawn star
        itemClass.create_item("star", xposition, yposition + 1)
        star_s = True
        Entity(model='cube',
               color=color.white,
               collision=True,
               collider=None,
               ignore=False,
               always_on_top=True,
               position=(xposition, yposition),
               texture=Texture("textures/deadblock2.png"),
               scale=(1, 1))
    elif item == 'p':
        itemClass.create_item("1up", xposition, yposition + 1)
        oneUP_s = True
        Entity(model='cube',
               color=color.white,
               collision=True,
               collider=None,
               ignore=False,
               always_on_top=True,
               position=(xposition, yposition),
               texture=Texture("textures/deadblock2.png"),
               scale=(1, 1))
Exemple #13
0
 def try_split(self, itemx, count):
     assert count < itemx.count, "Tried to take more than you have"
     assert count > 0, "Tried to take less than 1"
     itemx.count -= count
     self.inventory.append(
         item.create_item(self.root, itemx.id_str, self, -1, count))
def mine(cmd):
    # Get the player's data.
    player_data = player.Player()

    # Checks to see if the player is in the right location.
    if player_data.location == config.location_id_mines:

        search_for_rusty_pickaxe = item.search_for_item(
            sought_item="rustypickaxe")
        search_for_pickaxe = item.search_for_item(sought_item="pickaxe")
        search_for_super_pickaxe = item.search_for_item(
            sought_item="superpickaxe")

        has_pickaxe = None
        has_super_pickaxe = None
        found_poudrin = None

        if search_for_rusty_pickaxe is None and search_for_pickaxe is None and search_for_super_pickaxe is None:
            rusty_pickaxe_object = config.item_map.get("rustypickaxe")
            item.create_item(rusty_pickaxe_object)
            response = "But, alas, you have no pickaxe! Luckily, there's a rusty on the floor. You pick it up, and can now mine. Once you've gotten more slime, you should head into town to look for a better pickaxe instead of relying on hand-me-downs."
            return response

        else:
            if search_for_rusty_pickaxe is not None:
                pickaxe = search_for_rusty_pickaxe
            if search_for_pickaxe is not None:
                pickaxe = search_for_pickaxe
                has_pickaxe = True
            if search_for_super_pickaxe is not None:
                pickaxe = search_for_super_pickaxe
                has_super_pickaxe = True

        if player_data.hunger < 100:
            pickaxe.durability -= 1

            pickaxe_broken = False
            if pickaxe.durability <= 0:
                pickaxe_broken = True
                item.delete_item(pickaxe.id)
            else:
                item.edit_item(sought_item=pickaxe.id,
                               property="durability",
                               new_value=pickaxe.durability)

            if has_pickaxe or has_super_pickaxe is True:
                if has_super_pickaxe:
                    poudrin_chance = 10
                    extra_slime_chance = 20
                    yield_celling = 300
                    extra_celling = 3
                else:
                    poudrin_chance = 5
                    extra_slime_chance = 10
                    yield_celling = 200
                    extra_celling = 2

                if random.randint(1, 100) < poudrin_chance:
                    poudrin_object = config.item_map.get("poudrin")
                    item.create_item(poudrin_object)
                    found_poudrin = True
            else:
                yield_celling = 100
                extra_slime_chance = 5
                extra_celling = 1

            # Select a random number from 1 to 100 to provide the user with.
            mine_yield = random.randint(1, yield_celling)

            # Add the slime to the player's slimes.
            player_data.slimes += mine_yield
            player_data.hunger += random.randint(1, 5)
            player_data.persist()

            response = "You mined {mine_yield} slime!".format(
                mine_yield=mine_yield)

            if random.randint(1, 100) < extra_slime_chance:
                extra_yield = (random.randint(1, yield_celling) *
                               random.randint(1, extra_celling))
                player_data.slimes += extra_yield
                player_data.persist()
                response += "<br><b>Lucky!</b> You hit an extra big vein of slime, you got {} extra slime!".format(
                    extra_yield)

            if found_poudrin:
                response += "<br>You found a <b>slime poudrin</b>! You could probably sell this bad boy for a FORTUNE!"

            if pickaxe_broken:
                response += "<br>Oh no! Your pickaxe broke!"

            mine_sound = pygame.mixer.Sound("media/sounds/mine.wav")
            pygame.mixer.Sound.play(mine_sound)
        else:
            response = "You're too hungry to mine any more slime! You'll have to eat something..."

    else:
        required_location = config.id_to_location.get(config.location_id_mines)
        response = config.text_invalid_location.format(
            location_name=required_location.name)

    return response
Exemple #15
0
 def add_item_from_token(self, token, coords):
     new_item = item.create_item(token)
     self.grid[coords].add_item(new_item)
     return new_item
Exemple #16
0
	def process_events(self, events):
		for event in events:
			if event.type==pygame.KEYDOWN:
				if event.key==pygame.K_ESCAPE:
					self.finish()
				if self.selected_item:
					if event.key==pygame.K_x:
						if self.selected_item_is_owned:
							self.selected_item.dequip()
							self.first_start()
						else:
							ui_states.interdict_ok(self.root, title="Error", text="Not yours!", button = "OK")
					if event.key==pygame.K_d:
						if self.selected_item_is_owned and self.shop_editable:
							if self.selected_item.equipped==-1:
								self.root.state_manager.states["game"].entities.append(
									ship.create_ship(self.root, "cargo_pod_generic", self.selected_item.parent.rigidbody.x, self.selected_item.parent.rigidbody.y, 1,1)
									)
								self.root.state_manager.states["game"].entities[-1].pick_up(self.selected_item)
								del self.selected_item.parent.inventory[self.selected_item.parent.inventory.index(self.selected_item)]
								self.first_start()
							else:
								ui_states.interdict_ok(self.root, title="Error", text="Cannot drop equipped item!%nDequip with X first", button = "OK")
						elif not self.shop_editable:
							ui_states.interdict_ok(self.root, title="Error", text="Not Editable", button = "OK")
						else:
							ui_states.interdict_ok(self.root, title="Error", text="Not yours!", button = "OK")
					if event.key==pygame.K_u:
						if self.selected_item_is_owned and self.shop_editable:
							self.selected_item.fire()
						elif not self.shop_editable:
							ui_states.interdict_ok(self.root, title="Error", text="Not Editable", button = "OK")
						else:
							ui_states.interdict_ok(self.root, title="Error", text="Not yours!", button = "OK")
					if event.key==pygame.K_e:
						if self.selected_item_is_owned and self.shop_editable:
							self.root.state_manager.start_interdicting("hardpoint_select", {
								"inv_id":self.sm_id,
								"item":self.selected_item
							})
						elif not self.shop_editable:
							ui_states.interdict_ok(self.root, title="Error", text="Not Editable", button = "OK")
						else:
							ui_states.interdict_ok(self.root, title="Error", text="Not yours!", button = "OK")
					if event.key==pygame.K_s:
						if self.shop_editable:
							if self.selected_item.equipped==-1:
								self.selected_item.parent.try_stack(self.selected_item)
								self.first_start()
							else:
								ui_states.interdict_ok(self.root, title="Error", text="Dequip first", button = "OK")
						else:
							ui_states.interdict_ok(self.root, title="Error", text="Not Editable", button = "OK")
					if event.key==pygame.K_a:
						if self.shop_editable:
							text=inputbox.ask(self.root.screen.screen, "Number to take >> ")
							if text=="meme man 2k14" and self.selected_item.id_str=="money":
								self.ship.inventory.append(item.create_item(absroot, "moneygun", self.ship))
								self.first_start()
								critical("Paul Blart Mode Enabled")
							try:
								self.selected_item.parent.try_split(self.selected_item,
								int(text)
								)
							except AssertionError as e:
								ui_states.interdict_ok(absroot, title="Failure", text=str(e), button = "OK")
							self.first_start()
						else:
							ui_states.interdict_ok(self.root, title="Error", text="Not Editable", button = "OK")
					if event.key==pygame.K_t and self.is_shop:
						if self.selected_item_is_owned and self.shop_editable:
							if overlaps(self.selected_item.tags, self.shop_other.config.get("buys", ["_all"])) and self.selected_item.can_sell:
								cost=self.selected_item.get_cost()*absroot.galaxy.get_sector().get_sell_price(self.selected_item)
								def _yes(*a,**k):
									self.shop_other.pick_up(self.selected_item)
									del self.selected_item.parent.inventory[self.selected_item.parent.inventory.index(self.selected_item)]
									self.selected_item.reparent(self.shop_other)
									
									
									self.ship.inventory.append(item.create_item(absroot, "money", self.ship))
									self.ship.inventory[-1].count=cost
									self.ship.try_stack(self.ship.inventory[-1])
									self.selected_item=None
									self.first_start()
								if absroot.settings["gameplay"]["buysell_confirm"]:
									ui_states.interdict_yn(self.root, title="Confirm", text="Are you sure you want to sell "+str(self.selected_item.count)+" "+self.selected_item.name+" for "+str(cost),
									 button_y = "SELL", button_n="NO", callback_y=_yes)
								else:
									_yes()
							elif not self.selected_item.can_sell:
								ui_states.interdict_ok(self.root, title="Sorry...", text="You can't sell that", button = "OK")
							else:
								ui_states.interdict_ok(self.root, title="Sorry...", text="I don't buy that", button = "OK")

						elif not self.shop_editable:
							ui_states.interdict_ok(self.root, title="Error", text="Not Editable", button = "OK")
						else:
							if self.selected_item.can_buy:
								if self.ship.get_item("money"):
									cost=self.selected_item.get_cost()*absroot.galaxy.get_sector().get_buy_price(self.selected_item)
									if self.ship.get_item("money").count>cost:
										def _yes(*a, **k):
											self.ship.pick_up(self.selected_item)

											del self.selected_item.parent.inventory[self.selected_item.parent.inventory.index(self.selected_item)]
											
											self.selected_item.reparent(self.ship)
											
											self.ship.get_item("money").consume(cost)
											self.first_start()
											self.selected_item=None
										if absroot.settings["gameplay"]["buysell_confirm"]:
											ui_states.interdict_yn(self.root, title="Confirm", text="Are you sure you want to buy "+str(self.selected_item.count)+" "+self.selected_item.name+" for "+str(cost),
								 			 button_y = "BUY", button_n="NO", callback_y=_yes)
										else:
											_yes()
									else:
										ui_states.interdict_ok(self.root, title="Sorry...", text="You don't have enough money.%nNeed "+str(cost), button = "OK")
								else:
									ui_states.interdict_ok(self.root, title="Sorry...", text="You don't even have 1 money!", button = "OK")
							else:
								ui_states.interdict_ok(self.root, title="Sorry...", text="You can't buy that", button = "OK")

			if event.type==pygame.MOUSEBUTTONDOWN:
				adj_pos=list(pygame.mouse.get_pos())
				#adj_pos[1]+=self.OFFSET
				if event.button==1:	
					for l in self.tiles:
						if l[1].collidepoint(adj_pos):
							self.selected_item=l[0]
							self.selected_item_is_owned=l[3]
				if event.button==4:
					for l in self.tiles:
						l[1].move_ip(0,64)
					self.initial_offset+=64
				if event.button==5:
					for l in self.tiles:
						l[1].move_ip(0,-64)
					self.initial_offset-=64
Exemple #17
0
    def process_events(self, events):
        for event in events:
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    self.finish()
                if self.selected_item:
                    if event.key == pygame.K_x:
                        if self.selected_item_is_owned:
                            self.selected_item.dequip()
                            self.first_start()
                        else:
                            ui_states.interdict_ok(self.root,
                                                   title="Error",
                                                   text="Not yours!",
                                                   button="OK")
                    if event.key == pygame.K_d:
                        if self.selected_item_is_owned and self.shop_editable:
                            if self.selected_item.equipped == -1:
                                self.root.state_manager.states[
                                    "game"].entities.append(
                                        ship.create_ship(
                                            self.root, "cargo_pod_generic",
                                            self.selected_item.parent.
                                            rigidbody.x, self.selected_item.
                                            parent.rigidbody.y, 1, 1))
                                self.root.state_manager.states[
                                    "game"].entities[-1].pick_up(
                                        self.selected_item)
                                del self.selected_item.parent.inventory[
                                    self.selected_item.parent.inventory.index(
                                        self.selected_item)]
                                self.first_start()
                            else:
                                ui_states.interdict_ok(
                                    self.root,
                                    title="Error",
                                    text=
                                    "Cannot drop equipped item!%nDequip with X first",
                                    button="OK")
                        elif not self.shop_editable:
                            ui_states.interdict_ok(self.root,
                                                   title="Error",
                                                   text="Not Editable",
                                                   button="OK")
                        else:
                            ui_states.interdict_ok(self.root,
                                                   title="Error",
                                                   text="Not yours!",
                                                   button="OK")
                    if event.key == pygame.K_u:
                        if self.selected_item_is_owned and self.shop_editable:
                            self.selected_item.fire()
                        elif not self.shop_editable:
                            ui_states.interdict_ok(self.root,
                                                   title="Error",
                                                   text="Not Editable",
                                                   button="OK")
                        else:
                            ui_states.interdict_ok(self.root,
                                                   title="Error",
                                                   text="Not yours!",
                                                   button="OK")
                    if event.key == pygame.K_e:
                        if self.selected_item_is_owned and self.shop_editable:
                            self.root.state_manager.start_interdicting(
                                "hardpoint_select", {
                                    "inv_id": self.sm_id,
                                    "item": self.selected_item
                                })
                        elif not self.shop_editable:
                            ui_states.interdict_ok(self.root,
                                                   title="Error",
                                                   text="Not Editable",
                                                   button="OK")
                        else:
                            ui_states.interdict_ok(self.root,
                                                   title="Error",
                                                   text="Not yours!",
                                                   button="OK")
                    if event.key == pygame.K_s:
                        if self.shop_editable:
                            if self.selected_item.equipped == -1:
                                self.selected_item.parent.try_stack(
                                    self.selected_item)
                                self.first_start()
                            else:
                                ui_states.interdict_ok(self.root,
                                                       title="Error",
                                                       text="Dequip first",
                                                       button="OK")
                        else:
                            ui_states.interdict_ok(self.root,
                                                   title="Error",
                                                   text="Not Editable",
                                                   button="OK")
                    if event.key == pygame.K_a:
                        if self.shop_editable:
                            text = inputbox.ask(self.root.screen.screen,
                                                "Number to take >> ")
                            if text == "meme man 2k14" and self.selected_item.id_str == "money":
                                self.ship.inventory.append(
                                    item.create_item(absroot, "moneygun",
                                                     self.ship))
                                self.first_start()
                                critical("Paul Blart Mode Enabled")
                            try:
                                self.selected_item.parent.try_split(
                                    self.selected_item, int(text))
                            except AssertionError as e:
                                ui_states.interdict_ok(absroot,
                                                       title="Failure",
                                                       text=str(e),
                                                       button="OK")
                            self.first_start()
                        else:
                            ui_states.interdict_ok(self.root,
                                                   title="Error",
                                                   text="Not Editable",
                                                   button="OK")
                    if event.key == pygame.K_t and self.is_shop:
                        if self.selected_item_is_owned and self.shop_editable:
                            if overlaps(
                                    self.selected_item.tags,
                                    self.shop_other.config.get(
                                        "buys",
                                        ["_all"
                                         ])) and self.selected_item.can_sell:
                                cost = self.selected_item.get_cost(
                                ) * absroot.galaxy.get_sector().get_sell_price(
                                    self.selected_item)

                                def _yes(*a, **k):
                                    self.shop_other.pick_up(self.selected_item)
                                    del self.selected_item.parent.inventory[
                                        self.selected_item.parent.inventory.
                                        index(self.selected_item)]
                                    self.selected_item.reparent(
                                        self.shop_other)

                                    self.ship.inventory.append(
                                        item.create_item(
                                            absroot, "money", self.ship))
                                    self.ship.inventory[-1].count = cost
                                    self.ship.try_stack(
                                        self.ship.inventory[-1])
                                    self.selected_item = None
                                    self.first_start()

                                if absroot.settings["gameplay"][
                                        "buysell_confirm"]:
                                    ui_states.interdict_yn(
                                        self.root,
                                        title="Confirm",
                                        text="Are you sure you want to sell " +
                                        str(self.selected_item.count) + " " +
                                        self.selected_item.name + " for " +
                                        str(cost),
                                        button_y="SELL",
                                        button_n="NO",
                                        callback_y=_yes)
                                else:
                                    _yes()
                            elif not self.selected_item.can_sell:
                                ui_states.interdict_ok(
                                    self.root,
                                    title="Sorry...",
                                    text="You can't sell that",
                                    button="OK")
                            else:
                                ui_states.interdict_ok(self.root,
                                                       title="Sorry...",
                                                       text="I don't buy that",
                                                       button="OK")

                        elif not self.shop_editable:
                            ui_states.interdict_ok(self.root,
                                                   title="Error",
                                                   text="Not Editable",
                                                   button="OK")
                        else:
                            if self.selected_item.can_buy:
                                if self.ship.get_item("money"):
                                    cost = self.selected_item.get_cost(
                                    ) * absroot.galaxy.get_sector(
                                    ).get_buy_price(self.selected_item)
                                    if self.ship.get_item(
                                            "money").count > cost:

                                        def _yes(*a, **k):
                                            self.ship.pick_up(
                                                self.selected_item)

                                            del self.selected_item.parent.inventory[
                                                self.selected_item.parent.
                                                inventory.index(
                                                    self.selected_item)]

                                            self.selected_item.reparent(
                                                self.ship)

                                            self.ship.get_item(
                                                "money").consume(cost)
                                            self.first_start()
                                            self.selected_item = None

                                        if absroot.settings["gameplay"][
                                                "buysell_confirm"]:
                                            ui_states.interdict_yn(
                                                self.root,
                                                title="Confirm",
                                                text=
                                                "Are you sure you want to buy "
                                                +
                                                str(self.selected_item.count) +
                                                " " + self.selected_item.name +
                                                " for " + str(cost),
                                                button_y="BUY",
                                                button_n="NO",
                                                callback_y=_yes)
                                        else:
                                            _yes()
                                    else:
                                        ui_states.interdict_ok(
                                            self.root,
                                            title="Sorry...",
                                            text=
                                            "You don't have enough money.%nNeed "
                                            + str(cost),
                                            button="OK")
                                else:
                                    ui_states.interdict_ok(
                                        self.root,
                                        title="Sorry...",
                                        text="You don't even have 1 money!",
                                        button="OK")
                            else:
                                ui_states.interdict_ok(
                                    self.root,
                                    title="Sorry...",
                                    text="You can't buy that",
                                    button="OK")

            if event.type == pygame.MOUSEBUTTONDOWN:
                adj_pos = list(pygame.mouse.get_pos())
                #adj_pos[1]+=self.OFFSET
                if event.button == 1:
                    for l in self.tiles:
                        if l[1].collidepoint(adj_pos):
                            self.selected_item = l[0]
                            self.selected_item_is_owned = l[3]
                if event.button == 4:
                    for l in self.tiles:
                        l[1].move_ip(0, 64)
                    self.initial_offset += 64
                if event.button == 5:
                    for l in self.tiles:
                        l[1].move_ip(0, -64)
                    self.initial_offset -= 64
Exemple #18
0
	def try_split(self, itemx, count):
		assert count<itemx.count, "Tried to take more than you have"
		assert count>0, "Tried to take less than 1"
		itemx.count-=count
		self.inventory.append(item.create_item(self.root, itemx.id_str, self, -1, count))
Exemple #19
0
 def setUp(self):
     self.test_item = item.create_item('GENERIC_ITEM')