protected override void OnChecked(NPC?npc, int index, int count, Item?item, string?str) { if (item is SObject crafted) { ItemCrafted?.Invoke(null, new ItemReceivedEventArgs(crafted, 1)); } }
static public object Rit_RefreshUpgradeIdol(Thea2.Server.Group target, RitualsTask sourceTask) { if (target != null && target.items != null) { BuildingRecipe br = (BuildingRecipe)BUILD_REC.IDOL; var oldIdol = target.items.Find(o => o.GetItem().GetSource() == br); if (oldIdol == null) { return(null); } var oldDemon = oldIdol.GetItem().superConnection; #region Create new idol List <ItemBase> ibs = ItemBase.items.Where(o => o.GetSource() == br && (o as ItemCrafted).recipeIngredientCount[0] == sourceTask.GetMaterial1Count() && (o as ItemCrafted).recipeIngreadients[0].Get() == sourceTask.GetMaterial1()).ToList(); if (ibs.Count != 1) { Debug.LogError("[ERROR]Number of options in upgrade idol is different than 1: " + ibs.Count); return(null); } ItemCrafted ib = ibs[0] as ItemCrafted; ItemBase inst = ib.Clone <ItemBase>(true); Skill skill = null; if (br.skills != null) { if (!SkillInstance.skillPacks.ContainsKey(br.skills)) { Debug.LogError("[ERROR]Missing skillpack " + br.skills); return(null); } List <Skill> si = SkillInstance.skillPacks[br.skills]; HashSet <Tag> essences = new HashSet <Tag>(); Dictionary <Tag, FInt> essenceCounts = new Dictionary <Tag, FInt>(); List <Skill> valid = new List <Skill>(); CountedResource material1 = null; CountedResource material2 = null; if (ib.recipeIngreadients.Length > 0) { material1 = new CountedResource(); material1.resourceName = ib.recipeIngreadients[0].Get(); material1.resourceCount = ib.recipeIngredientCount[0]; } if (ib.recipeIngreadients.Length > 1) { material2 = new CountedResource(); material2.resourceName = ib.recipeIngreadients[1].Get(); material2.resourceCount = ib.recipeIngredientCount[1]; } if (material1 != null) { foreach (var v in material1.resourceName.essences) { FInt count = new FInt(v.amount) * material1.resourceCount; if (count <= 0) { continue; } essences.Add(v.tag); essenceCounts[v.tag] = count; } } if (material2 != null) { foreach (var v in material2.resourceName.essences) { FInt count = new FInt(v.amount) * material2.resourceCount; if (count <= 0) { continue; } if (!essences.Contains(v.tag)) { essences.Add(v.tag); } if (!essenceCounts.ContainsKey(v.tag)) { essenceCounts[v.tag] = count; } else { essenceCounts[v.tag] += count; } } if (essences.Count > 0) { Tag g = (Tag)TAG.ESSENCE_GRAY; essences.Add(g); } } foreach (var v in si) { bool b = true; foreach (var e in v.baseEssence) { if (!essences.Contains(e.tag)) { b = false; break; } } if (!b) { continue; } valid.Add(v); } if (valid.Count < 1) { Debug.LogError("[ERROR]No valid skill during upgrade of the idol in skillpack " + br.skills); return(null); } skill = valid[0]; } if (skill != null) { inst.skill = SkillInstance.Instantiate(skill, inst); } #endregion #region Destroy old idol //destroy old idol var ceb = target.TakeItem(oldIdol.GetItem(), 1); ceb.GetItem().Destroy(); #endregion //Add new idol var cebNewIdol = target.AddItem(inst, 1); //super connect with old demon to keep it alive if one was still there, otherwise it will create new one. if (oldDemon != null && oldDemon.Valid()) { cebNewIdol.GetItem().SuperConnectWith(oldDemon); } } return(null); }