Skip to content

Commit 1314bb8

Browse files
committed
Make ModPCFacRep easier to find in the CS
1 parent f659466 commit 1314bb8

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

WARNINGS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,12 @@ No instances of the detected marker exist in this file.
306306
### Uses ModReputation without an explicit target
307307
This script is probably changing an NPC's reputation instead of the player's.
308308

309+
### Uses ModPCFacRep without specifying a faction
310+
The faction argument is optional because it defaults to the speaker's faction, but this makes it hard to find these lines in the CS.
311+
312+
### Contains superfluous characters in a ModPCFacRep call
313+
This line includes commas or puts quotes around the reputation amount. This is pointless and makes it harder to find this line in the CS.
314+
309315
## Magic
310316

311317
### Uses effect

src/validators/scripts.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub struct ScriptValidator {
3838
needs_marker: Regex,
3939
marker_id: Regex,
4040
mod_reputation: Regex,
41+
mod_facrep: Regex,
4142
}
4243

4344
struct ScriptInfo {
@@ -184,6 +185,40 @@ impl Handler<'_> for ScriptValidator {
184185
);
185186
}
186187
}
188+
if let Some(captures) = self.mod_facrep.captures(code) {
189+
if captures.get(3).is_none() {
190+
if let TES3Object::DialogueInfo(info) = record {
191+
println!(
192+
"Info {} in topic {} uses ModPCFacRep without specifying a faction",
193+
info.id, topic.id
194+
);
195+
} else if let TES3Object::Script(script) = record {
196+
println!(
197+
"Script {} uses ModReputation without specifying a faction",
198+
script.id
199+
);
200+
}
201+
}
202+
let mut garbage = code.contains(',');
203+
if !garbage {
204+
if let Some(capture) = captures.get(1) {
205+
garbage = capture.as_str().contains('"');
206+
}
207+
}
208+
if garbage {
209+
if let TES3Object::DialogueInfo(info) = record {
210+
println!(
211+
"Info {} in topic {} contains superfluous characters in a ModPCFacRep call",
212+
info.id, topic.id
213+
);
214+
} else if let TES3Object::Script(script) = record {
215+
println!(
216+
"Script {} contains superfluous characters in a ModPCFacRep call",
217+
script.id
218+
);
219+
}
220+
}
221+
}
187222
}
188223

189224
fn on_cellref(
@@ -301,6 +336,7 @@ impl ScriptValidator {
301336
.case_insensitive(true)
302337
.build()?;
303338
let mod_reputation = Regex::new(r"^[,\s]*modreputation[,\s]")?;
339+
let mod_facrep = Regex::new(r#"modpcfacrep[,\s]+([0-9"-]+)([,\s]+([^,\s]+))?[,\s]*$"#)?;
304340
Ok(Self {
305341
unique_heads,
306342
scripts: HashMap::new(),
@@ -319,6 +355,7 @@ impl ScriptValidator {
319355
marker_id,
320356
markers: HashMap::new(),
321357
mod_reputation,
358+
mod_facrep,
322359
})
323360
}
324361

0 commit comments

Comments
 (0)