mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-29 06:44:00 -06:00
mechanic: move act and plot bar to quest book
This commit is contained in:
+37
-27
@@ -73,19 +73,23 @@ class Stats(SignalMixin):
|
|||||||
self.emit("change")
|
self.emit("change")
|
||||||
|
|
||||||
|
|
||||||
class QuestBook:
|
class QuestBook(SignalMixin):
|
||||||
|
signals = ["complete_act", "complete_quest"]
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self._quests: T.List[str] = []
|
self._quests: T.List[str] = []
|
||||||
|
self.act = 0
|
||||||
|
self.plot_bar = Bar(max_=26)
|
||||||
self.quest_bar = Bar(max_=1)
|
self.quest_bar = Bar(max_=1)
|
||||||
self.monster: T.Optional[Monster] = None
|
self.monster: T.Optional[Monster] = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current(self) -> T.Optional[str]:
|
def current_quest(self) -> T.Optional[str]:
|
||||||
if self._quests:
|
if self._quests:
|
||||||
return self._quests[-1]
|
return self._quests[-1]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def add(self, name: str) -> None:
|
def add_quest(self, name: str) -> None:
|
||||||
logger.info("Commencing quest: %s", name)
|
logger.info("Commencing quest: %s", name)
|
||||||
self._quests = self._quests[-100:]
|
self._quests = self._quests[-100:]
|
||||||
self._quests.append(name)
|
self._quests.append(name)
|
||||||
@@ -239,7 +243,7 @@ class PlotTask(RegularTask):
|
|||||||
|
|
||||||
|
|
||||||
class Player(SignalMixin):
|
class Player(SignalMixin):
|
||||||
signals = ["new_task", "level_up", "complete_act"]
|
signals = ["new_task", "level_up"]
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@@ -254,11 +258,15 @@ class Player(SignalMixin):
|
|||||||
self.race: Race = race
|
self.race: Race = race
|
||||||
self.class_: Class = class_
|
self.class_: Class = class_
|
||||||
self.stats: Stats = stats
|
self.stats: Stats = stats
|
||||||
self.act = 0
|
|
||||||
|
|
||||||
self.exp_bar = Bar(max_=level_up_time(1))
|
self.exp_bar = Bar(max_=level_up_time(1))
|
||||||
self.level = 1
|
self.level = 1
|
||||||
|
|
||||||
|
self.quest_book = QuestBook()
|
||||||
|
self.inventory = Inventory(capacity=10 + self.stats[StatType.strength])
|
||||||
|
self.equipment = Equipment()
|
||||||
|
self.spell_book = SpellBook()
|
||||||
|
|
||||||
self.task_bar = Bar(max_=0)
|
self.task_bar = Bar(max_=0)
|
||||||
self.task: T.Optional[BaseTask] = None
|
self.task: T.Optional[BaseTask] = None
|
||||||
self.queue: T.List[BaseTask] = [
|
self.queue: T.List[BaseTask] = [
|
||||||
@@ -280,16 +288,9 @@ class Player(SignalMixin):
|
|||||||
"you set out on a long and dangerous journey",
|
"you set out on a long and dangerous journey",
|
||||||
4_000,
|
4_000,
|
||||||
),
|
),
|
||||||
PlotTask(f"Loading {act_name(self.act + 1)}", 2_000),
|
PlotTask(f"Loading {act_name(self.quest_book.act + 1)}", 2_000),
|
||||||
]
|
]
|
||||||
|
|
||||||
self.plot_bar = Bar(max_=sum(task.duration for task in self.queue))
|
|
||||||
self.quest_book = QuestBook()
|
|
||||||
|
|
||||||
self.inventory = Inventory(capacity=10 + self.stats[StatType.strength])
|
|
||||||
self.equipment = Equipment()
|
|
||||||
self.spell_book = SpellBook()
|
|
||||||
|
|
||||||
self.set_task(RegularTask("Loading", 2_000))
|
self.set_task(RegularTask("Loading", 2_000))
|
||||||
|
|
||||||
def set_task(self, task: BaseTask) -> None:
|
def set_task(self, task: BaseTask) -> None:
|
||||||
@@ -417,10 +418,10 @@ class Simulation:
|
|||||||
self.player.exp_bar.increment(self.player.task_bar.max_ / 1000)
|
self.player.exp_bar.increment(self.player.task_bar.max_ / 1000)
|
||||||
|
|
||||||
# advance quest
|
# advance quest
|
||||||
if gain and self.player.act >= 1:
|
if gain and self.player.quest_book.act >= 1:
|
||||||
if (
|
if (
|
||||||
self.player.quest_book.quest_bar.done
|
self.player.quest_book.quest_bar.done
|
||||||
or self.player.quest_book.current is None
|
or self.player.quest_book.current_quest is None
|
||||||
):
|
):
|
||||||
self.complete_quest()
|
self.complete_quest()
|
||||||
else:
|
else:
|
||||||
@@ -429,11 +430,11 @@ class Simulation:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# advance plot
|
# advance plot
|
||||||
if gain or not self.player.act:
|
if gain:
|
||||||
if self.player.plot_bar.done:
|
if self.player.quest_book.plot_bar.done:
|
||||||
self.interplot_cinematic()
|
self.interplot_cinematic()
|
||||||
else:
|
else:
|
||||||
self.player.plot_bar.increment(
|
self.player.quest_book.plot_bar.increment(
|
||||||
self.player.task_bar.max_ / 1000
|
self.player.task_bar.max_ / 1000
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -516,17 +517,21 @@ class Simulation:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def complete_act(self) -> None:
|
def complete_act(self) -> None:
|
||||||
self.player.act += 1
|
self.player.quest_book.act += 1
|
||||||
self.player.plot_bar.reset(60 * 60 * (1 + 5 * self.player.act))
|
self.player.quest_book.plot_bar.reset(
|
||||||
if self.player.act > 1:
|
60 * 60 * (1 + 5 * self.player.quest_book.act)
|
||||||
|
)
|
||||||
|
if self.player.quest_book.act > 1:
|
||||||
self.player.win_item()
|
self.player.win_item()
|
||||||
self.player.win_equipment()
|
self.player.win_equipment()
|
||||||
self.player.emit("complete_act")
|
self.player.quest_book.emit("complete_act")
|
||||||
|
|
||||||
def complete_quest(self) -> None:
|
def complete_quest(self) -> None:
|
||||||
self.player.quest_book.quest_bar.reset(50 + random.below_low(1000))
|
self.player.quest_book.quest_bar.reset(50 + random.below_low(1000))
|
||||||
if self.player.quest_book.current:
|
if self.player.quest_book.current_quest:
|
||||||
logger.info("Quest completed: %s", self.player.quest_book.current)
|
logger.info(
|
||||||
|
"Quest completed: %s", self.player.quest_book.current_quest
|
||||||
|
)
|
||||||
random.choice(
|
random.choice(
|
||||||
[
|
[
|
||||||
self.player.win_spell,
|
self.player.win_spell,
|
||||||
@@ -558,7 +563,8 @@ class Simulation:
|
|||||||
else:
|
else:
|
||||||
raise AssertionError
|
raise AssertionError
|
||||||
|
|
||||||
self.player.quest_book.add(caption)
|
self.player.quest_book.add_quest(caption)
|
||||||
|
self.player.quest_book.emit("complete_quest")
|
||||||
|
|
||||||
def interplot_cinematic(self) -> None:
|
def interplot_cinematic(self) -> None:
|
||||||
def enqueue(task: BaseTask) -> None:
|
def enqueue(task: BaseTask) -> None:
|
||||||
@@ -605,7 +611,7 @@ class Simulation:
|
|||||||
|
|
||||||
s = random.below(3)
|
s = random.below(3)
|
||||||
for i in itertools.count(start=1):
|
for i in itertools.count(start=1):
|
||||||
if i > random.below(1 + self.player.act + 1):
|
if i > random.below(1 + self.player.quest_book.act + 1):
|
||||||
break
|
break
|
||||||
s += 1 + random.below(2)
|
s += 1 + random.below(2)
|
||||||
if s % 3 == 0:
|
if s % 3 == 0:
|
||||||
@@ -686,7 +692,11 @@ class Simulation:
|
|||||||
else:
|
else:
|
||||||
raise AssertionError
|
raise AssertionError
|
||||||
|
|
||||||
enqueue(PlotTask(f"Loading {act_name(self.player.act + 1)}", 1_000))
|
enqueue(
|
||||||
|
PlotTask(
|
||||||
|
f"Loading {act_name(self.player.quest_book.act + 1)}", 1_000
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def special_item() -> str:
|
def special_item() -> str:
|
||||||
|
|||||||
@@ -219,8 +219,8 @@ class PlotView(urwid.Pile):
|
|||||||
self.list_box = urwid.ListBox([])
|
self.list_box = urwid.ListBox([])
|
||||||
self.plot_bar = CustomProgressBar()
|
self.plot_bar = CustomProgressBar()
|
||||||
|
|
||||||
self.player.connect("complete_act", self.sync_act_add)
|
self.player.quest_book.connect("complete_act", self.sync_act_add)
|
||||||
self.player.plot_bar.connect("change", self.sync_position)
|
self.player.quest_book.plot_bar.connect("change", self.sync_position)
|
||||||
self.sync()
|
self.sync()
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
@@ -237,13 +237,14 @@ class PlotView(urwid.Pile):
|
|||||||
def sync_acts(self) -> None:
|
def sync_acts(self) -> None:
|
||||||
del self.list_box.body[:]
|
del self.list_box.body[:]
|
||||||
for act_number in range(
|
for act_number in range(
|
||||||
max(0, self.player.act - self.cutoff), self.player.act
|
max(0, self.player.quest_book.act - self.cutoff),
|
||||||
|
self.player.quest_book.act,
|
||||||
):
|
):
|
||||||
self.list_box.body.append(
|
self.list_box.body.append(
|
||||||
ReadOnlyCheckBox(act_name(act_number), state=True)
|
ReadOnlyCheckBox(act_name(act_number), state=True)
|
||||||
)
|
)
|
||||||
self.list_box.body.append(
|
self.list_box.body.append(
|
||||||
ReadOnlyCheckBox(act_name(self.player.act), state=False)
|
ReadOnlyCheckBox(act_name(self.player.quest_book.act), state=False)
|
||||||
)
|
)
|
||||||
|
|
||||||
def sync_act_add(self):
|
def sync_act_add(self):
|
||||||
@@ -251,13 +252,13 @@ class PlotView(urwid.Pile):
|
|||||||
if self.list_box.body:
|
if self.list_box.body:
|
||||||
self.list_box.body[-1].set_state(True)
|
self.list_box.body[-1].set_state(True)
|
||||||
self.list_box.body.append(
|
self.list_box.body.append(
|
||||||
ReadOnlyCheckBox(act_name(self.player.act), state=False)
|
ReadOnlyCheckBox(act_name(self.player.quest_book.act), state=False)
|
||||||
)
|
)
|
||||||
self.list_box.set_focus(len(self.list_box.body) - 1)
|
self.list_box.set_focus(len(self.list_box.body) - 1)
|
||||||
|
|
||||||
def sync_position(self) -> None:
|
def sync_position(self) -> None:
|
||||||
self.plot_bar.set_completion(self.player.plot_bar.position)
|
self.plot_bar.set_completion(self.player.quest_book.plot_bar.position)
|
||||||
self.plot_bar.set_max(self.player.plot_bar.max_)
|
self.plot_bar.set_max(self.player.quest_book.plot_bar.max_)
|
||||||
|
|
||||||
|
|
||||||
class TaskView(urwid.Pile):
|
class TaskView(urwid.Pile):
|
||||||
|
|||||||
Reference in New Issue
Block a user