Repository navigation
Expand file tree
/
Copy pathPickableArrowsCore.cpp
More file actions
151 lines (118 loc) · 5.97 KB
/
Copy pathPickableArrowsCore.cpp
File metadata and controls
151 lines (118 loc) · 5.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Supported with union (c) 2018-2021 Union team
// Union SOURCE file
namespace GOTHIC_ENGINE {
bool PickableArrowsCore::enabled = true;
float PickableArrowsCore::groundRecoveryChance = 1.0f; // 100% domyślnie
float PickableArrowsCore::npcRecoveryChance = 1.0f; // 100% domyślnie
bool PickableArrowsCore::allowNpcInventoryPickup = true;
bool PickableArrowsCore::allowGroundPickup = true;
bool PickableArrowsCore::chanceDependsOnSkills = false;
bool PickableArrowsCore::requireDamageForNpcRecovery = true;
void PickableArrowsCore::Init() {
ReadOptions();
srand((unsigned int)time(NULL));
}
int PickableArrowsCore::GetBestRangedSkill() {
if (!player) return 100;
oCNpc* hero = player;
if (!hero) return 100;
#if ENGINE == Engine_G1 || ENGINE == Engine_G1A
int bowPercent = hero->GetTalentValue(oCNpcTalent::NPC_TAL_BOW);
int crossbowPercent = hero->GetTalentValue(oCNpcTalent::NPC_TAL_CROSSBOW);
return max(bowPercent, crossbowPercent);
#else
int effectiveBow = hero->hitChance[NPC_HITCHANCE_BOW];
int effectiveXbow = hero->hitChance[NPC_HITCHANCE_CROSSBOW];
return max(effectiveBow, effectiveXbow);
#endif
}
void PickableArrowsCore::ReadOptions() {
if (!zoptions) return;
enabled = zoptions->ReadBool("PICKABLE_ARROWS", "Enabled", true);
chanceDependsOnSkills = zoptions->ReadBool("PICKABLE_ARROWS", "ChanceDependsOnSkills", false);
int groundIndex = zoptions->ReadInt("PICKABLE_ARROWS", "GroundRecoveryChance", 100);
int npcIndex = zoptions->ReadInt("PICKABLE_ARROWS", "NpcRecoveryChance", 100);
groundRecoveryChance = (float)groundIndex / 100.0f;
npcRecoveryChance = (float)npcIndex / 100.0f;
allowNpcInventoryPickup = zoptions->ReadBool("PICKABLE_ARROWS", "AllowNpcInventoryPickup", true);
allowGroundPickup = zoptions->ReadBool("PICKABLE_ARROWS", "AllowGroundPickup", true);
requireDamageForNpcRecovery = zoptions->ReadBool("PICKABLE_ARROWS", "RequireDamageForNpcRecovery", true);
if (groundRecoveryChance < 0.0f) groundRecoveryChance = 0.0f;
if (groundRecoveryChance > 1.0f) groundRecoveryChance = 1.0f;
if (npcRecoveryChance < 0.0f) npcRecoveryChance = 0.0f;
if (npcRecoveryChance > 1.0f) npcRecoveryChance = 1.0f;
}
bool PickableArrowsCore::IsArrowOrBolt(oCItem* item) {
if (!item) return false;
if (item->mainflag == ITM_CAT_MUN) {
if ((item->flags & ITM_FLAG_BOW) || (item->flags & ITM_FLAG_CROSSBOW)) {
return true;
}
}
return false;
}
void PickableArrowsCore::UpdateMenuItem(const char* itemName, const char* value) {
zSTRING itemNameStr = itemName;
zCMenuItem* menuItem = zCMenuItem::GetByName(itemNameStr);
if (menuItem) {
zSTRING valueStr = value;
menuItem->SetText(valueStr, 0, TRUE);
}
}
void PickableArrowsCore::SetMenuItemEnabled(const char* itemName, bool enabled) {
zSTRING itemNameStr = itemName;
zCMenuItem* menuItem = zCMenuItem::GetByName(itemNameStr);
if (menuItem) {
if (enabled) {
menuItem->flags |= IT_SELECTABLE;
} else {
menuItem->flags &= ~IT_SELECTABLE;
}
}
}
void PickableArrowsCore::UpdateMenu() {
zCMenu* activeMenu = zCMenu::GetActive();
if (!activeMenu) return;
zSTRING menuName = activeMenu->name;
if (menuName != "PickableArrows:Menu_Opt_PickableArrows") return;
if (chanceDependsOnSkills && player) {
int skill = GetBestRangedSkill();
if (skill > 100) skill = 100;
if (skill < 0) skill = 0;
int menuIndex = skill;
zCMenuItem* groundSlider = zCMenuItem::GetByName("PickableArrows:MenuItem_Opt_PickableArrows_GroundRecoveryChance_Slider");
zCMenuItem* npcSlider = zCMenuItem::GetByName("PickableArrows:MenuItem_Opt_PickableArrows_NpcRecoveryChance_Slider");
if (groundSlider && groundSlider->m_parType == MENU_ITEM_CHOICEBOX) {
zCMenuItemChoice* choice = (zCMenuItemChoice*)groundSlider;
choice->option = menuIndex;
}
if (npcSlider && npcSlider->m_parType == MENU_ITEM_CHOICEBOX) {
zCMenuItemChoice* choice = (zCMenuItemChoice*)npcSlider;
choice->option = menuIndex;
}
if (zoptions) {
zSTRING indexStr = zSTRING(menuIndex);
zoptions->WriteString("PICKABLE_ARROWS", "GroundRecoveryChance", indexStr, FALSE);
zoptions->WriteString("PICKABLE_ARROWS", "NpcRecoveryChance", indexStr, FALSE);
}
}
}
void PickableArrowsCore::ResetChanceSliders() {
groundRecoveryChance = 1.0f;
npcRecoveryChance = 1.0f;
zCMenuItem* groundSlider = zCMenuItem::GetByName("PickableArrows:MenuItem_Opt_PickableArrows_GroundRecoveryChance_Slider");
zCMenuItem* npcSlider = zCMenuItem::GetByName("PickableArrows:MenuItem_Opt_PickableArrows_NpcRecoveryChance_Slider");
if (groundSlider && groundSlider->m_parType == MENU_ITEM_CHOICEBOX) {
zCMenuItemChoice* choice = (zCMenuItemChoice*)groundSlider;
choice->option = 100;
}
if (npcSlider && npcSlider->m_parType == MENU_ITEM_CHOICEBOX) {
zCMenuItemChoice* choice = (zCMenuItemChoice*)npcSlider;
choice->option = 100;
}
if (zoptions) {
zoptions->WriteString("PICKABLE_ARROWS", "GroundRecoveryChance", "100", TRUE);
zoptions->WriteString("PICKABLE_ARROWS", "NpcRecoveryChance", "100", TRUE);
}
}
}