public void Update() { var mapData = Game.I.MapController.MapDatas; foreach (var pair in _components) { if (_toDelete.Contains(pair.Key)) { return; } var component = pair.Value; if (component.IsExloding) { foreach (var point in component.Range) { var id = mapData[point.X][point.Y].EntityId; if (id != null) { var toDamage = Game.I.EntityManager.GetEntity(id.Value); var mc = toDamage.GetEcsComponent <MovementComponent>(); var msg = new TakeDamageMsg(id.Value, 2); if (mc.IsMoving) { mc.OnEndMoving += () => Game.I.Messages.SendEvent(msg); } else { Game.I.Messages.SendEvent(msg); } } } var entity = Game.I.EntityManager.GetEntity(pair.Key); Game.I.EntityManager.DestroyEntity(pair.Key); Object.Destroy(entity.gameObject); } else { var entity = Game.I.EntityManager.GetEntity(pair.Key); var target = Game.I.MapController.GetTileWorldPosition(component.Target); entity.transform.DOMove(target, Utils.MovementSpeed).SetEase(Ease.Linear).OnComplete(OnMoveComplete); component.IsExloding = true; } } foreach (var i in _toDelete) { _components.Remove(i); } _toDelete.Clear(); }
private void MakeShoot(TakeDamageMsg msg) { var target = Game.I.EntityManager.GetEntity(msg.EntityId); if (target != null) { var mc = target.GetEcsComponent <MovementComponent>(); if (mc.IsMoving) { mc.OnEndMoving += () => Game.I.Messages.SendEvent(msg); } else { Game.I.Messages.SendEvent(msg); } } }
private void OnTakeDamageMsg(TakeDamageMsg msg) { var id = msg.EntityId; var hc = _components[id]; --hc.CurrentHealth; if (hc.CurrentHealth <= 0) { _views[id].PlayDeath(); Game.I.EntityManager.DestroyEntity(id); } else { var view = _views[id]; view.SetHealth((float)hc.CurrentHealth / hc.MaxHealth); } }