forked from project-fika/Fuyu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added mod to add a flea entry for all items in the items.json
- Loading branch information
Showing
2 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
Devtools/Fuyu.Devtool.GenerateFleaMarketOffers/src/GenerateFleaMarketOffersMod.cs
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,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Fuyu.Common.IO; | ||
using Fuyu.DependencyInjection; | ||
using Fuyu.Modding; | ||
using System.Diagnostics; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Fuyu.Backend.BSG.ItemTemplates; | ||
using Fuyu.Backend.BSG.Models.Profiles.Info; | ||
using Fuyu.Backend.BSG.Models.Trading; | ||
using Fuyu.Backend.BSG.Services; | ||
using Fuyu.Backend.EFTMain; | ||
using Fuyu.Backend.EFTMain.Services; | ||
using Fuyu.Common.Hashing; | ||
|
||
public class Mod : AbstractMod | ||
{ | ||
public override string Id { get; } = "Fuyu.DevTools.GenerateFleamarketOffers"; | ||
|
||
public override string Name { get; } = "GenerateFleaMarketOffers"; | ||
|
||
public override Task OnLoad(DependencyContainer container) | ||
{ | ||
var player = new RagfairPlayerUser(new MongoId(true), 344, EMemberCategory.Developer, EMemberCategory.Developer, | ||
"b1gdeveloper", 69.420f, true); | ||
new Thread((() => | ||
{ | ||
Terminal.WriteLine("Generating offers..."); | ||
var sw = Stopwatch.StartNew(); | ||
var templates = EftOrm.Instance.GetItemTemplates()["data"]!.ToObject<Dictionary<MongoId, ItemTemplate>>(); | ||
var handbook = EftOrm.Instance.GetHandbook(); | ||
var success = 0; | ||
var failed = 0; | ||
|
||
foreach (var (tid, template) in templates) | ||
{ | ||
var entry = handbook.Items.Find(i => i.Id == tid); | ||
int price = entry?.Price ?? 100; | ||
|
||
if (price <= 0) | ||
{ | ||
price = 100; | ||
} | ||
|
||
try | ||
{ | ||
var item = ItemFactoryService.Instance.CreateItem(template.Id); | ||
|
||
var x = RagfairService.Instance.CreateAndAddOffer(player, | ||
[item], | ||
false, | ||
[new HandoverRequirement() { Count = price, TemplateId = "5449016a4bdc2d6f028b456f" }], | ||
TimeSpan.FromMinutes(30d), | ||
false | ||
); | ||
|
||
if (x == null) | ||
{ | ||
failed++; | ||
} | ||
else | ||
{ | ||
success++; | ||
} | ||
} | ||
catch (Exception) | ||
{ | ||
// ignored | ||
} | ||
} | ||
|
||
Terminal.WriteLine($"Done generating offers: {sw.ElapsedMilliseconds}ms, {success} succeeded and {failed} failed"); | ||
})).Start(); | ||
|
||
return Task.CompletedTask; | ||
} | ||
} |
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,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Fuyu.Common.IO; | ||
using Fuyu.DependencyInjection; | ||
using Fuyu.Modding; | ||
using System.Diagnostics; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Fuyu.Backend.BSG.ItemTemplates; | ||
using Fuyu.Backend.BSG.Models.Profiles.Info; | ||
using Fuyu.Backend.BSG.Models.Trading; | ||
using Fuyu.Backend.BSG.Services; | ||
using Fuyu.Backend.EFTMain; | ||
using Fuyu.Backend.EFTMain.Services; | ||
using Fuyu.Common.Hashing; | ||
|
||
public class GenerateFleaMarketOffersMod : AbstractMod | ||
{ | ||
public override string Id { get; } = "com.project-fika.generatefleamarketoffers"; | ||
|
||
public override string Name { get; } = "GenerateFleaMarketOffers"; | ||
|
||
public override Task OnLoad(DependencyContainer container) | ||
{ | ||
var player = new RagfairPlayerUser(new MongoId(true), 344, EMemberCategory.Developer, EMemberCategory.Developer, | ||
"b1gdeveloper", 69.420f, true); | ||
new Thread((() => | ||
{ | ||
Terminal.WriteLine("Generating offers..."); | ||
var sw = Stopwatch.StartNew(); | ||
var templates = EftOrm.Instance.GetItemTemplates()["data"]!.ToObject<Dictionary<MongoId, ItemTemplate>>(); | ||
var handbook = EftOrm.Instance.GetHandbook(); | ||
var success = 0; | ||
var failed = 0; | ||
|
||
foreach (var (tid, template) in templates) | ||
{ | ||
var entry = handbook.Items.Find(i => i.Id == tid); | ||
int price = entry?.Price ?? 100; | ||
|
||
if (price <= 0) | ||
{ | ||
price = 100; | ||
} | ||
|
||
try | ||
{ | ||
var item = ItemFactoryService.Instance.CreateItem(template.Id); | ||
|
||
var x = RagfairService.Instance.CreateAndAddOffer(player, | ||
[item], | ||
false, | ||
[new HandoverRequirement() { Count = price, TemplateId = "5449016a4bdc2d6f028b456f" }], | ||
TimeSpan.FromMinutes(30d), | ||
false | ||
); | ||
|
||
if (x == null) | ||
{ | ||
failed++; | ||
} | ||
else | ||
{ | ||
success++; | ||
} | ||
} | ||
catch (Exception) | ||
{ | ||
// ignored | ||
} | ||
} | ||
|
||
Terminal.WriteLine($"Done generating offers: {sw.ElapsedMilliseconds}ms, {success} succeeded and {failed} failed"); | ||
})).Start(); | ||
|
||
return Task.CompletedTask; | ||
} | ||
} |