public void Initialize(Unity.Entities.World space) { //regenStartSystem = space.GetOrCreateSystem<RegenStartSystem>(); regenSystem = space.GetOrCreateSystem <RegenSystem>(); regenCompleterSystem = space.GetOrCreateSystem <RegenCompleterSystem>(); levelUpSystem = space.GetOrCreateSystem <LevelUpSystem>(); levelUpEffectsSystem = space.GetOrCreateSystem <LevelUpEffectsSystem>(); attributesSystem = space.GetOrCreateSystem <AttributesSystem>(); //AddSystemToUpdateList(regenStartSystem); AddSystemToUpdateList(regenSystem); AddSystemToUpdateList(regenCompleterSystem); AddSystemToUpdateList(levelUpSystem); AddSystemToUpdateList(levelUpEffectsSystem); AddSystemToUpdateList(attributesSystem); statUpdateSystem = space.GetOrCreateSystem <StatUpdateSystem>(); AddSystemToUpdateList(statUpdateSystem); SetLinks(); }
private void ApplyDamage(Entity attacker, Entity defender, float damageDone) { // now get components if (!(World.EntityManager.HasComponent <Stats>(attacker) && World.EntityManager.HasComponent <Stats>(defender))) { return; } ZoxID defenderID = World.EntityManager.GetComponentData <ZoxID>(defender); Stats defenderStats = World.EntityManager.GetComponentData <Stats>(defender); ZoxID attackerID = World.EntityManager.GetComponentData <ZoxID>(attacker); Stats attackerStats = World.EntityManager.GetComponentData <Stats>(attacker); Translation defenderTranslation = World.EntityManager.GetComponentData <Translation>(defender); int healthIndex = 0; // decrease health if (defenderStats.states.Length == 0) { return; // cannot apply damage to gods } StateStaz healthStat = defenderStats.states[healthIndex]; if (damageDone > 0 && healthStat.IsMaxValue()) { // add regening to them RegenCompleterSystem.StartRegening(World.EntityManager, defender); } healthStat.value -= damageDone; //Debug.Log("Damage done: " + damageDone + " to " + defender.Index // + " - " + defenderStats.states[0].value + " out of " + defenderStats.states[0].maxValue); if (healthStat.value < 0) { healthStat.value = 0; } defenderStats.states[healthIndex] = healthStat; // health pop up here damagePopupSystem.SpawnPopup(damageDone, defenderTranslation.Value); // Death if (healthStat.value == 0)// && defenderStats.isDead == 0) { //Debug.LogError("Defender ID has died: " + defender.Index + " at " + UnityEngine.Time.time); // Give rewards to Victor int metaID = 0; if (World.EntityManager.HasComponent <Character>(defender)) { metaID = World.EntityManager.GetComponentData <Character>(defender).metaID; } RewardVictor(ref defenderStats, attacker, ref attackerStats, defenderID.clanID, metaID); defenderStats.willDie = 1; //defenderStats.timeDied = UnityEngine.Time.time; // Spawn Item //body.velocity = float3.zero; // give xp to attacker } else { // Attack back! RespondToAttack(defender, attacker); TriggerStatbar(defender, defenderID.id); } World.EntityManager.SetComponentData(defender, defenderStats); }