-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Snarkki/LootTesting
Loot testing
- Loading branch information
Showing
16 changed files
with
12,740 additions
and
653 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[*.cs] | ||
|
||
# CS0649: Field 'UnusedLootItem.Cost' is never assigned to, and will always have its default value 0 | ||
dotnet_diagnostic.CS0649.severity = none |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Newtonsoft.Json; | ||
using System.IO; | ||
|
||
|
||
namespace RandomEnemies.Mechanics | ||
{ | ||
[Serializable] | ||
internal class UnusedLootItem | ||
{ | ||
[JsonProperty("Name")] | ||
public string Name; | ||
|
||
[JsonProperty("File")] | ||
public string File; | ||
|
||
[JsonProperty("Cost")] | ||
public int Cost; | ||
|
||
[JsonProperty("CR")] | ||
public int CR; | ||
|
||
[JsonProperty("Description")] | ||
public string Description; | ||
} | ||
|
||
internal class UnusedLootDict | ||
{ | ||
[JsonProperty("Dict")] | ||
public Dictionary<string, UnusedLootItem> LootDict = new Dictionary<string, UnusedLootItem>(); | ||
} | ||
|
||
internal static class LootJSON | ||
{ | ||
public static UnusedLootDict LoadJSON(string json) | ||
{ | ||
return JsonConvert.DeserializeObject<UnusedLootDict>(json, new JsonSerializerSettings | ||
{ | ||
TypeNameHandling = TypeNameHandling.All | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using static RandomEnemies.Main; | ||
using Kingmaker.PubSubSystem; | ||
using Kingmaker; | ||
using Kingmaker.EntitySystem; | ||
using Kingmaker.View.MapObjects; | ||
using Kingmaker.Utility; | ||
using Kingmaker.EntitySystem.Entities; | ||
using Owlcat.Runtime.Core.Utils; | ||
using Kingmaker.Blueprints.Area; | ||
using RandomEnemies.Utilities; | ||
using UnityEngine; | ||
using System.IO; | ||
using Kingmaker.Blueprints.Items; | ||
using Kingmaker.Blueprints; | ||
using Kingmaker.Items; | ||
using Kingmaker.Blueprints.Loot; | ||
using Kingmaker.RuleSystem; | ||
using Kingmaker.Blueprints.Items.Equipment; | ||
using Kingmaker.Dungeon.Blueprints; | ||
using Kingmaker.Blueprints.Root; | ||
|
||
namespace RandomEnemies.Mechanics | ||
{ | ||
class LootHandler | ||
{ | ||
|
||
public static UnusedLootDict RegLoot = LootJSON.LoadJSON(File.ReadAllText($"{ModPath}/regular.json")); | ||
|
||
public static int Level2Cost(int level) | ||
{ | ||
return (int)(Math.Pow(level, 2) * 160); | ||
} | ||
|
||
public static void GiveRandom(UnitEntityData entityData, int level) | ||
{ | ||
SetWrap.EnsureItemsGiven(); | ||
var blueprint = RegLoot.LootDict.Where(p => p.Value.CR >= (level - 5 >= 1 ? level - 5 : 1) && p.Value.CR <= level && p.Value.Cost <= Level2Cost(level))?.Random().Key; | ||
if (blueprint.IsNullOrEmpty() || SetWrap.ItemsGiven[Game.Instance.Player.GameId].Contains(blueprint)) | ||
{ | ||
if (3 < level && level < 20) | ||
GiveRandom(entityData, level + 1); | ||
return; | ||
} | ||
if (!SetWrap.ItemsGiven[Game.Instance.Player.GameId].Contains(blueprint)) | ||
SetWrap.ItemsGiven[Game.Instance.Player.GameId].Add(blueprint); | ||
Main.LogDebug($"Gave: {blueprint} to entity {entityData}"); | ||
entityData.Inventory.Add(ResourcesLibrary.TryGetBlueprint<BlueprintItem>(blueprint)); | ||
} | ||
|
||
public static int CalculateLevel() | ||
{ | ||
var roll = RulebookEvent.Dice.D100; | ||
var level = Game.Instance.Player.PartyLevel; | ||
if (0 <= roll && roll < 10) | ||
{ | ||
level -= 3; | ||
} | ||
else if (10 <= roll && roll < 25) | ||
{ | ||
level -= 2; | ||
} | ||
else if (25 <= roll && roll < 40) | ||
{ | ||
level -= 1; | ||
} | ||
else if (40 <= roll && roll < 80) | ||
{ | ||
//no change | ||
} | ||
else if (80 <= roll && roll < 95) | ||
{ | ||
level += 1; | ||
} | ||
else if (95 <= roll && roll < 99) | ||
{ | ||
level += 2; | ||
} | ||
else if (roll == 100) | ||
{ | ||
level += 3; | ||
} | ||
else | ||
{ | ||
//no change | ||
} | ||
|
||
if (level < 1) | ||
level = 1; | ||
|
||
return level; | ||
} | ||
public static bool RollForLoot() | ||
{ | ||
int roll = UnityEngine.Random.Range(1, 100); | ||
if (roll <= (int)Main.settings.ChanceForLootDrop) | ||
{ return true; } | ||
else return false; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Kingmaker; | ||
using Kingmaker.EntitySystem; | ||
using Kingmaker.Utility; | ||
using Kingmaker.View.MapObjects; | ||
using RandomEnemies.Utilities; | ||
using Owlcat.Runtime.Core.Utils; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using UnityEngine.Rendering; | ||
using Kingmaker.EntitySystem.Entities; | ||
|
||
namespace RandomEnemies.Mechanics | ||
{ | ||
public static class LootHelper | ||
{ | ||
public static IEnumerable<LootWrapper> GetEntitiesCurrentArea() | ||
{ | ||
SetWrap.EnsureContainersChecked(); | ||
var lootWrapperList = new List<LootWrapper>(); | ||
|
||
var interactionLootParts = Game.Instance.State.Units | ||
.Where<UnitEntityData>(e => e.IsPlayersEnemy) | ||
.Where<UnitEntityData>(e => !e.IsDeadAndHasLoot) | ||
.Select<EntityDataBase, InteractionLootPart>(i => i.Get<InteractionLootPart>()) | ||
.Where<InteractionLootPart>(i => i?.Loot != Game.Instance.Player.SharedStash) | ||
.NotNull<InteractionLootPart>(); | ||
|
||
var source = TempList.Get<InteractionLootPart>(); | ||
|
||
foreach (var interactionLootPart in interactionLootParts) | ||
{ | ||
if (!interactionLootPart.IsViewed) | ||
source.Add(interactionLootPart); | ||
} | ||
|
||
var collection = source.Distinct<InteractionLootPart>((IEqualityComparer<InteractionLootPart>)new MassLootHelper.LootDuplicateCheck()).Select<InteractionLootPart, LootWrapper>((Func<InteractionLootPart, LootWrapper>)(i => new LootWrapper() | ||
{ | ||
InteractionLoot = i | ||
})); | ||
|
||
lootWrapperList.AddRange(collection); | ||
return (IEnumerable<LootWrapper>)lootWrapperList; | ||
} | ||
|
||
public static int Worth(this LootWrapper container) | ||
{ | ||
return container.InteractionLoot.Loot.Items.Select(i => i.Cost).Sum(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Newtonsoft.Json; | ||
using System.IO; | ||
|
||
|
||
namespace RandomEnemies.Loot | ||
{ | ||
[Serializable] | ||
internal class UnusedLootItem | ||
{ | ||
[JsonProperty("Name")] | ||
public string Name; | ||
|
||
[JsonProperty("File")] | ||
public string File; | ||
|
||
[JsonProperty("Cost")] | ||
public int Cost; | ||
|
||
[JsonProperty("CR")] | ||
public int CR; | ||
|
||
[JsonProperty("Description")] | ||
public string Description; | ||
} | ||
|
||
internal class UnusedLootDict | ||
{ | ||
[JsonProperty("Dict")] | ||
public Dictionary<string, UnusedLootItem> LootDict = new Dictionary<string, UnusedLootItem>(); | ||
} | ||
|
||
internal static class LootJSON | ||
{ | ||
public static UnusedLootDict LoadJSON(string json) | ||
{ | ||
return JsonConvert.DeserializeObject<UnusedLootDict>(json, new JsonSerializerSettings | ||
{ | ||
TypeNameHandling = TypeNameHandling.All | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.