Skip to content

Commit d8155bd

Browse files
Fix scaling issues
1 parent 974c749 commit d8155bd

File tree

4 files changed

+69
-32
lines changed

4 files changed

+69
-32
lines changed

main.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,18 @@ class Mod : GenericMod {
235235
if (attacker->entity_data.hostility_type == cube::Creature::EntityBehaviour::Player ||
236236
attacker->entity_data.hostility_type == cube::Creature::EntityBehaviour::Pet)
237237
{
238-
int xp_gain = 100;
238+
int level = GetCreatureLevel(creature) + 1;
239+
int stars = creature->entity_data.level + 1;
240+
const static float multiplier = 1.0f / (LEVELS_PER_REGION + 1.0f);
241+
cube::Creature* player = game->GetPlayer();
242+
243+
int xp_gain = 100 * stars;
239244

240245
if (player->entity_data.level > GetCreatureLevel(creature)) {
241-
xp_gain = (int)std::roundf(100 * (creature->entity_data.level + 1) * std::powf(0.8f, player->entity_data.level - GetCreatureLevel(creature)));
246+
xp_gain *= std::pow((float)level / (float)player->entity_data.level, 3);
242247
}
243248
else {
244-
xp_gain = (int)std::roundf(100 * (creature->entity_data.level + 1) * (1 + 0.15f * (GetCreatureLevel(creature) - player->entity_data.level)) * std::powf(1.05f, GetCreatureLevel(creature) - player->entity_data.level));
249+
xp_gain *= (1 + multiplier * (GetCreatureLevel(creature) - player->entity_data.level)) * std::powf(1.05f, GetCreatureLevel(creature) - player->entity_data.level);
245250
}
246251

247252
if ((creature->entity_data.appearance.flags2 & (1 << (int)cube::Creature::AppearanceModifiers::IsBoss)) != 0)
@@ -355,8 +360,8 @@ class Mod : GenericMod {
355360
// ##### CREATURE ######
356361
// Defense
357362
m_CreatureScaling.insert_or_assign(STAT_TYPE::HEALTH, 0.9);
358-
m_CreatureScaling.insert_or_assign(STAT_TYPE::ARMOR, 0.7);
359-
m_CreatureScaling.insert_or_assign(STAT_TYPE::RESISTANCE, 0.7);
363+
m_CreatureScaling.insert_or_assign(STAT_TYPE::ARMOR, 0.01);
364+
m_CreatureScaling.insert_or_assign(STAT_TYPE::RESISTANCE, 0.01);
360365

361366
// Offense
362367
m_CreatureScaling.insert_or_assign(STAT_TYPE::ATK_POWER, 0.8);
@@ -399,7 +404,7 @@ class Mod : GenericMod {
399404
if (creature->entity_data.hostility_type != cube::Creature::EntityBehaviour::Player &&
400405
creature->entity_data.hostility_type != cube::Creature::EntityBehaviour::Pet)
401406
{
402-
*stat *= m_CreatureScaling.at(type) * 0.5 * std::pow(2.7183, 0.2 * GetCreatureLevel(creature)) / 1.21 * std::pow(0.99, 1 + 0.07 * GetCreatureLevel(creature) * GetCreatureLevel(creature));
407+
*stat *= m_CreatureScaling.at(type) * (1 + log2f((GetCreatureLevel(creature) + 1001.0f) / 1000.0f) * 1000.0f);
403408

404409
}
405410
}
@@ -429,6 +434,12 @@ class Mod : GenericMod {
429434
}
430435

431436
virtual void OnCreatureHPCalculated(cube::Creature* creature, float* hp) override {
437+
438+
if (creature->entity_data.hostility_type != cube::Creature::EntityBehaviour::Player)
439+
{
440+
SetEquipmentRegion(creature, creature->entity_data.current_region);
441+
}
442+
432443
ApplyStatBuff(creature, hp, STAT_TYPE::HEALTH);
433444
ApplyCreatureBuff(creature, hp, STAT_TYPE::HEALTH);
434445
}

src/GearScalingOverWrite.h

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,22 @@ extern "C" float GetGearScaling(cube::Item * item, cube::Creature* creature, int
2222

2323
int effective_rarity = item->GetEffectiveRarity(&region);
2424
float base_res = ((base * 0.5f) / (float)0x20);
25-
float mod_modifier = (mod3 / 0x10624DD3) / 7.0f;
25+
float mod_modifier = (mod3 / 0x10624DD3) / 8.0f;
2626

2727
float X = 1.4;
28-
float Y = base_res + effective_rarity + mod_modifier;
2928

30-
float result = std::powf(X, Y);
29+
float result = X + base_res + mod_modifier;
3130

3231
cube::Game* game = cube::GetGame();
3332
if (game && creature->entity_data.hostility_type == cube::Creature::EntityBehaviour::Player)
3433
{
35-
result *= 0.5 * std::pow(2.7183, 0.2 * GetItemLevel(item)) / 1.21 * std::pow(0.99, 1 + 0.07 * GetItemLevel(item) * GetItemLevel(item));
34+
result *= 1 + log2f((GetItemLevel(item) + 0.5f * effective_rarity + 1001.0f) / 1000.0f) * 1000.0f;
35+
}
36+
else if (creature->entity_data.hostility_type == cube::Creature::EntityBehaviour::Hostile)
37+
{
38+
result *= 0.1f * (effective_rarity + 1);
3639
}
40+
3741
return result;
3842
}
3943

@@ -64,37 +68,50 @@ extern "C" float GetOtherStatsRe(cube::Item * item, cube::Creature * creature)
6468

6569
float result = std::powf(X, Y);
6670

67-
68-
result *= 0.01f + 0.0016f * GetItemLevel(item);
69-
if (result > 0.2f) {
70-
result = std::log2f(result/0.2f)*0.2f + 0.2f;
71-
result *= randomizer;
71+
cube::Game* game = cube::GetGame();
72+
if (game && creature->entity_data.hostility_type == cube::Creature::EntityBehaviour::Player)
73+
{
74+
result *= 0.01f + 0.0016f * GetItemLevel(item);
75+
if (result > 0.2f) {
76+
result = std::log2f(result / 0.2f) * 0.2f + 0.2f;
77+
result *= randomizer;
78+
}
7279
}
80+
return result;
81+
}
7382

7483

75-
84+
extern "C" float GetHasteRe(cube::Item * item, cube::Creature * creature) {
7685
int category = item->category;
7786

7887
if (category < 3 || category > 9)
7988
{
80-
result *= 0;
89+
return 0;
8190
}
8291

83-
84-
return result;
92+
return GetOtherStatsRe(item, creature) * (PyroRand(item->modifier) / 32768.0f);
8593
}
8694

95+
extern "C" float GetRegenRe(cube::Item * item, cube::Creature * creature) {
96+
int category = item->category;
8797

88-
extern "C" float GetHasteRe(cube::Item * item, cube::Creature * creature) {
89-
return GetOtherStatsRe(item, creature) * PyroRand(item->modifier + 0x157) / 32768;
90-
}
98+
if ((category < 4 || category > 9) && category != 26)
99+
{
100+
return 0;
101+
}
91102

92-
extern "C" float GetRegenRe(cube::Item * item, cube::Creature * creature) {
93-
return GetOtherStatsRe(item, creature) * PyroRand(item->GetSellingPrice() + 0x159) / 32768;
103+
return GetOtherStatsRe(item, creature) * (PyroRand(item->modifier + 0x157) / 32768.0f);
94104
}
95105

96106
extern "C" float GetCritRe(cube::Item * item, cube::Creature * creature) {
97-
return GetOtherStatsRe(item, creature) * PyroRand(item->GetBuyingPrice() + 0x161) / 32768;
107+
int category = item->category;
108+
109+
if (category < 3 || category > 10)
110+
{
111+
return 0;
112+
}
113+
114+
return GetOtherStatsRe(item, creature) * (PyroRand(item->modifier + 0x99) / 32768.0f);
98115
}
99116

100117
extern "C" float GearScaling(float x, float y, cube::Item* item)

src/utility.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,24 @@ int GetItemLevel(cube::Item* item)
2929

3030
int res = 1 + LEVELS_PER_REGION * GetRegionDistance(item->region) + GetLevelVariation(item->modifier, LEVELS_PER_REGION);
3131

32-
if (res > 333) {
33-
res = 333;
34-
}
35-
3632
return res;
3733
}
3834

35+
void SetEquipmentRegion(cube::Creature* creature, IntVector2 region)
36+
{
37+
cube::Equipment* equipment = &creature->entity_data.equipment;
38+
equipment->chest.region = region;
39+
equipment->hands.region = region;
40+
equipment->feet.region = region;
41+
equipment->neck.region = region;
42+
equipment->pet.region = region;
43+
equipment->ring_left.region = region;
44+
equipment->ring_right.region = region;
45+
equipment->weapon_left.region = region;
46+
equipment->weapon_right.region = region;
47+
equipment->shoulder.region = region;
48+
}
49+
3950
int GetCreatureLevel(cube::Creature* creature)
4051
{
4152
cube::Game* game = cube::GetGame();
@@ -66,9 +77,6 @@ int GetCreatureLevel(cube::Creature* creature)
6677
//return (1 + 5 * distance) + GetLevelVariation(creature->entity_data.race * distance, 5);
6778

6879
int res = (1 + LEVELS_PER_REGION * distance) + GetLevelVariation(creature->id, LEVELS_PER_REGION);
69-
if (res > 333) {
70-
res = 333;
71-
}
7280

7381

7482
return res;

src/utility.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ int GetRegionDistance(IntVector2 region);
88
int GetItemLevel(cube::Item* item);
99
int GetCreatureLevel(cube::Creature* creature);
1010
int GetLevelVariation(long long modifier, int range);
11+
void SetEquipmentRegion(cube::Creature* creature, IntVector2 region);
1112

1213
unsigned long long PyroRand(unsigned long long seed);

0 commit comments

Comments
 (0)