Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start working on a combat system #137

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MagicalLifeGUIWindows.GUI.New
{
public class NewWorldMenuLayout1920x1080
public static class NewWorldMenuLayout1920x1080
{
/// <summary>
/// The Y position at which all world size <see cref="InputBox"/>s are displayed at.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using MagicalLifeAPI.Util;
using MagicalLifeAPI.World.Data;
using MagicalLifeGUIWindows.Input.History;
using System;
using System.Collections.Generic;
using System.Linq;

Expand Down Expand Up @@ -70,9 +71,6 @@ private void Move(HasComponents selectable, Point2D target)
Extensions.EnqueueCollection(movementComponent.QueuedMovement, pth);
}
break;

default:
break;
}
}
}
Expand Down
35 changes: 33 additions & 2 deletions MLGUIWindows/Screens/LogoScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class LogoScreen

protected Rectangle TextZone { get; set; }



protected string Text { get; set; }

protected SpriteFont Font = Game1.AssetManager.Load<SpriteFont>(TextureLoader.FontMainMenuFont12x);
Expand All @@ -32,6 +34,7 @@ public class LogoScreen
/// </summary>
protected int Half { get; set; }


protected Texture2D Logo { get; set; }

protected Color Mask { get; set; }
Expand All @@ -41,17 +44,45 @@ public class LogoScreen
/// </summary>
/// <param name="logo">The resource path to the logo file that is to be displayed.</param>
/// <param name="duration">How many seconds to show the logo.</param>
public LogoScreen(string logo, float duration, string text = "")
public LogoScreen(string logo, float duration)
{
this.Frames = (int)duration * LogoScreen.FPS;
this.Half = this.Frames / 2;
this.Logo = Game1.AssetManager.Load<Texture2D>(logo);
this.DisplayZone = this.CalculateDisplayLocation();
this.Text = text;
this.Text = "";
this.CalculateTextZone();
this.Mask = Color.Black;
}

/// <summary>
///
/// </summary>
/// <param name="logo">The resource path to the logo file that is to be displayed.</param>
/// <param name="duration">How many seconds to show the logo.</param>
public LogoScreen(string logo, float duration, string text)
{
this.Frames = (int)duration * LogoScreen.FPS;
this.Half = this.Frames / 2;
this.Logo = Game1.AssetManager.Load<Texture2D>(logo);
this.DisplayZone = this.CalculateDisplayLocation();
this.InitText(text);
this.CalculateTextZone();
this.Mask = Color.Black;
}

private void InitText(string text)
{
if (!string.IsNullOrWhiteSpace(text))
{
this.Text = text;
}
else
{
Text = "";
}
}

public void Skip()
{
this.Frames = 0;
Expand Down
20 changes: 17 additions & 3 deletions MagicalLife.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2010
# Visual Studio Version 16
VisualStudioVersion = 16.0.28917.181
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{09293283-6E6D-4652-A633-5B70452244DA}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -33,14 +33,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MagicalLifeServerStandard",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MagicalLifeSettingsStandard", "MagicalLifeSettingsStandard\MagicalLifeSettingsStandard.csproj", "{EC7FD282-023D-4926-A766-19B36AEAC4C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MagicalLifeAPITest", "MagicalLifeAPITest\MagicalLifeAPITest.csproj", "{9CA6C7EF-99BC-4066-BB9D-0613E248B91D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MagicalLifeAPITest", "MagicalLifeAPITest\MagicalLifeAPITest.csproj", "{9CA6C7EF-99BC-4066-BB9D-0613E248B91D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MagicalLifeMod", "MagicalLifeMod\MagicalLifeMod.csproj", "{89B9DD2D-4904-4491-B111-E43A750E440B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MonoGUI", "MonoGUI\MonoGUI.csproj", "{251190F6-AC08-4274-895D-E806FD2D16C4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MLGUIWindows", "MLGUIWindows\MLGUIWindows.csproj", "{94CBCEE0-960D-4B20-B7C5-020C24022A79}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MonoLib", "MonoLib\MonoLib.csproj", "{893380B0-B822-4AAA-85DF-8E83A7620340}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -156,6 +158,18 @@ Global
{94CBCEE0-960D-4B20-B7C5-020C24022A79}.Release|x64.ActiveCfg = Release|x86
{94CBCEE0-960D-4B20-B7C5-020C24022A79}.Release|x86.ActiveCfg = Release|x86
{94CBCEE0-960D-4B20-B7C5-020C24022A79}.Release|x86.Build.0 = Release|x86
{893380B0-B822-4AAA-85DF-8E83A7620340}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{893380B0-B822-4AAA-85DF-8E83A7620340}.Debug|Any CPU.Build.0 = Debug|Any CPU
{893380B0-B822-4AAA-85DF-8E83A7620340}.Debug|x64.ActiveCfg = Debug|Any CPU
{893380B0-B822-4AAA-85DF-8E83A7620340}.Debug|x64.Build.0 = Debug|Any CPU
{893380B0-B822-4AAA-85DF-8E83A7620340}.Debug|x86.ActiveCfg = Debug|Any CPU
{893380B0-B822-4AAA-85DF-8E83A7620340}.Debug|x86.Build.0 = Debug|Any CPU
{893380B0-B822-4AAA-85DF-8E83A7620340}.Release|Any CPU.ActiveCfg = Release|Any CPU
{893380B0-B822-4AAA-85DF-8E83A7620340}.Release|Any CPU.Build.0 = Release|Any CPU
{893380B0-B822-4AAA-85DF-8E83A7620340}.Release|x64.ActiveCfg = Release|Any CPU
{893380B0-B822-4AAA-85DF-8E83A7620340}.Release|x64.Build.0 = Release|Any CPU
{893380B0-B822-4AAA-85DF-8E83A7620340}.Release|x86.ActiveCfg = Release|Any CPU
{893380B0-B822-4AAA-85DF-8E83A7620340}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
52 changes: 52 additions & 0 deletions MagicalLifeAPIStandard/Combat/Damage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

namespace MagicalLifeAPI.Combat
{
[DebuggerDisplay("DamageType = {DamageTypes} \n DamageAmount = {DamageAmount} ")]
public class Damage : DamageBase
{
public Damage(DamageTypes type, float damageAmount) : base(type, damageAmount)
{
}

public static Damage operator +(Damage damage, float amount)
{
return new Damage(damage.DamageTypes, damage.DamageAmount + amount);
}

public static Damage operator -(Damage damage, float amount)
{
return new Damage(damage.DamageTypes, damage.DamageAmount - amount);
}

public static Damage operator -(Damage damage, Resistance resistance)
{
if (resistance.DamageTypes == damage.DamageTypes)
{
return new Damage(damage.DamageTypes, damage.DamageAmount - resistance.DamageAmount);
}
else
{
throw new ArgumentException("Damage types of damage and resistance are not equal.");
}

}




public static Damage operator *(Damage damage, float amount)
{
return new Damage(damage.DamageTypes, damage.DamageAmount * amount);
}

public static Damage operator /(Damage damage, float amount)
{
return new Damage(damage.DamageTypes, damage.DamageAmount / amount);
}

}
}
63 changes: 63 additions & 0 deletions MagicalLifeAPIStandard/Combat/DamageBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace MagicalLifeAPI.Combat
{
public abstract class DamageBase : IEquatable<DamageBase>
{

public readonly DamageTypes DamageTypes;

public DamageBase()
{
DamageTypes = DamageTypes.FromValue(0);
DamageAmount = 10;
}

public DamageBase(DamageTypes type, float damageAmount)
{
DamageTypes = type;
DamageAmount = damageAmount;
}

public float DamageAmount { get; set; }

public override bool Equals(object obj)
{
if (obj is DamageBase)
{
return Equals(obj as DamageBase);
}
return false;

}

public bool Equals(DamageBase other)
{
return EqualityComparer<DamageTypes>.Default.Equals(DamageTypes, other.DamageTypes) &&
DamageAmount == other.DamageAmount;
}

public override int GetHashCode()
{
var hashCode = -424489883;
hashCode = hashCode * -1521134295 + EqualityComparer<DamageTypes>.Default.GetHashCode(DamageTypes);
hashCode = hashCode * -1521134295 + DamageAmount.GetHashCode();
return hashCode;
}

public static bool operator ==(DamageBase left, DamageBase right)
{
return EqualityComparer<DamageBase>.Default.Equals(left, right);
}

public static bool operator !=(DamageBase left, DamageBase right)
{
return !(left == right);
}



}
}
127 changes: 127 additions & 0 deletions MagicalLifeAPIStandard/Combat/DamageTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
using MagicalLifeAPI.Properties;
using MonoGUI.MonoLib.CustomTypes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MagicalLifeAPI.Combat
{
public class DamageTypes : Enumeration, IEquatable<DamageTypes>
{
public static readonly DamageTypes Poison = new DamageTypes(1, Lang.Poison);

public static readonly DamageTypes Magic = new DamageTypes(2, Lang.Magic);

public static readonly DamageTypes Fire = new DamageTypes(3, Lang.Fire);

public static readonly DamageTypes Crushing = new DamageTypes(4, Lang.Crushing);

public static readonly DamageTypes Piercing = new DamageTypes(5, Lang.Piercing);

public static readonly ICollection<DamageTypes> List = new List<DamageTypes> { Piercing, Crushing, Fire, Magic, Poison };

protected DamageTypes(int id, string name) : base(id, name)
{
}

/// <summary>
/// Adds the type of the damage.
/// </summary>
/// <param name="damage">The damage.</param>
/// <returns>If the new damage type was registered</returns>
public bool AddDamageType(DamageTypes damage)
{
if(!List.Contains(damage))
{
List.Add(damage);
return true;
}
return false;
}

public override bool Equals(object obj)
{
if (!(obj is DamageTypes))
{
return false;
}

DamageTypes damageTypes = obj as DamageTypes;
return Equals(damageTypes);
}

public override string ToString()
{
return Name;
}

public override int GetHashCode()
{
const int hash = 397;
return hash * Id.GetHashCode() * Name.GetHashCode();
}

public static bool operator ==(DamageTypes left, DamageTypes right)
{
if (left is null)
{
return right is null;
}

return left.Equals(right);
}

public static bool operator !=(DamageTypes left, DamageTypes right)
{
return !(left == right);
}

public static bool operator <(DamageTypes left, DamageTypes right)
{
return left is null ? !(right is null) : left.CompareTo(right) < 0;
}

public static bool operator <=(DamageTypes left, DamageTypes right)
{
return left is null || left.CompareTo(right) <= 0;
}

public static bool operator >(DamageTypes left, DamageTypes right)
{
return !(left is null) && left.CompareTo(right) > 0;
}

public static bool operator >=(DamageTypes left, DamageTypes right)
{
return left is null ? right is null : left.CompareTo(right) >= 0;
}


public static DamageTypes FromString(string roleString)
{
return List.Single(r => string.Equals(r.Name, roleString, StringComparison.OrdinalIgnoreCase));
}

public static DamageTypes FromValue(int value)
{
return List.Single(r => r.Id == value);
}

public bool Equals(DamageTypes other)
{

if (!other.Name.Equals(this.Name, StringComparison.OrdinalIgnoreCase))
{
return false;
}

if (other.Id != Id)
{
return false;
}

return true;
}
}
}
13 changes: 13 additions & 0 deletions MagicalLifeAPIStandard/Combat/IArmor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace MagicalLifeAPI.Combat
{
public interface IArmor
{
List<Resistance> Resistances { get; }


}
}
Loading