protected Item FindRandomContainer(ICollection <Traitor> traitors, ItemPrefab targetPrefabCandidate, bool includeNew, bool includeExisting) { List <Item> suitableItems = new List <Item>(); foreach (Item item in Item.ItemList) { if (item.HiddenInGame || item.NonInteractable || item.NonPlayerTeamInteractable) { continue; } if (item.Submarine == null || traitors.All(traitor => item.Submarine.TeamID != traitor.Character.TeamID)) { continue; } if (item.GetComponent <ItemContainer>() != null && allowedContainerIdentifiers.Contains(item.prefab.Identifier)) { if ((includeNew && !item.OwnInventory.IsFull()) || (includeExisting && item.OwnInventory.FindItemByIdentifier(targetPrefabCandidate.Identifier) != null)) { suitableItems.Add(item); } } } if (suitableItems.Count == 0) { return(null); } return(suitableItems[TraitorManager.RandomInt(suitableItems.Count)]); }
private static bool SpawnItem(ItemPrefab itemPrefab, List <ItemContainer> containers, KeyValuePair <ItemContainer, PreferredContainer> validContainer) { bool success = false; if (Rand.Value() > validContainer.Value.SpawnProbability) { return(false); } // Don't add dangerously reactive materials in thalamus wrecks if (validContainer.Key.Item.Submarine.WreckAI != null && itemPrefab.Tags.Contains("explodesinwater")) { return(false); } int amount = Rand.Range(validContainer.Value.MinAmount, validContainer.Value.MaxAmount + 1); for (int i = 0; i < amount; i++) { if (validContainer.Key.Inventory.IsFull()) { containers.Remove(validContainer.Key); break; } var item = new Item(itemPrefab, validContainer.Key.Item.Position, validContainer.Key.Item.Submarine); spawnedItems.Add(item); #if SERVER Entity.Spawner.CreateNetworkEvent(item, remove: false); #endif validContainer.Key.Inventory.TryPutItem(item, null); containers.AddRange(item.GetComponents <ItemContainer>()); success = true; } return(success); }
public SoldItem(ItemPrefab itemPrefab, ushort id, bool removed, byte sellerId) { ItemPrefab = itemPrefab; ID = id; Removed = removed; SellerID = sellerId; }
private bool BuyItems(GUIButton button, object obj) { int cost = selectedItemCost; if (CrewManager.Money < cost) { return(false); } CrewManager.Money -= cost; for (int i = selectedItemList.children.Count - 1; i >= 0; i--) { GUIComponent child = selectedItemList.children[i]; ItemPrefab ip = child.UserData as ItemPrefab; if (ip == null) { continue; } gameMode.CargoManager.AddItem(ip); selectedItemList.RemoveChild(child); } return(false); }
public SalvageMission(MissionPrefab prefab, Location[] locations) : base(prefab, locations) { if (prefab.ConfigElement.Attribute("itemname") != null) { DebugConsole.ThrowError("Error in SalvageMission - use item identifier instead of the name of the item."); string itemName = prefab.ConfigElement.GetAttributeString("itemname", ""); itemPrefab = MapEntityPrefab.Find(itemName) as ItemPrefab; if (itemPrefab == null) { DebugConsole.ThrowError("Error in SalvageMission: couldn't find an item prefab with the name " + itemName); } } else { string itemIdentifier = prefab.ConfigElement.GetAttributeString("itemidentifier", ""); itemPrefab = MapEntityPrefab.Find(null, itemIdentifier) as ItemPrefab; if (itemPrefab == null) { DebugConsole.ThrowError("Error in SalvageMission - couldn't find an item prefab with the identifier " + itemIdentifier); } } string spawnPositionTypeStr = prefab.ConfigElement.GetAttributeString("spawntype", ""); if (string.IsNullOrWhiteSpace(spawnPositionTypeStr) || !Enum.TryParse(spawnPositionTypeStr, true, out spawnPositionType)) { spawnPositionType = Level.PositionType.Cave | Level.PositionType.Ruin; } }
protected Item FindTargetContainer(ICollection <Traitor> traitors, ItemPrefab targetPrefabCandidate) { Item result = null; if (preferNew) { result = FindRandomContainer(traitors, targetPrefabCandidate, true, false); } if (result == null) { result = FindRandomContainer(traitors, targetPrefabCandidate, allowNew, allowExisting); } if (result == null) { return(null); } if (allowNew && !result.OwnInventory.IsFull()) { return(result); } if (allowExisting && result.OwnInventory.FindItemByIdentifier(targetPrefabCandidate.Identifier) != null) { return(result); } return(null); }
public ItemSpawnInfo(ItemPrefab prefab, Vector2 position, Submarine sub, float?condition = null) { Prefab = prefab ?? throw new ArgumentException("ItemSpawnInfo prefab cannot be null."); Position = position; Submarine = sub; Condition = condition ?? prefab.Health; }
public ItemSpawnInfo(ItemPrefab prefab, Vector2 position, Submarine sub, float?condition = null) { Prefab = prefab; Position = position; Submarine = sub; Condition = condition ?? prefab.Health; }
public ItemSpawnInfo(ItemPrefab prefab, Inventory inventory, Action <Item> onSpawned, float?condition = null) { Prefab = prefab ?? throw new ArgumentException("ItemSpawnInfo prefab cannot be null."); Inventory = inventory; Condition = condition ?? prefab.Health; this.onSpawned = onSpawned; }
public void PurchaseItem(ItemPrefab item) { campaign.Money -= item.Price; purchasedItems.Add(item); OnItemsChanged?.Invoke(); }
public void AutoPurchaseExisting() { if (GameMain.Client != null) { return; } var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode); int totalitems = 0; int totalcost = 0; foreach (CampaignPurchase cp in GameMain.NilMod.ServerExistingCampaignAutobuy) { if (!cp.isvalid) { continue; } ItemPrefab prefab = (ItemPrefab)ItemPrefab.Find(cp.itemprefab); for (int i = 0; i < cp.count; i++) { if (campaign.Money >= prefab.Price) { totalitems += 1; totalcost += prefab.Price; campaign.CargoManager.PurchaseItem(prefab); } } } GameMain.Server.ServerLog.WriteLine("AUTOBUY: Added " + totalitems + " Items costing " + totalcost + " money.", ServerLog.MessageType.ServerMessage); LastUpdateID++; }
public ItemSpawnInfo(ItemPrefab prefab, Vector2 worldPosition, Action <Item> onSpawned, float?condition = null) { Prefab = prefab ?? throw new ArgumentException("ItemSpawnInfo prefab cannot be null."); Position = worldPosition; Condition = condition ?? prefab.Health; this.onSpawned = onSpawned; }
private void InitializeJobItem(Character character, WayPoint spawnPoint, XElement itemElement, Item parentItem = null) { string itemName = itemElement.GetAttributeString("name", ""); ItemPrefab itemPrefab = MapEntityPrefab.Find(itemName) as ItemPrefab; if (itemPrefab == null) { DebugConsole.ThrowError("Tried to spawn \"" + Name + "\" with the item \"" + itemName + "\". Matching item prefab not found."); return; } Item item = new Item(itemPrefab, character.Position, null); if (GameMain.Server != null && Entity.Spawner != null) { Entity.Spawner.CreateNetworkEvent(item, false); } if (itemElement.GetAttributeBool("equip", false)) { List <InvSlotType> allowedSlots = new List <InvSlotType>(item.AllowedSlots); allowedSlots.Remove(InvSlotType.Any); character.Inventory.TryPutItem(item, null, allowedSlots); } else { character.Inventory.TryPutItem(item, null, item.AllowedSlots); } if (item.Prefab.NameMatches("ID Card") && spawnPoint != null) { foreach (string s in spawnPoint.IdCardTags) { item.AddTag(s); } item.AddTag("name:" + character.Name); item.AddTag("job:" + Name); if (!string.IsNullOrWhiteSpace(spawnPoint.IdCardDesc)) { item.Description = spawnPoint.IdCardDesc; } } foreach (WifiComponent wifiComponent in item.GetComponents <WifiComponent>()) { wifiComponent.TeamID = character.TeamID; } if (parentItem != null) { parentItem.Combine(item); } foreach (XElement childItemElement in itemElement.Elements()) { InitializeJobItem(character, spawnPoint, childItemElement, item); } }
public void Init() { CharacterPrefab.LoadAll(); MissionPrefab.Init(); TraitorMissionPrefab.Init(); MapEntityPrefab.Init(); MapGenerationParams.Init(); LevelGenerationParams.LoadPresets(); ScriptedEventSet.LoadPrefabs(); Order.Init(); EventManagerSettings.Init(); AfflictionPrefab.LoadAll(GetFilesOfType(ContentType.Afflictions)); SkillSettings.Load(GetFilesOfType(ContentType.SkillSettings)); StructurePrefab.LoadAll(GetFilesOfType(ContentType.Structure)); ItemPrefab.LoadAll(GetFilesOfType(ContentType.Item)); JobPrefab.LoadAll(GetFilesOfType(ContentType.Jobs)); CorpsePrefab.LoadAll(GetFilesOfType(ContentType.Corpses)); NPCConversation.LoadAll(GetFilesOfType(ContentType.NPCConversations)); ItemAssemblyPrefab.LoadAll(); LevelObjectPrefab.LoadAll(); GameModePreset.Init(); LocationType.Init(); SubmarineInfo.RefreshSavedSubs(); Screen.SelectNull(); NetLobbyScreen = new NetLobbyScreen(); CheckContentPackage(); }
protected Vector2?GetCargoSpawnPosition(ItemPrefab itemPrefab, out Submarine cargoRoomSub) { cargoRoomSub = null; WayPoint cargoSpawnPos = WayPoint.GetRandom(SpawnType.Cargo, null, Submarine.MainSub, useSyncedRand: true); if (cargoSpawnPos == null) { DebugConsole.ThrowError($"Couldn't spawn items for mission \"{Name}\": no waypoints marked as Cargo were found"); return(null); } var cargoRoom = cargoSpawnPos.CurrentHull; if (cargoRoom == null) { DebugConsole.ThrowError($"Couldn't spawn items for mission \"{Name}\": waypoints marked as Cargo must be placed inside a room"); return(null); } cargoRoomSub = cargoRoom.Submarine; return(new Vector2( cargoSpawnPos.Position.X + Rand.Range(-20.0f, 20.0f, Rand.RandSync.Server), cargoRoom.Rect.Y - cargoRoom.Rect.Height + itemPrefab.Size.Y / 2)); }
public RequiredItem(ItemPrefab itemPrefab, int amount, float minCondition, bool useCondition) { ItemPrefab = itemPrefab; Amount = amount; MinCondition = minCondition; UseCondition = useCondition; }
private static Dictionary <ItemContainer, PreferredContainer> GetValidContainers(PreferredContainer preferredContainer, IEnumerable <ItemContainer> allContainers, Dictionary <ItemContainer, PreferredContainer> validContainers, bool primary) { validContainers.Clear(); foreach (ItemContainer container in allContainers) { if (!container.AutoFill) { continue; } if (primary) { if (!ItemPrefab.IsContainerPreferred(preferredContainer.Primary, container)) { continue; } } else { if (!ItemPrefab.IsContainerPreferred(preferredContainer.Secondary, container)) { continue; } } if (!validContainers.ContainsKey(container)) { validContainers.Add(container, preferredContainer); } } return(validContainers); }
public CharacterInventory(XElement element, Character character) : base(character, element.GetAttributeString("slots", "").Split(',').Count()) { this.character = character; IsEquipped = new bool[capacity]; SlotTypes = new InvSlotType[capacity]; AccessibleWhenAlive = element.GetAttributeBool("accessiblewhenalive", true); string[] slotTypeNames = element.GetAttributeString("slots", "").Split(','); System.Diagnostics.Debug.Assert(slotTypeNames.Length == capacity); for (int i = 0; i < capacity; i++) { InvSlotType parsedSlotType = InvSlotType.Any; slotTypeNames[i] = slotTypeNames[i].Trim(); if (!Enum.TryParse(slotTypeNames[i], out parsedSlotType)) { DebugConsole.ThrowError("Error in the inventory config of \"" + character.SpeciesName + "\" - " + slotTypeNames[i] + " is not a valid inventory slot type."); } SlotTypes[i] = parsedSlotType; switch (SlotTypes[i]) { //case InvSlotType.Head: //case InvSlotType.OuterClothes: case InvSlotType.LeftHand: case InvSlotType.RightHand: hideEmptySlot[i] = true; break; } } InitProjSpecific(element); #if CLIENT //clients don't create items until the server says so if (GameMain.Client != null) { return; } #endif foreach (XElement subElement in element.Elements()) { if (!subElement.Name.ToString().Equals("item", StringComparison.OrdinalIgnoreCase)) { continue; } string itemIdentifier = subElement.GetAttributeString("identifier", ""); ItemPrefab itemPrefab = MapEntityPrefab.Find(null, itemIdentifier) as ItemPrefab; if (itemPrefab == null) { DebugConsole.ThrowError("Error in character inventory \"" + character.SpeciesName + "\" - item \"" + itemIdentifier + "\" not found."); continue; } Entity.Spawner?.AddToSpawnQueue(itemPrefab, this); } }
public bool CanBeApplied(XElement element, UpgradePrefab prefab) { if (string.Equals("Structure", element.Name.ToString(), StringComparison.OrdinalIgnoreCase)) { return(IsWallUpgrade); } string identifier = element.GetAttributeString("identifier", string.Empty); if (string.IsNullOrWhiteSpace(identifier)) { return(false); } ItemPrefab?item = ItemPrefab.Find(null, identifier); if (item == null) { return(false); } string[] disallowedUpgrades = element.GetAttributeStringArray("disallowedupgrades", new string[0]); if (disallowedUpgrades.Any(s => s.Equals(Identifier, StringComparison.OrdinalIgnoreCase) || s.Equals(prefab.Identifier, StringComparison.OrdinalIgnoreCase))) { return(false); } return(item.GetAllowedUpgrades().Contains(Identifier) || ItemTags.Any(tag => item.Tags.Contains(tag) || item.Identifier.Equals(tag, StringComparison.OrdinalIgnoreCase))); }
public void SellItem(ItemPrefab item) { campaign.Money += item.Price; purchasedItems.Remove(item); OnItemsChanged?.Invoke(); }
public void Init() { MissionPrefab.Init(); MapEntityPrefab.Init(); MapGenerationParams.Init(); LevelGenerationParams.LoadPresets(); ScriptedEventSet.LoadPrefabs(); AfflictionPrefab.LoadAll(GetFilesOfType(ContentType.Afflictions)); StructurePrefab.LoadAll(GetFilesOfType(ContentType.Structure)); ItemPrefab.LoadAll(GetFilesOfType(ContentType.Item)); JobPrefab.LoadAll(GetFilesOfType(ContentType.Jobs)); ItemAssemblyPrefab.LoadAll(); NPCConversation.LoadAll(GetFilesOfType(ContentType.NPCConversations)); ItemAssemblyPrefab.LoadAll(); LevelObjectPrefab.LoadAll(); GameModePreset.Init(); LocationType.Init(); Submarine.RefreshSavedSubs(); Screen.SelectNull(); NetLobbyScreen = new NetLobbyScreen(); CheckContentPackage(); }
public virtual int HowManyCanBePut(ItemPrefab itemPrefab, int i) { if (i < 0 || i >= slots.Length) { return(0); } return(slots[i].HowManyCanBePut(itemPrefab)); }
public virtual int HowManyCanBePut(ItemPrefab itemPrefab, int i, float?condition) { if (i < 0 || i >= slots.Length) { return(0); } return(slots[i].HowManyCanBePut(itemPrefab, condition: condition)); }
public virtual bool CanBePut(ItemPrefab itemPrefab, int i) { if (i < 0 || i >= slots.Length) { return(false); } return(slots[i].CanBePut(itemPrefab)); }
public virtual bool CanBePutInSlot(ItemPrefab itemPrefab, int i, float?condition = null) { if (i < 0 || i >= slots.Length) { return(false); } return(slots[i].CanBePut(itemPrefab, condition)); }
public ItemProduction(XElement element) { Items = new List <Item>(); HungerRate = element.GetAttributeFloat("hungerrate", 0.0f); InvHungerRate = element.GetAttributeFloat("invhungerrate", 0.0f); HappinessRate = element.GetAttributeFloat("happinessrate", 0.0f); InvHappinessRate = element.GetAttributeFloat("invhappinessrate", 0.0f); string[] requiredHappinessStr = element.GetAttributeString("requiredhappiness", "0-100").Split('-'); string[] requiredHungerStr = element.GetAttributeString("requiredhunger", "0-100").Split('-'); HappinessRange = new Vector2(0, 100); HungerRange = new Vector2(0, 100); float tempF; if (requiredHappinessStr.Length >= 2) { if (float.TryParse(requiredHappinessStr[0], NumberStyles.Any, CultureInfo.InvariantCulture, out tempF)) { HappinessRange.X = tempF; } if (float.TryParse(requiredHappinessStr[1], NumberStyles.Any, CultureInfo.InvariantCulture, out tempF)) { HappinessRange.Y = tempF; } } if (requiredHungerStr.Length >= 2) { if (float.TryParse(requiredHungerStr[0], NumberStyles.Any, CultureInfo.InvariantCulture, out tempF)) { HungerRange.X = tempF; } if (float.TryParse(requiredHungerStr[1], NumberStyles.Any, CultureInfo.InvariantCulture, out tempF)) { HungerRange.Y = tempF; } } Rate = element.GetAttributeFloat("rate", 0.016f); totalCommonness = 0.0f; foreach (XElement subElement in element.Elements()) { switch (subElement.Name.LocalName.ToLowerInvariant()) { case "item": string identifier = subElement.GetAttributeString("identifier", ""); Item newItemToProduce = new Item { Prefab = string.IsNullOrEmpty(identifier) ? null : ItemPrefab.Find("", subElement.GetAttributeString("identifier", "")), Commonness = subElement.GetAttributeFloat("commonness", 0.0f) }; totalCommonness += newItemToProduce.Commonness; Items.Add(newItemToProduce); break; } } timer = 1.0f; }
private static XElement ParseMedical(ItemPrefab prefab) { XElement?itemMeleeWeapon = prefab.ConfigElement.GetChildElement(nameof(MeleeWeapon)); // affliction, amount, duration List <Tuple <string, float, float> > onSuccessAfflictions = new List <Tuple <string, float, float> >(); List <Tuple <string, float, float> > onFailureAfflictions = new List <Tuple <string, float, float> >(); int medicalRequiredSkill = 0; if (itemMeleeWeapon != null) { List <StatusEffect> statusEffects = new List <StatusEffect>(); foreach (XElement subElement in itemMeleeWeapon.Elements()) { string name = subElement.Name.ToString(); if (name.Equals(nameof(StatusEffect), StringComparison.OrdinalIgnoreCase)) { StatusEffect statusEffect = StatusEffect.Load(subElement, debugIdentifier); if (statusEffect == null || !statusEffect.HasTag("medical")) { continue; } statusEffects.Add(statusEffect); } else if (IsRequiredSkill(subElement, out Skill? skill) && skill != null) { medicalRequiredSkill = (int)skill.Level; } } List <StatusEffect> successEffects = statusEffects.Where(se => se.type == ActionType.OnUse).ToList(); List <StatusEffect> failureEffects = statusEffects.Where(se => se.type == ActionType.OnFailure).ToList(); foreach (StatusEffect statusEffect in successEffects) { float duration = statusEffect.Duration; onSuccessAfflictions.AddRange(statusEffect.ReduceAffliction.Select(pair => Tuple.Create(GetAfflictionName(pair.affliction), -pair.amount, duration))); onSuccessAfflictions.AddRange(statusEffect.Afflictions.Select(affliction => Tuple.Create(affliction.Prefab.Name, affliction.NonClampedStrength, duration))); } foreach (StatusEffect statusEffect in failureEffects) { float duration = statusEffect.Duration; onFailureAfflictions.AddRange(statusEffect.ReduceAffliction.Select(pair => Tuple.Create(GetAfflictionName(pair.affliction), -pair.amount, duration))); onFailureAfflictions.AddRange(statusEffect.Afflictions.Select(affliction => Tuple.Create(affliction.Prefab.Name, affliction.NonClampedStrength, duration))); } } return(new XElement("Medical", new XAttribute("skillamount", medicalRequiredSkill), new XAttribute("successafflictions", FormatArray(onSuccessAfflictions.Select(tpl => tpl.Item1))), new XAttribute("successamounts", FormatArray(onSuccessAfflictions.Select(tpl => FormatFloat(tpl.Item2)))), new XAttribute("successdurations", FormatArray(onSuccessAfflictions.Select(tpl => FormatFloat(tpl.Item3)))), new XAttribute("failureafflictions", FormatArray(onFailureAfflictions.Select(tpl => tpl.Item1))), new XAttribute("failureamounts", FormatArray(onFailureAfflictions.Select(tpl => FormatFloat(tpl.Item2)))), new XAttribute("failuredurations", FormatArray(onFailureAfflictions.Select(tpl => FormatFloat(tpl.Item3)))) )); }
public void AddToSpawnQueue(ItemPrefab itemPrefab, Vector2 position, Submarine sub, float?condition = null) { if (GameMain.Client != null) { return; } spawnQueue.Enqueue(new ItemSpawnInfo(itemPrefab, position, sub, condition)); }
public void AddToSpawnQueue(ItemPrefab itemPrefab, Inventory inventory, float?condition = null) { if (GameMain.Client != null) { return; } spawnQueue.Enqueue(new ItemSpawnInfo(itemPrefab, inventory, condition)); }
public void AddToSpawnQueue(ItemPrefab itemPrefab, Vector2 worldPosition, float?condition = null) { if (GameMain.Client != null) { return; } spawnQueue.Enqueue(new ItemSpawnInfo(itemPrefab, worldPosition, condition)); }