Skip to content

Commit

Permalink
Merge pull request #1500 from StarWarsFoundryVTT/species_starting_xp_…
Browse files Browse the repository at this point in the history
…1459

feat(species): starting XP
  • Loading branch information
wrycu authored May 10, 2024
2 parents 20aa7ce + 67618da commit bc9c3af
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
* Purchasing Signature Abilities now takes these links into account, if defined
* Purchasing Force Powers now checks the required force rating
* Sheets now default to the v2 version (they can still be manually changed back to v1)
* Species can now have starting XP defined
* Dragging a species onto a player character grants the starting XP
* The importer has been updated to import starting XP
* Fixes:
* Sending a signature ability to chat now includes purchased upgrades
* Granting XP to the entire group now updates the XP logs
Expand Down
2 changes: 2 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@
"SWFFG.GrantXP": "Grant XP",
"SWFFG.GrantXPTo": "Grant XP to",
"SWFFG.GrantXPToAllCharacters": "Grant XP to all characters",
"SWFFG.GrantXPSpecies": "received species {species}",
"SWFFG.StartingXP": "Starting XP",
"SWFFG.ObligationTable": "Obligation Table",
"SWFFG.DutyTable": "Duty Table",
"SWFFG.Range": "Range",
Expand Down
24 changes: 21 additions & 3 deletions modules/actors/actor-sheet-ffg.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import DiceHelpers from "../helpers/dice-helpers.js";
import ActorOptions from "./actor-ffg-options.js";
import ImportHelpers from "../importer/import-helpers.js";
import ModifierHelpers from "../helpers/modifiers.js";
import ActorHelpers, {xpLogSpend} from "../helpers/actor-helpers.js";
import ActorHelpers, {xpLogEarn, xpLogSpend} from "../helpers/actor-helpers.js";
import ItemHelpers from "../helpers/item-helpers.js";
import EmbeddedItemHelpers from "../helpers/embeddeditem-helpers.js";
import {change_role, deregister_crew, build_crew_roll} from "../helpers/crew.js";
Expand Down Expand Up @@ -58,6 +58,24 @@ export class ActorSheetFFG extends ActorSheet {
// Handle item sorting within the same Actor
if ( this.actor.uuid === item.parent?.uuid ) return this._onSortItem(event, itemData);

if (this.actor.type === "character" && itemData.type === "species") {
// add starting XP from species
const curAvailable = parseInt(this.actor.system?.experience?.available);
const curTotal = parseInt(this.actor.system?.experience?.total);
const startingXP = parseInt(itemData.system?.startingXP);
await this.actor.update(
{
system: {
experience: {
available: curAvailable + startingXP,
total: curTotal + startingXP,
}
}
}
);
await xpLogEarn(this.actor, startingXP, curAvailable + startingXP, curTotal + startingXP, game.i18n.format("SWFFG.GrantXPSpecies", {species: itemData.name}) );
}

// Create the owned item
return this._onDropItemCreate(itemData);
} else {
Expand Down Expand Up @@ -1435,11 +1453,11 @@ export class ActorSheetFFG extends ActorSheet {
let sameActor = data.actorId === this.actor.id;
if (!sameActor) {
try {
this.actor.createEmbeddedDocuments("Item", [duplicate(data.data)]); // Create a new Item
this.actor.createEmbeddedDocuments("Item", [foundry.utils.duplicate(data.data)]); // Create a new Item
const actor = game.actors.get(data.actorId);
await actor.items.get(data.data._id)?.delete(); // Delete originating item from other actor
} catch (err) {
CONFIG.logger.error(`Error transfering item between actors.`, err);
CONFIG.logger.error(`Error transferring item between actors.`, err);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions modules/importer/oggdude/importers/species.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default class Species {
attributes: {},
description: item.Description,
talents: {},
startingXP: item.StartingAttrs.Experience ? parseInt(item.StartingAttrs.Experience, 10) : 0,
};

// populate starting characteristics
Expand Down
3 changes: 2 additions & 1 deletion template.json
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,8 @@
},
"species": {
"templates": ["core"],
"talents": {}
"talents": {},
"startingXP": 0
},
"criticalinjury": {
"templates": ["core"],
Expand Down
3 changes: 3 additions & 0 deletions templates/items/ffg-species-sheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ <h1 class="charname"><input name="name" type="text" value="{{item.name}}" placeh
<input class="attribute-key" type="text" name="data.attributes.Strain.key" value="Strain" style="display: none;" />
<input type="text" name="data.attributes.Strain.modtype" value="Stat" style="display: none;" />
<input type="text" name="data.attributes.Strain.mod" value="Strain" style="display: none;" />

{{!-- Starting XP Box --}}
{{> "systems/starwarsffg/templates/parts/shared/ffg-block.html" (object blocktype="single" title="SWFFG.StartingXP" type="Number" name="data.startingXP" value=data.startingXP)}}
</div>
</div>
</div>
Expand Down

0 comments on commit bc9c3af

Please sign in to comment.