potion.cpp 859 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright (c) 2022-2023 the Dviglo project
  2. // Copyright (c) 2008-2023 the Urho3D project
  3. // License: MIT
  4. #include "potion.h"
  5. namespace Urho3D
  6. {
  7. static constexpr int POTION_HEAL_AMOUNT = 5;
  8. void Potion::RegisterObject(Context* context)
  9. {
  10. context->RegisterFactory<Potion>();
  11. }
  12. Potion::Potion(Context* context)
  13. : GameObject(context)
  14. {
  15. healAmount = POTION_HEAL_AMOUNT;
  16. }
  17. void Potion::Start()
  18. {
  19. SubscribeToEvent(node_, E_NODECOLLISION, URHO3D_HANDLER(Potion, HandleNodeCollision));
  20. }
  21. void Potion::ObjectCollision(GameObject& otherObject, VariantMap& eventData)
  22. {
  23. if (healAmount > 0)
  24. {
  25. if (otherObject.Heal(healAmount))
  26. {
  27. // Could also remove the potion directly, but this way it gets removed on next update
  28. healAmount = 0;
  29. duration = 0;
  30. }
  31. }
  32. }
  33. } // namespace Urho3D