From 627c6cb077c05a34656959889de8f0a116f6b529 Mon Sep 17 00:00:00 2001 From: "Crom (Thibaut CHARLES)" Date: Wed, 4 Mar 2015 17:09:45 +0100 Subject: [PATCH] Constrution d'un joueur --- Assets/src/Player.cs | 41 +++++++++++++++++++++++++++++++++++++ Assets/src/Player.cs.meta | 12 +++++++++++ Assets/src/RulesDatabase.cs | 17 +++++++-------- Assets/src/TwoDA.cs | 5 +++-- 4 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 Assets/src/Player.cs create mode 100644 Assets/src/Player.cs.meta diff --git a/Assets/src/Player.cs b/Assets/src/Player.cs new file mode 100644 index 0000000..cea04b2 --- /dev/null +++ b/Assets/src/Player.cs @@ -0,0 +1,41 @@ +using UnityEngine; +using System.Collections; + +public class Player { + + Player(int _charID, int _roleID){ + charID = _charID; + roleID = _roleID; + + var ct = Rdb.GetTable("characters"); + charname = ct.GetValue(charID, "name"); + spellID = ct.GetValue(charID, "spell"); + hp = ct.GetValue(charID, "hp"); + + var rt = Rdb.GetTable("roles"); + rolename = rt.GetValue(roleID, "name"); + ultiID = rt.GetValue(roleID, "ulti"); + align = rt.GetValue(roleID, "alignment"); + } + + + + + + + void DebugInfo() { + Debug.Log(charname+" is a "+rolename+" with "+hp.ToString()+" hit points"); + } + + + + int charID; + int roleID; + + string charname; + int spellID; + int hp; + string rolename; + int ultiID; + string align; +} diff --git a/Assets/src/Player.cs.meta b/Assets/src/Player.cs.meta new file mode 100644 index 0000000..ad2bed7 --- /dev/null +++ b/Assets/src/Player.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 1747e8b9a8f0111409e8e9970a88305a +timeCreated: 1425468606 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/src/RulesDatabase.cs b/Assets/src/RulesDatabase.cs index 8fb682d..027125c 100644 --- a/Assets/src/RulesDatabase.cs +++ b/Assets/src/RulesDatabase.cs @@ -2,7 +2,8 @@ using UnityEngine; using System.IO; using System.Collections.Generic; -public class RulesDatabase { +//RulesDatabase +public class Rdb { public static TwoDA GetTable(string name) { TwoDA t = null; @@ -18,16 +19,16 @@ public class RulesDatabase { } public static string GetStrRef(int strref) { - RulesDatabase inst = Get(); + Rdb inst = Get(); - return inst.m_strref.GetValue(strref, "text"); + return inst.m_strref.GetValue(strref, "text"); } - private RulesDatabase() { + private Rdb() { m_tables = new Dictionary(); string[] files = Directory.GetFiles(m_folder, "*.2da", SearchOption.AllDirectories); @@ -43,12 +44,12 @@ public class RulesDatabase { } - private static RulesDatabase m_inst = null; + private static Rdb m_inst = null; private static object m_singlmutex = new Object(); - private static RulesDatabase Get() { + private static Rdb Get() { lock(m_singlmutex) { if(m_inst==null) - m_inst = new RulesDatabase(); + m_inst = new Rdb(); } return m_inst; } @@ -58,4 +59,4 @@ public class RulesDatabase { private string m_folder = "Assets/rules"; -} +} \ No newline at end of file diff --git a/Assets/src/TwoDA.cs b/Assets/src/TwoDA.cs index e121f7b..1c0f236 100644 --- a/Assets/src/TwoDA.cs +++ b/Assets/src/TwoDA.cs @@ -1,4 +1,5 @@ using UnityEngine; +using System; using System.Collections.Generic; using System.Text.RegularExpressions; @@ -47,11 +48,11 @@ public class TwoDA : UnityEngine.Object { file.Close(); } - public string GetValue(int nRow, string sColumn) { + public T GetValue(int nRow, string sColumn) { int nCol = FindHeaderCol(sColumn); if(nCol>=0) { - return m_data[nRow][nCol]; + return (T)Convert.ChangeType(m_data[nRow][nCol], typeof(T)); } else { throw new UnityException("Column '"+sColumn+"' not found in 2DA");