Skip to content

Commit

Permalink
Introduce buff categories of "Buff" and "Debuff". Created a Lootable …
Browse files Browse the repository at this point in the history
…folder and an example loottable. Updated Readme to include Unity version.
  • Loading branch information
Fydar committed Nov 22, 2018
1 parent 3cf87c7 commit 5317b42
Show file tree
Hide file tree
Showing 22 changed files with 77 additions and 90 deletions.
7 changes: 3 additions & 4 deletions NOTICE.md
@@ -1,8 +1,7 @@
##### NOTICE File for the Apache License, Version 2.0
**NOTICE File for the Apache License, Version 2.0**

# RPGCore

Created and maintained by Anthony Marmont (https://anthonymarmont.com/).

This is public work available on GitHub (https://github.com/Fydar/RPGCore).
Created and maintained by Anthony Marmont (<https://anthonymarmont.com/>).

This is public work available on GitHub (<https://github.com/Fydar/RPGCore>).
14 changes: 8 additions & 6 deletions README.md
Expand Up @@ -4,6 +4,8 @@

RPGCore is a framework for producing RPG games and mechanics in Unity.

It's currently using **Unity 2018.2.3f1**.

![RPGCore Main Demo][MainImage]

At it's core, it features a behaviour system that's used to create items and buffs. The behaviour system is setup using a visual scripting tool, shown below.
Expand All @@ -30,12 +32,6 @@ I am currently in the process of rewriting RPGCore to run on servers and not rel

RPGCore is built around a modular behaviour system. One of the core uses for this system is modular items.

## Poison Potion

Below is a poision potion. The user may drink it and take damage - though I'm not sure why they would want too.

![Poison Potion][PoisonPotion]

### Fire Cape

Below is an item called the "Fire Cape". It applies the Immolate buff to it's owner, which deals damage to nearby enemies.
Expand All @@ -46,6 +42,12 @@ This graph in the game is interpreted by the tooltip system, which renders the "

![Fire Cape Tooltip][FireCapeTooltip]

## Poison Potion

Below is a poision potion. The user may drink it and take damage - though I'm not sure why they would want too.

![Poison Potion][PoisonPotion]

## Buffs

The modular behaviour system has other applications, such as buffs and debuffs. Events can be used to trigger behaviours on ticks of the buff, and effects can be applied continuously throughout the duration of the buff.
Expand Down
36 changes: 18 additions & 18 deletions RPGCore/Assets/RPGCore/Scripts/Buffs/Buff.cs
Expand Up @@ -141,27 +141,10 @@ public void AddClock (BuffClock clock)

clock.StackSize.OnValueChanged += RecalculateStackSizeCallback;
clock.OnRemove += removeCallback;
clock.OnTick += () => { OnTick (); };
clock.OnTick += OnTick;

RecalculateStackSizeCallback (0);
}

private void RecalculateStackSizeCallback (int _)
{
RecalculateStackSize ();
}

private void RecalculateStackSize ()
{
int counter = BaseStackSize.Value;

foreach (BuffClock addClock in Clocks)
{
counter += addClock.StackSize.Value;
}
StackSize.Value = counter;
}

public void RemoveClock (BuffClock clock)
{
clock.OnTick -= OnTick;
Expand All @@ -183,5 +166,22 @@ public void RemoveBuff ()
if (OnRemove != null)
OnRemove ();
}

private void RecalculateStackSizeCallback (int _)
{
RecalculateStackSize ();
}

private void RecalculateStackSize ()
{
int counter = BaseStackSize.Value;

foreach (BuffClock addClock in Clocks)
{
counter += addClock.StackSize.Value;
}
StackSize.Value = counter;
}

}
}
2 changes: 1 addition & 1 deletion RPGCore/Assets/RPGCore/Scripts/Buffs/BuffClock.cs
Expand Up @@ -5,7 +5,7 @@

namespace RPGCore
{
[System.Serializable]
[Serializable]
public abstract class BuffClock
{
public Action OnRemove;
Expand Down
4 changes: 2 additions & 2 deletions RPGCore/Assets/RPGCore/Scripts/Buffs/BuffClockDecaying.cs
Expand Up @@ -9,9 +9,9 @@ public class BuffClockDecaying : BuffClock
{
public float Duration = 3.0f;
public int Ticks = 20;
public float TimeRemaining;

public float TimeRemaining = 0.0f;
private int TicksCompleted = 0;
private int TicksCompleted;

public override float DisplayPercent
{
Expand Down
5 changes: 2 additions & 3 deletions RPGCore/Assets/RPGCore/Scripts/Buffs/BuffClockFixed.cs
Expand Up @@ -9,7 +9,7 @@ public class BuffClockFixed : BuffClock
{
public float TicksPerSecond = 3.0f;

private float tickProgress = 0.0f;
private float tickProgress;

public override float DisplayPercent
{
Expand All @@ -33,8 +33,7 @@ public BuffClockFixed (BuffGrantNode buffNode, IBehaviourContext context)
{
TicksPerSecond = buffNode.TicksPerSecond[context].Value;
}



public override void Update (float deltaTime)
{
tickProgress += deltaTime;
Expand Down
3 changes: 0 additions & 3 deletions RPGCore/Assets/RPGCore/Scripts/Buffs/BuffCollection.cs
Expand Up @@ -2,9 +2,6 @@
using System.Collections;
using System.Collections.Generic;

#if UNITY_EDITOR
#endif

namespace RPGCore
{
public class BuffCollection : IEnumerable<Buff>
Expand Down
2 changes: 1 addition & 1 deletion RPGCore/Assets/RPGCore/Scripts/Buffs/BuffTemplate.cs
Expand Up @@ -15,6 +15,6 @@ public class BuffTemplate : BehaviourGraph
#endif
public Sprite Icon;

public bool isDebuff = false;
public BuffType Type;
}
}
9 changes: 9 additions & 0 deletions RPGCore/Assets/RPGCore/Scripts/Buffs/BuffType.cs
@@ -0,0 +1,9 @@
namespace RPGCore
{
public enum BuffType
{
None,
Buff,
Debuff
}
}
11 changes: 11 additions & 0 deletions RPGCore/Assets/RPGCore/Scripts/Buffs/BuffType.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions RPGCore/Assets/RPGCore/Scripts/Buffs/IntegerStack.cs
Expand Up @@ -15,7 +15,7 @@ public class IntegerStack
{
public Action<int> OnValueChanged;

private int delta = 0;
private int delta;

public float Delta
{
Expand Down Expand Up @@ -71,10 +71,10 @@ public Modifier (IntegerStack parent, int value)

[SerializeField]
[FormerlySerializedAs ("BaseValue")]
private int baseValue = 0;
private int baseValue;

[NonSerialized]
private int lastValue = 0;
private int lastValue;
[NonSerialized]
private bool isDirty = true;

Expand Down Expand Up @@ -164,7 +164,6 @@ protected int Sum (List<Modifier> modifiers)
[CustomPropertyDrawer (typeof (IntegerStack))]
public class IntegerStackDrawer : PropertyDrawer
{

public override float GetPropertyHeight (SerializedProperty property, GUIContent label)
{
return base.GetPropertyHeight (property, label);
Expand All @@ -181,17 +180,14 @@ public override void OnGUI (Rect position, SerializedProperty property, GUIConte
IntegerStack statInst = (IntegerStack)GetTargetObjectOfProperty (property);

Rect fieldRect;
//Rect valueRect;

if (Application.isPlaying)
{
fieldRect = new Rect (position.x, position.y, position.width - 40, position.height);
//valueRect = new Rect (fieldRect.xMax, fieldRect.y, 40, position.height);
}
else
{
fieldRect = position;
//valueRect = position;
}

valueProperty.intValue = EditorGUI.IntField (fieldRect, label, valueProperty.intValue);
Expand Down
@@ -1,5 +1,5 @@
using UnityEngine;
using UnityEditor;
using UnityEditor;
using UnityEngine;

namespace RPGCore.Utility.Editors
{
Expand Down Expand Up @@ -35,7 +35,7 @@ public Texture2D RenderShader (Color primary, Color secondary, int width, int he
if (x > y)
preview.SetPixel (x, y, primary);
else if (x == y)
preview.SetPixel (x, y, new Color(
preview.SetPixel (x, y, new Color (
(primary.r + secondary.r) * 0.5f,
(primary.g + secondary.g) * 0.5f,
(primary.b + secondary.b) * 0.5f));
Expand Down
@@ -1,5 +1,4 @@
using RPGCore.Behaviour;
using RPGCore.Behaviour.Connections;
using System;
using System.Collections.Generic;
using UnityEngine;
Expand Down
40 changes: 6 additions & 34 deletions RPGCore/Assets/RPGCore/Scripts/Item/Tables/Loottable.cs
@@ -1,4 +1,5 @@
using UnityEngine;
using System;
using System.Collections.Generic;

#if UNITY_EDITOR
Expand All @@ -10,7 +11,7 @@ namespace RPGCore.Tables
[CreateAssetMenu (menuName = "RPGCore/Loottable")]
public class Loottable : ScriptableObject
{
[System.Serializable]
[Serializable]
public class ItemEntry : GenericTableEntry<ItemGenerator>
{
public ItemEntry (ItemGenerator item, float balance)
Expand All @@ -20,7 +21,7 @@ public ItemEntry (ItemGenerator item, float balance)
}
}

[System.Serializable]
[Serializable]
public class ItemRoll : MultiAssetSelector<ItemGenerator, ItemEntry>
{

Expand Down Expand Up @@ -77,45 +78,16 @@ public List<ItemSurrogate> SelectMultiple ()
return cachedGeneratedItems;
}

private void Test ()
{
foreach (ItemRoll roll in TableRolls)
{
ItemGenerator gen = roll.Select ();
Debug.Log (gen.RewardTemplate.BaseName);
}
}

private void MultipleTest ()
{
foreach (ItemRoll roll in TableRolls)
{
ItemGenerator[] gen = roll.SelectMultiple ();
for (int i = 0; i < gen.Length; i++)
{
Debug.Log (gen[i].RewardTemplate.BaseName);
}
}
}

#if UNITY_EDITOR
[CustomEditor (typeof (Loottable))]
public class LootTableDrawer : Editor
[CustomEditor (typeof (Loottable), true)]
class LootTableDrawer : Editor
{
Loottable lootTable;
public override void OnInspectorGUI ()
{
lootTable = (Loottable)target;
//lootTable = (Loottable)target;

DrawDefaultInspector ();
if (GUILayout.Button ("Roll"))
{
lootTable.Test ();
}
if (GUILayout.Button ("RollMultiple"))
{
lootTable.MultipleTest ();
}
}
}
#endif
Expand Down
5 changes: 4 additions & 1 deletion RPGCore/Assets/RPGCore/Scripts/UI/Buffs/BuffsBar.cs
Expand Up @@ -32,8 +32,11 @@ private void Subscribe (RPGCharacter character)

private void CreateIndicator (Buff buff)
{
if (buff.buffTemplate.Type == BuffType.None)
return;

Transform parent;
if (buff.buffTemplate.isDebuff)
if (buff.buffTemplate.Type == BuffType.Debuff)
parent = DebuffsHolder;
else
parent = BuffsHolder;
Expand Down
Expand Up @@ -14,7 +14,7 @@ public class DrawerLibraryResources : ScriptableObject
public Texture2D WarningIcon;
[ErrorIfNull]
public Texture2D ErrorIcon;

public static DrawerLibraryResources Instance
{
get
Expand Down
Expand Up @@ -147,7 +147,7 @@ public static float Padding
static RuntimePreviewGenerator ()
{
m_Scene = EditorSceneManager.NewPreviewScene ();

var Light0 = CreateLight ();
Light0.transform.rotation = Quaternion.Euler (70, 180, 0);
Light0.color = new Color (1.0f, 0.95f, 0.9f);
Expand All @@ -157,7 +157,7 @@ static RuntimePreviewGenerator ()
Light1.transform.rotation = Quaternion.Euler (340, 218, 177);
Light1.color = new Color (.4f, .4f, .45f, 0f) * .7f;
Light1.intensity = 1;

PreviewRenderCamera = null;
PreviewDirection = new Vector3 (-1f, -1f, -1f);
Padding = 0f;
Expand Down Expand Up @@ -367,7 +367,7 @@ private static void CalculateMaxDistance (Vector3 point)

float horizontalDistance = projectionPlaneHorizontal.GetDistanceToPoint (point);
float verticalDistance = projectionPlaneVertical.GetDistanceToPoint (point);

float halfFrustumHeight = Mathf.Max (verticalDistance, horizontalDistance / aspect);
float distance = halfFrustumHeight / Mathf.Tan (renderCamera.fieldOfView * 0.5f * Mathf.Deg2Rad);

Expand Down
Expand Up @@ -247,7 +247,7 @@ private static FieldInfo GetSerializationField (Type type, string name)
FieldInfo[] fields = type.GetFields (BindingFlags.Public | BindingFlags.Instance);
foreach (FieldInfo field in fields)
{
var attributes = field.GetCustomAttributes (typeof(FormerlySerializedAsAttribute), true);
var attributes = field.GetCustomAttributes (typeof (FormerlySerializedAsAttribute), true);

foreach (var attribute in attributes)
{
Expand Down
Expand Up @@ -398,4 +398,4 @@ private static object GetValue_Imp (object source, string name, int index)
}
}
#endif
}
}

0 comments on commit 5317b42

Please sign in to comment.