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

Merge branch 'master' into 'main'

Dodge

See merge request !34
parents 16860b71 a0f07491
No related branches found
No related tags found
2 merge requests!41Pushing new changes in main into master,!34Dodge
......@@ -6,7 +6,10 @@ using UnityEngine.InputSystem;
using BigSock.Item;
namespace BigSock {
// Common class for all characters.
/*
Common class for all characters.
*/
public partial class Character : Entity {
/*
......@@ -74,27 +77,6 @@ namespace BigSock {
public int level;
/*
Indicates whether or not the characer is a live.
*/
public bool Alive { get; private set; } = true;
/*
Stores the next time the character can recieve damage.
*/
public DateTime NextTimeCanTakeDamage { get; private set; } = DateTime.Now;
/*
How long between each time the character can take damage.
*/
public TimeSpan IFrameDuration {
get => _iFrameDuration;
private set => _iFrameDuration = value;
}
public TimeSpan _iFrameDuration = new TimeSpan(0, 0, 0, 0, 333);
protected Rigidbody2D rb;
......@@ -163,11 +145,11 @@ namespace BigSock {
/*
Add Kcockback.
Add Knockback.
*/
//public void KnockBack(float force, Vector2 difference) {
// rb.AddForce(difference * force, ForceMode2D.Impulse);
//}
public void KnockBack(float force, Vector2 difference) {
rb.AddForce(difference * force, ForceMode2D.Impulse);
}
public void KnockBack(IAttackStats attack) {
Vector2 difference = ((Vector2) transform.position - attack.Source).normalized;
//KnockBack(attack.Knockback, difference);
......@@ -194,11 +176,11 @@ namespace BigSock {
if(!attack.IsCalculated) throw new ArgumentException("Attack needs to be calculated.", nameof(attack));
// Check if player has IFrames
if(NextTimeCanTakeDamage > DateTime.Now)
if(HasIFrames)
return false;
// Start new IFrames
NextTimeCanTakeDamage = DateTime.Now + IFrameDuration;
AddIFrames(IFrameDuration);
// Trigger the event for taking damage.
OnTakeDamage?.Invoke(this, attack.Actor, attack);
......@@ -285,6 +267,8 @@ namespace BigSock {
/*
Items
*/
......@@ -464,4 +448,181 @@ namespace BigSock {
}
/*
Status effects.
*/
public partial class Character {
/*
Indicates whether or not the characer is alive.
*/
public bool Alive { get; private set; } = true;
/*
How long between each time the character can take damage.
*/
public TimeSpan IFrameDuration {
get => _iFrameDuration;
private set => _iFrameDuration = value;
}
public TimeSpan _iFrameDuration = new TimeSpan(0, 0, 0, 0, 333);
/*
Is the character stunned.
*/
public bool IsStunned => NextTimeNotStunned > DateTime.Now;
/*
Stores the next time the character can isn't stunned.
*/
public DateTime NextTimeNotStunned { get; private set; } = DateTime.Now;
/*
Is the character visible.
*/
public bool IsInvisible => NextTimeVisible > DateTime.Now;
/*
Stores the next time the character can recieve damage.
*/
public DateTime NextTimeVisible { get; private set; } = DateTime.Now;
/*
Is the character invincible.
*/
public bool HasIFrames => NextTimeCanTakeDamage > DateTime.Now;
/*
Stores the next time the character can recieve damage.
*/
public DateTime NextTimeCanTakeDamage { get; private set; } = DateTime.Now;
/*
Adds a status effect to the character.
*/
public bool AddStatusEffect(StatusEffectType statusType, TimeSpan amount) {
switch(statusType) {
case StatusEffectType.Invincible: return AddIFrames(amount);
case StatusEffectType.Invisible: return AddInvisibility(amount);
case StatusEffectType.Stun: return AddStun(amount);
default: return false;
}
}
/*
Adds Stun for the character.
*/
public bool AddStun(TimeSpan amount) {
// Get when the status effect would expire.
var wouldExpire = DateTime.Now + IFrameDuration;
// Only if that's later than current.
if(wouldExpire > NextTimeNotStunned) {
// If character currently doesn't have the status effect.
if(NextTimeNotStunned < DateTime.Now) {
ApplyStun();
}
// Set new time.
NextTimeNotStunned = wouldExpire;
return true;
}
return false;
}
/*
Appies Stun to the character.
*/
private void ApplyStun() {
}
/*
Removes Stun for the character.
*/
private void RemoveStun() {
}
/*
Adds invisibility for the character.
*/
public bool AddInvisibility(TimeSpan amount) {
// Get when the status effect would expire.
var wouldExpire = DateTime.Now + IFrameDuration;
// Only if that's later than current.
if(wouldExpire > NextTimeVisible) {
// If character currently doesn't have the status effect.
if(NextTimeVisible < DateTime.Now) {
ApplyInvisibility();
}
// Set new time.
NextTimeVisible = wouldExpire;
return true;
}
return false;
}
/*
Appies invisibility to the character.
*/
private void ApplyInvisibility() {
}
/*
Removes invisibility for the character.
*/
private void RemoveInvisibility() {
}
/*
Adds IFrames for the character.
*/
public bool AddIFrames(TimeSpan amount) {
// Get when the IFrames would expire.
var nextCanTakeDamage = DateTime.Now + IFrameDuration;
// Only if that's later than current.
if(nextCanTakeDamage > NextTimeCanTakeDamage) {
// If character currently doesn't have the status effect.
if(NextTimeCanTakeDamage < DateTime.Now) {
ApplyIFrames();
}
// Set new time.
NextTimeCanTakeDamage = nextCanTakeDamage;
return true;
}
return false;
}
/*
Appies IFrames to the character.
*/
private void ApplyIFrames() {
}
/*
Removes IFrames for the character.
*/
private void RemoveIFrames() {
}
}
}
using System.Collections;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using BigSock.Service;
namespace BigSock {
/*
A basic dodge move that gives a push and a short invincibility.
*/
public class AbilityDodge : BaseAbility {
public static readonly float BASE_FORCE = 0.5f;
public static readonly TimeSpan IFRAME_DURATION = new TimeSpan(0, 0, 0, 0, 500);
public override ulong Id => 201;
public override string Name => "Dodge";
public override string Description => "A basic dodge move.";
public AbilityDodge() {
StaminaCost = 4;
Cooldown = new TimeSpan(0, 0, 0, 1, 0);
}
/*
Activates the ability.
*/
protected override bool Activate(Character actor, Vector3? target) {
if(target == null) return false;
// Get direction.
var temp = (target.Value - actor.transform.position);
temp.z = 0;
var direction = (Vector2) temp.normalized;
// Get the force.
var force = BASE_FORCE * actor.Stats.MoveSpeed;
// Apply the push and iframes.
actor.KnockBack(force, direction);
actor.AddStatusEffect(StatusEffectType.Invincible, IFRAME_DURATION);
return true;
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: c7c0fcb77471bc0469856ad6f91803c5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using System;
namespace BigSock {
/*
The different types of status effects.
*/
public enum StatusEffectType {
Invincible = 0,
Invisible = 1,
Stun = 2,
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 3b098d33750fa314c975d94a25c5b14f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -36,6 +36,7 @@ namespace BigSock {
protected IAttack _testAttack;
protected IAttack _testAttack2;
protected IAbility _dodge;
public DateTime NextTimeCanAttack { get; private set; } = DateTime.Now;
......@@ -58,13 +59,16 @@ namespace BigSock {
//!! DEBUG: Add item to player at start to test if it works.
TryPickUpItem(ItemService.SINGLETON.Get(201));
TryPickUpItem(ItemService.SINGLETON.Get(201));
TryPickUpItem(ItemService.SINGLETON.Get(202));
TryPickUpItem(ItemService.SINGLETON.Get(101));
var tmp = PrefabService.SINGLETON;
//TryPickUpItem(ItemService.SINGLETON.Get(201));
//TryPickUpItem(ItemService.SINGLETON.Get(201));
//TryPickUpItem(ItemService.SINGLETON.Get(202));
//TryPickUpItem(ItemService.SINGLETON.Get(101));
//var tmp = PrefabService.SINGLETON;
_testAttack = (IAttack) AbilityService.SINGLETON.Get(101);
_testAttack2 = (IAttack) AbilityService.SINGLETON.Get(102);
_dodge = AbilityService.SINGLETON.Get(201);
}
......@@ -122,12 +126,20 @@ namespace BigSock {
}
}
// If pressed Z: Big attack.
if(Input.GetKey(KeyCode.Z)) {
_testAttack2.Use(this, Camera.main.ScreenToWorldPoint(Input.mousePosition));
}
// If pressed X: dodge.
if(Input.GetKey(KeyCode.X)) {
_dodge.Use(this, Camera.main.ScreenToWorldPoint(Input.mousePosition));
}
//!! Code for testing the new item stuff.
if(Input.GetKeyDown(KeyCode.Space)) {
if(Input.GetKeyDown(KeyCode.M)) {
var item = ItemService.SINGLETON.GetRandom(); // new ItemRunningShoes();
TryPickUpItem(item);
}
......
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