Skip to content

Commit

Permalink
Add possibility to specify which maps Rainbow Berries take into account
Browse files Browse the repository at this point in the history
  • Loading branch information
maddie480 committed Oct 9, 2022
1 parent 3c2433d commit 14b6b8e
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Ahorn/entities/rainbowBerry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module CollabUtils2RainbowBerry

using ..Ahorn, Maple

@mapdef Entity "CollabUtils2/RainbowBerry" RainbowBerry(x::Integer, y::Integer, levelSet::String="SpringCollab2020/1-Beginner")
@mapdef Entity "CollabUtils2/RainbowBerry" RainbowBerry(x::Integer, y::Integer, levelSet::String="SpringCollab2020/1-Beginner", maps::String="")

const placements = Ahorn.PlacementDict(
"Rainbow Berry (Collab Utils 2 / READ DOCS)" => Ahorn.EntityPlacement(
Expand Down
7 changes: 6 additions & 1 deletion Ahorn/lang/en_gb.lang
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Chapter Panel Trigger
# Chapter Panel Trigger
placements.triggers.CollabUtils2/ChapterPanelTrigger.tooltips.map=The SID (string ID) of the map that will be entered with the trigger.
placements.triggers.CollabUtils2/ChapterPanelTrigger.tooltips.returnToLobbyMode=Determines how "Return to Lobby" will behave after entering this map.\n- SetReturnToHere: the Return to Lobby button will return the player to the nearest spawn point in the current map.\n- RemoveReturn: the Return to Lobby button will disappear from the pause menu.\n- DoNotChangeReturn: the current Return to Lobby button will not be changed.
placements.triggers.CollabUtils2/ChapterPanelTrigger.tooltips.allowSaving=If selected, the player will be allowed to save and return to the lobby in the map this trigger teleports to, by selecting "Save" when returning to lobby. Not compatible with maps that have checkpoints.
Expand All @@ -24,6 +24,7 @@ placements.entities.CollabUtils2/FakeMiniHeart.tooltips.particleColor=The color

# Rainbow Berry
placements.entities.CollabUtils2/RainbowBerry.tooltips.levelSet=The rainbow berry will only spawn if all silver berries in this level set have been collected.
placements.entities.CollabUtils2/RainbowBerry.tooltips.maps=This setting allows to restrict which maps in the level set this rainbow berry takes into account. To do this, list the map names (.bin names only) separated by commas.\nLeave empty if you want the player to collect all silver berries in the level set to make the rainbow berry spawn.

# Mini Heart Door
placements.entities.CollabUtils2/MiniHeartDoor.tooltips.requires=Determines the number of Crystal Hearts required to open the heart door. Counts hearts within the level set specified in the "Level Set" attribute.
Expand All @@ -44,3 +45,7 @@ placements.entities.CollabUtils2/SpeedBerry.tooltips.bronzeTime=The time (in sec

# Mini Heart Door Unlock Cutscene Trigger
placements.triggers.CollabUtils2/MiniHeartDoorUnlockCutsceneTrigger.tooltips.doorID=The ID of the door this cutscene should unlock. Only useful if you have multiple heart doors in the same lobby, otherwise you can leave that empty.

# Rainbow Berry Unlock Cutscene Trigger
placements.triggers.CollabUtils2/RainbowBerryUnlockCutsceneTrigger.tooltips.levelSet=If you have multiple rainbow berries in the same lobby, copy the "Level Set" setting of the rainbow berry this trigger should affect here.\nIf you only have one rainbow berry in the lobby, you don't need to fill out this field.
placements.triggers.CollabUtils2/RainbowBerryUnlockCutsceneTrigger.tooltips.maps=If you have multiple rainbow berries in the same lobby, copy the "Maps" setting of the rainbow berry this trigger should affect here.\nIf you only have one rainbow berry in the lobby, you don't need to fill out this field.
3 changes: 2 additions & 1 deletion Ahorn/triggers/rainbowBerryUnlockCutsceneTrigger.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module CollabUtils2RainbowBerryUnlockCutsceneTrigger

using ..Ahorn, Maple

@mapdef Trigger "CollabUtils2/RainbowBerryUnlockCutsceneTrigger" RainbowBerryUnlockCutsceneTrigger(x::Integer, y::Integer, width::Integer=Maple.defaultTriggerWidth, height::Integer=Maple.defaultTriggerHeight)
@mapdef Trigger "CollabUtils2/RainbowBerryUnlockCutsceneTrigger" RainbowBerryUnlockCutsceneTrigger(x::Integer, y::Integer,
width::Integer=Maple.defaultTriggerWidth, height::Integer=Maple.defaultTriggerHeight, levelSet::String="", maps::String="")

const placements = Ahorn.PlacementDict(
"Rainbow Berry Unlock Cutscene (Collab Utils 2 / READ DOCS)" => Ahorn.EntityPlacement(
Expand Down
55 changes: 47 additions & 8 deletions Entities/RainbowBerry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Monocle;
using MonoMod.Utils;
using System.Collections.Generic;
using System.Linq;

namespace Celeste.Mod.CollabUtils2.Entities {
/// <summary>
Expand All @@ -11,13 +12,27 @@ namespace Celeste.Mod.CollabUtils2.Entities {
[CustomEntity("CollabUtils2/RainbowBerry")]
[RegisterStrawberry(tracked: false, blocksCollection: false)]
public class RainbowBerry : Strawberry {
private string levelSet;
private readonly string levelSet;
private readonly string mapsRaw;
private readonly string[] maps;

internal HoloRainbowBerry HologramForCutscene;
internal int CutsceneTotalBerries;

public RainbowBerry(EntityData data, Vector2 offset, EntityID gid) : base(data, offset, gid) {
levelSet = data.Attr("levelSet");

if (string.IsNullOrEmpty(data.Attr("maps"))) {
maps = null;
mapsRaw = null;
} else {
maps = data.Attr("maps").Split(',');
mapsRaw = data.Attr("maps");

for (int i = 0; i < maps.Length; i++) {
maps[i] = levelSet + "/" + maps[i];
}
}
}

public override void Added(Scene scene) {
Expand All @@ -29,13 +44,17 @@ public override void Added(Scene scene) {

if (CollabMapDataProcessor.SilverBerries.ContainsKey(levelSet)) {
int missingBerries = 0;
int totalBerries = CollabMapDataProcessor.SilverBerries[levelSet].Count;
int totalBerries = 0;
foreach (KeyValuePair<string, EntityID> requiredSilver in CollabMapDataProcessor.SilverBerries[levelSet]) {
// check if the silver was collected.
AreaStats stats = SaveData.Instance.GetAreaStatsFor(AreaData.Get(requiredSilver.Key).ToKey());
if (!stats.Modes[0].Strawberries.Contains(requiredSilver.Value)) {
// this berry wasn't collected!
missingBerries++;
if (maps == null || maps.Contains(requiredSilver.Key)) {
totalBerries++;

// check if the silver was collected.
AreaStats stats = SaveData.Instance.GetAreaStatsFor(AreaData.Get(requiredSilver.Key).ToKey());
if (!stats.Modes[0].Strawberries.Contains(requiredSilver.Value)) {
// this berry wasn't collected!
missingBerries++;
}
}
}

Expand All @@ -47,7 +66,7 @@ public override void Added(Scene scene) {
RemoveSelf();
} else {
// all berries are here! check if we should play the unlock cutscene.
if (!CollabModule.Instance.SaveData.CombinedRainbowBerries.Contains((scene as Level).Session.Area.GetSID())) {
if (!CollabModule.Instance.SaveData.CombinedRainbowBerries.Contains(GetCombinedRainbowId(scene as Level))) {
// spawn the hologram for the animation...
HoloRainbowBerry hologram = new HoloRainbowBerry(Position, totalBerries, totalBerries);
hologram.Tag = Tags.FrozenUpdate;
Expand All @@ -65,5 +84,25 @@ public override void Added(Scene scene) {
}
}
}

public string GetCombinedRainbowId(Level level) {
if (maps != null) {
return string.Join(",", maps);
} else {
return level.Session.Area.GetSID();
}
}

public bool MatchesRainbowBerryTriggerWithSettings(string levelSet, string maps) {
if (!string.IsNullOrEmpty(levelSet) && this.levelSet != levelSet) {
return false;
}

if (!string.IsNullOrEmpty(maps) && this.mapsRaw != maps) {
return false;
}

return true;
}
}
}
1 change: 1 addition & 0 deletions Loenn/entities/rainbowBerry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ rainbowBerry.placements = {
name = "default",
data = {
levelSet = "SpringCollab2020/1-Beginner",
maps = ""
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions Loenn/lang/en_gb.lang
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ entities.CollabUtils2/MiniHeartDoor.attributes.description.doorID=An identifier
# Rainbow Berry
entities.CollabUtils2/RainbowBerry.placements.name.default=Rainbow Berry
entities.CollabUtils2/RainbowBerry.attributes.description.levelSet=The rainbow berry will only spawn if all silver berries in this level set have been collected.
entities.CollabUtils2/RainbowBerry.attributes.description.maps=This setting allows to restrict which maps in the level set this rainbow berry takes into account. To do this, list the map names (.bin names only) separated by commas.\nLeave empty if you want the player to collect all silver berries in the level set to make the rainbow berry spawn.

# Silver Berry
entities.CollabUtils2/SilverBerry.placements.name.default=Silver Berry
Expand Down Expand Up @@ -61,6 +62,8 @@ triggers.CollabUtils2/MiniHeartDoorUnlockCutsceneTrigger.attributes.description.

# Rainbow Berry Unlock Cutscene Trigger
triggers.CollabUtils2/RainbowBerryUnlockCutsceneTrigger.placements.name.default=Rainbow Berry Unlock Cutscene
triggers.CollabUtils2/RainbowBerryUnlockCutsceneTrigger.attributes.description.levelSet=If you have multiple rainbow berries in the same lobby, copy the "Level Set" setting of the rainbow berry this trigger should affect here.\nIf you only have one rainbow berry in the lobby, you don't need to fill out this field.
triggers.CollabUtils2/RainbowBerryUnlockCutsceneTrigger.attributes.description.maps=If you have multiple rainbow berries in the same lobby, copy the "Maps" setting of the rainbow berry this trigger should affect here.\nIf you only have one rainbow berry in the lobby, you don't need to fill out this field.

# Silver Berry Collect Trigger
triggers.CollabUtils2/SilverBerryCollectTrigger.placements.name.default=Silver Berry Collect
Expand Down
6 changes: 5 additions & 1 deletion Loenn/triggers/rainbowBerryUnlockCutscene.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ local trigger = {}
trigger.name = "CollabUtils2/RainbowBerryUnlockCutsceneTrigger"
trigger.placements = {
{
name = "default"
name = "default",
data = {
levelSet = "",
maps = ""
}
}
}

Expand Down
22 changes: 19 additions & 3 deletions Triggers/RainbowBerryUnlockCutsceneTrigger.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
using Celeste.Mod.CollabUtils2.Entities;
using Celeste.Mod.Entities;
using Microsoft.Xna.Framework;
using Monocle;
using System.Linq;

namespace Celeste.Mod.CollabUtils2.Triggers {
[CustomEntity("CollabUtils2/RainbowBerryUnlockCutsceneTrigger")]
class RainbowBerryUnlockCutsceneTrigger : Trigger {
public RainbowBerryUnlockCutsceneTrigger(EntityData data, Vector2 offset) : base(data, offset) { }
private RainbowBerry berry;

private readonly string levelSet;
private readonly string maps;

public RainbowBerryUnlockCutsceneTrigger(EntityData data, Vector2 offset) : base(data, offset) {
levelSet = data.Attr("levelSet");
maps = data.Attr("maps");
}

public override void Awake(Scene scene) {
base.Awake(scene);

berry = Scene.Entities.OfType<RainbowBerry>()
.Where(b => b.MatchesRainbowBerryTriggerWithSettings(levelSet, maps))
.FirstOrDefault();
}

public override void OnEnter(Player player) {
base.OnEnter(player);

RainbowBerry berry = Scene.Entities.OfType<RainbowBerry>().FirstOrDefault();
if (berry != null && berry.HologramForCutscene != null && player != null) {
// spawn the unlock cutscene.
Scene.Add(new RainbowBerryUnlockCutscene(berry, berry.HologramForCutscene, berry.CutsceneTotalBerries));
Expand All @@ -20,7 +36,7 @@ public override void OnEnter(Player player) {
berry.HologramForCutscene = null;

// save that the cutscene happened so that it doesn't happen again.
CollabModule.Instance.SaveData.CombinedRainbowBerries.Add((Scene as Level).Session.Area.GetSID());
CollabModule.Instance.SaveData.CombinedRainbowBerries.Add(berry.GetCombinedRainbowId(Scene as Level));
}

// this trigger is one-use.
Expand Down
2 changes: 1 addition & 1 deletion everest.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- Name: CollabUtils2
Version: 1.6.15
Version: 1.6.16
DLL: bin/Debug/net452/CollabUtils2.dll
Dependencies:
- Name: Everest
Expand Down

0 comments on commit 14b6b8e

Please sign in to comment.