Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dotnet build
1 change: 1 addition & 0 deletions run.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dotnet run --project ./src/MagiRogue
42 changes: 42 additions & 0 deletions src/Arquimedes/Data/Spells/spells_alteration.json
Original file line number Diff line number Diff line change
@@ -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"]
}
]
2 changes: 1 addition & 1 deletion src/Arquimedes/Data/Spells/spells_dimensionalism.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"ShapingAbility": "Mana Shaping",
"Effects": [
{
"AreaOfEffect": "Target",
"AreaOfEffect": "TargetSelf",
"Radius": 0,
"TargetsTile": true,
"EffectType": "TELEPORT",
Expand Down
4 changes: 4 additions & 0 deletions src/Arquimedes/Enumerators/SpellAreaEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public enum SpellAreaEffect
/// </summary>
Target,
/// <summary>
/// Applies the effect to the caster at the specified target location (e.g., teleporting the caster to a tile).
/// </summary>
TargetSelf,
/// <summary>
/// Targets everything in a circle radius
/// </summary>
Ball,
Expand Down
5 changes: 4 additions & 1 deletion src/Arquimedes/Enumerators/SpellContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public enum SpellContext
Buff,
Debuff,
Teleport,
Distance
Distance,
Terraforming,
Dig,
BlocksSight,
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Arquimedes.Enumerators
{
public enum EffectType
public enum SpellEffectType
{
DAMAGE,
MEMISSION,
Expand All @@ -13,5 +13,7 @@ public enum EffectType
KNOCKBACK,
LIGHT,
KINESIS,
RAISEWALL,
DIG
}
}
}
3 changes: 2 additions & 1 deletion src/Arquimedes/Enumerators/TargetState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
{
public enum TargetState
{
IdleMode,
LookMode,
TargetingSpell,
TargetingItem,
}
}
}
20 changes: 10 additions & 10 deletions src/Arquimedes/Utils/FileUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -49,21 +49,21 @@ public static List<T> GetSourceTreeList<T>(string wildCard)
try
{
Parallel.ForEach(files, file =>
{
try
{
{
try
{
foreach (T? item in JsonUtils.JsonDeseralize<List<T>>(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)
{
Expand Down
85 changes: 32 additions & 53 deletions src/Diviner/KeyboardHandle.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Beware the null-forgiving operator, young apprentice!

The null-forgiving operator ! is used on item.Mass after checking if (sucess), but the success condition doesn't guarantee that item is non-null. The EndItemTargetting() method could return success with a null item in edge cases.

Apply this enchantment to ensure safe access:

-                            timeTaken = TimeHelper.GetShootingTime(_getPlayer, item!.Mass);
+                            timeTaken = TimeHelper.GetShootingTime(_getPlayer, item?.Mass ?? 0);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
timeTaken = TimeHelper.GetShootingTime(_getPlayer, item!.Mass);
timeTaken = TimeHelper.GetShootingTime(_getPlayer, item?.Mass ?? 0);
🤖 Prompt for AI Agents
In src/Diviner/KeyboardHandle.cs at line 300, the code uses the null-forgiving
operator on item.Mass without guaranteeing item is non-null after the success
check. To fix this, add an explicit null check for item before accessing its
Mass property, ensuring item is not null before calling
TimeHelper.GetShootingTime. This prevents potential null reference exceptions in
edge cases where success is true but item is null.

}
if (sucess)
{
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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<SavingService>().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<MagiMap>(json)!;
}
return false;
}

if (info.IsKeyPressed(Keys.OemMinus))
{
Locator.GetService<SavingService>().SaveGameToFolder(Find.Universe, "TestFile");
return false;
}

if (info.IsKeyPressed(Keys.P) && (_targetCursor?.EntityInTarget()) == true)
{
var target = _targetCursor.TargetEntity();
Expand Down
67 changes: 52 additions & 15 deletions src/Diviner/Windows/LookWindow.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
{
Expand All @@ -29,24 +24,66 @@ 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);
}

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<PlantComponent>(out var vegetation))
{
desc.Append("Tile has the following vegetation: ").Append(vegetation!.Plant.Name).AppendLine();
}
if (tile.GetComponent<WaterTile>(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;
}
}
}
5 changes: 0 additions & 5 deletions src/MagusEngine/Bus/MapBus/ChangeControlledEntitiy.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
Loading
Loading