public static bool IsItemRuinable(Item item) { if (item?.active != true || item.maxStack != 1) { return(false); } if (!item.accessory && !item.melee && !item.ranged && !item.magic && !item.summon) { return(false); } if (item.rare == 0 || item.rare == -1 /*|| item.rare == 1*/) { return(false); } var config = RuinedItemsConfig.Instance; string uid = ItemID.GetUniqueKey(item.type); var blacklistedItemUids = config.Get <HashSet <string> >(nameof(config.CannotRuinItems)); if (blacklistedItemUids.Contains(uid)) { return(false); } /*if( asWildRoll ) { * var config = RuinedItemsConfig.Instance; * return config.Get<float>( nameof(config.GeneralRuinRollChance) ) > 0f; * }*/ return(true); }
public bool CreateImpartmentContract(Player player, Item item) { var items = new HashSet <string> { ItemID.GetUniqueKey(item.type) }; return(ImpartmentContractItem.Create(player, player.Center, items) != -1); }
//////////////// public override void Action(CommandCaller caller, string input, string[] args) { var mymod = (IntrinsicsMod)this.mod; if (!mymod.Config.DebugModeCheat) { caller.Reply("Cheat mode not active. See configs.", Color.Red); return; } if (Main.netMode == 1) { LogHelpers.Warn("Not supposed to run on client."); return; } if (Main.netMode == 2 && caller.CommandType != CommandType.Console) { bool hasPriv = UserHelpers.HasBasicServerPrivilege(caller.Player); if (!hasPriv) { caller.Reply("Access denied.", Color.Red); return; } } if (args.Length < 1) { caller.Reply("Insufficient arguments.", Color.Red); return; } string itemName = string.Join(" ", args); int itemId; if (!ItemAttributeHelpers.DisplayNamesToIds.ContainsKey(itemName)) { itemId = ItemID.TypeFromUniqueKey(itemName); if (itemId == 0) { caller.Reply("Invalid item name: " + itemName, Color.Red); return; } } else { itemId = ItemAttributeHelpers.DisplayNamesToIds[itemName]; } var myplayer = TmlHelpers.SafelyGetModPlayer <IntrinsicsPlayer>(Main.LocalPlayer); myplayer.RemoveIntrinsic(ItemID.GetUniqueKey(itemId)); //TODO GetProperUniqueId caller.Reply("Intrinsic removed.", Color.Lime); }
public static bool ApplyIntrinsic(Player player, Item intrinsicItem, bool isEnabled, bool forceApply = false) { bool canApply = forceApply || IntrinsicsLogic.ItemHasIntrinsics(intrinsicItem); if (canApply) { var myplayer = TmlHelpers.SafelyGetModPlayer <IntrinsicsPlayer>(player); myplayer.ApplyIntrinsic(ItemID.GetUniqueKey(intrinsicItem), isEnabled); //TODO GetProperUniqueId } return(canApply); }
public override void RightClick(Item item, Player player) { int newType = -1; if (Array.IndexOf(Summon, item.type) > -1) { newType = mod.ItemType(ItemID.GetUniqueKey(item.type).Replace("Terraria ", string.Empty) + "Summon"); } if (newType != -1) { int num = Item.NewItem(player.getRect(), newType, prefixGiven: item.prefix); if (Main.netMode == NetmodeID.MultiplayerClient) { NetMessage.SendData(MessageID.SyncItem, number: num, number2: 1f); } } }
public IconData(Type type, int id) { this.type = type; this.id = id; switch (type) { case Type.Item: uniqueKey = ItemID.GetUniqueKey(id); animation = Main.itemAnimations[id] as DrawAnimationVertical ?? new DrawAnimationVertical(0, 1); break; case Type.NPC: uniqueKey = NPCID.GetUniqueKey(id); animation = new DrawAnimationVertical(5, Main.npcFrameCount[id]); break; case Type.Projectile: uniqueKey = ProjectileID.GetUniqueKey(id); animation = new DrawAnimationVertical(5, Main.projFrames[id]); break; } }
public ItemDefinition(int type) : base(ItemID.GetUniqueKey(type)) { }
//////////////// public override void Action(CommandCaller caller, string input, string[] args) { var mymod = (IntrinsicsMod)this.mod; if (!mymod.Config.DebugModeCheat) { caller.Reply("Cheat mode not active. See configs.", Color.Red); return; } if (Main.netMode == 1) { LogHelpers.Warn("Not supposed to run on client."); return; } if (Main.netMode == 2 && caller.CommandType != CommandType.Console) { bool hasPriv = UserHelpers.HasBasicServerPrivilege(caller.Player); if (!hasPriv) { caller.Reply("Access denied.", Color.Red); return; } } if (args.Length < 1) { caller.Reply("Insufficient arguments.", Color.Red); return; } if (args[0].Length == 0 || args[0][0] != '\"') { caller.Reply("Invalid first item name: " + args[0], Color.Red); return; } IList <Item> items = new List <Item>(); int argNextIdx = 0; string itemKey; while (CommandsHelpers.GetQuotedStringFromArgsAt(args, argNextIdx, out argNextIdx, out itemKey)) { int itemId; if (!ItemAttributeHelpers.DisplayNamesToIds.ContainsKey(itemKey)) { itemId = ItemID.TypeFromUniqueKey(itemKey); if (itemId == 0) { caller.Reply("Invalid item name: " + itemKey, Color.Red); return; } } else { itemId = ItemAttributeHelpers.DisplayNamesToIds[itemKey]; } var item = new Item(); item.SetDefaults(itemId); items.Add(item); } IEnumerable <string> itemNames = items.Select(i => ItemID.GetUniqueKey(i.type)); //TODO GetProperUniqueId if (ImpartmentContractItem.Create(Main.LocalPlayer, Main.LocalPlayer.Center, new HashSet <string>(itemNames)) != -1) { caller.Reply("Created Impartment Contract.", Color.Lime); } else { caller.Reply("Could not create Impartment Contract.", Color.Red); } }
//Examples: //############ //Mod summonersAssociation = ModLoader.GetMod("SummonersAssociation"); // // Regular call for a regular summon weapon // summonersAssociation?.Call( // "AddMinionInfo", // ItemType<MinionItem>(), // BuffType<MinionBuff>(), // ProjectileType<MinionProjectile>() // ); // // If the weapon summons two minions // summonersAssociation?.Call( // "AddMinionInfo", // ItemType<MinionItem>(), // BuffType<MinionBuff>(), // new List<int> { // ProjectileType<MinionProjectile1>(), // ProjectileType<MinionProjectile2>() // } // ); // // If you want to override the minionSlots of the projectile // (for example useful if you have a Stardust Dragon-like minion and you only want it to count one segment towards the number of summoned minions) // summonersAssociation?.Call( // "AddMinionInfo", // ItemType<MinionItem>(), // BuffType<MinionBuff>(), // ProjectileType<MinionProjectile>(), // 1f // ); // // If you want to override the minionSlots of the projectiles you specify (same order) // (for example useful if you have some complex minion that consists of multiple parts) // summonersAssociation?.Call( // "AddMinionInfo", // ItemType<MinionItem>(), // BuffType<MinionBuff>(), // new List<int> { // ProjectileType<MinionProjectile1>(), // ProjectileType<MinionProjectile2>() // }, // new List<float> { // 0.25f, // 0.5f // } // ); public override object Call(params object[] args) { /* message string, then * if "AddMinionInfo": * int, int, List<int>, List<float> * or * int, int, List<int> * or * int, int, int, float * or * int, int, int * * else if "SomeOther": * ... */ try { string message = args[0] as string; if (message == "AddMinionInfo") { if (SupportedMinionsFinalized) { throw new Exception($"{Name} Call Error: The attempted message, \"{message}\", was sent too late. {Name} expects Call messages to happen during Mod.PostSetupContent."); } int itemID = Convert.ToInt32(args[1]); int buffID = Convert.ToInt32(args[2]); if (itemID == 0 || itemID >= ItemLoader.ItemCount) { throw new Exception("Invalid item '" + itemID + "' registered"); } string itemMsg = " ### Minion from item '" + ItemID.GetUniqueKey(itemID) + "' not added"; if (buffID == 0 || buffID >= BuffLoader.BuffCount) { throw new Exception("Invalid buff '" + buffID + "' registered" + itemMsg); } if (args[3] is List <int> ) { var projIDs = args[3] as List <int>; if (projIDs.Count == 0) { throw new Exception("Projectile list empty" + itemMsg); } foreach (int type in projIDs) { if (type == 0 || type >= ProjectileLoader.ProjectileCount) { throw new Exception("Invalid projectile '" + type + "' registered" + itemMsg); } } if (args.Length == 5) { var slots = args[4] as List <float>; if (projIDs.Count != slots.Count) { throw new Exception("Length of the projectile list does not match up with the length of the slot list" + itemMsg); } AddMinion(new MinionModel(itemID, buffID, projIDs, slots)); } else { AddMinion(new MinionModel(itemID, buffID, projIDs)); } } else { int projID = Convert.ToInt32(args[3]); if (projID == 0 || projID >= ProjectileLoader.ProjectileCount) { throw new Exception("Invalid projectile '" + projID + "' registered" + itemMsg); } if (args.Length == 5) { float slot = Convert.ToSingle(args[4]); AddMinion(new MinionModel(itemID, buffID, projID, slot)); } else { AddMinion(new MinionModel(itemID, buffID, projID)); } } return("Success"); } } catch (Exception e) { Logger.Error(Name + " Call Error: " + e.StackTrace + e.Message); } return("Failure"); }
//////////////// /// <summary> /// Generates a hash value to uniquely identify a (vanilla) item instance by its field values. /// </summary> /// <param name="item"></param> /// <param name="noContext">Omits `owner`, `netID`, and `favorited` fields.</param> /// <param name="minimal">Uses only the item's unique ID (`GetUniqueKey(...)`), `prefix`, and `stack`.</param> /// <returns></returns> public static int GetVanillaSnapshotHash(Item item, bool noContext, bool minimal) { int hash = Entities.EntityHelpers.GetVanillaSnapshotHash(item, noContext); string id = ItemID.GetUniqueKey(item); hash ^= ("id" + id).GetHashCode(); hash ^= ("prefix" + item.prefix).GetHashCode(); hash ^= ("stack" + item.stack).GetHashCode(); if (!noContext) { hash ^= ("owner" + item.owner).GetHashCode(); hash ^= ("netID" + item.netID).GetHashCode(); hash ^= ("favorited" + item.favorited).GetHashCode(); } if (!minimal) { hash ^= ("mana" + item.mana).GetHashCode(); //hash ^= ("buyOnce"+item.buyOnce).GetHashCode(); //? hash ^= ("manaIncrease" + item.manaIncrease).GetHashCode(); hash ^= ("lifeRegen" + item.lifeRegen).GetHashCode(); hash ^= ("notAmmo" + item.notAmmo).GetHashCode(); hash ^= ("ammo" + item.ammo).GetHashCode(); hash ^= ("shootSpeed" + item.shootSpeed).GetHashCode(); hash ^= ("rare" + item.rare).GetHashCode(); //hash ^= ( "noUseGraphic" + item.noUseGraphic ).GetHashCode(); hash ^= ("useAmmo" + item.useAmmo).GetHashCode(); hash ^= ("shieldSlot" + item.shieldSlot).GetHashCode(); hash ^= ("stringColor" + item.stringColor).GetHashCode(); hash ^= ("balloonSlot" + item.balloonSlot).GetHashCode(); hash ^= ("faceSlot" + item.faceSlot).GetHashCode(); hash ^= ("neckSlot" + item.neckSlot).GetHashCode(); hash ^= ("noMelee" + item.noMelee).GetHashCode(); hash ^= ("wingSlot" + item.wingSlot).GetHashCode(); hash ^= ("waistSlot" + item.waistSlot).GetHashCode(); hash ^= ("shoeSlot" + item.shoeSlot).GetHashCode(); hash ^= ("frontSlot" + item.frontSlot).GetHashCode(); hash ^= ("backSlot" + item.backSlot).GetHashCode(); hash ^= ("handOffSlot" + item.handOffSlot).GetHashCode(); //hash ^= ("ToolTip"+item.ToolTip).GetHashCode(); //hash ^= ("release"+item.release).GetHashCode(); hash ^= ("buffTime" + item.buffTime).GetHashCode(); //hash ^= ("buy"+item.buy).GetHashCode(); //? //hash ^= ("newAndShiny"+item.newAndShiny).GetHashCode(); //? hash ^= ("reuseDelay" + item.reuseDelay).GetHashCode(); hash ^= ("sentry" + item.sentry).GetHashCode(); hash ^= ("summon" + item.summon).GetHashCode(); hash ^= ("thrown" + item.thrown).GetHashCode(); hash ^= ("ranged" + item.ranged).GetHashCode(); hash ^= ("magic" + item.magic).GetHashCode(); hash ^= ("melee" + item.melee).GetHashCode(); hash ^= ("crit" + item.crit).GetHashCode(); hash ^= ("DD2Summon" + item.DD2Summon).GetHashCode(); hash ^= ("shopCustomPrice" + (item.shopCustomPrice == null ? -1 : (int)item.shopCustomPrice)).GetHashCode(); hash ^= ("shopSpecialCurrency" + item.shopSpecialCurrency).GetHashCode(); hash ^= ("uniqueStack" + item.uniqueStack).GetHashCode(); hash ^= ("cartTrack" + item.cartTrack).GetHashCode(); hash ^= ("mountType" + item.mountType).GetHashCode(); hash ^= ("handOnSlot" + item.handOnSlot).GetHashCode(); hash ^= ("buffType" + item.buffType).GetHashCode(); hash ^= ("noWet" + item.noWet).GetHashCode(); hash ^= ("material" + item.material).GetHashCode(); hash ^= ("vanity" + item.vanity).GetHashCode(); hash ^= ("social" + item.social).GetHashCode(); hash ^= ("value" + item.value).GetHashCode(); hash ^= ("legSlot" + item.legSlot).GetHashCode(); hash ^= ("shoot" + item.shoot).GetHashCode(); hash ^= ("headSlot" + item.headSlot).GetHashCode(); hash ^= ("holdStyle" + item.holdStyle).GetHashCode(); //////hash ^= ("type"+item.type).GetHashCode(); //hash ^= ("keepTime"+item.keepTime).GetHashCode(); //hash ^= ("ownTime"+item.ownTime).GetHashCode(); //hash ^= ("ownIgnore"+item.ownIgnore).GetHashCode(); hash ^= ("instanced" + item.instanced).GetHashCode(); hash ^= ("paint" + item.paint).GetHashCode(); hash ^= ("hairDye" + item.hairDye).GetHashCode(); hash ^= ("expert" + item.expert).GetHashCode(); hash ^= ("expertOnly" + item.expertOnly).GetHashCode(); hash ^= ("useStyle" + item.useStyle).GetHashCode(); hash ^= ("makeNPC" + item.makeNPC).GetHashCode(); hash ^= ("fishingPole" + item.fishingPole).GetHashCode(); hash ^= ("dye" + item.dye).GetHashCode(); hash ^= ("wornArmor" + item.wornArmor).GetHashCode(); hash ^= ("tileWand" + item.tileWand).GetHashCode(); hash ^= ("spawnTime" + item.spawnTime).GetHashCode(); //hash ^= ("isBeingGrabbed"+item.isBeingGrabbed).GetHashCode(); //hash ^= ("beingGrabbed"+item.beingGrabbed).GetHashCode(); //hash ^= ("noGrabDelay"+item.noGrabDelay).GetHashCode(); hash ^= ("bodySlot" + item.bodySlot).GetHashCode(); hash ^= ("flame" + item.flame).GetHashCode(); hash ^= ("questItem" + item.questItem).GetHashCode(); hash ^= ("bait" + item.bait).GetHashCode(); hash ^= ("channel" + item.channel).GetHashCode(); hash ^= ("mech" + item.mech).GetHashCode(); hash ^= ("useAnimation" + item.useAnimation).GetHashCode(); hash ^= ("defense" + item.defense).GetHashCode(); //hash ^= ("UseSound"+item.UseSound).GetHashCode(); hash ^= ("scale" + item.scale).GetHashCode(); hash ^= ("glowMask" + item.glowMask).GetHashCode(); hash ^= ("alpha" + item.alpha).GetHashCode(); hash ^= ("color" + item.color).GetHashCode(); hash ^= ("useTurn" + item.useTurn).GetHashCode(); hash ^= ("autoReuse" + item.autoReuse).GetHashCode(); hash ^= ("consumable" + item.consumable).GetHashCode(); hash ^= ("potion" + item.potion).GetHashCode(); hash ^= ("healMana" + item.healMana).GetHashCode(); hash ^= ("knockBack" + item.knockBack).GetHashCode(); hash ^= ("healLife" + item.healLife).GetHashCode(); hash ^= ("placeStyle" + item.placeStyle).GetHashCode(); hash ^= ("createWall" + item.createWall).GetHashCode(); hash ^= ("createTile" + item.createTile).GetHashCode(); hash ^= ("tileBoost" + item.tileBoost).GetHashCode(); hash ^= ("hammer" + item.hammer).GetHashCode(); hash ^= ("axe" + item.axe).GetHashCode(); hash ^= ("pick" + item.pick).GetHashCode(); hash ^= ("maxStack" + item.maxStack).GetHashCode(); hash ^= ("useTime" + item.useTime).GetHashCode(); hash ^= ("damage" + item.damage).GetHashCode(); hash ^= ("accessory" + item.accessory).GetHashCode(); } return(hash); }
public static void RemoveIntrinsic(Player player, Item item) { var myplayer = TmlHelpers.SafelyGetModPlayer <IntrinsicsPlayer>(player); myplayer.RemoveIntrinsic(ItemID.GetUniqueKey(item)); //TODO GetProperUniqueId }
public static int CreateContract(Player player, params Item[] items) { IEnumerable <string> itemNames = items.Select(i => ItemID.GetUniqueKey(i.type)); //TODO GetProperUniqueId return(ImpartmentContractItem.Create(player, player.Center, new HashSet <string>(itemNames))); }