Unstable 1.1.14.0

This commit is contained in:
Markus Isberg
2023-10-02 16:43:54 +03:00
parent 94f5a93a0c
commit cf8f0de659
606 changed files with 21906 additions and 11456 deletions
@@ -132,7 +132,7 @@ namespace Barotrauma
else
{
outmsg.WriteUInt16(speaker?.ID ?? Entity.NullEntityID);
outmsg.WriteString(Text ?? string.Empty);
outmsg.WriteString(GetDisplayText()?.Value ?? string.Empty);
outmsg.WriteBoolean(FadeToBlack);
outmsg.WriteByte((byte)Options.Count);
for (int i = 0; i < Options.Count; i++)
@@ -0,0 +1,55 @@
#nullable enable
using Barotrauma.Extensions;
using Barotrauma.Networking;
using System.Collections.Generic;
using System.Linq;
namespace Barotrauma;
partial class EventLogAction : EventAction
{
partial void AddEntryProjSpecific(EventLog? eventLog, string displayText)
{
if (eventLog == null) { return; }
if (!TargetTag.IsEmpty)
{
List<Client> targetClients = new List<Client>();
foreach (var target in ParentEvent.GetTargets(TargetTag))
{
if (target is Character character)
{
var ownerClient = GameMain.Server.ConnectedClients.Find(c => c.Character == character);
if (ownerClient != null && eventLog != null)
{
targetClients.Add(ownerClient);
}
}
else
{
DebugConsole.AddWarning($"{target} is not a valid target for an EventLogAction. The target should be a character.");
}
}
if (eventLog.TryAddEntry(ParentEvent.Prefab.Identifier, Id, displayText, targetClients) && ShowInServerLog)
{
Log(targetClients);
}
}
else
{
if (eventLog != null && eventLog.TryAddEntry(ParentEvent.Prefab.Identifier, Id, displayText, GameMain.Server.ConnectedClients) && ShowInServerLog)
{
Log(targetClients: null);
}
}
void Log(List<Client>? targetClients)
{
string clientStr = targetClients == null || targetClients.None() ?
string.Empty :
$" ({string.Join(", ", targetClients.Select(c => NetworkMember.ClientLogName(c)))})";
GameServer.Log($"Event \"{ParentEvent.Prefab.Name}\"{clientStr}: " + displayText,
ParentEvent is TraitorEvent ? ServerLog.MessageType.Traitors : ServerLog.MessageType.Chat);
}
}
}
@@ -0,0 +1,36 @@
namespace Barotrauma
{
partial class EventObjectiveAction : EventAction
{
partial void UpdateProjSpecific()
{
if (GameMain.Server == null) { return; }
EventManager.NetEventObjective objective = new EventManager.NetEventObjective(
Type,
Identifier,
ObjectiveTag,
TextTag,
ParentObjectiveId,
CanBeCompleted);
if (TargetTag.IsEmpty)
{
foreach (var client in GameMain.Server.ConnectedClients)
{
if (client.Character == null) { continue; }
EventManager.ServerWriteObjective(client, objective);
}
}
else
{
foreach (var target in ParentEvent.GetTargets(TargetTag))
{
if (target is not Character character) { continue; }
var ownerClient = GameMain.Server.ConnectedClients.Find(c => c.Character == character);
if (ownerClient == null) { continue; }
EventManager.ServerWriteObjective(ownerClient, objective);
}
}
}
}
}
@@ -0,0 +1,22 @@
#nullable enable
using Barotrauma.Networking;
using System.Collections.Generic;
namespace Barotrauma;
partial class EventLog
{
public bool TryAddEntry(Identifier eventPrefabId, Identifier entryId, string text, IEnumerable<Client> targetClients)
{
if (TryAddEntryInternal(eventPrefabId, entryId, text))
{
foreach (var targetClient in targetClients)
{
EventManager.ServerWriteEventLog(targetClient, new EventManager.NetEventLogEntry(eventPrefabId, entryId, text));
}
return true;
}
return false;
}
}
@@ -1,12 +1,29 @@
using Barotrauma.Networking;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Barotrauma
{
partial class EventManager
{
public static void ServerWriteEventLog(Client client, NetEventLogEntry entry)
{
IWriteMessage outmsg = new WriteOnlyMessage();
outmsg.WriteByte((byte)ServerPacketHeader.EVENTACTION);
outmsg.WriteByte((byte)NetworkEventType.EVENTLOG);
outmsg.WriteNetSerializableStruct(entry);
GameMain.Server?.ServerPeer?.Send(outmsg, client.Connection, DeliveryMethod.Reliable);
}
public static void ServerWriteObjective(Client client, NetEventObjective entry)
{
IWriteMessage outmsg = new WriteOnlyMessage();
outmsg.WriteByte((byte)ServerPacketHeader.EVENTACTION);
outmsg.WriteByte((byte)NetworkEventType.EVENTOBJECTIVE);
outmsg.WriteNetSerializableStruct(entry);
GameMain.Server?.ServerPeer?.Send(outmsg, client.Connection, DeliveryMethod.Reliable);
}
public void ServerRead(IReadMessage inc, Client sender)
{
UInt16 actionId = inc.ReadUInt16();
@@ -16,14 +33,14 @@ namespace Barotrauma
{
if (ev is not ScriptedEvent scriptedEvent) { continue; }
var actions = FindActions(scriptedEvent);
foreach (EventAction action in actions.Select(a => a.Item2))
var actions = scriptedEvent.GetAllActions();
foreach (EventAction action in actions.Select(a => a.action))
{
if (action is not ConversationAction convAction || convAction.Identifier != actionId) { continue; }
if (!convAction.TargetClients.Contains(sender))
{
#if DEBUG || UNSTABLE
DebugConsole.ThrowError($"Client \"{sender.Name}\" tried to respond to a ConversationAction that was not targeted to them.");
DebugConsole.ThrowError($"Client \"{sender.Name}\" tried to respond to a ConversationAction that was not targeted to them ({convAction.Text}).");
#endif
continue;
}
@@ -1,4 +1,7 @@
using Barotrauma.Networking;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Barotrauma
{
@@ -20,6 +23,99 @@ namespace Barotrauma
GameServer.Log($"{TextManager.Get("MissionInfo")}: {header} - {message}", ServerLog.MessageType.ServerMessage);
}
public static int DistributeRewardsToCrew(IEnumerable<Character> crew, int totalReward)
{
int remainingRewards = totalReward;
float sum = GetRewardDistibutionSum(crew);
if (MathUtils.NearlyEqual(sum, 0)) { return remainingRewards; }
foreach (Character character in crew)
{
int rewardDistribution = character.Wallet.RewardDistribution;
float rewardWeight = sum > 100 ? rewardDistribution / sum : rewardDistribution / 100f;
int reward = Math.Min(remainingRewards, (int)(totalReward * rewardWeight));
character.Wallet.Give(reward);
remainingRewards -= reward;
if (remainingRewards <= 0) { break; }
}
return remainingRewards;
}
partial void DistributeExperienceToCrew(IEnumerable<Character> crew, int experienceGain)
{
Dictionary<Character, float> traitorExpSteal = new Dictionary<Character, float>();
float totalExpSteal = 0.0f;
foreach (var traitorEvent in GameMain.Server.TraitorManager.ActiveEvents)
{
if (traitorEvent.TraitorEvent.CurrentState != TraitorEvent.State.Completed) { continue; }
if (traitorEvent.Traitor?.Character == null || !GameMain.Server.ConnectedClients.Contains(traitorEvent.Traitor)) { continue; }
float expSteal = Math.Max(traitorEvent.TraitorEvent.Prefab.StealPercentageOfExperience, 0.0f);
AddTraitorExpSteal(traitorEvent.Traitor.Character, expSteal);
foreach (var secondaryTraitor in traitorEvent.TraitorEvent.SecondaryTraitors)
{
AddTraitorExpSteal(secondaryTraitor.Character, expSteal);
}
void AddTraitorExpSteal(Character traitorCharacter, float expSteal)
{
if (traitorCharacter == null) { return; }
if (!traitorExpSteal.ContainsKey(traitorCharacter))
{
traitorExpSteal.Add(traitorCharacter, 0.0f);
}
traitorExpSteal[traitorCharacter] += expSteal;
}
}
totalExpSteal = traitorExpSteal.Values.Sum();
//if exp to steal exceeds 100%, normalize to get it back to 100%
//(e.g. two traitors who both steal 75%, they'll share 50% of all the exp gains)
if (totalExpSteal > 100.0f)
{
foreach (Character traitor in traitorExpSteal.Keys)
{
traitorExpSteal[traitor] /= totalExpSteal;
}
totalExpSteal = 100.0f;
}
if (totalExpSteal > 0)
{
GameServer.Log($"Traitors stole {(int)totalExpSteal}% of the total experience.", ServerLog.MessageType.Traitors);
}
int nonTraitorCount = GameSession.GetSessionCrewCharacters(CharacterType.Both).Count(c => !traitorExpSteal.ContainsKey(c));
foreach (Networking.Client c in GameMain.Server.ConnectedClients)
{
//give the experience to the stored characterinfo if the client isn't currently controlling a character
GiveMissionExperience(c.Character?.Info ?? c.CharacterInfo);
}
foreach (Character bot in GameSession.GetSessionCrewCharacters(CharacterType.Bot))
{
GiveMissionExperience(bot.Info);
}
void GiveMissionExperience(CharacterInfo info)
{
if (info == null) { return; }
var experienceGainMultiplierIndividual = new AbilityMissionExperienceGainMultiplier(this, 1f);
info.Character?.CheckTalents(AbilityEffectType.OnGainMissionExperience, experienceGainMultiplierIndividual);
int finalExperienceGain = (int)(experienceGain * experienceGainMultiplierIndividual.Value);
if (info.Character != null && traitorExpSteal.TryGetValue(info.Character, out float expToSteal))
{
int stealAmount = (int)(experienceGain * nonTraitorCount * expToSteal / 100.0f);
GameServer.Log($"Traitor {info.Character} stole {stealAmount} ({(int)expToSteal}%) of the total experience.", ServerLog.MessageType.Traitors);
finalExperienceGain += stealAmount;
}
else
{
GameServer.Log($"{(int)(finalExperienceGain * totalExpSteal / 100.0f)} ({(int)totalExpSteal}%) was stolen from {info.Name}.", ServerLog.MessageType.Traitors);
finalExperienceGain -= (int)(finalExperienceGain * totalExpSteal / 100.0f);
}
info.GiveExperience(finalExperienceGain);
}
}
public virtual void ServerWriteInitial(IWriteMessage msg, Client c)
{
msg.WriteUInt16((ushort)State);
@@ -4,8 +4,6 @@ namespace Barotrauma
{
partial class NestMission : Mission
{
private Level.Cave selectedCave;
public override void ServerWriteInitial(IWriteMessage msg, Client c)
{
base.ServerWriteInitial(msg, c);