Skip to content

Commit

Permalink
Merge remote-tracking branch 'darkademic/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Inq8 committed Aug 2, 2024
2 parents 7b72cdf + e2448d9 commit c625035
Show file tree
Hide file tree
Showing 14 changed files with 384 additions and 68 deletions.
35 changes: 4 additions & 31 deletions OpenRA.Mods.CA/Traits/Player/PlayerExperienceLevels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common;
Expand Down Expand Up @@ -67,13 +68,7 @@ public class PlayerExperienceLevels : ConditionalTrait<PlayerExperienceLevelsInf
bool dummyActorQueued;
int ticksUntilSpawnDummyActor;

int fadeInMaxTicks = 5;
int waitMaxTicks = 85;
int fadeOutMaxTicks = 15;

int fadeInTicks = 0;
int waitTicks = 0;
int fadeOutTicks = 0;
public event Action<int> LevelledUp;

public PlayerExperienceLevels(Actor self, PlayerExperienceLevelsInfo info)
: base(info)
Expand All @@ -93,19 +88,6 @@ public PlayerExperienceLevels(Actor self, PlayerExperienceLevelsInfo info)

public int? XpRequiredForNextLevel => currentLevel >= maxLevel ? null : nextLevelXpRequired;

public float LevelUpImageAlpha {
get {
if (fadeInTicks > 0)
return 1f - (float)fadeInTicks / fadeInMaxTicks;
else if (waitTicks > 0)
return 1f;
else if (fadeOutTicks > 0)
return (float)fadeOutTicks / fadeOutMaxTicks;
else
return 0f;
}
}

public IEnumerable<string> ProvidesPrerequisites
{
get
Expand Down Expand Up @@ -136,13 +118,6 @@ void ITick.Tick(Actor self)
LevelUp(self);
}

if (fadeInTicks > 0)
fadeInTicks--;
else if (waitTicks > 0)
waitTicks--;
else if (fadeOutTicks > 0)
fadeOutTicks--;

if (notificationQueued && --ticksUntilNotification <= 0)
{
if (Info.LevelUpNotification != null)
Expand Down Expand Up @@ -175,12 +150,10 @@ void LevelUp(Actor self)
if (Info.LevelUpSound != null)
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Sounds", Info.LevelUpSound, self.Owner.Faction.InternalName);

fadeInTicks = fadeInMaxTicks;
waitTicks = waitMaxTicks;
fadeOutTicks = fadeOutMaxTicks;

currentLevel++;

LevelledUp?.Invoke(currentLevel);

if (currentLevel < maxLevel)
nextLevelXpRequired = Info.LevelXpRequirements[currentLevel];

Expand Down
74 changes: 65 additions & 9 deletions OpenRA.Mods.CA/Traits/Player/ProvidesPrerequisiteOnCounts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
*/
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
Expand All @@ -31,7 +33,10 @@ public class ProvidesPrerequisiteOnCountsInfo : TraitInfo, ITechTreePrerequisite
public readonly string[] Factions = { };

[Desc("If true, the prerequisite is permanent once the count is reached.")]
public readonly bool Permanent = true;
public readonly bool Permanent = false;

[Desc("If true, the prerequisite is permanent if an upgrade is acquired.")]
public readonly string[] PermanentAfterUpgrades = null;

[NotificationReference("Speech")]
[Desc("Speech notification to play when player levels up.")]
Expand All @@ -47,6 +52,10 @@ public class ProvidesPrerequisiteOnCountsInfo : TraitInfo, ITechTreePrerequisite
[ActorReference]
public readonly string DummyActor = null;

[NotificationReference("Sounds")]
[Desc("Sound notification to play when count is incremented.")]
public readonly string IncrementSound = null;

IEnumerable<string> ITechTreePrerequisiteInfo.Prerequisites(ActorInfo info)
{
return new string[] { Prerequisite };
Expand All @@ -60,23 +69,41 @@ public class ProvidesPrerequisiteOnCount : ITechTreePrerequisite, INotifyCreated
public readonly ProvidesPrerequisiteOnCountsInfo Info;
readonly Actor self;
readonly Dictionary<string, int> counts;
readonly bool validFaction;
TechTree techTree;
UpgradesManager upgradesManager;
bool permanentlyUnlocked;
bool notificationQueued;
int ticksUntilNotification;
bool dummyActorQueued;
int ticksUntilSpawnDummyActor;

public event Action Incremented;
public event Action Decremented;
public event Action Unlocked;
public event Action<string> UnlockedPermanently;

public ProvidesPrerequisiteOnCount(ActorInitializer init, ProvidesPrerequisiteOnCountsInfo info)
{
Info = info;
self = init.Self;
counts = new Dictionary<string, int>();
permanentlyUnlocked = false;
ticksUntilNotification = info.NotificationDelay;

var player = self.Owner;
validFaction = info.Factions.Length == 0 || info.Factions.Contains(player.Faction.InternalName);
}

public bool Enabled
{
get
{
return validFaction;
}
}

bool Enabled
bool PrerequisitesGranted
{
get
{
Expand All @@ -98,13 +125,15 @@ bool AllRequiredCountsReached
}
}

public Dictionary<string, int> Counts => counts;

public string[] Factions => Info.Factions;

public IEnumerable<string> ProvidesPrerequisites
{
get
{
if (!Enabled)
if (!PrerequisitesGranted)
yield break;

yield return Info.Prerequisite;
Expand All @@ -120,10 +149,14 @@ void INotifyCreated.Created(Actor self)
var playerActor = self.Info.Name == "player" ? self : self.Owner.PlayerActor;
techTree = playerActor.Trait<TechTree>();
techTree.ActorChanged(self);
upgradesManager = playerActor.TraitOrDefault<UpgradesManager>();
}

void ITick.Tick(Actor self)
{
if (!Enabled)
return;

if (notificationQueued && --ticksUntilNotification <= 0)
{
if (Info.RequiredCountReachedNotification != null)
Expand All @@ -149,6 +182,19 @@ void ITick.Tick(Actor self)
});
});
}

if (!permanentlyUnlocked && Info.PermanentAfterUpgrades != null)
{
foreach (var upgrade in Info.PermanentAfterUpgrades)
{
if (upgradesManager.IsUnlocked(upgrade))
{
permanentlyUnlocked = true;
UnlockedPermanently?.Invoke(upgrade);
break;
}
}
}
}

public void Increment(string type)
Expand All @@ -159,31 +205,41 @@ public void Increment(string type)
counts[type]++;
techTree.ActorChanged(self);

if (AllRequiredCountsReached)
if (!permanentlyUnlocked && counts[type] <= Info.RequiredCounts[type])
{
if (!permanentlyUnlocked)
Incremented?.Invoke();

if (Info.IncrementSound != null)
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Sounds", Info.IncrementSound, self.Owner.Faction.InternalName);

if (AllRequiredCountsReached)
{
Unlocked?.Invoke();
notificationQueued = true;

if (Info.DummyActor != null)
{
dummyActorQueued = true;
ticksUntilSpawnDummyActor = 1;
}
}

if (Info.Permanent)
permanentlyUnlocked = true;
if (Info.Permanent)
{
permanentlyUnlocked = true;
UnlockedPermanently?.Invoke(null);
}
}
}
}

public void Decrement(string type)
{
if (!counts.ContainsKey(type))
if (permanentlyUnlocked || !counts.ContainsKey(type))
return;

counts[type]--;
techTree.ActorChanged(self);
Decremented?.Invoke();
}
}
}
4 changes: 4 additions & 0 deletions OpenRA.Mods.CA/Traits/Player/UpgradesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public UpgradesManager(Actor self, UpgradesManagerInfo info)
Hash = 0;
}

public event Action<string> UpgradeCompleted;

public UpgradeInfo UpgradeableActorCreated(Upgradeable upgradeable, string upgradeType, string sourceActorType, string targetActorType, string condition, int cost, int buildDuration, int buildDurationModifier)
{
if (upgrades.ContainsKey(upgradeType))
Expand Down Expand Up @@ -85,6 +87,8 @@ public void UpgradeProviderCreated(string type)

foreach (var p in upgradeables)
p.Trait.Unlock();

UpgradeCompleted?.Invoke(type);
}

public bool IsUnlocked(string upgradeType)
Expand Down
3 changes: 1 addition & 2 deletions OpenRA.Mods.CA/Traits/UpdatesCount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ void INotifyCreated.Created(Actor self)
void UpdateCounters(Player owner)
{
counters = owner.PlayerActor.TraitsImplementing<ProvidesPrerequisiteOnCount>()
.Where(c => c.Info.RequiredCounts.ContainsKey(Info.Type)
&& (c.Factions.Length == 0 || c.Factions.Contains(owner.Faction.InternalName)));
.Where(c => c.Info.RequiredCounts.ContainsKey(Info.Type) && c.Enabled);
}

void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#region Copyright & License Information
/**
* Copyright (c) The OpenRA Combined Arms Developers (see CREDITS).
* This file is part of OpenRA Combined Arms, which is free software.
* It is made available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. For more information, see COPYING.
*/
#endregion

using OpenRA.Mods.CA.Traits;
using OpenRA.Mods.Common.Widgets;
using OpenRA.Widgets;

namespace OpenRA.Mods.CA.Widgets.Logic
{
class AlliedCoalitionIndicatorLogic : ChromeLogic
{
const string NoneImage = "none";
const string DisabledImage = "disabled";

string chosenCoalition;

[ObjectCreator.UseCtor]
public AlliedCoalitionIndicatorLogic(Widget widget, World world)
{
UpgradesManager upgradesManager = null;

upgradesManager = world.LocalPlayer.PlayerActor.Trait<UpgradesManager>();
var container = widget.Get<ContainerWidget>("ALLIED_COALITION");
var coalitionImage = container.Get<ImageWidget>("ALLIED_COALITION_IMAGE");

if (world.LocalPlayer.Faction.Side != "Allies")
{
coalitionImage.GetImageName = () => DisabledImage;
coalitionImage.IsVisible = () => false;
return;
}

if (upgradesManager == null)
{
coalitionImage.GetImageName = () => NoneImage;
coalitionImage.IsVisible = () => true;
return;
}

upgradesManager.UpgradeCompleted += (coalitionName) =>
{
if (coalitionName.EndsWith(".coalition"))
chosenCoalition = coalitionName.Split('.')[0];
};

coalitionImage.GetImageName = () => $"{chosenCoalition ?? NoneImage}";
coalitionImage.IsVisible = () => true;
}
}
}
Loading

0 comments on commit c625035

Please # to comment.