Changeset 8edd04e in lost-haven for main/Player.java


Ignore:
Timestamp:
Jun 7, 2020, 3:04:32 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
master
Children:
a49176d
Parents:
155577b
Message:

Make the decompiled game code compile successfully

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/Player.java

    r155577b r8edd04e  
    11package main;
    22
     3import java.awt.Font;
     4import java.awt.Graphics;
     5import java.awt.MouseInfo;
     6import java.io.*;
     7import java.util.*;
     8
     9import gamegui.*;
     10
    311public class Player extends Creature {
    4         private Point target;
    5         private int experience;
    6         private int gold;
    7        
    8         public Player() {
    9                 super();
    10                 target = new Point(0, 0);
    11         }
    12 
    13         public Player(String name) {
    14                 super(name);
    15                 target = new Point(0, 0);
    16         }
    17        
    18         public Player(String name, Gender gender) {
    19                 super(name, gender);
    20                 target = new Point(0, 0);
    21         }
    22        
    23         public int getExperience() {
    24                 return experience;
    25         }
    26        
    27         public int getGold() {
    28                 return gold;
    29         }
    30        
    31         public Point getTarget() {
    32                 return target;
    33         }
    34        
    35         public void setExperience(int experience) {
    36                 this.experience = experience;
    37         }
    38        
    39         public void setGold(int gold) {
    40                 this.gold = gold;
    41         }
    42        
    43         public void setTarget(Point target) {
    44                 this.target = target;
    45         }
     12
     13  private int gold;
     14  private int attributePoints;
     15  private int[] skills;
     16  private int skillPoints;
     17  private LinkedList<Item> inventory;
     18  private LinkedList<Item> gemsUsed;
     19  private HashMap<Gem, Integer> gems;
     20  private int relicCount;
     21  private int gemValue;
     22  private long timePlayed;
     23  private long timeLoggedOn;
     24
     25  public Player() {
     26    this.name = "Player";
     27    this.type = CreatureType.Player;
     28    this.skills = new int[9];
     29    this.inventory = new LinkedList<Item>();
     30    this.gemsUsed = new LinkedList<Item>();
     31    this.gems = new HashMap<Gem, Integer>();
     32    this.relicCount = 0;
     33    this.gemValue = 0;
     34    this.timePlayed = 0L;
     35    this.timeLoggedOn = 0L;
     36  }
     37
     38  public Player(Player p) {
     39    super(p);
     40    this.skills = (int[])p.skills.clone();
     41    this.attributePoints = p.attributePoints;
     42    this.skillPoints = p.skillPoints;
     43    this.inventory = new LinkedList<Item>(p.inventory);
     44    this.gemsUsed = new LinkedList<Item>(p.gemsUsed);
     45    this.gems = new HashMap<Gem, Integer>(p.gems);
     46    this.relicCount = p.relicCount;
     47    this.gemValue = p.gemValue;
     48    this.timePlayed = p.timePlayed;
     49    this.timeLoggedOn = p.timeLoggedOn;
     50  }
     51
     52  public Player copy() {
     53    return new Player(this);
     54  }
     55
     56  public boolean readyForBoss() {
     57    return (this.relicCount >= 4);
     58  }
     59
     60  public void setTimeLoggedOn(long time) {
     61    this.timeLoggedOn = time;
     62  }
     63
     64  public long getTimePlayed() {
     65    return this.timePlayed;
     66  }
     67
     68  public void updateTimePlayed() {
     69    this.timePlayed += System.currentTimeMillis() - this.timeLoggedOn;
     70  }
     71
     72  public void drawInventory(Graphics g, ScrollList inv, int x, int y) {
     73    int mouseX = (MouseInfo.getPointerInfo().getLocation()).x;
     74    int mouseY = (MouseInfo.getPointerInfo().getLocation()).y;
     75    int locX = (mouseX - x) / 50;
     76    int locY = (mouseY - y + inv.getTextStart()) / 50;
     77    if (locX + 4 * locY >= 0 && locX + 4 * locY < inv.getList().size()) {
     78      Window popup;
     79      String itemType;
     80      MultiTextbox desc;
     81      Item i = ((ItemImg)inv.getList().get(locX + locY * 4)).getItem();
     82      switch (i.getType()) {
     83        case Relic:
     84          popup = new Window("popup", mouseX - 100, mouseY - 150, 100, 165, false);
     85          break;
     86        default:
     87          popup = new Window("popup", mouseX - 100, mouseY - 100, 100, 100, false);
     88          break;
     89      }
     90      Font font12 = new Font("Arial", 0, 12);
     91      switch (i.getType()) {
     92        case LightWeapon:
     93          itemType = "Light Weapon";
     94          break;
     95        case HeavyWeapon:
     96          itemType = "Heavy Weapon";
     97          break;
     98        case RangedWeapon:
     99          itemType = "Ranged Weapon";
     100          break;
     101        default:
     102          itemType = i.getType().toString();
     103          break;
     104      }
     105      popup.add(new Label("name", 5, 5, 90, 15, i.getName(), font12));
     106      popup.add(new Label("type", 5, 35, 90, 15, itemType, font12));
     107      switch (i.getType()) {
     108        case LightWeapon:
     109        case HeavyWeapon:
     110        case RangedWeapon:
     111          popup.add(new Label("damage", 5, 50, 90, 15, "Damage: " + ((Weapon)i).getDamage(), font12));
     112          popup.add(new Label("damage", 5, 65, 90, 15, "Cooldown: " + (((Weapon)i).getAttackSpeed() / 10.0D) + " s", font12));
     113          break;
     114        case Spell:
     115          popup.add(new Label("energy", 5, 50, 90, 15, "Energy: " + ((Gem)i).getValue(), font12));
     116          desc = new MultiTextbox("description", 1, 80, 99, 84, "", false, font12, g.getFontMetrics(font12));
     117          desc.setText(i.getDescription());
     118          desc.setBorder(false);
     119          popup.add(desc);
     120          break;
     121      }
     122      popup.draw(g);
     123    }
     124  }
     125
     126  public void save(PrintWriter out) {
     127    super.save(out);
     128    out.println(this.name);
     129    out.println(this.level);
     130    out.println(this.timePlayed);
     131    out.println(this.experience);
     132    out.println(String.valueOf(getTarget().getX()) + "," + getTarget().getY());
     133    out.println(getAttribute(Attribute.Strength));
     134    out.println(getAttribute(Attribute.Dexterity));
     135    out.println(getAttribute(Attribute.Constitution));
     136    out.println(getAttribute(Attribute.Wisdom));
     137    out.println(getSkill(Skill.LightWeapons));
     138    out.println(getSkill(Skill.HeavyWeapons));
     139    out.println(getSkill(Skill.RangedWeapons));
     140    out.println(getSkill(Skill.Evocation));
     141    out.println(getSkill(Skill.Enchantment));
     142    out.println(this.attributePoints);
     143    out.println(this.skillPoints);
     144    out.println(getMaxHitpoints());
     145    out.println(getMaxManapoints());
     146    Object[] arr = LostHavenRPG.respawnPoints.toArray();
     147    for (int x = 0; x < arr.length; x++) {
     148      if (((RespawnPoint)arr[x]).isMarked())
     149        out.println(x);
     150    }
     151    out.println("---");
     152    Iterator<Item> iter = this.inventory.iterator();
     153    while (iter.hasNext())
     154      out.println(((Item)iter.next()).getName());
     155    out.println("---");
     156    iter = this.gemsUsed.iterator();
     157    while (iter.hasNext())
     158      out.println(((Item)iter.next()).getName());
     159    out.println("---");
     160  }
     161
     162  public static Player loadTemplate(BufferedReader in) {
     163    Player p = new Player();
     164    try {
     165      p.level = Integer.parseInt(in.readLine());
     166      p.setSkill(Skill.LightWeapons, Integer.parseInt(in.readLine()));
     167      p.setSkill(Skill.HeavyWeapons, Integer.parseInt(in.readLine()));
     168      p.setSkill(Skill.RangedWeapons, Integer.parseInt(in.readLine()));
     169      p.setSkill(Skill.Evocation, Integer.parseInt(in.readLine()));
     170      p.setSkill(Skill.Enchantment, Integer.parseInt(in.readLine()));
     171      p.attributePoints = Integer.parseInt(in.readLine());
     172      p.skillPoints = Integer.parseInt(in.readLine());
     173    } catch (IOException ioe) {
     174      ioe.printStackTrace();
     175    }
     176    return p;
     177  }
     178
     179  public void load(BufferedReader in) {
     180    try {
     181      super.load(in);
     182      int hp = getHitpoints();
     183      int mp = getManapoints();
     184      setName(in.readLine());
     185      this.level = Integer.valueOf(in.readLine()).intValue();
     186      this.timePlayed = Long.valueOf(in.readLine()).longValue();
     187      setExperience(Integer.valueOf(in.readLine()).intValue());
     188      String strTarget = in.readLine();
     189      getTarget().setX(Integer.valueOf(strTarget.substring(0, strTarget.indexOf(","))).intValue());
     190      getTarget().setY(Integer.valueOf(strTarget.substring(strTarget.indexOf(",") + 1)).intValue());
     191      setAttribute(Attribute.Strength, Integer.parseInt(in.readLine()));
     192      setAttribute(Attribute.Dexterity, Integer.parseInt(in.readLine()));
     193      setAttribute(Attribute.Constitution, Integer.parseInt(in.readLine()));
     194      setAttribute(Attribute.Wisdom, Integer.parseInt(in.readLine()));
     195      setSkill(Skill.LightWeapons, Integer.parseInt(in.readLine()));
     196      setSkill(Skill.HeavyWeapons, Integer.parseInt(in.readLine()));
     197      setSkill(Skill.RangedWeapons, Integer.parseInt(in.readLine()));
     198      setSkill(Skill.Evocation, Integer.parseInt(in.readLine()));
     199      setSkill(Skill.Enchantment, Integer.parseInt(in.readLine()));
     200      this.attributePoints = Integer.parseInt(in.readLine());
     201      this.skillPoints = Integer.parseInt(in.readLine());
     202      setMaxHitpoints(Integer.parseInt(in.readLine()));
     203      setMaxManapoints(Integer.parseInt(in.readLine()));
     204      setHitpoints(hp);
     205      setManapoints(mp);
     206      setWeapon(this.weapon.baseWeapon);
     207      String strItem;
     208      while (!(strItem = in.readLine()).equals("---"))
     209        ((RespawnPoint)LostHavenRPG.respawnPoints.get(Integer.parseInt(strItem))).mark();
     210      this.weapon.update();
     211      while (!(strItem = in.readLine()).equals("---"))
     212        pickUp(LostHavenRPG.items.get(strItem));
     213      while (!(strItem = in.readLine()).equals("---")) {
     214        pickUp(LostHavenRPG.items.get(strItem));
     215        activateGem((Gem)LostHavenRPG.items.get(strItem));
     216      }
     217    } catch (IOException ioe) {
     218      ioe.printStackTrace();
     219    }
     220  }
     221
     222  public void pickUp(Item item) {
     223    this.inventory.add(item);
     224    LostHavenRPG.lstInventory.getList().add(new ItemImg(item));
     225    if (item.isRelic()) {
     226      this.relicCount++;
     227    }
     228  }
     229
     230  public boolean activateGem(Gem item) {
     231    if (this.gemValue + item.getValue() > getSkill(Skill.Evocation))
     232      return false;
     233    this.gemsUsed.add(item);
     234    LostHavenRPG.lstGems.getList().add(new ItemImg(item));
     235    this.inventory.remove(item);
     236    LostHavenRPG.lstInventory.getList().remove(new ItemImg(item));
     237    this.gemValue += item.getValue();
     238    addGem((Gem)LostHavenRPG.items.get(item.getName()));
     239    if (getSpell() == null) {
     240      setSpell(new Weapon("spell", ItemType.Spell, "Dagger.png", new java.awt.image.BufferedImage[8], 10, 250, 0));
     241    }
     242    getSpell().update();
     243    return true;
     244  }
     245
     246  public void deactivateGem(Gem item) {
     247    this.inventory.add(item);
     248    LostHavenRPG.lstInventory.getList().add(new ItemImg(item));
     249    this.gemsUsed.remove(item);
     250    LostHavenRPG.lstGems.getList().remove(new ItemImg(item));
     251    this.gemValue -= item.getValue();
     252    removeGem((Gem)LostHavenRPG.items.get(item.getName()));
     253    if (this.gemsUsed.size() == 0) {
     254      this.spell = null;
     255    } else {
     256      getSpell().update();
     257    }
     258  }
     259
     260  public LinkedList<Item> getInventory() {
     261    return this.inventory;
     262  }
     263
     264  public LinkedList<Item> getGems() {
     265    return this.gemsUsed;
     266  }
     267
     268  public void initGems(LinkedList<Gem> lstGems) {
     269    Iterator<Gem> iter = lstGems.iterator();
     270    while (iter.hasNext())
     271      this.gems.put(iter.next(), Integer.valueOf(0));
     272  }
     273
     274  public void addGem(Gem gem) {
     275    this.gems.put(gem, Integer.valueOf(((Integer)this.gems.get(gem)).intValue() + 1));
     276  }
     277
     278  public void removeGem(Gem gem) {
     279    this.gems.put(gem, Integer.valueOf(((Integer)this.gems.get(gem)).intValue() - 1));
     280  }
     281
     282  public int getGemNum(String name) {
     283    Iterator<Gem> iter = this.gems.keySet().iterator();
     284    while (iter.hasNext()) {
     285      Gem cur = iter.next();
     286      if (cur.getName().equals(name)) {
     287        return ((Integer)this.gems.get(cur)).intValue();
     288      }
     289    }
     290    return 0;
     291  }
     292
     293  public void increaseLevel() {
     294    this.skillPoints += 2;
     295    setHitpoints(getHitpoints() + getAttribute(Attribute.Constitution));
     296    setMaxHitpoints(getMaxHitpoints() + getAttribute(Attribute.Constitution));
     297    setManapoints(getManapoints() + getAttribute(Attribute.Wisdom));
     298    setMaxManapoints(getMaxManapoints() + getAttribute(Attribute.Wisdom));
     299    setLevel(getLevel() + 1);
     300  }
     301
     302  public void allocateAttribute(Attribute point) {
     303    if (this.attributePoints > 0) {
     304      setAttribute(point, getAttribute(point) + 1);
     305      this.attributePoints--;
     306    }
     307  }
     308
     309  public void repickAttribute(Attribute point) {
     310    if (getAttribute(point) > 6) {
     311      setAttribute(point, getAttribute(point) - 1);
     312      this.attributePoints++;
     313    }
     314  }
     315
     316  public void allocateSkill(Skill point) {
     317    if (this.skillPoints > 0) {
     318      setSkill(point, getSkill(point) + 1);
     319      this.skillPoints--;
     320      this.weapon.update();
     321    }
     322  }
     323
     324  public void repickSkill(Skill point) {
     325    if (getSkill(point) > 0) {
     326      setSkill(point, getSkill(point) - 1);
     327      this.skillPoints++;
     328      this.weapon.update();
     329    }
     330  }
     331
     332  private int skillIndex(Skill skill) {
     333    switch (skill) {
     334      case LightWeapons:
     335        return 0;
     336      case HeavyWeapons:
     337        return 1;
     338      case RangedWeapons:
     339        return 2;
     340      case Evocation:
     341        return 3;
     342      case Enchantment:
     343        return 4;
     344    }
     345    return -1;
     346  }
     347
     348  public int getSkill(Skill skill) {
     349    return this.skills[skillIndex(skill)];
     350  }
     351
     352  public void setSkill(Skill skill, int num) {
     353    this.skills[skillIndex(skill)] = num;
     354  }
     355
     356  public int getGold() {
     357    return this.gold;
     358  }
     359
     360  public int getAttributePoints() {
     361    return this.attributePoints;
     362  }
     363
     364  public int getSkillPoints() {
     365    return this.skillPoints;
     366  }
     367
     368  public int getGemValue() {
     369    return this.gemValue;
     370  }
     371
     372  public int getRelicCount() {
     373    return this.relicCount;
     374  }
     375
     376  public void setWeapon(Weapon weapon) {
     377    this.weapon = new EquippedWeapon(this, weapon);
     378    switch (weapon.getType()) {
     379      case LightWeapon:
     380      case HeavyWeapon:
     381        setModel(LostHavenRPG.meleeModel);
     382        break;
     383      case RangedWeapon:
     384        setModel(LostHavenRPG.rangedModel);
     385        break;
     386    }
     387    this.weapon.update();
     388    (this.model.getAnimation(Direction.North, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.North, Action.Attacking)).frames.size());
     389    (this.model.getAnimation(Direction.South, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.South, Action.Attacking)).frames.size());
     390    (this.model.getAnimation(Direction.East, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.East, Action.Attacking)).frames.size());
     391    (this.model.getAnimation(Direction.West, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.West, Action.Attacking)).frames.size());
     392  }
     393
     394  public void setGold(int gold) {
     395    this.gold = gold;
     396  }
     397
     398  public void setAttributePoints(int attributePoints) {
     399    this.attributePoints = attributePoints;
     400  }
     401
     402  public void setAttribute(Attribute attribute, int num) {
     403    this.attributes[attributeIndex(attribute)] = num;
     404    updateStats();
     405  }
     406
     407  private void updateStats() {
     408    this.hitpoints = 4 * this.attributes[2];
     409    this.maxHitpoints = 4 * this.attributes[2];
     410    this.manapoints = 2 * this.attributes[3];
     411    this.maxManapoints = 2 * this.attributes[3];
     412  }
     413
     414  public class ItemImg implements Listable {
     415    public Item i;
     416    public int xCoord;
     417    public int yCoord;
     418
     419    public ItemImg(Item i) {
     420      this.i = i;
     421    }
     422
     423    public void draw(int x, int y, Graphics g) {
     424      this.xCoord = x;
     425      this.yCoord = y;
     426      this.i.drawStatic(g, x, y);
     427    }
     428
     429    public Item getItem() {
     430      return this.i;
     431    }
     432
     433    public int getHeight() {
     434      return this.i.getImg().getHeight();
     435    }
     436
     437    public int getWidth() {
     438      return this.i.getImg().getWidth();
     439    }
     440
     441    public int getXOffset() {
     442      return 0;
     443    }
     444
     445    public int getYOffset() {
     446      return 0;
     447    }
     448
     449    public boolean equals(Object o) {
     450      return (((ItemImg)o).i == this.i);
     451    }
     452  }
    46453}
Note: See TracChangeset for help on using the changeset viewer.