protected override void OnUpdate() { Entities.WithAll <BulletHitTaker>().ForEach((Entity littlebitchEntity, ref BulletHitTaker littlebitch) => { if (littlebitch.wasHit == 1) { littlebitch.wasHit = 0; Entity bulletEntity = bulletSpawnSystem.bullets[littlebitch.bulletID]; if (World.EntityManager.HasComponent <Bullet>(bulletEntity)) { Bullet bullet = World.EntityManager.GetComponentData <Bullet>(bulletEntity); ZoxID bulletID = World.EntityManager.GetComponentData <ZoxID>(bulletEntity); if (characterSpawnSystem.characters.ContainsKey(bulletID.creatorID)) { Entity attackingCharacter = characterSpawnSystem.characters[bulletID.creatorID]; DamageSystem.AddDamage(World.EntityManager, attackingCharacter, littlebitchEntity, 1, bullet.damage); } else if (TurretSpawnerSystem.turrets.ContainsKey(bulletID.creatorID)) { DamageSystem.AddDamage(World.EntityManager, TurretSpawnerSystem.turrets[bulletID.creatorID], littlebitchEntity, 1, bullet.damage); } else { UnityEngine.Debug.LogError("Character does not exist: " + bulletID.id + " out of " + characterSpawnSystem.characters.Count + " characters."); } // get angle of hit float3 littlebitchPosition = World.EntityManager.GetComponentData <Translation>(littlebitchEntity).Value; float3 bulletPosition = World.EntityManager.GetComponentData <Translation>(bulletEntity).Value; float3 difference = math.normalize(littlebitchPosition - bulletPosition); #if UNITY_EDITOR UnityEngine.Debug.DrawLine(bulletPosition, bulletPosition + difference, UnityEngine.Color.red, 5); #endif // add force to character BodyForce force = World.EntityManager.GetComponentData <BodyForce>(littlebitchEntity); force.acceleration += difference * 1.5f; World.EntityManager.SetComponentData(littlebitchEntity, force); bulletDeathSystem.UseBullet(littlebitch.bulletID); } // else bullet has already been removed } }); }
protected override void OnUpdate() { Entities.WithAll <MeleeAttack, ZoxID, Targeter>().ForEach((Entity e, ref MeleeAttack hitter, ref ZoxID zoxID, ref Targeter targeter) => { if (hitter.didHit == 1) { hitter.didHit = 0; DamageSystem.AddDamage(World.EntityManager, e, targeter.nearbyCharacter.character, 0, hitter.attackDamage); } }); }
public void GiveExperienceToPlayers() { foreach (var player in sys.playerSystemGroup.playerSpawnSystem.controllers.Values) { foreach (var defender in sys.characterSystemGroup.characterSpawnSystem.characters.Values) { if (player.Index != defender.Index) { DamageSystem.AddDamage(EntityManager, player, defender, 0, UnityEngine.Random.Range(1, 12)); //break; } } } }