def test_npc_interaction(): """ start | w1 <- dialog becomes available | end """ game = Game('test') start = Waypoint(game.graph, 'start') w1 = Waypoint(game.graph, 'w1') end = Waypoint(game.graph, 'end') start.add_destination(w1) w1.add_destination(end) game.set_start(start) npc_dialog = Dialog() ds = Mail(npc_dialog.graph, 'test subject', 'test body') with pytest.raises(PlayerStateException): NonPlayableCharacter('test', 'npc', npc_dialog) npc_dialog.set_start(ds) npc_dialog.start.waypoints.append(w1) game.add_non_playable_character(NonPlayableCharacter('test', 'npc', npc_dialog)) instance = game.create_new_game() instance.add_player(Player('test', 'player'), 'testy', 'mctestpants') assert len(instance.npc_states) == 1 assert ds not in [k for k, _ in instance.player_states[0].inventory.values()] interactions = instance.player_states[0].move_to(w1) assert len(interactions.keys()) == 1 and len(interactions.values()) == 1
def game(): """ start (path with dialog) / \ w1 (m1) w2 (d1) \ / knot1 / | \ w3 w4 w5 <- with task t1,t2,t3 \ | end <- task from dialog td1 :return: game with described graph """ #TODO, check interaction model in waypoint dialog = Dialog() dialog_start = Mail(dialog.graph, 'start sub', 'start body') m1 = Mail(dialog.graph, 'second sub', 'second body') td1 = Task(None, 'some task 1', 'some task', 'some solution') d1 = Speech(dialog.graph, 'content', task=td1) game = Game('test') start = Waypoint(game.graph, 'start') w1 = Waypoint(game.graph, 'w1') w2 = Waypoint(game.graph, 'w2') knot = Waypoint(game.graph, 'knot') w3 = Waypoint(game.graph, 'w3') t1 = Task(w3, 'some task 1', 'some task') w4 = Waypoint(game.graph, 'w4') t2 = Task(w4, 'some task 2', 'some task') w5 = Waypoint(game.graph, 'w5') t3 = Task(w5, 'some task 3', 'some task') end = Waypoint(game.graph, 'end') start.add_destination(w1, 1.1) start.add_destination(w2) w1.add_destination(knot) w2.add_destination(knot) knot.add_task(t1) knot.add_task(t2) knot.add_task(t3) w3.add_destination(end) w4.add_destination(end) game.set_start(start) dialog_end = Speech(dialog.graph, 'next content', destination=end) dialog.set_start(dialog_start) dialog_start.add_follow_up(d1) dialog_start.add_follow_up(m1) dialog_start.waypoints.append(start) d1.add_follow_up(dialog_end, None) game.add_non_playable_character(NonPlayableCharacter( 'bob', 'test', dialog)) return game
def test_npc_required_response(): """ start | w1 <- dialog becomes available | end <- blocked till dialog in phase 2 (ds2) """ game = Game('test') start = Waypoint(game.graph, 'start') w1 = Waypoint(game.graph, 'w1') end = Waypoint(game.graph, 'end') game.set_start(start) npc_dialog = Dialog() ds1 = Mail(npc_dialog.graph, 'test subject 1', 'test body 1') ds1.waypoints.append(w1) start.add_destination(w1) npc_dialog.set_start(ds1) ds2 = Mail(npc_dialog.graph, 'test subject 2', 'test body 2', items=['test item'], destination=end) ds1.add_follow_up(ds2, end) w1.add_interaction(ds2) npc = NonPlayableCharacter('test', 'npc', npc_dialog) game.add_non_playable_character(npc) instance = game.create_new_game() instance.add_player(Player('test', 'player'), 'testy', 'mctestpants') assert len(instance.player_states[0].available_moves()) == 1 interactions = instance.player_states[0].move_to(w1) assert len(instance.player_states[0].available_moves()) == 0 npc_instance = next(iter([n for n in instance.npc_states if n == npc]), None) if not npc_instance: assert fail('could not find npc instance in game instance') assert len(instance.player_states[0].inventory) == 0 npc_instance.update_player_dialog(instance.player_states[0], interactions[npc], 'mail response') assert len(instance.player_states[0].inventory) == 1 assert len(instance.player_states[0].available_moves()) == 1 assert instance.player_states[0].move_to(end)