partial void KillProjSpecific(CauseOfDeathType causeOfDeath, Affliction causeOfDeathAffliction, bool log) { if (log) { if (causeOfDeath == CauseOfDeathType.Affliction) { GameServer.Log(GameServer.CharacterLogName(this) + " has died (Cause of death: " + causeOfDeathAffliction.Prefab.Name + ")", ServerLog.MessageType.Attack); } else { GameServer.Log(GameServer.CharacterLogName(this) + " has died (Cause of death: " + causeOfDeath + ")", ServerLog.MessageType.Attack); } } healthUpdateTimer = 0.0f; if (CauseOfDeath.Killer != null && CauseOfDeath.Killer.IsTraitor && CauseOfDeath.Killer != this) { var owner = GameMain.Server.ConnectedClients.Find(c => c.Character == this); if (owner != null) { GameMain.Server.SendDirectChatMessage(TextManager.FormatServerMessage("KilledByTraitorNotification"), owner, ChatMessageType.ServerMessageBoxInGame); } } foreach (Client client in GameMain.Server.ConnectedClients) { if (client.InGame) { client.PendingPositionUpdates.Enqueue(this); } } }
public override bool Start(Traitor traitor) { if (!base.Start(traitor)) { return(false); } foreach (var item in Item.ItemList) { if (item.Submarine == null || Traitors.All(t => item.Submarine.TeamID != t.Character.TeamID)) { continue; } if (item.Condition > conditionThreshold && (item.Prefab?.Identifier == tag || item.HasTag(tag))) { targetItems.Add(item); } } //only target items in the main sub if there are any if (targetItems.Count > 1 && targetItems.Any(it => it.Submarine == Submarine.MainSub)) { targetItems.RemoveAll(it => it.Submarine != Submarine.MainSub); } if (targetItems.Count > 0) { var textId = targetItems[0].Prefab.GetItemNameTextId(); targetItemPrefabName = TextManager.FormatServerMessage(textId) ?? targetItems[0].Prefab.Name; } return(targetItems.Count > 0); }
public override bool Start(Traitor traitor) { if (!base.Start(traitor)) { return(false); } foreach (var item in Item.ItemList) { if (item.Submarine == null || Traitors.All(t => item.Submarine.TeamID != t.Character.TeamID)) { continue; } if (item.Prefab?.Identifier == tag || item.HasTag(tag)) { var connectionPanel = item.GetComponent <ConnectionPanel>(); if (connectionPanel != null) { targetConnectionPanels.Add(connectionPanel); } } } if (targetConnectionPanels.Count > 0) { var textId = targetConnectionPanels[0].Item.Prefab.GetItemNameTextId(); targetItemPrefabName = TextManager.FormatServerMessage(textId) ?? targetConnectionPanels[0].Item.Prefab.Name; } return(targetConnectionPanels.Count > 0); }
public override bool Start(Traitor traitor) { if (!base.Start(traitor)) { return(false); } var startTime = Timing.TotalTime; foreach (Character character in Character.CharacterList) { if (character.Submarine == null || Traitors.All(t => character.Submarine.TeamID != t.Character.TeamID) || character.SpawnTime + gracePeriod < startTime) { continue; } if (character.SpeciesName.ToLowerInvariant() == speciesId) { targetCharacter = character; break; } } targetCharacterName = TextManager.FormatServerMessage($"character.{speciesId}").ToLowerInvariant(); return(targetCharacter != null); }
public override bool Start(Traitor traitor) { if (!base.Start(traitor)) { return(false); } if (targetPrefab != null) { return(true); } targetPrefab = FindItemPrefab(identifier); if (targetPrefab == null) { return(false); } var targetPrefabTextId = targetPrefab.GetItemNameTextId(); targetNameText = targetPrefabTextId != null?TextManager.FormatServerMessage(targetPrefabTextId) : targetPrefab.Name; targetContainer = FindTargetContainer(Traitors, targetPrefab); if (targetContainer == null) { targetPrefab = null; targetContainer = null; return(false); } var containerPrefabTextId = targetContainer.Prefab.GetItemNameTextId(); targetContainerNameText = containerPrefabTextId != null?TextManager.FormatServerMessage(containerPrefabTextId) : targetContainer.Prefab.Name; var targetHullTextId = targetContainer.CurrentHull?.prefab.GetHullNameTextId(); targetHullNameText = targetHullTextId != null?TextManager.FormatServerMessage(targetHullTextId) : targetContainer?.CurrentHull?.DisplayName ?? ""; if (allowNew && !targetContainer.OwnInventory.IsFull()) { existingItems.Clear(); foreach (var item in targetContainer.OwnInventory.Items) { existingItems.Add(item); } Entity.Spawner.AddToSpawnQueue(targetPrefab, targetContainer.OwnInventory); target = null; } else if (allowExisting) { target = targetContainer.OwnInventory.FindItemByIdentifier(targetPrefab.Identifier); } else { targetPrefab = null; targetContainer = null; return(false); } return(true); }
public override bool Start(Traitor traitor) { if (!base.Start(traitor)) { return(false); } poisonName = TextManager.FormatServerMessage(poisonId) ?? poisonId; Targets = traitor.Mission.FindKillTarget(traitor.Character, Filter, targetCount, targetPercentage); targetWasInfected = new bool[Targets.Count]; return(Targets != null && !Targets.All(t => t.IsDead)); }
private int CountMatchingItems() { int result = 0; foreach (var item in Item.ItemList) { if (!matchInventory && Traitors.All(traitor => item.FindParentInventory(inventory => inventory.Owner is Character && inventory.Owner != traitor.Character) != null)) { continue; } if (item.Submarine == null) { //items outside the sub don't count as destroyed if they're still in the traitor's inventory bool carriedByTraitor = Traitors.Any(traitor => item.IsOwnedBy(traitor.Character)); if (!carriedByTraitor) { continue; } } else { if (Traitors.All(traitor => item.Submarine.TeamID != traitor.Character.TeamID)) { continue; } } if (item.Condition <= 0.0f) { continue; } var identifierMatches = matchIdentifier && item.prefab.Identifier == tag; if (identifierMatches && tagPrefabName == null) { var textId = item.Prefab.GetItemNameTextId(); tagPrefabName = textId != null?TextManager.FormatServerMessage(textId) : item.Prefab.Name; } if (identifierMatches || (matchTag && item.HasTag(tag))) { ++result; } } // Quick fix if (tagPrefabName == null && matchIdentifier) { tagPrefabName = TextManager.FormatServerMessage($"entityname.{tag}"); } return(result); }
public GoalUnwiring(string tag, string targetConnectionName, string targetConnectionDisplayTag) : base() { this.tag = tag; this.targetConnectionName = targetConnectionName; if (targetConnectionDisplayTag != string.Empty) { targetConnectionDisplayName = TextManager.FormatServerMessage(targetConnectionDisplayTag); InfoTextId = "TraitorGoalUnwireInfo"; } else { InfoTextId = "TraitorGoalUnwireAllInfo"; } }
public override bool Start(Traitor traitor) { if (!base.Start(traitor)) { return(false); } catalystItemName = TextManager.FormatServerMessage($"entityname.{catalystItemIdentifier}"); activeEntity = null; activeEntityIndex = 0; switch (entityTypes[activeEntityIndex]) { case EntityTypes.Character: foreach (Character character in Character.CharacterList) { if (character.Submarine == null || Traitors.All(t => character.Submarine.TeamID != t.Character.TeamID)) { continue; } if (character.SpeciesName.ToLowerInvariant() == entities[activeEntityIndex].ToLowerInvariant()) { activeEntity = character; break; } } break; case EntityTypes.Item: foreach (Item item in Item.ItemList) { if (item.Submarine == null || Traitors.All(t => item.Submarine.TeamID != t.Character.TeamID)) { continue; } if (item.prefab.Identifier.ToLowerInvariant() == entities[0].ToLowerInvariant()) { activeEntity = item; break; } } break; } graceTimer = 0.0f; return(activeEntity != null); }
public void Greet(GameServer server, string codeWords, string codeResponse, MessageSender messageSender) { string greetingMessage = TextManager.FormatServerMessage(Mission.StartText, new string[] { "[codewords]", "[coderesponse]" }, new string[] { codeWords, codeResponse }); messageSender(greetingMessage); Client traitorClient = server.ConnectedClients.Find(c => c.Character == Character); Client ownerClient = server.ConnectedClients.Find(c => c.Connection == server.OwnerConnection); if (traitorClient != ownerClient && ownerClient != null && ownerClient.Character == null) { GameMain.Server.SendTraitorMessage(ownerClient, CurrentObjective.StartMessageServerText, Mission?.Identifier, TraitorMessageType.ServerMessageBox); } }
private int CountMatchingItems() { int result = 0; foreach (var item in Item.ItemList) { if (!matchInventory && Traitors.All(traitor => item.FindParentInventory(inventory => inventory.Owner is Character && inventory.Owner != traitor.Character) != null)) { continue; } if (item.Submarine == null) { if (!(item.ParentInventory?.Owner is Character)) { continue; } } else { if (Traitors.All(traitor => item.Submarine.TeamID != traitor.Character.TeamID)) { continue; } } if (item.Condition <= 0.0f) { continue; } var identifierMatches = matchIdentifier && item.prefab.Identifier == tag; if (identifierMatches && tagPrefabName == null) { var textId = item.Prefab.GetItemNameTextId(); tagPrefabName = textId != null?TextManager.FormatServerMessage(textId) : item.Prefab.Name; } if (identifierMatches || (matchTag && item.HasTag(tag))) { ++result; } } return(result); }
public string GetTargetNames(List <Character> targets) { string names = string.Empty; for (int i = 0; i < targets.Count; i++) { names += targets[i].Name; if (i < targets.Count - 1) { names += ", "; } } if (names.Length > 0) { return(names); } else { return(TextManager.FormatServerMessage("unknown")); } }
public override bool Start(Traitor traitor) { if (!base.Start(traitor)) { return(false); } foreach (var item in Item.ItemList) { if (item.Submarine == null || item.Submarine.TeamID != Traitor.Character.TeamID) { continue; } if (item.Condition > conditionThreshold && (item.Prefab?.Identifier == tag || item.HasTag(tag))) { targetItems.Add(item); } } if (targetItems.Count > 0) { var textId = targetItems[0].Prefab.GetItemNameTextId(); targetItemPrefabName = TextManager.FormatServerMessage(textId) ?? targetItems[0].Prefab.Name; } return(targetItems.Count > 0); }
public void ServerRead(IReadMessage msg, Client sender) { UInt16 currentLocIndex = msg.ReadUInt16(); UInt16 selectedLocIndex = msg.ReadUInt16(); byte selectedMissionCount = msg.ReadByte(); List <int> selectedMissionIndices = new List <int>(); for (int i = 0; i < selectedMissionCount; i++) { selectedMissionIndices.Add(msg.ReadByte()); } bool purchasedHullRepairs = msg.ReadBoolean(); bool purchasedItemRepairs = msg.ReadBoolean(); bool purchasedLostShuttles = msg.ReadBoolean(); UInt16 buyCrateItemCount = msg.ReadUInt16(); List <PurchasedItem> buyCrateItems = new List <PurchasedItem>(); for (int i = 0; i < buyCrateItemCount; i++) { string itemPrefabIdentifier = msg.ReadString(); int itemQuantity = msg.ReadRangedInteger(0, CargoManager.MaxQuantity); buyCrateItems.Add(new PurchasedItem(ItemPrefab.Prefabs[itemPrefabIdentifier], itemQuantity)); } UInt16 purchasedItemCount = msg.ReadUInt16(); List <PurchasedItem> purchasedItems = new List <PurchasedItem>(); for (int i = 0; i < purchasedItemCount; i++) { string itemPrefabIdentifier = msg.ReadString(); int itemQuantity = msg.ReadRangedInteger(0, CargoManager.MaxQuantity); purchasedItems.Add(new PurchasedItem(ItemPrefab.Prefabs[itemPrefabIdentifier], itemQuantity)); } UInt16 soldItemCount = msg.ReadUInt16(); List <SoldItem> soldItems = new List <SoldItem>(); for (int i = 0; i < soldItemCount; i++) { string itemPrefabIdentifier = msg.ReadString(); UInt16 id = msg.ReadUInt16(); bool removed = msg.ReadBoolean(); byte sellerId = msg.ReadByte(); soldItems.Add(new SoldItem(ItemPrefab.Prefabs[itemPrefabIdentifier], id, removed, sellerId)); } ushort purchasedUpgradeCount = msg.ReadUInt16(); List <PurchasedUpgrade> purchasedUpgrades = new List <PurchasedUpgrade>(); for (int i = 0; i < purchasedUpgradeCount; i++) { string upgradeIdentifier = msg.ReadString(); UpgradePrefab prefab = UpgradePrefab.Find(upgradeIdentifier); string categoryIdentifier = msg.ReadString(); UpgradeCategory category = UpgradeCategory.Find(categoryIdentifier); int upgradeLevel = msg.ReadByte(); if (category == null || prefab == null) { continue; } purchasedUpgrades.Add(new PurchasedUpgrade(prefab, category, upgradeLevel)); } ushort purchasedItemSwapCount = msg.ReadUInt16(); List <PurchasedItemSwap> purchasedItemSwaps = new List <PurchasedItemSwap>(); for (int i = 0; i < purchasedItemSwapCount; i++) { UInt16 itemToRemoveID = msg.ReadUInt16(); Item itemToRemove = Entity.FindEntityByID(itemToRemoveID) as Item; string itemToInstallIdentifier = msg.ReadString(); ItemPrefab itemToInstall = string.IsNullOrEmpty(itemToInstallIdentifier) ? null : ItemPrefab.Find(string.Empty, itemToInstallIdentifier); if (itemToRemove == null) { continue; } purchasedItemSwaps.Add(new PurchasedItemSwap(itemToRemove, itemToInstall)); } if (!AllowedToManageCampaign(sender)) { DebugConsole.ThrowError("Client \"" + sender.Name + "\" does not have a permission to manage the campaign"); return; } Location location = Map.CurrentLocation; int hullRepairCost = location?.GetAdjustedMechanicalCost(HullRepairCost) ?? HullRepairCost; int itemRepairCost = location?.GetAdjustedMechanicalCost(ItemRepairCost) ?? ItemRepairCost; int shuttleRetrieveCost = location?.GetAdjustedMechanicalCost(ShuttleReplaceCost) ?? ShuttleReplaceCost; if (purchasedHullRepairs != this.PurchasedHullRepairs) { if (purchasedHullRepairs && Money >= hullRepairCost) { this.PurchasedHullRepairs = true; Money -= hullRepairCost; } else if (!purchasedHullRepairs) { this.PurchasedHullRepairs = false; Money += hullRepairCost; } } if (purchasedItemRepairs != this.PurchasedItemRepairs) { if (purchasedItemRepairs && Money >= itemRepairCost) { this.PurchasedItemRepairs = true; Money -= itemRepairCost; } else if (!purchasedItemRepairs) { this.PurchasedItemRepairs = false; Money += itemRepairCost; } } if (purchasedLostShuttles != this.PurchasedLostShuttles) { if (GameMain.GameSession?.SubmarineInfo != null && GameMain.GameSession.SubmarineInfo.LeftBehindSubDockingPortOccupied) { GameMain.Server.SendDirectChatMessage(TextManager.FormatServerMessage("ReplaceShuttleDockingPortOccupied"), sender, ChatMessageType.MessageBox); } else if (purchasedLostShuttles && Money >= shuttleRetrieveCost) { this.PurchasedLostShuttles = true; Money -= shuttleRetrieveCost; } else if (!purchasedItemRepairs) { this.PurchasedLostShuttles = false; Money += shuttleRetrieveCost; } } if (currentLocIndex < Map.Locations.Count && Map.AllowDebugTeleport) { Map.SetLocation(currentLocIndex); } Map.SelectLocation(selectedLocIndex == UInt16.MaxValue ? -1 : selectedLocIndex); if (Map.SelectedLocation == null) { Map.SelectRandomLocation(preferUndiscovered: true); } if (Map.SelectedConnection != null) { Map.SelectMission(selectedMissionIndices); } CheckTooManyMissions(Map.CurrentLocation, sender); List <PurchasedItem> currentBuyCrateItems = new List <PurchasedItem>(CargoManager.ItemsInBuyCrate); currentBuyCrateItems.ForEach(i => CargoManager.ModifyItemQuantityInBuyCrate(i.ItemPrefab, -i.Quantity)); buyCrateItems.ForEach(i => CargoManager.ModifyItemQuantityInBuyCrate(i.ItemPrefab, i.Quantity)); CargoManager.SellBackPurchasedItems(new List <PurchasedItem>(CargoManager.PurchasedItems)); CargoManager.PurchaseItems(purchasedItems, false); // for some reason CargoManager.SoldItem is never cleared by the server, I've added a check to SellItems that ignores all // sold items that are removed so they should be discarded on the next message CargoManager.BuyBackSoldItems(new List <SoldItem>(CargoManager.SoldItems)); CargoManager.SellItems(soldItems); foreach (var(prefab, category, _) in purchasedUpgrades) { UpgradeManager.PurchaseUpgrade(prefab, category); // unstable logging int price = prefab.Price.GetBuyprice(UpgradeManager.GetUpgradeLevel(prefab, category), Map?.CurrentLocation); int level = UpgradeManager.GetUpgradeLevel(prefab, category); GameServer.Log($"SERVER: Purchased level {level} {category.Identifier}.{prefab.Identifier} for {price}", ServerLog.MessageType.ServerMessage); } foreach (var purchasedItemSwap in purchasedItemSwaps) { if (purchasedItemSwap.ItemToInstall == null) { UpgradeManager.CancelItemSwap(purchasedItemSwap.ItemToRemove); } else { UpgradeManager.PurchaseItemSwap(purchasedItemSwap.ItemToRemove, purchasedItemSwap.ItemToInstall); } } foreach (Item item in Item.ItemList) { if (item.PendingItemSwap != null && !purchasedItemSwaps.Any(it => it.ItemToRemove == item)) { UpgradeManager.CancelItemSwap(item); item.PendingItemSwap = null; } } }
protected internal override string GetInfoText(Traitor traitor, string textId, IEnumerable <string> keys, IEnumerable <string> values) { var infoText = base.GetInfoText(traitor, textId, keys, values); return(!string.IsNullOrEmpty(durationInfoTextId) && !infoText.Contains("[duration]") ? TextManager.FormatServerMessage(durationInfoTextId, new[] { "[infotext]", "[duration]" }, new[] { infoText, requiredDuration.ToString() }) : infoText); }
public virtual IEnumerable <string> StatusTextValues(Traitor traitor) => new [] { InfoText(traitor), TextManager.FormatServerMessage(StatusValueTextId) };
protected internal override string GetInfoText(Traitor traitor, string textId, IEnumerable <string> keys, IEnumerable <string> values) { var infoText = base.GetInfoText(traitor, textId, keys, values); return(!string.IsNullOrEmpty(optionalInfoTextId) ? TextManager.FormatServerMessage(optionalInfoTextId, new[] { "[infotext]" }, new[] { infoText }) : infoText); }
public void ServerRead(IReadMessage msg, Client sender) { UInt16 selectedLocIndex = msg.ReadUInt16(); byte selectedMissionIndex = msg.ReadByte(); bool purchasedHullRepairs = msg.ReadBoolean(); bool purchasedItemRepairs = msg.ReadBoolean(); bool purchasedLostShuttles = msg.ReadBoolean(); UInt16 purchasedItemCount = msg.ReadUInt16(); List <PurchasedItem> purchasedItems = new List <PurchasedItem>(); for (int i = 0; i < purchasedItemCount; i++) { string itemPrefabIdentifier = msg.ReadString(); int itemQuantity = msg.ReadRangedInteger(0, CargoManager.MaxQuantity); purchasedItems.Add(new PurchasedItem(ItemPrefab.Prefabs[itemPrefabIdentifier], itemQuantity)); } if (!sender.HasPermission(ClientPermissions.ManageCampaign)) { DebugConsole.ThrowError("Client \"" + sender.Name + "\" does not have a permission to manage the campaign"); return; } if (purchasedHullRepairs != this.PurchasedHullRepairs) { if (purchasedHullRepairs && Money >= HullRepairCost) { this.PurchasedHullRepairs = true; Money -= HullRepairCost; } else if (!purchasedHullRepairs) { this.PurchasedHullRepairs = false; Money += HullRepairCost; } } if (purchasedItemRepairs != this.PurchasedItemRepairs) { if (purchasedItemRepairs && Money >= ItemRepairCost) { this.PurchasedItemRepairs = true; Money -= ItemRepairCost; } else if (!purchasedItemRepairs) { this.PurchasedItemRepairs = false; Money += ItemRepairCost; } } if (purchasedLostShuttles != this.PurchasedLostShuttles) { if (GameMain.GameSession?.SubmarineInfo != null && GameMain.GameSession.SubmarineInfo.LeftBehindSubDockingPortOccupied) { GameMain.Server.SendDirectChatMessage(TextManager.FormatServerMessage("ReplaceShuttleDockingPortOccupied"), sender, ChatMessageType.MessageBox); } else if (purchasedLostShuttles && Money >= ShuttleReplaceCost) { this.PurchasedLostShuttles = true; Money -= ShuttleReplaceCost; } else if (!purchasedItemRepairs) { this.PurchasedLostShuttles = false; Money += ShuttleReplaceCost; } } Map.SelectLocation(selectedLocIndex == UInt16.MaxValue ? -1 : selectedLocIndex); if (Map.SelectedLocation == null) { Map.SelectRandomLocation(preferUndiscovered: true); } if (Map.SelectedConnection != null) { Map.SelectMission(selectedMissionIndex); } List <PurchasedItem> currentItems = new List <PurchasedItem>(CargoManager.PurchasedItems); foreach (PurchasedItem pi in currentItems) { CargoManager.SellItem(pi, pi.Quantity); } foreach (PurchasedItem pi in purchasedItems) { CargoManager.PurchaseItem(pi.ItemPrefab, pi.Quantity); } }
public override bool Start(Traitor traitor) { if (!base.Start(traitor)) { return(false); } if (targetPrefab != null) { return(true); } string targetPrefabTextId; if (percentage > 0f) { spawnAmount = (int)Math.Floor(Character.CharacterList.FindAll(c => c.TeamID == traitor.Character.TeamID && c != traitor.Character && !c.IsDead && (filter == null || filter(c))).Count *percentage); } if (spawnAmount > 1 && allowNew) { containedPrefab = FindItemPrefab(identifier); targetPrefab = FindItemPrefab(itemContainerId); if (containedPrefab == null || targetPrefab == null) { return(false); } targetPrefabTextId = containedPrefab.GetItemNameTextId(); } else { spawnAmount = 1; containedPrefab = null; targetPrefab = FindItemPrefab(identifier); if (targetPrefab == null) { return(false); } targetPrefabTextId = targetPrefab.GetItemNameTextId(); } targetNameText = targetPrefabTextId != null?TextManager.FormatServerMessage(targetPrefabTextId) : targetPrefab.Name; targetContainer = FindTargetContainer(Traitors, targetPrefab); if (targetContainer == null) { targetPrefab = null; targetContainer = null; return(false); } var containerPrefabTextId = targetContainer.Prefab.GetItemNameTextId(); targetContainerNameText = containerPrefabTextId != null?TextManager.FormatServerMessage(containerPrefabTextId) : targetContainer.Prefab.Name; var targetHullTextId = targetContainer.CurrentHull?.prefab.GetHullNameTextId(); targetHullNameText = targetHullTextId != null?TextManager.FormatServerMessage(targetHullTextId) : targetContainer?.CurrentHull?.DisplayName ?? ""; if (allowNew && !targetContainer.OwnInventory.IsFull()) { existingItems.Clear(); foreach (var item in targetContainer.OwnInventory.AllItems.Distinct()) { existingItems.Add(item); } Entity.Spawner.AddToSpawnQueue(targetPrefab, targetContainer.OwnInventory); target = null; } else if (allowExisting) { target = targetContainer.OwnInventory.FindItemByIdentifier(targetPrefab.Identifier); } else { targetPrefab = null; targetContainer = null; return(false); } return(true); }
protected internal override string GetInfoText(Traitor traitor, string textId, IEnumerable <string> keys, IEnumerable <string> values) { var infoText = base.GetInfoText(traitor, textId, keys, values); return(!string.IsNullOrEmpty(timeLimitInfoTextId) ? TextManager.FormatServerMessage(timeLimitInfoTextId, new[] { "[infotext]", "[timelimit]" }, new[] { infoText, $"{TimeSpan.FromSeconds(timeLimit):g}" }) : infoText); }