forked from PerpetuumOnline/PerpetuumServer
-
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathLargeDrillerModule.cs
More file actions
111 lines (97 loc) · 4.58 KB
/
LargeDrillerModule.cs
File metadata and controls
111 lines (97 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using Perpetuum.Data;
using Perpetuum.EntityFramework;
using Perpetuum.ExportedTypes;
using Perpetuum.Items;
using Perpetuum.Players;
using Perpetuum.Services.MissionEngine.MissionTargets;
using Perpetuum.Zones;
using Perpetuum.Zones.Beams;
using Perpetuum.Zones.Terrains;
using Perpetuum.Zones.Terrains.Materials;
using Perpetuum.Zones.Terrains.Materials.Minerals;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Transactions;
namespace Perpetuum.Modules
{
public class LargeDrillerModule : DrillerModule
{
public LargeDrillerModule(CategoryFlags ammoCategoryFlags, RareMaterialHandler rareMaterialHandler, MaterialHelper materialHelper)
: base(ammoCategoryFlags, rareMaterialHandler, materialHelper)
{
}
public override void DoExtractMinerals(IZone zone)
{
Position centralTile = ParentRobot.PositionWithHeight;
MaterialType materialType;
if (!(GetAmmo() is MiningAmmo ammo))
{
return;
}
materialType = ammo.MaterialType;
MaterialInfo materialInfo = MaterialHelper.GetMaterialInfo(materialType);
CheckEnablerEffect(materialInfo, centralTile);
MineralLayer mineralLayer = zone.Terrain
.GetMineralLayerOrThrow(materialInfo.Type);
double materialAmount = materialInfo.Amount * MiningAmountModifier.Value;
List<Position> mineralPositions = centralTile.GetEightNeighbours(ParentRobot.Zone.Size).ToList();
mineralPositions.Add(centralTile);
int emptyTilesCounter = 0;
// make it parallel
foreach (Position position in mineralPositions)
{
List<ItemInfo> extractedMaterials = Extract(mineralLayer, position, (uint)materialAmount);
if (extractedMaterials.Count == 0)
{
emptyTilesCounter++;
_ = emptyTilesCounter
.ThrowIfEqual(9, ErrorCodes.NoMineralOnTile);
continue;
}
extractedMaterials
.AddRange(RareMaterialHandler.GenerateRareMaterials(materialInfo.EntityDefault.Definition));
CreateBeam(position.Center, BeamState.AlignToTerrain);
using (TransactionScope scope = Db.CreateTransaction())
{
Debug.Assert(ParentRobot != null, "ParentRobot != null");
Robots.RobotInventory container = ParentRobot.GetContainer();
Debug.Assert(container != null, "container != null");
container.EnlistTransaction();
Player player = ParentRobot as Player;
Debug.Assert(player != null, "player != null");
foreach (ItemInfo material in extractedMaterials)
{
Db.Query()
.CommandText("exec sp_RecordResourceGathered @gathered_on, @resource_name, @quantity")
.SetParameter("@gathered_on", DateTime.UtcNow)
.SetParameter("@resource_name", material.EntityDefault.Name)
.SetParameter("@quantity", material.Quantity)
.ExecuteNonQuery();
Item item = (Item)Factory.CreateWithRandomEID(material.Definition);
item.Owner = Owner;
item.Quantity = material.Quantity;
container.AddItem(item, true);
int drilledMineralDefinition = material.Definition;
int drilledQuantity = material.Quantity;
player.MissionHandler
.EnqueueMissionEventInfo(
new DrillMineralEventInfo(
player,
drilledMineralDefinition,
drilledQuantity,
position));
player.Zone?.MiningLogHandler.EnqueueMiningLog(drilledMineralDefinition, drilledQuantity);
}
//save container
container.Save();
OnGathererMaterial(zone, player, (int)materialInfo.Type);
Transaction.Current.OnCommited(() => container.SendUpdateToOwnerAsync());
scope.Complete();
}
}
GenerateHeat(EffectType.effect_excavator, 6);
}
}
}