Exemple #1
0
    public static DataChangeEvent Serdes(DataChangeEvent e, AssetMapping mapping, ISerializer s)
    {
        if (s == null)
        {
            throw new ArgumentNullException(nameof(s));
        }
        if (s.IsWriting() && e == null)
        {
            throw new ArgumentNullException(nameof(e));
        }

        ChangeProperty property = s.EnumU8(nameof(ChangeProperty), e?.ChangeProperty ?? ChangeProperty.Unk0);

        return(property switch
        {
            ChangeProperty.Unk0 => ChangeUnk0Event.Serdes((ChangeUnk0Event)e, s),
            ChangeProperty.Health => ChangeHealthEvent.Serdes((ChangeHealthEvent)e, mapping, s),
            ChangeProperty.Mana => ChangeManaEvent.Serdes((ChangeManaEvent)e, mapping, s),
            ChangeProperty.Status => ChangeStatusEvent.Serdes((ChangeStatusEvent)e, mapping, s),
            ChangeProperty.Language => ChangeLanguageEvent.Serdes((ChangeLanguageEvent)e, mapping, s),
            ChangeProperty.Experience => ChangeExperienceEvent.Serdes((ChangeExperienceEvent)e, mapping, s),
            ChangeProperty.UnkB => ChangeUnkBEvent.Serdes((ChangeUnkBEvent)e, s),
            ChangeProperty.UnkC => ChangeUnkCEvent.Serdes((ChangeUnkCEvent)e, s),
            ChangeProperty.Item => ChangeItemEvent.Serdes((ChangeItemEvent)e, mapping, s),
            ChangeProperty.Gold => ChangeGoldEvent.Serdes((ChangeGoldEvent)e, mapping, s),
            ChangeProperty.Food => ChangeFoodEvent.Serdes((ChangeFoodEvent)e, mapping, s),
            _ => throw new FormatException($"Unexpected data change type \"{property}\"")
        });
Exemple #2
0
 private void OnChangeHealthEvent(ChangeHealthEvent e)
 {
     if (e.Defender.gameObject == gameObject)
     {
         TakeDamage(e.Damage);
     }
 }
 public void Damage(float damage)
 {
     Currenthealth -= damage;
     if (Currenthealth <= 0)
     {
         DieEvent?.Invoke();
     }
     ChangeHealthEvent?.Invoke(Currenthealth);
 }
        public void Damage(float value)
        {
            _health = Mathf.Max(0f, _health - value);

            ChangeHealthEvent?.Invoke(_health);

            if (_health > 0f)
            {
                return;
            }

            DieEvent?.Invoke();
        }
    public static ChangeHealthEvent Serdes(ChangeHealthEvent e, AssetMapping mapping, ISerializer s)
    {
        if (s == null)
        {
            throw new ArgumentNullException(nameof(s));
        }
        e ??= new ChangeHealthEvent();
        e.Operation = s.EnumU8(nameof(Operation), e.Operation);
        e.Unk3      = s.UInt8(nameof(Unk3), e.Unk3);
        int zeroed = s.UInt8(null, 0);

        s.Assert(zeroed == 0, "ChangeHealthEvent: Expected byte 4 to be 0");
        e.PartyMemberId = PartyMemberId.SerdesU8(nameof(PartyMemberId), e.PartyMemberId, mapping, s);
        e.Unk6          = s.UInt16(nameof(Unk6), e.Unk6);
        e.Amount        = s.UInt16(nameof(Amount), e.Amount);
        s.Assert(zeroed == 0, "ChangeHealthEvent: Expected word 6 to be 0");
        return(e);
    }
 private void OnEnable()
 {
     _health = _defaultHealth;
     ChangeHealthEvent?.Invoke(_health);
 }
Exemple #7
0
 private void OnDisable()
 {
     onChangeHealth -= ChangeHealthUI;
 }
Exemple #8
0
 void Start()
 {
     onChangeHealth += ChangeHealthUI;
 }