Systems.loot - robblofield/TomeboundDocs GitHub Wiki

Systems.loot

Author: Ash Neale

Updated: 02/01/24

Overview

This is a script that manages Loot and creating the gems spawned from broken objects

Dependencies

None

Contents

  • Use case
  • Breakdown of code
    • Using variables
    • Variables
    • Class Declaration
    • The if statements that check CurrentJem
  • Future Expansion
  • Full code reference

Use Case

This Script will be used to increase and decrease the players Jem amount, to be used in future implimentation of shops and when jems are found from broken objects.

Breakdown of code

Using variables

using System.Collections; using System.Collections.Generic; using UnityEngine;

Variables

public int MaxJem = 10; public int CurrentJem; public void GetJem() public void LoseJem()

Public int Max Jem: Public Integer Max Jem is the variable that sets the max number the CurrentJem variable can reach.

public int CurrentJem: Public Integer Current Jem is the variable that holds the current number of Jems the player has.

public void GetJem(): This variable can be assigned to a trigger to increase CurrentJem by 1.

public void LoseJem(): This variable can be assigned to a trigger to Decreased CurrentJem by 1.

Class Declaration

public class Money : MonoBehaviour

The Jem Class contains the variables MaxJem,CurrentJem,GetJem and LoseJem and a if statements that check CurrentJem.

The if statements that check CurrentJem

`void Update() { if (CurrentJem <= 0) ; { CurrentJem = 0;

}
if (CurrentJem >= MaxJem) ;
{
    CurrentJem = MaxJem;
}

}`

These statements keeps CurrentJem above 0 and below MaxJem to prevent future possible errors related to the Jem number.

Future expansion

  • Intergration with shops

  • Script to also include items, cosmetics and compendium items

Full code reference

`using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Loot : MonoBehaviour { public int MaxJem = 10; public int CurrentJem;

 void Start()
 {
     CurrentJem = PlayerPrefs.GetInt("amount");
 }

 // Checking player Jem
 void Update()
 {
     if (CurrentJem <= 0)
     {
         CurrentJem = 0;

     }
     if (CurrentJem >= MaxJem)
     {
         CurrentJem = MaxJem;
     }
  }

 // Jem increase and decrease functions
 public void GetJem()
 {
     CurrentJem++;
     PlayerPrefs.SetInt("amount", CurrentJem);
 }

 public void LoseJem()
 {
     CurrentJem--;
     PlayerPrefs.SetInt("amount", CurrentJem);
 }

}`