Skip to content

Commit

Permalink
Inventory with restrictions and item freezing and defrosting. Equipme…
Browse files Browse the repository at this point in the history
…nt now delegates to base item, if any, for params. Fix bugs team recaching after recompile.
  • Loading branch information
JoeOsborn committed Apr 25, 2012
1 parent 4a87d9d commit 3b09d82
Show file tree
Hide file tree
Showing 94 changed files with 416 additions and 75 deletions.
30 changes: 15 additions & 15 deletions Assets/Editor/SRPGKit/InventoryEditor.cs
Expand Up @@ -17,21 +17,6 @@ public class InventoryEditor : SRPGCKEditor {
EditorGUILayout.HelpBox("Inventory is used for unequipped items such as commodities and consumables. Inventory items do not provide passive effects, skills, or other adjustments until they are instantiated. Formulae are in character-stat scope.", MessageType.Info);
}
EditorGUIUtility.LookLikeInspector();
inv.limitedCapacity = EditorGUILayout.Toggle(
"Limited Total Count",
inv.limitedCapacity
);
if(inv.limitedCapacity) {
inv.capacityF = EditorGUIExt.FormulaField(
"Capacity:",
inv.capacityF ??
Formula.Constant(20),
inv.name+".inventory.capacity",
formulaOptions,
lastFocusedControl
);
}

inv.limitedStacks = EditorGUILayout.Toggle(
"Limited Stacks",
inv.limitedStacks
Expand All @@ -46,6 +31,21 @@ public class InventoryEditor : SRPGCKEditor {
lastFocusedControl
);
}

inv.limitedStacks = EditorGUILayout.Toggle(
"Override Item Stack Size",
inv.limitedStackSize
);
if(inv.limitedStackSize) {
inv.stackSizeF = EditorGUIExt.FormulaField(
"Stack Size:",
inv.stackSizeF ??
Formula.Constant(1),
inv.name+".inventory.stackSize",
formulaOptions,
lastFocusedControl
);
}

inv.limitedWeight = EditorGUILayout.Toggle(
"Limited Weight",
Expand Down
44 changes: 44 additions & 0 deletions Assets/Editor/SRPGKit/ItemEditor.cs
@@ -0,0 +1,44 @@
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;

[CustomEditor(typeof(Item))]
public class ItemEditor : SRPGCKEditor {
[MenuItem("SRPGCK/Create item", false, 3)]
public static Item CreateItem()
{
return ScriptableObjectUtility.CreateAsset<Item>(
null,
"Assets/SRPGCK Data/Items",
true
);
}
Item it;

public override void OnEnable() {
it = target as Item;
base.OnEnable();
it.fdb = fdb;
name = "Item";
}

public override void OnSRPGCKInspectorGUI() {
it.name = EditorGUILayout.TextField("Name", it.name);
it.prefab = EditorGUILayout.ObjectField(
"Prefab",
it.prefab as UnityEngine.Object,
typeof(Transform),
false
) as Transform;
it.weight = EditorGUILayout.FloatField("Weight", it.weight);
it.stackSize = EditorGUILayout.IntField("Stack Size", it.stackSize);
it.parameters = EditorGUIExt.ParameterFoldout(
"Parameter",
it.parameters,
"item."+it.itemName+".params.",
formulaOptions,
lastFocusedControl,
ref it.editorShowParameters
);
}
}
7 changes: 7 additions & 0 deletions Assets/Editor/SRPGKit/ItemEditor.cs.meta

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

21 changes: 18 additions & 3 deletions Assets/Plugins/SRPGKit/Equipment/Equipment.cs
Expand Up @@ -20,6 +20,7 @@ public class Equipment : MonoBehaviour {
public StatusEffect[] statusEffectPrefabs;

Dictionary<string, Formula> runtimeParameters;
InstantiatedItem baseItem;

public void Start() {
for(int i = 0; i < equipmentSlots.Length; i++) {
Expand All @@ -35,6 +36,7 @@ public class Equipment : MonoBehaviour {
wielder = t.GetComponent<Character>();
if(wielder == null) { t = t.parent; }
}
baseItem = GetComponent<InstantiatedItem>();
if(wielder == null) { Debug.LogError("No wielder"); }
if(equippedSlots == null || equippedSlots.Length == 0) {
wielder.Equip(this);
Expand All @@ -50,20 +52,33 @@ public class Equipment : MonoBehaviour {
}
}
}
public bool HasParam(string pname) {

public bool HasOwnParam(string pname) {
MakeParametersIfNecessary();
return runtimeParameters.ContainsKey(pname);
}

public bool HasParam(string pname) {
return HasOwnParam(pname) || (baseItem != null && baseItem.HasParam(pname));
}

public Formulae fdb { get {
if(wielder != null) { return wielder.fdb; }
return Formulae.DefaultFormulae;
} }

public float GetParam(string pname, SkillDef scontext=null) {
public float GetParam(string pname, SkillDef scontext=null, float fallback=float.NaN) {
MakeParametersIfNecessary();
FindWielder();
if(!HasOwnParam(pname)) {
if(baseItem != null) {
return baseItem.GetParam(pname, scontext, fallback);
}
if(float.IsNaN(fallback)) {
Debug.LogError("No fallback for missing equipment param "+pname);
}
return fallback;
}
return runtimeParameters[pname].GetValue(fdb, scontext, null, null, this);
}

Expand Down
4 changes: 4 additions & 0 deletions Assets/Plugins/SRPGKit/Game Flow/Arbiter.cs
Expand Up @@ -47,6 +47,7 @@ public class Arbiter : MonoBehaviour {
_teams = null;
return null;
}
_teams[t.id] = t;
}
}
return _teams;
Expand All @@ -58,6 +59,9 @@ public class Arbiter : MonoBehaviour {

public Team GetTeam(int team) {
if(!Application.isPlaying) { return EditorGetTeam(team); }
if(_teams == null || _teams.Count == 0) {
teams = null;
}
return teams[team];
}
public void AddTeam(Team t) {
Expand Down
20 changes: 20 additions & 0 deletions Assets/Plugins/SRPGKit/Game Flow/InstantiatedItem.cs
@@ -0,0 +1,20 @@
using UnityEngine;
using System.Linq;
using System.Collections.Generic;
using UnityEditor;

public class InstantiatedItem : MonoBehaviour {
public Item item;

public bool HasParam(string pname) {
return item.HasParam(pname);
}

public float GetParam(
string pname,
SkillDef scontext=null,
float fallback=float.NaN
) {
return item.GetParam(pname, scontext, fallback);
}
}
7 changes: 7 additions & 0 deletions Assets/Plugins/SRPGKit/Game Flow/InstantiatedItem.cs.meta

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

0 comments on commit 3b09d82

Please sign in to comment.