Salvage dungeons (#14520)

This commit is contained in:
metalgearsloth
2023-03-10 16:41:22 +11:00
committed by GitHub
parent 214ca06997
commit 6157dfa3c0
145 changed files with 24649 additions and 396 deletions

View File

@@ -0,0 +1,334 @@
using Content.Client.Computer;
using Content.Client.Stylesheets;
using Content.Client.UserInterface.Controls;
using Content.Shared.Parallax.Biomes;
using Content.Shared.Procedural;
using Content.Shared.Procedural.Loot;
using Content.Shared.Procedural.Rewards;
using Content.Shared.Random;
using Content.Shared.Random.Helpers;
using Content.Shared.Salvage;
using Content.Shared.Salvage.Expeditions;
using Content.Shared.Salvage.Expeditions.Structure;
using Content.Shared.Shuttles.BUIStates;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
namespace Content.Client.Salvage.UI;
[GenerateTypedNameReferences]
public sealed partial class SalvageExpeditionWindow : FancyWindow,
IComputerWindow<EmergencyConsoleBoundUserInterfaceState>
{
private readonly IGameTiming _timing;
private readonly IPrototypeManager _prototype;
private readonly SharedSalvageSystem _salvage;
public event Action<ushort>? ClaimMission;
private bool _claimed;
private TimeSpan _nextOffer;
public SalvageExpeditionWindow()
{
RobustXamlLoader.Load(this);
_timing = IoCManager.Resolve<IGameTiming>();
_prototype = IoCManager.Resolve<IPrototypeManager>();
_salvage = IoCManager.Resolve<IEntityManager>().EntitySysManager.GetEntitySystem<SharedSalvageSystem>();
}
public void UpdateState(SalvageExpeditionConsoleState state)
{
_claimed = state.Claimed;
_nextOffer = state.NextOffer;
Container.DisposeAllChildren();
for (var i = 0; i < state.Missions.Count; i++)
{
// TODO: Make this XAML
var mission = state.Missions[i];
var config = _prototype.Index<SalvageExpeditionPrototype>(mission.Config);
var dungeonConfig = _prototype.Index<DungeonConfigPrototype>(config.DungeonConfigPrototype);
var faction = SharedSalvageSystem.GetFaction(config.Factions, mission.Seed);
var factionConfig = _prototype.Index<SalvageFactionPrototype>(faction);
// If we ever need this on server then move it
var missionDesc = string.Empty;
var missionDetails = string.Empty;
switch (config.Mission)
{
case SalvageStructure structure:
var structureConfig = (SalvageStructureFaction) factionConfig.Configs[mission.Config];
missionDesc = "Demolition";
// TODO:
missionDetails = $"Destroy {SharedSalvageSystem.GetStructureCount(structure, mission.Seed)} {_prototype.Index<EntityPrototype>(structureConfig.Spawn).Name} structures.";
break;
default:
throw new NotImplementedException();
}
// Mission
var missionStripe = new StripeBack()
{
Margin = new Thickness(0f, -5f, 0f, 0f)
};
missionStripe.AddChild(new Label()
{
Text = missionDesc,
HorizontalAlignment = HAlignment.Center,
Margin = new Thickness(0f, 5f, 0f, 5f),
});
var lBox = new BoxContainer()
{
Orientation = BoxContainer.LayoutOrientation.Vertical
};
// Difficulty
// Details
lBox.AddChild(new Label()
{
Text = $"Difficulty:"
});
var difficultyColor = StyleNano.NanoGold;
switch (config.DifficultyRating)
{
case DifficultyRating.None:
difficultyColor = StyleNano.ButtonColorDefault;
break;
case DifficultyRating.Minor:
difficultyColor = StyleNano.GoodGreenFore;
break;
case DifficultyRating.Moderate:
difficultyColor = StyleNano.ConcerningOrangeFore;
break;
default:
throw new ArgumentOutOfRangeException();
}
lBox.AddChild(new Label
{
Text = config.DifficultyRating.ToString(),
FontColorOverride = difficultyColor,
HorizontalAlignment = HAlignment.Left,
Margin = new Thickness(0f, 0f, 0f, 5f),
});
// Details
lBox.AddChild(new Label
{
Text = $"Details:"
});
lBox.AddChild(new Label
{
Text = missionDetails,
FontColorOverride = StyleNano.NanoGold,
HorizontalAlignment = HAlignment.Left,
Margin = new Thickness(0f, 0f, 0f, 5f),
});
// Details
lBox.AddChild(new Label
{
Text = $"Hostiles:"
});
lBox.AddChild(new Label
{
Text = faction,
FontColorOverride = StyleNano.NanoGold,
HorizontalAlignment = HAlignment.Left,
Margin = new Thickness(0f, 0f, 0f, 5f),
});
// Duration
lBox.AddChild(new Label
{
Text = $"Duration:"
});
lBox.AddChild(new Label
{
Text = mission.Duration.ToString(),
FontColorOverride = StyleNano.NanoGold,
HorizontalAlignment = HAlignment.Left,
Margin = new Thickness(0f, 0f, 0f, 5f),
});
// Biome
lBox.AddChild(new Label
{
Text = "Biome:"
});
lBox.AddChild(new Label
{
Text = _prototype.Index<BiomePrototype>(config.Biome).Description,
FontColorOverride = StyleNano.NanoGold,
HorizontalAlignment = HAlignment.Left,
Margin = new Thickness(0f, 0f, 0f, 5f),
});
// Environment
lBox.AddChild(new Label
{
Text = "Environment:"
});
lBox.AddChild(new Label
{
Text = config.Description,
FontColorOverride = StyleNano.NanoGold,
HorizontalAlignment = HAlignment.Left,
Margin = new Thickness(0f, 0f, 0f, 5f),
});
// Modifiers
// TODO
// Rewards
lBox.AddChild(new Label()
{
Text = $"Reward:"
});
var salvageReward = SharedSalvageSystem.GetReward(_prototype.Index<WeightedRandomPrototype>(config.Reward), mission.Seed, _prototype);
var difficulty = config.DifficultyRating;
var rewardDesc = string.Empty;
switch (salvageReward)
{
case BankReward bank:
rewardDesc = $"Bank payment of {(int) (bank.Amount * SharedSalvageSystem.GetDifficultyModifier(difficulty))}";
break;
default:
throw new ArgumentOutOfRangeException();
}
lBox.AddChild(new Label()
{
Text = rewardDesc,
FontColorOverride = StyleNano.GoodGreenFore,
HorizontalAlignment = HAlignment.Left,
Margin = new Thickness(0f, 0f, 0f, 5f),
});
lBox.AddChild(new Label()
{
Text = $"Materials:"
});
if (config.Loots.Count == 0)
{
lBox.AddChild(new Label()
{
Text = "N/A",
FontColorOverride = StyleNano.ConcerningOrangeFore,
HorizontalAlignment = HAlignment.Left,
Margin = new Thickness(0f, 0f, 0f, 5f),
});
}
else
{
foreach (var lootProto in SharedSalvageSystem.GetLoot(config.Loots, mission.Seed, _prototype))
{
lBox.AddChild(new Label()
{
Text = lootProto.Description,
FontColorOverride = StyleNano.ConcerningOrangeFore,
HorizontalAlignment = HAlignment.Left,
Margin = new Thickness(0f, 0f, 0f, 5f),
});
}
}
// Claim
var claimButton = new Button()
{
HorizontalExpand = true,
Pressed = state.ActiveMission == mission.Index,
ToggleMode = true,
Disabled = state.Claimed,
};
claimButton.Label.Margin = new Thickness(0f, 5f);
claimButton.OnPressed += args =>
{
ClaimMission?.Invoke(mission.Index);
};
if (state.ActiveMission == mission.Index)
{
claimButton.Text = "Claimed";
claimButton.AddStyleClass(StyleBase.ButtonCaution);
}
else
{
claimButton.Text = "Claim";
}
// TODO: Fix this copypaste bullshit
var box = new PanelContainer()
{
PanelOverride = new StyleBoxFlat(new Color(30, 30, 34)),
HorizontalExpand = true,
Margin = new Thickness(5f, 0f),
Children =
{
new BoxContainer()
{
Orientation = BoxContainer.LayoutOrientation.Vertical,
Children =
{
missionStripe,
lBox,
claimButton,
},
Margin = new Thickness(5f, 5f)
}
}
};
LayoutContainer.SetAnchorPreset(box, LayoutContainer.LayoutPreset.Wide);
Container.AddChild(box);
}
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (_claimed)
{
NextOfferBar.Value = 0f;
NextOfferText.Text = "N/A";
return;
}
var remaining = _nextOffer - _timing.CurTime;
if (remaining < TimeSpan.Zero)
{
NextOfferBar.Value = 1f;
NextOfferText.Text = "00:00";
}
else
{
NextOfferBar.Value = 1f - (float) (remaining / SharedSalvageSystem.MissionCooldown);
NextOfferText.Text = $"{remaining.Minutes:00}:{remaining.Seconds:00}";
}
}
}