fixed attributes bug

This commit is contained in:
Denis Molony 2022-06-10 15:56:48 +10:00
parent 8765299cf4
commit e0a2c50d5b
3 changed files with 63 additions and 87 deletions

View File

@ -1,6 +1,7 @@
package com.bytezone.diskbrowser.wizardry;
import com.bytezone.diskbrowser.applefile.AbstractFile;
import com.bytezone.diskbrowser.utilities.Utility;
// -----------------------------------------------------------------------------------//
public abstract class Character extends AbstractFile
@ -12,6 +13,7 @@ public abstract class Character extends AbstractFile
{ "Fighter", "Mage", "Priest", "Thief", "Bishop", "Samurai", "Lord", "Ninja" };
static String[] statuses =
{ "OK", "Afraid", "Asleep", "Paralyze", "Stoned", "Dead", "Ashes", "Lost" };
static char[] awardsText = ">!$#&*<?BCPKODG@".toCharArray ();
int scenario;
@ -21,4 +23,22 @@ public abstract class Character extends AbstractFile
{
super (name, buffer);
}
// ---------------------------------------------------------------------------------//
public String getAwardString ()
// ---------------------------------------------------------------------------------//
{
StringBuilder text = new StringBuilder ();
int awards = Utility.getShort (buffer, 206);
for (int i = 0; i < 16; i++)
{
if ((awards & 0x01) != 0)
text.append (awardsText[i]);
awards >>>= 1;
}
return text.toString ();
}
}

View File

@ -10,9 +10,9 @@ import com.bytezone.diskbrowser.utilities.Utility;
class CharacterV1 extends Character
// -----------------------------------------------------------------------------------//
{
private static char[] awardsText = ">!$#&*<?BCPKODG@".toCharArray ();
public final int[] attributes = new int[6]; // 0:18
public final int[] saveVs = new int[5]; // 0:31
private final Attributes attributes;
private final Statistics stats;
private final List<Spell> spellBook = new ArrayList<> ();
@ -26,7 +26,6 @@ class CharacterV1 extends Character
this.scenario = scenario;
attributes = new Attributes ();
stats = new Statistics ();
stats.race = races[buffer[34] & 0xFF];
@ -37,9 +36,18 @@ class CharacterV1 extends Character
stats.status = statuses[stats.statusValue];
stats.alignment = alignments[buffer[42] & 0xFF];
stats.gold = Utility.getShort (buffer, 52) + Utility.getShort (buffer, 54) * 10000
+ Utility.getShort (buffer, 56) * 100000000L;
stats.experience = Utility.getShort (buffer, 124) + Utility.getShort (buffer, 126) * 10000;
int attr1 = Utility.getShort (buffer, 44);
int attr2 = Utility.getShort (buffer, 46);
attributes[0] = attr1 & 0x001F;
attributes[1] = (attr1 & 0x03E0) >>> 5;
attributes[2] = (attr1 & 0x7C00) >>> 10;
attributes[3] = attr2 & 0x001F;
attributes[4] = (attr2 & 0x03E0) >>> 5;
attributes[5] = (attr2 & 0x7C00) >>> 10;
stats.gold = Utility.getWizLong (buffer, 52);
stats.experience = Utility.getWizLong (buffer, 124);
stats.level = Utility.getShort (buffer, 132);
stats.hitsLeft = Utility.getShort (buffer, 134);
@ -47,31 +55,15 @@ class CharacterV1 extends Character
stats.armourClass = buffer[176];
attributes.strength = (buffer[44] & 0xFF) % 16;
if (attributes.strength < 3)
attributes.strength += 16;
attributes.array[0] = attributes.strength;
// saving throws
attr1 = Utility.getShort (buffer, 48);
attr2 = Utility.getShort (buffer, 50);
int i1 = (buffer[44] & 0xFF) / 16;
int i2 = (buffer[45] & 0xFF) % 4;
attributes.intelligence = i1 / 2 + i2 * 8;
attributes.array[1] = attributes.intelligence;
attributes.piety = (buffer[45] & 0xFF) / 4;
attributes.array[2] = attributes.piety;
attributes.vitality = (buffer[46] & 0xFF) % 16;
if (attributes.vitality < 3)
attributes.vitality += 16;
attributes.array[3] = attributes.vitality;
int a1 = (buffer[46] & 0xFF) / 16;
int a2 = (buffer[47] & 0xFF) % 4;
attributes.agility = a1 / 2 + a2 * 8;
attributes.array[4] = attributes.agility;
attributes.luck = (buffer[47] & 0xFF) / 4;
attributes.array[5] = attributes.luck;
saveVs[0] = attr1 & 0x001F;
saveVs[1] = (attr1 & 0x03E0) >>> 5;
saveVs[2] = (attr1 & 0x7C00) >>> 10;
saveVs[3] = attr2 & 0x001F;
saveVs[4] = (attr2 & 0x03E0) >>> 5;
}
// ---------------------------------------------------------------------------------//
@ -95,7 +87,6 @@ class CharacterV1 extends Character
identified = (buffer[ptr + 4] == 1);
baggageList.add (new Baggage (item, equipped, identified));
stats.assetValue += item.getCost ();
// item.partyOwns++;
}
else
System.out.println (
@ -112,10 +103,7 @@ class CharacterV1 extends Character
for (int bit = 0; bit < 8; bit++)
{
if (((buffer[i] >>> bit) & 0x01) != 0)
{
spellBook.add (spellList.get (index));
// System.out.println (spellList.get (index));
}
if (++index >= spellList.size ())
break;
@ -134,8 +122,6 @@ class CharacterV1 extends Character
text.append ("\nType ............... " + stats.type);
text.append ("\nAlignment .......... " + stats.alignment);
text.append ("\nStatus ............. " + stats.status);
// text.append ("\nType ............... " + stats.typeInt);
// text.append ("\nStatus ............. " + stats.statusValue);
text.append ("\nGold ............... " + String.format ("%,d", stats.gold));
text.append ("\nExperience ......... " + String.format ("%,d", stats.experience));
text.append ("\nNext level ......... " + String.format ("%,d", stats.nextLevel));
@ -150,12 +136,12 @@ class CharacterV1 extends Character
text.append ("\nAwards ............. " + getAwardString ());
text.append ("\nOut ................ " + isOut ());
text.append ("\n\nStrength ........... " + attributes.strength);
text.append ("\nIntelligence ....... " + attributes.intelligence);
text.append ("\nPiety .............. " + attributes.piety);
text.append ("\nVitality ........... " + attributes.vitality);
text.append ("\nAgility ............ " + attributes.agility);
text.append ("\nLuck ............... " + attributes.luck);
text.append ("\n\nStrength ........... " + attributes[0]);
text.append ("\nIntelligence ....... " + attributes[1]);
text.append ("\nPiety .............. " + attributes[2]);
text.append ("\nVitality ........... " + attributes[3]);
text.append ("\nAgility ............ " + attributes[4]);
text.append ("\nLuck ............... " + attributes[5]);
int[] spellPoints = getMageSpellPoints ();
text.append ("\n\nMage spell points ..");
@ -216,24 +202,6 @@ class CharacterV1 extends Character
return stats.nextLevel;
}
// ---------------------------------------------------------------------------------//
public String getAwardString ()
// ---------------------------------------------------------------------------------//
{
StringBuilder text = new StringBuilder ();
int awards = Utility.getShort (buffer, 206);
for (int i = 0; i < 16; i++)
{
if ((awards & 0x01) != 0)
text.append (awardsText[i]);
awards >>>= 1;
}
return text.toString ();
}
// ---------------------------------------------------------------------------------//
public boolean isOut ()
// ---------------------------------------------------------------------------------//
@ -263,7 +231,7 @@ class CharacterV1 extends Character
}
// ---------------------------------------------------------------------------------//
public Attributes getAttributes ()
int[] getAttributes ()
// ---------------------------------------------------------------------------------//
{
return attributes;
@ -341,17 +309,4 @@ class CharacterV1 extends Character
public int armourClass;
public int assetValue;
}
// ---------------------------------------------------------------------------------//
public class Attributes
// ---------------------------------------------------------------------------------//
{
public int strength;
public int intelligence;
public int piety;
public int vitality;
public int agility;
public int luck;
public int[] array = new int[6];
}
}

View File

@ -18,7 +18,6 @@ import com.bytezone.diskbrowser.gui.DataSource;
import com.bytezone.diskbrowser.pascal.PascalDisk;
import com.bytezone.diskbrowser.utilities.HexFormatter;
import com.bytezone.diskbrowser.utilities.Utility;
import com.bytezone.diskbrowser.wizardry.CharacterV1.Attributes;
import com.bytezone.diskbrowser.wizardry.CharacterV1.Statistics;
import com.bytezone.diskbrowser.wizardry.Header.ScenarioData;
import com.bytezone.diskbrowser.wizardry.Spell.SpellType;
@ -78,11 +77,13 @@ public class WizardryScenarioDisk extends PascalDisk
DefaultMutableTreeNode currentRoot = (DefaultMutableTreeNode) model.getRoot ();
DefaultMutableTreeNode dataNode = findNode (currentRoot, "SCENARIO.DATA");
DefaultMutableTreeNode msgNode = findNode (currentRoot, "SCENARIO.MESGS");
if (dataNode == null || msgNode == null)
{
System.out.println ("Wizardry data or msg node not found");
return;
}
dataNode.setAllowsChildren (true);
msgNode.setAllowsChildren (true);
@ -90,9 +91,7 @@ public class WizardryScenarioDisk extends PascalDisk
// Process SCENARIO.MESGS (requires scenario)
AppleFileSource afs = (AppleFileSource) msgNode.getUserObject ();
// DefaultMutableTreeNode node = linkNode ("Messages", "Messages string", msgNode);
extractMessages (msgNode, afs.getSectors ());
// makeNodeVisible (node);
// Process SCENARIO.DATA (requires scenario and messages)
afs = (AppleFileSource) dataNode.getUserObject ();
@ -104,12 +103,9 @@ public class WizardryScenarioDisk extends PascalDisk
extractCharacters (linkNode ("Characters", "Characters string", dataNode), sectors);
extractImages (linkNode ("Images", "Images string", dataNode), sectors);
extractExperienceLevels (linkNode ("Experience", "Experience string", dataNode), sectors);
// node = linkNode ("Spells", "Spells string", dataNode);
DefaultMutableTreeNode node = null;
extractSpells (node, sectors);
extractSpells (sectors);
extractLevels (linkNode ("Maze", "Levels string", dataNode), sectors);
// Make the Spells node (and its siblings) visible
// makeNodeVisible (node);
// add information about each characters' baggage, spells known etc.
for (CharacterV1 character : characters)
@ -131,6 +127,7 @@ public class WizardryScenarioDisk extends PascalDisk
DefaultAppleFileSource afs = new DefaultAppleFileSource (name, text, this);
DefaultMutableTreeNode node = new DefaultMutableTreeNode (afs);
parent.add (node);
return node;
}
@ -151,6 +148,7 @@ public class WizardryScenarioDisk extends PascalDisk
&& !text.equals ("WIZARDRY.CODE"))
return false;
}
return true;
}
@ -259,11 +257,11 @@ public class WizardryScenarioDisk extends PascalDisk
for (CharacterV1 ch : characters)
{
Statistics stats = ch.getStatistics ();
Attributes att = ch.getAttributes ();
int[] att = ch.getAttributes ();
text.append (String.format ("%-15s %2d %-8s %-8s %-8s %3d", ch, (stats.ageInWeeks / 52),
stats.alignment, stats.race, stats.type, stats.hitsMax));
text.append (String.format (" %2d %2d %2d %2d %2d %2d", att.strength, att.intelligence,
att.piety, att.vitality, att.agility, att.luck));
text.append (String.format (" %2d %2d %2d %2d %2d %2d", att[0], att[1], att[2], att[3],
att[4], att[5]));
text.append (String.format (" %5s %s%n", stats.status, ch.isOut () ? "* OUT *" : ""));
}
@ -412,7 +410,7 @@ public class WizardryScenarioDisk extends PascalDisk
}
// ---------------------------------------------------------------------------------//
private void extractSpells (DefaultMutableTreeNode node, List<DiskAddress> sectors)
private void extractSpells (List<DiskAddress> sectors)
// ---------------------------------------------------------------------------------//
{
spells = new ArrayList<> ();
@ -427,6 +425,7 @@ public class WizardryScenarioDisk extends PascalDisk
byte[] buffer = disk.readBlock (da);
int level = 1;
int ptr = -1;
while (ptr < 255)
{
ptr++;
@ -435,15 +434,17 @@ public class WizardryScenarioDisk extends PascalDisk
ptr++;
if (ptr == start)
break;
String spell = HexFormatter.getString (buffer, start, ptr - start);
if (spell.startsWith ("*"))
{
spell = spell.substring (1);
++level;
}
Spell s = Spell.getSpell (spell, spellType, level, buffer);
spells.add (s);
// addToNode (s, node, da, spellSector);
}
spellType = SpellType.PRIEST;
}