private float OnItemResearchEnd(ResearchTable table, float chance) { Item item = table.GetResearchItem(); float num1 = ResearchChance; if (!item.hasCondition) { if (chance <= num1) { chance = 0f; } else { chance = 1f; } return(chance); } float num2 = item.maxCondition / item.info.condition.max; float successChance = num1 * num2 * item.conditionNormalized; if (chance <= successChance) { chance = 0f; } else { chance = 1f; } return(chance); }
public override void Update(GameTime gameTime) { if (Main.player[Main.myPlayer].GetModPlayer <ResearchPlayer>().destroyingItem != realItem) { realItem = item = Main.player[Main.myPlayer].GetModPlayer <ResearchPlayer>().destroyingItem; } ResearchUI ui = ((ResearchFrom14)ModLoader.GetMod("ResearchFrom14")).ui; if (realItem == null || realItem.IsAir) { ui.totalText.SetText(""); } else { int totalR = ResearchTable.GetTotalResearch(realItem); if (totalR > 0) { ui.totalText.TextColor = Color.White; ui.totalText.SetText("" + Math.Min(Main.player[Main.myPlayer].GetModPlayer <ResearchPlayer>().GetResearchedAmount(realItem), totalR) + "/" + totalR); } else { ui.totalText.TextColor = Color.Red; ui.totalText.SetText("Unresearchable!"); } } base.Update(gameTime); }
public override void ServerInit() { base.ServerInit(); ResearchTable researchTable = this; this.inventory.canAcceptItem = new Func <Item, int, bool>(researchTable.ItemFilter); }
private void OnItemResearch(ResearchTable table, Item targetItem, BasePlayer player) { if (player == null) { return; } if (CanInstant(player) && CanControlled(player)) { rust.SendChatMessage(player, "", lang.GetMessage("Both Permission", this, player.UserIDString)); table.researchDuration = 10f; return; } if (!CanControlled(player) && !CanInstant(player)) { table.researchDuration = 10f; return; } if (CanInstant(player)) { table.researchDuration = 0f; } if (CanControlled(player)) { table.researchDuration = researchSpeed; } }
object OnItemResearch(ResearchTable table, Item targetItem, BasePlayer player) { addcoin(player.userID.ToString(), researchmoney); Puts("User '" + player.name + "' earned coins from research!"); return(null); }
public void ActivatePurchaseUI(int player) { if (player == Main.myPlayer && Main.netMode != NetmodeID.Server) { ui?.setVisible(true); Main.playerInventory = true; Main.recBigList = false; if (ModContent.GetInstance <ExceptionListConfig>().forceReload) { ResearchTable.InitResearchTable(); if (Main.netMode == NetmodeID.MultiplayerClient) { ModPacket pk = this.GetPacket(); pk.Write((byte)99); pk.Write((byte)Main.myPlayer); pk.Send(-1, -1); Main.player[Main.myPlayer].GetModPlayer <ResearchPlayer>().RebuildCache(); ModContent.GetInstance <ExceptionListConfig>().forceReload = false; } else { ModContent.GetInstance <ExceptionListConfig>().forceReload = false; SaveListConfig(); } } } }
private Item GetBlueprint(ItemDefinition learnableItem, int amount = 1) { Item item = ItemManager.Create(ResearchTable.GetBlueprintTemplate(), amount); item.blueprintTarget = learnableItem.itemid; return(item); }
void OnItemResearchStart(ResearchTable table) { table.researchCostFraction = ResearchCostFraction; if ((bool)Config["InstantResearch"]) { table.researchDuration = 0f; } }
public bool IsResearched(String itemTag) { int res = ResearchTable.GetTotalResearch(itemTag); if (res < 1) { return(false); } return(GetResearchedAmount(itemTag) >= res); }
public bool IsResearched(int itemType) { int res = ResearchTable.GetTotalResearch(itemType); if (res < 1) { return(false); } return(GetResearchedAmount(itemType) >= res); }
private async Task _LoadDataTables() { Task[] loaders = new Task[] { Task.Run(() => _versions = new VersionTable()), Task.Run(() => _colors = new ColorTable()), Task.Run(() => _items = new ItemTable()), Task.Run(() => _recipes = new RecipeTable()), Task.Run(() => _researchs = new ResearchTable()), Task.Run(() => _schematics = new SchematicTable()), }; await Task.WhenAll(loaders); }
public new void Enter(IemStateManager.StateManager sm) { TargetPracticeStateManager gsm = (TargetPracticeStateManager)sm; gsm.partition = new IemObjectPlacement.CopyPastePlacement( "tp_v1_" + gsm.eg.difficultyLevel, gsm.location); ResearchTable researchtable = IemUtils.FindComponentNearestToLocation <ResearchTable>( gsm.location, 50); Vector3 playerstart = researchtable.transform.position; researchtable.Kill(BaseNetworkable.DestroyMode.None); RepairBench repairbench = IemUtils.FindComponentNearestToLocation <RepairBench>( gsm.location, 50); Vector3 playerlook = repairbench.transform.position; repairbench.Kill(BaseNetworkable.DestroyMode.None); me.Puts("player start location is " + playerstart); me.Puts("player look location is " + playerlook); me.Puts("swutcged " + IemUtils.SwitchTypesToTarget <BaseOven>(gsm.location)); gsm.eg.player.inventory.Strip(); EntitiesTakingDamage += gsm.eg.PlayerImmortal; IemUtils.MovePlayerToTeamLocation(gsm.eg.player, playerstart); Vector3 relativePos = playerstart - playerlook; Quaternion rotation = Quaternion.LookRotation(relativePos); gsm.eg.player.transform.rotation = rotation; IemUtils.SetMetabolismValues(gsm.eg.player); IemUtils.ClearInventory(gsm.eg.player); IemUI.CreateGameBanner(gsm.eg.player, "GAME LOBBY"); IemUtils.PlaySound(gsm.eg.player); gsm.eg.returnZone = new IemUtils.ReturnZone(playerstart, gsm.eg.player); IemUI.Confirm(gsm.eg.player, $"Weclome to target practice\n" + $"Knock down the targets to proceed to the next level.\n" + $"each level timer will start when you fire the first shot", "Start Shootin'", gsm.proceedAction); gsm.eg.targets = IemUtils.FindComponentsNearToLocation <ReactiveTarget>(gsm.location, 50); me.Puts("targets count is " + gsm.eg.targets.Count()); }
public bool IsResearched(Item item) { int res = ResearchTable.GetTotalResearch(item); if (res < 1) { return(false); } if (item.prefix > 0) { return(IsResearchedPrefix(item) && (GetResearchedAmount(item) >= res)); } return(GetResearchedAmount(item) >= res); }
private float IOnItemResearchEnd(ResearchTable table, float chance) { var returnvar = Interface.CallHook("OnItemResearchEnd", table, chance); if (returnvar is float) { return((float)returnvar); } if (returnvar is double) { return((float)(double)returnvar); } return(chance); }
public void Research() { if (destroyingItem == null || destroyingItem.IsAir) { return; } int type = destroyingItem.type; int stack = destroyingItem.stack; if (!IsResearched(destroyingItem)) { bool needsCacheRebuilt = true; destroyingItem.stack = AddResearchedAmount(destroyingItem); AddResearchPrefix(destroyingItem); if (destroyingItem.stack == stack) { destroyingItem.stack--; needsCacheRebuilt = false; } if (destroyingItem.stack != stack) { if (destroyingItem.stack <= 0) { destroyingItem.TurnToAir(); } else if (ResearchFrom14.PlaceInInventory(player, destroyingItem)) { destroyingItem = new Item(); } if (GetResearchedAmount(type) < ResearchTable.GetTotalResearch(type)) { Main.PlaySound(SoundID.Grab); } else { Main.PlaySound(SoundID.Item4); if (needsCacheRebuilt) { rebuildingCache = true; researchedCache.Add(type); CheckRecipesForItem(type); rebuildingCache = false; } } } } }
int OnItemScrap(ResearchTable table, Item item) { decimal rate = GetPlayerRate(table.user); if (config.Prices.ContainsKey(item.info)) { return((int)(config.Prices[item.info].Cost * rate)); } else { PrintWarning("{0} has created blueprint for unlisted item - \"{1}\". Setting default price.", table.user == null ? "Unknown player" : $"Player \"{table.user.displayName}\"", item.info.displayName.english); return((int)(GetDefaultPrice(item.info) * rate)); } }
public override void ModifyTooltips(Item item, List <TooltipLine> tooltips) { if (ModContent.GetInstance <Config>().showResearch) { ResearchPlayer rp = Main.player[Main.myPlayer].GetModPlayer <ResearchPlayer>(); if (rp.IsResearched(item)) { if (ModContent.GetInstance <Config>().showResearched) { tooltips.Add(new TooltipLine(this.mod, "Research", "Researched!") { overrideColor = Color.Lerp(Color.HotPink, Color.White, 0.1f) }); } } else { if (ResearchTable.GetTotalResearch(item) <= 0) { tooltips.Add(new TooltipLine(this.mod, "Research", "Unresearchable!") { overrideColor = Color.Lerp(Color.HotPink, Color.White, 0.1f) }); } else { if (!rp.IsResearched(item.type)) { tooltips.Add(new TooltipLine(this.mod, "Research", "Research " + (ResearchTable.GetTotalResearch(item) - rp.GetResearchedAmount(item)) + " more to unlock.") { overrideColor = Color.Lerp(Color.HotPink, Color.White, 0.1f) }); } else { tooltips.Add(new TooltipLine(this.mod, "Research", "Base item Researched, but not this Prefix for this item.") { overrideColor = Color.Lerp(Color.HotPink, Color.White, 0.1f) }); } } } } if (ModContent.GetInstance <Config>().showTag) { tooltips.Add(new TooltipLine(this.mod, "tagID", "<" + ResearchFrom14.ItemToTag(item) + ">")); } }
public void ResearchAttemptFinished() { Item targetItem = this.GetTargetItem(); Item scrapItem = this.GetScrapItem(); if (targetItem != null && scrapItem != null) { int num = this.ScrapForResearch(targetItem); object obj = Interface.CallHook("OnItemResearched", this, num); if (obj is int) { num = (int)obj; } if (scrapItem.amount >= num) { if (scrapItem.amount > num) { scrapItem.UseItem(num); } else { this.inventory.Remove(scrapItem); scrapItem.RemoveFromContainer(); scrapItem.Remove(0f); } this.inventory.Remove(targetItem); targetItem.Remove(0f); Item item = ItemManager.Create(ResearchTable.GetBlueprintTemplate(), 1, (ulong)0); item.blueprintTarget = targetItem.info.itemid; if (!item.MoveToContainer(this.inventory, 0, true)) { item.Drop(this.GetDropPosition(), this.GetDropVelocity(), new Quaternion()); } if (this.researchSuccessEffect.isValid) { Effect.server.Run(this.researchSuccessEffect.resourcePath, this, 0, Vector3.zero, Vector3.zero, null, false); } } } base.SendNetworkUpdateImmediate(false); if (this.user != null) { this.user.inventory.loot.SendImmediate(); } this.EndResearch(); }
public void ResearchAttemptFinished() { Item targetItem = this.GetTargetItem(); Item scrapItem = this.GetScrapItem(); if (targetItem != null && scrapItem != null) { int amountToConsume = this.ScrapForResearch(targetItem); object obj1 = Interface.CallHook("OnItemResearched", (object)this, (object)amountToConsume); if (obj1 is int) { amountToConsume = (int)obj1; } if (scrapItem.amount >= amountToConsume) { if (scrapItem.amount <= amountToConsume) { this.inventory.Remove(scrapItem); scrapItem.RemoveFromContainer(); scrapItem.Remove(0.0f); } else { scrapItem.UseItem(amountToConsume); } this.inventory.Remove(targetItem); targetItem.Remove(0.0f); Item obj2 = ItemManager.Create(ResearchTable.GetBlueprintTemplate(), 1, 0UL); obj2.blueprintTarget = targetItem.info.itemid; if (!obj2.MoveToContainer(this.inventory, 0, true)) { obj2.Drop(this.GetDropPosition(), this.GetDropVelocity(), (Quaternion)null); } if (this.researchSuccessEffect.isValid) { Effect.server.Run(this.researchSuccessEffect.resourcePath, (BaseEntity)this, 0U, Vector3.get_zero(), Vector3.get_zero(), (Connection)null, false); } } } this.SendNetworkUpdateImmediate(false); if (Object.op_Inequality((Object)this.user, (Object)null)) { this.user.inventory.loot.SendImmediate(); } this.EndResearch(); }
public override void Load() { base.Load(); ResearchTable.ClearTable(); invalidSetDefaults.Clear(); if (!Main.dedServ) { purchaseUI = new UserInterface(); ui = new ResearchUI(); ui.Activate(); purchaseUI.SetState(ui); hotkey = RegisterHotKey("Open or Close ResearchUI", "Add"); prefixUI = new UserInterface(); preUI = new PrefixUI(); preUI.Activate(); prefixUI.SetState(preUI); preHotkey = RegisterHotKey("Open or Close Prefix Assignment", "Subtract"); } }
// Return value: // - null = continue with default behaviour of hammer hit // - anything else: prevent default behaviour. private object HandleUpgradeRequest(BasePlayer player, ResearchTable researchTable) { if (UpgradeCost.Count > 0) { if (!player.CanCraft(UpgradeCost)) { StringBuilder builder = new StringBuilder(); foreach (var ingredient in UpgradeCost) { builder.AppendLine("- x" + ingredient.amount.ToString("0") + " " + ingredient.itemDef.displayName.english); } string ingredientsStr = builder.ToString(); player.ShowScreenMessage(Lang.Translate(player, "ingredients-missing-youneed") + "\n" + ingredientsStr, 10, TextAnchor.MiddleLeft); return(true); } } float lastHit = lastHammerHit[player]; if (Time.time - lastHit > Constants.HammerConfirmTime) // Confirm the upgrade { lastHammerHit[player] = Time.time; player.ShowScreenMessage(Lang.Translate(player, "hammer-confirm-upgrade"), Constants.HammerConfirmTime); return(true); } lastHammerHit[player] = 0; // Reset time foreach (var ingredient in UpgradeCost) { List <Item> takenItems = new List <Item>(); player.inventory.Take(takenItems, ingredient.itemid, (int)ingredient.amount); } CrafterManager.CreateCrafter(researchTable); FxManager.PlayFx(researchTable.ServerPosition, Constants.UpgradeTopTierFxPrefab); player.HideScreenMessage(); return(true); }
// Fill ResearchTable and Workbench with scrap on spawn. void OnEntitySpawned(BaseNetworkable entity) { if (entity is ResearchTable) { ResearchTable table = entity as ResearchTable; Item tuition = ItemManager.CreateByItemID(scrapID, 777); if (tuition != null) { tuition.MoveToContainer(table.inventory, 1, true); } } else if (entity is Workbench) { Workbench bench = entity as Workbench; Item tuition = ItemManager.CreateByItemID(scrapID, bench.GetScrapForExperiment()); if (tuition != null) { tuition.MoveToContainer(bench.inventory, 1, true); } } }
/// <summary> /// Creates a crafter from the given research table. /// </summary> /// <param name="researchTable">The research table to replace.</param> /// <returns></returns> public static Crafter CreateCrafter(ResearchTable researchTable) { var recyclerEntity = GameManager.server.CreateEntity(Constants.StaticRecyclerPrefab, researchTable.ServerPosition, researchTable.ServerRotation); var recycler = recyclerEntity.GetComponent <Recycler>(); recyclerEntity.OwnerID = researchTable.OwnerID; // Copy ownership to recycler. recyclerEntity.Spawn(); // Drop all items in research table onto the ground if (researchTable.inventory.AnyItems()) { researchTable.inventory.Drop(Constants.ItemDropPrefab, researchTable.ServerPosition + new Vector3(0, 1.5f, 0), researchTable.ServerRotation); } // Remove original research table. researchTable.Kill(); var crafter = CreateCrafter(recycler); return(crafter); }
void OnItemResearch(ResearchTable table, Item item, BasePlayer player) { if (!player) { table.researchDuration = 10; return; } var speed = GetPlayerSpeed(player); if (!speed.IsModifier) { table.researchDuration = (float)speed.Speed; } else if (config.Prices.ContainsKey(item.info)) { table.researchDuration = (float)(config.Prices[item.info].Speed * speed.Speed); } else { table.researchDuration = (float)(10 * speed.Speed); } }
private object CanLootEntity(BasePlayer player, ResearchTable rst) { if (rst == null) { return(null); } if (rsloot.ContainsKey(rst.net.ID)) { return(null); } rsloot.Add(rst.net.ID, player.userID); if (!rstimer.ContainsKey(player.userID)) { #if DEBUG Puts($"Creating CheckLooting timer for {player.displayName}"); #endif rstimer.Add(player.userID, timer.Every(0.5f, () => CheckLooting(player))); RsGUI(player, rst.net.ID); } return(null); }
public int AddResearchedAmount(String itemTag, int amount) { if (itemTag == "0") { if (research.ContainsKey(itemTag)) { research.Remove(itemTag); } return(amount); } int available = 0; if (research.ContainsKey(itemTag)) { available = research.GetAsInt(itemTag); } int max = ResearchTable.GetTotalResearch(itemTag); if (available >= max) { return(amount); } if (available + amount > max) { research[itemTag] = max; return((amount + available) - max); } else { research[itemTag] = available + amount; return(0); } }
public override void Unload() { ResearchTable.ClearTable(); invalidSetDefaults.Clear(); }
public override object Call(params object[] args) { if (args.Length == 0 || !(args[0] is string) || (((args[0]) as string) == null)) { Logger.Info("Mod call was Empty. This will display, in log, what functions are currently available. All function calls are case-insensitive, but arguments are not."); Logger.Info("Player arguments accept the Player object or the Player.whoAmI (position in the Main.player array)"); Logger.Info("Item arguments take Item objects, ModItem object, the int Type of that item or the Item Tag of the item)"); Logger.Info("Int values accept int or its string representation"); Logger.Info("Functions available"); Logger.Info(" - IsResearched (Player, Item) "); Logger.Info("Returns -1 if the item is irresearchable, 0 if it is totally researched or the number of items remaining before becoming fully researched."); Logger.Info(" - AddResearch (Player, Item, Int) "); Logger.Info("Adds Int to the researched amount of Item for the given Player. Send Int32.Max for fully research the item regardless of current amount. This will not research items considered unresearchable. Returns the research amount remaining after adding."); Logger.Info(" - SetDefaultMaxResearch (Item, Int) "); Logger.Info("Sets the default, starting value for the specified item's research needed. If this value is -1, makes it impossible to research, 0 makes this mod's algorithm decide, positive values are set as the amount needed.\n" + "Note: This function does not alter the values outright. After finishing calling all the SetDefault* you need, call ResetTable."); Logger.Info(" - SetDefaultCategories (Item, List<string>) or SetDefaultCategories (Item, string ...) "); Logger.Info("Sets the default category to a custom value. This does not stop it from showing up in other categories, it's just a way to make custom categories for mods possible.\n" + "Note: This function does not alter the values outright. After finishing calling all the SetDefault* you need, call ResetTable."); Logger.Info(" - ResetTable() "); Logger.Info("Resets the table, applying the new defaults that have been set. This function is required to apply the changes made by the two SetDefault functions. Use it at the end of all your Item Changes."); return(null); } string function = args[0] as string; /* IsResearched * - Params * - Player * - item * - Returns -1 if unresearchable, 0 if researched, the remaining items to reseach otherwise.*/ if (function.ToLower().Equals("isresearched")) { if (args.Length != 3) { Logger.Error("Error in ModCall IsResearched: Invalid parameter number (Player, Item)"); return(null); } Player p = getPlayerFromObject(args[1]); if (p == null) { Logger.Error("Error in ModCall IsResearched: Player is null (means not really a Player or a player.whoAmI)"); return(null); } int?itemID = getItemTypeFromObject(args[2]); if (itemID == null) { Logger.Error("Error in ModCall IsResearched: Item is null (means not really an Item, ModItem, int or valid ItemTag string)"); return(null); } if (itemID.Value == 0) { Logger.Error("Error in ModCall IsResearched: Item type is 0. This value is not valid (probably invalid ItemTag string)"); return(null); } ResearchPlayer player = p.GetModPlayer <ResearchPlayer>(); int researched = player.GetResearchedAmount(itemID.Value); int total = ResearchTable.GetTotalResearch(itemID.Value); if (total < 1) { return(-1); } if (researched <= total) { return(total - researched); } return(0); } /* AddResearch * - Params * - Player * - item * - amount * - Adds research amount to item for Player*/ if (function.ToLower().Equals("addresearch")) { if (args.Length != 4) { Logger.Error("Error in ModCall AddResearch: Invalid parameter number (Player, Item, int amount)"); return(null); } Player p = getPlayerFromObject(args[1]); if (p == null) { Logger.Error("Error in ModCall AddResearch: Player is null (means not really a Player or a player.whoAmI)"); return(null); } int?itemID = getItemTypeFromObject(args[2]); if (itemID == null) { Logger.Error("Error in ModCall AddResearch: Item is null (means not really an Item, ModItem, int or valid ItemTag string)"); return(null); } if (itemID.Value == 0) { Logger.Error("Error in ModCall AddResearch: Item type is 0. This value is not valid (probably invalid ItemTag string)"); return(null); } int?amount = getIntFromObject(args[3]); if (amount == null) { Logger.Error("Error in ModCall AddResearch: amount is null (means not really an int or an int-parsable string)"); return(null); } ResearchPlayer player = p.GetModPlayer <ResearchPlayer>(); if (ResearchTable.GetTotalResearch(itemID.Value) <= 0) { return(-1); } try { Item itm = new Item(); itm.SetDefaults(itemID.Value); itm.stack = amount.Value == Int32.MaxValue ? (amount.Value - 1000): amount.Value; int total = player.AddResearchedAmount(itm); return(total); }catch (Exception ex) { Logger.Error("Error in ModCall AddResearch: Item cannot be SetDefault"); } return(null); } /* SetDefaultMaxResearch * - Params * - item * - int amount * Sets the default value for the required research for the given item to become infinite * - Returns nothing*/ if (function.ToLower().Equals("setdefaultmaxresearch")) { if (args.Length != 3) { Logger.Error("Error in ModCall SetDefaultMaxResearch: Invalid parameter number (Item, int)"); return(null); } int?itemID = getItemTypeFromObject(args[1]); if (itemID == null) { Logger.Error("Error in ModCall SetDefaultMaxResearch: Item is null (means not really an Item, ModItem, int or valid ItemTag string)"); return(null); } if (itemID.Value == 0) { Logger.Error("Error in ModCall SetDefaultMaxResearch: Item type is 0. This value is not valid (probably invalid ItemTag string)"); return(null); } int?amount = getIntFromObject(args[2]); if (amount == null) { Logger.Error("Error in ModCall SetDefaultMaxResearch: amount is null (means not really an int or an int-parsable string)"); return(null); } ResearchTable.defaultValues[itemID.Value] = amount.Value; return(ResearchTable.defaultValues[itemID.Value]); } /* SetDefaultCategories * - Params * - item * - List<string> or string... * Sets the default categories for the given item * - Returns true if successfully added category*/ if (function.ToLower().Equals("setdefaultcategories")) { if (args.Length < 3) { Logger.Error("Error in ModCall SetDefaultCategories: Invalid parameter number (Item, List<string> or string...)"); return(null); } int?itemID = getItemTypeFromObject(args[1]); if (itemID == null) { Logger.Error("Error in ModCall SetDefaultCategories: Item is null (means not really an Item, ModItem, int or valid ItemTag string)"); return(null); } if (itemID.Value == 0) { Logger.Error("Error in ModCall SetDefaultCategories: Item type is 0. This value is not valid (probably invalid ItemTag string)"); return(null); } List <string> cats = getListOfStringFromObjects(args, 2); if (cats.Count == 0) { Logger.Error("Error in ModCall SetDefaultCategories: no strings found"); return(null); } if (ResearchTable.defaultCategories.ContainsKey(itemID.Value)) { ResearchTable.defaultCategories[itemID.Value].AddRange(cats); } else { ResearchTable.defaultCategories[itemID.Value] = cats; } return(true); } if (function.ToLower().Equals("resettable")) { ResearchTable.InitResearchTable(); } Logger.Error("Error in ModCall: function \"" + function + "\" does not exist."); return(null); }
public override void HandlePacket(BinaryReader reader, int whoAmI) { int messageID = reader.ReadByte(); Logger.Info("Received Message id " + messageID); /*message 0: Share research with server (not used) * int Player * TAGCompound Research*/ if (messageID == 0) { int player = reader.ReadByte(); if (Main.netMode == NetmodeID.Server || player != Main.myPlayer) { TagCompound tempResearch = TagIO.Read(reader); foreach (KeyValuePair <string, object> read in tempResearch) { Main.player[player].GetModPlayer <ResearchPlayer>().research[read.Key] = tempResearch.GetAsInt(read.Key); } Main.player[player].GetModPlayer <ResearchPlayer>().dirtyCache = true; Main.player[player].GetModPlayer <ResearchPlayer>().RebuildCache(); return; } } /*message 1: dirty cache * int player * refreshes the cache*/ if (messageID == 1) { int player = reader.ReadByte(); Main.player[player].GetModPlayer <ResearchPlayer>().dirtyCache = true; Main.player[player].GetModPlayer <ResearchPlayer>().RebuildCache(); return; } /*message 10 : P2P item cache sharing * byte player * int count * int[count] itemIDs * Share the cache with another player. Meant to share multiple, fully researched items at once. * Will send another such message to the sender (with this whoAmI) with the researched items, * and will keep sending them to one another until the cache is equal*/ if (messageID == 10) //Shared item Cache { ResearchPlayer rp = Main.player[Main.myPlayer].GetModPlayer <ResearchPlayer>(); int sendTo = reader.ReadByte(); //Logger.Info("Received shared cache Message to "+i); List <int> oldCache = new List <int>(); oldCache.AddRange(rp.researchedCache); int count = reader.ReadInt32(); for (int i = 0; i < count; i++) { int id = reader.ReadInt32(); if (!rp.IsResearched(id)) { rp.AddResearchedAmount(id, ResearchTable.GetTotalResearch(id)); rp.CheckRecipesForItem(id); } } if (Main.netMode == NetmodeID.Server || sendTo != Main.myPlayer) { rp.shareCacheTo(sendTo); } return; } /*message 11: Share single item with intermediate result * byte player to send to * byte player that sent the message * int item * int research count * * Adds the research count to the player's research, and replies with the same message with its previous research count */ if (messageID == 11) { ResearchPlayer rp = Main.player[Main.myPlayer].GetModPlayer <ResearchPlayer>(); int sendTo = reader.ReadByte(); int orgSender = reader.ReadByte(); int itm = reader.ReadInt32(); int amount = reader.ReadInt32(); int prevResearch = rp.GetResearchedAmount(itm); int res = rp.AddResearchedAmount(itm, amount); if (Main.netMode == NetmodeID.Server) { ModPacket pk = GetPacket(); pk.Write((byte)11); pk.Write((byte)(sendTo)); pk.Write((byte)(orgSender)); pk.Write(itm); pk.Write(amount); pk.Send(sendTo); return; } //Logger.Info("Received share single item Message from " + sender + ". Item " + itm + " with amount "+ amount); if (rp.IsResearched(itm) && res != amount) { rp.CheckRecipesForItem(itm); //Logger.Info("Item "+ itm + " was fully researched with " + amount); rp.RebuildCache(); if (orgSender == Main.myPlayer) { return; } ModPacket pk = GetPacket(); pk.Write((byte)11); pk.Write((byte)(orgSender)); pk.Write((byte)(orgSender)); pk.Write(itm); pk.Write(prevResearch + amount); pk.Send(); } else { //Logger.Info("Item " + itm + " was not fully researched with " + amount); } return; } /*message 12: Share prefixes * byte player to send to * int itm * int count * byte[count] prefixes * * Sends all prefixes for item itm, with no replies. Only adds prefixes.*/ if (messageID == 12) { ResearchPlayer rp = Main.player[Main.myPlayer].GetModPlayer <ResearchPlayer>(); int sendTo = reader.ReadByte(); int itm = reader.ReadInt32(); int count = reader.ReadInt32(); List <byte> prefixes = new List <byte>(); for (int i = 0; i < count; i++) { byte p = reader.ReadByte(); prefixes.Add(p); rp.AddResearchPrefix(itm, p); } if (Main.netMode == NetmodeID.Server) { ModPacket pk = GetPacket(); pk.Write((byte)12); pk.Write((byte)(sendTo)); pk.Write(prefixes.Count); for (int k = 0; k < prefixes.Count; k++) { pk.Write((byte)(prefixes[k])); } pk.Send(sendTo); } return; } if (messageID == 99) { int player = reader.ReadByte(); ResearchTable.InitResearchTable(); if (Main.netMode == NetmodeID.Server) { ModPacket pk = this.GetPacket(); pk.Write((byte)99); pk.Write((byte)player); pk.Send(-1, player); ModContent.GetInstance <ExceptionListConfig>().forceReload = false; SaveListConfig(); } else { Main.player[Main.myPlayer].GetModPlayer <ResearchPlayer>().RebuildCache(); } ModContent.GetInstance <ExceptionListConfig>().forceReload = false; return; } }
private object OnResearchCostDetermine(Item item, ResearchTable table) { return(Interface.Oxide.CallDeprecatedHook("OnItemScrap", "OnResearchCostDetermine(Item item, ResearchTable table)", new System.DateTime(2021, 7, 1), table, item)); }
private float OnItemResearchEnd(ResearchTable table, float chance) { Item item = table.GetResearchItem(); float num1 = ResearchChance; if (!item.hasCondition) { if (chance <= num1) { chance = 0f; } else { chance = 1f; } return chance; } float num2 = item.maxCondition / item.info.condition.max; float successChance = num1 * num2 * item.conditionNormalized; if (chance <= successChance) { chance = 0f; } else { chance = 1f; } return chance; }
void OnItemResearchStart(ResearchTable table) { table.researchCostFraction = ResearchCostFraction; if((bool) Config["InstantResearch"]) { table.researchDuration = 0f; } }
private float IOnItemResearchEnd(ResearchTable table, float chance) { var returnvar = Interface.CallHook("OnItemResearchEnd", table, chance); if (returnvar is float) return (float)returnvar; if (returnvar is double) return (float)(double)returnvar; return chance; }