private void RewardVictor(ref Stats deadMonster, Entity attacker, ref Stats attackerStats, int defenderClanID, int defenderMetaID) { //int levelID = 0; /*if (!(StatsIndexes.experience < attackerStats.states.Length)) * { * Debug.LogError("States are too small, doesnt havexp in them: " + attackerStats.states.Length); * return; * }*/ if (attackerStats.levels.Length == 0) { return; } // should create a KillSystem that gives rewards //StateStaz experience = attackerStats.states[StatsIndexes.experience]; Level attackerLevel = attackerStats.levels[0]; // should pick up items called Soul Orbs that give you experience instead int levelValue = 0; if (deadMonster.levels.Length > 0) { levelValue = deadMonster.levels[0].value; } float experienceGiven = (levelValue + 1) * UnityEngine.Random.Range(0.5f, 1.5f); ZoxID attackerID = World.EntityManager.GetComponentData <ZoxID>(attacker); if (attackerID.creatorID == 0) { // normal experience // Debug.LogError("Giving experience: " + experienceGiven); attackerLevel.experienceGained += experienceGiven;// adding health as experience, shouldnt be based on their level? } else { if (characterSpawnSystem.characters.ContainsKey(attackerID.creatorID) == false) { //Debug.LogError("Creator does not exist."); attackerLevel.experienceGained += experienceGiven; } else { Entity summonerEntity = characterSpawnSystem.characters[attackerID.creatorID]; if (World.EntityManager.HasComponent <Stats>(summonerEntity)) { Stats summoner = World.EntityManager.GetComponentData <Stats>(summonerEntity); if (summoner.levels.Length > 0) { //StateStaz summonerExp = summoner.states[StatsIndexes.experience]; Level summonerLevel = summoner.levels[0]; summonerLevel.experienceGained += experienceGiven / 2f; if (summonerLevel.experienceGained >= summonerLevel.experienceRequired) { summoner.leveledUp = 1; } summoner.levels[0] = summonerLevel; World.EntityManager.SetComponentData(summonerEntity, summoner); attackerLevel.experienceGained += experienceGiven / 2f; StatsUISpawnSystem.OnUpdatedStat(World.EntityManager, summonerEntity, StatType.Level, 0); } else { attackerLevel.experienceGained += experienceGiven; } } else { attackerLevel.experienceGained += experienceGiven; //Debug.LogError("Creator exists. But has no stats."); //experience.value += experienceGiven;// adding health as experience, shouldnt be based on their level? } } } if (attackerLevel.experienceGained >= attackerLevel.experienceRequired) { attackerStats.leveledUp = 1; } attackerStats.levels[0] = attackerLevel; World.EntityManager.SetComponentData(attacker, attackerStats); StatsUISpawnSystem.OnUpdatedStat(World.EntityManager, attacker, StatType.Level, 0); // give quest completion stat to the character if (characterSpawnSystem.characters.ContainsKey(attackerID.id)) { Entity characterEntity = characterSpawnSystem.characters[attackerID.id]; // get questlog if (World.EntityManager.HasComponent <QuestLog>(characterEntity)) { QuestLog questLog = World.EntityManager.GetComponentData <QuestLog>(characterEntity); if (questLog.OnKilledCharacter(defenderMetaID)) { World.EntityManager.SetComponentData(characterEntity, questLog); // update questlog UI //Bootstrap.instance.systemsManager.questLogUISpawnSystem.UpdateUI(createdID.id); } } } }
private void SaveComponentData <T>(Entity e, string typeName, string entityName) where T : struct, IComponentData { string filePath = GetFolderPath(typeName, entityName) + typeof(T).Name.ToString() + ".txt"; //Debug.LogError("Saving [" + entityName + "] [" + typeof(T).Name.ToString() + "] to File at: " + filePath); string json; /*if (typeof(BlitzSerializeable<T>) == typeof(T)) * { * BlitzSerializeable<T> component = EntityManager.GetComponentData<BlitzSerializeable<T>>(e); * json = component.GetJson(); * }*/ if (typeof(T) == typeof(Inventory)) { if (EntityManager.HasComponent <Inventory>(e) == false) { Debug.LogError("Character has no inventory.."); json = ""; } else { Inventory component = EntityManager.GetComponentData <Inventory>(e); json = component.GetJson(); } } else if (typeof(T) == typeof(Stats)) { if (World.EntityManager.HasComponent <Stats>(e)) { Stats component = EntityManager.GetComponentData <Stats>(e); json = component.GetJson(); } else { json = ""; } } else if (typeof(T) == typeof(Skills)) { if (World.EntityManager.HasComponent <Skills>(e)) { Skills component = EntityManager.GetComponentData <Skills>(e); json = component.GetJson(); } else { json = ""; } } else if (typeof(T) == typeof(Equipment)) { if (World.EntityManager.HasComponent <Equipment>(e)) { Equipment component = EntityManager.GetComponentData <Equipment>(e); json = component.GetJson(); } else { json = ""; } } else if (typeof(T) == typeof(QuestLog)) { if (World.EntityManager.HasComponent <QuestLog>(e)) { QuestLog component = EntityManager.GetComponentData <QuestLog>(e); json = component.GetJson(); } else { json = ""; } } else { T component = EntityManager.GetComponentData <T>(e); json = ToJson(component); } //Debug.Log("Saving Json to: " + filePath + " of type " + typeof(T).ToString() + "\n" + json); System.IO.File.WriteAllText(filePath, json); }