diff --git a/build.cmd b/build.cmd new file mode 100644 index 00000000..6b11cb56 --- /dev/null +++ b/build.cmd @@ -0,0 +1 @@ +dotnet build diff --git a/run.cmd b/run.cmd new file mode 100644 index 00000000..4e77cbf2 --- /dev/null +++ b/run.cmd @@ -0,0 +1 @@ +dotnet run --project ./src/MagiRogue diff --git a/src/Arquimedes/Data/Spells/spells_alteration.json b/src/Arquimedes/Data/Spells/spells_alteration.json new file mode 100644 index 00000000..bc182503 --- /dev/null +++ b/src/Arquimedes/Data/Spells/spells_alteration.json @@ -0,0 +1,42 @@ +[ + { + "Id": "raise_wall", + "ShapingAbility": "Mana Shaping", + "Name": "Raise wall", + "SpellLevel": 2, + "Description": "This spell raises a wall at the desired location, it uses the material found on the floor to raise this wall", + "SpellRange": 4, + "MagicCost": 7, + "MagicArt": "Alteration", + "Effects": [ + { + "AreaOfEffect": "Target", + "EffectType": "RAISEWALL", + "TargetsTile": true, + "IgnoresWall": true + } + ], + "Manifestation": "Instant", + "Context": ["Terraforming", "BlocksSight"] + }, + { + "Id": "dig", + "ShapingAbility": "Mana Shaping", + "Name": "Dig", + "SpellLevel": 2, + "Description": "This spell transmutates the targeted wall into rubble", + "SpellRange": 4, + "MagicCost": 7, + "MagicArt": "Alteration", + "Effects": [ + { + "AreaOfEffect": "Target", + "EffectType": "DIG", + "TargetsTile": true, + "IgnoresWall": true + } + ], + "Manifestation": "Instant", + "Context": ["Terraforming", "Dig"] + } +] diff --git a/src/Arquimedes/Data/Spells/spells_dimensionalism.json b/src/Arquimedes/Data/Spells/spells_dimensionalism.json index eaf61657..f722abce 100644 --- a/src/Arquimedes/Data/Spells/spells_dimensionalism.json +++ b/src/Arquimedes/Data/Spells/spells_dimensionalism.json @@ -4,7 +4,7 @@ "ShapingAbility": "Mana Shaping", "Effects": [ { - "AreaOfEffect": "Target", + "AreaOfEffect": "TargetSelf", "Radius": 0, "TargetsTile": true, "EffectType": "TELEPORT", diff --git a/src/Arquimedes/Enumerators/SpellAreaEffect.cs b/src/Arquimedes/Enumerators/SpellAreaEffect.cs index ef09b159..685e1df5 100644 --- a/src/Arquimedes/Enumerators/SpellAreaEffect.cs +++ b/src/Arquimedes/Enumerators/SpellAreaEffect.cs @@ -22,6 +22,10 @@ public enum SpellAreaEffect /// Target, /// + /// Applies the effect to the caster at the specified target location (e.g., teleporting the caster to a tile). + /// + TargetSelf, + /// /// Targets everything in a circle radius /// Ball, diff --git a/src/Arquimedes/Enumerators/SpellContext.cs b/src/Arquimedes/Enumerators/SpellContext.cs index b2e1e145..f9d495d8 100644 --- a/src/Arquimedes/Enumerators/SpellContext.cs +++ b/src/Arquimedes/Enumerators/SpellContext.cs @@ -14,6 +14,9 @@ public enum SpellContext Buff, Debuff, Teleport, - Distance + Distance, + Terraforming, + Dig, + BlocksSight, } } diff --git a/src/Arquimedes/Enumerators/EffectType.cs b/src/Arquimedes/Enumerators/SpellEffectType.cs similarity index 78% rename from src/Arquimedes/Enumerators/EffectType.cs rename to src/Arquimedes/Enumerators/SpellEffectType.cs index f1e943ed..477bda83 100644 --- a/src/Arquimedes/Enumerators/EffectType.cs +++ b/src/Arquimedes/Enumerators/SpellEffectType.cs @@ -1,6 +1,6 @@ namespace Arquimedes.Enumerators { - public enum EffectType + public enum SpellEffectType { DAMAGE, MEMISSION, @@ -13,5 +13,7 @@ public enum EffectType KNOCKBACK, LIGHT, KINESIS, + RAISEWALL, + DIG } -} \ No newline at end of file +} diff --git a/src/Arquimedes/Enumerators/TargetState.cs b/src/Arquimedes/Enumerators/TargetState.cs index 3c7fefad..70143693 100644 --- a/src/Arquimedes/Enumerators/TargetState.cs +++ b/src/Arquimedes/Enumerators/TargetState.cs @@ -2,8 +2,9 @@ { public enum TargetState { + IdleMode, LookMode, TargetingSpell, TargetingItem, } -} \ No newline at end of file +} diff --git a/src/Arquimedes/Utils/FileUtils.cs b/src/Arquimedes/Utils/FileUtils.cs index 46c325fc..fc967bb0 100644 --- a/src/Arquimedes/Utils/FileUtils.cs +++ b/src/Arquimedes/Utils/FileUtils.cs @@ -18,7 +18,7 @@ public static string[] GetFiles(string wildCard) // Get absolutepath string absPath = Path.GetFullPath(Path.Combine(_appDomain, realDir)).Replace('\\', Path.DirectorySeparatorChar); - return Directory.GetFiles(absPath, pattern, SearchOption.AllDirectories); + return Directory.GetFiles(absPath, pattern, SearchOption.TopDirectoryOnly); } public static string? GetAllTextFromFile(FileInfo file) @@ -49,21 +49,21 @@ public static List GetSourceTreeList(string wildCard) try { Parallel.ForEach(files, file => - { - try - { + { + try + { foreach (T? item in JsonUtils.JsonDeseralize>(file)!) { - result.Add(item); + result.Add(item); } - } - catch (System.Exception ex) - { + } + catch (System.Exception ex) + { System.Console.WriteLine($"Something went wrong {ex}"); return; - } - }); + } + }); } catch (System.Exception ex) { diff --git a/src/Diviner/KeyboardHandle.cs b/src/Diviner/KeyboardHandle.cs index 6b1d6f32..a70571cd 100644 --- a/src/Diviner/KeyboardHandle.cs +++ b/src/Diviner/KeyboardHandle.cs @@ -1,25 +1,23 @@ +using System.Diagnostics.CodeAnalysis; using Arquimedes.Enumerators; using Diviner.Windows; using MagusEngine; using MagusEngine.Actions; using MagusEngine.Bus.MapBus; using MagusEngine.Bus.UiBus; +using MagusEngine.Components.EntityComponents; +using MagusEngine.Components.EntityComponents.Ai; using MagusEngine.Core.Entities; using MagusEngine.Core.Magic; using MagusEngine.Core.MapStuff; -using MagusEngine.Components.EntityComponents; -using MagusEngine.Components.EntityComponents.Ai; -using MagusEngine.Serialization.MapConverter; +using MagusEngine.Exceptions; using MagusEngine.Services; using MagusEngine.Systems; using MagusEngine.Systems.Time; using MagusEngine.Utils.Extensions; -using Newtonsoft.Json; using SadConsole.Input; using SadRogue.Primitives; -using System.Diagnostics.CodeAnalysis; using Color = SadRogue.Primitives.Color; -using MagusEngine.Exceptions; namespace Diviner { @@ -110,30 +108,26 @@ private static bool HandleMove(Keyboard info, Universe world, UIManager ui) } #endregion WorldMovement - - foreach (Keys key in _movementDirectionMapping.Keys) + if (world.CurrentMap is null) + return false; + var key = _movementDirectionMapping.Keys.FirstOrDefault(info.IsKeyPressed); + if (_movementDirectionMapping.TryGetValue(key, out var moveDirection)) { - if (info.IsKeyPressed(key) && world.CurrentMap is not null) + Point deltaMove = new(moveDirection.DeltaX, moveDirection.DeltaY); + var actor = (Actor)world.CurrentMap.ControlledEntitiy!; + if (world.CurrentMap.ControlledEntitiy is not Player) { - Direction moveDirection = _movementDirectionMapping[key]; - Point deltaMove = new(moveDirection.DeltaX, moveDirection.DeltaY); - var actor = (Actor)world.CurrentMap.ControlledEntitiy!; - if (world.CurrentMap.ControlledEntitiy is not Player) - { - if (world.CurrentMap.CheckForIndexOutOfBounds(world.CurrentMap.ControlledEntitiy!.Position + deltaMove)) - return false; - - int distance = HandleNonPlayerMoveAndReturnDistance(world, deltaMove); + if (world.CurrentMap.CheckForIndexOutOfBounds(world.CurrentMap.ControlledEntitiy!.Position + deltaMove)) + return false; - return world.CurrentMap.PlayerExplored[world.CurrentMap.ControlledEntitiy.Position + deltaMove] - && distance <= _targetCursor?.MaxDistance - && actor!.MoveBy(deltaMove); - } + int distance = HandleNonPlayerMoveAndReturnDistance(world, deltaMove); - return actor!.MoveBy(deltaMove); + return world.CurrentMap.PlayerExplored[world.CurrentMap.ControlledEntitiy.Position + deltaMove] + && distance <= _targetCursor?.MaxDistance + && actor!.MoveBy(deltaMove); } + return actor!.MoveBy(deltaMove); } - return false; } @@ -299,7 +293,7 @@ private static bool HandleActions(Keyboard info, Universe uni, UIManager ui) { (sucess, var item) = _targetCursor.EndItemTargetting(); if (sucess) - timeTaken = TimeHelper.GetShootingTime(_getPlayer, item.Mass); + timeTaken = TimeHelper.GetShootingTime(_getPlayer, item!.Mass); } if (sucess) { @@ -351,6 +345,19 @@ private static bool HandleDebugActions(Keyboard info, Universe uni, UIManager ui return false; } + if (info.IsKeyPressed(Keys.F2)) + { + uni!.CurrentMap!.ForceFovCalculation(); + return false; + } + + if (info.IsKeyPressed(Keys.K) && _targetCursor?.TileInTarget() == true) + { + Tile tile = uni!.CurrentMap!.GetTileAt(_targetCursor.Position)!; + tile!.IsTransparent = !tile.IsTransparent; + return false; + } + if (info.IsKeyPressed(Keys.F8)) { uni!.CurrentMap!.ControlledEntitiy!.AddComponents(new TestComponent()); @@ -437,34 +444,6 @@ private static bool HandleDebugActions(Keyboard info, Universe uni, UIManager ui return false; } - if (info.IsKeyPressed(Keys.OemPlus)) - { - MagiMap map = (MagiMap)_getPlayer.CurrentMap!; - map.LastPlayerPosition = _getPlayer.Position; - if (Find.Universe.MapIsWorld(map)) - { - string json = JsonConvert.SerializeObject(Find.Universe.WorldMap); - - Locator.GetService().SaveJsonToSaveFolder(json); - } - else - { - string json = map.SaveMapToJson(_getPlayer); - - // The universe class also isn't being serialized properly, crashing newtonsoft - // TODO: Revise this line of code when the time comes to work on the save system. - //var gameState = JsonConvert.SerializeObject(new GameState().Universe); - // MapTemplate mapDeJsonified = JsonConvert.DeserializeObject(json)!; - } - return false; - } - - if (info.IsKeyPressed(Keys.OemMinus)) - { - Locator.GetService().SaveGameToFolder(Find.Universe, "TestFile"); - return false; - } - if (info.IsKeyPressed(Keys.P) && (_targetCursor?.EntityInTarget()) == true) { var target = _targetCursor.TargetEntity(); diff --git a/src/Diviner/Windows/LookWindow.cs b/src/Diviner/Windows/LookWindow.cs index 90581674..992be586 100644 --- a/src/Diviner/Windows/LookWindow.cs +++ b/src/Diviner/Windows/LookWindow.cs @@ -1,6 +1,7 @@ -using MagusEngine.Core.Entities.Base; +using System.Text; +using MagusEngine.Components.TilesComponents; +using MagusEngine.Core.Entities.Base; using MagusEngine.Core.MapStuff; -using System.Text; using Console = SadConsole.Console; namespace Diviner.Windows @@ -14,13 +15,7 @@ public class LookWindow : PopWindow public LookWindow(MagiEntity entity) : base(entity.Name) { entityLooked = entity; - - lookConsole = new Console(Width - ButtonWidth - 4, Height - 4) - { - Position = new Point(ButtonWidth + 2, 1) - }; - - lookConsole.Cursor.Position = new Point(1, 1); + lookConsole = CreateLookConsole(); StringBuilder desc = new(); if (entity.Description is not null) { @@ -29,6 +24,10 @@ public LookWindow(MagiEntity entity) : base(entity.Name) desc.Append(entity.GetCurrentStatus()); lookConsole.Cursor.Print(entity.Description); } +#if DEBUG + desc.Append("ID: ").Append(entity.ID).AppendLine(); +#endif + desc.Append("Position: ").AppendLine(entity.Position.ToString()); Children.Add(lookConsole); } @@ -36,17 +35,55 @@ public LookWindow(Tile tile) : base(tile.Name) { tileLooked = tile; - lookConsole = new Console(Width - ButtonWidth - 4, Height - 4) - { - Position = new Point(ButtonWidth + 2, 1) - }; + lookConsole = CreateLookConsole(); - lookConsole.Cursor.Position = new Point(1, 1); + StringBuilder desc = new(); if (tile.Description is not null) { - lookConsole.Cursor.Print(tile.Description); + desc.Append(tile.Description).AppendLine(); } + desc.Append("This is made of: ").Append(tile.Material.Name).AppendLine(); +#if DEBUG + desc.Append("ID: ").Append(tile.ID).AppendLine(); +#endif + if (tile.IsTransparent) + desc.Append("This tile is transparent").AppendLine(); + else + desc.Append("This tile doesn't lets light though").AppendLine(); + if (tile.IsWalkable) + desc.Append("This tile is walkable").AppendLine(); + else + desc.Append("This tile isn't walkable").AppendLine(); + if (tile.Traits?.Count > 0) + { + desc.AppendLine("This tile has the following properties:"); + foreach (var trait in tile.Traits) + { + desc.Append(trait.ToString()).AppendLine(); + } + } + if (tile!.GetComponent(out var vegetation)) + { + desc.Append("Tile has the following vegetation: ").Append(vegetation!.Plant.Name).AppendLine(); + } + if (tile.GetComponent(out var water)) + { + desc.Append("This looks to have ").Append(water?.Depth).Append(" depth").AppendLine(); + } + desc.Append("Position: ").AppendLine(tile.Position.ToString()); + lookConsole.Cursor.Print(desc.ToString()); Children.Add(lookConsole); } + + private Console CreateLookConsole() + { + var console = new Console(Width - 2, Height - 3) + { + Position = new Point(1, 1), + }; + + console.Cursor.Position = new Point(0, 0); + return console; + } } } diff --git a/src/MagusEngine/Bus/MapBus/ChangeControlledEntitiy.cs b/src/MagusEngine/Bus/MapBus/ChangeControlledEntitiy.cs index ac68de53..8ca78c3c 100644 --- a/src/MagusEngine/Bus/MapBus/ChangeControlledEntitiy.cs +++ b/src/MagusEngine/Bus/MapBus/ChangeControlledEntitiy.cs @@ -1,9 +1,4 @@ using MagusEngine.Core.Entities.Base; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace MagusEngine.Bus.MapBus { diff --git a/src/MagusEngine/Bus/UiBus/AddMessageLog.cs b/src/MagusEngine/Bus/UiBus/AddMessageLog.cs index 0498a638..f06e8e10 100644 --- a/src/MagusEngine/Bus/UiBus/AddMessageLog.cs +++ b/src/MagusEngine/Bus/UiBus/AddMessageLog.cs @@ -1,4 +1,6 @@ using Arquimedes.Enumerators; +using MagusEngine.Core.Entities.Base; +using MagusEngine.Systems; using MagusEngine.Utils.Extensions; namespace MagusEngine.Bus.UiBus @@ -16,6 +18,14 @@ public AddMessageLog(string message, bool playerSees = true, PointOfView firstOr Person = firstOrThirdPerson; } + public AddMessageLog(string message, MagiEntity? entity, PointOfView firstOrThirdPerson = PointOfView.First) + { + Message = message; + if (Find.ControlledEntity is not null && entity is not null) + PlayerCanSee = Find.ControlledEntity.CanSee(entity!.Position); + Person = firstOrThirdPerson; + } + public AddMessageLog(string message, Point playerPoint, Point actionPoint, int playerFieldOfView, PointOfView firstOrThirdPerson = PointOfView.First) { Message = message; diff --git a/src/MagusEngine/Components/BaseEffectComponent.cs b/src/MagusEngine/Components/BaseEffectComponent.cs index edbba48a..770f3d2c 100644 --- a/src/MagusEngine/Components/BaseEffectComponent.cs +++ b/src/MagusEngine/Components/BaseEffectComponent.cs @@ -75,9 +75,9 @@ protected virtual void GetTime_TurnPassed(object? sender, TimeDefSpan e) { if (Execution == ExecutionType.OnEnd) ExecuteEffect(); - Parent?.RemoveComponent(this); if (!RemoveMessage.IsNullOrEmpty()) - Locator.GetService()?.SendMessage(new(RemoveMessage!, Parent == Find.Universe.Player)); + Locator.GetService()?.SendMessage(new(RemoveMessage!, Parent)); + Parent?.RemoveComponent(this); Find.Universe.Time.TurnPassed -= GetTime_TurnPassed; _isActive = false; return; diff --git a/src/MagusEngine/Core/Entities/Actor.cs b/src/MagusEngine/Core/Entities/Actor.cs index 51655f28..0ac9181c 100644 --- a/src/MagusEngine/Core/Entities/Actor.cs +++ b/src/MagusEngine/Core/Entities/Actor.cs @@ -481,7 +481,7 @@ public double AttackRange() return 1; // to be implemented item range that permits attacking and stuff! } - public bool CanSee(Point pos) + public override bool CanSee(Point pos) { UpdateFov(); return actorFov.BooleanResultView[pos]; diff --git a/src/MagusEngine/Core/Entities/Base/Anatomy.cs b/src/MagusEngine/Core/Entities/Base/Anatomy.cs index c09b66e9..7fb847f4 100644 --- a/src/MagusEngine/Core/Entities/Base/Anatomy.cs +++ b/src/MagusEngine/Core/Entities/Base/Anatomy.cs @@ -1,3 +1,8 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; using Arquimedes.Enumerators; using GoRogue.Random; using MagusEngine.Actions; @@ -6,12 +11,8 @@ using MagusEngine.Services; using MagusEngine.Systems; using MagusEngine.Utils; +using MagusEngine.Utils.Extensions; using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; namespace MagusEngine.Core.Entities.Base { @@ -96,6 +97,8 @@ public bool CanSee { get { + if (Organs.Count == 0) + return false; return Organs.Exists(o => o.OrganType is OrganType.Visual && o.Working); } } @@ -105,6 +108,8 @@ public bool HasATorso { get { + if (Limbs.Count == 0) + return false; return Limbs.Exists(l => l.LimbType is LimbType.UpperBody && l.Attached); } } @@ -350,14 +355,11 @@ private void ConfigureLimbs(int volume) CalculateTissueVolume(bp); } - foreach (var organ in Organs) + foreach (var organ in Organs.Where(i => !i.InsideOf.IsNullOrEmpty())) { - if (!string.IsNullOrEmpty(organ.InsideOf)) - { - var limb = AllBPs.Find(i => i.Id.Equals(organ.InsideOf)) - ?? throw new ApplicationException($"Something went really wrong! Cound't find the limb for organ {organ.Id} with insides {organ.InsideOf}"); - limb.Insides.Add(organ); - } + var limb = AllBPs.Find(i => i.Id.Equals(organ.InsideOf)) + ?? throw new ApplicationException($"Something went really wrong! Cound't find the limb for organ {organ.Id} with insides {organ.InsideOf}"); + limb.Insides.Add(organ); } } diff --git a/src/MagusEngine/Core/Entities/Base/MagiEntity.cs b/src/MagusEngine/Core/Entities/Base/MagiEntity.cs index 3f53a822..7149c286 100644 --- a/src/MagusEngine/Core/Entities/Base/MagiEntity.cs +++ b/src/MagusEngine/Core/Entities/Base/MagiEntity.cs @@ -1,12 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; using Arquimedes.Interfaces; using MagusEngine.Exceptions; using MagusEngine.Services; using MagusEngine.Systems.Physics; using SadConsole.Entities; using SadRogue.Primitives; -using System; -using System.Collections.Generic; -using System.Diagnostics; namespace MagusEngine.Core.Entities.Base { @@ -198,6 +198,8 @@ public bool MoveTo(Point newPosition, bool ignoreWalkable = false) } } + public virtual bool CanSee(Point pos) => false; + #endregion Methods #region Components diff --git a/src/MagusEngine/Core/Entities/Player.cs b/src/MagusEngine/Core/Entities/Player.cs index 8deecc29..01a0cf2b 100644 --- a/src/MagusEngine/Core/Entities/Player.cs +++ b/src/MagusEngine/Core/Entities/Player.cs @@ -22,7 +22,7 @@ public static Player TestPlayer() var magic = player.GetComponent(); var abb = player.Mind.GetAbility(magic.GetMagicShapingAbility()); - abb.Score = 55; + abb.Score = 65; magic.KnowSpells[0].Proficiency = 1; if (!magic.KnowSpells.Exists(x => x.Id == "magic_missile")) { @@ -48,6 +48,9 @@ public static Player TestPlayer() Spell knockBack = DataManager.QuerySpellInData("push", 1)!; + Spell dig = DataManager.QuerySpellInData("dig", 2)!; + Spell raiseWall = DataManager.QuerySpellInData("raise_wall", 2)!; + magic.AddToSpellList([ cure, haste, @@ -58,7 +61,9 @@ public static Player TestPlayer() teleport, coneOfCold, fingerOfDeath, - knockBack + knockBack, + dig, + raiseWall, ]); return player; diff --git a/src/MagusEngine/Core/Entities/Target.cs b/src/MagusEngine/Core/Entities/Target.cs index f86d937d..4eab55b8 100644 --- a/src/MagusEngine/Core/Entities/Target.cs +++ b/src/MagusEngine/Core/Entities/Target.cs @@ -1,3 +1,6 @@ +using System; +using System.Collections.Generic; +using System.Linq; using Arquimedes.Enumerators; using GoRogue.GameFramework; using GoRogue.Pathing; @@ -7,15 +10,13 @@ using MagusEngine.Core.Entities.Base; using MagusEngine.Core.Magic; using MagusEngine.Core.MapStuff; +using MagusEngine.Exceptions; using MagusEngine.Services; using MagusEngine.Systems; using MagusEngine.Systems.Time; using MagusEngine.Utils; using SadConsole.Effects; using SadRogue.Primitives; -using System; -using System.Collections.Generic; -using System.Linq; namespace MagusEngine.Core.Entities { @@ -78,7 +79,7 @@ public Target(Point spawnCoord) public bool EntityInTarget(bool ignorePlayer = true) { - var entity = Cursor?.CurrentMagiMap?.GetEntitiesAt(Cursor.Position, Cursor.CurrentMagiMap.LayerMasker.MaskAllBelow((int)MapLayer.SPECIAL)).FirstOrDefault(); + var entity = Cursor?.CurrentMagiMap?.GetEntitiesAt(Cursor.Position, Cursor.CurrentMagiMap.LayerMasker.MaskAllBelow((int)MapLayer.PROJECTILE)).FirstOrDefault(); if (entity is null) return false; if (ignorePlayer && entity is Player) @@ -95,7 +96,7 @@ public void OnSelectSpell(Spell spell, Actor caster) if (_selectedSpell.Effects.Any(e => e.AreaOfEffect is SpellAreaEffect.Self)) { var (sucess, s) = EndSpellTargetting(); - Locator.GetService().SendMessage(new(TimeHelper.GetCastingTime(Find.Universe.Player, s), sucess)); + Locator.GetService().SendMessage(new(TimeHelper.GetCastingTime(Find.Universe.Player, s!), sucess)); return; } @@ -129,47 +130,31 @@ public void StartTargetting() Cursor.IgnoresWalls = true; } - // TODO: Customize who should you target public (bool, Spell?) EndSpellTargetting() { bool spellInRange = (int)Distance.Chebyshev.Calculate(OriginCoord, Cursor.Position) <= _selectedSpell?.SpellRange; - if (_selectedSpell?.Manifestation == SpellManifestation.Instant) + if (!spellInRange) { - //if (_selectedSpell?.Effects.Any(e => e.AreaOfEffect is SpellAreaEffect.Beam) == true) - //{ - // return AffectPath(); - //} - //if (_selectedSpell?.Effects.Any(e => e.AreaOfEffect is SpellAreaEffect.Cone) == true) - //{ - // return AffectArea(); - //} - //if (_selectedSpell?.Effects.Any(e => e.AreaOfEffect is SpellAreaEffect.Ball) == true) - //{ - // return AffectArea(); - //} - if (spellInRange) - { - return AffectTarget(); - } + Locator.GetService().SendMessage(new("The target is too far!")); + return (false, null); } - if (spellInRange) + if (_selectedSpell!.Manifestation == SpellManifestation.Instant) { - ActionManager.CastManifestedSpell(_selectedSpell!, _caster, OriginCoord, Cursor.Position); - var spellCasted = _selectedSpell; - EndTargetting(); - return (true, spellCasted); + return AffectTarget(); } - Locator.GetService().SendMessage(new("The target is too far!")); - return (false, null); + ActionManager.CastManifestedSpell(_selectedSpell!, _caster!, OriginCoord, Cursor.Position); + var spellCasted = _selectedSpell; + EndTargetting(); + return (true, spellCasted); } - public (bool, Item) EndItemTargetting() + public (bool, Item?) EndItemTargetting() { int distance = (int)Distance.Chebyshev.Calculate(OriginCoord, Cursor.Position); if (distance <= MaxDistance && _selectedItem is not null) { - ActionManager.ShootProjectileAction(_caster.Position, Cursor.Position, _selectedItem, _caster); + ActionManager.ShootProjectileAction(_caster!.Position, Cursor.Position, _selectedItem, _caster); var item = _selectedItem; EndTargetting(); return (true, item); @@ -181,9 +166,16 @@ public void StartTargetting() private (bool, Spell) AffectTarget() { bool casted; - if (TravelPath is not null) + if (_selectedSpell is null) + throw new NullValueException(nameof(_selectedSpell)); + + if (_selectedSpell.Effects?.Any(i => i.AreaOfEffect == SpellAreaEffect.Self) == true) { - casted = _selectedSpell?.CastSpell(TravelPath.End, _caster!) ?? false; + casted = _selectedSpell.CastSpell(_caster!.Position, _caster); + } + else if (TravelPath is not null) + { + casted = _selectedSpell!.CastSpell(TravelPath.End, _caster!); } else { @@ -203,7 +195,7 @@ public void EndTargetting() _selectedItem = null; _caster = null; - State = TargetState.LookMode; + State = TargetState.IdleMode; if (TravelPath is not null) { @@ -212,7 +204,7 @@ public void EndTargetting() TravelPath = null; } - Locator.GetService().SendMessage(new(_lastControlledEntity)); + Locator.GetService().SendMessage(new(_lastControlledEntity!)); Locator.GetService().SendMessage(new(Cursor)); } } @@ -223,44 +215,13 @@ private void ClearTileDictionary() // if there is anything in the path, clear it foreach (Point point in _tileDictionary.Keys) { - Tile tile = Cursor.CurrentMagiMap.GetTileAt(point); + Tile tile = Cursor!.CurrentMagiMap!.GetTileAt(point)!; if (tile is not null) - tile.Appearence.Background = tile.LastSeenAppereance.Background; + tile.Appearence.Background = tile!.LastSeenAppereance!.Background; } _tileDictionary.Clear(); } - //private (bool, Spell?) AffectArea() - //{ - // if (_selectedSpell.Effects.Any(e => e.Radius > 0)) - // { - // var allPos = new List(); - - // foreach (var entity in TargetList) - // { - // if (entity.CanBeAttacked) - // allPos.Add(entity.Position); - // } - - // if (_selectedSpell.AffectsTile) - // { - // foreach (var pos in _tileDictionary.Keys) - // { - // if (!allPos.Contains(pos)) - // allPos.Add(pos); - // } - // } - - // var sucess = _selectedSpell.CastSpell(allPos, _caster); - // var spell = _selectedSpell; - - // EndTargetting(); - - // return (sucess, spell); - // } - // return (false, null); - //} - /// /// Makes the render and the path to the target /// @@ -268,7 +229,7 @@ private void ClearTileDictionary() /// private void Cursor_Moved(object? sender, ValueChangedEventArgs e) { - if (Cursor is null) + if (Cursor is null || Cursor.CurrentMagiMap is null) return; TravelPath = Cursor.CurrentMagiMap.AStar.ShortestPath(OriginCoord, e.NewValue)!; if (State is TargetState.LookMode || TravelPath is null) @@ -283,22 +244,19 @@ private void Cursor_Moved(object? sender, ValueChangedEventArgs e) foreach (Point pos in TravelPath.Steps) { // gets each point in the travel path steps and change the background of the wall - var halp = Cursor.CurrentMagiMap.GetTileAt(pos); + var halp = Cursor.CurrentMagiMap.GetTileAt(pos)!; halp.Appearence.Background = Color.Yellow; _tileDictionary.TryAdd(pos, halp); } // This loops makes sure that all the pos that aren't in the TravelPath gets it's // proper appearence - foreach (Point item in _tileDictionary.Keys) + foreach (Point item in _tileDictionary.Keys.Where(i => !TravelPath.Steps.Contains(i))) { - if (!TravelPath.Steps.Contains(item)) + Tile llop = Cursor.CurrentMagiMap.GetTileAt(item)!; + if (llop is not null) { - Tile llop = Cursor.CurrentMagiMap.GetTileAt(item); - if (llop is not null) - { - llop.Appearence.Background = llop.LastSeenAppereance.Background; - } + llop.Appearence.Background = llop.LastSeenAppereance!.Background; } } if (_selectedSpell is not null) @@ -321,8 +279,6 @@ public bool TileInTarget() { if (!EntityInTarget() && Cursor?.CurrentMagiMap?.GetTileAt(Cursor.Position) != null) { - //if (!lookMode) - // State = TargetState.TargetingSpell; return true; } return false; @@ -334,7 +290,7 @@ public bool TileInTarget() /// private void AddTileToDictionary(Point point, bool ignoresWall = false) { - var halp = Cursor.CurrentMagiMap.GetTileAt(point); + var halp = Cursor!.CurrentMagiMap!.GetTileAt(point); if (halp is not null && (halp.IsTransparent || ignoresWall)) { halp.Appearence.Background = Color.Yellow; @@ -344,15 +300,21 @@ private void AddTileToDictionary(Point point, bool ignoresWall = false) public void LookTarget() { - if (DetermineWhatToLook() is MagiEntity entity) + var look = DetermineWhatToLook(); + var messageBus = Locator.GetService(); + if (look is MagiEntity entity) + { + messageBus.SendMessage(new(entity)); + } + else if (look is Tile tile) { - Locator.GetService().SendMessage(new(entity)); + messageBus.SendMessage(new(tile)); } } - public MagiEntity? TargetEntity() => Cursor.CurrentMagiMap.GetEntityAt(Cursor.Position); + public MagiEntity? TargetEntity() => Cursor!.CurrentMagiMap!.GetEntityAt(Cursor.Position); - private Tile? TargetAtTile() => Cursor.CurrentMagiMap.GetTileAt(Cursor.Position); + private Tile? TargetAtTile() => Cursor!.CurrentMagiMap!.GetTileAt(Cursor.Position); private IGameObject? DetermineWhatToLook() { diff --git a/src/MagusEngine/Core/Magic/Effects/DamageEffect.cs b/src/MagusEngine/Core/Magic/Effects/DamageEffect.cs index a5c477c9..95bbe3b6 100644 --- a/src/MagusEngine/Core/Magic/Effects/DamageEffect.cs +++ b/src/MagusEngine/Core/Magic/Effects/DamageEffect.cs @@ -20,7 +20,7 @@ public class DamageEffect : SpellEffectBase public DamageEffect() { - EffectType = EffectType.DAMAGE; + EffectType = Arquimedes.Enumerators.SpellEffectType.DAMAGE.ToString(); SpellDamageTypeId = "blunt"; } diff --git a/src/MagusEngine/Core/Magic/Effects/DigEffect.cs b/src/MagusEngine/Core/Magic/Effects/DigEffect.cs new file mode 100644 index 00000000..9dc49e64 --- /dev/null +++ b/src/MagusEngine/Core/Magic/Effects/DigEffect.cs @@ -0,0 +1,22 @@ +using Arquimedes.Enumerators; +using MagusEngine.Bus.UiBus; +using MagusEngine.Core.Entities; +using MagusEngine.Core.MapStuff; +using MagusEngine.Services; + +namespace MagusEngine.Core.Magic.Effects +{ + public class DigEffect : SpellEffectBase + { + public DigEffect() + { + EffectType = SpellEffectType.DIG.ToString(); + } + + public override void ApplyEffect(Point target, Actor caster, Spell spellCasted) + { + if (!TileHelpers.ChangeTileEffect(target, caster, spellCasted.Power, TileType.Floor)) + Locator.GetService().SendMessage(new("Can't make the change to this tile")); + } + } +} diff --git a/src/MagusEngine/Core/Magic/Effects/HasteEffect.cs b/src/MagusEngine/Core/Magic/Effects/HasteEffect.cs index 63944c6f..a110b75e 100644 --- a/src/MagusEngine/Core/Magic/Effects/HasteEffect.cs +++ b/src/MagusEngine/Core/Magic/Effects/HasteEffect.cs @@ -22,7 +22,7 @@ public HasteEffect(SpellAreaEffect areaOfEffect, float hastePower, int duration, SpellDamageTypeId = spellDamageTypeId; HastePower = hastePower; Duration = duration; - EffectType = EffectType.HASTE; + EffectType = Arquimedes.Enumerators.SpellEffectType.HASTE.ToString(); } public override void ApplyEffect(Point target, Actor caster, Spell spellCasted) diff --git a/src/MagusEngine/Core/Magic/Effects/KnockbackEffect.cs b/src/MagusEngine/Core/Magic/Effects/KnockbackEffect.cs index 0eb9f0de..190b7c37 100644 --- a/src/MagusEngine/Core/Magic/Effects/KnockbackEffect.cs +++ b/src/MagusEngine/Core/Magic/Effects/KnockbackEffect.cs @@ -15,7 +15,7 @@ public class KnockbackEffect : SpellEffectBase public KnockbackEffect() { SpellDamageTypeId = "blunt"; - EffectType = EffectType.KNOCKBACK; + EffectType = Arquimedes.Enumerators.SpellEffectType.KNOCKBACK.ToString(); } public override void ApplyEffect(Point target, Actor caster, Spell spellCasted) diff --git a/src/MagusEngine/Core/Magic/Effects/LightEffect.cs b/src/MagusEngine/Core/Magic/Effects/LightEffect.cs index feec92fb..0ae510f1 100644 --- a/src/MagusEngine/Core/Magic/Effects/LightEffect.cs +++ b/src/MagusEngine/Core/Magic/Effects/LightEffect.cs @@ -11,7 +11,7 @@ public class LightEffect : SpellEffectBase public LightEffect() { - EffectType = EffectType.LIGHT; + EffectType = Arquimedes.Enumerators.SpellEffectType.LIGHT.ToString(); } public override void ApplyEffect(Point target, Actor caster, Spell spellCasted) diff --git a/src/MagusEngine/Core/Magic/Effects/MEssionEffect.cs b/src/MagusEngine/Core/Magic/Effects/MEssionEffect.cs index e0816f57..68fcbb4f 100644 --- a/src/MagusEngine/Core/Magic/Effects/MEssionEffect.cs +++ b/src/MagusEngine/Core/Magic/Effects/MEssionEffect.cs @@ -1,11 +1,5 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Arquimedes.Enumerators; using MagusEngine.Core.Entities; -using MagusEngine.Core.Magic.Interfaces; namespace MagusEngine.Core.Magic.Effects { @@ -15,7 +9,7 @@ public class MEssionEffect : SpellEffectBase public MEssionEffect() { - EffectType = EffectType.MEMISSION; + EffectType = Arquimedes.Enumerators.SpellEffectType.MEMISSION.ToString(); } public override void ApplyEffect(Point target, Actor caster, Spell spellCasted) diff --git a/src/MagusEngine/Core/Magic/Effects/MageSightEffect.cs b/src/MagusEngine/Core/Magic/Effects/MageSightEffect.cs index 3a906be6..d86f3fbd 100644 --- a/src/MagusEngine/Core/Magic/Effects/MageSightEffect.cs +++ b/src/MagusEngine/Core/Magic/Effects/MageSightEffect.cs @@ -20,7 +20,7 @@ public MageSightEffect(int duration) { Duration = duration; AreaOfEffect = SpellAreaEffect.Self; - EffectType = EffectType.MAGESIGHT; + EffectType = Arquimedes.Enumerators.SpellEffectType.MAGESIGHT.ToString(); } public override void ApplyEffect(Point target, Actor caster, Spell spellCasted) diff --git a/src/MagusEngine/Core/Magic/Effects/PermEffect.cs b/src/MagusEngine/Core/Magic/Effects/PermEffect.cs index 21b77bb1..fa88150d 100644 --- a/src/MagusEngine/Core/Magic/Effects/PermEffect.cs +++ b/src/MagusEngine/Core/Magic/Effects/PermEffect.cs @@ -12,7 +12,7 @@ public class PermEffect //: IPermEffect // private const int _totalTime = Time.TimeHelper.Year; public int SolidManaCost { get; set; } - public EffectType EffectType { get; set; } + public SpellEffectType EffectType { get; set; } public ISpellEffect Enchantment { get; set; } public Actor Caster { get; set; } public string EnchantName { get; set; } diff --git a/src/MagusEngine/Core/Magic/Effects/RaiseWallEffect.cs b/src/MagusEngine/Core/Magic/Effects/RaiseWallEffect.cs new file mode 100644 index 00000000..db562445 --- /dev/null +++ b/src/MagusEngine/Core/Magic/Effects/RaiseWallEffect.cs @@ -0,0 +1,22 @@ +using Arquimedes.Enumerators; +using MagusEngine.Bus.UiBus; +using MagusEngine.Core.Entities; +using MagusEngine.Core.MapStuff; +using MagusEngine.Services; + +namespace MagusEngine.Core.Magic.Effects +{ + public class RaiseWallEffect : SpellEffectBase + { + public RaiseWallEffect() + { + EffectType = SpellEffectType.RAISEWALL.ToString(); + } + + public override void ApplyEffect(Point target, Actor caster, Spell spellCasted) + { + if (!TileHelpers.ChangeTileEffect(target, caster, spellCasted.Power, TileType.Wall)) + Locator.GetService().SendMessage(new("Can't make the change to this tile")); + } + } +} diff --git a/src/MagusEngine/Core/Magic/Effects/SeverEffect.cs b/src/MagusEngine/Core/Magic/Effects/SeverEffect.cs index 9a3f487d..03cee82d 100644 --- a/src/MagusEngine/Core/Magic/Effects/SeverEffect.cs +++ b/src/MagusEngine/Core/Magic/Effects/SeverEffect.cs @@ -1,6 +1,5 @@ using Arquimedes.Enumerators; using MagusEngine.Core.Entities; -using MagusEngine.Exceptions; using MagusEngine.Systems; using Newtonsoft.Json; @@ -20,7 +19,7 @@ public SeverEffect(SpellAreaEffect areaOfEffect, string spellDamageTypeId, int r SpellDamageTypeId = spellDamageTypeId; Radius = radius; BaseDamage = dmg; - EffectType = EffectType.SEVER; + EffectType = SpellEffectType.SEVER.ToString(); SpellDamageTypeId = "sharp"; } diff --git a/src/MagusEngine/Core/Magic/Effects/TeleportEffect.cs b/src/MagusEngine/Core/Magic/Effects/TeleportEffect.cs index bc42c431..d6206bf6 100644 --- a/src/MagusEngine/Core/Magic/Effects/TeleportEffect.cs +++ b/src/MagusEngine/Core/Magic/Effects/TeleportEffect.cs @@ -3,7 +3,6 @@ using MagusEngine.Bus.UiBus; using MagusEngine.Core.Entities; using MagusEngine.Core.Entities.Base; -using MagusEngine.Core.Magic.Interfaces; using MagusEngine.Services; using Newtonsoft.Json; @@ -21,12 +20,16 @@ public TeleportEffect(SpellAreaEffect areaOfEffect = SpellAreaEffect.Target, SpellDamageTypeId = spellDamageTypeId; Radius = radius; TargetsTile = true; - EffectType = EffectType.TELEPORT; + EffectType = SpellEffectType.TELEPORT.ToString(); } public override void ApplyEffect(Point target, Actor caster, Spell spellCasted) { - var entity = caster?.CurrentMagiMap?.GetEntityAt(target); + var entity = AreaOfEffect switch + { + SpellAreaEffect.TargetSelf => caster, + _ => caster?.CurrentMagiMap?.GetEntityAt(target), + }; if (ActionManager.MoveActorTo(entity, target)) { var entityName = entity.Name ?? "Unknown entity"; diff --git a/src/MagusEngine/Core/Magic/Interfaces/ISpellEffect.cs b/src/MagusEngine/Core/Magic/Interfaces/ISpellEffect.cs index d2e94816..4e2b75e8 100644 --- a/src/MagusEngine/Core/Magic/Interfaces/ISpellEffect.cs +++ b/src/MagusEngine/Core/Magic/Interfaces/ISpellEffect.cs @@ -17,8 +17,7 @@ public interface ISpellEffect double ConeCircleSpan { get; set; } bool TargetsTile { get; set; } int BaseDamage { get; set; } - [JsonConverter(typeof(StringEnumConverter))] - EffectType EffectType { get; set; } + string EffectType { get; set; } bool CanMiss { get; set; } /// diff --git a/src/MagusEngine/Core/Magic/Magic.cs b/src/MagusEngine/Core/Magic/Magic.cs index 1351aa13..4b7371ef 100644 --- a/src/MagusEngine/Core/Magic/Magic.cs +++ b/src/MagusEngine/Core/Magic/Magic.cs @@ -21,7 +21,7 @@ public class Magic : IMagic // Create a magic inspired by Mother of learning public List KnowSpells { get; set; } - public List KnowEffects { get; set; } + public List KnowEffects { get; set; } public List KnowArea { get; set; } public List KnowDamageTypes { get; set; } diff --git a/src/MagusEngine/Core/Magic/Spell.cs b/src/MagusEngine/Core/Magic/Spell.cs index 767653da..a575c259 100644 --- a/src/MagusEngine/Core/Magic/Spell.cs +++ b/src/MagusEngine/Core/Magic/Spell.cs @@ -269,6 +269,9 @@ private void ApplyEffects(Point target, Actor caster, MagiEntity? entity = null) case SpellAreaEffect.Self: effect.ApplyEffect(caster.Position, caster, this); continue; + case SpellAreaEffect.TargetSelf: + effect.ApplyEffect(target, caster, this); + continue; case SpellAreaEffect.Target: entity ??= Find.CurrentMap?.GetEntityAt(target); if (!CanTarget(caster, entity, effect)) diff --git a/src/MagusEngine/Core/Magic/SpellEffectBase.cs b/src/MagusEngine/Core/Magic/SpellEffectBase.cs index 7d190a84..0e805b03 100644 --- a/src/MagusEngine/Core/Magic/SpellEffectBase.cs +++ b/src/MagusEngine/Core/Magic/SpellEffectBase.cs @@ -13,7 +13,7 @@ public abstract class SpellEffectBase : ISpellEffect public int Radius { get; set; } public double ConeCircleSpan { get; set; } public bool TargetsTile { get; set; } - public EffectType EffectType { get; set; } + public string EffectType { get; set; } = null!; // this can't be null public bool CanMiss { get; set; } public bool IsResistable { get; set; } public string? SpellDamageTypeId { get; set; } diff --git a/src/MagusEngine/Core/MapStuff/MagiMap.cs b/src/MagusEngine/Core/MapStuff/MagiMap.cs index 276a3769..52e308c2 100644 --- a/src/MagusEngine/Core/MapStuff/MagiMap.cs +++ b/src/MagusEngine/Core/MapStuff/MagiMap.cs @@ -1,12 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; using Arquimedes.Enumerators; using GoRogue.GameFramework; using GoRogue.Pathing; using GoRogue.Random; +using MagusEngine.Components.TilesComponents; using MagusEngine.Core.Entities; using MagusEngine.Core.Entities.Base; -using MagusEngine.Components.EntityComponents; -using MagusEngine.Components.TilesComponents; using MagusEngine.Serialization.MapConverter; +using MagusEngine.Services.Factory; using MagusEngine.Systems; using MagusEngine.Utils; using MagusEngine.Utils.Extensions; @@ -17,11 +21,6 @@ using SadRogue.Primitives; using SadRogue.Primitives.GridViews; using SadRogue.Primitives.SpatialMaps; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using MagusEngine.Services.Factory; namespace MagusEngine.Core.MapStuff { @@ -30,7 +29,7 @@ namespace MagusEngine.Core.MapStuff /// [DebuggerDisplay("{" + nameof(GetDebuggerDisplay) + "(),nq}")] [JsonConverter(typeof(MapJsonConverter))] - public sealed class MagiMap : GoRogue.GameFramework.Map, IDisposable + public sealed class MagiMap : Map, IDisposable { #region Fields @@ -100,7 +99,7 @@ public MagiMap(string mapName, int width = 60, int height = 60, bool usesWeighEv (int)MapLayer.GHOSTS, (int)MapLayer.ACTORS, (int)MapLayer.PROJECTILE, - (int)MapLayer.SPECIAL)) + (int)MapLayer.SPECIAL), useCachedGridViews: true) { // Treat the fov as a component. GoRogueComponents.Add(new MagiRogueFOVVisibilityHandler(this, Color.DarkSlateGray, (int)MapLayer.GHOSTS)); @@ -174,7 +173,7 @@ public void UpdateRooms() for (int t = 0; t < room.DoorsPoint.Count; t++) { Tile? door = GetTileAt(room.DoorsPoint[t]); - room.Doors.Add(door); + room.Doors.Add(door!); } } } @@ -210,13 +209,13 @@ public Actor[] GetAllActors(Func? actionToRunInActors = null) Actor[] search; if (actionToRunInActors is null) { - search = Entities.GetLayer((int)MapLayer.ACTORS).Items.Cast().ToArray(); + search = [.. Entities.GetLayer((int)MapLayer.ACTORS).Items.Cast()]; } else { - search = Entities.GetLayer((int)MapLayer.ACTORS).Items.Cast().Where(actionToRunInActors).ToArray(); + search = [.. Entities.GetLayer((int)MapLayer.ACTORS).Items.Cast().Where(actionToRunInActors)]; } - _lastCalledActors.TryAdd(actionToRunInActors, search); + _lastCalledActors.TryAdd(actionToRunInActors!, search); return search; } @@ -370,7 +369,7 @@ public T SafeGetEntityById(uint id) where T : IGameObject { return (T)filter.Item; } - return default; + return default!; } public void ConfigureRender(ScreenSurface renderer) @@ -379,7 +378,7 @@ public void ConfigureRender(ScreenSurface renderer) { return; } - EntityRender = new(); + EntityRender = []; renderer.SadComponents.Add(EntityRender); EntityRender.DoEntityUpdate = true; @@ -408,7 +407,6 @@ public string SaveMapToJson(Player player) private void FovCalculate(Actor actor) { - /*if (PlayerFOV.CurrentFOV.Count() >= actor.Stats.ViewRadius)*/ if (actor.ActorAnatomy.CanSee) { PlayerFOV.Calculate(actor.Position, actor.GetViewRadius(), Radius.Circle); @@ -430,7 +428,7 @@ internal void SetSeed(ulong seed) /// public void ForceFovCalculation() { - Actor actor = (Actor)ControlledEntitiy; + Actor actor = (Actor)ControlledEntitiy!; FovCalculate(actor); } @@ -441,7 +439,7 @@ public void ForceFovCalculation() /// Returns an Point to a tile that is walkable and there is no actor there public Point GetRandomWalkableTile() { - var rng = GoRogue.Random.GlobalRandom.DefaultRNG; + var rng = GlobalRandom.DefaultRNG; Point rngPoint = new(rng.NextInt(Width - 1), rng.NextInt(Height - 1)); while (!IsTileWalkable(rngPoint)) @@ -513,7 +511,7 @@ public FastAStar AStarWithAllWalkable() public List ReturnAllTrees() { - List result = new(); + List result = []; foreach (Point p in Terrain.Positions()) { var tree = (Tile?)Terrain[p]; @@ -532,7 +530,7 @@ public List ReturnAllTrees() /// public void AddRoom(Room r) { - Rooms ??= new List(); + Rooms ??= []; int tries = 1000; while (!CheckIfRoomFitsInsideMap(r) && --tries != 0) { @@ -577,7 +575,7 @@ private void FindOtherPlaceForRoom(Room r) /// public void AddRooms(List r) { - Rooms ??= new List(); + Rooms ??= []; Rooms.AddRange(r); } @@ -585,13 +583,13 @@ public void SpawnRoomThingsOnMap(Room r) { Point[] posRoom = r.RoomPoints; - for (int x = 0; x < r.Template.Obj.Rows.Length; x++) + for (int x = 0; x < r!.Template!.Obj!.Rows.Length; x++) { string currentRow = r.Template.Obj.Rows[x]; for (int y = 0; y < currentRow.Length; y++) { char c = currentRow[y]; - Point pos = posRoom[Point.ToIndex(x, y, r.Template.Obj.Rows.Length)]; + Point pos = posRoom[Point.ToIndex(x, y, r!.Template.Obj.Rows.Length)]; if (CheckForIndexOutOfBounds(pos)) { // skip over if not in the map @@ -618,11 +616,11 @@ private void TryToPutFurniture(Point pos, object? fur) } else { - str = fur.ToString(); + str = fur!.ToString()!; } try { - Furniture furniture = DataManager.QueryFurnitureInData(str); + Furniture furniture = DataManager.QueryFurnitureInData(str)!; furniture.Position = pos; AddMagiEntity(furniture); } @@ -645,7 +643,7 @@ private void TryToPutTerrain(Point pos, object? ter) } else { - str = ter.ToString(); + str = ter.ToString()!; } try { @@ -675,7 +673,7 @@ private void TryToPutTerrain(Point pos, object? ter) private static string ParseRandomChance(JArray array) { - List strs = new(); + List strs = []; for (int i = 0; i < array.Count; i++) { var child = array[i]; @@ -794,7 +792,7 @@ public void Dispose() public IGameObject? FindTypeOfFood(Food whatToEat, IGameObject entity) { - const int defaultSearchRange = 25; + // const int defaultSearchRange = 25; throw new NotImplementedException("Lazy"); // var registry = Locator.GetService(); // foreach (var objId in registry.CompView()) @@ -808,7 +806,7 @@ public void Dispose() // } // } - return null; + // return null; } public Tile[] GetAllTilesWithComponents() where TFind : class diff --git a/src/MagusEngine/Core/MapStuff/Tile.cs b/src/MagusEngine/Core/MapStuff/Tile.cs index 6a2e2a8b..8e41e8fe 100644 --- a/src/MagusEngine/Core/MapStuff/Tile.cs +++ b/src/MagusEngine/Core/MapStuff/Tile.cs @@ -15,7 +15,7 @@ public class Tile : MagiGameObject private Material? _material; public ColoredGlyph Appearence { get; } = null!; - public ColoredGlyph? LastSeenAppereance { get; } + public ColoredGlyph? LastSeenAppereance { get; private set; } public int MoveTimeCost { get; set; } = 100; public string? Name { get; set; } public string? Description { get; set; } @@ -43,7 +43,8 @@ public Tile( ? Locator.GetService().UseID : null, collection - ) { } + ) + { } public Tile( Color foreground, @@ -57,7 +58,7 @@ public Tile( : this(isWalkable, isTransparent, pos, collection) { Appearence = new(foreground, background, glyph); - LastSeenAppereance = (ColoredGlyph)Appearence.Clone(); + UpdateLastSeenAppearence(); } public Tile() @@ -92,7 +93,7 @@ public Tile( { SetUpSomeBasicProps(name, idMaterial, moveTimeCost); Appearence = glyph; - LastSeenAppereance = (ColoredGlyph)glyph.Clone(); + UpdateLastSeenAppearence(); } private Tile(Tile tile) @@ -180,5 +181,10 @@ private void SetUpSomeBasicProps(string? name, string idMaterial, int moveTimeCo Name = name; MaterialId = idMaterial; } + + public void UpdateLastSeenAppearence() + { + LastSeenAppereance = (ColoredGlyph)Appearence.Clone(); + } } } diff --git a/src/MagusEngine/Core/MapStuff/TileHelpers.cs b/src/MagusEngine/Core/MapStuff/TileHelpers.cs new file mode 100644 index 00000000..6ee3b042 --- /dev/null +++ b/src/MagusEngine/Core/MapStuff/TileHelpers.cs @@ -0,0 +1,27 @@ +using Arquimedes.Enumerators; +using MagusEngine.Core.Entities; +using MagusEngine.Services.Factory; +using MagusEngine.Systems.Physics; +using MagusEngine.Utils; + +namespace MagusEngine.Core.MapStuff +{ + public static class TileHelpers + { + public static bool ChangeTileEffect(Point target, Actor actor, int modifier, TileType change) + { + if (actor is null || actor.CurrentMagiMap is null) + return false; + + var tile = actor.CurrentMagiMap?.GetTileAt(target)!; + var threashold = PhysicsSystem.GetMiningDificulty(tile.Material); + if ((modifier * (125 + Mrn.Normal1D100Dice)) <= threashold) + return false; + + tile.ChangeTileType(change); + tile.GoRogueComponents.Clear(); + + return true; + } + } +} diff --git a/src/MagusEngine/MagusEngine.csproj b/src/MagusEngine/MagusEngine.csproj index 66003fcf..4ea31540 100644 --- a/src/MagusEngine/MagusEngine.csproj +++ b/src/MagusEngine/MagusEngine.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/MagusEngine/Serialization/EntitySerialization/SpellTemplate.cs b/src/MagusEngine/Serialization/EntitySerialization/SpellTemplate.cs index 49660e34..160f18bd 100644 --- a/src/MagusEngine/Serialization/EntitySerialization/SpellTemplate.cs +++ b/src/MagusEngine/Serialization/EntitySerialization/SpellTemplate.cs @@ -20,7 +20,7 @@ public override Spell ReadJson(JsonReader reader, Type objectType, foreach (JToken token in listEffectsJson) { - EffectType effect = Enum.Parse((string)token["EffectType"]!); + SpellEffectType effect = Enum.Parse((string)token["EffectType"]!); if (!Locator.GetService().TryGetSpellEffect(effect, token, out var eff)) continue; effectsList.Add(eff); diff --git a/src/MagusEngine/Services/Factory/SpellEffectFactory.cs b/src/MagusEngine/Services/Factory/SpellEffectFactory.cs index 799d07de..0d23a5a2 100644 --- a/src/MagusEngine/Services/Factory/SpellEffectFactory.cs +++ b/src/MagusEngine/Services/Factory/SpellEffectFactory.cs @@ -19,13 +19,15 @@ public SpellEffectFactory() Register("KNOCKBACK", static token => token.ToObject()); Register("LIGHT", static token => token.ToObject()); Register("MEMISSION", static token => token.ToObject()); + Register("RAISEWALL", static token => token.ToObject()); + Register("DIG", static token => token.ToObject()); } - public ISpellEffect? GetSpellEffect(EffectType effect, JToken token) => + public ISpellEffect? GetSpellEffect(SpellEffectType effect, JToken token) => GetValueFromKey(effect.ToString(), token); public bool TryGetSpellEffect( - EffectType key, + SpellEffectType key, JToken token, [NotNullWhen(true)] out ISpellEffect? effect ) => TryGetValueFromKey(key.ToString(), token, out effect); diff --git a/src/MagusEngine/Services/Factory/TileFactory.cs b/src/MagusEngine/Services/Factory/TileFactory.cs index c34277a4..10806d43 100644 --- a/src/MagusEngine/Services/Factory/TileFactory.cs +++ b/src/MagusEngine/Services/Factory/TileFactory.cs @@ -128,6 +128,18 @@ private static Tile CreateTile(Point pos, public static void ResetCachedMaterial() => cachedMaterial = null; + public static void ChangeTileType(this Tile tile, TileType type) + { + var (foreground, background, glyph, isWalkable, isTransparent, name) = DetermineTileLookAndName(tile.Material, type); + tile.Appearence.Foreground = foreground; + tile.Appearence.Background = background; + tile.Appearence.Glyph = glyph; + tile.IsWalkable = isWalkable; + tile.IsTransparent = isTransparent; + tile.Name = name; + tile.UpdateLastSeenAppearence(); + } + private static (Color, Color, char, bool, bool, string) DetermineTileLookAndName(Material? material, TileType tileType) { char glyph; diff --git a/src/MagusEngine/Systems/Find.cs b/src/MagusEngine/Systems/Find.cs index 26ea7d9b..78a302e9 100644 --- a/src/MagusEngine/Systems/Find.cs +++ b/src/MagusEngine/Systems/Find.cs @@ -1,13 +1,13 @@ +using System.Collections.Generic; using Arquimedes.Enumerators; +using MagusEngine.Components.TilesComponents; using MagusEngine.Core.Civ; using MagusEngine.Core.Entities.Base; using MagusEngine.Core.MapStuff; using MagusEngine.Core.WorldStuff.History; -using MagusEngine.Components.TilesComponents; using MagusEngine.Serialization.EntitySerialization; using MagusEngine.Systems.Time; using MagusEngine.Utils.Extensions; -using System.Collections.Generic; namespace MagusEngine.Systems { diff --git a/src/MagusEngine/Systems/Physics/PhysicsSystem.cs b/src/MagusEngine/Systems/Physics/PhysicsSystem.cs index 6f1d76a1..5e829ae6 100644 --- a/src/MagusEngine/Systems/Physics/PhysicsSystem.cs +++ b/src/MagusEngine/Systems/Physics/PhysicsSystem.cs @@ -1,12 +1,13 @@ +using System; +using System.Linq; using MagusEngine.Bus.UiBus; +using MagusEngine.Components.EntityComponents.Effects; +using MagusEngine.Core; using MagusEngine.Core.Entities; using MagusEngine.Core.Entities.Base; -using MagusEngine.Components.EntityComponents.Effects; using MagusEngine.Services; using MagusEngine.Utils; using SadRogue.Primitives; -using System; -using System.Linq; namespace MagusEngine.Systems.Physics { @@ -145,5 +146,12 @@ public static void DealWithPushes(MagiEntity? entity, effectMessage); entity?.AddComponent(comp, comp.Tag); } + + public static double GetMiningDificulty(Material? material) + { + if (material is null) + return 0; + return material.DensityKgM3 ?? 1 * material.Hardness ?? 1 / (material.ImpactFractureMpa ?? 1 + 1); + } } } diff --git a/src/MagusEngine/Utils/MRN.cs b/src/MagusEngine/Utils/MRN.cs index 3024e6fe..258b5302 100644 --- a/src/MagusEngine/Utils/MRN.cs +++ b/src/MagusEngine/Utils/MRN.cs @@ -31,12 +31,12 @@ private static int ExplodingDice() if (roll1 == 6) { - roll1 = Dice.Roll("1d6 - 1"); + roll1 = Dice.Roll("1d6-1"); sumRoll1 += roll1; } if (roll2 == 6) { - roll2 = Dice.Roll("1d6 - 1"); + roll2 = Dice.Roll("1d6-1"); sumRoll2 += roll2; }