Пример #1
0
def fight():

    player = game.get_player()
    pol = Police()

    #if fight was successful
    if pol.get_result(player.get_fighter_skills(), True):

        #fight off police, get to travel to new region so update
        universe = game.get_universe()
        universe.set_currentregion(game.get_potential_region())

        ship = game.get_player().get_ship()
        ship.set_fuel(game.get_potential_fuel())

        return json.dumps({"result": "success"})

    #change current region to random one
    regions = game.get_regions()
    universe = game.get_universe()
    rand = random.randint(0, len(regions) - 1)
    universe.set_currentregion(regions[rand])

    #player loses 40 hit points on their ship
    ship = player.get_ship()
    hp_lost = 40
    ship.set_health(ship.get_health() - hp_lost)

    #police confiscate items
    items = request.form["items"]
    items = json.loads(items)
    player.remove_from_inventory(items)

    return json.dumps({
        "result": "fail",
        "health_penalty": hp_lost,
        "health": ship.get_health()
    })
Пример #2
0
def flee():
    #whether or not player is successful, region remains same

    player = game.get_player()
    pol = Police()

    #False is for not using fighter skills
    if pol.get_result(player.get_pilotskills(), False):
        ship = game.get_player().get_ship()
        ship.set_fuel(game.get_potential_fuel())
        return json.dumps({"result": "success"})

    #credit penalty is 15-30% of player's credits
    credit_penalty = int(player.get_credits() * (random.randint(15, 30) / 100))
    player.set_credits(player.get_credits() - credit_penalty)

    print(credit_penalty)
    print(player.get_credits())

    #player loses 10 hit points on their ship
    ship = player.get_ship()
    hp_lost = 10
    ship.set_health(ship.get_health() - hp_lost)

    #police confiscate items
    items = request.form["items"]
    items = json.loads(items)
    player.remove_from_inventory(items)

    return json.dumps({
        "result": "fail",
        "health_penalty": hp_lost,
        "health": ship.get_health(),
        "credit_penalty": credit_penalty,
        "credits": player.get_credits()
    })