Dio93 / LC-DuckMod

A duck mod for Lethal Company
0 stars 0 forks source link

Ducks can't use fire exits #13

Open TerabyteTim opened 4 months ago

TerabyteTim commented 4 months ago

If you enter the building through a fire exit, ducks will transfer to another player. If you are in single-player, duck will go through main entrance to find you.

Same with leaving - if you take fire exit out of building, the ducks run all the way to the main entrance then find you outside

AtomicJuno commented 4 months ago

I'd like it if this feature could be a config option because it actually helps that they go to the main entrance if i go into a fire exit. It allows the duck to pick up stuff on the way towards me so there's a multitasking element

TerabyteTim commented 3 months ago

@Dio93 I forked this and fixed locally. Here's the updated code I made to allow ducks to use both fire and main exits. To be placed at the top of your Teleport() function in PetAI.cs

EntranceTeleport[] entranceTeleports = FindObjectsOfType<EntranceTeleport>();
            int                closestIndex      = -1;
            float              closestDist       = float.MaxValue;

            for (int i = 0; i < entranceTeleports.Length; i++)
            {
                //Only look for entrances inside/outside of building based on our state
                if (this.isInFactory == entranceTeleports[i].isEntranceToBuilding)
                {
                    continue;
                }

                float dist = Vector3.Distance(this.transform.position, entranceTeleports[i].transform.position);

                if (dist < closestDist)
                {
                    closestIndex = i;
                    closestDist  = dist;
                }
            }

            //Set next and main good way
            if (closestIndex >= 0)
            {
                nextEntrance = entranceTeleports[closestIndex].transform.position;

                //Find target based on next
                int targetIndex = -1;

                for (int i = 0; i < entranceTeleports.Length; i++)
                {
                    if (entranceTeleports[i].entranceId == entranceTeleports[closestIndex].entranceId && entranceTeleports[i].isEntranceToBuilding != entranceTeleports[closestIndex].isEntranceToBuilding)
                    {
                        targetIndex = i;
                        break;
                    }
                }

                targetEntrance = entranceTeleports[targetIndex].transform.position;
            }

            //Failsafe, set to main entrance only
            else 
            {
                if (this.isInFactory)
                {
                    nextEntrance   = RoundManager.FindMainEntrancePosition(false, false);
                    targetEntrance = RoundManager.FindMainEntrancePosition(false, true);
                }
                else
                {
                    nextEntrance   = RoundManager.FindMainEntrancePosition(false, true);
                    targetEntrance = RoundManager.FindMainEntrancePosition(false, false);
                }
            }
Dio93 commented 3 months ago

Hey, sorry for the late reply. Unfortunately, I'm really busy right now. Thank you very much for fixing the issue. I have pushed the latest version of the code so you can enjoy the latest features with your fix (I haven't included your fix yet). As soon as I have more time, I will continue working on this project.