Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Enemy Control #352

Merged
merged 53 commits into from
Feb 6, 2024
Merged

Add Enemy Control #352

merged 53 commits into from
Feb 6, 2024

Conversation

xAstroBoy
Copy link
Contributor

@xAstroBoy xAstroBoy commented Feb 3, 2024

Closes #250

@winstxnhdw
Copy link
Owner

Oh dear, there's a lot more problems than I thought.

    public EnemyIdentity IdentifyEnemy(EnemyAI enemy) {
        return enemy is null
            ? EnemyIdentity.None
            : enemy switch {
                CentipedeAI => EnemyIdentity.Centipede,
                BaboonBirdAI => EnemyIdentity.Baboon,
                FlowermanAI => EnemyIdentity.Flowerman,
                ForestGiantAI => EnemyIdentity.ForestGiant,
                HoarderBugAI => EnemyIdentity.HoarderBug,
                JesterAI => EnemyIdentity.Jester,
                MaskedPlayerEnemy => EnemyIdentity.Masked,
                MouthDogAI => EnemyIdentity.MouthDog,
                NutcrackerEnemyAI => EnemyIdentity.Nutcracker,
                PufferAI => EnemyIdentity.Puffer,
                SandWormAI => EnemyIdentity.Sandworm,
                SpringManAI => EnemyIdentity.Springman,
                _ => EnemyIdentity.Default,
            };
    }

Why did you not just return the enemy instead? You are making a lot of unnecessary indirections, which you later have to indirect back again.

Please be patient while I fix this.

@xAstroBoy
Copy link
Contributor Author

Oh dear, there's a lot more problems than I thought.

    public EnemyIdentity IdentifyEnemy(EnemyAI enemy) {
        return enemy is null
            ? EnemyIdentity.None
            : enemy switch {
                CentipedeAI => EnemyIdentity.Centipede,
                BaboonBirdAI => EnemyIdentity.Baboon,
                FlowermanAI => EnemyIdentity.Flowerman,
                ForestGiantAI => EnemyIdentity.ForestGiant,
                HoarderBugAI => EnemyIdentity.HoarderBug,
                JesterAI => EnemyIdentity.Jester,
                MaskedPlayerEnemy => EnemyIdentity.Masked,
                MouthDogAI => EnemyIdentity.MouthDog,
                NutcrackerEnemyAI => EnemyIdentity.Nutcracker,
                PufferAI => EnemyIdentity.Puffer,
                SandWormAI => EnemyIdentity.Sandworm,
                SpringManAI => EnemyIdentity.Springman,
                _ => EnemyIdentity.Default,
            };
    }

Why did you not just return the enemy instead? You are making a lot of unnecessary indirections, which you later have to indirect back again.

Please be patient while I fix this.

that is how to identify which enemy class is to specifically control without casting the enemy over and over?

@winstxnhdw
Copy link
Owner

You could probably just do this.

T IdentifyEnemy(EnemyAI enemy) where T : EnemyAI {
   ...
}

without casting the enemy over and over?

Also, you are doing a lot of casting anyways.

            case EnemyIdentity.Centipede:
                return ((CentipedeAI)this.EnemyToPossess).GetSecondarySkillName();
            case EnemyIdentity.Baboon:
                return ((BaboonBirdAI)this.EnemyToPossess).GetSecondarySkillName();
            case EnemyIdentity.HoarderBug:
                return ((HoarderBugAI)this.EnemyToPossess).GetSecondarySkillName();
            case EnemyIdentity.Jester:
                return ((JesterAI)this.EnemyToPossess).GetSecondarySkillName();
            case EnemyIdentity.Nutcracker:
                return ((NutcrackerEnemyAI)this.EnemyToPossess).GetSecondarySkillName();
            case EnemyIdentity.Puffer:
                return ((PufferAI)this.EnemyToPossess).GetSecondarySkillName();
            case EnemyIdentity.Sandworm:
                return ((SandWormAI)this.EnemyToPossess).GetSecondarySkillName();
            case EnemyIdentity.MouthDog:
                return ((MouthDogAI)this.EnemyToPossess).GetSecondarySkillName();

@winstxnhdw
Copy link
Owner

I am still looking really superficially. Give me a while to dig into it.

@winstxnhdw
Copy link
Owner

winstxnhdw commented Feb 3, 2024

It would've probably been better to use a IController interface since every extension has a common method. We'll see.

@xAstroBoy
Copy link
Contributor Author

You could probably just do this.

T IdentifyEnemy(EnemyAI enemy) where T : EnemyAI {
   ...
}

without casting the enemy over and over?

Also, you are doing a lot of casting anyways.

            case EnemyIdentity.Centipede:
                return ((CentipedeAI)this.EnemyToPossess).GetSecondarySkillName();
            case EnemyIdentity.Baboon:
                return ((BaboonBirdAI)this.EnemyToPossess).GetSecondarySkillName();
            case EnemyIdentity.HoarderBug:
                return ((HoarderBugAI)this.EnemyToPossess).GetSecondarySkillName();
            case EnemyIdentity.Jester:
                return ((JesterAI)this.EnemyToPossess).GetSecondarySkillName();
            case EnemyIdentity.Nutcracker:
                return ((NutcrackerEnemyAI)this.EnemyToPossess).GetSecondarySkillName();
            case EnemyIdentity.Puffer:
                return ((PufferAI)this.EnemyToPossess).GetSecondarySkillName();
            case EnemyIdentity.Sandworm:
                return ((SandWormAI)this.EnemyToPossess).GetSecondarySkillName();
            case EnemyIdentity.MouthDog:
                return ((MouthDogAI)this.EnemyToPossess).GetSecondarySkillName();

yes, but the switch case casts only based off which enemy is, and the enum acts as a identity

@winstxnhdw
Copy link
Owner

Have you seen IEnemyPrompter?

@xAstroBoy
Copy link
Contributor Author

Have you seen IEnemyPrompter?

nvm

@xAstroBoy
Copy link
Contributor Author

@winstxnhdw another issue is seconday attack while you are dead and controlling a enemy you risk of starting a vote for the ship to leave early

@winstxnhdw
Copy link
Owner

@winstxnhdw another issue is seconday attack while you are dead and controlling a enemy you risk of starting a vote for the ship to leave early

Good catch. We can patch that out.

@xAstroBoy
Copy link
Contributor Author

xAstroBoy commented Feb 3, 2024

@winstxnhdw i want to use Update() and add a better primary and secondary since with your input system sometimes it fails and it does not hold on the attacks.
Also a way to set the enemy walk/run speed would be handy as well, since controlcompany does that to make it as natural as possible.

@winstxnhdw
Copy link
Owner

i want to use Update() and add a better primary and secondary since with your input system sometimes it fails and it does not hold on the attacks.

Can you tell me how it fails? You might be implementing it wrongly. Hold commands must be set within the update loop like this.

    void Update() {
        InputListener.onShiftButtonHold?.Invoke(Keyboard.current[Key.LeftShift].isPressed);
        InputListener.onFButtonHold?.Invoke(Keyboard.current[Key.F].isPressed);
        InputListener.onRButtonHold?.Invoke(Keyboard.current[Key.R].isPressed);
        InputListener.onEButtonHold?.Invoke(Keyboard.current[Key.E].isPressed);

        foreach ((Func<bool> keyPressed, Action eventAction) in this.InputActions) {
            if (!keyPressed()) continue;
            eventAction();
        }
    }

@xAstroBoy
Copy link
Contributor Author

i want to use Update() and add a better primary and secondary since with your input system sometimes it fails and it does not hold on the attacks.

Can you tell me how it fails? You might be implementing it wrongly. Hold commands must be set within the update loop like this.

    void Update() {
        InputListener.onShiftButtonHold?.Invoke(Keyboard.current[Key.LeftShift].isPressed);
        InputListener.onFButtonHold?.Invoke(Keyboard.current[Key.F].isPressed);
        InputListener.onRButtonHold?.Invoke(Keyboard.current[Key.R].isPressed);
        InputListener.onEButtonHold?.Invoke(Keyboard.current[Key.E].isPressed);

        foreach ((Func<bool> keyPressed, Action eventAction) in this.InputActions) {
            if (!keyPressed()) continue;
            eventAction();
        }
    }

yeah, the secondary needs to be a hold attack, because you need to keep pressing the button to make the jester crank and when it pops out the secondary has to be released, ill investigate better, but im not sure about that, as well we need to disable ping scan until we stop possessing the enemy

@winstxnhdw
Copy link
Owner

Also a way to set the enemy walk/run speed would be handy as well, since controlcompany does that to make it as natural as possible.

Would subscribing to the onLeftBracketPress and onRightBracketPress events to change speed work?

@Totoqoe
Copy link

Totoqoe commented Feb 5, 2024

There's a bug where if an enemy despawns or you get kicked while possessing it, then you're unable to to possess any other enemies until you restart.

@D1GQ
Copy link
Contributor

D1GQ commented Feb 5, 2024

There's also issue where the door gets absolutely spammed trying to open and close it as an enemy. And it seems disabling The death HUD doesn't work when possessing.

@xAstroBoy
Copy link
Contributor Author

@winstxnhdw a health checker to see if a possessed enemy is dead to eject PossessionMod and a way to give AI the enemy control and override it would be nice.
Haven't figured how to fix the door issue .

@winstxnhdw
Copy link
Owner

AI the enemy control and override it would be nice

What?

@winstxnhdw
Copy link
Owner

Haven't figured how to fix the door issue .

Just use TriggerMod interact??

@xAstroBoy
Copy link
Contributor Author

Haven't figured how to fix the door issue .

Just use TriggerMod interact??

yeah triggermod can do it, but when you are dead is not working to open/close doors.

@winstxnhdw
Copy link
Owner

Nope, it still works.

@xAstroBoy
Copy link
Contributor Author

Nope, it still works.

not dedicated to the enemy itself tho?
for example if you possess a enemy and you want to make it leave the facility that wouldn't work.

@winstxnhdw
Copy link
Owner

Oh, you mean the entrances? Honestly, there is nothing wrong with noclipping outside. Let's figure it out next time.

Comment on lines 113 to 155
void HandleEnemyMovements() {
if (this.EnemyToPossess is null) return;
switch (this.enemyIdentity) {
case EnemyIdentity.Nutcracker:
if (this.IsUsingPrimarySkill || this.IsUsingSecondarySkill) return; // prevent this from blocking the sentry skill of the nutcracker.
(this.EnemyToPossess as NutcrackerEnemyAI)?.OnMoving();
break;
case EnemyIdentity.Baboon:
break;
case EnemyIdentity.Centipede:
break;
case EnemyIdentity.Flowerman:
break;
case EnemyIdentity.ForestGiant:
break;
case EnemyIdentity.HoarderBug:
break;
case EnemyIdentity.Jester:
break;
case EnemyIdentity.Masked:
break;
case EnemyIdentity.MouthDog:
break;
case EnemyIdentity.Puffer:
break;
case EnemyIdentity.Sandworm:
break;
case EnemyIdentity.Springman:
break;
case EnemyIdentity.Blob:
break;
case EnemyIdentity.ElectricBees:
break;
case EnemyIdentity.Thumper:
break;
case EnemyIdentity.Default:
break;
case EnemyIdentity.None:
break;
default:
break;
}
}
Copy link
Owner

@winstxnhdw winstxnhdw Feb 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been wondering what's the point of this? Do we just let the Nutcracker move on its own?

@winstxnhdw
Copy link
Owner

winstxnhdw commented Feb 6, 2024

I just spent 7 hours on this. This is the last time I will be accepting a PR of such dubious quality. The next time I see a PR that will take more more than 2 hours to fix, I am just closing it. I can't waste so much time anymore.

Copy link
Owner

@winstxnhdw winstxnhdw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was absolute mental abuse.

@winstxnhdw winstxnhdw merged commit f858a1a into winstxnhdw:main Feb 6, 2024
4 checks passed
@xAstroBoy xAstroBoy deleted the enemy-control branch February 6, 2024 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request]: Enhance control over the enemy.
4 participants