Just some dumb refactoring
This commit is contained in:
parent
46d77d4f89
commit
440a89ffae
|
|
@ -37,6 +37,12 @@ namespace flyff {
|
|||
Recovery = 14,
|
||||
Quest = 25,
|
||||
};
|
||||
|
||||
|
||||
static std::ostream &operator<<(std::ostream &os, const ItemKind2 &kind) {
|
||||
os << "ItemKind2(" << static_cast<unsigned>(kind) << ")";
|
||||
return os;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -80,7 +80,14 @@ namespace flyff {
|
|||
Knuckle = 203,
|
||||
|
||||
Shield = 300,
|
||||
|
||||
HealthPill = 1404
|
||||
};
|
||||
|
||||
static std::ostream &operator<<(std::ostream &os, const ItemKind3 &kind) {
|
||||
os << "ItemKind3(" << static_cast<unsigned>(kind) << ")";
|
||||
return os;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -418,34 +418,36 @@ void on_keyup_hook(int event_type, const EmscriptenKeyboardEvent *event, void *u
|
|||
|
||||
// client.show_announcement("Hello world!", {0xFF, 0, 0});
|
||||
|
||||
std::cout << "Player object ID: " << std::hex << client.player->object_id << std::dec << std::endl;
|
||||
auto current = client.movers.first;
|
||||
do {
|
||||
const auto &mover = current->mover;
|
||||
|
||||
if (mover->type == flyff::ObjectType::Item) {
|
||||
std::cout << "Item "
|
||||
<< std::hex << mover->object_id << std::dec
|
||||
<< " at " << mover->position
|
||||
<< " (" << std::hex << static_cast<u32>(mover) << std::dec << ")"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
current = current->next;
|
||||
} while (current);
|
||||
|
||||
// auto items = client.player->inventory.begin();
|
||||
// std::cout << "Player has " << client.player->get_inventory_slots() << " slots" << std::endl;
|
||||
// for (auto i = 0; i < client.player->get_inventory_slots(); i++) {
|
||||
// if (items[i].property) {
|
||||
// const auto &item = items[i].property;
|
||||
// std::cout << "Player object ID: " << std::hex << client.player->object_id << std::dec << std::endl;
|
||||
// auto current = client.movers.first;
|
||||
// do {
|
||||
// const auto &mover = current->mover;
|
||||
//
|
||||
// std::cout << client.get_text(item->name) << ": "
|
||||
// << reinterpret_cast<const void *>(static_cast<u32>(item)) << ", "
|
||||
// if (mover->type == flyff::ObjectType::Item) {
|
||||
// std::cout << "Item "
|
||||
// << std::hex << mover->object_id << std::dec
|
||||
// << " at " << mover->position
|
||||
// << " (" << std::hex << static_cast<u32>(mover) << std::dec << ")"
|
||||
// << std::endl;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// current = current->next;
|
||||
// } while (current);
|
||||
|
||||
auto items = client.player->inventory.begin();
|
||||
std::cout << "Player has " << client.player->get_inventory_slots() << " slots" << std::endl;
|
||||
for (auto i = 0; i < client.player->get_inventory_slots(); i++) {
|
||||
if (items[i].property) {
|
||||
const auto &item = items[i].property;
|
||||
|
||||
std::cout << client.get_text(item->name) << ": "
|
||||
<< reinterpret_cast<const void *>(static_cast<u32>(item)) << ", "
|
||||
<< "Ik2: " << item->item_kind2 << ", "
|
||||
<< "Ik3: " << item->item_kind3 << ", "
|
||||
<< std::endl;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -578,10 +580,10 @@ void attacker_script() {
|
|||
// attack_target()
|
||||
|
||||
if (neuz.player->get_hp_percent() != 100) {
|
||||
|
||||
auto food_item = flyff::Pointer<flyff::InventoryItem>(nullptr);
|
||||
{
|
||||
auto items = player->inventory.begin();
|
||||
int32_t smallest_difference = std::numeric_limits<int32_t>::max();
|
||||
auto food_item = flyff::Pointer<flyff::InventoryItem>(nullptr);
|
||||
for (auto i = 0; i < player->get_inventory_slots(); i++) {
|
||||
const auto &item_property = items[i].property;
|
||||
if (item_property &&
|
||||
|
|
@ -598,18 +600,51 @@ void attacker_script() {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (food_item) {
|
||||
std::string str = "Eating ";
|
||||
str.append(neuz.get_text(food_item->property->name));
|
||||
str.append(" because it has the smallest difference of ");
|
||||
str.append(std::to_string(smallest_difference));
|
||||
|
||||
neuz.show_message(str);
|
||||
|
||||
client.send_use_item_in_inventory(food_item->index);
|
||||
} else {
|
||||
// HP is not full but no food item found.
|
||||
auto pill_item = flyff::Pointer<flyff::InventoryItem>(nullptr);
|
||||
{
|
||||
auto items = player->inventory.begin();
|
||||
int32_t smallest_difference = std::numeric_limits<int32_t>::max();
|
||||
for (auto i = 0; i < player->get_inventory_slots(); i++) {
|
||||
const auto &item_property = items[i].property;
|
||||
if (item_property &&
|
||||
player->can_use_item(item_property) &&
|
||||
item_property->item_kind3 == flyff::ItemKind3::HealthPill) {
|
||||
auto hp = client.player->get_hp();
|
||||
auto max_hp = client.player->get_max_hp();
|
||||
// How much HP is left over after healing with this item.
|
||||
int32_t difference = max_hp - (hp + item_property->heal_hp);
|
||||
|
||||
if (difference >= 0 && std::abs(difference) < std::abs(smallest_difference)) {
|
||||
pill_item = flyff::Pointer<flyff::InventoryItem>(&items[i]);
|
||||
smallest_difference = difference;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(pill_item) {
|
||||
std::string str = "Eating ";
|
||||
str.append(neuz.get_text(pill_item->property->name));
|
||||
str.append(" because food item was not ready.");
|
||||
|
||||
neuz.show_message(str);
|
||||
|
||||
client.send_use_item_in_inventory(pill_item->index);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (neuz.player->get_move_state() == flyff::Object::MoveState::Stand &&
|
||||
!neuz.player->is_attacking()) {
|
||||
|
|
|
|||
|
|
@ -274,7 +274,8 @@ WASM_IMPORT_IMPL(env, _glUniform3fv) = [](u32 a, u32 b, u32 c) {
|
|||
|
||||
/* import: 'a' 'K' */
|
||||
// "K": "_glTexImage2D",
|
||||
WASM_IMPORT_IMPL(env, _glTexImage2D) = [](u32 target, u32 level, u32 internalformat, u32 d, u32 e, u32 f, u32 g, u32 h, u32 i) {
|
||||
WASM_IMPORT_IMPL(env, _glTexImage2D) = [](u32 target, u32 level, u32 internalformat, u32 d, u32 e, u32 f, u32 g, u32 h,
|
||||
u32 i) {
|
||||
const auto &pixels = fugg::ModulePointer<const void>(i);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
|
|
@ -788,7 +789,8 @@ WASM_IMPORT_IMPL(env, _glUniform4f) = [](u32 a, f32 b, f32 c, f32 d, f32 e) {
|
|||
};
|
||||
/* import: 'a' 'lb' */
|
||||
// "lb": "_glCompressedTexImage2D",
|
||||
WASM_IMPORT_IMPL(env, _glCompressedTexImage2D) = [](u32 target, u32 level, u32 internalformat, u32 width, u32 height, u32 border, u32 image_size, u32 h) {
|
||||
WASM_IMPORT_IMPL(env, _glCompressedTexImage2D) = [](u32 target, u32 level, u32 internalformat, u32 width, u32 height,
|
||||
u32 border, u32 image_size, u32 h) {
|
||||
const auto &data = fugg::ModulePointer<const void>(h);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
|
|
@ -1155,7 +1157,8 @@ WASM_IMPORT_IMPL(env, _emscripten_webgl_create_context) = [](u32 a, u32 b) {
|
|||
#endif
|
||||
|
||||
auto attr = static_cast<const EmscriptenWebGLContextAttributes *>(attributes);
|
||||
std::cout << "Trying to create a context with version " << attr->majorVersion << "." << attr->minorVersion << std::endl;
|
||||
std::cout << "Trying to create a context with version " << attr->majorVersion << "." << attr->minorVersion
|
||||
<< std::endl;
|
||||
|
||||
return static_cast<u32>(
|
||||
emscripten_webgl_create_context(target, attributes)
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
#include <wasm-rt.h>
|
||||
#include <client.h>
|
||||
#include <fugg.h>
|
||||
#include <flyff.h>
|
||||
|
||||
#include <emscripten/bind.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
|
||||
#include "embind.h"
|
||||
|
||||
|
|
@ -24,7 +26,7 @@ void platform_text_edited_hook(u32 ptr, u32 selection_start, u32 selection_end)
|
|||
}
|
||||
|
||||
void platform_got_devicemotion_permission_hook() {
|
||||
using PlatformGotDeviceMotionPermissionFn = void (*)(void);
|
||||
using PlatformGotDeviceMotionPermissionFn = void (*)();
|
||||
auto platform_got_devicemotion_permission = fugg::function_ref<PlatformGotDeviceMotionPermissionFn>(
|
||||
fugg::embind::kFunctionMap["platform_got_devicemotion_permission"]->fn
|
||||
);
|
||||
|
|
@ -32,13 +34,13 @@ void platform_got_devicemotion_permission_hook() {
|
|||
platform_got_devicemotion_permission();
|
||||
}
|
||||
|
||||
void platform_captcha_completed_hook(std::string token) {
|
||||
void platform_captcha_completed_hook(const std::string& token) {
|
||||
struct WireType {
|
||||
size_t length;
|
||||
char data[1];
|
||||
};
|
||||
|
||||
WireType* wt = (WireType*)malloc(sizeof(size_t) + token.length());
|
||||
auto* wt = (WireType*)malloc(sizeof(size_t) + token.length());
|
||||
wt->length = token.length();
|
||||
memcpy(wt->data, token.data(), token.length());
|
||||
|
||||
|
|
@ -57,7 +59,6 @@ void platform_captcha_completed_hook(std::string token) {
|
|||
platform_captcha_completed,
|
||||
fugg::RuntimePointer<WireType>(wt)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
using PlatformWebsocketFn = void (*)(emscripten::val event);
|
||||
|
|
@ -69,7 +70,7 @@ void platform_websocket_open_hook(emscripten::val event) {
|
|||
fugg::embind::kFunctionMap["platform_websocket_open"]->fn
|
||||
);
|
||||
|
||||
platform_websocket_open(event);
|
||||
platform_websocket_open(std::move(event));
|
||||
}
|
||||
|
||||
void platform_websocket_close_hook(emscripten::val event) {
|
||||
|
|
@ -79,10 +80,10 @@ void platform_websocket_close_hook(emscripten::val event) {
|
|||
fugg::embind::kFunctionMap["platform_websocket_close"]->fn
|
||||
);
|
||||
|
||||
platform_websocket_close(event);
|
||||
platform_websocket_close(std::move(event));
|
||||
}
|
||||
|
||||
void platform_websocket_message_hook(emscripten::val event) {
|
||||
void platform_websocket_message_hook(const emscripten::val& event) {
|
||||
// std::cout << "platform_websocket_message: Got " << event["data"]["byteLength"].as<unsigned long>() << " bytes" << std::endl;
|
||||
|
||||
struct Test {
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ void free(void *ptr_) {
|
|||
emscripten_builtin_free(ptr_);
|
||||
|
||||
#if TRACE_ALLOC
|
||||
std::cout << "FUGG: Free'd OUTSIDE pointer at " << reinterpret_cast<void*>(ptr) << std::endl;
|
||||
std::cout << "FUGG: Free'd OUTSIDE pointer at " << reinterpret_cast<void*>(ptr_) << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in New Issue