Decompiled source of BloodyRewards v1.0.11

BloodyRewards.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.Json;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Unity.IL2CPP;
using Bloodstone.API;
using Bloody.Core;
using Bloody.Core.API.v1;
using Bloody.Core.GameData.v1;
using Bloody.Core.Helper.v1;
using Bloody.Core.Methods;
using Bloody.Core.Models.v1;
using Bloody.Core.Models.v1.Base;
using BloodyRewards.DB;
using BloodyRewards.DB.Models;
using BloodyRewards.Systems;
using BloodyRewards.Utils;
using BloodyWallet.API;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using ProjectM;
using ProjectM.Network;
using Stunlock.Core;
using Stunlock.Network;
using Unity.Collections;
using Unity.Entities;
using UnityEngine;
using VampireCommandFramework;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("BloodyRewards")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Rewards System for VRising")]
[assembly: AssemblyFileVersion("1.0.11.0")]
[assembly: AssemblyInformationalVersion("1.0.11+1.Branch.master.Sha.e624520149cc56c90ae3906e57c9af2fc0468efd")]
[assembly: AssemblyProduct("BloodyRewards")]
[assembly: AssemblyTitle("BloodyRewards")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.11.0")]
[module: UnverifiableCode]
namespace BloodyRewards
{
	[BepInPlugin("BloodyRewards", "BloodyRewards", "1.0.11")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin, IRunOnInitialized
	{
		private Harmony _harmony;

		public static Logger Logger;

		public static SystemsCore SystemsCore;

		public static ConfigEntry<bool> RewardsEnabled;

		public static ConfigEntry<int> DropNpcPercentage;

		public static ConfigEntry<int> IncrementPercentageDropEveryTenLevelsNpc;

		public static ConfigEntry<int> DropdNpcRewardsMin;

		public static ConfigEntry<int> DropNpcRewardsMax;

		public static ConfigEntry<int> MaxRewardsPerDayPerPlayerNpc;

		public static ConfigEntry<int> DropdVBloodPercentage;

		public static ConfigEntry<int> IncrementPercentageDropEveryTenLevelsVBlood;

		public static ConfigEntry<int> DropVBloodRewardsMin;

		public static ConfigEntry<int> DropVBloodRewardsMax;

		public static ConfigEntry<int> MaxRewardsPerDayPerPlayerVBlood;

		public static ConfigEntry<int> DropPvpPercentage;

		public static ConfigEntry<int> IncrementPercentageDropEveryTenLevelsPvp;

		public static ConfigEntry<int> DropPvpRewardsMin;

		public static ConfigEntry<int> DropPvpRewardsMax;

		public static ConfigEntry<int> MaxRewardsPerDayPerPlayerPvp;

		public static ConfigEntry<int> MaximumDeathsSamePlayer { get; set; }

		public static ConfigEntry<int> CoolDownDeathsSamePlayer { get; set; }

		public static ConfigEntry<bool> WalletSystem { get; set; }

		public static ConfigEntry<int> WalletAmountPveMax { get; set; }

		public static ConfigEntry<int> WalletAmountPveMin { get; set; }

		public static ConfigEntry<int> WalletAmountVBloodMax { get; set; }

		public static ConfigEntry<int> WalletAmountVBloodMin { get; set; }

		public static ConfigEntry<int> WalletAmountPVPMax { get; set; }

		public static ConfigEntry<int> WalletAmountPVPMin { get; set; }

		public static ConfigEntry<bool> DailyLoginRewards { get; set; }

		public static ConfigEntry<int> AmountDailyLoginReward { get; set; }

		public static ConfigEntry<bool> ConnectionTimeReward { get; set; }

		public static ConfigEntry<int> AmountTimeReward { get; set; }

		public static ConfigEntry<int> TimeReward { get; set; }

		public override void Load()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			Logger = new Logger(((BasePlugin)this).Log);
			_harmony = new Harmony("BloodyRewards");
			CommandRegistry.RegisterAll();
			EventsHandlerSystem.OnInitialize += new OnGameDataInitializedEventHandler(GameDataOnInitialize);
			InitConfigServer();
			LoadDataFromFiles.CreateFilesConfig();
			Logger.LogInfo("Plugin BloodyRewards version 1.0.11 is loaded!");
		}

		private void GameDataOnInitialize(World world)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			SystemsCore = Core.SystemsCore;
			LoadDataFromFiles.SetConfigMod();
			if (ConfigDB.DailyLoginRewards)
			{
				EventsHandlerSystem.OnUserConnected += new OnUserConnectedEventHandler(OnlineRewards.OnlineUser);
			}
			if (ConfigDB.ConnectionTimeReward)
			{
				ConnectionTimeSystemRewards.UserRewardTimne();
			}
			if (ConfigDB.WalletSystem)
			{
				EventsHandlerSystem.OnDeath += new DeathEventHandler(RewardSystemVirtual.ServerEvents_OnDeath);
				EventsHandlerSystem.OnVampireDowned += new VampireDownedHandler(RewardSystemVirtual.ServerEvents_OnVampireDowned);
			}
			else
			{
				EventsHandlerSystem.OnDeath += new DeathEventHandler(RewardSystem.ServerEvents_OnDeath);
				EventsHandlerSystem.OnVampireDowned += new VampireDownedHandler(RewardSystem.ServerEvents_OnVampireDowned);
			}
			LoadDataFromFiles.LoadRewardsToDB();
			LoadDataFromFiles.LoadUserRewardsPerDayToDB();
			LoadDataFromFiles.LoadRewardLDayliistFiles();
			LoadDataFromFiles.LoadKillersListFiles();
		}

		public override bool Unload()
		{
			CommandRegistry.UnregisterAssembly();
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			return true;
		}

		private void InitConfigServer()
		{
			RewardsEnabled = ((BasePlugin)this).Config.Bind<bool>("RewardsSystem", "enabled", true, "Enable Rewards System");
			DropNpcPercentage = ((BasePlugin)this).Config.Bind<int>("RewardsSystem", "minPercentageDropNpc", 5, "Percent chance that an NPC will drop the type of reward from the shop");
			IncrementPercentageDropEveryTenLevelsNpc = ((BasePlugin)this).Config.Bind<int>("RewardsSystem", "IncrementPercentageDropEveryTenLevelsNpc", 5, "Percentage increase for every rank of 10 levels of the NPC");
			DropdNpcRewardsMin = ((BasePlugin)this).Config.Bind<int>("RewardsSystem", "DropdNpcRewardsMin", 1, "Minimum reward an NPC can drop");
			DropNpcRewardsMax = ((BasePlugin)this).Config.Bind<int>("RewardsSystem", "DropNpcRewardsMax", 5, "Maximum reward an NPC can drop");
			MaxRewardsPerDayPerPlayerNpc = ((BasePlugin)this).Config.Bind<int>("RewardsSystem", "MaxRewardsPerDayPerPlayerNpc", 5, "Maximum number of reward that a user can get per day by NPC death");
			DropdVBloodPercentage = ((BasePlugin)this).Config.Bind<int>("RewardsSystem", "minPercentageDropVBlood", 20, "Percent chance that an VBlood will drop the type of reward from the shop");
			IncrementPercentageDropEveryTenLevelsVBlood = ((BasePlugin)this).Config.Bind<int>("RewardsSystem", "IncrementPercentageDropEveryTenLevelsVBlood", 5, "Percentage increase for every rank of 10 levels of the VBlood");
			DropVBloodRewardsMin = ((BasePlugin)this).Config.Bind<int>("RewardsSystem", "DropVBloodRewardsMin", 10, "Minimum reward an VBlood can drop");
			DropVBloodRewardsMax = ((BasePlugin)this).Config.Bind<int>("RewardsSystem", "DropVBloodRewardsMax", 20, "Maximum reward an VBlood can drop");
			MaxRewardsPerDayPerPlayerVBlood = ((BasePlugin)this).Config.Bind<int>("RewardsSystem", "MaxRewardsPerDayPerPlayerVBlood", 20, "Maximum number of reward that a user can get per day by VBlood death");
			DropPvpPercentage = ((BasePlugin)this).Config.Bind<int>("RewardsSystem", "minPercentageDropPvp", 100, "Percent chance that victory in a PVP duel will drop the type of reward in the store");
			IncrementPercentageDropEveryTenLevelsPvp = ((BasePlugin)this).Config.Bind<int>("RewardsSystem", "IncrementPercentageDropEveryTenLevelsPvp", 5, "Percentage increase for every rank of 10 levels of the Player killed in pvp duel");
			DropPvpRewardsMin = ((BasePlugin)this).Config.Bind<int>("RewardsSystem", "DropPvpRewardsMin", 15, "Minimum reward can drop victory in PVP");
			DropPvpRewardsMax = ((BasePlugin)this).Config.Bind<int>("RewardsSystem", "DropPvpRewardsMax", 20, "Maximum reward can drop victory in PVP");
			MaxRewardsPerDayPerPlayerPvp = ((BasePlugin)this).Config.Bind<int>("RewardsSystem", "MaxRewardsPerDayPerPlayerPvp", 20, "Maximum number of reward that a user can get per day by victory in PVP");
			MaximumDeathsSamePlayer = ((BasePlugin)this).Config.Bind<int>("RewardsSystem", "MaximumDeathsSamePlayer", 1, "Maximum number of consecutive deaths to the same player that are allowed before executing the cooldown");
			CoolDownDeathsSamePlayer = ((BasePlugin)this).Config.Bind<int>("RewardsSystem", "CoolDownDeathsSamePlayer", 30, "Minutes a player must wait to receive a reward for killing the same player again");
			WalletSystem = ((BasePlugin)this).Config.Bind<bool>("Wallet", "enabled", false, "Activate rewards in virtual currency through BloodyWallet ( https://github.com/oscarpedrero/BloodyWallet )");
			WalletAmountPveMax = ((BasePlugin)this).Config.Bind<int>("Wallet", "amountPveMax", 2, "Maximum amount of virtual coins for when you drop in PVE");
			WalletAmountPveMin = ((BasePlugin)this).Config.Bind<int>("Wallet", "amountPveMin", 1, "Minumun amount of virtual coins for when you drop in PVE");
			WalletAmountVBloodMax = ((BasePlugin)this).Config.Bind<int>("Wallet", "amountVBloodMax", 2, "Maximum amount of virtual coins for when you drop in VBlood");
			WalletAmountVBloodMin = ((BasePlugin)this).Config.Bind<int>("Wallet", "amountVBloodMin", 1, "Minimun amount of virtual coins for when you drop in VBlood");
			WalletAmountPVPMax = ((BasePlugin)this).Config.Bind<int>("Wallet", "amountPVPMax", 2, "Maximum amount of virtual coins for when you drop in PVE");
			WalletAmountPVPMin = ((BasePlugin)this).Config.Bind<int>("Wallet", "amountPVPMin", 1, "Minimun amount of virtual coins for when you drop in PVE");
			DailyLoginRewards = ((BasePlugin)this).Config.Bind<bool>("DayliLoginRewardsSystem", "DailyLoginRewards", true, "Daily reward for connecting to the server");
			AmountDailyLoginReward = ((BasePlugin)this).Config.Bind<int>("DayliLoginRewardsSystem", "AmountDailyLoginReward", 15, "Amount of rewards for login");
			ConnectionTimeReward = ((BasePlugin)this).Config.Bind<bool>("ConnectionTimeReward", "ConnectionTimeReward", true, "Connection time reward");
			AmountTimeReward = ((BasePlugin)this).Config.Bind<int>("ConnectionTimeReward", "AmountTimeReward", 1, "Amount of rewards for connection time");
			TimeReward = ((BasePlugin)this).Config.Bind<int>("ConnectionTimeReward", "TimeReward", 5, "Every how many minutes the reward will be awarded");
		}

		public void OnGameInitialized()
		{
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "BloodyRewards";

		public const string PLUGIN_NAME = "BloodyRewards";

		public const string PLUGIN_VERSION = "1.0.11";
	}
}
namespace BloodyRewards.Utils
{
	internal class Helpers
	{
		internal static void ProcessVampireDowned(Entity entity)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			Entity val = default(Entity);
			if (!VampireDownedServerEventSystem.TryFindRootOwner(entity, 1, Plugin.SystemsCore.EntityManager, ref val))
			{
				Plugin.Logger.LogMessage("Couldn't get victim entity");
				return;
			}
			Entity val2 = default(Entity);
			if (!VampireDownedServerEventSystem.TryFindRootOwner(ECSExtensions.Read<VampireDownedBuff>(entity).Source, 1, Plugin.SystemsCore.EntityManager, ref val2))
			{
				Plugin.Logger.LogMessage("Couldn't get victim entity");
				return;
			}
			PlayerCharacter victim = ECSExtensions.Read<PlayerCharacter>(val);
			Plugin.Logger.LogMessage($"{victim.Name} is victim");
			if (ECSExtensions.Has<UnitLevel>(val2))
			{
				Plugin.Logger.LogInfo($"{victim.Name} was killed by a unit. [He is currently not receiving a reward]");
				return;
			}
			if (!ECSExtensions.Has<PlayerCharacter>(val2))
			{
				Plugin.Logger.LogWarning($"Killer could not be identified for {victim.Name}, if you know how to reproduce this please contact Trodi on discord or report on github");
				return;
			}
			PlayerCharacter killer = ECSExtensions.Read<PlayerCharacter>(val2);
			if (killer.UserEntity == victim.UserEntity)
			{
				Plugin.Logger.LogInfo($"{victim.Name} killed themselves. [He is currently not receiving a reward]");
				return;
			}
			PvpModel pvpModel = new PvpModel();
			pvpModel.killer = ((FixedString64Bytes)(ref killer.Name)).Value;
			pvpModel.target = ((FixedString64Bytes)(ref victim.Name)).Value;
			pvpModel.date = DateTime.Now;
			List<PvpModel> list = ShareDB.KillersPVP.Where((PvpModel x) => x.target == ((FixedString64Bytes)(ref victim.Name)).Value && x.killer == ((FixedString64Bytes)(ref killer.Name)).Value && x.date.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd")).ToList();
			if (list.Count == 0)
			{
				ShareDB.KillersPVP.Add(pvpModel);
				if (ConfigDB.WalletSystem)
				{
					RewardSystemVirtual.pvpReward(val2, val);
				}
				else
				{
					RewardSystem.pvpReward(val2, val);
				}
				SaveDataToFiles.saveKillerPVPList();
			}
			else if (list.Count <= Plugin.MaximumDeathsSamePlayer.Value)
			{
				ShareDB.KillersPVP.Add(pvpModel);
				if (ConfigDB.WalletSystem)
				{
					RewardSystemVirtual.pvpReward(val2, val);
				}
				else
				{
					RewardSystem.pvpReward(val2, val);
				}
				SaveDataToFiles.saveKillerPVPList();
			}
			else
			{
				if (!((list.LastOrDefault().date - DateTime.Now).TotalMinutes >= (double)Plugin.CoolDownDeathsSamePlayer.Value))
				{
					return;
				}
				foreach (PvpModel item in list)
				{
					ShareDB.KillersPVP.Remove(item);
				}
				if (ConfigDB.WalletSystem)
				{
					RewardSystemVirtual.pvpReward(val2, val);
				}
				else
				{
					RewardSystem.pvpReward(val2, val);
				}
				ShareDB.KillersPVP.Add(pvpModel);
				SaveDataToFiles.saveKillerPVPList();
			}
		}
	}
}
namespace BloodyRewards.Systems
{
	internal class ConnectionTimeSystemRewards : MonoBehaviour
	{
		internal static Action action;

		internal static Coroutine TimerCoroutine;

		internal static void UserRewardTimne()
		{
			action = delegate
			{
				//IL_014d: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
				IEnumerable<UserModel> online = GameData.Users.Online;
				DayliLoginTimeModel dayliLoginTimeModel = new DayliLoginTimeModel();
				DateTime now = DateTime.Now;
				string text = default(string);
				PrefabGUID val = default(PrefabGUID);
				foreach (UserModel user in online)
				{
					try
					{
						dayliLoginTimeModel = (from x in ShareDB.getDayliLoginTimeModel()
							where x.player == user.CharacterName
							select x).FirstOrDefault();
						if (dayliLoginTimeModel == null)
						{
							dayliLoginTimeModel.player = user.CharacterName;
							dayliLoginTimeModel.LastDateTime = now;
							dayliLoginTimeModel.LastDayConnection = now.ToString("yyyy/MM/dd");
							ShareDB.getDayliLoginTimeModel().Add(dayliLoginTimeModel);
							SaveDataToFiles.saveDayliTimeLogin();
						}
						else if ((now - dayliLoginTimeModel.LastDateTime).TotalMinutes + 1.0 >= (double)ConfigDB.TimeReward)
						{
							dayliLoginTimeModel.LastDayConnection = now.ToString("yyyy/MM/dd");
							dayliLoginTimeModel.LastDateTime = now;
							if (ConfigDB.WalletSystem)
							{
								WalletAPI.AddTokenToUser(ConfigDB.AmountTimeReward, "BloodyRewards", ((EntityModel)user).Entity, ((EntityModel)user).Entity, ref text);
								UserModelMethods.SendSystemMessage(user, text);
							}
							else
							{
								List<RewardModel> list = ShareDB.getRewardList().ToList();
								int index = new Random().Next(list.Count);
								((PrefabGUID)(ref val))..ctor(list[index].guid);
								UserModelMethods.DropItemNearby(user, val, ConfigDB.AmountTimeReward);
							}
							SaveDataToFiles.saveDayliTimeLogin();
						}
					}
					catch (Exception ex)
					{
						Plugin.Logger.LogError("Error generating connection reward for user " + user.CharacterName + ": " + ex.Message);
					}
				}
				Plugin.Logger.LogInfo($"Next checking at {ConfigDB.TimeReward * 60}");
			};
			Plugin.Logger.LogInfo($"Next checking at {ConfigDB.TimeReward * 60}");
			TimerCoroutine = CoroutineHandler.StartRepeatingCoroutine(action, (float)(ConfigDB.TimeReward * 60));
		}
	}
	internal class OnlineRewards
	{
		internal static void OnlineUser(ServerBootstrapSystem sender, NetConnectionId netConnectionId)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			if (!ConfigDB.DailyLoginRewards)
			{
				return;
			}
			int num = sender._NetEndPointToApprovedUserIndex[netConnectionId];
			Entity userEntity = ((Il2CppArrayBase<ServerClient>)(object)sender._ApprovedUsersLookup)[num].UserEntity;
			UserModel val = GameData.Users.FromEntity(userEntity);
			bool num2 = IsNewUser(userEntity);
			string userNick = val.CharacterName;
			if (num2)
			{
				return;
			}
			DayliLoginTimeModel dayliLoginTimeModel = (from x in ShareDB.getDayliLoginTimeModel()
				where x.player == userNick
				select x).FirstOrDefault();
			if (dayliLoginTimeModel != null)
			{
				if (dayliLoginTimeModel.LastDayConnection != DateTime.Now.ToString("yyyy/MM/dd"))
				{
					dayliLoginTimeModel.LastDayConnection = DateTime.Now.ToString("yyyy/MM/dd");
					if (ConfigDB.WalletSystem)
					{
						string text = default(string);
						WalletAPI.AddTokenToUser(ConfigDB.AmountDailyLoginReward, "BloodyRewards", ((EntityModel)val).Entity, ((EntityModel)val).Entity, ref text);
						UserModelMethods.SendSystemMessage(val, text);
					}
					else
					{
						List<RewardModel> list = ShareDB.getRewardList().ToList();
						int index = new Random().Next(list.Count);
						PrefabGUID val2 = default(PrefabGUID);
						((PrefabGUID)(ref val2))..ctor(list[index].guid);
						UserModelMethods.DropItemNearby(val, val2, ConfigDB.AmountDailyLoginReward);
					}
					SaveDataToFiles.saveDayliTimeLogin();
				}
				return;
			}
			if (ConfigDB.WalletSystem)
			{
				string text2 = default(string);
				WalletAPI.AddTokenToUser(ConfigDB.AmountDailyLoginReward, "BloodyRewards", ((EntityModel)val).Entity, ((EntityModel)val).Entity, ref text2);
				UserModelMethods.SendSystemMessage(val, text2);
			}
			else
			{
				List<RewardModel> list2 = ShareDB.getRewardList().ToList();
				int index2 = new Random().Next(list2.Count);
				PrefabGUID val3 = default(PrefabGUID);
				((PrefabGUID)(ref val3))..ctor(list2[index2].guid);
				UserModelMethods.DropItemNearby(val, val3, ConfigDB.AmountDailyLoginReward);
			}
			DayliLoginTimeModel dayliLoginTimeModel2 = new DayliLoginTimeModel();
			dayliLoginTimeModel2.player = val.CharacterName;
			dayliLoginTimeModel2.LastDateTime = DateTime.Now;
			dayliLoginTimeModel2.LastDayConnection = DateTime.Now.ToString("yyyy/MM/dd");
			ShareDB.getDayliLoginTimeModel().Add(dayliLoginTimeModel2);
			SaveDataToFiles.saveDayliTimeLogin();
		}

		public static bool IsNewUser(Entity userEntity)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			User val = ECSExtensions.Read<User>(userEntity);
			return ((FixedString64Bytes)(ref val.CharacterName)).IsEmpty;
		}
	}
	public class RewardSystem
	{
		private static EntityManager em = Plugin.SystemsCore.EntityManager;

		private static Random rnd = new Random();

		private static PrefabGUID vBloodType = Prefabs.BloodType_VBlood;

		public static void ServerEvents_OnDeath(DeathEventListenerSystem sender, NativeArray<DeathEvent> deathEvents)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			if (ConfigDB.WalletSystem)
			{
				return;
			}
			Enumerator<DeathEvent> enumerator = deathEvents.GetEnumerator();
			while (enumerator.MoveNext())
			{
				DeathEvent current = enumerator.Current;
				if (((EntityManager)(ref em)).HasComponent<PlayerCharacter>(current.Killer) && ((EntityManager)(ref em)).HasComponent<Movement>(current.Died) && ((EntityManager)(ref em)).HasComponent<UnitLevel>(current.Died))
				{
					pveReward(current.Killer, current.Died);
				}
			}
		}

		public static void ServerEvents_OnVampireDowned(VampireDownedServerEventSystem sender, NativeArray<Entity> vampireDownedEntitys)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if (!ConfigDB.WalletSystem)
			{
				Enumerator<Entity> enumerator = vampireDownedEntitys.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Helpers.ProcessVampireDowned(enumerator.Current);
				}
			}
		}

		private static void pveReward(Entity killer, Entity died)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if (!((EntityManager)(ref em)).HasComponent<Minion>(died))
			{
				PlayerCharacter componentData = ((EntityManager)(ref em)).GetComponentData<PlayerCharacter>(killer);
				UserModel userModelKiller = GameData.Users.FromEntity(componentData.UserEntity);
				ModifiableInt level = ((EntityManager)(ref em)).GetComponentData<UnitLevel>(died).Level;
				if (ECSExtensions.Has<VBloodUnit>(died) ? true : false)
				{
					rewardForVBlood(userModelKiller, ModifiableInt.op_Implicit(level));
				}
				else
				{
					rewardForNPC(userModelKiller, ModifiableInt.op_Implicit(level));
				}
			}
		}

		internal static void pvpReward(Entity killer, Entity died)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			if (((EntityManager)(ref em)).HasComponent<Minion>(died))
			{
				return;
			}
			PlayerCharacter componentData = ((EntityManager)(ref em)).GetComponentData<PlayerCharacter>(killer);
			UserModel val = GameData.Users.FromEntity(componentData.UserEntity);
			List<RewardModel> list = ShareDB.getRewardList().ToList();
			int index = new Random().Next(list.Count);
			PrefabGUID val2 = default(PrefabGUID);
			((PrefabGUID)(ref val2))..ctor(list[index].guid);
			((EntityManager)(ref em)).GetComponentData<PlayerCharacter>(died);
			if (!probabilityOeneratingReward(calculateDropPercentage((int)GameData.Users.FromEntity(componentData.UserEntity).Character.Equipment.Level, ConfigDB.DropPvpPercentage, ConfigDB.IncrementPercentageDropEveryTenLevelsPvp)))
			{
				return;
			}
			int num = 0;
			num = rnd.Next(ConfigDB.DropPvpRewardsMin, ConfigDB.DropPvpRewardsMax);
			if (!ConfigDB.searchUserRewardPerDay(val.CharacterName, out var userRewardsPerDayModel))
			{
				return;
			}
			int num2 = userRewardsPerDayModel.AmountPvp + num;
			if (num2 <= ConfigDB.MaxRewardsPerDayPerPlayerPvp)
			{
				userRewardsPerDayModel.AmountPvp = num2;
				Entity val3 = default(Entity);
				if (!UserModelMethods.TryGiveItem(val, val2, num, ref val3))
				{
					UserModelMethods.DropItemNearby(val, val2, num);
				}
				ConfigDB.addUserRewardsPerDayToList(userRewardsPerDayModel);
				SaveDataToFiles.saveUsersRewardsPerDay();
			}
			else if (userRewardsPerDayModel.AmountNpc < ConfigDB.MaxRewardsPerDayPerPlayerPvp)
			{
				num = ConfigDB.MaxRewardsPerDayPerPlayerPvp - userRewardsPerDayModel.AmountPvp;
				userRewardsPerDayModel.AmountPvp += num;
				Entity val4 = default(Entity);
				if (!UserModelMethods.TryGiveItem(val, val2, num, ref val4))
				{
					UserModelMethods.DropItemNearby(val, val2, num);
				}
				ConfigDB.addUserRewardsPerDayToList(userRewardsPerDayModel);
				SaveDataToFiles.saveUsersRewardsPerDay();
			}
		}

		private static void rewardForNPC(UserModel userModelKiller, int diedLevel)
		{
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			List<RewardModel> list = (from x in ShareDB.getRewardList()
				where !x.onlyVBlood
				select x).ToList();
			if (list.Count == 0)
			{
				list = ShareDB.getRewardList();
			}
			int index = new Random().Next(list.Count);
			PrefabGUID val = default(PrefabGUID);
			((PrefabGUID)(ref val))..ctor(list[index].guid);
			if (!probabilityOeneratingReward(calculateDropPercentage(diedLevel, ConfigDB.DropNpcPercentage, ConfigDB.IncrementPercentageDropEveryTenLevelsNpc)))
			{
				return;
			}
			int num = 0;
			num = rnd.Next(ConfigDB.DropdNpcRewardsMin, ConfigDB.DropNpcRewardsMax);
			if (!ConfigDB.searchUserRewardPerDay(userModelKiller.CharacterName, out var userRewardsPerDayModel))
			{
				return;
			}
			int num2 = userRewardsPerDayModel.AmountNpc + num;
			if (num2 <= ConfigDB.MaxRewardsPerDayPerPlayerNpc)
			{
				userRewardsPerDayModel.AmountNpc = num2;
				Entity val2 = default(Entity);
				if (!UserModelMethods.TryGiveItem(userModelKiller, val, num, ref val2))
				{
					UserModelMethods.DropItemNearby(userModelKiller, val, num);
				}
				ConfigDB.addUserRewardsPerDayToList(userRewardsPerDayModel);
				SaveDataToFiles.saveUsersRewardsPerDay();
			}
			else if (userRewardsPerDayModel.AmountNpc < ConfigDB.MaxRewardsPerDayPerPlayerNpc)
			{
				num = ConfigDB.MaxRewardsPerDayPerPlayerNpc - userRewardsPerDayModel.AmountNpc;
				userRewardsPerDayModel.AmountNpc += num;
				Entity val3 = default(Entity);
				if (!UserModelMethods.TryGiveItem(userModelKiller, val, num, ref val3))
				{
					UserModelMethods.DropItemNearby(userModelKiller, val, num);
				}
				ConfigDB.addUserRewardsPerDayToList(userRewardsPerDayModel);
				SaveDataToFiles.saveUsersRewardsPerDay();
			}
		}

		private static void rewardForVBlood(UserModel userModelKiller, int diedLevel)
		{
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			List<RewardModel> list = (from x in ShareDB.getRewardList()
				where x.onlyVBlood
				select x).ToList();
			if (list.Count == 0)
			{
				list = ShareDB.getRewardList();
			}
			int index = new Random().Next(list.Count);
			PrefabGUID val = default(PrefabGUID);
			((PrefabGUID)(ref val))..ctor(list[index].guid);
			if (!probabilityOeneratingReward(calculateDropPercentage(diedLevel, ConfigDB.DropdVBloodPercentage, ConfigDB.IncrementPercentageDropEveryTenLevelsVBlood)))
			{
				return;
			}
			int num = 0;
			num = rnd.Next(ConfigDB.DropVBloodRewardsMin, ConfigDB.DropVBloodRewardsMax);
			if (!ConfigDB.searchUserRewardPerDay(userModelKiller.CharacterName, out var userRewardsPerDayModel))
			{
				return;
			}
			int num2 = userRewardsPerDayModel.AmountVBlood + num;
			if (num2 <= ConfigDB.MaxRewardsPerDayPerPlayerVBlood)
			{
				userRewardsPerDayModel.AmountVBlood = num2;
				Entity val2 = default(Entity);
				if (!UserModelMethods.TryGiveItem(userModelKiller, val, num, ref val2))
				{
					UserModelMethods.DropItemNearby(userModelKiller, val, num);
				}
				ConfigDB.addUserRewardsPerDayToList(userRewardsPerDayModel);
				SaveDataToFiles.saveUsersRewardsPerDay();
			}
			else if (userRewardsPerDayModel.AmountVBlood < ConfigDB.MaxRewardsPerDayPerPlayerVBlood)
			{
				num = ConfigDB.MaxRewardsPerDayPerPlayerVBlood - userRewardsPerDayModel.AmountVBlood;
				userRewardsPerDayModel.AmountVBlood += num;
				Entity val3 = default(Entity);
				if (!UserModelMethods.TryGiveItem(userModelKiller, val, num, ref val3))
				{
					UserModelMethods.DropItemNearby(userModelKiller, val, num);
				}
				ConfigDB.addUserRewardsPerDayToList(userRewardsPerDayModel);
				SaveDataToFiles.saveUsersRewardsPerDay();
			}
		}

		private static int calculateDropPercentage(int level, int initialPercent, int incremental)
		{
			return decimal.ToInt32(Math.Ceiling((decimal)(level / 10)) * (decimal)incremental) + initialPercent;
		}

		private static bool probabilityOeneratingReward(int percentage)
		{
			if (new Random().Next(1, 100) <= percentage)
			{
				return true;
			}
			return false;
		}
	}
	public class RewardSystemVirtual
	{
		private static EntityManager em = Plugin.SystemsCore.EntityManager;

		private static Random rnd = new Random();

		private static PrefabGUID vBloodType = Prefabs.BloodType_VBlood;

		public static void ServerEvents_OnDeath(DeathEventListenerSystem sender, NativeArray<DeathEvent> deathEvents)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			if (!ConfigDB.WalletSystem)
			{
				return;
			}
			Enumerator<DeathEvent> enumerator = deathEvents.GetEnumerator();
			while (enumerator.MoveNext())
			{
				DeathEvent current = enumerator.Current;
				if (((EntityManager)(ref em)).HasComponent<PlayerCharacter>(current.Killer) && ((EntityManager)(ref em)).HasComponent<Movement>(current.Died) && ((EntityManager)(ref em)).HasComponent<UnitLevel>(current.Died))
				{
					pveReward(current.Killer, current.Died);
				}
			}
		}

		public static void ServerEvents_OnVampireDowned(VampireDownedServerEventSystem sender, NativeArray<Entity> vampireDownedEntitys)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if (ConfigDB.WalletSystem)
			{
				Enumerator<Entity> enumerator = vampireDownedEntitys.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Helpers.ProcessVampireDowned(enumerator.Current);
				}
			}
		}

		private static void pveReward(Entity killer, Entity died)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if (!((EntityManager)(ref em)).HasComponent<Minion>(died))
			{
				PlayerCharacter componentData = ((EntityManager)(ref em)).GetComponentData<PlayerCharacter>(killer);
				UserModel userModelKiller = GameData.Users.FromEntity(componentData.UserEntity);
				ModifiableInt level = ((EntityManager)(ref em)).GetComponentData<UnitLevel>(died).Level;
				if (ECSExtensions.Has<VBloodUnit>(died) ? true : false)
				{
					rewardForVBlood(userModelKiller, ModifiableInt.op_Implicit(level));
				}
				else
				{
					rewardForNPC(userModelKiller, ModifiableInt.op_Implicit(level));
				}
			}
		}

		internal static void pvpReward(Entity killer, Entity died)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			if (((EntityManager)(ref em)).HasComponent<Minion>(died))
			{
				return;
			}
			PlayerCharacter componentData = ((EntityManager)(ref em)).GetComponentData<PlayerCharacter>(killer);
			UserModel val = GameData.Users.FromEntity(componentData.UserEntity);
			((EntityManager)(ref em)).GetComponentData<PlayerCharacter>(died);
			if (!probabilityOeneratingReward(calculateDropPercentage((int)GameData.Users.FromEntity(componentData.UserEntity).Character.Equipment.Level, ConfigDB.DropPvpPercentage, ConfigDB.IncrementPercentageDropEveryTenLevelsPvp)))
			{
				return;
			}
			int num = 0;
			num = rnd.Next(ConfigDB.WalletAmountPVPMin, ConfigDB.WalletAmountPVPMax);
			if (ConfigDB.searchUserRewardPerDay(val.CharacterName, out var userRewardsPerDayModel))
			{
				int num2 = userRewardsPerDayModel.AmountPvp + num;
				if (num2 <= ConfigDB.MaxRewardsPerDayPerPlayerPvp)
				{
					userRewardsPerDayModel.AmountPvp = num2;
					string text = default(string);
					WalletAPI.AddTokenToUser(num, "BloodyRewards", ((EntityModel)val).Entity, ((EntityModel)val).Entity, ref text);
					UserModelMethods.SendSystemMessage(val, text);
					ConfigDB.addUserRewardsPerDayToList(userRewardsPerDayModel);
					SaveDataToFiles.saveUsersRewardsPerDay();
					Plugin.Logger.LogInfo($"Drop PVP {num} rewards");
				}
				else if (userRewardsPerDayModel.AmountNpc < ConfigDB.MaxRewardsPerDayPerPlayerPvp)
				{
					num = ConfigDB.MaxRewardsPerDayPerPlayerPvp - userRewardsPerDayModel.AmountPvp;
					userRewardsPerDayModel.AmountPvp += num;
					string text2 = default(string);
					WalletAPI.AddTokenToUser(num, "BloodyRewards", ((EntityModel)val).Entity, ((EntityModel)val).Entity, ref text2);
					UserModelMethods.SendSystemMessage(val, text2);
					ConfigDB.addUserRewardsPerDayToList(userRewardsPerDayModel);
					SaveDataToFiles.saveUsersRewardsPerDay();
					Plugin.Logger.LogInfo($"Drop PVP {num} rewards");
				}
			}
		}

		private static void rewardForNPC(UserModel userModelKiller, int diedLevel)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			if (!probabilityOeneratingReward(calculateDropPercentage(diedLevel, ConfigDB.DropNpcPercentage, ConfigDB.IncrementPercentageDropEveryTenLevelsNpc)))
			{
				return;
			}
			int num = 0;
			num = rnd.Next(ConfigDB.WalletAmountPveMin, ConfigDB.WalletAmountPveMax);
			if (ConfigDB.searchUserRewardPerDay(userModelKiller.CharacterName, out var userRewardsPerDayModel))
			{
				int num2 = userRewardsPerDayModel.AmountNpc + num;
				if (num2 <= ConfigDB.MaxRewardsPerDayPerPlayerNpc)
				{
					userRewardsPerDayModel.AmountNpc = num2;
					string text = default(string);
					WalletAPI.AddTokenToUser(num, "BloodyRewards", ((EntityModel)userModelKiller).Entity, ((EntityModel)userModelKiller).Entity, ref text);
					UserModelMethods.SendSystemMessage(userModelKiller, text);
					ConfigDB.addUserRewardsPerDayToList(userRewardsPerDayModel);
					SaveDataToFiles.saveUsersRewardsPerDay();
				}
				else if (userRewardsPerDayModel.AmountNpc < ConfigDB.MaxRewardsPerDayPerPlayerNpc)
				{
					num = ConfigDB.MaxRewardsPerDayPerPlayerNpc - userRewardsPerDayModel.AmountNpc;
					userRewardsPerDayModel.AmountNpc += num;
					string text2 = default(string);
					WalletAPI.AddTokenToUser(num, "BloodyRewards", ((EntityModel)userModelKiller).Entity, ((EntityModel)userModelKiller).Entity, ref text2);
					UserModelMethods.SendSystemMessage(userModelKiller, text2);
					ConfigDB.addUserRewardsPerDayToList(userRewardsPerDayModel);
					SaveDataToFiles.saveUsersRewardsPerDay();
				}
			}
		}

		private static void rewardForVBlood(UserModel userModelKiller, int diedLevel)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			if (!probabilityOeneratingReward(calculateDropPercentage(diedLevel, ConfigDB.DropdVBloodPercentage, ConfigDB.IncrementPercentageDropEveryTenLevelsVBlood)))
			{
				return;
			}
			int num = 0;
			num = rnd.Next(ConfigDB.WalletAmountVBloodMin, ConfigDB.WalletAmountVBloodMax);
			if (ConfigDB.searchUserRewardPerDay(userModelKiller.CharacterName, out var userRewardsPerDayModel))
			{
				int num2 = userRewardsPerDayModel.AmountVBlood + num;
				if (num2 <= ConfigDB.MaxRewardsPerDayPerPlayerVBlood)
				{
					userRewardsPerDayModel.AmountVBlood = num2;
					string text = default(string);
					WalletAPI.AddTokenToUser(num, "BloodyRewards", ((EntityModel)userModelKiller).Entity, ((EntityModel)userModelKiller).Entity, ref text);
					UserModelMethods.SendSystemMessage(userModelKiller, text);
					ConfigDB.addUserRewardsPerDayToList(userRewardsPerDayModel);
					SaveDataToFiles.saveUsersRewardsPerDay();
				}
				else if (userRewardsPerDayModel.AmountVBlood < ConfigDB.MaxRewardsPerDayPerPlayerVBlood)
				{
					num = ConfigDB.MaxRewardsPerDayPerPlayerVBlood - userRewardsPerDayModel.AmountVBlood;
					userRewardsPerDayModel.AmountVBlood += num;
					string text2 = default(string);
					WalletAPI.AddTokenToUser(num, "BloodyRewards", ((EntityModel)userModelKiller).Entity, ((EntityModel)userModelKiller).Entity, ref text2);
					UserModelMethods.SendSystemMessage(userModelKiller, text2);
					ConfigDB.addUserRewardsPerDayToList(userRewardsPerDayModel);
					SaveDataToFiles.saveUsersRewardsPerDay();
				}
			}
		}

		private static int calculateDropPercentage(int level, int initialPercent, int incremental)
		{
			return decimal.ToInt32(Math.Ceiling((decimal)(level / 10)) * (decimal)incremental) + initialPercent;
		}

		private static bool probabilityOeneratingReward(int percentage)
		{
			if (new Random().Next(1, 100) <= percentage)
			{
				return true;
			}
			return false;
		}
	}
}
namespace BloodyRewards.DB
{
	public class ConfigDB
	{
		public static List<(string name, DateTime date, UserRewardsPerDayModel model)> _normalizedUsersRewardsPerDay = new List<(string, DateTime, UserRewardsPerDayModel)>();

		public static bool RewardsEnabled { get; set; } = true;


		public static int DropNpcPercentage { get; set; } = 0;


		public static int IncrementPercentageDropEveryTenLevelsNpc { get; set; } = 0;


		public static int DropdNpcRewardsMin { get; set; } = 0;


		public static int DropNpcRewardsMax { get; set; } = 0;


		public static int MaxRewardsPerDayPerPlayerNpc { get; set; } = 0;


		public static int DropdVBloodPercentage { get; set; } = 0;


		public static int IncrementPercentageDropEveryTenLevelsVBlood { get; set; } = 0;


		public static int DropVBloodRewardsMin { get; set; } = 0;


		public static int DropVBloodRewardsMax { get; set; } = 0;


		public static int MaxRewardsPerDayPerPlayerVBlood { get; set; } = 0;


		public static int DropPvpPercentage { get; set; } = 0;


		public static int IncrementPercentageDropEveryTenLevelsPvp { get; set; } = 0;


		public static int DropPvpRewardsMin { get; set; } = 0;


		public static int DropPvpRewardsMax { get; set; } = 0;


		public static int MaxRewardsPerDayPerPlayerPvp { get; set; } = 0;


		public static List<UserRewardsPerDayModel> UsersRewardsPerDay { get; set; } = new List<UserRewardsPerDayModel>();


		public static bool WalletSystem { get; internal set; }

		public static int WalletAmountPveMax { get; internal set; }

		public static int WalletAmountPveMin { get; internal set; }

		public static int WalletAmountPVPMin { get; internal set; }

		public static int WalletAmountPVPMax { get; internal set; }

		public static int WalletAmountVBloodMin { get; internal set; }

		public static int WalletAmountVBloodMax { get; internal set; }

		public static bool DailyLoginRewards { get; internal set; }

		public static int AmountDailyLoginReward { get; internal set; }

		public static bool ConnectionTimeReward { get; internal set; }

		public static int AmountTimeReward { get; internal set; }

		public static int TimeReward { get; internal set; }

		public static bool setUsersRewardsPerDay(List<UserRewardsPerDayModel> listUsersRewardsPerDay)
		{
			UsersRewardsPerDay = new List<UserRewardsPerDayModel>();
			foreach (UserRewardsPerDayModel item in listUsersRewardsPerDay)
			{
				DateTime dateTime = DateTime.Parse(item.date);
				if (!(dateTime != DateTime.Today))
				{
					_normalizedUsersRewardsPerDay.Add((item.CharacterName, dateTime, item));
					UsersRewardsPerDay.Add(item);
				}
			}
			return true;
		}

		public static void addUserRewardsPerDayToList(UserRewardsPerDayModel userRewardsPerDay)
		{
			foreach (var (text, item, userRewardsPerDayModel) in _normalizedUsersRewardsPerDay)
			{
				if (text == userRewardsPerDay.CharacterName)
				{
					UsersRewardsPerDay.Remove(userRewardsPerDayModel);
					_normalizedUsersRewardsPerDay.Remove((text, item, userRewardsPerDayModel));
					UsersRewardsPerDay.Add(userRewardsPerDay);
					_normalizedUsersRewardsPerDay.Add((userRewardsPerDay.CharacterName, DateTime.Parse(userRewardsPerDay.date), userRewardsPerDay));
					break;
				}
			}
		}

		public static bool searchUserRewardPerDay(string characterName, out UserRewardsPerDayModel userRewardsPerDayModel)
		{
			userRewardsPerDayModel = null;
			if (characterName == "")
			{
				return false;
			}
			DateTime today = DateTime.Today;
			string date = $"{DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day}";
			foreach (var (text, dateTime, userRewardsPerDayModel2) in _normalizedUsersRewardsPerDay)
			{
				if (text == characterName)
				{
					if (today == dateTime)
					{
						userRewardsPerDayModel = userRewardsPerDayModel2;
						break;
					}
					UsersRewardsPerDay.Remove(userRewardsPerDayModel2);
					_normalizedUsersRewardsPerDay.Remove((text, dateTime, userRewardsPerDayModel2));
					userRewardsPerDayModel = new UserRewardsPerDayModel
					{
						CharacterName = userRewardsPerDayModel2.CharacterName,
						date = date
					};
					UsersRewardsPerDay.Add(userRewardsPerDayModel2);
					_normalizedUsersRewardsPerDay.Add((characterName, today, userRewardsPerDayModel));
					break;
				}
			}
			if (userRewardsPerDayModel == null)
			{
				userRewardsPerDayModel = new UserRewardsPerDayModel
				{
					CharacterName = characterName,
					date = date
				};
				UsersRewardsPerDay.Add(userRewardsPerDayModel);
				_normalizedUsersRewardsPerDay.Add((characterName, today, userRewardsPerDayModel));
				return true;
			}
			return true;
		}
	}
	internal class LoadDataFromFiles
	{
		public static readonly string ConfigPath = Path.Combine(Paths.ConfigPath, "BloodyRewards");

		public static string RewardListFile = Path.Combine(ConfigPath, "currency_list.json");

		public static string KillerPVPListFile = Path.Combine(ConfigPath, "pvp_kills.json");

		public static string RewardLDayliistFile = Path.Combine(ConfigPath, "dayli_time_online_list.json");

		public static string UserRewardsPerDayFile = Path.Combine(ConfigPath, "user_currencies_per_day.json");

		public static bool loadRewards()
		{
			try
			{
				return ShareDB.setRewardList(JsonSerializer.Deserialize<List<RewardModel>>(File.ReadAllText(RewardListFile)));
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError("Error: " + ex.Message);
				return false;
			}
		}

		public static bool loadKillers()
		{
			try
			{
				return ShareDB.setKillerPvpList(JsonSerializer.Deserialize<List<PvpModel>>(File.ReadAllText(KillerPVPListFile)));
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError("Error: " + ex.Message);
				return false;
			}
		}

		public static bool loadRewardLDayliistFiles()
		{
			try
			{
				return ShareDB.settDayliLoginTimeModel(JsonSerializer.Deserialize<List<DayliLoginTimeModel>>(File.ReadAllText(RewardLDayliistFile)));
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError("Error: " + ex.Message);
				return false;
			}
		}

		public static bool loadUserRewardsPerDay()
		{
			try
			{
				return ConfigDB.setUsersRewardsPerDay(JsonSerializer.Deserialize<List<UserRewardsPerDayModel>>(File.ReadAllText(UserRewardsPerDayFile)));
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError("Error: " + ex.Message);
				return false;
			}
		}

		public static void CreateFilesConfig()
		{
			if (!Directory.Exists(ConfigPath))
			{
				Directory.CreateDirectory(ConfigPath);
			}
			if (!File.Exists(RewardListFile))
			{
				File.WriteAllText(RewardListFile, "[{\"id\":1,\"name\":\"Silver Coin\",\"guid\":-949672483}]");
			}
			if (!File.Exists(UserRewardsPerDayFile))
			{
				File.WriteAllText(UserRewardsPerDayFile, "[]");
			}
			if (!File.Exists(RewardLDayliistFile))
			{
				File.WriteAllText(RewardLDayliistFile, "[]");
			}
			if (!File.Exists(KillerPVPListFile))
			{
				File.WriteAllText(KillerPVPListFile, "[]");
			}
		}

		public static void LoadRewardsToDB()
		{
			if (!loadRewards())
			{
				Plugin.Logger.LogError("Error loading RewardsList");
			}
		}

		public static void LoadUserRewardsPerDayToDB()
		{
			if (!loadUserRewardsPerDay())
			{
				Plugin.Logger.LogError("Error loading loadUserRewardsPerDay");
			}
		}

		public static void LoadRewardLDayliistFiles()
		{
			if (!loadRewardLDayliistFiles())
			{
				Plugin.Logger.LogError("Error loading loadUserRewardsPerDay");
			}
		}

		public static void LoadKillersListFiles()
		{
			if (!loadKillers())
			{
				Plugin.Logger.LogError("Error loading loadKillers");
			}
		}

		public static void SetConfigMod()
		{
			ConfigDB.RewardsEnabled = Plugin.RewardsEnabled.Value;
			ConfigDB.DropNpcPercentage = Plugin.DropNpcPercentage.Value;
			ConfigDB.IncrementPercentageDropEveryTenLevelsNpc = Plugin.IncrementPercentageDropEveryTenLevelsNpc.Value;
			ConfigDB.DropdNpcRewardsMin = Plugin.DropdNpcRewardsMin.Value;
			ConfigDB.DropNpcRewardsMax = Plugin.DropNpcRewardsMax.Value;
			ConfigDB.MaxRewardsPerDayPerPlayerNpc = Plugin.MaxRewardsPerDayPerPlayerNpc.Value;
			ConfigDB.DropdVBloodPercentage = Plugin.DropdVBloodPercentage.Value;
			ConfigDB.IncrementPercentageDropEveryTenLevelsVBlood = Plugin.IncrementPercentageDropEveryTenLevelsVBlood.Value;
			ConfigDB.DropVBloodRewardsMin = Plugin.DropVBloodRewardsMin.Value;
			ConfigDB.DropVBloodRewardsMax = Plugin.DropVBloodRewardsMax.Value;
			ConfigDB.MaxRewardsPerDayPerPlayerVBlood = Plugin.MaxRewardsPerDayPerPlayerVBlood.Value;
			ConfigDB.DropPvpPercentage = Plugin.DropPvpPercentage.Value;
			ConfigDB.IncrementPercentageDropEveryTenLevelsPvp = Plugin.IncrementPercentageDropEveryTenLevelsPvp.Value;
			ConfigDB.DropPvpRewardsMin = Plugin.DropPvpRewardsMin.Value;
			ConfigDB.DropPvpRewardsMax = Plugin.DropPvpRewardsMax.Value;
			ConfigDB.MaxRewardsPerDayPerPlayerPvp = Plugin.MaxRewardsPerDayPerPlayerPvp.Value;
			ConfigDB.WalletSystem = Plugin.WalletSystem.Value;
			ConfigDB.WalletAmountPveMax = Plugin.WalletAmountPveMax.Value;
			ConfigDB.WalletAmountPveMin = Plugin.WalletAmountPveMin.Value;
			ConfigDB.WalletAmountVBloodMax = Plugin.WalletAmountVBloodMax.Value;
			ConfigDB.WalletAmountVBloodMin = Plugin.WalletAmountVBloodMin.Value;
			ConfigDB.WalletAmountPVPMax = Plugin.WalletAmountPVPMax.Value;
			ConfigDB.WalletAmountPVPMin = Plugin.WalletAmountPVPMin.Value;
			ConfigDB.DailyLoginRewards = Plugin.DailyLoginRewards.Value;
			ConfigDB.AmountDailyLoginReward = Plugin.AmountDailyLoginReward.Value;
			ConfigDB.ConnectionTimeReward = Plugin.ConnectionTimeReward.Value;
			ConfigDB.AmountTimeReward = Plugin.AmountTimeReward.Value;
			ConfigDB.TimeReward = Plugin.TimeReward.Value;
		}
	}
	internal class SaveDataToFiles
	{
		public static bool saveKillerPVPList()
		{
			try
			{
				string contents = JsonSerializer.Serialize(ShareDB.getKillersPVPList());
				File.WriteAllText(LoadDataFromFiles.KillerPVPListFile, contents);
				return true;
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError("Error: " + ex.Message);
				return false;
			}
		}

		public static bool saveRewardsList()
		{
			try
			{
				string contents = JsonSerializer.Serialize(ShareDB.getRewardList());
				File.WriteAllText(LoadDataFromFiles.RewardListFile, contents);
				return true;
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError("Error: " + ex.Message);
				return false;
			}
		}

		public static bool saveDayliTimeLogin()
		{
			try
			{
				string contents = JsonSerializer.Serialize(ShareDB.getDayliLoginTimeModel());
				File.WriteAllText(LoadDataFromFiles.RewardLDayliistFile, contents);
				return true;
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError("Error: " + ex.Message);
				return false;
			}
		}

		public static bool saveUsersRewardsPerDay()
		{
			try
			{
				string contents = JsonSerializer.Serialize(ConfigDB.UsersRewardsPerDay);
				File.WriteAllText(LoadDataFromFiles.UserRewardsPerDayFile, contents);
				return true;
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError("Error: " + ex.Message);
				return false;
			}
		}
	}
	public class ShareDB
	{
		public static List<RewardModel> rewardsList = new List<RewardModel>();

		public static List<DayliLoginTimeModel> ListDayliLoginTimeModel = new List<DayliLoginTimeModel>();

		public static List<PvpModel> KillersPVP = new List<PvpModel>();

		public static List<PvpModel> getKillersPVPList()
		{
			return KillersPVP;
		}

		public static List<RewardModel> getRewardList()
		{
			return rewardsList;
		}

		public static List<DayliLoginTimeModel> getDayliLoginTimeModel()
		{
			return ListDayliLoginTimeModel;
		}

		public static void addKillersPVPModel(PvpModel pvpModel)
		{
			KillersPVP.Add(pvpModel);
		}

		public static void addDayliLoginTimeModel(DayliLoginTimeModel dayliLoginTimeModel)
		{
			ListDayliLoginTimeModel.Add(dayliLoginTimeModel);
		}

		public static RewardModel getReward(int guid)
		{
			return rewardsList.FirstOrDefault((RewardModel reward) => reward.guid == guid);
		}

		public static RewardModel getRewardByName(string name)
		{
			return rewardsList.FirstOrDefault((RewardModel reward) => reward.name == name);
		}

		public static bool setRewardList(List<RewardModel> rewards)
		{
			rewardsList = rewards;
			return true;
		}

		public static bool setKillerPvpList(List<PvpModel> killers)
		{
			KillersPVP = killers;
			return true;
		}

		public static bool settDayliLoginTimeModel(List<DayliLoginTimeModel> rewards)
		{
			ListDayliLoginTimeModel = rewards;
			return true;
		}

		public static bool addRewardList(string name, int guid, bool onlyVBlood)
		{
			RewardModel rewardModel = new RewardModel();
			int id = getRewardList().Last().id + 1;
			rewardModel.name = name;
			rewardModel.guid = guid;
			rewardModel.id = id;
			rewardModel.onlyVBlood = onlyVBlood;
			rewardsList.Add(rewardModel);
			return true;
		}

		public static List<string> GetRewardListMessage()
		{
			List<string> list = new List<string>();
			foreach (RewardModel rewards in rewardsList)
			{
				list.Add(FontColorChatSystem.White("[") + FontColorChatSystem.Yellow(rewards.id.ToString()) + FontColorChatSystem.White("]") + " " + FontColorChatSystem.Yellow(rewards.name) + " ");
			}
			return list;
		}

		public static bool SearchRewardByCommand(int index, out RewardModel rewardModel)
		{
			rewardModel = rewardsList.FirstOrDefault((RewardModel reward) => reward.id == index);
			if (rewardModel == null)
			{
				return false;
			}
			return true;
		}

		public static bool RemoveRewardyByCommand(int index)
		{
			try
			{
				rewardsList.RemoveAll((RewardModel reward) => reward.id == index);
				return true;
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError("Error: " + ex.Message);
				return false;
			}
		}

		public static List<RewardModel> searchRewardByNameForShop(string text)
		{
			List<RewardModel> list = new List<RewardModel>();
			foreach (RewardModel rewards in rewardsList)
			{
				if (rewards.name.Contains(text))
				{
					list.Add(rewards);
				}
			}
			return list;
		}

		public static int searchIdForReward(int GUID)
		{
			foreach (RewardModel rewards in rewardsList)
			{
				if (rewards.guid == GUID)
				{
					return rewards.id;
				}
			}
			return -1;
		}
	}
}
namespace BloodyRewards.DB.Models
{
	[Serializable]
	public class RewardModel
	{
		public bool onlyVBlood { get; set; }

		public int id { get; set; }

		public string name { get; set; }

		public int guid { get; set; }
	}
	public class DayliLoginTimeModel
	{
		public string player { get; set; } = string.Empty;


		public string LastDayConnection { get; set; } = string.Empty;


		public DateTime LastDateTime { get; set; }
	}
	public class PvpModel
	{
		public string killer { get; set; }

		public string target { get; set; }

		public DateTime date { get; set; }
	}
	public class UserRewardsPerDayModel
	{
		public string CharacterName { get; set; }

		public string date { get; set; }

		public int AmountNpc { get; set; }

		public int AmountVBlood { get; set; }

		public int AmountPvp { get; set; }
	}
}
namespace BloodyRewards.Command
{
	[CommandGroup("brw", null)]
	internal class RewardsCommand
	{
		public static bool forceRestartTimerConnection;

		public static RewardModel reward { get; private set; }

		public static List<RewardModel> rewards { get; private set; }

		[Command("add", null, "\"<Name>\" <PrefabGuid> <OnlyForVBlood true/false>", "Add a reward. To know the PrefabGuid of an item you must look for the item in the following URL <#4acc45><u>https://gaming.tools/v-rising/items</u></color>", null, true)]
		public static void AddReward(ChatCommandContext ctx, string name, int item, bool onlyVBlood)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.WalletSystem.Value)
			{
				throw ctx.Error("BloodyWallet is activated as a reward so this command is disabled.");
			}
			new PrefabGUID(item);
			if (!ShareDB.addRewardList(name, item, onlyVBlood))
			{
				throw ctx.Error("Invalid item type");
			}
			SaveDataToFiles.saveRewardsList();
			ctx.Reply(FontColorChatSystem.Yellow("Added reward " + FontColorChatSystem.White(name ?? "") + " to the system"));
		}

		[Command("list", null, "", "List of rewards available", null, true)]
		public static void ListReward(ChatCommandContext ctx)
		{
			if (Plugin.WalletSystem.Value)
			{
				throw ctx.Error("BloodyWallet is activated as a reward so this command is disabled.");
			}
			if (!ConfigDB.RewardsEnabled)
			{
				throw ctx.Error("Reward System is disabled");
			}
			List<string> rewardListMessage = ShareDB.GetRewardListMessage();
			if (rewardListMessage.Count <= 0)
			{
				throw ctx.Error("No reward available");
			}
			foreach (string item in rewardListMessage)
			{
				ctx.Reply(item);
			}
		}

		[Command("remove", "crm", "<NumberItem>", "Delete a reward", null, true)]
		public static void RemoveReward(ChatCommandContext ctx, int index)
		{
			if (Plugin.WalletSystem.Value)
			{
				throw ctx.Error("BloodyWallet is activated as a reward so this command is disabled.");
			}
			try
			{
				if (ShareDB.rewardsList.Count == 1)
				{
					throw ctx.Error(FontColorChatSystem.Yellow("Do not remove all reward."));
				}
				if (!ShareDB.SearchRewardByCommand(index, out var rewardModel))
				{
					throw ctx.Error(FontColorChatSystem.Yellow("Reward removed error."));
				}
				if (!ShareDB.RemoveRewardyByCommand(index))
				{
					throw ctx.Error(FontColorChatSystem.Yellow("Reward " + FontColorChatSystem.White(rewardModel.name ?? "") + " removed error."));
				}
				SaveDataToFiles.saveRewardsList();
				LoadDataFromFiles.loadRewards();
				ctx.Reply(FontColorChatSystem.Yellow("Reward " + FontColorChatSystem.White(rewardModel.name ?? "") + " removed successful."));
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError("Error: " + ex.Message);
				throw ctx.Error("Error: " + ex.Message);
			}
		}

		[Command("force start connection timer", "", "", "Start the connection time rewards timer", null, true)]
		public static void RestartReward(ChatCommandContext ctx)
		{
			try
			{
				if (forceRestartTimerConnection)
				{
					ConnectionTimeSystemRewards.UserRewardTimne();
					forceRestartTimerConnection = false;
					ctx.Reply(FontColorChatSystem.White("Successfully started connection time reward system."));
				}
				else
				{
					forceRestartTimerConnection = true;
					ctx.Reply(FontColorChatSystem.Red("You are going to force a restart of the connection time reward system. If it was not stopped before, this could cause a double reward for connection time. To continue, run the command " + FontColorChatSystem.Yellow("'.brw force start connection timer' again.")));
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError("Error: " + ex.Message);
				throw ctx.Error("Error: " + ex.Message);
			}
		}
	}
}