Exemple #1
0
 public void AIMapReady()
 {
     orig_AIMapReady();
     if (room.roomSettings.GetEffectAmount((RoomSettings.RoomEffect.Type)patch_RoomSettings.patch_RoomEffect.Type.LMSwarmers) > 0f)
     {
         bool         dark            = room.roomSettings.Palette == 24 || (room.roomSettings.fadePalette != null && room.roomSettings.fadePalette.palette == 24);
         IntVector2[] accessableTiles = room.aimap.CreatureSpecificAImap(StaticWorld.GetCreatureTemplate(CreatureTemplate.Type.Fly)).accessableTiles;
         int          num             = (int)((float)accessableTiles.Length * 0.05f * room.roomSettings.GetEffectAmount((RoomSettings.RoomEffect.Type)patch_RoomSettings.patch_RoomEffect.Type.LMSwarmers));
         System.Collections.Generic.List <IntVector2> list = new System.Collections.Generic.List <IntVector2>();
         for (int i = 0; i < num; i++)
         {
             list.Add(accessableTiles[UnityEngine.Random.Range(0, accessableTiles.Length)]);
         }
         LMOracleSwarmer.Behavior behavior = null;
         for (int j = 0; j < list.Count; j++)
         {
             LMOracleSwarmer LMOracleSwarmer = new LMOracleSwarmer(new AbstractPhysicalObject(room.world, (AbstractPhysicalObject.AbstractObjectType)patch_AbstractPhysicalObject.AbstractObjectType.LMOracleSwarmer, null, room.GetWorldCoordinate(list[j]), room.game.GetNewID()), room.world);
             LMOracleSwarmer.abstractPhysicalObject.destroyOnAbstraction = true;
             LMOracleSwarmer.firstChunk.HardSetPosition(room.MiddleOfTile(list[j]));
             LMOracleSwarmer.system           = this;
             LMOracleSwarmer.waitToFindOthers = j;
             LMOracleSwarmer.dark             = dark;
             if (behavior == null)
             {
                 behavior = LMOracleSwarmer.currentBehavior;
             }
             else
             {
                 LMOracleSwarmer.currentBehavior = behavior;
             }
             room.AddObject(LMOracleSwarmer);
             LMOracleSwarmer.NewRoom(room);
         }
     }
 }
Exemple #2
0
 // Token: 0x060022D6 RID: 8918 RVA: 0x00212894 File Offset: 0x00210A94
 public LMOracleSwarmer(AbstractPhysicalObject abstractPhysicalObject, World world) : base(abstractPhysicalObject, world)
 {
     travelDirection = Custom.RNV();
     currentBehavior = new LMOracleSwarmer.Behavior(this);
     color           = currentBehavior.color;
     stuckList       = new System.Collections.Generic.List <Vector2>();
 }
Exemple #3
0
    // Token: 0x060022D8 RID: 8920 RVA: 0x00212994 File Offset: 0x00210B94
    public override void Update(bool eu)
    {
        if (system != null && system.Frozen)
        {
            return;
        }
        base.Update(eu);
        if (!room.readyForAI || room.gravity * affectedByGravity > 0.5f)
        {
            return;
        }
        direction = travelDirection;
        switch (mode)
        {
        case MovementMode.Swarm:
            SwarmBehavior();
            if (onlySwarm > 0)
            {
                onlySwarm--;
            }
            else if (currentBehavior.suckle && UnityEngine.Random.value < 0.1f && system != null && system.mycelia.Count > 0)
            {
                Mycelium mycelium = system.mycelia[UnityEngine.Random.Range(0, system.mycelia.Count)];
                if (Custom.DistLess(firstChunk.pos, mycelium.Tip, 400f) && room.VisualContact(firstChunk.pos, mycelium.Tip))
                {
                    bool flag = false;
                    int  num  = 0;
                    while (num < otherSwarmers.Count && !flag)
                    {
                        if ((otherSwarmers[num] as LMOracleSwarmer).suckleMyc == mycelium)
                        {
                            flag = true;
                        }
                        num++;
                    }
                    if (!flag)
                    {
                        mode          = MovementMode.SuckleMycelia;
                        suckleMyc     = mycelium;
                        attachedToMyc = false;
                    }
                }
            }
            else if (room.aimap.getAItile(firstChunk.pos).terrainProximity < 7)
            {
                if (stuckListCounter > 0)
                {
                    stuckListCounter--;
                }
                else
                {
                    stuckList.Insert(0, firstChunk.pos);
                    if (stuckList.Count > 10)
                    {
                        stuckList.RemoveAt(stuckList.Count - 1);
                    }
                    stuckListCounter = 80;
                }
                if (UnityEngine.Random.value < 0.025f && stuckList.Count > 1 && Custom.DistLess(firstChunk.pos, stuckList[stuckList.Count - 1], 200f))
                {
                    System.Collections.Generic.List <int> list = new System.Collections.Generic.List <int>();
                    for (int i = 0; i < room.abstractRoom.connections.Length; i++)
                    {
                        if (room.aimap.ExitDistanceForCreature(room.GetTilePosition(firstChunk.pos), i, StaticWorld.GetCreatureTemplate(CreatureTemplate.Type.Fly)) > 0)
                        {
                            list.Add(i);
                        }
                    }
                    if (list.Count > 0)
                    {
                        mode     = MovementMode.FollowDijkstra;
                        dijkstra = list[UnityEngine.Random.Range(0, list.Count)];
                    }
                }
            }
            break;

        case MovementMode.SuckleMycelia:
            if (suckleMyc == null)
            {
                mode = MovementMode.Swarm;
            }
            else if (attachedToMyc)
            {
                direction = Custom.DirVec(firstChunk.pos, suckleMyc.Tip);
                float num2 = Vector2.Distance(firstChunk.pos, suckleMyc.Tip);
                firstChunk.vel -= (2f - num2) * direction * 0.15f;
                firstChunk.pos -= (2f - num2) * direction * 0.15f;
                suckleMyc.points[suckleMyc.points.GetLength(0) - 1, 0] += (2f - num2) * direction * 0.35f;
                suckleMyc.points[suckleMyc.points.GetLength(0) - 1, 2] += (2f - num2) * direction * 0.35f;
                travelDirection = new Vector2(0f, 0f);
                if (UnityEngine.Random.value < 0.05f)
                {
                    room.AddObject(new NeuronSpark((firstChunk.pos + suckleMyc.Tip) / 2f));
                }
                if (UnityEngine.Random.value < 0.0125f)
                {
                    suckleMyc = null;
                    onlySwarm = UnityEngine.Random.Range(40, 400);
                }
            }
            else
            {
                travelDirection = Custom.DirVec(firstChunk.pos, suckleMyc.Tip);
                if (Custom.DistLess(firstChunk.pos, suckleMyc.Tip, 5f))
                {
                    attachedToMyc = true;
                }
                else if (UnityEngine.Random.value < 0.05f && !room.VisualContact(firstChunk.pos, suckleMyc.Tip))
                {
                    suckleMyc = null;
                }
            }
            color = Vector2.Lerp(color, currentBehavior.color, 0.05f);
            break;

        case MovementMode.FollowDijkstra:
        {
            IntVector2 tilePosition = room.GetTilePosition(firstChunk.pos);
            int        num3         = -1;
            int        num4         = int.MaxValue;
            for (int j = 0; j < 4; j++)
            {
                if (!room.GetTile(tilePosition + Custom.fourDirections[j]).Solid)
                {
                    int num5 = room.aimap.ExitDistanceForCreature(tilePosition + Custom.fourDirections[j], dijkstra, StaticWorld.GetCreatureTemplate(CreatureTemplate.Type.Fly));
                    if (num5 > 0 && num5 < num4)
                    {
                        num3 = j;
                        num4 = num5;
                    }
                }
            }
            if (num3 > -1)
            {
                travelDirection += Custom.fourDirections[num3].ToVector2().normalized * 1.4f + Custom.RNV() * UnityEngine.Random.value * 0.5f;
            }
            else
            {
                mode = MovementMode.Swarm;
            }
            travelDirection.Normalize();
            int num6 = room.aimap.ExitDistanceForCreature(tilePosition, dijkstra, StaticWorld.GetCreatureTemplate(CreatureTemplate.Type.Fly));
            if ((UnityEngine.Random.value < 0.025f && num6 < 34) || num6 < 12 || dijkstra < 0 || UnityEngine.Random.value < 0.0025f || (room.aimap.getAItile(firstChunk.pos).terrainProximity >= 7 && UnityEngine.Random.value < 0.0166666675f))
            {
                mode = MovementMode.Swarm;
            }
            break;
        }
        }
        firstChunk.vel += travelDirection * 0.3f * (1f - room.gravity * affectedByGravity);
        firstChunk.vel *= Custom.LerpMap(firstChunk.vel.magnitude, 0.2f, 3f, 1f, 0.9f);
        if (currentBehavior.Dead)
        {
            Vector2 vector = currentBehavior.color;
            currentBehavior = new LMOracleSwarmer.Behavior(this);
            if (UnityEngine.Random.value > 0.25f)
            {
                currentBehavior.color = vector;
            }
        }
        else if (currentBehavior.leader == this)
        {
            currentBehavior.life -= currentBehavior.deathSpeed;
        }
        if (abstractPhysicalObject.destroyOnAbstraction && grabbedBy.Count > 0)
        {
            abstractPhysicalObject.destroyOnAbstraction = false;
        }
    }