瀏覽代碼

Add roll support for difficulty_class.

Sam Jaffe 4 年之前
父節點
當前提交
08ed1f1d13
共有 1 個文件被更改,包括 7 次插入2 次删除
  1. 7 2
      src/roll.cxx

+ 7 - 2
src/roll.cxx

@@ -18,8 +18,13 @@ die_roll::operator int() const {
 }
 
 dice_roll::operator int() const {
-  return std::accumulate(sub_rolls.begin(), sub_rolls.end(), 0) +
+  auto subtotal = std::accumulate(sub_rolls.begin(), sub_rolls.end(), 0) +
          std::accumulate(modifiers.begin(), modifiers.end(), 0);
+  if (dc.comp != difficulty_class::test::None) {
+    return static_cast<int>(dc(subtotal));
+  } else {
+    return subtotal;
+  }
 }
 
 die_roll roll_impl(die const & d, engine::random & gen) {
@@ -35,7 +40,7 @@ dice_roll roll_impl(dice const & d, engine::random & gen) {
   for (die const & di : d.of) {
     hits.push_back(roll_impl(di, gen));
   }
-  return {hits, d.modifier};
+  return {hits, d.modifier, d.dc};
 }
 
 roller::roller() : gen() {}