Last active
May 19, 2024 20:04
-
-
Save dextercd/aecdd61d95bc6f33b89bb559d52f2e33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- By dextercd | |
local entity_id = GetUpdatedEntityID() | |
local controls = EntityGetFirstComponentIncludingDisabled(entity_id, "ControlsComponent") | |
local animal_ai = EntityGetFirstComponentIncludingDisabled(entity_id, "AnimalAIComponent") | |
local frame = GameGetFrameNum() | |
if not controls or not animal_ai | |
or not ComponentGetValue2(controls, "polymorph_hax") | |
or not ComponentGetValue2(controls, "mButtonDownFire") | |
or ComponentGetValue2(controls, "mButtonFrameFire") ~= frame | |
or ComponentGetValue2(controls, "polymorph_next_attack_frame") > frame | |
then | |
return | |
end | |
local attack_ranged_entity_file = ComponentGetValue2(animal_ai, "attack_ranged_entity_file") | |
local frames_between_attack = ComponentGetValue2(animal_ai, "attack_ranged_frames_between") | |
local offset_x = ComponentGetValue2(animal_ai, "attack_ranged_offset_x") | |
local offset_y = ComponentGetValue2(animal_ai, "attack_ranged_offset_y") | |
local x, y, _, scale_x, scale_y = EntityGetTransform(entity_id) | |
for _, ai_attack in ipairs(EntityGetComponent(entity_id, "AIAttackComponent") or {}) do | |
SetRandomSeed(x + 0.11231 + frame, y + 0.2341) | |
if Random(100) <= ComponentGetValue2(ai_attack, "use_probability") then | |
attack_ranged_entity_file = ComponentGetValue2(ai_attack, "attack_ranged_entity_file") | |
frames_between_attack = ComponentGetValue2(ai_attack, "frames_between") | |
offset_x = ComponentGetValue2(ai_attack, "attack_ranged_offset_x") | |
offset_y = ComponentGetValue2(ai_attack, "attack_ranged_offset_y") | |
end | |
end | |
offset_x = offset_x * scale_x | |
offset_y = offset_y * scale_y | |
-- TODO: Entity rotation | |
local shoot_x = x + offset_x | |
local shoot_y = y + offset_y | |
local aimvec_x, aimvec_y = ComponentGetValue2(controls, "mAimingVectorNormalized") | |
local target_x = shoot_x + aimvec_x * 2 | |
local target_y = shoot_y + aimvec_y * 2 | |
if attack_ranged_entity_file == "data/entities/projectiles/acidshot.xml" | |
and EntityGetFilename(entity_id) ~= "data/entities/animals/acidshooter.xml" | |
then | |
attack_ranged_entity_file = "" | |
end | |
if attack_ranged_entity_file == "" then | |
return | |
end | |
ComponentSetValue2(controls, "polymorph_next_attack_frame", frame + frames_between_attack) | |
local projectile = EntityLoad(attack_ranged_entity_file, shoot_x, shoot_y) | |
GameShootProjectile(entity_id, | |
shoot_x, shoot_y, | |
target_x, target_y, | |
projectile, | |
true | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment