Last active
March 2, 2024 20:19
-
-
Save fdrobidoux/b226f2b857d855404e140fb0428e1658 to your computer and use it in GitHub Desktop.
AdA2 - Idea for making better events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Ada2.Engine.Services; | |
using Ada2.RpgModule.Scripting; | |
using Ada2.RpgModule.Services.Abstractions; | |
using Monofoxe.Engine.EC; | |
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Ada2.RpgModule.Maps | |
{ | |
public abstract class ComplexRpgEvent | |
{ | |
protected readonly IPlayerService playerService = ModuleManager.Module.Services.GetService<IPlayerService>(); | |
public string Name { get; protected init; } | |
public int Page { get; protected init; } | |
public Entity Entity { get; protected init; } | |
public virtual void PostBuild(GameMap map) { } | |
public virtual bool? EvaluateConditions() { return null; } | |
public virtual IEnumerator Script(RpgScriptedSequence arg) | |
{ | |
yield return false; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Linq; | |
using System.Reflection; | |
using Ada2.Engine.Scripting; | |
using Ada2.Engine.Scripting.Actions; | |
using Ada2.Engine.Services; | |
using Ada2.Engine.Services.Abstractions; | |
using Ada2.RpgModule.Components.Map.Events; | |
using Ada2.RpgModule.Entities.Map; | |
using Ada2.RpgModule.ExtendedMapBuilder; | |
using Ada2.RpgModule.Helpers; | |
using Ada2.RpgModule.Helpers.Conditions; | |
using Ada2.RpgModule.Scripting; | |
using Ada2.RpgModule.Services.Abstractions; | |
using Ada2.Scripting.Actions; | |
using Monofoxe.Engine; | |
using Monofoxe.Engine.EC; | |
using Monofoxe.Engine.SceneSystem; | |
namespace Ada2.RpgModule.Maps | |
{ | |
[GameMap(Name = "NoriHouse1")] | |
public class NoriHouse1Map : GameMap | |
{ | |
private const string MUSIC_FILENAME = "off_da_wall.ogg"; | |
public NoriHouse1Map(string spawnPoint) : base("NoriHouse1", spawnPoint) | |
{ | |
} | |
protected override void PostBuildSetup() | |
{ | |
base.PostBuildSetup(); | |
//if (musicService.CurrentSongName != MUSIC_FILENAME) | |
//{ | |
// musicService.Stop(); | |
// musicService.Load(MUSIC_FILENAME); | |
// musicService.Play(); | |
//} | |
if (fileSaveManager.CurrentGame.ItemsFound.Contains("coffee")) | |
{ | |
var item = AllItems.FirstOrDefault(x => x.TiledObj.Name == "Coffee"); | |
if (item != null) | |
{ | |
item.Visible = false; | |
item.GetComponent<OnUseEventComponent>().Enabled = false; | |
} | |
} | |
if (fileSaveManager.CurrentGame.ItemsFound.Contains("paper")) | |
{ | |
var item = AllItems.FirstOrDefault(x => x.TiledObj.Name == "Paper"); | |
if (item != null) | |
{ | |
item.Visible = false; | |
item.GetComponent<OnUseEventComponent>().Enabled = false; | |
} | |
} | |
} | |
// | |
// We would do this... | |
// | |
[RpgEvent("TakePlante", 1)] | |
protected class TakePlante_CanBePickedUp : ComplexRpgEvent | |
{ | |
[RpgEventDependency] | |
IFileSaveService fileSaveManager; | |
[RpgEventDependency] | |
IRpgDialogueService dialogueService; | |
[RpgEventDependency] | |
dynamic l18n; | |
public override bool? EvaluateConditions() | |
{ | |
return !this.playerService.CurrentGame.ItemsFound.Contains("fougere"); | |
} | |
public override IEnumerator Script(RpgScriptedSequence arg) | |
{ | |
if (fileSaveManager.CurrentGame.ItemsFound.Contains("fougere")) | |
yield return false; | |
dialogueService.BeginDialogue(l18n.PLANT.NORI_1); | |
yield return GenericActions.WaitFor(TimeSpan.FromSeconds(1.5f)); | |
if (arg.Parameters[0] is Item plante1 && arg.Parameters[1] is Item plante2) | |
{ | |
plante1.Visible = false; | |
plante2.Visible = false; | |
} | |
fileSaveManager.CurrentGame.AddItem("fougere"); | |
dialogueService.EndDialogue(); | |
yield return false; | |
} | |
} | |
[RpgEvent("TakePlante", 2)] | |
protected class TakePlante_AfterTaken : ComplexRpgEvent | |
{ | |
public override bool? EvaluateConditions() | |
{ | |
return this.playerService.CurrentGame.ItemsFound.Contains("fougere"); | |
} | |
public override void PostBuild(GameMap map) | |
{ | |
foreach (var item in map.AllItems.Where(x => new[] { "Plante1", "Plante2" }.Contains(x.TiledObj.Name))) | |
item.DestroyEntity(); | |
this.Entity.DestroyEntity(); | |
} | |
public override IEnumerator Script(RpgScriptedSequence arg) | |
{ | |
yield return false; | |
} | |
} | |
// | |
// Instead of this... | |
// | |
[RpgEvent("TakePlante")] | |
[ItemWasFoundCondition("fougere", false)] | |
IEnumerator TakePlante(RpgScriptedSequence arg) | |
{ | |
if (fileSaveManager.CurrentGame.ItemsFound.Contains("fougere")) | |
yield return false; | |
dialogueService.BeginDialogue(l18n.PLANT.NORI_1); | |
yield return GenericActions.WaitFor(TimeSpan.FromSeconds(1.5f)); | |
if (arg.Parameters[0] is Item plante1 && arg.Parameters[1] is Item plante2) | |
{ | |
plante1.Visible = false; | |
plante2.Visible = false; | |
} | |
fileSaveManager.CurrentGame.AddItem("fougere"); | |
dialogueService.EndDialogue(); | |
yield return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment