コード例 #1
0
ファイル: test_statistic.py プロジェクト: Rydra/rftg-tracker
def test_compatible_with_any_kind_of_game():
    description = 'Increases you defense and stamina, but reduces your speed'
    properties = [{
        'statistic': 'DEFENSE',
        'value': +5,
        'factor': 'additive'
    }, {
        'statistic': 'STAMINA',
        'value': +2,
        'factor': 'additive'
    }, {
        'statistic': 'SPEED',
        'value': -2,
        'factor': 'additive'
    }]
    hylian_shield = Enhancer(name='Hylian Shield',
                             description=description,
                             properties=properties)

    empire = Player('Cherrymilk')
    empire.add_statistic('DEFENSE', value=5)
    empire.add_statistic('STAMINA', value=4)
    empire.add_statistic('SPEED', value=4)

    empire.add_enhancer(hylian_shield)

    statistics = empire.get_statistics()

    assert statistics['DEFENSE'].actual_value == 10
    assert statistics['STAMINA'].actual_value == 6
    assert statistics['SPEED'].actual_value == 2
コード例 #2
0
ファイル: test_statistic.py プロジェクト: Rydra/rftg-tracker
def test_an_empire_can_add_enhancers():
    properties = [{
        'statistic': 'MILITARY',
        'value': 2,
        'factor': 'multiplicative'
    }, {
        'statistic': 'DRAW_CARDS_ON_EXPLORE',
        'value': 0.5,
        'factor': 'multiplicative'
    }]
    description = 'Boosts military, but halves the amount of cards you see when exploring'
    uberBombardier = Enhancer(name='UberBombardier',
                              description=description,
                              properties=properties)

    empire = Player('Cherrymilk')
    empire.add_enhancer(uberBombardier)
    empire.add_statistic('MILITARY', value=2)
    empire.add_statistic('DRAW_CARDS_ON_EXPLORE')

    statistics = empire.get_statistics()

    assert statistics['MILITARY'].original_value == 2
    assert statistics['MILITARY'].actual_value == 4
    assert statistics['DRAW_CARDS_ON_EXPLORE'].actual_value == 0
コード例 #3
0
ファイル: test_statistic.py プロジェクト: Rydra/rftg-tracker
def test_enhancers_may_define_their_own_formula():
    # Custom enhancers are applied in the end of all calculations
    description = 'Increases magic due to some secret formula'
    properties = [{
        'statistic':
        'MAGIC',
        'factor':
        'custom',
        'formula':
        'base_value * MULTIPLICATORS + STAMINA // 3 - SPEED // 5 + ADDITIONS'
    }, {
        'statistic': 'MAGIC',
        'value': 2,
        'factor': 'multiplicative'
    }, {
        'statistic': 'MAGIC',
        'value': 3,
        'factor': 'additive'
    }]

    stat_enhancer = Enhancer(name="Wild magic",
                             description=description,
                             properties=properties)

    player = Player('Hercule')
    player.add_statistic('SPEED', value=7)
    player.add_statistic('MAGIC', value=2)
    player.add_enhancer(stat_enhancer)

    statistics = player.get_statistics()
    assert statistics['MAGIC'].actual_value == 6
コード例 #4
0
ファイル: test_collector.py プロジェクト: Intey/pygamed
def test_collector_float():
    p = Player()
    c = Collector(2)
    r = Sticks(20)

    res = c.collect(r, 1.5)
    assert r.value == 18
    assert res.name == r.name
    assert res.value == 2
コード例 #5
0
ファイル: test_collector.py プロジェクト: Intey/pygamed
def test_collector_stopping():
    p = Player()
    c = Collector(2)
    r = Sticks(20)

    n1 = c.collect(r, 0.8)
    c.stop()  # player release collection key
    n2 = c.collect(r, 0.3)
    assert r.value == 20
    assert n1.value == 0
    assert n2.value == 0
コード例 #6
0
ファイル: test_collector.py プロジェクト: Intey/pygamed
def test_collector():
    p = Player()
    c = Collector(2)
    r = Sticks(20)
    collected = c.collect(r, 1.0)
    assert r.value == 18
    assert collected.value == 2

    collected = c.collect(r, 2)
    assert r.value == 14
    assert collected.value == 4
コード例 #7
0
ファイル: player_actor.py プロジェクト: Intey/pygamed
 def __init__(self, collide_manager: CollisionManagerGrid,
              keyboard_handler: KeyStateHandler) -> None:
     Actor.__init__(self,
                    'assets/user.png',
                    position=(20, 20),
                    domain=Player())
     self.cm = collide_manager
     self.key_handler = keyboard_handler
     self.schedule(self.update)
     self.accelerator = Accelerator(100, 5, 40)
     self.last_create_delta = 0
     self.create_cooldown = 500
     self.last_shoot_dt = 0
     self.shoot_rate = 2
コード例 #8
0
ファイル: test_statistic.py プロジェクト: Rydra/rftg-tracker
def test_stats_are_enhancers_as_well():
    description = 'Increases your ability to run, but for every 5 points you lose 1 point of strength'
    properties = [{
        'statistic': 'STRENGTH',
        'value': -1 / 5,
        'factor': 'additive',
        'depends_on': 'RUNNING'
    }]

    stat_enhancer = Enhancer(name="Speed per Strength",
                             description=description,
                             properties=properties)

    player = Player('Hercule')
    player.add_statistic('RUNNING', value=7)
    player.add_statistic('STRENGTH', value=4)
    player.add_enhancer(stat_enhancer)

    statistics = player.get_statistics()
    assert statistics['STRENGTH'].actual_value == 3
コード例 #9
0
ファイル: test_statistic.py プロジェクト: Rydra/rftg-tracker
def test_some_bonuses_may_depend_on_player_caracteristics():
    description = 'Boosts your might by one plus the number of pockets you have'  # For real
    properties = [{
        'statistic': 'MIGHT',
        'value': 1,
        'factor': 'additive'
    }, {
        'statistic': 'MIGHT',
        'value': 1,
        'factor': 'additive',
        'depends_on': 'POCKET'
    }]

    pocket_master = Enhancer(name='Pocket master',
                             description=description,
                             properties=properties)

    player = Player('Hercule')
    player.add_statistic('MIGHT', value=2)
    player.add_keyword('POCKET', amount=4)
    player.add_enhancer(pocket_master)

    statistics = player.get_statistics()
    assert statistics['MIGHT'].actual_value == 7
コード例 #10
0
ファイル: test_statistic.py プロジェクト: Rydra/rftg-tracker
def test_some_stats_require_multiplicative_percentages():
    description = 'Increases your chance to dodge'
    properties = [{
        'statistic': 'DODGE',
        'value': 0.25,
        'factor': 'additive-multiplicatively'
    }]
    ninja_boots = Enhancer(name='Ninja Boots',
                           description=description,
                           properties=properties)

    player = Player('Tixus')
    player.add_statistic('DODGE', value=0, needs_rounding=False)
    player.add_enhancer(ninja_boots)
    player.add_enhancer(ninja_boots)

    statistics = player.get_statistics()
    assert statistics['DODGE'].actual_value == 0.3125
コード例 #11
0
def deserialize(Type, v):
    if Type in [float, int, NoneType, str]:
        result = v
    elif issubclass(Type, enum.Enum):
        result = Type[v]
    elif Type in [Direction, Position]:
        x, y = v
        result = Type(x=deserialize(float, x), y=deserialize(float, y))
    elif Type == Map:
        result = Map(
            materials=[deserialize(Material, m) for m in v['materials']],
            objects=[(deserialize(Object, o), deserialize(Position, p))
                     for o, p in v['objects']],
            width=deserialize(int, v['width']))
    elif Type == Player:
        result = Player(name=deserialize(str, v['name']),
                        position=deserialize(Position, v['position']),
                        forward=deserialize(Direction, v['forward']))
    else:
        raise Exception("Cannot deserialize object of type {}".format(Type))
    assert isinstance(result, Type), "{} is not a {}".format(v, Type)
    return result
コード例 #12
0
ファイル: test_collector.py プロジェクト: Intey/pygamed
def test_collector_continuation():
    p = Player()
    c = Collector(2)
    r = Sticks(20)

    collected = c.collect(r, 0.5)
    assert r.value == 20
    assert collected.value == 0

    collected = c.collect(r, 0.5)
    assert r.value == 18
    assert collected.value == 2

    collected = c.collect(r, 1.1)
    assert r.value == 16, "1.1 delta should collect only as 1.0"
    assert collected.value == 2

    assert c.elapsed == 0.1, "collector should save rest time if not stopped"

    collected = c.collect(r, 0.9)
    assert r.value == 14, "should continue collect after over second collection"
    assert collected.value == 2
コード例 #13
0
ファイル: main.py プロジェクト: Rydra/rftg-tracker
def new_player(name):
    metadata = load_data_from_yaml()
    statistics = metadata['STATISTICS']

    player = Player(name)
    for statisticname in statistics:
        player.add_statistic(statisticname)

    base_enhancers = metadata['BASE_ENHANCERS']
    for base_enhancer in base_enhancers:
        enhancer_data = metadata['ENHANCERS'][base_enhancer]
        enhancer = Enhancer(enhancer_data['name'],
                            enhancer_data['description'],
                            enhancer_data['properties'])
        player.add_enhancer(enhancer)

    return player
コード例 #14
0
def player(user_: User = user(), ladder_id=0, score=0, earned_points=0, borrowed_points=0, ranking=0, wins=0, losses=0) -> Player:
    return Player(user_.user_id, user_.name, user_.email, user_.phone_number, user_.photo_url, user_.availability_text, user_.admin, ladder_id, score, earned_points, borrowed_points, ranking, wins, losses)
コード例 #15
0
def load_player_spawn(path):
    spawn = _load_json_document(os.path.join(path, 'spawn.json'))
    spawn_position, spawn_forward = _position_from_json(
        spawn['position']), _direction_from_json(spawn['forward'])
    return Player('steve', spawn_position, spawn_forward)
コード例 #16
0
def test_shoot():
    player = Player()
    bear = Bear()
    player.shoot(bear)
    assert bear.health == 80