private EntityType GetHitterType(DamageRecord record) { EntityType hitBy = EntityType.Other; if (record.Hit.HaveAttacker()) { GameObject attacker = ZNetScene.instance.FindInstance(record.Hit.m_attacker); var attackerCharacter = ComponentCache.GetComponent <Character>(attacker); if (attackerCharacter is not null) { if (attackerCharacter.IsPlayer()) { hitBy = EntityType.Player; } else { hitBy = EntityType.Creature; } } } return(hitBy); }
public void Modify(DropContext context) { CharacterDropModConfigEpicLoot config; if (context.Extended.Config.TryGet(CharacterDropModConfigEpicLoot.ModName, out Config cfg) && cfg is CharacterDropModConfigEpicLoot modConfig) { config = modConfig; } else { return; } #if DEBUG Log.LogDebug("Adding magic modifiers."); #endif if (InitializeMagicItem is null) { #if DEBUG Log.LogDebug("Couldn't find LootRoller.InitializeMagicItem."); #endif return; } var itemDrop = ComponentCache.GetComponent <ItemDrop>(context.Item); if (EpicLoot.EpicLoot.CanBeMagicItem(itemDrop.m_itemData)) { var extendedItemData = new ExtendedItemData(itemDrop.m_itemData); var rarity = RollRarity(config); if (rarity is Rarity.None) { return; } if (rarity is Rarity.Unique) { MakeUnique(itemDrop, extendedItemData, modConfig); } else { //Make magic. var epicLootRarity = RarityToItemRarity(rarity); if (epicLootRarity is not null) { MakeMagic(epicLootRarity.Value, itemDrop, extendedItemData, context.Pos); } } } }
void Start() { cc = new ComponentCache(gameObject , ComponentCache.LogMessageLevel.all); Debug.LogWarning("Test Cache"); cc.GetComponent<AudioSource>(); cc.GetComponent<AudioSource>(); cc.DestroyComponent<AudioSource>(); Debug.LogWarning("Add component test"); asrc1 = gameObject.AddComponent<AudioSource>(); asrc1.mute = true; AudioSource testAs = cc.GetComponent<AudioSource>(); if (testAs != asrc1) Debug.LogError("Retrieved component not the same?"); testAs = cc.GetComponent<AudioSource>(); if (testAs != asrc1) Debug.LogError("Retrieved component not the same?"); Debug.LogWarning("Adding second component"); AudioSource asrc2 = gameObject.AddComponent<AudioSource>(); Debug.LogWarning("Destroying first component"); cc.DestroyComponent(asrc1); cc.GetComponent<AudioSource>(); cc.GetComponent<AudioSource>(); Assert.IsNull(asrc1); Assert.IsNotNull(asrc2); }
public void Modify(DropContext context) { if (context?.Item is null) { return; } if (context?.Extended?.Config?.SetQualityLevel <= 0) { return; } var itemDrop = ComponentCache.GetComponent <ItemDrop>(context.Item); Log.LogTrace($"Setting level of item '{context.Item.name}' to {context.Extended.Config.SetQualityLevel.Value}"); itemDrop.m_itemData.m_quality = context.Extended.Config.SetQualityLevel; }
public void Modify(DropContext context) { if (context?.Item is null) { return; } if (context?.Extended?.Config?.SetDurability < 0) { return; } var itemDrop = ComponentCache.GetComponent <ItemDrop>(context.Item); Log.LogTrace($"Setting durability of item '{context.Item.name}' to {context.Extended.Config.SetDurability.Value}"); itemDrop.m_itemData.m_durability = context.Extended.Config.SetDurability; }
public bool IsValid(Character character, CharacterDropItemConfiguration config) { if (character is null) { #if DEBUG Log.LogTrace("[ConditionKilledByEntityType] No character found."); #endif return(true); } if (string.IsNullOrWhiteSpace(config.ConditionKilledByEntityType.Value)) { return(true); } var requiredEntityTypes = ConvertToEnum(config.ConditionKilledByEntityType.Value.SplitByComma()); if (requiredEntityTypes.Count == 0) { #if DEBUG Log.LogTrace("[ConditionKilledByEntityType] No valid requirements found."); #endif return(true); } var lastHit = RecordLastHit.GetLastHit(character); if (lastHit is null) { #if DEBUG Log.LogTrace($"{nameof(config.ConditionKilledByDamageType)}: Disabling drop {config.SectionKey} due to not finding any last hit data."); #endif return(false); } EntityType killedBy = EntityType.Other; if (lastHit.Hit.HaveAttacker()) { GameObject attacker = ZNetScene.instance.FindInstance(lastHit.Hit.m_attacker); var attackerCharacter = ComponentCache.GetComponent <Character>(attacker); if (attackerCharacter is not null) { if (attackerCharacter.IsPlayer()) { killedBy = EntityType.Player; } else { killedBy = EntityType.Creature; } } } #if DEBUG Log.LogTrace($"[ConditionKilledByEntityType] Killed by '{killedBy}'"); #endif return(requiredEntityTypes.Any(x => x == killedBy)); }
private static int AfterSpawnedItem(GameObject item, List <KeyValuePair <GameObject, int> > drops, int index) { var resultIndex = index; try { var count = LoopCounter.GetCount(drops) - 1; int itemIndex = GetIndex(drops, count); #if DEBUG //Log.LogDebug($"[AfterSpawnedItem] Count: {count}, Index: {itemIndex}"); #endif if (itemIndex >= drops.Count) { #if DEBUG // Log.LogWarning($"Ups. Attempting to access drop index {itemIndex} in drop list with count {drops.Count}"); #endif return(resultIndex); } var drop = drops[itemIndex]; bool shouldStack = false; // Check if we should be stacking the item if (drop.Value > 1) { if (ConfigurationManager.GeneralConfig.AlwaysAutoStack) { shouldStack = true; } else { var extendedData = TempDropListCache.GetDrop(drops, itemIndex); if (extendedData is not null && extendedData.Config.SetAutoStack) { shouldStack = true; } } } if (shouldStack) { var maxStack = GetMaxStackSize(drop.Key); var stackSize = Math.Min(maxStack, drop.Value - index); if (stackSize > 1) { // Apply stack to item, and skip loop equivalently. var itemDrop = ComponentCache.GetComponent <ItemDrop>(item); Log.LogTrace($"Stacking item '{drop.Key.name}' {stackSize} times out of maximum {maxStack}."); itemDrop.SetStack(stackSize); // Deduct 1 from result, since loop will increment on its own, and OnSpawnedItem will have incremented loop too. LoopCounter.Increment(drops, stackSize - 1); resultIndex += stackSize - 1; #if DEBUG //Log.LogTrace($"Setting new loop index: {resultIndex}"); #endif } } } catch (Exception e) { Log.LogError($"Error while attempting to stack item '{item.name}'. Skipping stacking.", e); } return(resultIndex); int GetMaxStackSize(GameObject item) { var itemDrop = ComponentCache.GetComponent <ItemDrop>(item); if (itemDrop.IsNull() || itemDrop.m_itemData?.m_shared is null) { return(-1); } return(itemDrop.m_itemData.m_shared.m_maxStackSize); } }