Skip to content

Commit

Permalink
This is v0.2.3beta
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrdacor committed Feb 4, 2021
1 parent 0bf2348 commit 4e8c8a3
Show file tree
Hide file tree
Showing 11 changed files with 579 additions and 44 deletions.
12 changes: 6 additions & 6 deletions Ambermoon.Core/Battle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,8 @@ void HurtAnimationFinished()
ShowBattleFieldDamage((int)tile, damage);
if (target.Ailments.HasFlag(Ailment.Sleep))
game.RemoveAilment(Ailment.Sleep, target);
target.Damage(damage);
if (!game.Godmode || target is Monster)
target.Damage(damage);
return;
}
default:
Expand Down Expand Up @@ -1852,7 +1853,8 @@ void EndHurt()
}
if (target.Ailments.HasFlag(Ailment.Sleep))
RemoveAilment(Ailment.Sleep, target);
target.Damage(damage);
if (!game.Godmode || target is Monster)
target.Damage(damage);
EndHurt();
}
);
Expand Down Expand Up @@ -2703,15 +2705,13 @@ AttackResult ProcessAttack(Character attacker, int attackedSlot, out int damage,
int CalculatePhysicalDamage(Character attacker, Character target)
{
// TODO: how is damage calculated?
return attacker.BaseAttack + game.RandomInt(0, attacker.VariableAttack) - (target.BaseDefense + game.RandomInt(0, target.VariableDefense)); ;
return Math.Min((int)target.HitPoints.TotalCurrentValue, attacker.BaseAttack + game.RandomInt(0, attacker.VariableAttack) - (target.BaseDefense + game.RandomInt(0, target.VariableDefense)));
}

uint CalculateSpellDamage(Character caster, Character target, uint baseDamage, uint variableDamage)
{
// TODO: how is magic damage calculated?
// TODO: does INT affect damage?
// Note: In contrast to physical attacks this should always deal at least 1 damage
return baseDamage + (uint)game.RandomInt(0, (int)variableDamage); // TODO
return Math.Min(target.HitPoints.TotalCurrentValue, baseDamage + (uint)game.RandomInt(0, (int)variableDamage));
}
}

Expand Down
97 changes: 67 additions & 30 deletions Ambermoon.Core/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ enum CharacterInfo
public FloatPosition ViewportOffset { get; private set; } = null;
readonly bool legacyMode = false;
public event Action QuitRequested;
public bool Godmode
{
get;
set;
} = false;
bool ingame = false;
bool is3D = false;
internal bool WindowActive => currentWindow.Window != Window.MapView;
Expand All @@ -198,9 +203,9 @@ enum CharacterInfo
readonly Layout layout;
readonly Dictionary<CharacterInfo, UIText> characterInfoTexts = new Dictionary<CharacterInfo, UIText>();
readonly Dictionary<CharacterInfo, Panel> characterInfoPanels = new Dictionary<CharacterInfo, Panel>();
internal IMapManager MapManager { get; }
internal IItemManager ItemManager { get; }
internal ICharacterManager CharacterManager { get; }
public IMapManager MapManager { get; }
public IItemManager ItemManager { get; }
public ICharacterManager CharacterManager { get; }
readonly Places places;
readonly IRenderView renderView;
internal ISavegameManager SavegameManager { get; }
Expand Down Expand Up @@ -1885,7 +1890,7 @@ void ScrollCursor(Position cursorPosition, bool down)
}
}

internal IEnumerable<PartyMember> PartyMembers => Enumerable.Range(0, MaxPartyMembers)
public IEnumerable<PartyMember> PartyMembers => Enumerable.Range(0, MaxPartyMembers)
.Select(i => GetPartyMember(i)).Where(p => p != null);
internal PartyMember GetPartyMember(int slot) => CurrentSavegame.GetPartyMember(slot);
internal Chest GetChest(uint index) => CurrentSavegame.Chests[(int)index];
Expand Down Expand Up @@ -2622,35 +2627,48 @@ void Fade(Action midFadeAction)
AddTimedEvent(TimeSpan.FromMilliseconds(FadeTime), () => allInputDisabled = false);
}

internal void Teleport(MapChangeEvent mapChangeEvent)
/// <summary>
/// This is used by external triggers like a cheat engine.
/// </summary>
public bool Teleport(uint mapIndex, uint x, uint y, CharacterDirection direction)
{
Fade(() =>
if (WindowActive || BattleActive || layout.PopupActive || !ingame)
return false;

var newMap = MapManager.GetMap(mapIndex);
bool mapChange = newMap.Index != Map.Index;
var player = is3D ? (IRenderPlayer)player3D : player2D;
bool mapTypeChanged = Map.Type != newMap.Type;

// The position (x, y) is 1-based in the data so we subtract 1.
// Moreover the players position is 1 tile below its drawing position
// in non-world 2D so subtract another 1 from y.
player.MoveTo(newMap, x - 1,
y - (newMap.Type == MapType.Map2D && !newMap.IsWorldMap ? 2u : 1u),
CurrentTicks, true, direction);
this.player.Position.X = RenderPlayer.Position.X;
this.player.Position.Y = RenderPlayer.Position.Y;

if (!mapTypeChanged)
{
var newMap = MapManager.GetMap(mapChangeEvent.MapIndex);
bool mapChange = newMap.Index != Map.Index;
var player = is3D ? (IRenderPlayer)player3D : player2D;
bool mapTypeChanged = Map.Type != newMap.Type;
// Trigger events after map transition
TriggerMapEvents(EventTrigger.Move, (uint)player.Position.X,
(uint)player.Position.Y + (Map.IsWorldMap || is3D ? 0u : 1u));

// The position (x, y) is 1-based in the data so we subtract 1.
// Moreover the players position is 1 tile below its drawing position
// in non-world 2D so subtract another 1 from y.
player.MoveTo(newMap, mapChangeEvent.X - 1,
mapChangeEvent.Y - (newMap.Type == MapType.Map2D && !newMap.IsWorldMap ? 2u : 1u),
CurrentTicks, true, mapChangeEvent.Direction);
this.player.Position.X = RenderPlayer.Position.X;
this.player.Position.Y = RenderPlayer.Position.Y;
PlayerMoved(mapChange);
}

if (!mapTypeChanged)
{
// Trigger events after map transition
TriggerMapEvents(EventTrigger.Move, (uint)player.Position.X,
(uint)player.Position.Y + (Map.IsWorldMap || is3D ? 0u : 1u));
if (mapChange)
UpdateMapName();

PlayerMoved(mapChange);
}
return true;
}

if (mapChange)
UpdateMapName();
internal void Teleport(MapChangeEvent mapChangeEvent)
{
Fade(() =>
{
Teleport(mapChangeEvent.MapIndex, mapChangeEvent.X, mapChangeEvent.Y, mapChangeEvent.Direction);
});
}

Expand Down Expand Up @@ -2793,10 +2811,13 @@ static uint CalculateDamage(PartyMember partyMember)
if (damage != 0)
{
// TODO: show damage splash
partyMember.Damage(damage);
if (!Godmode)
{
partyMember.Damage(damage);

if (partyMember.Alive) // update HP etc if not died already
layout.SetCharacter(i, partyMember);
if (partyMember.Alive) // update HP etc if not died already
layout.SetCharacter(i, partyMember);
}
}
}
}
Expand Down Expand Up @@ -3189,6 +3210,22 @@ void HandleNextEvent()
});
}

/// <summary>
/// This is used by external triggers like a cheat engine.
///
/// Returns false if the current game state does not allow
/// to start a fight.
/// </summary>
public bool StartBattle(uint monsterGroupIndex)
{
if (WindowActive || BattleActive || layout.PopupActive ||
allInputDisabled || !inputEnable || !ingame)
return false;

StartBattle(monsterGroupIndex, false, null);
return true;
}

/// <summary>
/// Starts a battle with the given monster group index.
/// It is used for monsters that are present on the map.
Expand Down
7 changes: 5 additions & 2 deletions Ambermoon.Data.Common/ICharacterManager.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
namespace Ambermoon.Data
using System.Collections.Generic;

namespace Ambermoon.Data
{
public interface ICharacterManager
{
NPC GetNPC(uint index);
Monster GetMonster(uint index);
MonsterGroup GetMonsterGroup(uint index);
Monster[] Monsters { get; }
IReadOnlyList<Monster> Monsters { get; }
IReadOnlyDictionary<uint, MonsterGroup> MonsterGroups { get; }
}
}
5 changes: 4 additions & 1 deletion Ambermoon.Data.Common/IItemManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
namespace Ambermoon.Data
using System.Collections.Generic;

namespace Ambermoon.Data
{
public interface IItemManager
{
IReadOnlyList<Item> Items { get; }
Item GetItem(uint index);
}
}
5 changes: 4 additions & 1 deletion Ambermoon.Data.Common/IMapManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
namespace Ambermoon.Data
using System.Collections.Generic;

namespace Ambermoon.Data
{
public interface IMapManager
{
IReadOnlyList<Map> Maps { get; }
Map GetMap(uint index);
Tileset GetTilesetForMap(Map map);
Labdata GetLabdataForMap(Map map);
Expand Down
3 changes: 2 additions & 1 deletion Ambermoon.Data.Legacy/Characters/CharacterManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public CharacterManager(IGameData gameData, IGraphicProvider graphicProvider)

public MonsterGroup GetMonsterGroup(uint index) => index == 0 || !monsterGroups.ContainsKey(index) ? null : monsterGroups[index];

public Monster[] Monsters => monsters.Values.ToArray();
public IReadOnlyList<Monster> Monsters => monsters.Values.ToList();
public IReadOnlyDictionary<uint, MonsterGroup> MonsterGroups => monsterGroups;
}
}
2 changes: 2 additions & 0 deletions Ambermoon.Data.Legacy/ItemManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;

namespace Ambermoon.Data.Legacy
{
Expand All @@ -12,5 +13,6 @@ internal ItemManager(Dictionary<uint, Item> items)
}

public Item GetItem(uint index) => items[index];
public IReadOnlyList<Item> Items => items.Values.ToList();
}
}
5 changes: 3 additions & 2 deletions Ambermoon.Data.Legacy/MapManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Ambermoon.Data.Serialization;
using System.Collections.Generic;
using System.Linq;

namespace Ambermoon.Data.Legacy
{
Expand All @@ -9,6 +10,8 @@ public class MapManager : IMapManager
readonly Dictionary<uint, Tileset> tilesets = new Dictionary<uint, Tileset>(8);
readonly Dictionary<uint, Labdata> labdatas = new Dictionary<uint, Labdata>(29);

public IReadOnlyList<Map> Maps => maps.Values.ToList();

public MapManager(IGameData gameData, IMapReader mapReader, ITilesetReader tilesetReader, ILabdataReader labdataReader)
{
foreach (var tilesetFile in gameData.Files["Icon_data.amb"].Files)
Expand Down Expand Up @@ -44,7 +47,5 @@ public MapManager(IGameData gameData, IMapReader mapReader, ITilesetReader tiles
public Map GetMap(uint index) => maps[index];
public Tileset GetTilesetForMap(Map map) => tilesets[map.TilesetOrLabdataIndex];
public Labdata GetLabdataForMap(Map map) => labdatas[map.TilesetOrLabdataIndex];

public IEnumerable<Map> Maps => maps.Values;
}
}
2 changes: 1 addition & 1 deletion Ambermoon.net/Ambermoon.net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Ambermoon</RootNamespace>
<RuntimeIdentifiers>win-x86;win-x64;linux-x64</RuntimeIdentifiers>
<Version>0.2.2</Version>
<Version>0.2.3</Version>
<Copyright>Copyright (C) 2020-2021 by Robert Schneckenhaus</Copyright>
<Company>Robert Schneckenhaus</Company>
<Authors>Robert Schneckenhaus</Authors>
Expand Down
Loading

0 comments on commit 4e8c8a3

Please sign in to comment.