Skip to content

Commit

Permalink
cleanup headers, spacing, usings
Browse files Browse the repository at this point in the history
  • Loading branch information
baughj committed May 12, 2024
1 parent 918911b commit def3c4a
Show file tree
Hide file tree
Showing 165 changed files with 4,541 additions and 3,357 deletions.
25 changes: 18 additions & 7 deletions Hybrasyl.Tests/BaseTests.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
// This file is part of Project Hybrasyl.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the Affero General Public License as published by
// the Free Software Foundation, version 3.
//
// This program is distributed in the hope that it will be useful, but
// without ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the Affero General Public License
// for more details.
//
// You should have received a copy of the Affero General Public License along
// with this program. If not, see <http://www.gnu.org/licenses/>.
//
// (C) 2020-2023 ERISCO, LLC
//
// For contributors and individual authors please refer to CONTRIBUTORS.MD.

namespace Hybrasyl.Tests;


// No really, disable parallelization
//[CollectionDefinition("Hybrasyl", DisableParallelization = true)]
//public class HybrasylTestDefinitionClass { }
//public class HybrasylTestDefinitionClass { }
62 changes: 36 additions & 26 deletions Hybrasyl.Tests/CastableRestrictions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
using Hybrasyl;
using Hybrasyl.Objects;
using Hybrasyl.Tests;
// This file is part of Project Hybrasyl.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the Affero General Public License as published by
// the Free Software Foundation, version 3.
//
// This program is distributed in the hope that it will be useful, but
// without ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the Affero General Public License
// for more details.
//
// You should have received a copy of the Affero General Public License along
// with this program. If not, see <http://www.gnu.org/licenses/>.
//
// (C) 2020-2023 ERISCO, LLC
//
// For contributors and individual authors please refer to CONTRIBUTORS.MD.

using Hybrasyl.Xml.Objects;
using System.Drawing;
using System.Linq;
using System.Numerics;
using Xunit;

namespace Hybrasyl.Tests;
Expand Down Expand Up @@ -103,7 +116,6 @@ public void ForbidItem()
Assert.True(Fixture.TestUser.UseCastable(castable));
GiveItem("nochdaidh deum");
Assert.True(Fixture.TestUser.UseCastable(castable));

}

[Fact]
Expand Down Expand Up @@ -169,7 +181,7 @@ public void RequireWeaponAny()
GiveEquipment("Smol Sword");
Assert.True(Fixture.TestUser.UseCastable(castable));
}

[Fact]
public void RequireWeaponType()
{
Expand Down Expand Up @@ -425,23 +437,23 @@ public void TestForbidSlotAny()
[Fact]
public void TestForbidSlot()
{
// <Item Slot="Foot" RestrictionType="NotEquipped" Message="err_forbid_slot">Testinium Foot</Item>
Fixture.TestUser.Inventory.Clear();
Fixture.TestUser.Equipment.Clear();

var castable = GetCastable("TestForbidSlot");

// Test requirement missing
GiveEquipment("Testinium Foot");
Assert.False(Fixture.TestUser.UseCastable(castable));
Assert.Equal("err_forbid_slot", Fixture.TestUser.LastSystemMessage);
Fixture.TestUser.Equipment.Clear();

// Test requirement succeeding
GiveEquipment("Testinium Foot2");
Assert.True(Fixture.TestUser.UseCastable(castable));
GiveEquipment("Testinium Claw");
Assert.True(Fixture.TestUser.UseCastable(castable));
// <Item Slot="Foot" RestrictionType="NotEquipped" Message="err_forbid_slot">Testinium Foot</Item>
Fixture.TestUser.Inventory.Clear();
Fixture.TestUser.Equipment.Clear();

var castable = GetCastable("TestForbidSlot");

// Test requirement missing
GiveEquipment("Testinium Foot");
Assert.False(Fixture.TestUser.UseCastable(castable));
Assert.Equal("err_forbid_slot", Fixture.TestUser.LastSystemMessage);
Fixture.TestUser.Equipment.Clear();

// Test requirement succeeding
GiveEquipment("Testinium Foot2");
Assert.True(Fixture.TestUser.UseCastable(castable));
GiveEquipment("Testinium Claw");
Assert.True(Fixture.TestUser.UseCastable(castable));
}

[Fact]
Expand Down Expand Up @@ -491,7 +503,5 @@ public void TestForbidWeapon()
Fixture.TestUser.Equipment.Clear();
GiveEquipment("Smol Sword");
Assert.True(Fixture.TestUser.UseCastable(castable));

}

}
52 changes: 35 additions & 17 deletions Hybrasyl.Tests/Equipment.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
using Hybrasyl.Xml.Objects;
// This file is part of Project Hybrasyl.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the Affero General Public License as published by
// the Free Software Foundation, version 3.
//
// This program is distributed in the hope that it will be useful, but
// without ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the Affero General Public License
// for more details.
//
// You should have received a copy of the Affero General Public License along
// with this program. If not, see <http://www.gnu.org/licenses/>.
//
// (C) 2020-2023 ERISCO, LLC
//
// For contributors and individual authors please refer to CONTRIBUTORS.MD.

using System.Collections.Generic;
using System.Linq;
using Hybrasyl.Xml.Objects;
using Xunit;

namespace Hybrasyl.Tests;
Expand Down Expand Up @@ -99,9 +117,9 @@ public void EquipRestrictionCheckAbLevel()
var equipment = Game.World.CreateItem(item);
Assert.True(equipment.CheckRequirements(Fixture.TestUser, out var m1),
$"Equipment min level is 50, player level is 50, CheckRequirements failed with {m1}");
Assert.True(Fixture.TestUser.AddEquipment(equipment, (byte)EquipmentSlot.Armor),
Assert.True(Fixture.TestUser.AddEquipment(equipment, (byte) EquipmentSlot.Armor),
"Equipment level is 50, player level is 50, AddEquipment failed");
Assert.True(Fixture.TestUser.RemoveEquipment((byte)EquipmentSlot.Armor), "Failed to unequip equipment");
Assert.True(Fixture.TestUser.RemoveEquipment((byte) EquipmentSlot.Armor), "Failed to unequip equipment");
Fixture.TestUser.Stats.Level = 49;
Assert.False(equipment.CheckRequirements(Fixture.TestUser, out var m2),
"Equipment min level is 50, player level is 49, CheckRequirements succeeded");
Expand Down Expand Up @@ -137,9 +155,9 @@ public void EquipRestrictionCheckClass()
Fixture.TestUser.Class = Class.Monk;
Assert.True(equipment.CheckRequirements(Fixture.TestUser, out var m3),
$"Equipment class is Monk, user is Monk, CheckRequirements failed {m3}");
Assert.True(Fixture.TestUser.AddEquipment(equipment, (byte)EquipmentSlot.Armor),
Assert.True(Fixture.TestUser.AddEquipment(equipment, (byte) EquipmentSlot.Armor),
"Equipment class is Monk, user is Monk, AddEquipment failed");
Assert.True(Fixture.TestUser.RemoveEquipment((byte)EquipmentSlot.Armor), "Failed to unequip equipment");
Assert.True(Fixture.TestUser.RemoveEquipment((byte) EquipmentSlot.Armor), "Failed to unequip equipment");
}

[Fact]
Expand All @@ -158,9 +176,9 @@ public void EquipRestrictionCheckWeight()
Fixture.TestUser.Stats.Level = 99;
Assert.True(equipment.CheckRequirements(Fixture.TestUser, out var m3),
$"Equipment weight is 100, user is str 255 / level 99, CheckRequirements failed {m3}");
Assert.True(Fixture.TestUser.AddEquipment(equipment, (byte)EquipmentSlot.Armor),
Assert.True(Fixture.TestUser.AddEquipment(equipment, (byte) EquipmentSlot.Armor),
"Equipment weight is 100, user is str 255 / level 99, AddEquipment failed");
Assert.True(Fixture.TestUser.RemoveEquipment((byte)EquipmentSlot.Armor), "Failed to unequip equipment");
Assert.True(Fixture.TestUser.RemoveEquipment((byte) EquipmentSlot.Armor), "Failed to unequip equipment");
}

[Fact]
Expand All @@ -175,16 +193,16 @@ public void EquipRestrictionShieldTwoHand()
var twohandObj = Game.World.CreateItem(twohand);
Assert.True(
shieldObj.CheckRequirements(Fixture.TestUser, out var m1) &&
Fixture.TestUser.AddEquipment(shieldObj, (byte)EquipmentSlot.Shield),
Fixture.TestUser.AddEquipment(shieldObj, (byte) EquipmentSlot.Shield),
$"Check & Equip shield failed ({m1})");
Assert.False(twohandObj.CheckRequirements(Fixture.TestUser, out var m2),
"Shield equipped, equip two handed weapon,1 CheckRequirements succeeded");
Assert.Equal(Game.World.GetLocalString("item_equip_2h_shield"), m2);

Assert.True(Fixture.TestUser.RemoveEquipment((byte)EquipmentSlot.Shield));
Assert.True(Fixture.TestUser.RemoveEquipment((byte) EquipmentSlot.Shield));
Assert.True(
twohandObj.CheckRequirements(Fixture.TestUser, out var m3) &&
Fixture.TestUser.AddEquipment(twohandObj, (byte)EquipmentSlot.Weapon),
Fixture.TestUser.AddEquipment(twohandObj, (byte) EquipmentSlot.Weapon),
"Check & Equip 2H weapon failed");
Assert.False(shieldObj.CheckRequirements(Fixture.TestUser, out var m4));
Assert.Equal(Game.World.GetLocalString("item_equip_shield_2h"), m4);
Expand All @@ -204,7 +222,7 @@ public void EquipRestrictionUniqueEquipped()
var ring2Obj = Game.World.CreateItem(ring2);
Assert.True(
ring1Obj.CheckRequirements(Fixture.TestUser, out var m1) &&
Fixture.TestUser.AddEquipment(ring1Obj, (byte)EquipmentSlot.LeftHand), $"Equip first ring failed ({m1})");
Fixture.TestUser.AddEquipment(ring1Obj, (byte) EquipmentSlot.LeftHand), $"Equip first ring failed ({m1})");
Assert.True(Fixture.TestUser.Equipment.LRing != null);
Assert.False(ring2Obj.CheckRequirements(Fixture.TestUser, out var m2),
"Ring 1 equipped, Equipping duplicate unique-equipped item, CheckRequirements succeeded");
Expand Down Expand Up @@ -252,7 +270,7 @@ public void EquipRestrictionSlotRestriction()

Assert.True(
ringObj.CheckRequirements(Fixture.TestUser, out var m1) &&
Fixture.TestUser.AddEquipment(ringObj, (byte)EquipmentSlot.LeftHand),
Fixture.TestUser.AddEquipment(ringObj, (byte) EquipmentSlot.LeftHand),
$"Equip armor-prohibiting ring failed ({m1})");
Assert.True(Fixture.TestUser.Equipment.LRing != null, "Ring is missing");
Assert.False(armorObj.CheckRequirements(Fixture.TestUser, out var m2),
Expand All @@ -262,7 +280,7 @@ public void EquipRestrictionSlotRestriction()
// Try the reverse now
Assert.True(
ringObj.CheckRequirements(Fixture.TestUser, out var m3) &&
Fixture.TestUser.AddEquipment(armorObj, (byte)EquipmentSlot.Armor),
Fixture.TestUser.AddEquipment(armorObj, (byte) EquipmentSlot.Armor),
$"Equip ring-prohibiting armor failed ({m3})");
Assert.True(Fixture.TestUser.Equipment.LRing != null, "Armor is missing");
Assert.False(ringObj.CheckRequirements(Fixture.TestUser, out var m4),
Expand All @@ -287,7 +305,7 @@ public void EquipNegativeXpBonus()
ring.Properties.StatModifiers = new StatModifiers { BonusExtraXp = "-3" };

var ringObj = Game.World.CreateItem(ring);
Assert.True(Fixture.TestUser.AddEquipment(ringObj, (byte)EquipmentSlot.RightHand));
Assert.True(Fixture.TestUser.AddEquipment(ringObj, (byte) EquipmentSlot.RightHand));
Assert.True(Fixture.TestUser.Stats.ExtraXp == -3.0);

Fixture.TestUser.GiveExperience(10000, true);
Expand All @@ -306,7 +324,7 @@ public void EquipPositiveXpBonus()
ring.Properties.StatModifiers = new StatModifiers { BonusExtraXp = "3" };

var ringObj = Game.World.CreateItem(ring);
Assert.True(Fixture.TestUser.AddEquipment(ringObj, (byte)EquipmentSlot.RightHand));
Assert.True(Fixture.TestUser.AddEquipment(ringObj, (byte) EquipmentSlot.RightHand));
Assert.True(Fixture.TestUser.Stats.ExtraXp == 3.0);

Fixture.TestUser.GiveExperience(10000, true);
Expand Down Expand Up @@ -420,7 +438,7 @@ public void EquipEquipmentBonuses()

// Now remove

Fixture.TestUser.RemoveEquipment((byte)EquipmentSlot.RightHand);
Fixture.TestUser.RemoveEquipment((byte) EquipmentSlot.RightHand);

var currentAc = Fixture.TestUser.Stats.BaseAc - Fixture.TestUser.Stats.Level / 3 +
Fixture.TestUser.Stats.BonusAc;
Expand Down Expand Up @@ -490,7 +508,7 @@ public void EquipmentSlotOf()
ring.Name = "Test Ring";
var ringObj = Game.World.CreateItem(ring);
Assert.True(Fixture.TestUser.AddEquipment(ringObj, (byte) EquipmentSlot.RightHand));
Assert.Equal((byte)EquipmentSlot.RightHand, Fixture.TestUser.Equipment.SlotOfName(ringObj.Name));
Assert.Equal((byte) EquipmentSlot.RightHand, Fixture.TestUser.Equipment.SlotOfName(ringObj.Name));
Assert.Equal((byte) EquipmentSlot.None, Fixture.TestUser.Equipment.SlotOfName("Something that does not exist"));
}
}
52 changes: 36 additions & 16 deletions Hybrasyl.Tests/Fixtures.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
using Hybrasyl.Objects;
using Hybrasyl.Xml.Manager;
using Hybrasyl.Xml.Objects;
using Serilog;
// This file is part of Project Hybrasyl.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the Affero General Public License as published by
// the Free Software Foundation, version 3.
//
// This program is distributed in the hope that it will be useful, but
// without ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the Affero General Public License
// for more details.
//
// You should have received a copy of the Affero General Public License along
// with this program. If not, see <http://www.gnu.org/licenses/>.
//
// (C) 2020-2023 ERISCO, LLC
//
// For contributors and individual authors please refer to CONTRIBUTORS.MD.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Hybrasyl.Internals;
using Hybrasyl.Objects;
using Hybrasyl.Xml.Manager;
using Hybrasyl.Xml.Objects;
using Serilog;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;

[assembly: CollectionBehavior(CollectionBehavior.CollectionPerClass, DisableTestParallelization = true, MaxParallelThreads = 1)]
[assembly:
CollectionBehavior(CollectionBehavior.CollectionPerClass, DisableTestParallelization = true,
MaxParallelThreads = 1)]

namespace Hybrasyl.Tests;

Expand All @@ -24,7 +44,8 @@ public HybrasylFixture(IMessageSink sink)
{
this.sink = sink;
Log.Logger = new LoggerConfiguration().MinimumLevel.Debug()
.WriteTo.Console().WriteTo.File("hybrasyl-tests-.log", rollingInterval: RollingInterval.Day).WriteTo.TestCorrelator()
.WriteTo.Console().WriteTo.File("hybrasyl-tests-.log", rollingInterval: RollingInterval.Day).WriteTo
.TestCorrelator()
.CreateLogger();
var submoduleDir = AppDomain.CurrentDomain.BaseDirectory.Split("Hybrasyl.Tests");
Game.LoadCollisions();
Expand Down Expand Up @@ -85,8 +106,8 @@ public HybrasylFixture(IMessageSink sink)
Name = "Test Item"
};
TestItem.Properties.Stackable.Max = 1;
TestItem.Properties.Equipment = new Hybrasyl.Xml.Objects.Equipment
{ WeaponType = WeaponType.None, Slot = EquipmentSlot.None };
TestItem.Properties.Equipment = new Xml.Objects.Equipment
{ WeaponType = WeaponType.None, Slot = EquipmentSlot.None };
TestItem.Properties.Physical = new Physical { Durability = 1000, Weight = 1 };
TestItem.Properties.Categories = new List<Category>
{
Expand All @@ -100,8 +121,8 @@ public HybrasylFixture(IMessageSink sink)
Name = "Stackable Test Item"
};
StackableTestItem.Properties.Stackable.Max = 20;
StackableTestItem.Properties.Equipment = new Hybrasyl.Xml.Objects.Equipment
{ WeaponType = WeaponType.None, Slot = EquipmentSlot.None };
StackableTestItem.Properties.Equipment = new Xml.Objects.Equipment
{ WeaponType = WeaponType.None, Slot = EquipmentSlot.None };
StackableTestItem.Properties.Physical = new Physical { Durability = 1000, Weight = 1 };
StackableTestItem.Properties.Categories = new List<Category>
{
Expand All @@ -116,8 +137,8 @@ public HybrasylFixture(IMessageSink sink)
{
var item = new Item { Name = $"Equip Test {slot}" };
item.Properties.Stackable.Max = 1;
item.Properties.Equipment = new Hybrasyl.Xml.Objects.Equipment
{ WeaponType = slot == EquipmentSlot.Weapon ? WeaponType.Dagger : WeaponType.None, Slot = slot };
item.Properties.Equipment = new Xml.Objects.Equipment
{ WeaponType = slot == EquipmentSlot.Weapon ? WeaponType.Dagger : WeaponType.None, Slot = slot };
item.Properties.Physical = new Physical { Durability = 1000, Weight = 1 };
Game.World.WorldData.Add(item);
TestEquipment.Add(slot, item);
Expand Down Expand Up @@ -180,7 +201,7 @@ public HybrasylFixture(IMessageSink sink)
public Item StackableTestItem { get; }
public Dictionary<EquipmentSlot, Item> TestEquipment { get; } = new();
public static byte InventorySize => 59;

public User TestUser { get; }

public CreatureBehaviorSet TestSet { get; set; }
Expand All @@ -193,7 +214,7 @@ public void Dispose()
var server = World.DatastoreConnection.GetServer(ep.First().ToString());
server.FlushDatabase(15);
}
catch (Exception ex) {}
catch (Exception ex) { }
}

public void ResetUserStats()
Expand All @@ -219,5 +240,4 @@ public void ResetUserStats()
TestUser.Equipment.Clear();
TestUser.Vault.Clear();
}
}

}

0 comments on commit def3c4a

Please sign in to comment.