Skip to content

Commit 5838953

Browse files
authored
p34.7 (#511)
1 parent 2303a6d commit 5838953

File tree

12 files changed

+116
-80
lines changed

12 files changed

+116
-80
lines changed

src/Perpetuum.ExportedTypes/CategoryFlags.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ public enum CategoryFlags : long
5353
cf_command_robots = 0x0000000000001001,
5454
cf_combat_command_robots = 0x0000000000011001,
5555

56+
cf_drones = 0x0000000000001101,
57+
cf_assault_drones = 0x0000000000011101,
58+
cf_industrial_drones = 0x0000000000021101,
59+
cf_support_drones = 0x0000000000031101,
60+
cf_attack_drones = 0x0000000000041101,
61+
5662
cf_ammo = 0x000000000000000A,
5763
cf_railgun_ammo = 0x000000000000010A,
5864
cf_small_railgun_ammo = 0x000000000001010A,
@@ -193,6 +199,7 @@ public enum CategoryFlags : long
193199
cf_energy_warfare_upgrades = 0x00000000000D030F,
194200
cf_reactor_sealings = 0x00000000000E030F,
195201
cf_landmine_detectors = 0x00000000000F030F,
202+
cf_jumpers = 0x000000000010030F,
196203
cf_electronics_equipment = 0x000000000000040F,
197204
cf_sensor_boosters = 0x000000000001040F,
198205
cf_remote_sensor_boosters = 0x000000000002040F,
@@ -611,10 +618,6 @@ public enum CategoryFlags : long
611618
cf_mining_turrets = 0x0000000000000E92,
612619
cf_harvesting_turrets = 0x0000000000000F92,
613620
cf_combat_drones = 0x0000000000001092,
614-
cf_assault_drones = 0x0000000000001192,
615-
cf_industrial_drones = 0x0000000000001292,
616-
cf_support_drones = 0x0000000000001392,
617-
cf_attack_drones = 0x0000000000001492,
618621

619622
cf_production_items = 0x0000000000000094,
620623
cf_research_kits = 0x0000000000000194,

src/Perpetuum.RequestHandlers/EquipModule.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
using System.Collections.Generic;
2-
using System.Transactions;
31
using Perpetuum.Containers;
42
using Perpetuum.Data;
53
using Perpetuum.EntityFramework;
64
using Perpetuum.Host.Requests;
75
using Perpetuum.Items;
86
using Perpetuum.Modules;
97
using Perpetuum.Robots;
8+
using System.Collections.Generic;
9+
using System.Transactions;
1010

1111
namespace Perpetuum.RequestHandlers
1212
{
@@ -15,50 +15,50 @@ public class EquipModule : IRequestHandler
1515
private readonly IEntityRepository _entityRepository;
1616
private readonly RobotHelper _robotHelper;
1717

18-
public EquipModule(IEntityRepository entityRepository,RobotHelper robotHelper)
18+
public EquipModule(IEntityRepository entityRepository, RobotHelper robotHelper)
1919
{
2020
_entityRepository = entityRepository;
2121
_robotHelper = robotHelper;
2222
}
2323

2424
public void HandleRequest(IRequest request)
2525
{
26-
using (var scope = Db.CreateTransaction())
26+
using (TransactionScope scope = Db.CreateTransaction())
2727
{
28-
var character = request.Session.Character;
28+
Accounting.Characters.Character character = request.Session.Character;
2929
character.IsDocked.ThrowIfFalse(ErrorCodes.CharacterHasToBeDocked);
3030

31-
var containerEid = request.Data.GetOrDefault<long>(k.containerEID);
32-
var container = Container.GetWithItems(containerEid, character).ThrowIfNull(ErrorCodes.ContainerNotFound);
31+
long containerEid = request.Data.GetOrDefault<long>(k.containerEID);
32+
Container container = Container.GetWithItems(containerEid, character).ThrowIfNull(ErrorCodes.ContainerNotFound);
3333
container.ThrowIfType<VolumeWrapperContainer>(ErrorCodes.AccessDenied);
3434

35-
var robotEid = request.Data.GetOrDefault<long>(k.robotEID);
36-
var robot = _robotHelper.LoadRobotOrThrow(robotEid);
35+
long robotEid = request.Data.GetOrDefault<long>(k.robotEID);
36+
Robot robot = _robotHelper.LoadRobotOrThrow(robotEid);
3737
robot.IsSingleAndUnpacked.ThrowIfFalse(ErrorCodes.RobotMustbeSingleAndNonRepacked);
3838
robot.Initialize(character);
3939

40-
var slot = request.Data.GetOrDefault<int>(k.slot);
41-
var componentType = request.Data.GetOrDefault<string>(k.robotComponent).ToEnum<RobotComponentType>();
42-
var component = robot.GetRobotComponentOrThrow(componentType);
40+
int slot = request.Data.GetOrDefault<int>(k.slot);
41+
RobotComponentType componentType = request.Data.GetOrDefault<string>(k.robotComponent).ToEnum<RobotComponentType>();
42+
RobotComponent component = robot.GetRobotComponentOrThrow(componentType);
4343
component.MakeSlotFree(slot, container);
44-
var moduleEid = request.Data.GetOrDefault<long>(k.moduleEID);
45-
var module = (Module)container.GetItemOrThrow(moduleEid).Unstack(1);
46-
component.EquipModuleOrThrow(module, slot);
44+
long moduleEid = request.Data.GetOrDefault<long>(k.moduleEID);
45+
Module module = (Module)container.GetItemOrThrow(moduleEid).Unstack(1);
46+
component.EquipModuleOrThrow(module, slot, robot.Definition);
4747

4848
robot.Initialize(character);
4949
robot.Save();
5050
container.Save();
5151

5252
Transaction.Current.OnCompleted(completed =>
5353
{
54-
var result = new Dictionary<string, object>
54+
Dictionary<string, object> result = new Dictionary<string, object>
5555
{
56-
{k.robot, robot.ToDictionary()},
56+
{k.robot, robot.ToDictionary()},
5757
{k.container, container.ToDictionary()}
5858
};
5959
Message.Builder.FromRequest(request).WithData(result).WrapToResult().Send();
6060
});
61-
61+
6262
scope.Complete();
6363
}
6464
}

src/Perpetuum.RequestHandlers/FittingPreset/FittingPresetApply.cs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System.Collections.Generic;
2-
using System.Linq;
31
using Perpetuum.Containers;
42
using Perpetuum.Data;
53
using Perpetuum.EntityFramework;
@@ -8,6 +6,8 @@
86
using Perpetuum.Items.Ammos;
97
using Perpetuum.Modules;
108
using Perpetuum.Robots;
9+
using System.Collections.Generic;
10+
using System.Linq;
1111

1212
namespace Perpetuum.RequestHandlers.FittingPreset
1313
{
@@ -16,51 +16,55 @@ public class FittingPresetApply : FittingPresetRequestHandler
1616
private readonly IEntityRepository _entityRepository;
1717
private readonly RobotHelper _robotHelper;
1818

19-
public FittingPresetApply(IEntityRepository entityRepository,RobotHelper robotHelper)
19+
public FittingPresetApply(IEntityRepository entityRepository, RobotHelper robotHelper)
2020
{
2121
_entityRepository = entityRepository;
2222
_robotHelper = robotHelper;
2323
}
2424

2525
public override void HandleRequest(IRequest request)
2626
{
27-
using (var scope = Db.CreateTransaction())
27+
using (System.Transactions.TransactionScope scope = Db.CreateTransaction())
2828
{
29-
var id = request.Data.GetOrDefault<int>(k.ID);
30-
var robotEid = request.Data.GetOrDefault<long>(k.robotEID);
31-
var containerEid = request.Data.GetOrDefault<long>(k.containerEID);
32-
var forCorporation = request.Data.GetOrDefault<int>(k.forCorporation).ToBool();
29+
int id = request.Data.GetOrDefault<int>(k.ID);
30+
long robotEid = request.Data.GetOrDefault<long>(k.robotEID);
31+
long containerEid = request.Data.GetOrDefault<long>(k.containerEID);
32+
bool forCorporation = request.Data.GetOrDefault<int>(k.forCorporation).ToBool();
3333

34-
var character = request.Session.Character;
35-
var repo = GetFittingPresetRepository(character, forCorporation);
36-
var preset = repo.Get(id);
37-
var robot = _robotHelper.LoadRobotForCharacter(robotEid, character);
34+
Accounting.Characters.Character character = request.Session.Character;
35+
Robots.Fitting.IFittingPresetRepository repo = GetFittingPresetRepository(character, forCorporation);
36+
Robots.Fitting.FittingPreset preset = repo.Get(id);
37+
Robot robot = _robotHelper.LoadRobotForCharacter(robotEid, character);
3838
robot.ED.ThrowIfNotEqual(preset.Robot, ErrorCodes.WTFErrorMedicalAttentionSuggested);
3939

40-
var container = Container.GetWithItems(containerEid, character);
40+
Container container = Container.GetWithItems(containerEid, character);
4141
robot.EmptyRobot(character, container, false);
4242
robot.Initialize(character);
4343

44-
foreach (var moduleInfos in preset.Modules.GroupBy(i => i.Component))
44+
foreach (IGrouping<RobotComponentType, Robots.Fitting.FittingPreset.ModuleInfo> moduleInfos in preset.Modules.GroupBy(i => i.Component))
4545
{
46-
var component = robot.GetRobotComponent((RobotComponentType) moduleInfos.Key).ThrowIfNull(ErrorCodes.ItemNotFound);
46+
RobotComponent component = robot.GetRobotComponent(moduleInfos.Key).ThrowIfNull(ErrorCodes.ItemNotFound);
4747

48-
foreach (var moduleInfo in moduleInfos)
48+
foreach (Robots.Fitting.FittingPreset.ModuleInfo moduleInfo in moduleInfos)
4949
{
50-
var module = container.GetItems().OfType<Module>().FirstOrDefault(m => m.ED == moduleInfo.Module);
50+
Module module = container.GetItems().OfType<Module>().FirstOrDefault(m => m.ED == moduleInfo.Module);
5151
if (module == null)
52+
{
5253
continue;
54+
}
5355

5456
module = (Module)module.Unstack(1);
5557

5658
if (module is ActiveModule activeModule && moduleInfo.Ammo != EntityDefault.None)
5759
{
58-
var ammo = (Ammo)container.GetAndRemoveItemByDefinition(moduleInfo.Ammo.Definition, activeModule.AmmoCapacity);
60+
Ammo ammo = (Ammo)container.GetAndRemoveItemByDefinition(moduleInfo.Ammo.Definition, activeModule.AmmoCapacity);
5961
if (ammo != null)
62+
{
6063
activeModule.SetAmmo(ammo);
64+
}
6165
}
6266

63-
component.EquipModuleOrThrow(module, moduleInfo.Slot);
67+
component.EquipModuleOrThrow(module, moduleInfo.Slot, robot.Definition);
6468
}
6569
}
6670

@@ -69,13 +73,13 @@ public override void HandleRequest(IRequest request)
6973
robot.Save();
7074
container.Save();
7175

72-
var result = new Dictionary<string, object>
76+
Dictionary<string, object> result = new Dictionary<string, object>
7377
{
7478
{k.robot, robot.ToDictionary()},
7579
{k.container, container.ToDictionary()}
7680
};
7781
Message.Builder.FromRequest(request).WithData(result).Send();
78-
82+
7983
scope.Complete();
8084
}
8185
}

src/Perpetuum.RequestHandlers/Zone/Containers/EquipModule.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,22 @@ public class EquipModule : ZoneChangeModule
1111
{
1212
public override void DoChange(IZoneRequest request, Player player, Container container)
1313
{
14-
var componentType = request.Data.GetOrDefault<string>(k.robotComponent).ToEnum<RobotComponentType>();
15-
var component = player.GetRobotComponentOrThrow(componentType);
16-
var slot = request.Data.GetOrDefault<int>(k.slot);
14+
RobotComponentType componentType = request.Data.GetOrDefault<string>(k.robotComponent).ToEnum<RobotComponentType>();
15+
RobotComponent component = player.GetRobotComponentOrThrow(componentType);
16+
int slot = request.Data.GetOrDefault<int>(k.slot);
1717
component.GetModule(slot).ThrowIfNotNull(ErrorCodes.UsedSlot); //OPP: explicitly prohibit this to make this simpler
1818
// component.MakeSlotFree(slot, container); // Big nope
1919

20-
var moduleEid = request.Data.GetOrDefault<long>(k.moduleEID);
21-
var module = (Module)container.GetItemOrThrow(moduleEid).Unstack(1);
20+
long moduleEid = request.Data.GetOrDefault<long>(k.moduleEID);
21+
Module module = (Module)container.GetItemOrThrow(moduleEid).Unstack(1);
2222
module.CheckEnablerExtensionsAndThrowIfFailed(player.Character);
2323

2424
//Perform pre-fit check for fitting legality
2525
player.CheckEnergySystemAndThrowIfFailed(module);
2626

27-
component.EquipModuleOrThrow(module, slot);
27+
Robot robot = player;
28+
29+
component.EquipModuleOrThrow(module, slot, robot.Definition);
2830
}
2931
}
3032
}

src/Perpetuum/EntityFramework/EntityDefaultOptions.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,17 @@ public Faction Faction
162162
}
163163
}
164164

165+
public int[] AllowedBots
166+
{
167+
get
168+
{
169+
int[] ids = _dictionary.GetOrDefault(k.AllowedBots, Array.Empty<int>());
170+
Debug.Assert(ids.Length > 0);
171+
172+
return ids;
173+
}
174+
}
175+
165176
public int PlasmaDefinition => _dictionary.GetOrDefault<int>(k.PlasmaDefinition);
166177

167178
public int PlasmaConsumption => _dictionary.GetOrDefault<int>(k.PlasmaConsumption);

src/Perpetuum/ErrorCodes.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,5 +717,6 @@ public enum ErrorCodes
717717
NoxTeleportForbidden,
718718
PlasmaNotFound,
719719
Overheat,
720+
NotAllowedOnThisBot,
720721
}
721722
}

src/Perpetuum/Keywords.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,5 +1228,8 @@ public class k
12281228
// Plasma-based modules
12291229
public const string PlasmaDefinition = "plasmaDefinition";
12301230
public const string PlasmaConsumption = "plasmaConsumption";
1231+
1232+
// Allowed bots for this equipment
1233+
public const string AllowedBots = "allowedBots";
12311234
}
12321235
}

src/Perpetuum/Robots/Robot.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,25 @@ protected override void OnBeforeRemovedFromZone(IZone zone)
403403
base.OnBeforeRemovedFromZone(zone);
404404
}
405405

406+
//TODO: review if it's still has to be Lazy
406407
private void InitComponents()
407408
{
409+
//Peanuts Plague
408410
components = new Lazy<IEnumerable<Item>>(() => Children.OfType<Item>().ToArray());
411+
_ = components.Value; // force evaluation
409412
robotComponents = new Lazy<IEnumerable<RobotComponent>>(() => Components.OfType<RobotComponent>().ToArray());
410-
modules = new Lazy<IEnumerable<Module>>(() => RobotComponents.SelectMany(c => c.Modules).ToArray());
413+
_ = robotComponents.Value; // force evaluation
414+
modules = new Lazy<IEnumerable<Module>>(() => RobotComponents
415+
.SelectMany(c =>
416+
{
417+
c.Initialize();
418+
419+
return c.Modules;
420+
})
421+
.ToArray());
422+
_ = modules.Value; // force evaluation
411423
activeModules = new Lazy<IEnumerable<ActiveModule>>(() => Modules.OfType<ActiveModule>().ToArray());
424+
_ = activeModules.Value; // force evaluation
412425
}
413426

414427
protected override void OnEnterZone(IZone zone, ZoneEnterType enterType)

src/Perpetuum/Robots/RobotComponent.cs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ public override void Initialize()
4545

4646
private void InitModules()
4747
{
48-
modules = new Lazy<IEnumerable<Module>>(() => Children.OfType<Module>().ToArray());
49-
activeModules = new Lazy<IEnumerable<ActiveModule>>(() => Modules.OfType<ActiveModule>().ToArray());
48+
modules = new Lazy<IEnumerable<Module>>(() => Children.OfType<Module>().ToArray(), isThreadSafe: true);
49+
_ = modules.Value;
50+
activeModules = new Lazy<IEnumerable<ActiveModule>>(() => Modules.OfType<ActiveModule>().ToArray(), isThreadSafe: true);
51+
_ = activeModules.Value;
5052
}
5153

5254
public override void AcceptVisitor(IEntityVisitor visitor)
@@ -129,24 +131,31 @@ public bool IsValidSlotTo(Module module, int slot)
129131
(!specializedSlot || specializedModule);
130132
}
131133

132-
public ErrorCodes CanEquipModule(Module module, int slot)
134+
public ErrorCodes CanEquipModule(Module module, int slot, int robotDefinition = 0)
133135
{
134-
return IsUsedSlot(slot)
135-
? ErrorCodes.UsedSlot
136-
: !IsValidSlotTo(module, slot)
137-
? ErrorCodes.InvalidSlot
138-
: module.Quantity <= 0
139-
? ErrorCodes.WTFErrorMedicalAttentionSuggested
140-
: module.IsDamaged
141-
? ErrorCodes.ItemHasToBeRepaired
142-
: !CheckUniqueModule(module)
143-
? ErrorCodes.OnlyOnePerCategoryPerRobotAllowed
144-
: ErrorCodes.NoError;
136+
return IsRobotAllowed(module, robotDefinition)
137+
? ErrorCodes.NotAllowedOnThisBot
138+
: IsUsedSlot(slot)
139+
? ErrorCodes.UsedSlot
140+
: !IsValidSlotTo(module, slot)
141+
? ErrorCodes.InvalidSlot
142+
: module.Quantity <= 0
143+
? ErrorCodes.WTFErrorMedicalAttentionSuggested
144+
: module.IsDamaged
145+
? ErrorCodes.ItemHasToBeRepaired
146+
: !CheckUniqueModule(module)
147+
? ErrorCodes.OnlyOnePerCategoryPerRobotAllowed
148+
: ErrorCodes.NoError;
145149
}
146150

147-
public void EquipModuleOrThrow(Module module, int slot)
151+
private bool IsRobotAllowed(Module module, int robotDefinition = 0)
148152
{
149-
_ = CanEquipModule(module, slot).ThrowIfError();
153+
return module.ED.Options.AllowedBots.Length > 0 && !module.ED.Options.AllowedBots.Contains(robotDefinition);
154+
}
155+
156+
public void EquipModuleOrThrow(Module module, int slot, int robotDefinition = 0)
157+
{
158+
_ = CanEquipModule(module, slot, robotDefinition).ThrowIfError();
150159
EquipModule(module, slot);
151160
}
152161

src/Perpetuum/Zones/LandMines/LandMine.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,6 @@ public override void AcceptVisitor(IEntityVisitor visitor)
113113
}
114114
}
115115

116-
public override void OnUnitsFound(List<Player> unitsFound)
117-
{
118-
}
119-
120116
protected override ProximityDeviceBase GetThis()
121117
{
122118
return this;

0 commit comments

Comments
 (0)