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

Added a conditional item to test.

- Also moved some classes around to avoid future clutter.
parent e7220113
No related branches found
No related tags found
1 merge request!22Implemented initial version of conditional items.
Showing
with 48 additions and 21 deletions
......@@ -11,6 +11,9 @@ namespace BigSock.Item {
A class that represents an item that an effect when a condition is meet.
*/
public abstract class ConditionalItemBase : ItemBase {
public static readonly Random RND = new Random();
/*
The type of trigger this item uses.
*/
......
......@@ -14,17 +14,17 @@ namespace BigSock.Item {
/*
The name of the item.
*/
public string Name { get; protected set; }
public abstract string Name { get; }
/*
The description of the item.
*/
public string Description { get; protected set; }
public abstract string Description { get; }
/*
The id of the item.
*/
public ulong Id { get; protected set; }
public abstract ulong Id { get; }
}
}
\ No newline at end of file
using System.Collections;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
namespace BigSock.Item {
/*
An item that adds a 30% chance to deal double damage on hit.
*/
public class ItemFourEyes : OnHitItemBase {
public override ulong Id => 201;
public override string Name => "Four Eyes";
public override string Description => "30% chance to deal double dammage.";
public static readonly double CHANCE = 0.3;
public override void Handler(Character source, Character target, AttackStats attack) {
var roll = RND.NextDouble();
if(roll >= CHANCE) {
attack.Damage *= 2;
MonoBehaviour.print($"[ItemFourEyes.Handler()] Hit. ({roll:P1} >= {CHANCE:P1})")
} else {
MonoBehaviour.print($"[ItemFourEyes.Handler()] Miss. ({roll:P1} < {CHANCE:P1})")
}
}
}
}
\ No newline at end of file
......@@ -6,15 +6,16 @@ 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%";
public class ItemRunningShoes : PassiveItemBase {
public override ulong Id => 101;
public override string Name => "Running Shoes";
public override string Description => "Increases movement speed by 50%";
public ItemRunningShoes() {
Modifier = new CharacterStats{
MoveSpeed = 0.5f,
};
......
fileFormatVersion: 2
guid: 12406fa4fcf374142ad545946396cbde
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -44,6 +44,9 @@ namespace BigSock {
spriteRenderer = GetComponent<SpriteRenderer>();
hpBar.SetMaxHealth(Convert.ToInt32(MaxHP));
hpBar.SetHealth(Convert.ToInt32(HP));
//!! DEBUG: Add item to player at start to test if it works.
TryPickUpItem(new ItemFourEyes());
}
......@@ -106,7 +109,7 @@ namespace BigSock {
//!! Code for testing the new item stuff.
if(Input.GetKeyDown(KeyCode.Space)) {
TryPickUpItem(new RunningShoes());
TryPickUpItem(new ItemRunningShoes());
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment