Skip to content

Commit e7bd9d7

Browse files
committed
make notplayer not shoot when in kick mode, unless with tp wand, have notplayer use tp wand, fix a bunch of notplayer oddities
1 parent 2903311 commit e7bd9d7

File tree

3 files changed

+45
-22
lines changed

3 files changed

+45
-22
lines changed

noita-proxy/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,14 +1545,12 @@ impl eframe::App for App {
15451545
});
15461546
}
15471547
AppState::LangPick => {
1548-
//had to move arg check here because in new() i cannot access app_saved_state
1549-
if let Some(lang) = &self.args.language
1550-
{
1548+
if let Some(lang) = &self.args.language {
15511549
let li: LanguageIdentifier = lang.parse().unwrap();
15521550
self.app_saved_state.lang_id = Some(li.clone());
15531551
set_current_locale(li);
15541552
self.state = AppState::ModManager;
1555-
return
1553+
return;
15561554
}
15571555
egui::CentralPanel::default().show(ctx, draw_bg);
15581556
Window::new(tr("lang_picker"))

quant.ew/files/system/notplayer_ai/notplayer_ai.lua

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,18 @@ local function combine_tables(a, b)
158158
return c
159159
end
160160

161+
local function find_teleport_wand()
162+
for _, ent in ipairs(wandfinder.get_all_wands({}) or {}) do
163+
for _, child in pairs(EntityGetAllChildren(ent) or {}) do
164+
local spell = EntityGetFirstComponentIncludingDisabled(child, "ItemActionComponent")
165+
local spell_name = ComponentGetValue2(spell, "action_id")
166+
if spell_name == "TELEPORT_PROJECTILE" or spell_name == "TELEPORT_PROJECTILE_SHORT" then
167+
return ent
168+
end
169+
end
170+
end
171+
end
172+
161173
local function find_new_wand()
162174
local children = EntityGetAllChildren(state.attack_wand)
163175
local kick_mode
@@ -179,7 +191,6 @@ local function find_new_wand()
179191
state.bad_wands[state.target or 1] = {}
180192
end
181193
table.insert(state.bad_wands[state.target or 1], state.attack_wand)
182-
table.insert(state.empty_wands, state.attack_wand)
183194
state.attack_wand = wandfinder.find_attack_wand(combine_tables(state.empty_wands, state.bad_wands[state.target or 1]))
184195
changed_held = true
185196
return
@@ -217,12 +228,17 @@ local function find_new_wand()
217228
end
218229
if not is_any_not_empty then
219230
table.insert(state.empty_wands, state.attack_wand)
220-
state.attack_wand, kick_mode = wandfinder.find_attack_wand(combine_tables(state.empty_wands, state.bad_wands[state.target or 1]))
231+
if state.attack_wand == state.teleport_wand then
232+
state.attack_wand, kick_mode = wandfinder.find_attack_wand(state.empty_wands)
233+
else
234+
state.attack_wand, kick_mode = wandfinder.find_attack_wand(combine_tables(state.empty_wands, state.bad_wands[state.target or 1]))
235+
end
221236
changed_held = true
222237
end
223238
end
224239
if kick_mode then
225240
state.kick_mode = true
241+
state.attack_wand = state.teleport_wand
226242
end
227243
end
228244

@@ -527,6 +543,7 @@ local function init_state()
527543
had_potion = false,
528544

529545
attack_wand = wandfinder.find_attack_wand({}),
546+
teleport_wand = find_teleport_wand(),
530547
empty_wands = {},
531548
bad_wands = {},
532549
good_wands = {},
@@ -595,7 +612,9 @@ local function choose_wand_actions()
595612
end
596613
state.dont_throw = false
597614
aim_at(t_x, t_y)
598-
fire_wand(not state.last_did_hit and state.init_timer > no_shoot_time and not changed_held)-- or has_water_potion)
615+
fire_wand(not state.last_did_hit and state.init_timer > no_shoot_time
616+
and not changed_held and (state.teleport_wand == nil or
617+
state.teleport_wand ~= state.attack_wand or state.last_length > 100 * 100))
599618
if changed_held then
600619
changed_held = false
601620
end
@@ -681,6 +700,14 @@ local function choose_movement()
681700
end
682701
local t_x, t_y = EntityGetTransform(state.target)
683702
local dist = my_x - t_x
703+
local dy = my_y - t_y
704+
if dist * dist + dy * dy > 132 * 132
705+
and state.teleport_wand ~= nil
706+
and state.attack_wand ~= state.teleport_wand
707+
and GameGetFrameNum() % 100 == 0 then
708+
state.attack_wand = state.teleport_wand
709+
changed_held = true
710+
end
684711
local LIM = give_space
685712
if swap_side and (on_right ~= (my_x > t_x) or GameGetFrameNum() % 300 == 299) then
686713
swap_side = false
@@ -867,7 +894,7 @@ local function choose_movement()
867894
move = -1
868895
end
869896
state.dtype = 0
870-
if (is_froze or state.kick_mode) and math.abs(dist) < 10 then
897+
if (is_froze or state.kick_mode) and math.abs(dist) < 10 and my_y < t_y then
871898
state.control_w = false
872899
end
873900
local did_hit_up, _, _ = RaytracePlatforms(my_x, my_y, my_x, my_y - 40)
@@ -1041,10 +1068,10 @@ local function teleport_outside_cursed()
10411068
end
10421069

10431070
local function hold_something()
1044-
local ch_x, ch_y = EntityGetTransform(state.entity)
10451071
if GameGetFrameNum() % 20 == 5 then
10461072
find_new_wand()
10471073
end
1074+
local ch_x, ch_y = EntityGetTransform(state.entity)
10481075
local inventory = EntityGetFirstComponent(ctx.my_player.entity, "Inventory2Component")
10491076
local holding = ComponentGetValue2(inventory, "mActualActiveItem")
10501077
local i = 1
@@ -1220,7 +1247,7 @@ local function find_target()
12201247
else
12211248
local dx = x - x1
12221249
local dy = y - y1
1223-
state.last_length = dx * dx + dy + dy
1250+
state.last_length = dx * dx + dy * dy
12241251
if not is_suitable_target(state.target)
12251252
or (state.last_length > (MAX_RADIUS + 128) * (MAX_RADIUS + 128))
12261253
or (IsInvisible(state.target) and state.last_length > (INVIS_RANGE + 32)*(INVIS_RANGE + 32)) then
@@ -1436,7 +1463,7 @@ local function update()
14361463

14371464
find_target()
14381465

1439-
do_kick = state.last_length ~= nil and state.last_length < no_shoot_time
1466+
do_kick = state.last_length ~= nil and state.last_length < 100
14401467

14411468
hold_something()
14421469

quant.ew/files/system/notplayer_ai/wandfinder.lua

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,26 @@ local function entity_is_wand(entity_id)
66
return ComponentGetValue2(ability_component, "use_gun_script") == true
77
end
88

9-
local function get_all_wands(dont_do)
9+
function wandfinder.get_all_wands(dont_do)
1010
local wands = {}
1111
local items = GameGetAllInventoryItems(ctx.my_player.entity) or {}
1212
for _, item in ipairs(items) do
13-
local use = true
14-
for _, item2 in ipairs(dont_do) do
15-
if item == item2 then
16-
use = false
17-
end
18-
end
19-
if entity_is_wand(item) and use then
13+
if entity_is_wand(item) and not table.contains(dont_do, item) then
2014
table.insert(wands, item)
2115
end
2216
end
2317
return wands
2418
end
2519

2620
function wandfinder.find_attack_wand(dont_do)
27-
local wands = get_all_wands(dont_do)
21+
local wands = wandfinder.get_all_wands(dont_do)
2822
if #wands == 0 then
29-
wands = get_all_wands({})
30-
return wands[Random(1, #wands)], true
23+
wands = wandfinder.get_all_wands({})
24+
if #wands == 0 then
25+
return nil, true
26+
else
27+
return wands[Random(1, #wands)], true
28+
end
3129
end
3230
local largest = {-1, -1}
3331
for _, wand in ipairs(wands) do

0 commit comments

Comments
 (0)