void Awake() { db = GameObject.FindGameObjectWithTag("Database").GetComponent <GameDatabase>(); skillset = GetComponent <PlayerSkillset>(); isPlayer = false; }
/* * NETWORK-SPECIFIC */ public override void Attached() { // SETUP db = GameObject.FindGameObjectWithTag("Database").GetComponent <GameDatabase>(); renderer = GetComponent <Renderer> (); stats = GetComponent <ActorStats> (); inventory = GetComponent <Inventory> (); skillset = GetComponent <PlayerSkillset>(); // CUSTOMISATION TOKEN // Loads the player's inventory, chosen faction and race etc., // which were selected in the character creation screen. var customisation = (CustomisationToken)entity.attachToken; stats.LoadCustomisation(customisation); //stats.LoadInterface(); inventory.LoadInventory(); inventory.LoadInterface(); if (entity.isOwner) { // Sync customisation data to server... // BACKGROUND DATA (faction, race) state.BackgroundData.StartingFaction = stats.actorStartingFaction; state.BackgroundData.CharacterRace = stats.actorRaceName; // STATS // Gets each property in the actor's stats component. // For each one, sync with the player's stats on the server. BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly; PropertyInfo[] properties = stats.GetType().GetProperties(flags); BoltActorStatset statset = state.BoltActorStatset; for (int h = 0; h < properties.Length; h++) { try { statset.Statset[h].StatName = properties[h].Name; statset.Statset[h].StatValue = (System.Int32)properties[h].GetValue(stats, null); } catch (System.InvalidCastException cast) { Debug.LogWarning(cast.Message); Debug.LogWarning(properties[h].Name); } } // SKILLSET for (int i = 0; i < skillset.PlayerSkills.Count; i++) { state.BoltPlayerSkillset.Skillset[i].SkillName = skillset.PlayerSkills[i].GetSkill().SkillName; state.BoltPlayerSkillset.Skillset[i].SkillLevel = skillset.PlayerSkills[i].GetLevel(); } SyncInventory(); AddRacePerks(stats.actorRaceName); // adds the perks related to the player's race. // debug: give the player a random colour. state.DebugColour = new Color(Random.value, Random.value, Random.value); } state.AddCallback("BoltActorStatset", StatsChanged); state.AddCallback("BoltPlayerSkillset", SkillsetChanged); state.AddCallback("DebugColour", ColourChanged); state.AddCallback("BackgroundData", BackgroundDataChanged); }