Skip to content

Commit

Permalink
Objects can have a available uses count.
Browse files Browse the repository at this point in the history
  • Loading branch information
cracrayol committed Nov 1, 2019
1 parent b66fb49 commit 5e9d84b
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@

1.12
- Fixed Quivers with no arrows available on section should not show "(0 arrows)". Show "(0 arrows)" only on Action chart. Same to sell quiver object (see book 8, sect168)

- Objects on the Action Chart can have a available uses count (used in book 8, 9 11).
4 changes: 0 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ TODO
- Action chart buttons don't work on iPad Safari
- Dialogs with text input: Allow to confirm with the screen keyboard ("go" button)
- Remove the "Alert" text from the message dialog (same for confirms)
- Objects on the Action Chart should have a "available uses count".
* See "larnumaliqueur" object, book 8, sect228;
* See "vialbluepills2" object
* See "silverflask" object, book 11, sect261
- Google Play will require API 26 on november 2018 (upgrade Cordova version?)
- Allow to change the font size / family
* See http://www.lalit.org/lab/javascript-css-font-detect/
Expand Down
2 changes: 2 additions & 0 deletions src/ts/controller/actionChartController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ const actionChartController = {
// Drop the object, and do not keep it on the section
if( dropObject )
actionChartController.drop(objectId, false);
else
actionChartView.updateObjectsLists();

// Fire mechanics rules
mechanicsEngine.fireObjectUsed( objectId );
Expand Down
11 changes: 10 additions & 1 deletion src/ts/model/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ class Item {
*/
public itemCount : number;

/**
* Number of allowed usage of the item
*/
public usageCount : number;

/** The translated object description */
public description : string;

Expand Down Expand Up @@ -129,7 +134,11 @@ class Item {

/** Number of items the object it occupies on the backpack */
const txtItemCount : string = $o.attr('itemCount');
this.itemCount = txtItemCount ? parseFloat( txtItemCount ) : 1;
this.itemCount = txtItemCount ? parseInt( txtItemCount ) : 1;

/** Number of usage of the object */
const txtUsageCount : string = $o.attr('usageCount');
this.usageCount = txtUsageCount ? parseInt( txtUsageCount ) : 1;

/** The translated object description */
this.description = $o.find('description[lang=' + book.language + ']').text();
Expand Down
7 changes: 6 additions & 1 deletion src/ts/views/viewsUtils/objectsTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ class ObjectsTableItem {

html += '<span><b>' + name + '</b></span>';

// Usage count
if( this.item.usageCount > 1 ) {
html += ' <span>' + translations.text( 'usageCount' , [this.item.usageCount] ) + '</span>';
}

// Description
if( this.item.description ) {
html += '<br/><i><small>' + this.item.description;
Expand Down Expand Up @@ -376,7 +381,7 @@ class ObjectsTableItem {
return;

// Use the object
const dropObject = ( this.type == ObjectsTableType.INVENTORY );
const dropObject = ( this.type == ObjectsTableType.INVENTORY && --this.item.usageCount <= 0 );
actionChartController.use( this.item.id , dropObject );

// If the object was used from the section, remove it
Expand Down
2 changes: 2 additions & 0 deletions src/ts/views/viewsUtils/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class Translations {
'more' : 'Más',
'fightUnarmed' : 'Luchar desarmado',
'permanent' : 'Permanente',
'usageCount' : '(se puede usar {0} veces)',

//////////////////////////////////////
// Combats
Expand Down Expand Up @@ -398,6 +399,7 @@ class Translations {
'confirm20EPGrdMaster': 'This ability can only be used once every 20 days. Continue?',
'more' : 'More',
'permanent' : 'Permanent',
'usageCount' : '(can be used {0} times)',

//////////////////////////////////////
// Combats
Expand Down
3 changes: 1 addition & 2 deletions src/www/data/mechanics-11.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1449,8 +1449,7 @@

<section id="sect261">
<endurance count="+4" />
<object objectId="silverflask" useOnSection="true" index="0" />
<object objectId="silverflask" useOnSection="true" index="1" />
<object objectId="silverflask" useOnSection="true" />
</section>

<section id="sect264">
Expand Down
4 changes: 1 addition & 3 deletions src/www/data/mechanics-8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1341,9 +1341,7 @@
</section>

<section id="sect228">
<!-- TODO: This is semi-supported. Bot objects should occupy a single slot on the action chart -->
<object objectId="larnumaliqueur" index="0" />
<object objectId="larnumaliqueur" index="1" />
<object objectId="larnumaliqueur" />
</section>

<section id="sect230">
Expand Down
3 changes: 1 addition & 2 deletions src/www/data/mechanics-9.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@
</section>

<section id="sect29">
<object objectId="vialbluepills2" index="0" />
<object objectId="vialbluepills2" index="1" />
<object objectId="vialbluepills2" />
</section>

<section id="sect32">
Expand Down
42 changes: 39 additions & 3 deletions src/www/data/objects.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,7 @@
<name lang="es">Mapa de Tharro</name>
</object>

<object id="larnumaliqueur" itemCount="0.5">
<object id="larnumaliqueur" usageCount="2">
<name lang="en">Larnuma Liqueur</name>
<description lang="en">
Restores 3 ENDURANCE points per dose
Expand Down Expand Up @@ -1627,7 +1627,7 @@
<name lang="es">Ajorca</name>
</object>

<object id="vialbluepills2" itemCount="0.5">
<object id="vialbluepills2" usageCount="2">
<name lang="en">Vial of Blue Pills</name>
<description lang="en">
They enable the human body to extract oxygen from water by absorbing it through the skin.
Expand Down Expand Up @@ -1763,7 +1763,7 @@
<name lang="es">Caracola</name>
</object>

<object id="silverflask" itemCount="0.5">
<object id="silverflask" usageCount="2">
<name lang="en">Silver Flask</name>
<description lang="en">
The wine has been charmed with a potent magical spell, imbuing it with special healing properties.
Expand Down Expand Up @@ -1837,6 +1837,42 @@
<name lang="en">Jar of Black Berries</name>
</object>

<object id="laumspurjar" usageCount="5">
<name lang="en">Jar of Laumspur</name>
<description lang="en">Restores 4 ENDURANCE points when swallowed after combat.</description>
<usage class="endurance" increment="4" />
</object>

<object id="aletherjar" usageCount="4">
<name lang="en">Jar of Alether</name>
<description lang="en">Increases COMBAT SKILL by 2 points for duration of one fight only.</description>
<usage class="combatSkill" increment="2" />
</object>

<object id="gallowbrushjar" usageCount="2">
<name lang="en">Jar of Gallowbrush</name>
<description lang="en">Induces 10 hours’ sleep and loss of 2 ENDURANCE points per dose.</description>
<usage class="endurance" increment="-2" />
</object>

<object id="sabitojar" usageCount="2">
<name lang="en">Jar of Sabito</name>
<description lang="en">Enables user to breathe underwater.</description>
<usage class="endurance" increment="-2" />
</object>

<object id="laumwortjar" usageCount="3">
<name lang="en">Jar of Laumwort</name>
<description lang="en">Restores 2 ENDURANCE points if swallowed before or after combat.</description>
<usage class="endurance" increment="+2" />
</object>

<object id="oedejar" usageCount="1">
<name lang="en">Jar of Oede</name>
<description lang="en">Very rare and valuable. Many healing properties. Cures serious diseases. Restores 10 ENDURANCE points if swallowed before or after combat.</description>
<usage class="endurance" increment="+10" />
</object>

<!-- OTHERS -->

<!-- This not really an object, but needed for mechanics -->
Expand Down

1 comment on commit 5e9d84b

@tonib
Copy link
Owner

@tonib tonib commented on 5e9d84b Dec 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two problems with this:

  • usageCount must be stored (and persisted) in the ActionChart for each object, because if you change usageCount in Item, if you close the game and continue later, the usageCount will be lost: Item class was expected to be read-only. More, if you have two instances of the same item, right now share the same usageCount
  • Changes in existing objects could do weird things if we publish a version update. Ex: 1)The player plays with the old version, picks two "vialbluepills2" that count as 0.5 items. 2) Player updates the app 3) Now the object counts as 1 item and may exceed the max. Backpack Items count, and each has two uses (=> 4 total uses). The solution, I think, is keep the old object as is and create a new object (ex. "vialbluepills2withusage") and put this in the section. This would keep the compatibility.

I'll keep the merge, and change these things later.

Please sign in to comment.