Skip to content

Commit

Permalink
P34.1 (#505)
Browse files Browse the repository at this point in the history
* p34.1

* Hotfix for overheat
  • Loading branch information
Sellafield authored Jan 6, 2025
1 parent ba738cb commit 422585f
Show file tree
Hide file tree
Showing 21 changed files with 499 additions and 334 deletions.
5 changes: 4 additions & 1 deletion src/Perpetuum.Bootstrapper/Modules/EntitiesModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ protected override void Load(ContainerBuilder builder)
RegisterModule<RemoteControlledDrillerModule>(builder);
RegisterModule<RemoteControlledHarvesterModule>(builder);
RegisterModule<HarvesterModule>(builder);
RegisterModule<LargeHarvesterModule>(builder);
RegisterModule<Perpetuum.Modules.Module>(builder);
RegisterModule<WeaponModule>(builder);
RegisterModule<FirearmWeaponModule>(builder); // OPP: new subclass for firearms
Expand Down Expand Up @@ -472,7 +473,9 @@ void ByNamePatternAndFlag<T>(string substr, CategoryFlags cf, params Parameter[]
ByCategoryFlags<LargeDrillerModule>(CategoryFlags.cf_large_drillers, new NamedParameter("ammoCategoryFlags", CategoryFlags.cf_deep_mining_ammo));
ByCategoryFlags<RemoteControlledDrillerModule>(CategoryFlags.cf_industrial_turret_drillers);
ByCategoryFlags<RemoteControlledHarvesterModule>(CategoryFlags.cf_industrial_turret_harvesters);
ByCategoryFlags<HarvesterModule>(CategoryFlags.cf_harvesters, new NamedParameter("ammoCategoryFlags", CategoryFlags.cf_harvesting_ammo));
ByCategoryFlags<HarvesterModule>(CategoryFlags.cf_small_harvesters, new NamedParameter("ammoCategoryFlags", CategoryFlags.cf_harvesting_ammo));
ByCategoryFlags<HarvesterModule>(CategoryFlags.cf_medium_harvesters, new NamedParameter("ammoCategoryFlags", CategoryFlags.cf_harvesting_ammo));
ByCategoryFlags<LargeHarvesterModule>(CategoryFlags.cf_large_harvesters, new NamedParameter("ammoCategoryFlags", CategoryFlags.cf_mass_harvesting_ammo));
ByCategoryFlags<GeoScannerModule>(CategoryFlags.cf_mining_probes, new NamedParameter("ammoCategoryFlags", CategoryFlags.cf_mining_probe_ammo));
ByCategoryFlags<UnitScannerModule>(CategoryFlags.cf_chassis_scanner);
ByCategoryFlags<ContainerScannerModule>(CategoryFlags.cf_cargo_scanner);
Expand Down
2 changes: 2 additions & 0 deletions src/Perpetuum.ExportedTypes/AggregateField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -513,5 +513,7 @@ public enum AggregateField
drone_remote_command_translation_retreat_confirmation = 753,
server_wide_ep_bonus = 754,
server_wide_ep_bonus_duration = 755,
effect_excavator_harvesting_amount_modifier = 756,
effect_excavator_enhancer_harvesting_amount_modifier = 757,
}
}
2 changes: 2 additions & 0 deletions src/Perpetuum.ExportedTypes/CategoryFlags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public enum CategoryFlags : long
cf_nuimqol_combat_drones_units = 0x000000000202120A,
cf_thelodica_combat_drones_units = 0x000000000302120A,
cf_deep_mining_ammo = 0x000000000000130A,
cf_mass_harvesting_ammo = 0x000000000000140A,

cf_attack_drones_units = 0x000000000003120A,
cf_assault_drones_units = 0x000000000004120A,
Expand Down Expand Up @@ -233,6 +234,7 @@ public enum CategoryFlags : long
cf_harvesters = 0x000000000006060F,
cf_small_harvesters = 0x000000000106060F,
cf_medium_harvesters = 0x000000000206060F,
cf_large_harvesters = 0x000000000306060F,
cf_medium_harvesters_old = 0x000000000007060F,
cf_industrial_turret_harvesters = 0x000000000008060F,
cf_construction_modules = 0x000000000009060F,
Expand Down
12 changes: 9 additions & 3 deletions src/Perpetuum/Modules/ActiveModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,14 @@ protected ActiveModule(bool ranged) : this(CategoryFlags.undefined, ranged)
{
}

private const double heatCoefficient = 0.242;
private Lock _lock;
protected readonly ModuleProperty coreUsage;
protected readonly CycleTimeProperty cycleTime;
protected readonly ItemProperty falloff = ItemProperty.None;
protected readonly ModuleProperty optimalRange;

private readonly CategoryFlags ammoCategoryFlags;

protected virtual long GeneratedHeat => 1;

public Lock Lock
{
[CanBeNull]
Expand Down Expand Up @@ -174,6 +172,14 @@ public override Dictionary<string, object> ToDictionary()
return result;
}

public void GenerateHeat(EffectType effectType, double weaponCount = 1)
{
double heatValue = cycleTime.Value / 1000 * heatCoefficient * weaponCount;
ParentRobot.IncreaseHeatLevelByValue(
effectType,
heatValue);
}

protected abstract void OnAction();

protected virtual void HandleOffensivePVPCheck(Player parentPlayer, UnitLock unitLockTarget)
Expand Down
5 changes: 1 addition & 4 deletions src/Perpetuum/Modules/DrillerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ protected override void OnAction()
}

ConsumeAmmo();
ParentRobot.IncreaseOverheatByValue(
EffectType.effect_excavator,
GeneratedHeat);
}

protected override int CalculateEp(int materialType)
Expand Down Expand Up @@ -200,7 +197,7 @@ remoteControlledCreature.CommandRobot is Player ownerPlayer
scope.Complete();
}

ParentRobot.IncreaseOverheat(EffectType.effect_excavator);
GenerateHeat(EffectType.effect_excavator);
}

protected void CheckEnablerEffect(MaterialInfo materialInfo, Position position)
Expand Down
10 changes: 7 additions & 3 deletions src/Perpetuum/Modules/EffectModules/ExcavatorModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ namespace Perpetuum.Modules.EffectModules
public sealed class ExcavatorModule : EffectModule
{
private readonly ItemProperty miningAmountModifier;
private readonly ItemProperty harvestingAmountModifier;
private readonly ItemProperty stealthStrengthModifier;
private readonly ItemProperty effectEnhancerAuraRadiusModifier;

public ExcavatorModule()
{
stealthStrengthModifier = new ModuleProperty(this, AggregateField.effect_excavator_stealth_strength_modifier);
AddProperty(stealthStrengthModifier);

miningAmountModifier = new ModuleProperty(this, AggregateField.effect_excavator_mining_amount_modifier);
AddProperty(miningAmountModifier);

harvestingAmountModifier = new ModuleProperty(this, AggregateField.effect_excavator_harvesting_amount_modifier);
AddProperty(harvestingAmountModifier);

stealthStrengthModifier = new ModuleProperty(this, AggregateField.effect_excavator_stealth_strength_modifier);
AddProperty(stealthStrengthModifier);

effectEnhancerAuraRadiusModifier = new ModuleProperty(this, AggregateField.effect_enhancer_aura_radius_modifier);
AddProperty(effectEnhancerAuraRadiusModifier);
}
Expand Down
11 changes: 7 additions & 4 deletions src/Perpetuum/Modules/HarvesterModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ namespace Perpetuum.Modules
{
public class HarvesterModule : GathererModule
{
private const int MAX_EP_PER_DAY = 1440;
private readonly PlantHarvester.Factory _plantHarvesterFactory;
private readonly HarvestingAmountModifierProperty _harverstingAmountModifier;
protected const int MAX_EP_PER_DAY = 1440;
protected readonly PlantHarvester.Factory _plantHarvesterFactory;
protected readonly HarvestingAmountModifierProperty _harverstingAmountModifier;

public HarvesterModule(CategoryFlags ammoCategoryFlags, PlantHarvester.Factory plantHarvesterFactory) : base(ammoCategoryFlags, true)
{
Expand All @@ -51,6 +51,7 @@ public override void UpdateProperty(AggregateField field)
case AggregateField.effect_harvesting_amount_modifier:
case AggregateField.drone_amplification_harvesting_amount_modifier:
case AggregateField.drone_remote_command_translation_harvesting_amount_modifier:
case AggregateField.effect_excavator_mining_amount_modifier:
{
_harverstingAmountModifier.Update();

Expand Down Expand Up @@ -99,7 +100,7 @@ protected override void OnAction()
ConsumeAmmo();
}

public void DoHarvesting(IZone zone)
public virtual void DoHarvesting(IZone zone)
{
TerrainLock terrainLock = GetLock().ThrowIfNotType<TerrainLock>(ErrorCodes.InvalidLockType);
CreateBeam(terrainLock.Location, BeamState.AlignToTerrain);
Expand Down Expand Up @@ -144,6 +145,8 @@ remoteControlledCreature.CommandRobot is Player ownerPlayer
scope.Complete();
}
}

GenerateHeat(EffectType.effect_excavator);
}
}
}
8 changes: 4 additions & 4 deletions src/Perpetuum/Modules/LargeDrillerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ public LargeDrillerModule(CategoryFlags ammoCategoryFlags, RareMaterialHandler r
{
}

protected override long GeneratedHeat => 5;

public override void DoExtractMinerals(IZone zone)
{
ParentRobot.IncreaseOverheat(EffectType.effect_excavator);

Position centralTile = ParentRobot.PositionWithHeight;
MaterialType materialType;
if (!(GetAmmo() is MiningAmmo ammo))
Expand Down Expand Up @@ -96,7 +92,11 @@ public override void DoExtractMinerals(IZone zone)
Transaction.Current.OnCommited(() => container.SendUpdateToOwnerAsync());
scope.Complete();
}


}

GenerateHeat(EffectType.effect_excavator, 6);
}
}
}
94 changes: 94 additions & 0 deletions src/Perpetuum/Modules/LargeHarvesterModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
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.RemoteControl;
using Perpetuum.Zones.Terrains;
using Perpetuum.Zones.Terrains.Materials.Plants;
using Perpetuum.Zones.Terrains.Materials.Plants.Harvesters;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Transactions;

namespace Perpetuum.Modules
{
public class LargeHarvesterModule : HarvesterModule
{
public LargeHarvesterModule(CategoryFlags ammoCategoryFlags, PlantHarvester.Factory plantHarvesterFactory)
: base(ammoCategoryFlags, plantHarvesterFactory)
{
}

public override void DoHarvesting(IZone zone)
{
Position centralTile = ParentRobot.PositionWithHeight.OffsetInDirection(ParentRobot.Direction, 2);
List<Position> mineralPositions = centralTile.GetEightNeighbours(ParentRobot.Zone.Size).ToList();
mineralPositions.Add(centralTile);

int emptyTilesCounter = 0;

// make it parallel
foreach (Position position in mineralPositions)
{
using (TransactionScope scope = Db.CreateTransaction())
{
using (new TerrainUpdateMonitor(zone))
{
PlantInfo plantInfo = zone.Terrain.Plants.GetValue(position);
if (plantInfo.type == PlantType.NotDefined ||
Zone.Configuration.PlantRules.GetPlantRule(plantInfo.type) == null ||
plantInfo.material <= 0)
{
emptyTilesCounter++;
_ = emptyTilesCounter
.ThrowIfEqual(9, ErrorCodes.NoPlantOnTile);

continue;
}

CreateBeam(position, BeamState.AlignToTerrain);

double amountModifier = _harverstingAmountModifier.GetValueByPlantType(plantInfo.type);
IPlantHarvester plantHarvester = _plantHarvesterFactory(zone, amountModifier);
IEnumerable<ItemInfo> harvestedPlants = plantHarvester.HarvestPlant(position);


Debug.Assert(ParentRobot != null, "ParentRobot != null");
Robots.RobotInventory container = ParentRobot.GetContainer();
Debug.Assert(container != null, "container != null");
container.EnlistTransaction();
Player player = ParentRobot is RemoteControlledCreature remoteControlledCreature &&
remoteControlledCreature.CommandRobot is Player ownerPlayer
? ownerPlayer
: ParentRobot as Player;

Debug.Assert(player != null, "player != null");
foreach (ItemInfo extractedMaterial in harvestedPlants)
{
Item item = (Item)Factory.CreateWithRandomEID(extractedMaterial.Definition);
item.Owner = Owner;
item.Quantity = extractedMaterial.Quantity;
container.AddItem(item, true);
int extractedHarvestDefinition = extractedMaterial.Definition;
int extractedQuantity = extractedMaterial.Quantity;
player.MissionHandler.EnqueueMissionEventInfo(new HarvestPlantEventInfo(player, extractedHarvestDefinition, extractedQuantity, position));
player.Zone?.HarvestLogHandler.EnqueueHarvestLog(extractedHarvestDefinition, extractedQuantity);
}

container.Save();
OnGathererMaterial(zone, player, (int)plantInfo.type);
Transaction.Current.OnCommited(() => container.SendUpdateToOwnerAsync());
scope.Complete();
}
}
}

GenerateHeat(EffectType.effect_excavator, 6);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public HarvestingAmountModifierProperty(GathererModule module) : base(module, Ag
AddEffectModifier(AggregateField.effect_harvesting_amount_modifier);
AddEffectModifier(AggregateField.drone_amplification_harvesting_amount_modifier);
AddEffectModifier(AggregateField.drone_remote_command_translation_harvesting_amount_modifier);
AddEffectModifier(AggregateField.effect_excavator_harvesting_amount_modifier);
}

public double GetValueByPlantType(PlantType plantType)
Expand Down Expand Up @@ -68,6 +69,7 @@ protected override double CalculateValue()
ApplyEffectModifiers(ref p);
module.ParentRobot?.ApplyEffectPropertyModifiers(AggregateField.drone_amplification_harvesting_amount_modifier, ref p);
module.ParentRobot?.ApplyEffectPropertyModifiers(AggregateField.drone_remote_command_translation_harvesting_amount_modifier, ref p);
module.ParentRobot?.ApplyEffectPropertyModifiers(AggregateField.effect_excavator_harvesting_amount_modifier, ref p);

return p.Value;
}
Expand Down
5 changes: 1 addition & 4 deletions src/Perpetuum/Modules/Weapons/WeaponModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public WeaponModule(CategoryFlags ammoCategoryFlags) : base(ammoCategoryFlags, t
DamageModifier.AddEffectModifier(AggregateField.drone_amplification_damage_modifier);
DamageModifier.AddEffectModifier(AggregateField.drone_remote_command_translation_damage_modifier);
DamageModifier.AddEffectModifier(AggregateField.effect_dreadnought_weapon_damage_modifier);

}

public override void AcceptVisitor(IEntityVisitor visitor)
Expand Down Expand Up @@ -74,9 +73,7 @@ public override void UpdateProperty(AggregateField field)
protected override void OnAction()
{
action.DoAction();
ParentRobot.IncreaseOverheatByValue(
EffectType.effect_dreadnought,
GeneratedHeat);
GenerateHeat(EffectType.effect_dreadnought);
}

protected virtual bool CheckAccuracy(Unit victim)
Expand Down
1 change: 1 addition & 0 deletions src/Perpetuum/Perpetuum.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@
<Compile Include="MathHelper.cs" />
<Compile Include="MessageConstants.cs" />
<Compile Include="Modules\AdaptiveAlloy\AdaptiveAlloyModule.cs" />
<Compile Include="Modules\LargeHarvesterModule.cs" />
<Compile Include="Modules\ModuleProperties\RemoteCommandTranslatorArmorMaxProperty.cs" />
<Compile Include="Modules\ModuleProperties\RemoteCommandTranslatorDamageProperty.cs" />
<Compile Include="Modules\ModuleProperties\RemoteCommandTranslatorHarvestingAmountProperty.cs" />
Expand Down
Loading

0 comments on commit 422585f

Please sign in to comment.