Skip to content

Commit

Permalink
fix add_money
Browse files Browse the repository at this point in the history
  • Loading branch information
Dregu committed Oct 5, 2023
1 parent 9f4b8dd commit 16e3205
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/game_api/movable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class Movable : public Entity
virtual void drop(Entity* entity_to_drop) = 0; // 69, also used when throwing

/// Adds or subtracts the specified amount of money to the movable's (player's) inventory. Shows the calculation animation in the HUD.
virtual void add_money(uint32_t money) = 0; // 70
virtual void add_money(uint32_t money, ENT_TYPE money_type) = 0; // 70
virtual void apply_movement() = 0; // 71, disable this function and things can't move, some spin in place
virtual void damage_entity(Entity* victim) = 0; // 72, can't trigger, maybe extra params are needed
virtual void v73() = 0; // 73
Expand Down
12 changes: 10 additions & 2 deletions src/game_api/script/usertypes/entity_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

#include "color.hpp" // for Color, Color::a, Color::b, Color::g
#include "custom_types.hpp" // for get_custom_types_map
#include "entities_chars.hpp" // for Player
#include "entity.hpp" // for Entity, EntityDB, Animation, Rect
#include "items.hpp" // for Inventory
#include "math.hpp" // for Quad, AABB
#include "movable.hpp" // for Movable, Movable::falling_timer
#include "render_api.hpp" // for RenderInfo, RenderInfo::flip_horiz...
Expand Down Expand Up @@ -283,7 +285,13 @@ void register_usertypes(sol::state& lua)
auto light_on_fire = sol::overload(
static_cast<void (Movable::*)()>(&Movable::light_on_fire_broken),
static_cast<void (Movable::*)(uint8_t)>(&Movable::light_on_fire));

auto add_money = sol::overload(
[](Player& ent, uint32_t money)
{
ent.add_money(money, 0);
ent.inventory_ptr->collected_money_count--;
},
&Movable::add_money);
auto movable_type = lua.new_usertype<Movable>("Movable", sol::base_classes, sol::bases<Entity>());
movable_type["move"] = &Movable::move;
movable_type["movex"] = &Movable::movex;
Expand Down Expand Up @@ -332,7 +340,7 @@ void register_usertypes(sol::state& lua)
movable_type["pick_up"] = &Movable::pick_up;
movable_type["can_jump"] = &Movable::can_jump;
movable_type["standing_on"] = &Movable::standing_on;
movable_type["add_money"] = &Movable::add_money;
movable_type["add_money"] = add_money;
movable_type["is_on_fire"] = &Movable::is_on_fire;
movable_type["damage"] = damage;
movable_type["get_all_behaviors"] = &Movable::get_all_behaviors;
Expand Down

0 comments on commit 16e3205

Please sign in to comment.