fix hanf performance??
This commit is contained in:
@@ -333,13 +333,8 @@ export default function hanfSystem(globalData: IGlobalData) {
|
|||||||
let hanfDataIdToObjectMap: Map<number, ObjectMp> = new Map<number, ObjectMp>();
|
let hanfDataIdToObjectMap: Map<number, ObjectMp> = new Map<number, ObjectMp>();
|
||||||
let hanfDataIdToTextLabelMap: Map<number, TextLabelMp> = new Map<number, TextLabelMp>();
|
let hanfDataIdToTextLabelMap: Map<number, TextLabelMp> = new Map<number, TextLabelMp>();
|
||||||
|
|
||||||
mp.events.addDataHandler("hanfData", (entity: EntityMp, value) => {
|
mp.events.add("SERVER:Hanf_UpdateHanf", (dataJsonArr: string[]) => {
|
||||||
if (entity.type == 'player' && entity.remoteId == mp.players.local.remoteId) {
|
var dataJson = dataJsonArr.join('');
|
||||||
updateHanf(value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function updateHanf(dataJson: string) {
|
|
||||||
var data: Array<CannabisData> = <Array<CannabisData>>JSON.parse(dataJson)
|
var data: Array<CannabisData> = <Array<CannabisData>>JSON.parse(dataJson)
|
||||||
|
|
||||||
var newPlants = data.filter(d => currentHanfData.filter(x => x.Id === d.Id).length == 0);
|
var newPlants = data.filter(d => currentHanfData.filter(x => x.Id === d.Id).length == 0);
|
||||||
@@ -382,7 +377,7 @@ export default function hanfSystem(globalData: IGlobalData) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
currentHanfData = data;
|
currentHanfData = data;
|
||||||
}
|
});
|
||||||
|
|
||||||
function getPlantModel(plant: CannabisData): number {
|
function getPlantModel(plant: CannabisData): number {
|
||||||
var diff = Date.now() - Date.parse(plant.Time);
|
var diff = Date.now() - Date.parse(plant.Time);
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ namespace ReallifeGamemode.Server
|
|||||||
Rentcar.Setup();
|
Rentcar.Setup();
|
||||||
|
|
||||||
|
|
||||||
// HanfManager.Load();
|
HanfManager.Load();
|
||||||
|
|
||||||
World.WeatherSync.Load();
|
World.WeatherSync.Load();
|
||||||
|
|
||||||
|
|||||||
@@ -172,9 +172,12 @@ namespace ReallifeGamemode.Server.Managers
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void UpdateHanfDataTimer_Elapsed(object sender, ElapsedEventArgs e)
|
private static void UpdateHanfDataTimer_Elapsed(object sender, ElapsedEventArgs e)
|
||||||
|
{
|
||||||
|
NAPI.Task.Run(() =>
|
||||||
{
|
{
|
||||||
using var dbContext = new DatabaseContext();
|
using var dbContext = new DatabaseContext();
|
||||||
UpdateHanfWorldData(dbContext);
|
UpdateHanfWorldData(dbContext);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OnSeedBuyRangeColShapeEnter(ColShape colShape, Player player)
|
private static void OnSeedBuyRangeColShapeEnter(ColShape colShape, Player player)
|
||||||
@@ -205,7 +208,6 @@ namespace ReallifeGamemode.Server.Managers
|
|||||||
|
|
||||||
internal static void StartCannabisPlanting(Player player)
|
internal static void StartCannabisPlanting(Player player)
|
||||||
{
|
{
|
||||||
return;
|
|
||||||
player.ToggleInventory(InventoryToggleOption.HIDE);
|
player.ToggleInventory(InventoryToggleOption.HIDE);
|
||||||
|
|
||||||
if (!player.IsAlive())
|
if (!player.IsAlive())
|
||||||
@@ -286,12 +288,31 @@ namespace ReallifeGamemode.Server.Managers
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async static void UpdateHanfForPlayer(Player player, List<CannabisData> cannabisData = null)
|
public static void UpdateHanfForPlayer(Player player, List<CannabisData> cannabisData = null)
|
||||||
{
|
{
|
||||||
cannabisData ??= _currentCannabisData;
|
cannabisData ??= _currentCannabisData;
|
||||||
await NAPI.Task.WaitForMainThread();
|
|
||||||
player.SetSharedData("hanfData", JsonConvert.SerializeObject(cannabisData));
|
string jsonStr = JsonConvert.SerializeObject(cannabisData);
|
||||||
//player.TriggerEvent("SERVER:Hanf_UpdateHanfData");
|
List<string> parts = GetChunks(jsonStr, 500);
|
||||||
|
|
||||||
|
player.TriggerEvent("SERVER:Hanf_UpdateHanf", parts);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<string> GetChunks(string value, int chunkSize)
|
||||||
|
{
|
||||||
|
List<string> triplets = new List<string>();
|
||||||
|
while (value.Length > chunkSize)
|
||||||
|
{
|
||||||
|
triplets.Add(value.Substring(0, chunkSize));
|
||||||
|
value = value.Substring(chunkSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value != "")
|
||||||
|
{
|
||||||
|
triplets.Add(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return triplets;
|
||||||
}
|
}
|
||||||
|
|
||||||
[RemoteEvent("CLIENT:Hanf_BuySeeds")]
|
[RemoteEvent("CLIENT:Hanf_BuySeeds")]
|
||||||
@@ -349,7 +370,7 @@ namespace ReallifeGamemode.Server.Managers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[RemoteEvent("CLIENT:Hanf_HarvestHanf")]
|
[RemoteEvent("CLIENT:Hanf_HarvestHanf")]
|
||||||
public async void HanfManagerHarvestHanf(Player player, long hanfId)
|
public void HanfManagerHarvestHanf(Player player, long hanfId)
|
||||||
{
|
{
|
||||||
if (!player.IsLoggedIn())
|
if (!player.IsLoggedIn())
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user