Skip to content
Snippets Groups Projects
Commit f7968ed8 authored by Robin Halseth Sandvik's avatar Robin Halseth Sandvik
Browse files

New items system.

- Items class hierarchy.
- Inventory class.
- CharacterStats class.
- Applies modifiers to character's stats.
parent 6bfe0aa8
No related branches found
No related tags found
1 merge request!20New items system.
using System.Collections;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
namespace BigSock {
/*
Interface that represents the parameters of a generic character event.
*/
public interface ICharEventParams {
/*
The character that own's the event.
*/
Character Source { get; }
/*
The character that triggered the event. (If any)
ex.: OnKill -> the killed enemy. OnDamage -> Enemy that dealt the damage.
*/
Character Target { get; }
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: f392d99fa5161e04791a522b7becc933
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
namespace BigSock.Item {
/*
An inventory of a character.
*/
public class Inventory {
/*
The items in the inventory.
*/
public List<IItem> Items { get; protected set; } = new List<IItem>();
/*
The modifier from all the passives.
*/
public ICharacterStats Modifier { get; protected set; } = new CharacterStats();
/*
The max number of items the inventory can hold.
*/
public int Cap { get; set; } = 3;
/*
Adds an item to the inventory and manages changes.
*/
public bool AddItem(IItem item) {
if(Items.Count >= Cap) return false;
Items.Add(item);
// Add the passive effects to the modifier.
if(item is PassiveItemBase passive) {
Modifier = Modifier.Add(passive.Modifier);
}
//! Add ifs to handle the other 2 types of items.
return true;
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 91c4ea7605d846e4a8ea5208d2217072
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: dbcc22c9f61379c4e9676afbe7eb8feb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
namespace BigSock.Item {
/*
A passive item that increases user's running speed by 50%.
*/
public class RunningShoes : PassiveItemBase {
public RunningShoes() {
Id = 101;
Name = "Running Shoes";
Description = "Increases movement speed by 50%";
Modifier = new CharacterStats{
MoveSpeed = 0.5f,
};
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 12406fa4fcf374142ad545946396cbde
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: fad9ca94bd85fe14da5644defaaf3820
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -4,6 +4,7 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using BigSock.UI;
using BigSock.Item;
namespace BigSock {
......@@ -36,9 +37,9 @@ namespace BigSock {
// Start is called before the first frame update
void Start()
protected override void Start()
{
rb = GetComponent<Rigidbody2D>();
base.Start();
animator = GetComponent<Animator>();
spriteRenderer = GetComponent<SpriteRenderer>();
hpBar.SetMaxHealth(Convert.ToInt32(MaxHP));
......@@ -102,6 +103,11 @@ namespace BigSock {
}
//!! Code for testing the new item stuff.
if(Input.GetKeyDown(KeyCode.Space)) {
TryPickUpItem(new RunningShoes());
}
}
......
......@@ -28,8 +28,8 @@ namespace BigSock {
// private Collider2D_Proxy secondCollider;
protected virtual void Start(){
rb = GetComponent<Rigidbody2D>();
protected override void Start() {
base.Start();
m_Animator = gameObject.GetComponent<Animator>();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment