private void OnModifiedHealthRequest(BaseUnitHealth.ModifyHealth.ReceivedRequest request)
        {
            healthCommandReceiver.SendModifyHealthResponse(new BaseUnitHealth.ModifyHealth.Response(request.RequestId, new Empty()));

            var health = request.Payload.Amount;

            if (CheckAndUpdateHealth(health) == false)
            {
                return;
            }

            var status = statusWriter.Data;

            UnitState state = UnitState.None;

            if (health > 0)
            {
                if (status.State == UnitState.Sleep)
                {
                    state = UnitState.Alive;
                }
            }
            else
            {
                state = UnitState.Dead;
            }

            if (state == UnitState.None)
            {
                return;
            }

            var side = status.Side;

            if (UnitUtils.IsBuilding(status.Type))
            {
                side = UnitSide.None;
            }

            statusWriter.SendUpdate(new BaseUnitStatus.Update()
            {
                State = state,
                Side  = side,
            });

            if (state == UnitState.Dead)
            {
                timerSystem?.AddDeadUnit(SpatialComp.EntityId);
            }
        }
Beispiel #2
0
        private void OnModifiedHealthRequest(BaseUnitHealth.ModifyHealth.ReceivedRequest request)
        {
            healthCommandReceiver.SendModifyHealthResponse(new BaseUnitHealth.ModifyHealth.Response(request.RequestId, new Empty()));

            var health = request.Payload.Amount;

            if (CheckAndUpdateHealth(health) == false)
            {
                return;
            }

            if (health > 0)
            {
                return;
            }

            statusWriter.SendUpdate(new BaseUnitStatus.Update()
            {
                State = UnitState.Dead,
            });

            timerSystem?.AddDeadUnit(SpatialComp.EntityId);
        }