Class Originator

java.lang.Object
com.deco2800.game.memento.Originator

public class Originator extends Object
Part of the memento design pattern, originator is the object to store the states of the player, this includes the player's inventory states (e.g. amount of gold, type of sword, items in inventory, health and base attack value Can be extended to save states for other entities in the future or use as checkpoints for player to respawn
  • Field Details

    • state

      protected int state
    • gold

      protected int gold
    • stone

      protected int stone
    • wood

      protected int wood
    • currentHealth

      protected int currentHealth
    • attack

      protected int attack
    • defense

      protected int defense
    • weapon

      protected Equipments weapon
    • armor

      protected Equipments armor
    • items

      protected HashMap<Artefact,Integer> items
    • buildings

      protected HashMap<ShopBuilding,Integer> buildings
    • equipmentsList

      protected List<Equipments> equipmentsList
  • Constructor Details

    • Originator

      public Originator(int state)
      Originator constructor which can create a new originator to store the current state of the player before entering and exiting the shop
      Parameters:
      state - - the id of the current player state
  • Method Details

    • getState

      public int getState()
    • getWeapon

      public Equipments getWeapon()
      returns the weapon enum of the previously saved record
      Returns:
      weapon enum
    • getArmor

      public Equipments getArmor()
      returns the armor enum of the previously saved record
      Returns:
      armor enum
    • setWeapon

      public void setWeapon(Equipments weapon)
      sets the weapon enum
      Parameters:
      weapon - - weapon to be stored
    • setArmor

      public void setArmor(Equipments armor)
      sets the armor enum
      Parameters:
      armor - - chestplate to be stored
    • getGold

      public int getGold()
      retrieve the gold status for player
      Returns:
      amount of gold currently held by the player
    • setGold

      public void setGold(int gold)
      saves the amount of gold that the player currently have
      Parameters:
      gold - - amount of gold that the player current holds
    • setWood

      public void setWood(int wood)
      saves the amount of gold that the player currently have
      Parameters:
      wood - - amount of gold that the player current holds
    • getStone

      public int getStone()
      retrieve the stone status for player
      Returns:
      amount of stone currently held by the player
    • getWood

      public int getWood()
      retrieve the wood status for player
      Returns:
      amount of wood currently held by the player
    • setStone

      public void setStone(int stone)
      saves the amount of stone that the player currently have
      Parameters:
      stone - - amount of stone that the player current holds
    • setAttack

      public void setAttack(int attack)
      saves the attack value for the player, this includes the boost for player from different weapons bought in the shop
      Parameters:
      attack - - attack value for player
    • getAttack

      public int getAttack()
      returns the attack value of the player
      Returns:
      - basee attack value of player
    • setDefense

      public void setDefense(int defense)
      sets the defense multiplier
      Parameters:
      defense - - defense multiplier value
    • getDefense

      public int getDefense()
      returns the defense multiplier
    • getCurrentHealth

      public int getCurrentHealth()
      returns the current health of the player
      Returns:
      - current health of the player
    • setCurrentHealth

      public void setCurrentHealth(int health)
      saves the current health of the player
      Parameters:
      health - - player health
    • getItemList

      public HashMap<Artefact,Integer> getItemList()
      retrieve the list of items in player's inventory, may be extended to different lists depending on types of item
      Returns:
      - the list of artefacts items in player's inventory
    • setItems

      public void setItems(HashMap<Artefact,Integer> items)
      stores the current state of player's inventory items
      Parameters:
      items - - list of artefacts items in player's inventory
    • getEquipmentsList

      public List<Equipments> getEquipmentsList()
      retrieves all the previously bought equipment
      Returns:
      list of equipments
    • setEquipmentsList

      public void setEquipmentsList(List<Equipments> equipmentsList)
      record the list of equipment in the inventory
      Parameters:
      equipmentsList -
    • setBuildings

      public void setBuildings(HashMap<ShopBuilding,Integer> buildings)
      record the list of buildings in the inventory
      Parameters:
      buildings -
    • getBuildings

      public HashMap<ShopBuilding,Integer> getBuildings()
      retrieve the list of previously bought buildings
      Returns:
      hashmap of buildings
    • saveStateToMemento

      public Memento saveStateToMemento()
      converts the originator object to a memento to store in the caretaker
      Returns:
      - the new memento generated from the current originator
    • getStateFromMemento

      public void getStateFromMemento(Memento memento)
      returns the states of the player from the specified memento
      Parameters:
      memento - - the memento of the previous player state to read from
    • toString

      public String toString()
      Overrides:
      toString in class Object