private void TriggerStatbar(Entity entity, int defenderID) { if (!StatbarSystem.frontBars.ContainsKey(defenderID)) { //Debug.LogError("Spawning healthbar for npc."); statbarSystem.SpawnNPCBar(entity); } if (StatbarSystem.frontBars.ContainsKey(defenderID)) { // also make sure to turn on gui var frontbarEntity = StatbarSystem.frontBars[defenderID]; StatBarUI statBarUI = World.EntityManager.GetComponentData <StatBarUI>(frontbarEntity); if (statBarUI.isTakingDamage == 0) { statBarUI.isTakingDamage = 1; //statBarUI.timeStateChanged = UnityEngine.Time.time; //statBarUI.targetValue = targetValue; World.EntityManager.SetComponentData(frontbarEntity, statBarUI); //Debug.LogError("NPC now taking damage."); //UnityEngine.Debug.LogError("Character " + barIndex + " is now taking damage."); } } else { Debug.LogError("Character does not have a health bar: " + defenderID); } }
protected void UpdateStatbar(Stats stats, Entity character, int stateIndex) { ZoxID zoxID = World.EntityManager.GetComponentData <ZoxID>(character); int characterID = zoxID.id; if (stateIndex != -1) { StateStaz targetStateStat = stats.states[stateIndex]; if (targetStateStat.value == targetStateStat.maxValue) { // new system needed - struct that contains multiple bars, for various state stats if (StatbarSystem.frontBars.ContainsKey(characterID)) { StatBarUI statBarUI = World.EntityManager.GetComponentData <StatBarUI>(StatbarSystem.frontBars[characterID]); if (statBarUI.isTakingDamage == 1) { statBarUI.isTakingDamage = 0; //statBarUI.timeStateChanged = UnityEngine.Time.time; World.EntityManager.SetComponentData(StatbarSystem.frontBars[characterID], statBarUI); } } } //RegenStaz[] regens = stats.regens.ToArray(); // later check for all regens, if the value increase to max //foreach (RegenStaz regen in regens) { //RegenStaz regen = stats.regens[regenIndex]; // get index id /*int targetStatIndex = -1; * for (int i = 0; i < stats.states.Length; i++) * { * if (stats.states[i].id == targetStatIndex) * { * targetStatIndex = i; * break; * } * } */ } } }
private void StartDying(Entity statsEntity, int zoxID) { float3 position = World.EntityManager.GetComponentData <Translation>(statsEntity).Value; if (World.EntityManager.HasComponent <Character>(statsEntity)) { CharacterDatam characterDatam = characterSpawnSystem.meta[World.EntityManager.GetComponentData <Character>(statsEntity).metaID]; for (int i = 0; i < characterDatam.dropItems.Count; i++) { ItemDatam itemToDrop = characterDatam.dropItems[i].GetItem(); itemSpawnSystem.QueueItem(position,// + new float3(UnityEngine.Random.Range(-1f, 1f), 0, UnityEngine.Random.Range(-1f, 1f)), itemToDrop, characterDatam.dropItems[i].GetQuantity()); } } playerSpawnSystem.RemoveControllerCharacter(statsEntity); // game stuff if (World.EntityManager.HasComponent <Skills>(statsEntity)) { World.EntityManager.RemoveComponent <Skills>(statsEntity); } skillsSystem.RemoveSkills(statsEntity); if (World.EntityManager.HasComponent <Stats>(statsEntity)) { World.EntityManager.RemoveComponent <Stats>(statsEntity); } if (World.EntityManager.HasComponent <BulletHitTaker>(statsEntity)) { World.EntityManager.RemoveComponent <BulletHitTaker>(statsEntity); } // movement if (World.EntityManager.HasComponent <Body>(statsEntity)) { World.EntityManager.RemoveComponent <Body>(statsEntity); } if (World.EntityManager.HasComponent <WorldBound>(statsEntity)) { World.EntityManager.RemoveComponent <WorldBound>(statsEntity); } if (World.EntityManager.HasComponent <BodyForce>(statsEntity)) { World.EntityManager.RemoveComponent <BodyForce>(statsEntity); } if (World.EntityManager.HasComponent <BodyTorque>(statsEntity)) { World.EntityManager.RemoveComponent <BodyTorque>(statsEntity); } if (World.EntityManager.HasComponent <BodyInnerForce>(statsEntity)) { World.EntityManager.RemoveComponent <BodyInnerForce>(statsEntity); } // ai if (World.EntityManager.HasComponent <Targeter>(statsEntity)) { World.EntityManager.RemoveComponent <Targeter>(statsEntity); } if (World.EntityManager.HasComponent <Wander>(statsEntity)) { World.EntityManager.RemoveComponent <Wander>(statsEntity); } if (World.EntityManager.HasComponent <Mover>(statsEntity)) { World.EntityManager.RemoveComponent <Mover>(statsEntity); } if (World.EntityManager.HasComponent <AIState>(statsEntity)) { World.EntityManager.RemoveComponent <AIState>(statsEntity); } else { CrosshairSpawnSystem.RemoveUI(World.EntityManager, statsEntity); } // int uiIndex = StatbarSystem.GetListIndex(statsComponent.id); if (StatbarSystem.frontBars.ContainsKey(zoxID)) // if (uiIndex != -1) { Entity characterHealthBar = StatbarSystem.frontBars[zoxID]; StatBarUI statBar1 = World.EntityManager.GetComponentData <StatBarUI>(characterHealthBar); statBar1.isDead = 1; statBar1.targetPercentage = 0; //statBar1.timeStateChanged = UnityEngine.Time.time; World.EntityManager.SetComponentData(characterHealthBar, statBar1); } if (characterSpawnSystem.characters.ContainsKey(zoxID)) { characterSpawnSystem.characters.Remove(zoxID); } World.EntityManager.AddComponentData(statsEntity, new DyingOne { timeOfDeath = UnityEngine.Time.time }); if (TurretSpawnerSystem.bases.ContainsKey(zoxID)) { World.EntityManager.AddComponentData(TurretSpawnerSystem.bases[zoxID], new ScaleLerper { createdTime = UnityEngine.Time.time, lifeTime = deadbodyRemovalTime, scaleBegin = World.EntityManager.GetComponentData <NonUniformScale>(TurretSpawnerSystem.bases[zoxID]).Value, scaleEnd = float3.zero }); } World.EntityManager.AddComponentData(statsEntity, new ScaleLerper { createdTime = UnityEngine.Time.time, lifeTime = deadbodyRemovalTime, scaleBegin = World.EntityManager.GetComponentData <NonUniformScale>(statsEntity).Value, scaleEnd = float3.zero }); }