private static void onTriggerSpikesGetPlayerCollideIndex(On.Celeste.TriggerSpikes.orig_GetPlayerCollideIndex orig,
                                                                 TriggerSpikes self, Player player, out int minIndex, out int maxIndex)
        {
            orig(self, player, out minIndex, out maxIndex);

            DynData <TriggerSpikes> selfData = new DynData <TriggerSpikes>(self);

            if (selfData.Data.ContainsKey("grouped") && selfData.Get <bool>("grouped"))
            {
                int spikeCount = selfData.Get <int>("size") / 4;

                if (maxIndex >= 0 && minIndex < spikeCount)
                {
                    // let's pretend the player is pressing every trigger spike at once.
                    minIndex = 0;
                    maxIndex = spikeCount - 1;
                }
            }
        }
        private static void DrawSpikesHitboxes(TriggerSpikes triggerSpikes, Camera camera)
        {
            triggerSpikes.Collider?.Render(camera, HitboxColor.EntityColorInverselyLessAlpha);

            Vector2 offset, value;
            bool    vertical = false;

            switch (TriggerSpikesDirection(triggerSpikes))
            {
            case TriggerSpikes.Directions.Up:
                offset = new Vector2(-2f, -4f);
                value  = new Vector2(1f, 0f);
                break;

            case TriggerSpikes.Directions.Down:
                offset = new Vector2(-2f, 0f);
                value  = new Vector2(1f, 0f);
                break;

            case TriggerSpikes.Directions.Left:
                offset   = new Vector2(-4f, -2f);
                value    = new Vector2(0f, 1f);
                vertical = true;
                break;

            case TriggerSpikes.Directions.Right:
                offset   = new Vector2(0f, -2f);
                value    = new Vector2(0f, 1f);
                vertical = true;
                break;

            default:
                return;
            }

            Array spikes = TriggerSpikesSpikes(triggerSpikes) as Array;

            for (int i = 0; i < spikes.Length; i++)
            {
                object spikeInfo = spikes.GetValue(i);
                if (triggerSpikesTriggered == null)
                {
                    triggerSpikesTriggered = spikeInfo.GetType().GetField("Triggered", BindingFlags.Instance | BindingFlags.Public);
                }

                if (triggerSpikesLerp == null)
                {
                    triggerSpikesLerp = spikeInfo.GetType().GetField("Lerp", BindingFlags.Instance | BindingFlags.Public);
                }

                if ((bool)triggerSpikesTriggered.GetValue(spikeInfo) && (float)triggerSpikesLerp.GetValue(spikeInfo) >= 1f)
                {
                    Vector2 position = triggerSpikes.Position + value * (2 + i * 4) + offset;

                    int num = 1;
                    for (int j = i + 1; j < spikes.Length; j++)
                    {
                        object nextSpikeInfo = spikes.GetValue(j);
                        if ((bool)triggerSpikesTriggered.GetValue(nextSpikeInfo) && (float)triggerSpikesLerp.GetValue(nextSpikeInfo) >= 1f)
                        {
                            num++;
                            i++;
                        }
                        else
                        {
                            break;
                        }
                    }

                    Draw.HollowRect(position, 4f * (vertical ? 1 : num), 4f * (vertical ? num : 1),
                                    HitboxColor.GetCustomColor(Color.Red, triggerSpikes));
                }
            }
        }
示例#3
0
        public static Entity CreateEntityCopy(Entity savedEntity, string tag = "EntitiesSavedButNotLoaded")
        {
            Entity loadedEntity = null;
            Type   savedType    = savedEntity.GetType();

            if (savedEntity.GetEntityData() != null)
            {
                // 一般 Entity 都是 EntityData + Vector2
                loadedEntity = (savedType.GetConstructor(new[] { typeof(EntityData), typeof(Vector2) })
                                ?.Invoke(new object[] { savedEntity.GetEntityData(), Vector2.Zero })) as Entity;

                if (loadedEntity == null)
                {
                    // 部分例如草莓则是 EntityData + Vector2 + EntityID
                    loadedEntity = savedType
                                   .GetConstructor(new[] { typeof(EntityData), typeof(Vector2), typeof(EntityID) })
                                   ?.Invoke(new object[] {
                        savedEntity.GetEntityData(), Vector2.Zero, savedEntity.GetEntityId2().EntityId
                    }) as Entity;
                }

                if (loadedEntity == null && savedType.IsType <CrystalStaticSpinner>())
                {
                    loadedEntity = new CrystalStaticSpinner(savedEntity.GetEntityData(), Vector2.Zero,
                                                            (CrystalColor)savedEntity.GetField(typeof(CrystalStaticSpinner), "color"));
                }

                if (loadedEntity == null && savedType.IsType <TriggerSpikes>())
                {
                    loadedEntity = new TriggerSpikes(savedEntity.GetEntityData(), Vector2.Zero,
                                                     (TriggerSpikes.Directions)savedEntity.GetField(typeof(TriggerSpikes), "direction"));
                }

                if (loadedEntity == null && savedType.IsType <Spikes>())
                {
                    loadedEntity = new Spikes(savedEntity.GetEntityData(), Vector2.Zero,
                                              ((Spikes)savedEntity).Direction);
                }

                if (loadedEntity == null && savedType.IsType <TriggerSpikes>())
                {
                    loadedEntity = new Spring(savedEntity.GetEntityData(), Vector2.Zero, ((Spring)savedEntity).Orientation);
                }

                if (loadedEntity != null)
                {
                    loadedEntity.Position = savedEntity.Position;
                    loadedEntity.CopyEntityData(savedEntity);
                    loadedEntity.CopyEntityId2(savedEntity);
                    return(loadedEntity);
                }
            }

            // TODO 如果是他们的子类该怎么办……
            if (savedType.IsType <BadelineDummy>())
            {
                loadedEntity = new BadelineDummy(savedEntity.GetStartPosition());
            }
            else if (savedType.IsType <AngryOshiro>())
            {
                loadedEntity = new AngryOshiro(savedEntity.GetStartPosition(),
                                               (bool)savedEntity.GetField("fromCutscene"));
            }
            else if (savedType.IsType <Snowball>())
            {
                loadedEntity = new Snowball();
            }
            else if (savedType.IsType <SlashFx>() && savedEntity is SlashFx slashFx)
            {
                loadedEntity = slashFx.Clone();
            }
            else if (savedType.IsType <SpeedRing>() && savedEntity is SpeedRing speedRing)
            {
                loadedEntity = speedRing.Clone();
            }
            else if (savedType.IsType <FinalBossShot>() && savedEntity is FinalBossShot finalBossShot)
            {
                loadedEntity = finalBossShot.Clone();
            }
            else if (savedType.IsType <FinalBossBeam>() && savedEntity is FinalBossBeam finalBossBeam)
            {
                loadedEntity = finalBossBeam.Clone();
            }
            else if (savedType.IsType <BirdTutorialGui>() && savedEntity is BirdTutorialGui birdTutorialGui)
            {
                loadedEntity = birdTutorialGui.Clone();
            }
            else if (savedType.IsType <SoundEmitter>() && savedEntity is SoundEmitter soundEmitter)
            {
                loadedEntity = SoundEmitter.Play(soundEmitter.Source.EventName,
                                                 new Entity(soundEmitter.Position));
                if (SoundSourceAction.PlayingSoundSources.FirstOrDefault(source =>
                                                                         source.EventName == soundEmitter.Source.EventName) == null)
                {
                    (loadedEntity as SoundEmitter)?.Source.TryCopyObject(soundEmitter.Source);
                }
                else
                {
                    (loadedEntity as SoundEmitter)?.Source.Stop();
                }
            }
            else if (savedType.IsType <Debris>() && savedEntity is Debris debris)
            {
                loadedEntity = Engine.Pooler.Create <Debris>()
                               .Init(debris.GetStartPosition(), (char)debris.GetField("tileset"),
                                     (bool)debris.GetField("playSound"));
            }
            else if (savedType == typeof(TalkComponent.TalkComponentUI))
            {
                // ignore
            }
            else if (savedType.IsType <Entity>())
            {
                loadedEntity = new Entity(savedEntity.GetStartPosition());
            }
            else
            {
                if (savedEntity.GetType().FullName == "Celeste.MoveBlock+Debris")
                {
                    loadedEntity = (savedEntity as Actor).CloneMoveBlockDebris();
                }
                else if (savedEntity.ForceCreateInstance(tag) is Entity newEntity)
                {
                    loadedEntity = newEntity;
                }
            }


            if (loadedEntity == null)
            {
                return(null);
            }

            loadedEntity.Position = savedEntity.Position;
            loadedEntity.CopyEntityId2(savedEntity);
            loadedEntity.CopyStartPosition(savedEntity);

            return(loadedEntity);
        }
示例#4
0
        private void OverlayEntities(MapElement entities, Bitmap map, VirtualMap <char> solids, bool background)
        {
            CassetteBlock.Blocks.Clear();

            using (Graphics g = Graphics.FromImage(map)) {
                List <Entity> ents = new List <Entity>();
                for (int i = entities.Children.Count - 1; i >= 0; i--)
                {
                    MapElement child = entities.Children[i];

                    Entity entity = null;
                    if (child.Name.IndexOf("spikes", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        entity = background ? Spikes.FromElement(child) : null;
                    }
                    else if (child.Name.IndexOf("triggerSpikes", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        entity = background ? TriggerSpikes.FromElement(child) : null;
                    }
                    else if (child.Name.IndexOf("strawberry", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        entity = background ? Strawberry.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("goldenBerry", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Strawberry.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("redBlocks", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ClutterBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("greenBlocks", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ClutterBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("yellowBlocks", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ClutterBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("clutterCabinet", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ClutterCabinet.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("introCar", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? IntroCar.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("clothesLine", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ClothesLine.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("colorSwitch", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ColorSwitch.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("memorialTextController", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Strawberry.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("bonfire", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Bonfire.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("trapDoor", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? TrapDoor.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("movingPlatform", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? MovingPlatform.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("sinkingPlatform", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? SinkingPlatform.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("clutterDoor", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ClutterDoor.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("bridge", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Bridge.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("bridgeFixed", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? BridgeFixed.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("jumpThru", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? JumpThru.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("door", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Door.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("blockField", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? BlockField.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("lamp", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Lamp.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("hahaha", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Haha.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("waterFall", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? WaterFall.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("water", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Water.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("key", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Key.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("resortLantern", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ResortLantern.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("bird", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Bird.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("memorial", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Memorial.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("player", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? PlayerSpawn.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("zipMover", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ZipMover.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("wire", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Wire.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("crumbleBlock", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? CrumbleBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("refill", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Refill.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("spring", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Spring.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("fakeWall", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? FakeWall.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("exitBlock", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? FakeWall.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("lightBeam", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? LightBeam.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("cobweb", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Cobweb.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("cassette", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Cassette.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("flutterBird", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? FlutterBird.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("checkpoint", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Checkpoint.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("fallingBlock", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? FallingBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("introCrusher", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? FallingBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("cassetteBlock", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? CassetteBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("dashBlock", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? DashBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("coverupWall", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? CoverupWall.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("npc", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? NPC.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("birdForsakenCityGem", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ForsakenCityGem.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("soundSource", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? SoundSource.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("friendlyGhost", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? FriendlyGhost.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("floatingDebris", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? FloatingDebris.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("hangingLamp", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? HangingLamp.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("lockBlock", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? LockBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("heartGem", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? HeartGem.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("blackGem", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? HeartGem.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("dreamMirror", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? DreamMirror.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("darkChaser", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? DarkChaser.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("dreamBlock", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? DreamBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("touchSwitch", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? TouchSwitch.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("switchGate", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? SwitchGate.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("invisibleBarrier", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? InvisibleBarrier.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("payphone", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Payphone.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("spinner", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Spinner.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("rotateSpinner", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? RotateSpinner.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("trackSpinner", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? TrackSpinner.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("towerViewer", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? TowerViewer.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("foregroundDebris", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = !background?ForegroundDebris.FromElement(child) : null;
                    }
                    else if (background)
                    {
                        Console.WriteLine(child.Name);
                    }
                    if (entity != null)
                    {
                        ents.Add(entity);
                    }
                }

                ents.Sort(delegate(Entity one, Entity two) {
                    int comp = two.Depth.CompareTo(one.Depth);
                    return(comp == 0 ? one.ID.CompareTo(two.ID) : comp);
                });

                for (int i = 0; i < ents.Count; i++)
                {
                    Entity entity = ents[i];
                    entity.Render(g, solids);
                }
            }
        }