Skip to content

Commit

Permalink
Merge pull request #1629 from Miskatonic-Investigative-Society/develop
Browse files Browse the repository at this point in the history
7.4
  • Loading branch information
snap01 authored Nov 9, 2024
2 parents d7603e6 + de4008f commit 80ca16e
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 38 deletions.
8 changes: 8 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ Happy gaming !

When not specified, all changes were made by @castanhocorreia, @HavlockV, and @snap01.

## Version 7.4

When not specified, all changes were made by @castanhocorreia, @HavlockV, and @snap01.

- Allow .38 to be the start of a Firearms (Handgun) name
- Attempt to add skills when weapon with CoC ID skill names are dropped on Actor sheets
- Fix half DB calculations for build size 3 and higher

## Version 7.3

When not specified, all changes were made by @castanhocorreia, @HavlockV, and @snap01.
Expand Down
75 changes: 47 additions & 28 deletions module/actors/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,9 @@ export class CoCActor extends Actor {
0,
name
)
if (skillData === false) {
return
}
const value = Number(skillData.get('base-value'))
const parts = CoC7Item.getNamePartsSpec(
name,
Expand Down Expand Up @@ -1073,25 +1076,32 @@ export class CoCActor extends Actor {
const name = mainSkill.match(/\(([^)]+)\)/)
? mainSkill.match(/\(([^)]+)\)/)[1]
: mainSkill
// try to use an already defined skill
// TODO: search on the compendiums
const existing = game.items.find(
item => item.type === 'skill' &&
(item.name.toLocaleLowerCase() === name.toLocaleLowerCase() || item.system.skillName?.toLocaleLowerCase() === name.toLocaleLowerCase())
)
if (typeof existing !== 'undefined') {
await this.addItems([existing])
skill = await this.getSkillsByName(mainSkill)[0]
// skill = existing.toObject()
} else {
skill = await this.createWeaponSkill(
name,
!!data.system.properties?.rngd
if (name.match(/i\.skill\./)) {
const availableSkills = await game.system.api.cocid.fromCoCIDBest({ cocid: name, showLoading: true })
if (availableSkills.length) {
await this.addItems([availableSkills[0]])
skill = await this.getSkillsByName(mainSkill)[0]
}
}
if (!skill) {
const existing = game.items.find(
item => item.type === 'skill' &&
(item.name.toLocaleLowerCase() === name.toLocaleLowerCase() || item.system.skillName?.toLocaleLowerCase() === name.toLocaleLowerCase())
)
if (typeof existing !== 'undefined') {
await this.addItems([existing])
skill = await this.getSkillsByName(mainSkill)[0]
// skill = existing.toObject()
} else {
skill = await this.createWeaponSkill(
name,
!!data.system.properties?.rngd
)
}
}
}
if (skill) data.system.skill.main.id = skill.id
} // TODO : Else : selectionner le skill dans la liste ou en créer un nouveau.
}

const secondSkill = data.system?.skill?.alternativ?.name
if (secondSkill) {
Expand All @@ -1100,23 +1110,32 @@ export class CoCActor extends Actor {
const name = secondSkill.match(/\(([^)]+)\)/)
? secondSkill.match(/\(([^)]+)\)/)[1]
: secondSkill
const existing = game.items.find(
item => item.type === 'skill' &&
(item.name.toLocaleLowerCase() === name.toLocaleLowerCase() || item.system.skillName?.toLocaleLowerCase() === name.toLocaleLowerCase())
)
if (typeof existing !== 'undefined') {
await this.addItems([existing])
skill = await this.getSkillsByName(secondSkill)[0]
// skill = existing.toObject()
} else {
skill = await this.createWeaponSkill(
name,
!!data.system.properties?.rngd
if (name.match(/i\.skill\./)) {
const availableSkills = await game.system.api.cocid.fromCoCIDBest({ cocid: name, showLoading: true })
if (availableSkills.length) {
await this.addItems([availableSkills[0]])
skill = await this.getSkillsByName(secondSkill)[0]
}
}
if (!skill) {
const existing = game.items.find(
item => item.type === 'skill' &&
(item.name.toLocaleLowerCase() === name.toLocaleLowerCase() || item.system.skillName?.toLocaleLowerCase() === name.toLocaleLowerCase())
)
if (typeof existing !== 'undefined') {
await this.addItems([existing])
skill = await this.getSkillsByName(secondSkill)[0]
// skill = existing.toObject()
} else {
skill = await this.createWeaponSkill(
name,
!!data.system.properties?.rngd
)
}
}
}
if (skill) data.system.skill.alternativ.id = skill.id
} // TODO : Else : selectionner le skill dans la liste ou en créer un nouveau.
}
}

processedDataArray.push(foundry.utils.duplicate(data))
Expand Down
2 changes: 1 addition & 1 deletion module/apps/actor-importer-regexp.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const keys = {
sectionSpells: '\n(?:' + 'spells' + ')[:\n]',
handgun:
'(?<type>' +
' Gun|Revolver|Pistol|Handgun|Derringer|Beretta|Luger|Desert Eagle| \\.38' +
' Gun|Revolver|Pistol|Handgun|Derringer|Beretta|Luger|Desert Eagle|(^| )\\.38' +
')',
rifle:
'(?<type>' + 'Rifle|Shotgun|Carbine|Gauge |Lee-Enfield|Elephant' + ')',
Expand Down
4 changes: 2 additions & 2 deletions module/apps/actor-importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ export class CoC7ActorImporter {
}
attack.system.skill.id = null
items.push(attack)
this.weaponSkills.push([skill, attack])
this.weaponSkills.push([foundry.utils.duplicate(skill), attack])
}
}
// Skills
Expand Down Expand Up @@ -899,7 +899,7 @@ export class CoC7ActorImporter {
source: this.itemLocations
})
if (CONFIG.debug.CoC7Importer) {
console.debug(`${weapon.name} uses Handgun skill: ${skill}`)
console.debug(`${weapon.name} uses Handgun skill: `, skill)
}
} else if (this.getRegEx(this.keys.rifle).exec(weapon.name)) {
skill = await CoC7Utilities.guessItem('skill', localizedFirearm + ' (' + game.i18n.localize('CoC7.SkillNameRifleShotgun') + ')', {
Expand Down
3 changes: 2 additions & 1 deletion module/chat/cards/damage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { CoC7Dice } from '../../dice.js'
import { InteractiveChatCard } from '../interactive-chat-card.js'
import { createInlineRoll } from '../helper.js'
import { CoC7Utilities } from '../../utilities.js'

export class DamageCard extends InteractiveChatCard {
/**
Expand Down Expand Up @@ -244,7 +245,7 @@ export class DamageCard extends InteractiveChatCard {

if (!db.startsWith('-')) db = '+' + db
if (this.weapon.system.properties.addb) formula = formula + db
if (this.weapon.system.properties.ahdb) formula = formula + '+ ceil(' + db + '/2)'
if (this.weapon.system.properties.ahdb) formula = formula + CoC7Utilities.halfDB(this.actor.db)

if (formula) {
const maxDamage = new Roll(formula)[(!foundry.utils.isNewerVersion(game.version, '12') ? 'evaluate' : 'evaluateSync')/* // FoundryVTT v11 */]({ maximize: true }).total
Expand Down
3 changes: 2 additions & 1 deletion module/chat/damagecards.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// import { chatHelper } from './helper.js';
import { CoC7Dice } from '../dice.js'
import { ChatCardActor } from './card-actor.js'
import { CoC7Utilities } from '../utilities.js'

export class CoC7DamageRoll extends ChatCardActor {
constructor (itemId, actorKey, options) {
Expand Down Expand Up @@ -30,7 +31,7 @@ export class CoC7DamageRoll extends ChatCardActor {
this.rollString = this.rollString + '+' + this.actor.db
}
if (this.weapon.system.properties.ahdb) {
this.rollString = this.rollString + '+' + this.actor.db + '/2'
this.rollString = this.rollString + CoC7Utilities.halfDB(this.actor.db)
}

this.maxDamage = new Roll(this.rollString)[(!foundry.utils.isNewerVersion(game.version, '12') ? 'evaluate' : 'evaluateSync')/* // FoundryVTT v11 */]({ maximize: true })
Expand Down
3 changes: 2 additions & 1 deletion module/chat/rangecombat.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { CoC7Dice } from '../dice.js'
import { CoC7Check } from '../check.js'
import { chatHelper, CoC7Roll, CoC7Damage } from './helper.js'
import { CoC7Utilities } from '../utilities.js'

export class CoC7RangeInitiator {
constructor (actorKey = null, itemId = null, fastForward = false) {
Expand Down Expand Up @@ -755,7 +756,7 @@ export class CoC7RangeInitiator {
damageFormula = damageFormula + '+' + this.actor.db
}
if (this.item.system.properties.ahdb) {
damageFormula = damageFormula + '+ceil(' + this.actor.db + '/2)'
damageFormula = damageFormula + CoC7Utilities.halfDB(this.actor.db)
}
const damageDie = CoC7Damage.getMainDie(damageFormula)
const maxDamage = new Roll(damageFormula)[(!foundry.utils.isNewerVersion(game.version, '12') ? 'evaluate' : 'evaluateSync')/* // FoundryVTT v11 */]({ maximize: true }).total
Expand Down
1 change: 1 addition & 0 deletions module/coc7.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ Hooks.on('updateChatMessage', (chatMessage, chatData, diff, speaker) =>
)

Hooks.on('ready', async () => {
// CONFIG.compatibility.mode = CONST.COMPATIBILITY_MODES.SILENT
await Updater.checkForUpdate()

// game.CoC7.menus = new CoC7Menu();
Expand Down
22 changes: 21 additions & 1 deletion module/utilities.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global canvas, ChatMessage, CONFIG, CONST, Dialog, Folder, foundry, fromUuid, fromUuidSync, game, getDocumentClass, Hooks, Macro, Roll, Token, ui */
/* global canvas, ChatMessage, CONFIG, CONST, Dialog, Die, Folder, foundry, fromUuid, fromUuidSync, game, getDocumentClass, Hooks, Macro, NumericTerm, Roll, Token, ui */
import { COC7 } from './config.js'
import { CoC7Check } from './check.js'
import { CoC7Item } from './items/item.js'
Expand Down Expand Up @@ -957,4 +957,24 @@ export class CoC7Utilities {
}
return keepers[Math.floor(Math.random() * keepers.length)].id
}

static halfDB (db) {
db = ((db ?? '').toString().trim() === '' ? 0 : db).toString().trim()
const roll = new Roll(db)
for (const term of roll.terms) {
if (foundry.utils.isNewerVersion(game.version, '12') && term instanceof foundry.dice.terms.Die) {
term._faces = Math.floor(term._faces / 2)
} else if (term instanceof Die) {
// FoundryVTT V11
term.faces = Math.floor(term.faces / 2)
} else if (term instanceof NumericTerm) {
term.number = (term.number < 0 ? Math.ceil(term.number / 2) : Math.floor(term.number / 2))
}
}
let formula = roll.formula.toString().trim()
if (!formula.startsWith('-')) {
formula = '+' + formula
}
return formula
}
}
6 changes: 3 additions & 3 deletions system.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"id": "CoC7",
"title": "Call of Cthulhu 7th Edition",
"description": "An implementation of the Call of Cthulhu 7th Edition game system for Foundry Virtual Tabletop.",
"version": "7.3",
"version": "7.4",
"authors": [
{
"name": "Miskatonic Investigative Society"
}
],
"compatibility": {
"minimum": 10,
"minimum": 11,
"verified": 12
},
"esmodules": [
Expand Down Expand Up @@ -207,7 +207,7 @@
"secondaryTokenAttribute": "attribs.san",
"url": "https://github.com/Miskatonic-Investigative-Society/CoC7-FoundryVTT",
"manifest": "https://github.com/Miskatonic-Investigative-Society/CoC7-FoundryVTT/releases/latest/download/system.json",
"download": "https://github.com/Miskatonic-Investigative-Society/CoC7-FoundryVTT/releases/download/7.3/system.zip",
"download": "https://github.com/Miskatonic-Investigative-Society/CoC7-FoundryVTT/releases/download/7.4/system.zip",
"media": [
{
"type": "setup",
Expand Down

0 comments on commit 80ca16e

Please sign in to comment.